Skip to content

Commit

Permalink
[JavaScript] Remove mainLizmap from Geolocation module
Browse files Browse the repository at this point in the history
  • Loading branch information
rldhont committed Jul 20, 2024
1 parent d369b60 commit b395ae3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
22 changes: 16 additions & 6 deletions assets/src/modules/Geolocation.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,13 @@ import Feature from 'ol/Feature.js';
*/
export default class Geolocation {

constructor() {
/**
* Create a geolocation instance
*
* @param {Map} map - OpenLayers map
* @param {object} lizmap3 - The old lizmap object
*/
constructor(map, lizmap3) {
const color = 'rgb(3, 149, 214)';
const fillColor = 'rgba(3, 149, 214, 0.1)';
const strokeWidth = 1;
Expand All @@ -41,20 +47,22 @@ export default class Geolocation {
name: 'LizmapGeolocationGeolocationDrawLayer'
});

mainLizmap.map.addToolLayer(this._geolocationLayer);
map.addToolLayer(this._geolocationLayer);

this._lizmap3 = lizmap3;
this._firstGeolocation = true;
this._isBind = false;
this._bindIntervalID = 0;
this._bindIntervalInSecond = 10;
this._isLinkedToEdition = false;

const qgisProjectProjection = lizmap3.map.getProjection();
this._geolocation = new olGeolocation({
// `enableHighAccuracy` must be set to true to have the heading value
trackingOptions: {
enableHighAccuracy: true
},
projection: mainLizmap.projection
projection: qgisProjectProjection
});

this._geolocation.on('change:position', () => {
Expand All @@ -66,7 +74,7 @@ export default class Geolocation {

this._geolocation.on('change:tracking', () => {
// FIXME : later we'll need an object listening to 'geolocation.isTracking' event and setting visibility accordingly
const geolocationLayer = mainLizmap._lizmap3.map.getLayersByName('geolocation')[0];
const geolocationLayer = this._lizmap3.map.getLayersByName('geolocation')[0];
if (geolocationLayer) {
geolocationLayer.setVisibility(this.isTracking);
}
Expand Down Expand Up @@ -143,7 +151,8 @@ export default class Geolocation {
return this.position;
} else {
const position = this._geolocation.getPosition();
return transform(position, mainLizmap.projection, crs);
const qgisProjectProjection = this._lizmap3.map.getProjection();
return transform(position, qgisProjectProjection, crs);
}
}

Expand All @@ -155,7 +164,8 @@ export default class Geolocation {
get position() {
const position = this._geolocation.getPosition();
if (position) {
const position4326 = transform(position, mainLizmap.projection, 'EPSG:4326');
const qgisProjectProjection = this._lizmap3.map.getProjection();
const position4326 = transform(position, qgisProjectProjection, 'EPSG:4326');
return [parseFloat(position4326[0].toFixed(6)), parseFloat(position4326[1].toFixed(6))];
}
return undefined;
Expand Down
2 changes: 1 addition & 1 deletion assets/src/modules/Lizmap.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ export default class Lizmap {
this.permalink = new Permalink();
this.map = new map('newOlMap', this.initialConfig, this.serviceURL, this.state.map, this.state.baseLayers, this.state.rootMapGroup, this.lizmap3);
this.edition = new Edition(this.lizmap3);
this.geolocation = new Geolocation();
this.geolocation = new Geolocation(this.map, this.lizmap3);
this.geolocationSurvey = new GeolocationSurvey();
this.selectionTool = new SelectionTool();
this.digitizing = new Digitizing();
Expand Down

0 comments on commit b395ae3

Please sign in to comment.