From: Anton Khorev Date: Mon, 7 Apr 2025 12:26:44 +0000 (+0300) Subject: Render changesets at locations closest to map view center X-Git-Tag: live~49^2 X-Git-Url: https://git.openstreetmap.org./rails.git/commitdiff_plain/f11b38709b6cdf6b837d822f4c1e04f06d65ca71?ds=inline;hp=-c Render changesets at locations closest to map view center --- f11b38709b6cdf6b837d822f4c1e04f06d65ca71 diff --git a/app/assets/javascripts/index/history-changesets-layer.js b/app/assets/javascripts/index/history-changesets-layer.js index dc045779c..37a458737 100644 --- a/app/assets/javascripts/index/history-changesets-layer.js +++ b/app/assets/javascripts/index/history-changesets-layer.js @@ -34,6 +34,8 @@ OSM.HistoryChangesetsLayer = L.FeatureGroup.extend({ return b.bounds.getSize() - a.bounds.getSize(); }); + this.updateChangesetLocations(map); + for (const changeset of this._changesets) { const rect = L.rectangle(changeset.bounds, { weight: 2, color: "#FF9500", opacity: 1, fillColor: "#FFFFAF", fillOpacity: 0 }); @@ -42,6 +44,24 @@ OSM.HistoryChangesetsLayer = L.FeatureGroup.extend({ } }, + updateChangesetLocations: function (map) { + const mapCenterLng = map.getCenter().lng; + + for (const changeset of this._changesets) { + const changesetSouthWest = changeset.bounds.getSouthWest(); + const changesetNorthEast = changeset.bounds.getNorthEast(); + const changesetCenterLng = (changesetSouthWest.lng + changesetNorthEast.lng) / 2; + const shiftInWorldCircumferences = Math.round((changesetCenterLng - mapCenterLng) / 360); + + if (shiftInWorldCircumferences) { + changesetSouthWest.lng -= shiftInWorldCircumferences * 360; + changesetNorthEast.lng -= shiftInWorldCircumferences * 360; + + this.getLayer(changeset.id)?.setBounds(changeset.bounds); + } + } + }, + highlightChangeset: function (id) { this.getLayer(id)?.setStyle({ fillOpacity: 0.3, color: "#FF6600", weight: 3 }); }, diff --git a/app/assets/javascripts/index/history.js b/app/assets/javascripts/index/history.js index 3d572b6c7..058777840 100644 --- a/app/assets/javascripts/index/history.js +++ b/app/assets/javascripts/index/history.js @@ -236,6 +236,8 @@ OSM.History = function (map) { if (location.pathname === "/history") { OSM.router.replace("/history" + window.location.hash); loadFirstChangesets(); + } else { + changesetsLayer.updateChangesetsPositions(map); } }