如何将地图位置(lat,lng)对转换为mapbox中的屏幕位置(x,y)对 [英] How to convert a map location (lat, lng) pair to a screen position (x, y) pair in mapbox
问题描述
我正在使用 mapbox javascript API来做一些很酷的事情在地图上。现在我有一个地图位置(纬度,经度)对,我想将视图设置为此位置,然后使用javascript来模拟此位置的点击。问题是我需要在设置视图后找出该位置的屏幕位置(x,y)对。但是我该怎么做?
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?
似乎有一个API L.ICRS 。我试过但它返回了Na和x和y - 请检查下面的示例javascript代码。
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.
非常感谢!
推荐答案
Mapbox.js
使用地图对象的nofollow noreferrer> latLngToContainerPoint 方法。
Mapbox.js
Use the latLngToContainerPoint method off of the map
object.
项目是GL的等效函数。
这篇关于如何将地图位置(lat,lng)对转换为mapbox中的屏幕位置(x,y)对的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!