简体   繁体   English

如何将 lng 和 lat 从 OpenLayers 转换为 mapbox?

[英]How can I convert lng and lat from OpenLayers to mapbox?

OpenLayers uses an array like this: [15711464.77174924, 1340284.424706252] to handle center's coordinates, but for mapbox-gl I should set a value between -90 to 90 and I get this error: OpenLayers 使用这样的数组: [15711464.77174924, 1340284.424706252]来处理中心的坐标,但是对于mapbox-gl ,我应该设置一个介于 -90 到 90 之间的值,但我得到了这个错误:

Error: Invalid LngLat latitude value: must be between -90 and 90

So, is there any way to convert a coordinates like: 15711464.77174924 to between -90 to 90?那么,有什么方法可以将坐标转换为: 15711464.77174924到 -90 到 90 之间?

Spherical mercator coordinates assume the world is a sphere of radius 6378137 meters.球面墨卡托坐标假定世界是一个半径为 6378137 米的球体。 To convert to degrees (based on the OpenLayers source code https://github.com/openlayers/openlayers/blob/main/src/ol/proj/epsg3857.js#L132-L134 ) the function would be要转换为度数(基于 OpenLayers 源代码https://github.com/openlayers/openlayers/blob/main/src/ol/proj/epsg3857.js#L132-L134 ),function 将是

function toLonLat(input) {
    const RADIUS = 6378137;
    const HALF_SIZE = Math.PI * RADIUS;

    const lon = (180 * input[0]) / HALF_SIZE;
    const lat =
      (360 * Math.atan(Math.exp(input[1] / RADIUS))) / Math.PI - 90;

    return [lon, lat];
}

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

相关问题 如何从 openlayers map 获取经纬度值 - How to get lat/lng values from openlayers map 如何将地图位置(lat,lng)对转换为mapbox中的屏幕位置(x,y)对 - How to convert a map location (lat, lng) pair to a screen position (x, y) pair in mapbox 如何在字段集中显示 lat 和 lng 坐标(<input type="“text”" name="“lng”" id="“lng”" placeholder="“Longitude”"> )? - How can i display lat and lng coordinates inside a fieldset(<input type=“text” name=“lng” id=“lng” placeholder=“Longitude”>)? 如何将经纬度坐标转换为 Mapbox 地图图层上的点坐标? - How can I convert lat long coordinates to point coordinates on the map layer in Mapbox? 如何从 StandaloneSearchBox 获取 Lat 和 Lng? - How to get Lat and Lng from StandaloneSearchBox? 如何从经纬度获取地址? - How to get address from lat and lng? 如何从地理编码的地址中找到lat lng? - How to find the lat lng from a geocoded address? 如何在地图框的边界顶部获取经度? - How can I get lat on the boundary top of mapbox? 如何在MapBox中找到标记的纬度/经度? - How can I find the lat/lon of a marker in MapBox? 如何使用 JS 将两个值 (lat lng) 传递给 GET 请求的一个参数键? - How can I pass two values (lat lng) to one parameter key of GET request using JS?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM