How to convert a map location (lat, lng) pair to a screen position (x, y) pair in mapbox

匿名 (未验证) 提交于 2019-12-03 08:54:24

问题:

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.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!