From 70de6463d88c5bbfb00b36ce468a527e9ff31764 Mon Sep 17 00:00:00 2001 From: Anton Khorev Date: Sat, 12 Apr 2025 01:57:06 +0300 Subject: [PATCH] Store changesets of history changesets layer in map --- .../javascripts/index/history-changesets-layer.js | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/app/assets/javascripts/index/history-changesets-layer.js b/app/assets/javascripts/index/history-changesets-layer.js index 37a458737..e8ba99ddd 100644 --- a/app/assets/javascripts/index/history-changesets-layer.js +++ b/app/assets/javascripts/index/history-changesets-layer.js @@ -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; -- 2.39.5