Add via routing
This commit is contained in:
@@ -12,6 +12,9 @@ import org.json.JSONObject;
|
|||||||
public class ConfigServlet extends HttpServlet {
|
public class ConfigServlet extends HttpServlet {
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Output configuration as JSON
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||||
response.setContentType("application/json");
|
response.setContentType("application/json");
|
||||||
|
|||||||
@@ -17,9 +17,9 @@ const lib = new function () {
|
|||||||
|
|
||||||
const startMarker = new maplibregl.Marker({color: "#00FF00", draggable: true}).setLngLat([0, 0]);
|
const startMarker = new maplibregl.Marker({color: "#00FF00", draggable: true}).setLngLat([0, 0]);
|
||||||
const finishMarker = new maplibregl.Marker({color: "#FF0000", draggable: true}).setLngLat([0, 0]);
|
const finishMarker = new maplibregl.Marker({color: "#FF0000", draggable: true}).setLngLat([0, 0]);
|
||||||
startMarker.on("dragend", function() {lib.doRouting(map, startMarker.getLngLat(), finishMarker.getLngLat());});
|
|
||||||
finishMarker.on("dragend", function() {lib.doRouting(map, startMarker.getLngLat(), finishMarker.getLngLat());});
|
|
||||||
const viaMarkers = new Array();
|
const viaMarkers = new Array();
|
||||||
|
startMarker.on("dragend", function() {lib.doRouting(map, startMarker.getLngLat(), finishMarker.getLngLat(), viaMarkers);});
|
||||||
|
finishMarker.on("dragend", function() {lib.doRouting(map, startMarker.getLngLat(), finishMarker.getLngLat(), viaMarkers);});
|
||||||
|
|
||||||
map.on('mousemove', function (e) {
|
map.on('mousemove', function (e) {
|
||||||
var features = map.queryRenderedFeatures(e.point);
|
var features = map.queryRenderedFeatures(e.point);
|
||||||
@@ -68,7 +68,7 @@ const lib = new function () {
|
|||||||
startMarker.setLngLat([coordinates.lng, coordinates.lat]).addTo(map);
|
startMarker.setLngLat([coordinates.lng, coordinates.lat]).addTo(map);
|
||||||
startMarker.onMap = true;
|
startMarker.onMap = true;
|
||||||
if (finishMarker.onMap) {
|
if (finishMarker.onMap) {
|
||||||
lib.doRouting(map, coordinates, finishMarker.getLngLat());
|
lib.doRouting(map, coordinates, finishMarker.getLngLat(), viaMarkers);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
let finishbtn = document.getElementById("btn-finish");
|
let finishbtn = document.getElementById("btn-finish");
|
||||||
@@ -77,7 +77,19 @@ const lib = new function () {
|
|||||||
finishMarker.setLngLat([coordinates.lng, coordinates.lat]).addTo(map);
|
finishMarker.setLngLat([coordinates.lng, coordinates.lat]).addTo(map);
|
||||||
finishMarker.onMap = true;
|
finishMarker.onMap = true;
|
||||||
if (startMarker.onMap) {
|
if (startMarker.onMap) {
|
||||||
lib.doRouting(map, startMarker.getLngLat(), coordinates);
|
lib.doRouting(map, startMarker.getLngLat(), coordinates, viaMarkers);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
let viabtn = document.getElementById("btn-via");
|
||||||
|
viabtn.onclick = function () {
|
||||||
|
contextmenu.remove();
|
||||||
|
const marker = new maplibregl.Marker({color: "#0000FF", draggable: true}).setLngLat([coordinates.lng, coordinates.lat]);
|
||||||
|
marker.on("dragend", function() {lib.doRouting(map, startMarker.getLngLat(), finishMarker.getLngLat(), viaMarkers);});
|
||||||
|
marker.addTo(map);
|
||||||
|
marker.onMap = true;
|
||||||
|
viaMarkers.push(marker);
|
||||||
|
if (startMarker.onMap && finishMarker.onMap) {
|
||||||
|
lib.doRouting(map, startMarker.getLngLat(), finishMarker.getLngLat(), viaMarkers);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
@@ -93,9 +105,12 @@ const lib = new function () {
|
|||||||
points_encoded: false
|
points_encoded: false
|
||||||
};
|
};
|
||||||
if (vias != undefined && vias.length > 0) {
|
if (vias != undefined && vias.length > 0) {
|
||||||
|
for (let marker of vias) {
|
||||||
|
const lnglat = marker.getLngLat()
|
||||||
|
data.points.push([lnglat["lng"], lnglat["lat"]]);
|
||||||
}
|
}
|
||||||
data.points.push([finish.lng, finish.lat])
|
}
|
||||||
|
data.points.push([finish.lng, finish.lat]);
|
||||||
$.ajax({
|
$.ajax({
|
||||||
type: "POST",
|
type: "POST",
|
||||||
url: ghbase + "/route",
|
url: ghbase + "/route",
|
||||||
|
|||||||
Reference in New Issue
Block a user