]> git.openstreetmap.org Git - rails.git/blobdiff - app/assets/javascripts/index/history-changesets-layer.js
Render changesets at locations closest to map view center
[rails.git] / app / assets / javascripts / index / history-changesets-layer.js
index dc045779c781d4ca4bcb933f92e4f7d49f495f36..37a45873777913cff5172789c743be9396fdc7d0 100644 (file)
@@ -34,6 +34,8 @@ OSM.HistoryChangesetsLayer = L.FeatureGroup.extend({
       return b.bounds.getSize() - a.bounds.getSize();
     });
 
+    this.updateChangesetLocations(map);
+
     for (const changeset of this._changesets) {
       const rect = L.rectangle(changeset.bounds,
                                { weight: 2, color: "#FF9500", opacity: 1, fillColor: "#FFFFAF", fillOpacity: 0 });
@@ -42,6 +44,24 @@ OSM.HistoryChangesetsLayer = L.FeatureGroup.extend({
     }
   },
 
+  updateChangesetLocations: function (map) {
+    const mapCenterLng = map.getCenter().lng;
+
+    for (const changeset of this._changesets) {
+      const changesetSouthWest = changeset.bounds.getSouthWest();
+      const changesetNorthEast = changeset.bounds.getNorthEast();
+      const changesetCenterLng = (changesetSouthWest.lng + changesetNorthEast.lng) / 2;
+      const shiftInWorldCircumferences = Math.round((changesetCenterLng - mapCenterLng) / 360);
+
+      if (shiftInWorldCircumferences) {
+        changesetSouthWest.lng -= shiftInWorldCircumferences * 360;
+        changesetNorthEast.lng -= shiftInWorldCircumferences * 360;
+
+        this.getLayer(changeset.id)?.setBounds(changeset.bounds);
+      }
+    }
+  },
+
   highlightChangeset: function (id) {
     this.getLayer(id)?.setStyle({ fillOpacity: 0.3, color: "#FF6600", weight: 3 });
   },