From 8863446c39ac6d3f218837c1c2123b3a8642853f Mon Sep 17 00:00:00 2001 From: divyanshu_Kumar <154233802+d1vyanshu-kumar@users.noreply.github.com> Date: Sat, 6 Apr 2024 04:31:11 +0530 Subject: [PATCH 1/2] [fix] Reduce max zoom level to prevent unintended behavior due to excessive zooming #188 Related to #188 --- lib/js/echarts-leaflet/LeafletModel.js | 7 ++++++- src/js/netjsongraph.config.js | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/js/echarts-leaflet/LeafletModel.js b/lib/js/echarts-leaflet/LeafletModel.js index 8c7970c7..ce4baea1 100644 --- a/lib/js/echarts-leaflet/LeafletModel.js +++ b/lib/js/echarts-leaflet/LeafletModel.js @@ -23,6 +23,7 @@ export default function extendLeafletModel(echarts) { }, setCenterAndZoom(center, zoom) { + this.option.center = center; this.option.zoom = zoom; }, @@ -33,7 +34,10 @@ export default function extendLeafletModel(echarts) { }, defaultOption: { - mapOptions: {}, + mapOptions: { + zoomDelta: 0.25, // Set zoom sensitivity + zoomSnap: 0.19 // Disable zoom snapping + }, tiles: [ { urlTemplate: "http://{s}.tile.osm.org/{z}/{x}/{y}.png", @@ -44,6 +48,7 @@ export default function extendLeafletModel(echarts) { }, ], layerControl: {}, + }, }); } diff --git a/src/js/netjsongraph.config.js b/src/js/netjsongraph.config.js index dbde0ce6..4b80f2f4 100644 --- a/src/js/netjsongraph.config.js +++ b/src/js/netjsongraph.config.js @@ -238,7 +238,7 @@ const NetJSONGraphDefaultConfig = { "http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png", options: { minZoom: 3, - maxZoom: 32, + maxZoom: 15, attribution: `© OpenStreetMap contributors, tiles offered by Mapbox`, }, From 3e942e14f8531bb461ca4ee64aa3f0c39c824ccb Mon Sep 17 00:00:00 2001 From: divyanshu_Kumar <154233802+d1vyanshu-kumar@users.noreply.github.com> Date: Fri, 19 Apr 2024 18:44:34 +0530 Subject: [PATCH 2/2] [fix] Reduce max zoom level to prevent unintended behavior due to excessive zooming #188 Related to #188 --- lib/js/echarts-leaflet/LeafletCoordSys.js | 16 +++++++++++----- lib/js/echarts-leaflet/LeafletModel.js | 19 +++++++++++++++++-- 2 files changed, 28 insertions(+), 7 deletions(-) diff --git a/lib/js/echarts-leaflet/LeafletCoordSys.js b/lib/js/echarts-leaflet/LeafletCoordSys.js index f4b11cac..83a44ef2 100644 --- a/lib/js/echarts-leaflet/LeafletCoordSys.js +++ b/lib/js/echarts-leaflet/LeafletCoordSys.js @@ -7,8 +7,8 @@ * * @return {function} LeafletCoordSys */ -function createLeafletCoordSystem(echarts, L) { - const {util, graphic, matrix} = echarts; +function createLeafletCoordSystem(echarts, L, defaultconfig = {}) { + const { util, graphic, matrix } = echarts; const CustomOverlay = L.Layer.extend({ initialize(container) { this._container = container; @@ -53,10 +53,12 @@ function createLeafletCoordSystem(echarts, L) { this._mapOffset = [0, 0]; this._api = api; this._projection = L.Projection.Mercator; + const maxZoom = defaultconfig.maxZoom || 15; // Set default max zoom level + this._maxZoom = maxZoom; } function doConvert(methodName, ecModel, finder, value) { - const {leafletModel, seriesModel} = finder; + const { leafletModel, seriesModel } = finder; /* eslint-disable */ const coordSys = leafletModel @@ -65,7 +67,7 @@ function createLeafletCoordSystem(echarts, L) { ? seriesModel.coordinateSystem || // For map. (seriesModel.getReferringComponents("leaflet")[0] || {}) .coordinateSystem - : null; + : null; return coordSys === this ? coordSys[methodName](value) : null; /* eslint-enable */ } @@ -76,6 +78,10 @@ function createLeafletCoordSystem(echarts, L) { LeafletCoordSys.prototype.dimensions = ["lng", "lat"]; LeafletCoordSys.prototype.setZoom = function (zoom) { + const maxZoom = this._maxZoom; + if (zoom > maxZoom) { + zoom = maxZoom; + } this._zoom = zoom; }; @@ -198,7 +204,7 @@ function createLeafletCoordSystem(echarts, L) { leafletCoordSys = new LeafletCoordSys(map, api); leafletList.push(leafletCoordSys); leafletCoordSys.setMapOffset(leafletModel.__mapOffset || [0, 0]); - const {center, zoom} = leafletModel.get("mapOptions"); + const { center, zoom } = leafletModel.get("mapOptions"); if (center && zoom) { leafletCoordSys.setZoom(zoom); leafletCoordSys.setCenter(center); diff --git a/lib/js/echarts-leaflet/LeafletModel.js b/lib/js/echarts-leaflet/LeafletModel.js index ce4baea1..a0c1bc07 100644 --- a/lib/js/echarts-leaflet/LeafletModel.js +++ b/lib/js/echarts-leaflet/LeafletModel.js @@ -23,6 +23,14 @@ export default function extendLeafletModel(echarts) { }, setCenterAndZoom(center, zoom) { + // Limit zoom level before setting + const maxZoom = this.option.mapOptions.maxZoom || this.getMaxZoom(); + zoom = Math.min(zoom, maxZoom); + // If a zoom control exists, adjust its options + const map = this.getLeaflet(); + if (map.zoomControl) { + map.zoomControl.options.maxZoom = maxZoom; + } this.option.center = center; this.option.zoom = zoom; @@ -36,7 +44,8 @@ export default function extendLeafletModel(echarts) { defaultOption: { mapOptions: { zoomDelta: 0.25, // Set zoom sensitivity - zoomSnap: 0.19 // Disable zoom snapping + zoomSnap: 0.19, // Disable zoom snapping + maxZoom: 15 }, tiles: [ { @@ -48,7 +57,13 @@ export default function extendLeafletModel(echarts) { }, ], layerControl: {}, - + }, + /** + * Get the maximum supported zoom level + * @return {number} + */ + getMaxZoom() { + return this.option.maxZoom; }, }); }