简体   繁体   English

如何将经纬度坐标转换为 Mapbox 地图图层上的点坐标?

[英]How can I convert lat long coordinates to point coordinates on the map layer in Mapbox?

For a project I need to convert latitude and longitude coordinates to the map layer (map html canvas) point coordinates (in x and y).对于一个项目,我需要将纬度和经度坐标转换为地图层(地图 html 画布)点坐标(在 x 和 y 中)。 I have gone through almost the whole of Mapbox's documentation, but I can't seem to find it.我已经浏览了几乎整个 Mapbox 的文档,但我似乎找不到它。 Does anybody know how to do it?有人知道怎么做吗? (Javascript) (Javascript)

This:这个:

let point;
coordinates = [20,50]
point = convert(coordinates); // => point = (x, y);

Here is an example code from the official website.这是官方网站上的示例代码。 You have to register from the official website.您必须从官方网站注册。 And then you should get an access token for using Mapbox in your project.然后你应该得到一个在你的项目中使用 Mapbox 的访问令牌。 So it is quite simple.所以这很简单。

You can watch this video to understand visually how to do it.您可以观看此视频以直观地了解如何操作。

<script>
  mapboxgl.accessToken = '<your access token here>';
  var map = new mapboxgl.Map({
  container: 'map',
  style: 'mapbox://styles/mapbox/streets-v11',
  center: [12.550343, 55.665957],
  zoom: 8
});
 
var marker = new mapboxgl.Marker()
.setLngLat([12.550343, 55.665957])
.addTo(map);
</script>

Here you see above, in the "center" attribute you can define your own lat(firstly) and lng(secondly)在这里你看到上面,在“中心”属性中你可以定义你自己的 lat(first) 和 lng(secondly)

You can use mapboxgl.Map method called "project".您可以使用名为“project”的 mapboxgl.Map 方法。 It returns mapboxgl.Point by LngLatLike coordinates.它通过 LngLatLike 坐标返回 mapboxgl.Point。
TypeScript:打字稿:

const coordinates: LngLatLike = [37, 55];
const point = map.project(coordinates); // return Point object

// output: {
//   x: 713.802690844605
//   y: 390.2335262644118
// }

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

相关问题 将像素坐标转换为经纬度 - convert pixel coordinates to lat long 如何获取 javascript 中每一行的所有坐标? 因为我想使用 lat 和 long 在地图上绘制标记 - How can i fetch all the coordinates for every row of in javascript ? as i would like to use lat and long to draw marker on map 将SVG多边形路径转换为经纬度 - Convert SVG polygon path to lat and long coordinates 小册子中经纬度的坐标 - Coordinates to Lat Long in Leaflet 如何在Google Maps JS API中获取仍包含一组Lat / Long坐标的最小LatLngBounds? - How can I get the smallest LatLngBounds that still contains a set of Lat/Long Coordinates in Google Maps JS API? 如何从openlayers3中的矢量层获取点坐标? - How can I get the point coordinates from a vector layer in openlayers3? 单击 map 后如何使长纬度坐标可见并在下次单击之前可见? - How to make visible long lat coordinates after click to map and make visible until next click? 如何在反应中将地图框坐标传递给父 class? - How can I pass a mapbox coordinates to a parent class in react? 转换ArcGis地理坐标Lat Long wkid:4326到投影坐标wkid:102000/3857 - Convert ArcGis Geographic Coordinates Lat Long wkid: 4326 to Projected Coordinates wkid: 102000/3857 MapBox GL JS:从通过代码设置的字符串地址获取经纬度坐标 - MapBox GL JS: Get lat and long coordinates from string Address that is set through code
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM