[英]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.