Clear position watching on map destroy
All checks were successful
ci/woodpecker/push/build Pipeline was successful
All checks were successful
ci/woodpecker/push/build Pipeline was successful
This commit is contained in:
parent
616a62d4b5
commit
9e197a2b13
1 changed files with 6 additions and 4 deletions
|
@ -11,6 +11,7 @@
|
||||||
let latitude;
|
let latitude;
|
||||||
let longitude;
|
let longitude;
|
||||||
let accuracy;
|
let accuracy;
|
||||||
|
let watchPositionId: number;
|
||||||
const errorMessage = "Geolocation not available";
|
const errorMessage = "Geolocation not available";
|
||||||
const attribution = '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors';
|
const attribution = '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors';
|
||||||
const openStreetMapTile = 'https://tile.openstreetmap.org/{z}/{x}/{y}.png';
|
const openStreetMapTile = 'https://tile.openstreetmap.org/{z}/{x}/{y}.png';
|
||||||
|
@ -48,7 +49,7 @@
|
||||||
console.warn(`ERROR(${err.code}): ${err.message}`);
|
console.warn(`ERROR(${err.code}): ${err.message}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
navigator.geolocation.watchPosition(success, error, options);
|
watchPositionId = navigator.geolocation.watchPosition(success, error, options);
|
||||||
};
|
};
|
||||||
|
|
||||||
const renderMap = () => {
|
const renderMap = () => {
|
||||||
|
@ -73,12 +74,13 @@
|
||||||
await watchPosition();
|
await watchPosition();
|
||||||
leaflet = await import('leaflet');
|
leaflet = await import('leaflet');
|
||||||
|
|
||||||
setTimeout(() => {
|
|
||||||
renderMap()
|
renderMap()
|
||||||
}, 500);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
onDestroy(async () => {
|
onDestroy(async () => {
|
||||||
|
if(watchPositionId) {
|
||||||
|
navigator.geolocation.clearWatch(watchPositionId);
|
||||||
|
}
|
||||||
if (map) {
|
if (map) {
|
||||||
console.log('Unloading Leaflet map.');
|
console.log('Unloading Leaflet map.');
|
||||||
map.remove();
|
map.remove();
|
||||||
|
|
Loading…
Reference in a new issue