diff --git a/assets/src/modules/GeolocationSurvey.js b/assets/src/modules/GeolocationSurvey.js index b907a82313..d2ed149aa0 100644 --- a/assets/src/modules/GeolocationSurvey.js +++ b/assets/src/modules/GeolocationSurvey.js @@ -5,7 +5,9 @@ * @license MPL-2.0 */ -import {mainLizmap, mainEventDispatcher} from '../modules/Globals.js'; +import {mainEventDispatcher} from '../modules/Globals.js'; +import Edition from './Edition.js'; +import Geolocation from './Geolocation.js'; import {transform} from 'ol/proj.js'; /** @@ -14,12 +16,22 @@ 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 + * @param {object} lizmap3 - The old lizmap object + */ + constructor(geolocation, edition, lizmap3) { this.distanceLimit = 0; this.timeLimit = 0; this.accuracyLimit = 0; this.averageRecordLimit = 0; + this._geolocation = geolocation; + this._edition = edition; + this._lizmap3 = lizmap3; this._distanceMode = false; this._timeMode = false; this._timePauseMode = false; @@ -37,13 +49,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 @@ -83,7 +95,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(); } }; @@ -114,7 +126,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); } }; @@ -124,7 +136,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 @@ -214,8 +226,9 @@ export default class GeolocationSurvey { count++; } } + const qgisProjectProjection = this._lizmap3.map.getProjection(); - return transform([sumX / count, sumY / count], 'EPSG:4326', mainLizmap.projection); + return transform([sumX / count, sumY / count], 'EPSG:4326', qgisProjectProjection); } else { return undefined; } @@ -240,8 +253,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; } } }; diff --git a/assets/src/modules/Lizmap.js b/assets/src/modules/Lizmap.js index 6b7080902a..351583288f 100644 --- a/assets/src/modules/Lizmap.js +++ b/assets/src/modules/Lizmap.js @@ -153,7 +153,7 @@ export default class Lizmap { this.edition = new Edition(this._lizmap3); this.featuresTable = new FeaturesTable(this.initialConfig, this.lizmap3); 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();