]> git.openstreetmap.org Git - rails.git/commitdiff
Take viewport intersection into account when sorting changesets
authorAnton Khorev <tony29@yandex.ru>
Fri, 11 Apr 2025 23:59:50 +0000 (02:59 +0300)
committerAnton Khorev <tony29@yandex.ru>
Mon, 14 Apr 2025 14:39:18 +0000 (17:39 +0300)
app/assets/javascripts/index/history-changesets-layer.js
app/assets/javascripts/index/history.js

index 3f3514c538d3c15e2dedea18377e344085ea90e3..eafa2f71502bdeb63612a4488ae032bdfb753aec 100644 (file)
@@ -41,8 +41,6 @@ OSM.HistoryChangesetsLayer = L.FeatureGroup.extend({
   },
 
   updateChangesetShapes: function (map) {
   },
 
   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)),
     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));
     }
 
                                         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);
     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) {
   },
 
   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;
   toggleChangesetHighlight: function (id, state) {
     const changeset = this._changesets.get(id);
     if (!changeset) return;
index afa46c460530badae9c0027c1c18ce6909090865..74b9a4e248b53288f71beeca225936659a45f934 100644 (file)
@@ -68,6 +68,8 @@ OSM.History = function (map) {
         }
       }
 
         }
       }
 
+      changesetsLayer.reorderChangesets();
+
       if (keepInitialLocation) {
         keepInitialLocation = false;
         return;
       if (keepInitialLocation) {
         keepInitialLocation = false;
         return;