Skip to content

Commit

Permalink
[JavaScript] Remove mainLizmap from GeolocationSurvey module
Browse files Browse the repository at this point in the history
  • Loading branch information
rldhont committed Jul 31, 2024
1 parent 3158829 commit b50b4ef
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 11 deletions.
30 changes: 20 additions & 10 deletions assets/src/modules/GeolocationSurvey.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
*/

import {mainLizmap, mainEventDispatcher} from '../modules/Globals.js';
import Edition from './Edition.js';
import Geolocation from './Geolocation.js';
import {transform} from 'ol/proj.js';

/**
Expand All @@ -14,12 +16,20 @@ import {transform} from 'ol/proj.js';
*/
export default class GeolocationSurvey {

constructor() {
/**
* Create a geolocation survey instance
*
* @param {Geolocation} geolocation - The Lizmap geolocation instance
* @param {Edition} edition - The Lizmap edition instance
*/
constructor(geolocation, edition) {

this.distanceLimit = 0;
this.timeLimit = 0;
this.accuracyLimit = 0;
this.averageRecordLimit = 0;
this._geolocation = geolocation;
this._edition = edition;
this._distanceMode = false;
this._timeMode = false;
this._timePauseMode = false;
Expand All @@ -37,13 +47,13 @@ export default class GeolocationSurvey {

// Private method to insert a point at current or average position
_insertPoint() {
if (mainLizmap.geolocation.isTracking && (!this.accuracyMode || (mainLizmap.geolocation.accuracy <= this.accuracyLimit))) {
if (this._geolocation.isTracking && (!this.accuracyMode || (this._geolocation.accuracy <= this.accuracyLimit))) {

if (this.averageRecordMode && this.positionAverageInMapCRS !== undefined) {
mainLizmap.edition.drawControl.handler.insertXY(this.positionAverageInMapCRS);
this._edition.drawControl.handler.insertXY(this.positionAverageInMapCRS);
} else {
const node = mainLizmap.edition.drawControl.handler.point.geometry;
mainLizmap.edition.drawControl.handler.insertXY(node.x, node.y);
const node = this._edition.drawControl.handler.point.geometry;
this._edition.drawControl.handler.insertXY(node.x, node.y);
}

// Beep
Expand Down Expand Up @@ -83,7 +93,7 @@ export default class GeolocationSurvey {
if (this._distanceModeCallback === undefined) {
this._distanceModeCallback = () => {
// Insert automatically a point when lastSegmentLength >= distanceLimit
if (this._distanceMode && mainLizmap.edition.lastSegmentLength >= this.distanceLimit) {
if (this._distanceMode && this._edition.lastSegmentLength >= this.distanceLimit) {
this._insertPoint();
}
};
Expand Down Expand Up @@ -114,7 +124,7 @@ export default class GeolocationSurvey {
if (this._timeModeCallback === undefined) {
this._timeModeCallback = () => {
// Disable time mode when edition or geolocation end
if (!mainLizmap.edition.drawFeatureActivated || !mainLizmap.geolocation.isTracking) {
if (!this._edition.drawFeatureActivated || !this._geolocation.isTracking) {
this.toggleTimeMode(false);
}
};
Expand All @@ -124,7 +134,7 @@ export default class GeolocationSurvey {
if (this._timeMode) {
this._intervalID = window.setInterval(() => {
// Count taking care of accuracy if mode is active and pause mode
if (!this.timePauseMode && (!this.accuracyMode || (mainLizmap.geolocation.accuracy <= this.accuracyLimit))) {
if (!this.timePauseMode && (!this.accuracyMode || (this._geolocation.accuracy <= this.accuracyLimit))) {
this.timeCount = this.timeCount + 1;

// Insert automatically a point when timeCount >= timeLimit
Expand Down Expand Up @@ -240,8 +250,8 @@ export default class GeolocationSurvey {
}

// Record point taking care of accuracy if mode is active
if (!this.accuracyMode || (mainLizmap.geolocation.accuracy <= this.accuracyLimit)) {
this._positionPointsRecord[now] = mainLizmap.geolocation.position;
if (!this.accuracyMode || (this._geolocation.accuracy <= this.accuracyLimit)) {
this._positionPointsRecord[now] = this._geolocation.position;
}
}
};
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 @@ -150,7 +150,7 @@ export default class Lizmap {
this.edition = new Edition(this.lizmap3);
this.featuresTable = new FeaturesTable();
this.geolocation = new Geolocation(this.map, this.lizmap3);
this.geolocationSurvey = new GeolocationSurvey();
this.geolocationSurvey = new GeolocationSurvey(this.geolocation, this.edition);
this.selectionTool = new SelectionTool();
this.digitizing = new Digitizing();
this.snapping = new Snapping();
Expand Down

0 comments on commit b50b4ef

Please sign in to comment.