From edff867ea3fe7ec94a1322d688094e4127040bf6 Mon Sep 17 00:00:00 2001 From: Anton Khorev Date: Mon, 5 May 2025 13:00:09 +0300 Subject: [PATCH] Merge updateChangesetLocations into updateChangesetsGeometry --- .../index/history-changesets-layer.js | 43 ++++++++----------- 1 file changed, 17 insertions(+), 26 deletions(-) diff --git a/app/assets/javascripts/index/history-changesets-layer.js b/app/assets/javascripts/index/history-changesets-layer.js index b2849a66d..c6744d468 100644 --- a/app/assets/javascripts/index/history-changesets-layer.js +++ b/app/assets/javascripts/index/history-changesets-layer.js @@ -89,12 +89,25 @@ OSM.HistoryChangesetsLayer = L.FeatureGroup.extend({ }, updateChangesetsGeometry: function (map) { + const changesetSizeLowerBound = 20; // Min width/height of changeset in pixels + + const mapViewCenterLng = map.getCenter().lng; + for (const changeset of this._changesets.values()) { - const changesetMinCorner = map.project(L.latLng(changeset.bbox.maxlat, changeset.bbox.minlon)), - changesetMaxCorner = map.project(L.latLng(changeset.bbox.minlat, changeset.bbox.maxlon)), + const changesetNorthWestLatLng = L.latLng(changeset.bbox.maxlat, changeset.bbox.minlon), + changesetSouthEastLatLng = L.latLng(changeset.bbox.minlat, changeset.bbox.maxlon), + changesetCenterLng = (changesetNorthWestLatLng.lng + changesetSouthEastLatLng.lng) / 2, + shiftInWorldCircumferences = Math.round((changesetCenterLng - mapViewCenterLng) / 360); + + if (shiftInWorldCircumferences) { + changesetNorthWestLatLng.lng -= shiftInWorldCircumferences * 360; + changesetSouthEastLatLng.lng -= shiftInWorldCircumferences * 360; + } + + const changesetMinCorner = map.project(changesetNorthWestLatLng), + changesetMaxCorner = map.project(changesetSouthEastLatLng), changesetSizeX = changesetMaxCorner.x - changesetMinCorner.x, - changesetSizeY = changesetMaxCorner.y - changesetMinCorner.y, - changesetSizeLowerBound = 20; // Min width/height of changeset in pixels + changesetSizeY = changesetMaxCorner.y - changesetMinCorner.y; if (changesetSizeX < changesetSizeLowerBound) { changesetMinCorner.x -= (changesetSizeLowerBound - changesetSizeX) / 2; @@ -110,31 +123,9 @@ OSM.HistoryChangesetsLayer = L.FeatureGroup.extend({ map.unproject(changesetMaxCorner)); } - this._updateChangesetLocations(map); this.updateChangesetsOrder(); }, - _updateChangesetLocations: function (map) { - const mapViewCenterLng = map.getCenter().lng; - - for (const changeset of this._changesets.values()) { - const changesetNorthWestLatLng = changeset.bounds.getNorthWest(); - const changesetSouthEastLatLng = changeset.bounds.getSouthEast(); - const changesetCenterLng = (changesetNorthWestLatLng.lng + changesetSouthEastLatLng.lng) / 2; - const shiftInWorldCircumferences = Math.round((changesetCenterLng - mapViewCenterLng) / 360); - - if (shiftInWorldCircumferences) { - changesetNorthWestLatLng.lng -= shiftInWorldCircumferences * 360; - changesetSouthEastLatLng.lng -= shiftInWorldCircumferences * 360; - changeset.bounds = L.latLngBounds(changesetNorthWestLatLng, changesetSouthEastLatLng); - - for (const layer of this._bboxLayers) { - layer.updateChangesetLayerBounds(changeset); - } - } - } - }, - updateChangesetsOrder: function () { const changesetEntries = [...this._changesets]; changesetEntries.sort(([, a], [, b]) => b.bounds.getSize() - a.bounds.getSize()); -- 2.39.5