gpt4 book ai didi

javascript - 带自定义投影的 Leaflet 1.0.X fitBounds

转载 作者:太空宇宙 更新时间:2023-11-04 16:01:12 25 4
gpt4 key购买 nike

我正在致力于将项目从传单 0.7.3 迁移到传单 1.0.3。我的 map 有一个自定义投影,这似乎会导致 fitBounds 功能出现问题。

https://jsfiddle.net/4c2oxh89/是 fitBounds 与 leaflet 0.7.3 一起正常工作的示例

https://jsfiddle.net/jsywsgah/这是 fitBounds 与传单 1.0.3 一起工作不正确的示例

L.Projection.CustomProjection = {
tileSize: 256,
resolutionNum: 72,
inchesPerUnit: 39.3701,
originShift: Math.PI * 6378137,
mapConfig: {"aScales":[69885283.0036,34942641.5018,17471320.7509,8735660.37545,4367830.18772,2183915.09386,1200000,600000,300000,144000,68247.3466832,34123.6733416,17061.8366708,8530.9183354,4265.4591677,2132.72958385],"nCurrentScale":8,"nScale":300000,"initZoom":8,"initTop":-44485.818459823,"initLeft":-81008.552342608,"tileWidth":256,"tileHeight":256,"currentMap":"world_navteq_day","labelOpacity":10,"fallbackMap":"add"},

// https://github.com/Leaflet/Leaflet/blob/63fd4edc76893ab2a2f83d54e703e0a4da73de7b/src/geo/projection/Projection.SphericalMercator.js
bounds: (() => {
const d = 6378137 * Math.PI;
return L.bounds([-d, -d], [d, d]);
})(),

latLonToMeters: function(lat, lon){
const mx = lon * this.originShift / 180.0;
let my = Math.log(Math.tan((90 + lat) * Math.PI / 360.0)) / (Math.PI / 180.0);
my *= this.originShift / 180.0;
return [mx, my];
},

metersToLatLon: function(mx, my){
const lon = (mx / this.originShift) * 180.0;
let lat = (my / this.originShift) * 180.0;
lat = 180 / Math.PI * (2 * Math.atan( Math.exp( lat * Math.PI / 180.0)) - Math.PI / 2.0);
return [lat, lon];
},

latLonToPixels: function(lat, lon, zoom){
const m = this.latLonToMeters(lat, lon);
return this.metersToPixels(m[0], m[1], zoom);
},

metersToPixels: function(mx, my, zoom){
const scale = this.resolution(zoom);
const px = (mx / scale);
const py = (-my / scale);
return [Math.floor(px), Math.floor(py)];
},

pixelsToMeters: function(px, py, zoom){
const scale = this.resolution(zoom);
const gx = px * scale;
const gy = -py * scale;
return [gx, gy];
},

resolution: function(zoom){
return (this.mapConfig.aScales[zoom] / (this.resolutionNum * this.inchesPerUnit));
},

project: function(latLng, zoom){
const pixels = this.latLonToPixels(latLng.lat, latLng.lng, zoom);
return new L.Point(pixels[0], pixels[1]);
},

unproject: function(point, zoom){
const meters = this.pixelsToMeters(point.x, point.y, zoom);
const latLon = this.metersToLatLon(meters[0], meters[1]);
return new L.LatLng(latLon[0], latLon[1]);
},
};

有什么想法吗?

最佳答案

好的。所以。我刚刚复制/粘贴了 0.7.3 版本的 getBoundsZoom ,它就工作了。我不喜欢这个解决方案,但是:/

关于javascript - 带自定义投影的 Leaflet 1.0.X fitBounds,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42253805/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com