From: Anton Khorev Date: Fri, 11 Apr 2025 22:57:06 +0000 (+0300) Subject: Store changesets of history changesets layer in map X-Git-Tag: live~18^2~6 X-Git-Url: https://git.openstreetmap.org/rails.git/commitdiff_plain/70de6463d88c5bbfb00b36ce468a527e9ff31764 Store changesets of history changesets layer in map --- 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;