Skip to content
7 changes: 6 additions & 1 deletion lib/js/echarts-leaflet/LeafletCoordSys.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,12 @@ function createLeafletCoordSystem(echarts, L) {
mapRoot.classList.add("ec-extension-leaflet");
root.appendChild(mapRoot);

leafletModel.__map = L.map(mapRoot, leafletModel.get("mapOptions"));
const userOptions = leafletModel.get("mapOptions") || {};
const defaultOption = {
worldCopyJump: true,
};
const mapOptions = Object.assign({}, defaultOption, userOptions);
leafletModel.__map = L.map(mapRoot, mapOptions);
const map = leafletModel.__map;
const tiles = leafletModel.get("tiles");
const baseLayers = {};
Expand Down
44 changes: 44 additions & 0 deletions test/LeafletCoordSys.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import L from "leaflet";
import createLeafletCoordSystem from "../lib/js/echarts-leaflet/LeafletCoordSys";

describe("LeafletCoordSys", () => {
it("should set worldCopyJump to true by default", () => {
const echartsMock = {
util: {
curry: (fn, method) => fn.bind(null, method),
},
graphic: {
BoundingRect: class {},
},
matrix: {
create: () => [],
},
};
const LeafletCoordSys = createLeafletCoordSystem(echartsMock, L);
const mockModel = {
get: (key) => {
if (key === "mapOptions") return {}; // no user options
if (key === "tiles") return [];
if (key === "layerControl") return {};
return undefined;
},
__map: null,
};
const api = {
getDom: () => document.createElement("div"),
getZr: () => ({
painter: {
getViewportRoot: () => document.createElement("div"),
},
}),
};
const ecModel = {
eachComponent: (type, callback) => {
if (type === "leaflet") callback(mockModel);
},
eachSeries: () => {},
};
LeafletCoordSys.create(ecModel, api);
expect(mockModel.__map.options.worldCopyJump).toBe(true);
});
});
Loading