Skip to content

Commit fb1f620

Browse files
committed
feat: add possibility to follow routes
1 parent 94a4278 commit fb1f620

File tree

11 files changed

+415
-0
lines changed

11 files changed

+415
-0
lines changed

src/css/layer-switcher.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ div[id^="opacity-middle-div_ID_"] {
174174
.tools-layer-visibility,
175175
.tools-layer-info,
176176
.tools-layer-share,
177+
.tools-layer-follow,
177178
.tools-layer-edit,
178179
.tools-layer-export,
179180
.tools-layer-remove {

src/html/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
<%= require('html-loader!./tabs/isochroneWindow.html').default %>
4242
<%= require('html-loader!./tabs/routeDrawWindow.html').default %>
4343
<%= require('html-loader!./tabs/routeDrawSaveWindow.html').default %>
44+
<%= require('html-loader!./tabs/routeFollowWindow.html').default %>
4445
<%= require('html-loader!./tabs/positionWindow.html').default %>
4546
<%= require('html-loader!./tabs/informationsWindow.html').default %>
4647
<%= require('html-loader!./tabs/poiWindow.html').default %>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<div class="d-none" id="routeFollowWindow">
2+
Suivi de l'itinéraire.
3+
<p class="d-none notFollowAltert">VOUS VOUS ELOIGNEZ DE L'ITINERAIRE</p>
4+
<button class="recenter">Recentrer</button>
5+
<p>Temps restant estimé : <span class="remainingTime"></span></p>
6+
<p>Distance restante : <span class="remainingDist"></span></p>
7+
<p>Dénivelé positif restant : <span class="remainingDplus"></span></p>
8+
</div>

src/js/controls.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ import LocationLayers from "./services/location-styles";
3030
// TODO: activate
3131
// import ImmersiveNotifications from "./immersive-notifications";
3232

33+
import RouteFollow from "./route-follow";
34+
3335
/**
3436
* Ajout des contrôle à la fin du chargement de la carte
3537
* @see maplibregl.ScaleControl
@@ -149,6 +151,9 @@ const addControls = () => {
149151
Globals.signalement = new Signalement(map, {});
150152
Globals.signalementOSM = new SignalementOSM(map, {});
151153

154+
// suivi d'itinéraire
155+
Globals.routeFollow = new RouteFollow(map, {}, true);
156+
152157
// points de repère
153158
Globals.landmark = new Landmark(map, {
154159
// callback sur l'ouverture / fermeture du panneau

src/js/dom.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ const $signalementOSMWindow = document.getElementById("signalementOSMWindow");
7676
const $landmarkWindow = document.getElementById("landmarkWindow");
7777
const $compareLandmarkWindow = document.getElementById("compareLandmarkWindow");
7878
const $offlineMapsWindow = document.getElementById("offlineMapsWindow");
79+
const $routeFollowWindow = document.getElementById("routeFollowWindow");
7980

8081
export default {
8182
$search,
@@ -138,4 +139,5 @@ export default {
138139
$createCompareLandmarkBtn,
139140
$compareLandmarkWindow,
140141
$offlineMapsWindow,
142+
$routeFollowWindow,
141143
};

src/js/globals.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,9 @@ let immersiveNotifications = null;
108108
// Global control 3d
109109
let threeD = null;
110110

111+
// Global control route follow
112+
let routeFollow = null;
113+
111114
// Global flag: is the device connected to the internet?
112115
let online = (await Network.getStatus()).connected;
113116

@@ -198,4 +201,5 @@ export default {
198201
immersiveNotifications,
199202
newPlaceNotifEnabled,
200203
threeD,
204+
routeFollow,
201205
};

src/js/my-account/my-account-dom.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,11 @@ let MyAccountDOM = {
325325
text: "Télecharger le plan",
326326
value: "download",
327327
},
328+
{
329+
class: "tools-layer-follow",
330+
text: "Suivre",
331+
value: "follow",
332+
},
328333
{
329334
class: "tools-layer-share",
330335
text: "Partager",
@@ -383,6 +388,9 @@ let MyAccountDOM = {
383388
if (value === "download") {
384389
this.downloadRoute(route);
385390
}
391+
if (value === "follow") {
392+
this.followRoute(route);
393+
}
386394
});
387395
});
388396

src/js/my-account/my-account.js

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -797,6 +797,14 @@ class MyAccount {
797797
* @param {*} route
798798
*/
799799
downloadRoute(route) {
800+
if (!Globals.online) {
801+
Toast.show({
802+
text: "Fonctionnalité indisponible en mode hors ligne.",
803+
duration: "long",
804+
position: "bottom"
805+
});
806+
return;
807+
}
800808
let coordinates = [];
801809
route.data.steps.forEach((step) => {
802810
coordinates = coordinates.concat(step.geometry.coordinates);
@@ -874,6 +882,54 @@ class MyAccount {
874882
Globals.routeDraw.showDetails();
875883
}
876884

885+
/**
886+
* Ouvre le suivi d'itinéraire
887+
* @param {*} route
888+
*/
889+
followRoute(route) {
890+
let steps = JSON.parse(JSON.stringify(route.data.steps));
891+
const coords = [];
892+
steps.forEach( (step) => {
893+
coords.push(step.geometry.coordinates);
894+
});
895+
const dissolvedCoords = gisUtils.geoJsonMultiLineStringCoordsToSingleLineStringCoords(coords);
896+
897+
const routeLine = {
898+
type: "Feature",
899+
geometry: {
900+
type: "LineString",
901+
coordinates: dissolvedCoords,
902+
},
903+
properties: {
904+
distance: route.data.distance,
905+
duration: route.data.duration,
906+
},
907+
};
908+
Globals.routeFollow.setData({
909+
routeLine: routeLine,
910+
elevations: route.data.elevationData.elevationData,
911+
});
912+
this.hide();
913+
Globals.routeFollow.show();
914+
}
915+
916+
/**
917+
* Ouvre le suivi d'itinéraire à partir de son ID
918+
* @param {Number} routeId
919+
*/
920+
followRouteFromID(routeId) {
921+
try {
922+
this.followRoute(this.#getRouteFromID(routeId));
923+
} catch (e) {
924+
console.warn(e);
925+
Toast.show({
926+
text: "L'itinéraire n'a pas pu être ouvert.",
927+
duration: "short",
928+
position: "bottom"
929+
});
930+
}
931+
}
932+
877933
/**
878934
* Ouvre l'outil de création de point de repère pour le modifer
879935
* @param {*} landmark

src/js/nav.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,13 @@ class MenuNavigation {
137137
// y'a t il des particularités sur l'ouverture du panneau demandé ?
138138
var isSpecific = false;
139139
switch (id) {
140+
case "routeFollow":
141+
DOM.$search.classList.add("d-none");
142+
DOM.$filterPoiBtn.classList.add("higher");
143+
DOM.$layerManagerBtn.classList.add("higher");
144+
DOM.$backTopLeftBtn.classList.remove("d-none");
145+
Globals.currentScrollIndex = 2;
146+
break;
140147
case "offlineMaps":
141148
DOM.$search.classList.add("d-none");
142149
DOM.$filterPoiBtn.classList.add("d-none");
@@ -442,6 +449,13 @@ class MenuNavigation {
442449
var isSpecific = false;
443450
var isFinished = false; // hack pour search !
444451
switch (id) {
452+
case "routeFollow":
453+
Globals.routeFollow.disable();
454+
DOM.$search.classList.remove("d-none");
455+
DOM.$filterPoiBtn.classList.remove("higher");
456+
DOM.$layerManagerBtn.classList.remove("higher");
457+
DOM.$backTopLeftBtn.classList.add("d-none");
458+
break;
445459
case "offlineMaps":
446460
DOM.$search.classList.remove("d-none");
447461
DOM.$filterPoiBtn.classList.remove("d-none");

0 commit comments

Comments
 (0)