Add waypoint mode
This commit is contained in:
@@ -1,7 +1,11 @@
|
|||||||
const lib = new function () {
|
const lib = new function () {
|
||||||
|
|
||||||
let ghbase = ""
|
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
|
* Initialize Map etc
|
||||||
@@ -48,49 +52,72 @@ const lib = new function () {
|
|||||||
|
|
||||||
const contextmenu = new maplibregl.Popup()
|
const contextmenu = new maplibregl.Popup()
|
||||||
.setLngLat(coordinates)
|
.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);
|
.addTo(map);
|
||||||
|
|
||||||
let featbtn = document.getElementById("btn-feat");
|
if (planningMode === 'classic') {
|
||||||
featbtn.onclick = function () {
|
let featbtn = document.getElementById("btn-feat");
|
||||||
contextmenu.remove();
|
featbtn.onclick = function () {
|
||||||
const features = map.queryRenderedFeatures(e.point);
|
contextmenu.remove();
|
||||||
const prop = features.map(function (feat) {
|
const features = map.queryRenderedFeatures(e.point);
|
||||||
return feat["properties"];
|
const prop = features.map(function (feat) {
|
||||||
});
|
return feat["properties"];
|
||||||
const featPopup = new maplibregl.Popup()
|
});
|
||||||
.setLngLat(coordinates)
|
const featPopup = new maplibregl.Popup()
|
||||||
.setHTML(JSON.stringify(prop))
|
.setLngLat(coordinates)
|
||||||
.addTo(map);
|
.setHTML(JSON.stringify(prop))
|
||||||
};
|
.addTo(map);
|
||||||
let startbtn = document.getElementById("btn-start");
|
};
|
||||||
startbtn.onclick = function () {
|
let startbtn = document.getElementById("btn-start");
|
||||||
contextmenu.remove();
|
startbtn.onclick = function () {
|
||||||
startMarker.setLngLat([coordinates.lng, coordinates.lat]).addTo(map);
|
contextmenu.remove();
|
||||||
startMarker.onMap = true;
|
startMarker.setLngLat([coordinates.lng, coordinates.lat]).addTo(map);
|
||||||
if (finishMarker.onMap) {
|
startMarker.onMap = true;
|
||||||
lib.doRouting(map, coordinates, finishMarker.getLngLat(), viaMarkers);
|
if (finishMarker.onMap) {
|
||||||
}
|
lib.doRouting(map, coordinates, finishMarker.getLngLat(), viaMarkers);
|
||||||
};
|
}
|
||||||
let finishbtn = document.getElementById("btn-finish");
|
};
|
||||||
finishbtn.onclick = function () {
|
let finishbtn = document.getElementById("btn-finish");
|
||||||
contextmenu.remove();
|
finishbtn.onclick = function () {
|
||||||
finishMarker.setLngLat([coordinates.lng, coordinates.lat]).addTo(map);
|
contextmenu.remove();
|
||||||
finishMarker.onMap = true;
|
finishMarker.setLngLat([coordinates.lng, coordinates.lat]).addTo(map);
|
||||||
if (startMarker.onMap) {
|
finishMarker.onMap = true;
|
||||||
lib.doRouting(map, startMarker.getLngLat(), coordinates, viaMarkers);
|
if (startMarker.onMap) {
|
||||||
}
|
lib.doRouting(map, startMarker.getLngLat(), coordinates, viaMarkers);
|
||||||
};
|
}
|
||||||
let viabtn = document.getElementById("btn-via");
|
};
|
||||||
viabtn.onclick = function () {
|
let viabtn = document.getElementById("btn-via");
|
||||||
contextmenu.remove();
|
viabtn.onclick = function () {
|
||||||
const marker = new maplibregl.Marker({color: "#0000FF", draggable: true}).setLngLat([coordinates.lng, coordinates.lat]);
|
contextmenu.remove();
|
||||||
marker.on("dragend", function() {lib.doRouting(map, startMarker.getLngLat(), finishMarker.getLngLat(), viaMarkers);});
|
const marker = new maplibregl.Marker({color: "#0000FF", draggable: true}).setLngLat([coordinates.lng, coordinates.lat]);
|
||||||
marker.addTo(map);
|
marker.on("dragend", function() {lib.doRouting(map, startMarker.getLngLat(), finishMarker.getLngLat(), viaMarkers);});
|
||||||
marker.onMap = true;
|
marker.addTo(map);
|
||||||
viaMarkers.push(marker);
|
marker.onMap = true;
|
||||||
if (startMarker.onMap && finishMarker.onMap) {
|
viaMarkers.push(marker);
|
||||||
lib.doRouting(map, startMarker.getLngLat(), finishMarker.getLngLat(), viaMarkers);
|
if (startMarker.onMap && finishMarker.onMap) {
|
||||||
|
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