Skip to content

Commit d4f4165

Browse files
committed
【fix】修复在指定crs的res时 imagelayer出图错误的问题
1 parent 9b5566f commit d4f4165

File tree

1 file changed

+13
-25
lines changed

1 file changed

+13
-25
lines changed

src/leaflet/mapping/ImageMapLayer.js

Lines changed: 13 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -193,10 +193,10 @@ export var ImageMapLayer = Layer.extend({
193193
},
194194

195195
//获取请求瓦片宽高以及请求范围参数
196-
_getImageParams: function() {
197-
var size = this._calculateImageSize();
196+
_getImageParams: function(bounds) {
197+
var size = this._calculateImageSize(bounds);
198198
return {
199-
viewBounds: this._compriseBounds(this._calculateBounds()),
199+
viewBounds: this._compriseBounds(this._calculateBounds(bounds)),
200200
width: size.x,
201201
height: size.y
202202
};
@@ -345,7 +345,7 @@ export var ImageMapLayer = Layer.extend({
345345
}
346346
return;
347347
}
348-
var params = this._getImageParams();
348+
var params = this._getImageParams(bounds);
349349
if (params) {
350350
this._requestImage(params, bounds);
351351
} else if (this._currentImage) {
@@ -355,12 +355,9 @@ export var ImageMapLayer = Layer.extend({
355355
},
356356

357357
//将像素坐标转成点坐标
358-
_calculateBounds: function() {
359-
var pixelBounds = this._map.getPixelBounds();
360-
var sw = this._map.unproject(pixelBounds.getBottomLeft());
361-
var ne = this._map.unproject(pixelBounds.getTopRight());
362-
var neProjected = this._map.options.crs.project(ne);
363-
var swProjected = this._map.options.crs.project(sw);
358+
_calculateBounds: function(bounds) {
359+
var neProjected = this._map.options.crs.project(bounds.getNorthEast());
360+
var swProjected = this._map.options.crs.project(bounds.getSouthWest());
364361
return L.bounds(neProjected, swProjected);
365362
},
366363

@@ -380,21 +377,12 @@ export var ImageMapLayer = Layer.extend({
380377
},
381378

382379
//计算图层的宽高
383-
_calculateImageSize: function() {
384-
var map = this._map;
385-
var bounds = map.getPixelBounds();
386-
var size = map.getSize();
387-
388-
var sw = map.unproject(bounds.getBottomLeft());
389-
var ne = map.unproject(bounds.getTopRight());
390-
391-
var top = map.latLngToLayerPoint(ne).y;
392-
var bottom = map.latLngToLayerPoint(sw).y;
393-
394-
if (top > 0 || bottom < size.y) {
395-
size.y = bottom - top;
396-
}
397-
return size;
380+
_calculateImageSize: function(bounds) {
381+
// 与imageoverlay 内部逻辑一致
382+
var sizeBounds = new L.Bounds(
383+
this._map.latLngToLayerPoint(bounds.getNorthWest()),
384+
this._map.latLngToLayerPoint(bounds.getSouthEast()));
385+
return sizeBounds.getSize();
398386
}
399387
});
400388

0 commit comments

Comments
 (0)