Add waypoint mode
This commit is contained in:
@@ -1,7 +1,11 @@
|
||||
const lib = new function () {
|
||||
|
||||
let ghbase = ""
|
||||
let planningMode = "classic";
|
||||
let planningMode = "modern";
|
||||
const modeContext = {
|
||||
"classic": '<button id="btn-feat">feature</button></br><button id="btn-start">start</button></br><button id="btn-via">via</button></br><button id="btn-finish">finish</button>',
|
||||
"modern": '<button id="btn-feat">feature</button></br><button id="btn-waypoint">waypoint</button>'
|
||||
};
|
||||
|
||||
/**
|
||||
* Initialize Map etc
|
||||
@@ -48,9 +52,10 @@ const lib = new function () {
|
||||
|
||||
const contextmenu = new maplibregl.Popup()
|
||||
.setLngLat(coordinates)
|
||||
.setHTML('<button id="btn-feat">feature</button></br><button id="btn-start">start</button></br><button id="btn-via">via</button></br><button id="btn-finish">finish</button>')
|
||||
.setHTML(modeContext[planningMode])
|
||||
.addTo(map);
|
||||
|
||||
if (planningMode === 'classic') {
|
||||
let featbtn = document.getElementById("btn-feat");
|
||||
featbtn.onclick = function () {
|
||||
contextmenu.remove();
|
||||
@@ -93,6 +98,28 @@ const lib = new function () {
|
||||
lib.doRouting(map, startMarker.getLngLat(), finishMarker.getLngLat(), viaMarkers);
|
||||
}
|
||||
};
|
||||
} else if (planningMode === 'modern') {
|
||||
let waypointbtn = document.getElementById("btn-waypoint");
|
||||
waypointbtn.onclick = function () {
|
||||
contextmenu.remove();
|
||||
if (!startMarker.onMap) {
|
||||
startMarker.setLngLat([coordinates.lng, coordinates.lat]).addTo(map);
|
||||
startMarker.onMap = true;
|
||||
} else if (!finishMarker.onMap) {
|
||||
finishMarker.setLngLat([coordinates.lng, coordinates.lat]).addTo(map);
|
||||
finishMarker.onMap = true;
|
||||
lib.doRouting(map, startMarker.getLngLat(), coordinates);
|
||||
} else {
|
||||
const oldFinishMarker = new maplibregl.Marker({color: "#0000FF", draggable: true}).setLngLat(finishMarker.getLngLat());
|
||||
finishMarker.setLngLat([coordinates.lng, coordinates.lat]);
|
||||
oldFinishMarker.on("dragend", function() {lib.doRouting(map, startMarker.getLngLat(), finishMarker.getLngLat(), viaMarkers);});
|
||||
oldFinishMarker.addTo(map);
|
||||
oldFinishMarker.onMap = true;
|
||||
viaMarkers.push(oldFinishMarker);
|
||||
lib.doRouting(map, startMarker.getLngLat(), finishMarker.getLngLat(), viaMarkers);
|
||||
}
|
||||
}
|
||||
};
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user