var expiry = new Date();
expiry.setYear(expiry.getFullYear() + 10);
+ var engines = OSM.Directions.engines;
+
+ engines.sort(function (a, b) {
+ a = I18n.t('javascripts.directions.engines.' + a.id);
+ b = I18n.t('javascripts.directions.engines.' + b.id);
+ return a.localeCompare(b);
+ });
+
+ var select = $('select.routing_engines');
+
+ engines.forEach(function(engine, i) {
+ select.append("<option value='" + i + "'>" + I18n.t('javascripts.directions.engines.' + engine.id) + "</option>");
+ });
+
function Endpoint(input, iconUrl) {
var endpoint = {};
shadowUrl: OSM.MARKER_SHADOW,
shadowSize: [41, 41]
}),
- draggable: true
+ draggable: true,
+ autoPan: true
});
endpoint.marker.on('drag dragend', function (e) {
});
input.on("keydown", function() {
- input.removeClass("highlight_error");
+ input.removeClass("error");
});
input.on("change", function (e) {
awaitingGeocode = true;
-
+
// make text the same in both text boxes
var value = e.target.value;
endpoint.setValue(value);
endpoint.setValue = function(value, latlng) {
endpoint.value = value;
delete endpoint.latlng;
+ input.removeClass("error");
input.val(value);
if (latlng) {
endpoint.awaitingGeocode = false;
endpoint.hasGeocode = true;
if (json.length === 0) {
+ input.addClass("error");
alert(I18n.t('javascripts.directions.errors.no_place', {place: endpoint.value}));
- input.addClass("highlight_error");
return;
}
return h + ":" + (m < 10 ? '0' : '') + m;
}
- function setEngine(id) {
- engines.forEach(function(engine, i) {
- if (engine.id === id) {
- chosenEngine = engine;
- select.val(i);
- }
+ function findEngine(id) {
+ return engines.findIndex(function(engine) {
+ return engine.id === id;
});
}
+ function setEngine(index) {
+ chosenEngine = engines[index];
+ select.val(index);
+ }
+
function getRoute(fitRoute, reportErrors) {
// Cancel any route that is already in progress
if (awaitingRoute) awaitingRoute.abort();
.html(html);
// Add each row
- var cumulative = 0;
route.steps.forEach(function (step) {
var ll = step[0],
direction = step[1],
dist = step[3],
lineseg = step[4];
- cumulative += dist;
-
if (dist < 5) {
dist = "";
} else if (dist < 200) {
});
}
- var engines = OSM.Directions.engines;
-
- engines.sort(function (a, b) {
- a = I18n.t('javascripts.directions.engines.' + a.id);
- b = I18n.t('javascripts.directions.engines.' + b.id);
- return a.localeCompare(b);
- });
-
- var select = $('select.routing_engines');
-
- engines.forEach(function(engine, i) {
- select.append("<option value='" + i + "'>" + I18n.t('javascripts.directions.engines.' + engine.id) + "</option>");
- });
-
- var chosenEngineId = $.cookie('_osm_directions_engine');
- if(!chosenEngineId) {
- chosenEngineId = 'osrm_car';
+ var chosenEngineIndex = findEngine('fossgis_osrm_car');
+ if ($.cookie('_osm_directions_engine')) {
+ chosenEngineIndex = findEngine($.cookie('_osm_directions_engine'));
}
- setEngine(chosenEngineId);
+ setEngine(chosenEngineIndex);
select.on("change", function (e) {
chosenEngine = engines[e.target.selectedIndex];
to = route[1] && L.latLng(route[1].split(','));
if (params.engine) {
- setEngine(params.engine);
+ var engineIndex = findEngine(params.engine);
+
+ if (engineIndex >= 0) {
+ setEngine(engineIndex);
+ }
}
endpoints[0].setValue(params.from || "", from);