[英]How can I convert lng and lat from OpenLayers to mapbox?
OpenLayers 使用這樣的數組: [15711464.77174924, 1340284.424706252]
來處理中心的坐標,但是對於mapbox-gl
,我應該設置一個介於 -90 到 90 之間的值,但我得到了這個錯誤:
Error: Invalid LngLat latitude value: must be between -90 and 90
那么,有什么方法可以將坐標轉換為: 15711464.77174924
到 -90 到 90 之間?
球面墨卡托坐標假定世界是一個半徑為 6378137 米的球體。 要轉換為度數(基於 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.