[英]How to convert a map location (lat, lng) pair to a screen position (x, y) pair in mapbox
I am using mapbox javascript API to do some cool stuff on a map. 我正在使用mapbox javascript API在地图上做一些很酷的东西。 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.
现在我有一个地图位置(纬度,经度)对,我想将视图设置为此位置,然后使用javascript来模拟此位置的点击。 The problem is that I need to find out the screen position (x, y) pair of this location after setting the view.
问题是我需要在设置视图后找出该位置的屏幕位置(x,y)对。 But how do I do that?
但是我该怎么做?
It seems there is an API L.ICRS . 似乎有一个API L.ICRS 。 I tried but it returned NaN for both x and y -- please check my example javascript codes below.
我试过但是它返回了NaN的x和y - 请检查我的示例javascript代码如下。
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! 非常感谢你!
Use the latLngToContainerPoint method off of the map
object. 使用
map
对象的latLngToContainerPoint方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.