From 99fa539413cb159db90a2cc779df30cd936cbe5d Mon Sep 17 00:00:00 2001 From: Pierre Ecarlat <pecarlat@grandlyon.com> Date: Tue, 20 Aug 2024 14:39:09 +0200 Subject: [PATCH] Fixed flyTo when map is hidden --- src/app/map/components/map.component.ts | 19 +++++++++++++------ src/assets/scss/_z-index.scss | 4 ++-- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/src/app/map/components/map.component.ts b/src/app/map/components/map.component.ts index acbb68a1e..4081dd2f6 100644 --- a/src/app/map/components/map.component.ts +++ b/src/app/map/components/map.component.ts @@ -25,6 +25,8 @@ export class MapComponent implements OnChanges { @Input() public searchedValue: string | [number, number]; @Output() public selectedStructure: EventEmitter<Structure> = new EventEmitter<Structure>(); @Output() public clickOrientationButton: EventEmitter<Structure> = new EventEmitter<Structure>(); + + private readonly maxMobileViewWidth = 980; private currentStructure: Structure; public map: Map; @@ -69,10 +71,8 @@ export class MapComponent implements OnChanges { if (changes.structures) { const previousStructures = changes.structures.previousValue; - this.handleStructurePosition(previousStructures); } - this.handleMapMarkerTooltip(changes); this.handleSelectedMapMarker(changes); this.handlePrintableMarkers(); @@ -322,11 +322,18 @@ export class MapComponent implements OnChanges { }); } + private get isMobileView(): boolean { + return window.innerWidth <= this.maxMobileViewWidth; + } + private centerLeafletMapOnMarker(markerId: string): void { - if (this.mapService.getMarker(markerId)) { - const marker = this.mapService.getMarker(markerId); - const latLngs = marker.getLatLng(); - this.map.flyTo(new L.LatLng(latLngs.lat, latLngs.lng), ZoomLevel.max, this.zoomOptions); + // If map isn't showed, we shouldn't fly + if (this.isMobileView && !this.isMapPhone) return; + + const marker = this.mapService.getMarker(markerId); + if (marker) { + const latLng = marker.getLatLng(); + this.map.flyTo(new L.LatLng(latLng.lat, latLng.lng), ZoomLevel.max, this.zoomOptions); } } diff --git a/src/assets/scss/_z-index.scss b/src/assets/scss/_z-index.scss index 8ae3095ba..ce2f494f4 100644 --- a/src/assets/scss/_z-index.scss +++ b/src/assets/scss/_z-index.scss @@ -1,10 +1,10 @@ $map-selected-marker: 600; // Phone view -$btn-phone-switch-map-list-z-index: 1002; +$btn-phone-switch-map-list-z-index: 1001; $menu-phone-z-index: 1003; // Structure details -$structure-details-z-index: 1001; +$structure-details-z-index: 1002; $header-z-index: 1200; // Modals (filters/confirmationPopup/authen/...) -- GitLab