简体   繁体   English

如何将地图位置(lat,lng)对转换为mapbox中的屏幕位置(x,y)对

[英]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! 非常感谢你!

Mapbox.js Mapbox.js

Use the latLngToContainerPoint method off of the map object. 使用map对象的latLngToContainerPoint方法。

Mapbox GL JS Mapbox GL JS

project is the equivalent function for GL. 项目是GL的等效功能。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如果我假设一个纬度/经度位于0,0,那么我该如何计算另一对纬度/经度的x,y坐标? - If I have one lat/lng which I assume is at 0,0 then how do I calculate the x, y coordinates of another lat/lng pair? 将游戏位置转换为旋转地图中的纬度 - Convert game position to lat lng in rotated map 将地理坐标(lat,lng)映射到地图(x,y) - map geo coordinates (lat, lng) to map (x, y) 将 map 上的像素 x,y position 转换为纬度和经度 - convert pixel x,y position on map to lat and long 从LAT,LNG定制SVG地图获取X,Y - Get X,Y from LAT,LNG custom svg map 如何将 lng 和 lat 从 OpenLayers 转换为 mapbox? - How can I convert lng and lat from OpenLayers to mapbox? 计算GMaps地图的最佳经纬度位置 - Calculate the best lat and lng location for a GMaps map Mapbox:如何将 lat/lng 值输入输入字段并通过鼠标单击地图放置标记? - Mapbox: How to get lat/lng value into input field and place a marker by mouse clicking on the map? Angular-Google-Map:如何在加载位置数据后加载地图(Lat,Lng)? - Angular-Google-Map: How to Load Map after Position Data Loaded(Lat, Lng)? 如何将经纬度信息传递到Google地图 - How to pass the lat, lng information to the google map
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM