Skip to content

Commit f74bec5

Browse files
[fix]ICL-1410 review by qiw
1 parent b86936f commit f74bec5

File tree

2 files changed

+51
-9
lines changed

2 files changed

+51
-9
lines changed

src/leaflet/overlay/EChartsLayer.js

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ export const EchartsLayer = L.Layer.extend({
7373
this._ec = echarts.init(this._echartsContainer);
7474
this._ec.leafletMap= map;
7575
const me = this;
76-
7776
map.on("zoomstart", function () {
7877
me._disableEchartsContainer();
7978
});
@@ -114,15 +113,12 @@ export const EchartsLayer = L.Layer.extend({
114113
const coordSys = LeafletMapModel.coordinateSystem;
115114

116115
const ecLayers = api.getZr().painter.getLayers();
117-
116+
_setCanvasPosition(me._map, viewportRoot);
118117
const moveHandler = function () {
119118
if (rendering) {
120119
return;
121120
}
122-
const offset = me._map.containerPointToLayerPoint([0, 0]);
123-
const mapOffset = [offset.x || 0, offset.y || 0];
124-
viewportRoot.style.left = mapOffset[0] + 'px';
125-
viewportRoot.style.top = mapOffset[1] + 'px';
121+
const mapOffset = _setCanvasPosition(me._map, viewportRoot);
126122

127123
if (!me.options.loadWhileAnimating) {
128124
for (let item in ecLayers) {
@@ -209,7 +205,6 @@ export const EchartsLayer = L.Layer.extend({
209205
_div.style.width = size.x + 'px';
210206
_div.style.zIndex = 10;
211207
this._echartsContainer = _div;
212-
213208
this.getPane().appendChild(this._echartsContainer);
214209
const me = this;
215210

@@ -235,7 +230,7 @@ export const EchartsLayer = L.Layer.extend({
235230
export function LeafletMapCoordSys(leafletMap) {
236231
this._LeafletMap = leafletMap;
237232
this.dimensions = ['lng', 'lat'];
238-
this._mapOffset = [0, 0];
233+
this._mapOffset = _getMapOffset(leafletMap);
239234
}
240235

241236
LeafletMapCoordSys.prototype.dimensions = ['lng', 'lat'];
@@ -330,7 +325,7 @@ LeafletMapCoordSys.create = function (ecModel) {
330325
coordSys = new LeafletMapCoordSys(leafletMap);
331326
}
332327
leafletMapModel.coordinateSystem = coordSys;
333-
leafletMapModel.coordinateSystem.setMapOffset(leafletMapModel.__mapOffset || [0, 0]);
328+
leafletMapModel.coordinateSystem.setMapOffset(leafletMapModel.__mapOffset || _getMapOffset(leafletMap));
334329
});
335330
ecModel.eachSeries(function (seriesModel) {
336331
if (!seriesModel.get('coordinateSystem') || seriesModel.get('coordinateSystem') === 'leaflet') {
@@ -342,6 +337,19 @@ LeafletMapCoordSys.create = function (ecModel) {
342337
}
343338
})
344339
};
340+
341+
function _getMapOffset(map) {
342+
const offset = map.containerPointToLayerPoint([0, 0]);
343+
const mapOffset = [offset.x || 0, offset.y || 0];
344+
return mapOffset;
345+
}
346+
347+
function _setCanvasPosition(map, viewportRoot) {
348+
const mapOffset = _getMapOffset(map);
349+
viewportRoot.style.left = mapOffset[0] + 'px';
350+
viewportRoot.style.top = mapOffset[1] + 'px';
351+
return mapOffset;
352+
}
345353
export const echartsLayer = function (echartsOptions, options) {
346354
return new EchartsLayer(echartsOptions, options);
347355
};

test/leaflet/overlay/EchartsLayerSpec.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,4 +337,38 @@ describe('leaflet_EChartsLayer', () => {
337337
};
338338
}, 0)
339339
});
340+
341+
it('canvas top left', (done) => {
342+
debugger;
343+
var data = [
344+
{
345+
value: [104.006244, 30.677465]
346+
},
347+
{
348+
value: [104.041946, 30.689538]
349+
},
350+
{
351+
value: [104.002589, 30.64683]
352+
}
353+
];
354+
var option = {
355+
series: [
356+
{
357+
type: 'effectScatter',
358+
coordinateSystem: 'leaflet',
359+
data: data,
360+
symbolSize: 30
361+
}
362+
]
363+
};
364+
var echartsMapLayer = echartsLayer(option).addTo(map);
365+
const layer = document.getElementsByClassName('echarts-layer')[0];
366+
const panel = document.getElementsByClassName('leaflet-map-pane')[0];
367+
expect(echartsMapLayer).not.toBeNull();
368+
expect(layer.style.left).toBe('0px');
369+
expect(layer.style.top).toBe('0px');
370+
expect(panel.style.transform).toBe('translate3d(0px, 0px, 0px)');
371+
debugger;
372+
done();
373+
});
340374
});

0 commit comments

Comments
 (0)