Skip to content

Commit

Permalink
UPDATE: Remove mainLizmap dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
neo-garaix committed Dec 2, 2024
1 parent 7d912dc commit c80aa92
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions assets/src/modules/Geolocation.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand All @@ -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() {
Expand Down

0 comments on commit c80aa92

Please sign in to comment.