2017-02-15 6 views
1

私はプロジェクトをリーフレット0.7.3からリーフレット1.0.3に移行しています。マップにカスタム投影があり、これがfitBounds機能に問題を引き起こしているようです。リーフレット1.0.X fitBoundsとカスタムプロジェクション

https://jsfiddle.net/4c2oxh89/はリーフレット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]); 
    }, 
}; 

と間違って任意のアイデアを作業fitBoundsの例ですか?

答えて

1

そう。私はちょうど0.7.3バージョンのgetBoundsZoomをコピー/ペーストしていました。私はその解決策が嫌いですが、/

関連する問題