有一种将屏幕坐标转换为相应的经度和纬度值的方法

问题描述 投票:0回答:1

我正在网页上使用mapbox-gl js。我想在地图上显示一个标记,但我知道它的位置,因为它距容器顶部和容器左侧的距离。例如top:120px和left:80px。是否有任何方法可以将此信息(即屏幕坐标)转换为mapbox的经度和纬度坐标。如果没有直接方法,请建议一种解决方法,将屏幕坐标转换为世界坐标。

javascript reactjs coordinates mapbox-gl-js mercator
1个回答
0
投票

来自https://docs.mapbox.com/mapbox-gl-js/example/mouse-position/

这应该可以解决问题:

    map.on('mousemove', function(e) {
        document.getElementById('info').innerHTML =
        // e.point is the x, y coordinates of the mousemove event relative
        // to the top-left corner of the map
        JSON.stringify(e.point) +
        '<br />' +
        // e.lngLat is the longitude, latitude geographical position of the event
        JSON.stringify(e.lngLat.wrap());
© www.soinside.com 2019 - 2024. All rights reserved.