This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const success = (position) => { | |
const { latitude, longitude } = position.coords; | |
const timestamp = (new Date(Date.now())).toISOString(); | |
... | |
createNewEvent(latitude, longitude, timestamp); | |
} | |
const createNewEvent = (latitude, longitude, timestamp) => { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const toggle = () => { | |
if (isStart === null) { | |
isStart = true; | |
startTracking(); | |
} else { | |
isStart = !isStart; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const refreshMeter = (detail) => { | |
return new Promise((resolve) => { | |
if (path == null) return resolve(detail); | |
if (!isStart) return resolve(detail); | |
const delta = calculateDelta(path._latlngs) | |
accumulatedDistance += delta; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const drawNewSegment = (detail) => { | |
const { latitude, longitude } = detail; | |
return new Promise((resolve) => { | |
if (path == null) { | |
path = L.polyline([ | |
[ latitude, longitude ], | |
], { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const updateMap = (event) => { | |
... | |
drawNewSegment(event.detail) | |
.then((detail) => drawNewMarker(detail)) | |
.then((detail) => refreshMeter(detail)) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
L.tileLayer( | |
"https://api.mapbox.com/styles/v1/{id}/tiles/{z}/{x}/{y}?access_token={accessToken}", | |
{ | |
attribution: | |
'Map data © <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors, Imagery © <a href="https://www.mapbox.com/">Mapbox</a>', | |
maxZoom: 18, | |
id: "mapbox/streets-v11", | |
tileSize: 512, | |
zoomOffset: -1, | |
accessToken: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const LONDON_CENTRE_LAT_LNG = [51.505, -0.09]; | |
let map = L.map("tracker").setView(LONDON_CENTRE_LAT_LNG, 13); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<head> | |
<meta | |
name="viewport" | |
content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" | |
/> | |
<link | |
rel="stylesheet" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const HIGH_ACCURACY = true; | |
const MAX_CACHE_AGE_MILLISECOND = 30000; | |
const MAX_NEW_POSITION_MILLISECOND = 5000; | |
const trackOptions = { | |
enableHighAccuracy: HIGH_ACCURACY, | |
maximumAge: MAX_CACHE_AGE_MILLISECOND, | |
timeout: MAX_NEW_POSITION_MILLISECOND, | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const startTracking = () => { | |
if(!navigator.geolocation) { | |
logConsole.textContent = 'Geolocation is not supported by your browser'; | |
} else { | |
logConsole.textContent = 'Locating ...'; | |
distanceBox.textContent = '0.000'; | |
return navigator.geolocation.watchPosition(success, error, trackOptions); | |
} | |
} |
NewerOlder