1
我正在從項目小冊子0.7.3項目遷移到小葉1.0.3。我的地圖有一個自定義投影,這似乎是導致fitBounds功能的問題。傳單1.0.X fitBounds與自定義投影
https://jsfiddle.net/4c2oxh89/是與小葉正常工作0.7.3
https://jsfiddle.net/jsywsgah/是與小葉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]);
},
};
任何想法不正確工作fitBounds的例子fitBounds的例子嗎?