I am working with a leaflet app and I'm shifting a lot of the GIS calculations to the back end (a nodejs app). I need to be able to get the RGB value of a pixel given the latlng and the map zoom. (I'm using the Mapbox RGB Encoded Dem and I need elevation on a pixel-by-pixel basis). In order to do that, I need the XY value of the pixel relative to the map origin. This is conveniently done using leaflet's
map.project function. You can see a quick example of this here: codesandbox example.
Now I want to be able to get these XY coordinates on the back end, and I won't have the leaflet map instance to help me. (I could pass the
L.map instance to the back end, but I feel this is overkill.)
How can I write a function from scratch (or with some small / simple GIS libraries) to calculate the XY pixel value from a given
latlng and zoom? I feel this is probably a simple or even duplicate question but I'm not finding any coord transformation discussions that account for map zoom, or that are specific to a latlng's associated pixel on a webmap for a given projection and xyz coord.