Skip to content

Commit

Permalink
[fix] Fixed duplication of points when map bounds are crossed #575
Browse files Browse the repository at this point in the history
Closes #575
  • Loading branch information
pandafy committed May 23, 2024
1 parent 323a9bb commit 42698dc
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions openwisp_monitoring/device/static/monitoring/js/device-map.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 42698dc

Please sign in to comment.