Skip to content

Commit 9b95704

Browse files
committed
[fix] Fixed duplication of points when map bounds are crossed #575
Closes #575
1 parent 323a9bb commit 9b95704

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

openwisp_monitoring/device/static/monitoring/js/device-map.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,22 +236,35 @@
236236
let bounds = event.target.getBounds();
237237
if (bounds._southWest.lng < -180 && !netjsonGraph.westWorldFeaturesAppended) {
238238
let westWorldFeatures = window.structuredClone(netjsonGraph.data);
239+
// Exclude the features that may be added for the East world map
240+
westWorldFeatures.features = westWorldFeatures.features.filter(
241+
element => element.geometry.coordinates[0] <= 180
242+
);
239243
westWorldFeatures.features.forEach(element => {
240244
if (element.geometry) {
241245
element.geometry.coordinates[0] -= 360;
242246
}
243247
});
248+
// netjsonGraph.utils.appendData call the render method which
249+
// super imposes the data on the existing points on the map.
250+
netjsonGraph.leaflet.geoJSON.removeFrom(netjsonGraph.leaflet);
244251
netjsonGraph.utils.appendData(westWorldFeatures, netjsonGraph);
245252
netjsonGraph.westWorldFeaturesAppended = true;
246253

247254
}
248255
if (bounds._northEast.lng > 180 && !netjsonGraph.eastWorldFeaturesAppended) {
249256
let eastWorldFeatures = window.structuredClone(netjsonGraph.data);
257+
// Exclude the features that may be added for the West world map
258+
eastWorldFeatures.features = eastWorldFeatures.features.filter(
259+
element => element.geometry.coordinates[0] >= -180
260+
);
261+
window.console.log(eastWorldFeatures.features);
250262
eastWorldFeatures.features.forEach(element => {
251263
if (element.geometry) {
252264
element.geometry.coordinates[0] += 360;
253265
}
254266
});
267+
netjsonGraph.leaflet.geoJSON.removeFrom(netjsonGraph.leaflet);
255268
netjsonGraph.utils.appendData(eastWorldFeatures, netjsonGraph);
256269
netjsonGraph.eastWorldFeaturesAppended = true;
257270
}

0 commit comments

Comments
 (0)