Skip to content

Commit

Permalink
Change leaflet refresh method to apply the zoom in the same method wh…
Browse files Browse the repository at this point in the history
…ere the center is applied; (#175)
  • Loading branch information
JoaoFerreira-FrontEnd authored Jun 21, 2024
1 parent cf4e934 commit 877864b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/OSFramework/Maps/Feature/ICenter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
20 changes: 19 additions & 1 deletion src/Providers/Maps/Leaflet/Features/Center.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
9 changes: 2 additions & 7 deletions src/Providers/Maps/Leaflet/OSMap/OSMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 877864b

Please sign in to comment.