问题
I am using mapbox javascript API to do some cool stuff on a map. Now I have a map location (latitude, longitude) pair and I want to set the view to this location then use javascript to simulate a click at this location. The problem is that I need to find out the screen position (x, y) pair of this location after setting the view. But how do I do that?
It seems there is an API L.ICRS. I tried but it returned NaN for both x and y -- please check my example javascript codes below.
var latlng = [40.444621, -79.943231]
map.setView(latlng, 13);
L.CRS.EPSG3857.latLngToPoint(latlng, 13);
Can anybody help me on that? My final goal is to simulate a click at that position.
Thank you very much!
回答1:
Mapbox.js
Use the latLngToContainerPoint method off of the map
object.
Mapbox GL JS
project is the equivalent function for GL.
来源:https://stackoverflow.com/questions/23026561/how-to-convert-a-map-location-lat-lng-pair-to-a-screen-position-x-y-pair-i