Split engine id into mode and provider
This commit is contained in:
parent
51a2d85053
commit
d5b3a70ac1
4 changed files with 28 additions and 38 deletions
|
@ -44,15 +44,13 @@ OSM.Directions = function (map) {
|
|||
const engines = OSM.Directions.engines;
|
||||
|
||||
engines.sort(function (a, b) {
|
||||
const localised_a = I18n.t("javascripts.directions.engines." + a.id),
|
||||
localised_b = I18n.t("javascripts.directions.engines." + b.id);
|
||||
return localised_a.localeCompare(localised_b);
|
||||
return a.localeId.localeCompare(b.localeId);
|
||||
});
|
||||
|
||||
const select = $("select.routing_engines");
|
||||
|
||||
engines.forEach(function (engine, i) {
|
||||
select.append("<option value='" + i + "'>" + I18n.t("javascripts.directions.engines." + engine.id) + "</option>");
|
||||
select.append("<option value='" + i + "'>" + engine.localeId + "</option>");
|
||||
});
|
||||
|
||||
$(".directions_form .reverse_directions").on("click", function () {
|
||||
|
@ -98,13 +96,9 @@ OSM.Directions = function (map) {
|
|||
return h + ":" + (m < 10 ? "0" : "") + m;
|
||||
}
|
||||
|
||||
function findEngine(id) {
|
||||
return engines.findIndex(function (engine) {
|
||||
return engine.id === id;
|
||||
});
|
||||
}
|
||||
|
||||
function setEngine(index) {
|
||||
function setEngine(id) {
|
||||
const index = engines.findIndex(engine => engine.id === id);
|
||||
if (index < 0) return;
|
||||
chosenEngine = engines[index];
|
||||
select.val(index);
|
||||
}
|
||||
|
@ -230,11 +224,8 @@ OSM.Directions = function (map) {
|
|||
}
|
||||
}
|
||||
|
||||
let chosenEngineIndex = findEngine("fossgis_osrm_car");
|
||||
if (Cookies.get("_osm_directions_engine")) {
|
||||
chosenEngineIndex = findEngine(Cookies.get("_osm_directions_engine"));
|
||||
}
|
||||
setEngine(chosenEngineIndex);
|
||||
setEngine("fossgis_osrm_car");
|
||||
setEngine(Cookies.get("_osm_directions_engine"));
|
||||
|
||||
select.on("change", function (e) {
|
||||
chosenEngine = engines[e.target.selectedIndex];
|
||||
|
@ -286,13 +277,7 @@ OSM.Directions = function (map) {
|
|||
const params = new URLSearchParams(location.search),
|
||||
route = (params.get("route") || "").split(";");
|
||||
|
||||
if (params.has("engine")) {
|
||||
const engineIndex = findEngine(params.get("engine"));
|
||||
|
||||
if (engineIndex >= 0) {
|
||||
setEngine(engineIndex);
|
||||
}
|
||||
}
|
||||
if (params.has("engine")) setEngine(params.get("engine"));
|
||||
|
||||
endpoints[0].setValue(params.get("from") || route[0] || "");
|
||||
endpoints[1].setValue(params.get("to") || route[1] || "");
|
||||
|
@ -324,6 +309,8 @@ OSM.Directions.engines = [];
|
|||
|
||||
OSM.Directions.addEngine = function (engine, supportsHTTPS) {
|
||||
if (document.location.protocol === "http:" || supportsHTTPS) {
|
||||
engine.id = engine.provider + "_" + engine.mode;
|
||||
engine.localeId = I18n.t("javascripts.directions.engines." + engine.id);
|
||||
OSM.Directions.engines.push(engine);
|
||||
}
|
||||
};
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
// Doesn't yet support hints
|
||||
|
||||
(function () {
|
||||
function FOSSGISOSRMEngine(id, vehicleType) {
|
||||
function FOSSGISOSRMEngine(modeId, vehicleType) {
|
||||
let cachedHints = [];
|
||||
|
||||
function _processDirections(route) {
|
||||
|
@ -150,7 +150,8 @@
|
|||
}
|
||||
|
||||
return {
|
||||
id: id,
|
||||
mode: modeId,
|
||||
provider: "fossgis_osrm",
|
||||
creditline: "<a href=\"https://routing.openstreetmap.de/about.html\" target=\"_blank\">OSRM (FOSSGIS)</a>",
|
||||
draggable: true,
|
||||
|
||||
|
@ -181,7 +182,7 @@
|
|||
};
|
||||
}
|
||||
|
||||
OSM.Directions.addEngine(new FOSSGISOSRMEngine("fossgis_osrm_car", "car"), true);
|
||||
OSM.Directions.addEngine(new FOSSGISOSRMEngine("fossgis_osrm_bike", "bike"), true);
|
||||
OSM.Directions.addEngine(new FOSSGISOSRMEngine("fossgis_osrm_foot", "foot"), true);
|
||||
OSM.Directions.addEngine(new FOSSGISOSRMEngine("car", "car"), true);
|
||||
OSM.Directions.addEngine(new FOSSGISOSRMEngine("bicycle", "bike"), true);
|
||||
OSM.Directions.addEngine(new FOSSGISOSRMEngine("foot", "foot"), true);
|
||||
}());
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
(function () {
|
||||
function FOSSGISValhallaEngine(id, costing) {
|
||||
function FOSSGISValhallaEngine(modeId, costing) {
|
||||
const INSTR_MAP = [
|
||||
0, // kNone = 0;
|
||||
8, // kStart = 1;
|
||||
|
@ -82,7 +82,8 @@
|
|||
}
|
||||
|
||||
return {
|
||||
id: id,
|
||||
mode: modeId,
|
||||
provider: "fossgis_valhalla",
|
||||
creditline:
|
||||
"<a href='https://gis-ops.com/global-open-valhalla-server-online/' target='_blank'>Valhalla (FOSSGIS)</a>",
|
||||
draggable: false,
|
||||
|
@ -110,7 +111,7 @@
|
|||
};
|
||||
}
|
||||
|
||||
OSM.Directions.addEngine(new FOSSGISValhallaEngine("fossgis_valhalla_car", "auto"), true);
|
||||
OSM.Directions.addEngine(new FOSSGISValhallaEngine("fossgis_valhalla_bicycle", "bicycle"), true);
|
||||
OSM.Directions.addEngine(new FOSSGISValhallaEngine("fossgis_valhalla_foot", "pedestrian"), true);
|
||||
OSM.Directions.addEngine(new FOSSGISValhallaEngine("car", "auto"), true);
|
||||
OSM.Directions.addEngine(new FOSSGISValhallaEngine("bicycle", "bicycle"), true);
|
||||
OSM.Directions.addEngine(new FOSSGISValhallaEngine("foot", "pedestrian"), true);
|
||||
}());
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
(function () {
|
||||
function GraphHopperEngine(id, vehicleType) {
|
||||
function GraphHopperEngine(modeId, vehicleType) {
|
||||
const GH_INSTR_MAP = {
|
||||
"-3": 7, // sharp left
|
||||
"-2": 6, // left
|
||||
|
@ -47,7 +47,8 @@
|
|||
}
|
||||
|
||||
return {
|
||||
id: id,
|
||||
mode: modeId,
|
||||
provider: "graphhopper",
|
||||
creditline: "<a href=\"https://www.graphhopper.com/\" target=\"_blank\">GraphHopper</a>",
|
||||
draggable: false,
|
||||
|
||||
|
@ -73,7 +74,7 @@
|
|||
};
|
||||
}
|
||||
|
||||
OSM.Directions.addEngine(new GraphHopperEngine("graphhopper_car", "car"), true);
|
||||
OSM.Directions.addEngine(new GraphHopperEngine("graphhopper_bicycle", "bike"), true);
|
||||
OSM.Directions.addEngine(new GraphHopperEngine("graphhopper_foot", "foot"), true);
|
||||
OSM.Directions.addEngine(new GraphHopperEngine("car", "car"), true);
|
||||
OSM.Directions.addEngine(new GraphHopperEngine("bicycle", "bike"), true);
|
||||
OSM.Directions.addEngine(new GraphHopperEngine("foot", "foot"), true);
|
||||
}());
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue