]> git.openstreetmap.org Git - rails.git/commitdiff
Store changesets of history changesets layer in map
authorAnton Khorev <tony29@yandex.ru>
Fri, 11 Apr 2025 22:57:06 +0000 (01:57 +0300)
committerAnton Khorev <tony29@yandex.ru>
Sun, 13 Apr 2025 15:38:13 +0000 (18:38 +0300)
app/assets/javascripts/index/history-changesets-layer.js

index 37a45873777913cff5172789c743be9396fdc7d0..e8ba99dddcac0d3cf8748a476f32f70ebc2edb15 100644 (file)
@@ -1,15 +1,15 @@
 OSM.HistoryChangesetsLayer = L.FeatureGroup.extend({
-  _changesets: [],
+  _changesets: new Map,
 
   updateChangesets: function (map, changesets) {
-    this._changesets = changesets;
+    this._changesets = new Map(changesets.map(changeset => [changeset.id, changeset]));
     this.updateChangesetShapes(map);
   },
 
   updateChangesetShapes: function (map) {
     this.clearLayers();
 
-    for (const changeset of this._changesets) {
+    for (const changeset of this._changesets.values()) {
       const bottomLeft = map.project(L.latLng(changeset.bbox.minlat, changeset.bbox.minlon)),
             topRight = map.project(L.latLng(changeset.bbox.maxlat, changeset.bbox.maxlon)),
             width = topRight.x - bottomLeft.x,
@@ -30,13 +30,15 @@ OSM.HistoryChangesetsLayer = L.FeatureGroup.extend({
                                         map.unproject(topRight));
     }
 
-    this._changesets.sort(function (a, b) {
+    const changesetEntries = [...this._changesets];
+    changesetEntries.sort(([, a], [, b]) => {
       return b.bounds.getSize() - a.bounds.getSize();
     });
+    this._changesets = new Map(changesetEntries);
 
     this.updateChangesetLocations(map);
 
-    for (const changeset of this._changesets) {
+    for (const changeset of this._changesets.values()) {
       const rect = L.rectangle(changeset.bounds,
                                { weight: 2, color: "#FF9500", opacity: 1, fillColor: "#FFFFAF", fillOpacity: 0 });
       rect.id = changeset.id;
@@ -47,7 +49,7 @@ OSM.HistoryChangesetsLayer = L.FeatureGroup.extend({
   updateChangesetLocations: function (map) {
     const mapCenterLng = map.getCenter().lng;
 
-    for (const changeset of this._changesets) {
+    for (const changeset of this._changesets.values()) {
       const changesetSouthWest = changeset.bounds.getSouthWest();
       const changesetNorthEast = changeset.bounds.getNorthEast();
       const changesetCenterLng = (changesetSouthWest.lng + changesetNorthEast.lng) / 2;