Skip to content

Commit 0a187a3

Browse files
committed
【fix】修复leaflet 高性能点图层webgl渲染时地图为WGS84时偏移的问题 review by luoxiao
1 parent 7d1c664 commit 0a187a3

File tree

3 files changed

+29
-3
lines changed

3 files changed

+29
-3
lines changed

src/leaflet/overlay/GraphicLayer.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ export var GraphicLayer = L.Path.extend({
7979
*/
8080
onAdd: function (map) {
8181
this._map = map;
82+
this._crs = map.options.crs;
8283
this.defaultStyle = this._getDefaultStyle(this.options);
8384
this._renderer = this._createRenderer();
8485
this._container = this._renderer._container;
@@ -274,8 +275,9 @@ export var GraphicLayer = L.Path.extend({
274275
let center = map.getCenter();
275276
let longitude = center.lng;
276277
let latitude = center.lat;
277-
let zoom = map.getZoom();
278-
let maxZoom = map.getMaxZoom();
278+
const zoomOffset = this._crs.code === "EPSG:4326"?1:0;
279+
let zoom = map.getZoom()+zoomOffset;
280+
let maxZoom = map.getMaxZoom()+zoomOffset;
279281

280282
let mapViewport = {
281283
longitude: longitude,

src/leaflet/overlay/graphic/WebGLRenderer.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,8 @@ export var GraphicWebGLRenderer = L.Class.extend({
169169
radiusMinPixels: radiusMinPixels,
170170
radiusMaxPixels: radiusMaxPixels,
171171
strokeWidth: strokeWidth,
172+
coordinateSystem:this._isWGS84()?window.DeckGL.COORDINATE_SYSTEM.LNGLAT_OFFSETS:window.DeckGL.COORDINATE_SYSTEM.LNGLAT,
173+
isGeographicCoordinateSystem: this._isWGS84(),
172174
outline: outline,
173175
getPosition: function (point) {
174176
if (!point) {
@@ -258,6 +260,8 @@ export var GraphicWebGLRenderer = L.Class.extend({
258260
deckOptions.canvas = this._container;
259261
deckOptions.onBeforeRender = this._onBeforeRender.bind(this);
260262
deckOptions.onAfterRender = this._onAfterRender.bind(this);
263+
deckOptions.coordinateSystem = this._isWGS84()? window.DeckGL.COORDINATE_SYSTEM.LNGLAT_OFFSETS:window.DeckGL.COORDINATE_SYSTEM.LNGLAT;
264+
deckOptions.isGeographicCoordinateSystem = this._isWGS84();
261265
if (!this.deckGL) {
262266
this.deckGL = new window.DeckGL.experimental.DeckGLJS(deckOptions);
263267
} else {
@@ -304,6 +308,9 @@ export var GraphicWebGLRenderer = L.Class.extend({
304308
},
305309
_initPath: emptyFunc,
306310
_addPath: emptyFunc,
307-
containsPoint: emptyFunc
311+
containsPoint: emptyFunc,
312+
_isWGS84(){
313+
return this.layer._map.options.crs.code === "EPSG:4326";
314+
}
308315

309316
});

test/leaflet/overlay/GraphicLayerSpec.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,5 +329,22 @@ describe('leaflet_GraphicLayer', () => {
329329
map.remove();
330330
window.document.body.removeChild(testDiv);
331331
});
332+
it('CRS_4326_ICL_1042', (done) => {
333+
let { map, testDiv } = createMap();
334+
let layer = graphicLayer(graphics, { render: 'webgl' }).addTo(map);
335+
setTimeout(() => {
336+
expect(layer._crs).toEqual(map.options.crs);
337+
const state = layer.getState();
338+
expect(state.maxZoom).toEqual(map.getMaxZoom()+1);
339+
expect(state.zoom).toEqual(map.getZoom()+1);
340+
const webglRenderLayer = layer._renderer._renderLayer;
341+
expect(webglRenderLayer).not.toBeNull();
342+
expect(webglRenderLayer.props.coordinateSystem).toEqual(window.DeckGL.COORDINATE_SYSTEM.LNGLAT_OFFSETS);
343+
expect(webglRenderLayer.props.isGeographicCoordinateSystem).toBeTrue();
344+
map.remove();
345+
window.document.body.removeChild(testDiv);
346+
done();
347+
}, 4000);
348+
});
332349
});
333350
});

0 commit comments

Comments
 (0)