From: Anton Khorev Date: Fri, 11 Apr 2025 23:59:50 +0000 (+0300) Subject: Take viewport intersection into account when sorting changesets X-Git-Tag: live~31^2~1 X-Git-Url: https://git.openstreetmap.org./rails.git/commitdiff_plain/c39d3ea40b240c5332faabbb8c0c6789470b8468?ds=sidebyside;hp=--cc Take viewport intersection into account when sorting changesets --- c39d3ea40b240c5332faabbb8c0c6789470b8468 diff --git a/app/assets/javascripts/index/history-changesets-layer.js b/app/assets/javascripts/index/history-changesets-layer.js index 3f3514c53..eafa2f715 100644 --- a/app/assets/javascripts/index/history-changesets-layer.js +++ b/app/assets/javascripts/index/history-changesets-layer.js @@ -41,8 +41,6 @@ OSM.HistoryChangesetsLayer = L.FeatureGroup.extend({ }, updateChangesetShapes: function (map) { - this.clearLayers(); - 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)), @@ -64,20 +62,8 @@ OSM.HistoryChangesetsLayer = L.FeatureGroup.extend({ map.unproject(topRight)); } - 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.values()) { - delete changeset.isHighlighted; - const rect = L.rectangle(changeset.bounds, this._getChangesetStyle(changeset)); - rect.id = changeset.id; - rect.addTo(this); - } + this.reorderChangesets(); }, updateChangesetLocations: function (map) { @@ -98,6 +84,26 @@ OSM.HistoryChangesetsLayer = L.FeatureGroup.extend({ } }, + reorderChangesets: function () { + const changesetEntries = [...this._changesets]; + changesetEntries.sort(([, a], [, b]) => { + const aInViewport = !a.sidebarRelativePosition; + const bInViewport = !b.sidebarRelativePosition; + if (aInViewport !== bInViewport) return aInViewport - bInViewport; + return b.bounds.getSize() - a.bounds.getSize(); + }); + this._changesets = new Map(changesetEntries); + + this.clearLayers(); + + for (const changeset of this._changesets.values()) { + delete changeset.isHighlighted; + const rect = L.rectangle(changeset.bounds, this._getChangesetStyle(changeset)); + rect.id = changeset.id; + rect.addTo(this); + } + }, + toggleChangesetHighlight: function (id, state) { const changeset = this._changesets.get(id); if (!changeset) return; diff --git a/app/assets/javascripts/index/history.js b/app/assets/javascripts/index/history.js index afa46c460..74b9a4e24 100644 --- a/app/assets/javascripts/index/history.js +++ b/app/assets/javascripts/index/history.js @@ -68,6 +68,8 @@ OSM.History = function (map) { } } + changesetsLayer.reorderChangesets(); + if (keepInitialLocation) { keepInitialLocation = false; return;