From cada30700c4b0a0178366cf131f798d4e09c31e4 Mon Sep 17 00:00:00 2001 From: neo Date: Mon, 2 Dec 2024 12:37:24 +0100 Subject: [PATCH] UPDATE: Remove mainLizmap dependencies --- assets/src/modules/Geolocation.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/assets/src/modules/Geolocation.js b/assets/src/modules/Geolocation.js index 72d4d2e82f..f86c6e85f8 100644 --- a/assets/src/modules/Geolocation.js +++ b/assets/src/modules/Geolocation.js @@ -4,7 +4,7 @@ * @copyright 2023 3Liz * @license MPL-2.0 */ -import { mainLizmap, mainEventDispatcher } from '../modules/Globals.js'; +import { mainEventDispatcher } from '../modules/Globals.js'; import olGeolocation from 'ol/Geolocation.js'; import { transform } from 'ol/proj.js'; import { Vector as VectorSource } from 'ol/source.js'; @@ -50,6 +50,7 @@ export default class Geolocation { map.addToolLayer(this._geolocationLayer); this._lizmap3 = lizmap3; + this._map = map; this._firstGeolocation = true; this._isBind = false; this._bindIntervalID = 0; @@ -97,7 +98,8 @@ export default class Geolocation { this._geolocation.on('change:accuracyGeometry', () => { // Zoom on accuracy geometry extent when geolocation is activated for the first time if (this._firstGeolocation) { - mainLizmap.extent = this._geolocation.getAccuracyGeometry().getExtent(); + const bounds = this._geolocation.getAccuracyGeometry().getExtent(); + map.getView().fit(bounds, {nearest: true}); this.center(); this._firstGeolocation = false; @@ -107,12 +109,13 @@ export default class Geolocation { // Handle geolocation error this._geolocation.on('error', error => { - mainLizmap.displayMessage(error.message, 'danger', true); + this._lizmap3.addMessage(error.message, 'danger', true); }); } center() { - mainLizmap.center = this._geolocation.getPosition(); + const center = this._geolocation.getPosition(); + this._map.getView().setCenter(center); } toggleBind() {