From 9b957048e128ea046cafde691691ae77fa9bfb69 Mon Sep 17 00:00:00 2001 From: Gagan Deep Date: Thu, 23 May 2024 15:38:39 +0530 Subject: [PATCH] [fix] Fixed duplication of points when map bounds are crossed #575 Closes #575 --- .../device/static/monitoring/js/device-map.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/openwisp_monitoring/device/static/monitoring/js/device-map.js b/openwisp_monitoring/device/static/monitoring/js/device-map.js index fcc9d258d..5aeb49b39 100644 --- a/openwisp_monitoring/device/static/monitoring/js/device-map.js +++ b/openwisp_monitoring/device/static/monitoring/js/device-map.js @@ -236,22 +236,35 @@ let bounds = event.target.getBounds(); if (bounds._southWest.lng < -180 && !netjsonGraph.westWorldFeaturesAppended) { let westWorldFeatures = window.structuredClone(netjsonGraph.data); + // Exclude the features that may be added for the East world map + westWorldFeatures.features = westWorldFeatures.features.filter( + element => element.geometry.coordinates[0] <= 180 + ); westWorldFeatures.features.forEach(element => { if (element.geometry) { element.geometry.coordinates[0] -= 360; } }); + // netjsonGraph.utils.appendData call the render method which + // super imposes the data on the existing points on the map. + netjsonGraph.leaflet.geoJSON.removeFrom(netjsonGraph.leaflet); netjsonGraph.utils.appendData(westWorldFeatures, netjsonGraph); netjsonGraph.westWorldFeaturesAppended = true; } if (bounds._northEast.lng > 180 && !netjsonGraph.eastWorldFeaturesAppended) { let eastWorldFeatures = window.structuredClone(netjsonGraph.data); + // Exclude the features that may be added for the West world map + eastWorldFeatures.features = eastWorldFeatures.features.filter( + element => element.geometry.coordinates[0] >= -180 + ); + window.console.log(eastWorldFeatures.features); eastWorldFeatures.features.forEach(element => { if (element.geometry) { element.geometry.coordinates[0] += 360; } }); + netjsonGraph.leaflet.geoJSON.removeFrom(netjsonGraph.leaflet); netjsonGraph.utils.appendData(eastWorldFeatures, netjsonGraph); netjsonGraph.eastWorldFeaturesAppended = true; }