From 877864bbab53baa9b85b31cfe34ca54a4d6ea515 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Ferreira?= <60441552+JoaoFerreira-FrontEnd@users.noreply.github.com> Date: Fri, 21 Jun 2024 11:22:48 +0100 Subject: [PATCH] Change leaflet refresh method to apply the zoom in the same method where the center is applied; (#175) --- src/OSFramework/Maps/Feature/ICenter.ts | 2 +- src/Providers/Maps/Leaflet/Features/Center.ts | 20 ++++++++++++++++++- src/Providers/Maps/Leaflet/OSMap/OSMap.ts | 9 ++------- 3 files changed, 22 insertions(+), 9 deletions(-) diff --git a/src/OSFramework/Maps/Feature/ICenter.ts b/src/OSFramework/Maps/Feature/ICenter.ts index e8d6bec7..6505872b 100644 --- a/src/OSFramework/Maps/Feature/ICenter.ts +++ b/src/OSFramework/Maps/Feature/ICenter.ts @@ -12,7 +12,7 @@ namespace OSFramework.Maps.Feature { /** Refreshes the Current Center position of the Map * Changes whenever a marker is added or by enabling the Autofit on Zoom feature */ - refreshCenter(value: OSFramework.Maps.OSStructures.OSMap.Coordinates): void; + refreshCenter(value: OSFramework.Maps.OSStructures.OSMap.Coordinates, allowRefreshZoom?: boolean): void; /** Set Current center position of the Map */ setCurrentCenter(value: OSFramework.Maps.OSStructures.OSMap.Coordinates): void; /** Sets or updates the initial center position of the Map. diff --git a/src/Providers/Maps/Leaflet/Features/Center.ts b/src/Providers/Maps/Leaflet/Features/Center.ts index 2eaad53d..a3e635aa 100644 --- a/src/Providers/Maps/Leaflet/Features/Center.ts +++ b/src/Providers/Maps/Leaflet/Features/Center.ts @@ -52,9 +52,27 @@ namespace Provider.Maps.Leaflet.Feature { return responseObj; } - public refreshCenter(value: OSFramework.Maps.OSStructures.OSMap.Coordinates): void { + public refreshCenter(value: OSFramework.Maps.OSStructures.OSMap.Coordinates, allowRefreshZoom: boolean): void { const coordinates = new L.LatLng(value.lat as number, value.lng as number); this._map.provider.setView(coordinates); + if (allowRefreshZoom) { + if (this._map.features.zoom.isAutofit) { + if ( + this._map.markers.length > 1 || + (this._map.shapes.length > 0 && this._map.config.autoZoomOnShapes === true) + ) { + this._map.provider.setView(coordinates); + this._map.features.zoom.refreshZoom(); + } else { + this._map.provider.setView(coordinates, OSFramework.Maps.Helper.Constants.zoomAutofit); + } + } else { + this._map.provider.setView(coordinates, this._map.features.zoom.level); + } + } else { + this._map.provider.setView(coordinates); + } + this._currentCenter = coordinates; } diff --git a/src/Providers/Maps/Leaflet/OSMap/OSMap.ts b/src/Providers/Maps/Leaflet/OSMap/OSMap.ts index 6e84d003..65767d4f 100644 --- a/src/Providers/Maps/Leaflet/OSMap/OSMap.ts +++ b/src/Providers/Maps/Leaflet/OSMap/OSMap.ts @@ -290,13 +290,8 @@ namespace Provider.Maps.Leaflet.OSMap { } } - // Refresh the center position - this.features.center.refreshCenter(position); - - if (this.allowRefreshZoom) { - // Refresh the zoom - this.features.zoom.refreshZoom(); - } + // Refresh the center position and zoom if needed + this.features.center.refreshCenter(position, this.allowRefreshZoom); // Refresh the offset this.features.offset.setOffset(this.features.offset.getOffset);