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