Merge branch 'trial/dragging' into develop
Conflicts: WebContent/OSRM.JSONP.js WebContent/OSRM.debug.js WebContent/main.html
This commit is contained in:
commit
bab2887f8f
@ -11,7 +11,7 @@ Setup
|
||||
-----
|
||||
The frontend should work directly as provided.
|
||||
Several settings - including the URL for the routing server and the geocoder server - can be specified in `OSRM.config.js`.
|
||||
Different tile servers can be specified in `OSRM.main.js`.
|
||||
Different tile servers can be specified in `OSRM.Map.js`.
|
||||
Note that the URL shortener used for generating route links only works with URLs pointing to the official Project-OSRM website.
|
||||
|
||||
|
||||
|
80
WebContent/L.Bugfixes.js
Normal file
80
WebContent/L.Bugfixes.js
Normal file
@ -0,0 +1,80 @@
|
||||
/*
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU AFFERO General Public License as published by
|
||||
the Free Software Foundation; either version 3 of the License, or
|
||||
any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
or see http://www.gnu.org/licenses/agpl.txt.
|
||||
*/
|
||||
|
||||
// Leaflet bugfixes
|
||||
// [assorted bugfixes to Leaflet functions we use]
|
||||
|
||||
|
||||
// return closest point on segment or distance to that point
|
||||
L.LineUtil._sqClosestPointOnSegment = function (p, p1, p2, sqDist) {
|
||||
var x = p1.x,
|
||||
y = p1.y,
|
||||
dx = p2.x - x,
|
||||
dy = p2.y - y,
|
||||
dot = dx * dx + dy * dy,
|
||||
t;
|
||||
|
||||
if (dot > 0) {
|
||||
t = ((p.x - x) * dx + (p.y - y) * dy) / dot;
|
||||
|
||||
if (t > 1) {
|
||||
x = p2.x;
|
||||
y = p2.y;
|
||||
} else if (t > 0) {
|
||||
x += dx * t;
|
||||
y += dy * t;
|
||||
}
|
||||
}
|
||||
|
||||
dx = p.x - x;
|
||||
dy = p.y - y;
|
||||
|
||||
// DS_CHANGE: modified return values
|
||||
if(sqDist)
|
||||
return dx*dx + dy*dy;
|
||||
else {
|
||||
var p = new L.Point(x,y);
|
||||
p._sqDist = dx*dx + dy*dy;
|
||||
return p;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// makes requestAnimFrame respect the immediate paramter -> prevents drag events after dragend events
|
||||
// (alternatively: add if(!this.dragging ) return to L.Draggable._updatePosition, but must be done in leaflet.js!)
|
||||
// [TODO: In Leaflet 0.4 use L.Util.cancelAnimFrame(this._animRequest) in L.Draggable._onUp() instead, also has to be done in leaflet.js!]
|
||||
L.Util.requestAnimFrame = (function () {
|
||||
function timeoutDefer(callback) {
|
||||
window.setTimeout(callback, 1000 / 60);
|
||||
}
|
||||
|
||||
var requestFn = window.requestAnimationFrame ||
|
||||
window.webkitRequestAnimationFrame ||
|
||||
window.mozRequestAnimationFrame ||
|
||||
window.oRequestAnimationFrame ||
|
||||
window.msRequestAnimationFrame ||
|
||||
timeoutDefer;
|
||||
|
||||
return function (callback, context, immediate, contextEl) {
|
||||
callback = context ? L.Util.bind(callback, context) : callback;
|
||||
if (immediate ) { // DS_CHANGE: removed additional condition requestFn === timeoutDefer
|
||||
callback();
|
||||
} else {
|
||||
requestFn(callback, contextEl);
|
||||
}
|
||||
};
|
||||
}());
|
@ -16,8 +16,7 @@ or see http://www.gnu.org/licenses/agpl.txt.
|
||||
*/
|
||||
|
||||
// Leaflet extension: MouseMarker
|
||||
// [marker class that propagates modifier and button presses]
|
||||
// [currently deactivated: propagation mousemove events]
|
||||
// [marker class that propagates modifier and button presses in mouse click events and allows for changing icons]
|
||||
|
||||
|
||||
// extended marker class
|
||||
@ -26,19 +25,31 @@ L.MouseMarker = L.Marker.extend({
|
||||
L.Marker.prototype.initialize.apply(this, arguments);
|
||||
},
|
||||
|
||||
// _initInteraction: function (){
|
||||
// L.Marker.prototype._initInteraction.apply(this, arguments);
|
||||
// if (this.options.clickable)
|
||||
// L.DomEvent.addListener(this._icon, 'mousemove', this._fireMouseEvent, this);
|
||||
// },
|
||||
switchIcon: function( icon ) {
|
||||
this.options.icon = icon;
|
||||
|
||||
// _fireMouseEvent: function (e) {
|
||||
// this.fire(e.type, {
|
||||
// latlng: this._map.mouseEventToLatLng(e),
|
||||
// layerPoint: this._map.mouseEventToLayerPoint(e)
|
||||
// });
|
||||
// L.DomEvent.stopPropagation(e);
|
||||
// },
|
||||
if (this._map) {
|
||||
this._changeIcon();
|
||||
this._reset();
|
||||
}
|
||||
},
|
||||
|
||||
_changeIcon: function () {
|
||||
var options = this.options;
|
||||
|
||||
if (this._icon) {
|
||||
this._icon = options.icon.switchIcon( this._icon );
|
||||
this._icon.title = options.title;
|
||||
}
|
||||
|
||||
var panes = this._map._panes;
|
||||
|
||||
if (this._shadow)
|
||||
panes.shadowPane.removeChild(this._shadow);
|
||||
this._shadow = options.icon.createShadow();
|
||||
if (this._shadow)
|
||||
panes.shadowPane.appendChild(this._shadow);
|
||||
},
|
||||
|
||||
_onMouseClick: function (e) {
|
||||
L.DomEvent.stopPropagation(e);
|
||||
|
115
WebContent/L.SwitchableIcon.js
Normal file
115
WebContent/L.SwitchableIcon.js
Normal file
@ -0,0 +1,115 @@
|
||||
/*
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU AFFERO General Public License as published by
|
||||
the Free Software Foundation; either version 3 of the License, or
|
||||
any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
or see http://www.gnu.org/licenses/agpl.txt.
|
||||
*/
|
||||
|
||||
// Leaflet extension: SwitchableIcon
|
||||
// [will be an extension of L.Icon in Leaflet 0.4, for now it is a copy with added functionality]
|
||||
|
||||
|
||||
// icon class with functions to simply switch the icon images
|
||||
L.SwitchableIcon = L.Class.extend({
|
||||
options: {
|
||||
/*
|
||||
iconUrl: (String) (required)
|
||||
iconSize: (Point) (can be set through CSS)
|
||||
iconAnchor: (Point) (centered by default if size is specified, can be set in CSS with negative margins)
|
||||
popupAnchor: (Point) (if not specified, popup opens in the anchor point)
|
||||
shadowUrl: (Point) (no shadow by default)
|
||||
shadowSize: (Point)
|
||||
*/
|
||||
className: ''
|
||||
},
|
||||
|
||||
initialize: function (options) {
|
||||
L.Util.setOptions(this, options);
|
||||
},
|
||||
|
||||
createIcon: function () {
|
||||
return this._createIcon('icon');
|
||||
},
|
||||
|
||||
createShadow: function () {
|
||||
return this.options.shadowUrl ? this._createIcon('shadow') : null;
|
||||
},
|
||||
|
||||
_createIcon: function (name) {
|
||||
var img = this._createImg(this.options[name + 'Url']);
|
||||
this._setIconStyles(img, name);
|
||||
return img;
|
||||
},
|
||||
|
||||
_setIconStyles: function (img, name) {
|
||||
var options = this.options,
|
||||
size = options[name + 'Size'],
|
||||
anchor = options.iconAnchor;
|
||||
|
||||
if (!anchor && size) {
|
||||
anchor = size.divideBy(2, true);
|
||||
}
|
||||
|
||||
if (name === 'shadow' && anchor && options.shadowOffset) {
|
||||
anchor._add(options.shadowOffset);
|
||||
}
|
||||
|
||||
img.className = 'leaflet-marker-' + name + ' ' + options.className;
|
||||
|
||||
if (anchor) {
|
||||
img.style.marginLeft = (-anchor.x) + 'px';
|
||||
img.style.marginTop = (-anchor.y) + 'px';
|
||||
}
|
||||
|
||||
if (size) {
|
||||
img.style.width = size.x + 'px';
|
||||
img.style.height = size.y + 'px';
|
||||
}
|
||||
},
|
||||
|
||||
_createImg: function (src) {
|
||||
var el;
|
||||
if (!L.Browser.ie6) {
|
||||
el = document.createElement('img');
|
||||
el.src = src;
|
||||
} else {
|
||||
el = document.createElement('div');
|
||||
el.style.filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src="' + src + '")';
|
||||
}
|
||||
return el;
|
||||
},
|
||||
|
||||
// new functions start here
|
||||
switchIcon: function (el) {
|
||||
return this._switchIcon('icon', el);
|
||||
},
|
||||
|
||||
switchShadow: function (el) {
|
||||
return this.options.shadowUrl ? this._switchIcon('shadow', el) : null;
|
||||
},
|
||||
|
||||
_switchIcon: function (name, el) {
|
||||
var img = this._switchImg(this.options[name + 'Url'], el);
|
||||
this._setIconStyles(img, name);
|
||||
return img;
|
||||
},
|
||||
|
||||
_switchImg: function (src, el) {
|
||||
if (!L.Browser.ie6) {
|
||||
el.src = src;
|
||||
} else {
|
||||
el.style.filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src="' + src + '")';
|
||||
}
|
||||
return el;
|
||||
}
|
||||
});
|
@ -21,9 +21,33 @@ or see http://www.gnu.org/licenses/agpl.txt.
|
||||
|
||||
OSRM.GUI = {
|
||||
|
||||
// default state
|
||||
visible: true,
|
||||
width: 410,
|
||||
// defaults
|
||||
visible: null,
|
||||
width: null,
|
||||
|
||||
// init GUI
|
||||
init: function() {
|
||||
OSRM.GUI.visible = true;
|
||||
OSRM.GUI.width = document.getElementById("main-wrapper").clientWidth;
|
||||
|
||||
// translate
|
||||
document.getElementById("open-josm").innerHTML = OSRM.loc("OPEN_JOSM");
|
||||
document.getElementById("open-osmbugs").innerHTML = OSRM.loc("OPEN_OSMBUGS");
|
||||
document.getElementById("gui-reset").innerHTML = OSRM.loc("GUI_RESET");
|
||||
document.getElementById("gui-reverse").innerHTML = OSRM.loc("GUI_REVERSE");
|
||||
document.getElementById("gui-option-highlight-nonames-label").innerHTML = OSRM.loc("GUI_HIGHLIGHT_UNNAMED_ROADS");
|
||||
document.getElementById("options-toggle").innerHTML = OSRM.loc("GUI_OPTIONS");
|
||||
document.getElementById("gui-search-source").innerHTML = OSRM.loc("GUI_SEARCH");
|
||||
document.getElementById("gui-search-target").innerHTML = OSRM.loc("GUI_SEARCH");
|
||||
document.getElementById("gui-search-source-label").innerHTML = OSRM.loc("GUI_START")+":";
|
||||
document.getElementById("gui-search-target-label").innerHTML = OSRM.loc("GUI_END")+":";
|
||||
document.getElementById("input-source-name").title = OSRM.loc("GUI_START_TOOLTIP");
|
||||
document.getElementById("input-target-name").title = OSRM.loc("GUI_END_TOOLTIP");
|
||||
document.getElementById("legal-notice").innerHTML = OSRM.loc("GUI_LEGAL_NOTICE");
|
||||
|
||||
document.getElementById('input-source-name').value = OSRM.DEFAULTS.ONLOAD_SOURCE;
|
||||
document.getElementById('input-target-name').value = OSRM.DEFAULTS.ONLOAD_TARGET;
|
||||
},
|
||||
|
||||
// show/hide main-gui
|
||||
toggleMain: function() {
|
||||
|
@ -60,7 +60,7 @@ _onclickResult: function(marker_id, lat, lon) {
|
||||
|
||||
OSRM.G.markers.route[index].show();
|
||||
OSRM.G.markers.route[index].centerView();
|
||||
getRoute(OSRM.C.FULL_DESCRIPTION);
|
||||
OSRM.Routing.getRoute();
|
||||
},
|
||||
|
||||
|
||||
|
@ -66,8 +66,8 @@ OSRM.JSONP = {
|
||||
OSRM.JSONP.fences[id] = undefined; // clean fence
|
||||
}
|
||||
|
||||
OSRM.JSONP.sum[id] += new Number( new Date() - OSRM.JSONP.durations[id] );
|
||||
OSRM.debug.log("[jsonp] response handling: "+id+" "+ (OSRM.JSONP.sum[id]/OSRM.JSONP.counter[id]).toFixed(2) );
|
||||
// OSRM.JSONP.sum[id] += new Number( new Date() - OSRM.JSONP.durations[id] );
|
||||
// OSRM.debug.log("[jsonp] response handling: "+id+" "+ (OSRM.JSONP.sum[id]/OSRM.JSONP.counter[id]).toFixed(2) );
|
||||
};
|
||||
|
||||
// clean DOM (unfortunately, script elements cannot be reused by all browsers)
|
||||
@ -85,12 +85,11 @@ OSRM.JSONP = {
|
||||
// start timeout timer
|
||||
OSRM.JSONP.timers[id] = setTimeout(OSRM.JSONP.timeouts[id], timeout);
|
||||
|
||||
// statistics
|
||||
if(!OSRM.JSONP.durations) { OSRM.JSONP.durations = {}; OSRM.JSONP.counter = {}; OSRM.JSONP.sum = {}; }
|
||||
if(OSRM.JSONP.counter[id]) OSRM.JSONP.counter[id]++; else {OSRM.JSONP.counter[id] = 1;OSRM.JSONP.sum[id] = 0;}
|
||||
OSRM.JSONP.durations[id] = new Date();
|
||||
|
||||
// if(!OSRM.JSONP.durations) { OSRM.JSONP.durations = {}; OSRM.JSONP.counter = {}; OSRM.JSONP.sum = {}; }
|
||||
// if(OSRM.JSONP.counter[id]) OSRM.JSONP.counter[id]++; else {OSRM.JSONP.counter[id] = 1;OSRM.JSONP.sum[id] = 0;}
|
||||
// OSRM.JSONP.durations[id] = new Date();
|
||||
// OSRM.debug.log("[jsonp] init: "+id);
|
||||
|
||||
return true;
|
||||
},
|
||||
|
||||
|
@ -39,12 +39,14 @@ OSRM.loc = OSRM.Localization.translate;
|
||||
// German language support
|
||||
OSRM.Localization["de"] = {
|
||||
//gui
|
||||
"OPEN_JOSM": "JOSM",
|
||||
"OPEN_OSMBUGS": "OSM Bugs",
|
||||
"GUI_START": "Start",
|
||||
"GUI_END": "Ziel",
|
||||
"GUI_RESET": "Reset",
|
||||
"GUI_SEARCH": "Zeigen",
|
||||
"GUI_REVERSE": "Umdrehen",
|
||||
"GUI_OPTIONS": "Optionen",
|
||||
"GUI_OPTIONS": "Kartenwerkzeuge",
|
||||
"GUI_HIGHLIGHT_UNNAMED_ROADS": "Unbenannte Straßen hervorheben",
|
||||
"GUI_START_TOOLTIP": "Startposition eingeben",
|
||||
"GUI_END_TOOLTIP": "Zielposition eingeben",
|
||||
@ -80,12 +82,14 @@ OSRM.Localization["de"] = {
|
||||
// English language support
|
||||
OSRM.Localization["en"] = {
|
||||
//gui
|
||||
"OPEN_JOSM": "JOSM",
|
||||
"OPEN_OSMBUGS": "OSM Bugs",
|
||||
"GUI_START": "Start",
|
||||
"GUI_END": "End",
|
||||
"GUI_RESET": " Reset ",
|
||||
"GUI_SEARCH": " Show ",
|
||||
"GUI_REVERSE": "Reverse",
|
||||
"GUI_OPTIONS": "Options",
|
||||
"GUI_OPTIONS": "Mapping Tools",
|
||||
"GUI_HIGHLIGHT_UNNAMED_ROADS": "Highlight unnamed streets",
|
||||
"GUI_START_TOOLTIP": "Enter start",
|
||||
"GUI_END_TOOLTIP": "Enter destination",
|
||||
|
151
WebContent/OSRM.Map.js
Normal file
151
WebContent/OSRM.Map.js
Normal file
@ -0,0 +1,151 @@
|
||||
/*
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU AFFERO General Public License as published by
|
||||
the Free Software Foundation; either version 3 of the License, or
|
||||
any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
or see http://www.gnu.org/licenses/agpl.txt.
|
||||
*/
|
||||
|
||||
// OSRM map handling
|
||||
// [initialization, event handling, centering relative to UI]
|
||||
|
||||
// will hold the map object
|
||||
OSRM.GLOBALS.map = null;
|
||||
|
||||
|
||||
// map view/model
|
||||
// [extending Leaflet L.Map with setView/fitBounds methods that respect UI visibility]
|
||||
OSRM.MapView = L.Map.extend({
|
||||
setViewUI: function(position, zoom) {
|
||||
if( OSRM.GUI.visible == true ) {
|
||||
var point = OSRM.G.map.project( position, zoom);
|
||||
point.x-=OSRM.GUI.width/2;
|
||||
position = OSRM.G.map.unproject(point,zoom);
|
||||
}
|
||||
this.setView( position, zoom);
|
||||
},
|
||||
fitBoundsUI: function(bounds) {
|
||||
var southwest = bounds.getSouthWest();
|
||||
var northeast = bounds.getNorthEast();
|
||||
var zoom = OSRM.G.map.getBoundsZoom(bounds);
|
||||
var sw_point = OSRM.G.map.project( southwest, zoom);
|
||||
if( OSRM.GUI.visible == true )
|
||||
sw_point.x-=OSRM.GUI.width/2;
|
||||
else
|
||||
sw_point.x-=10;
|
||||
sw_point.y+=10;
|
||||
var ne_point = OSRM.G.map.project( northeast, zoom);
|
||||
ne_point.y-=10;
|
||||
sw_point.x+=10;
|
||||
bounds.extend( OSRM.G.map.unproject(sw_point,zoom) );
|
||||
bounds.extend( OSRM.G.map.unproject(ne_point,zoom) );
|
||||
this.fitBounds( bounds );
|
||||
},
|
||||
getCenterUI: function(unbounded) {
|
||||
var viewHalf = this.getSize();
|
||||
if( OSRM.GUI.visible == true )
|
||||
viewHalf.x += OSRM.GUI.width;
|
||||
var centerPoint = this._getTopLeftPoint().add(viewHalf.divideBy(2));
|
||||
|
||||
return this.unproject(centerPoint, this._zoom, unbounded);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
// map controller
|
||||
// [map initialization, event handling]
|
||||
OSRM.Map = {
|
||||
|
||||
// map initialization
|
||||
init: function() {
|
||||
// check if GUI is initialized!
|
||||
if(OSRM.GUI.visible == null)
|
||||
OSRM.GUI.init();
|
||||
|
||||
// setup tile servers
|
||||
var osmorgURL = 'http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
|
||||
osmorgAttribution = 'Map data © 2011 OpenStreetMap contributors, Imagery © 2011 Mapnik',
|
||||
osmorgOptions = {maxZoom: 18, attribution: osmorgAttribution};
|
||||
|
||||
var osmdeURL = 'http://{s}.tile.openstreetmap.de/tiles/osmde/{z}/{x}/{y}.png',
|
||||
osmdeAttribution = 'Map data © 2011 OpenStreetMap contributors, Imagery © 2011 Mapnik',
|
||||
osmdeOptions = {maxZoom: 18, attribution: osmdeAttribution};
|
||||
|
||||
var mapquestURL = 'http://otile{s}.mqcdn.com/tiles/1.0.0/osm/{z}/{x}/{y}.png',
|
||||
mapquestAttribution = 'Map data © 2011 OpenStreetMap contributors, Imagery © 2011 MapQuest',
|
||||
mapquestOptions = {maxZoom: 18, attribution: mapquestAttribution, subdomains: '1234'};
|
||||
|
||||
var cloudmadeURL = 'http://{s}.tile.cloudmade.com/BC9A493B41014CAABB98F0471D759707/997/256/{z}/{x}/{y}.png',
|
||||
cloudmadeAttribution = 'Map data © 2011 OpenStreetMap contributors, Imagery © 2011 CloudMade',
|
||||
cloudmadeOptions = {maxZoom: 18, attribution: cloudmadeAttribution};
|
||||
|
||||
var osmorg = new L.TileLayer(osmorgURL, osmorgOptions),
|
||||
osmde = new L.TileLayer(osmdeURL, osmdeOptions),
|
||||
mapquest = new L.TileLayer(mapquestURL, mapquestOptions),
|
||||
cloudmade = new L.TileLayer(cloudmadeURL, cloudmadeOptions);
|
||||
|
||||
// setup map
|
||||
OSRM.G.map = new OSRM.MapView('map', {
|
||||
center: new L.LatLng(51.505, -0.09),
|
||||
zoom: 13,
|
||||
zoomAnimation: false, // false: removes animations and hiding of routes during zoom
|
||||
fadeAnimation: false,
|
||||
layers: [osmorg]
|
||||
});
|
||||
|
||||
// add tileservers
|
||||
var baseMaps = {
|
||||
"osm.org": osmorg,
|
||||
"osm.de": osmde,
|
||||
"MapQuest": mapquest,
|
||||
"CloudMade": cloudmade
|
||||
};
|
||||
|
||||
var overlayMaps = {};
|
||||
var layersControl = new L.Control.Layers(baseMaps, overlayMaps);
|
||||
OSRM.G.map.addControl(layersControl);
|
||||
|
||||
// move zoom markers
|
||||
getElementsByClassName(document,'leaflet-control-zoom')[0].style.left=(OSRM.GUI.width+10)+"px";
|
||||
getElementsByClassName(document,'leaflet-control-zoom')[0].style.top="5px";
|
||||
|
||||
// initial map position and zoom
|
||||
var position = new L.LatLng( OSRM.DEFAULTS.ONLOAD_LATITUDE, OSRM.DEFAULTS.ONLOAD_LONGITUDE);
|
||||
OSRM.G.map.setViewUI( position, OSRM.DEFAULTS.ZOOM_LEVEL);
|
||||
|
||||
// map events
|
||||
OSRM.G.map.on('zoomend', OSRM.Map.zoomed );
|
||||
OSRM.G.map.on('click', OSRM.Map.click );
|
||||
OSRM.G.map.on('contextmenu', OSRM.Map.contextmenu );
|
||||
OSRM.G.map.on('mousemove', OSRM.Map.mousemove );
|
||||
},
|
||||
|
||||
// map event handlers
|
||||
zoomed: function(e) { OSRM.Routing.getRoute(); },
|
||||
contextmenu: function(e) {;},
|
||||
mousemove: function(e) { OSRM.Via.drawDragMarker(e); },
|
||||
click: function(e) {
|
||||
if( !OSRM.G.markers.hasSource() ) {
|
||||
var index = OSRM.G.markers.setSource( e.latlng );
|
||||
OSRM.Geocoder.updateAddress( OSRM.C.SOURCE_LABEL, OSRM.C.DO_FALLBACK_TO_LAT_LNG );
|
||||
OSRM.G.markers.route[index].show();
|
||||
OSRM.G.markers.route[index].centerView( OSRM.G.map.getZoom() );
|
||||
OSRM.Routing.getRoute();
|
||||
} else if( !OSRM.G.markers.hasTarget() ) {
|
||||
var index = OSRM.G.markers.setTarget( e.latlng );
|
||||
OSRM.Geocoder.updateAddress( OSRM.C.TARGET_LABEL, OSRM.C.DO_FALLBACK_TO_LAT_LNG );
|
||||
OSRM.G.markers.route[index].show();
|
||||
OSRM.G.markers.route[index].centerView( OSRM.G.map.getZoom() );
|
||||
OSRM.Routing.getRoute();
|
||||
}
|
||||
}
|
||||
};
|
@ -59,16 +59,7 @@ isShown: function() {
|
||||
centerView: function(zoom) {
|
||||
if( zoom == undefined )
|
||||
zoom = OSRM.DEFAULTS.ZOOM_LEVEL;
|
||||
|
||||
var position;
|
||||
if( OSRM.GUI.visible == true ) {
|
||||
var point = OSRM.G.map.project( this.position, zoom);
|
||||
point.x-=OSRM.GUI.width/2;
|
||||
position = OSRM.G.map.unproject(point,zoom);
|
||||
} else {
|
||||
position = this.position;
|
||||
}
|
||||
OSRM.G.map.setView( position, zoom);
|
||||
OSRM.G.map.setViewUI( this.position, zoom );
|
||||
},
|
||||
toString: function() {
|
||||
return "OSRM.Marker: \""+this.label+"\", "+this.position+")";
|
||||
@ -76,26 +67,9 @@ toString: function() {
|
||||
});
|
||||
|
||||
|
||||
// highlight marker class (cannot be dragged)
|
||||
OSRM.HighlightMarker = function( label, style, position) {
|
||||
OSRM.HighlightMarker.prototype.base.constructor.apply( this, arguments );
|
||||
this.label = label ? label : "highlight_marker";
|
||||
|
||||
this.marker.on( 'click', this.onClick );
|
||||
};
|
||||
OSRM.inheritFrom( OSRM.HighlightMarker, OSRM.Marker );
|
||||
OSRM.extend( OSRM.HighlightMarker, {
|
||||
toString: function() {
|
||||
return "OSRM.HighlightMarker: \""+this.label+"\", "+this.position+")";
|
||||
},
|
||||
onClick: function(e) {
|
||||
this.parent.hide();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
// route marker class (draggable, invokes route drawing routines)
|
||||
OSRM.RouteMarker = function ( label, style, position ) {
|
||||
style.baseicon = style.icon;
|
||||
OSRM.RouteMarker.prototype.base.constructor.apply( this, arguments );
|
||||
this.label = label ? label : "route_marker";
|
||||
|
||||
@ -114,16 +88,18 @@ onClick: function(e) {
|
||||
}
|
||||
}
|
||||
|
||||
getRoute(OSRM.C.FULL_DESCRIPTION);
|
||||
OSRM.Routing.getRoute();
|
||||
OSRM.G.markers.highlight.hide();
|
||||
},
|
||||
onDrag: function(e) {
|
||||
this.parent.setPosition( e.target.getLatLng() );
|
||||
getRoute(OSRM.C.NO_DESCRIPTION);
|
||||
if(OSRM.G.markers.route.length>1)
|
||||
OSRM.Routing.getDragRoute();
|
||||
OSRM.Geocoder.updateLocation( this.parent.label );
|
||||
},
|
||||
onDragStart: function(e) {
|
||||
OSRM.G.dragging = true;
|
||||
this.switchIcon(this.options.dragicon);
|
||||
|
||||
// store id of dragged marker
|
||||
for( var i=0; i<OSRM.G.markers.route.length; i++)
|
||||
@ -132,14 +108,17 @@ onDragStart: function(e) {
|
||||
break;
|
||||
}
|
||||
|
||||
if( this.parent != OSRM.G.markers.highlight)
|
||||
OSRM.G.markers.highlight.hide();
|
||||
if (OSRM.G.route.isShown())
|
||||
OSRM.G.route.showOldRoute();
|
||||
},
|
||||
onDragEnd: function(e) {
|
||||
OSRM.G.dragging = false;
|
||||
this.switchIcon(this.options.baseicon);
|
||||
|
||||
this.parent.setPosition( e.target.getLatLng() );
|
||||
getRoute(OSRM.C.FULL_DESCRIPTION);
|
||||
OSRM.Routing.getRoute();
|
||||
if (OSRM.G.route.isShown()) {
|
||||
OSRM.G.route.hideOldRoute();
|
||||
OSRM.G.route.hideUnnamedRoute();
|
||||
@ -154,17 +133,49 @@ toString: function() {
|
||||
});
|
||||
|
||||
|
||||
//drag marker class (draggable, invokes route drawing routines)
|
||||
OSRM.DragMarker = function ( label, style, position ) {
|
||||
OSRM.DragMarker.prototype.base.constructor.apply( this, arguments );
|
||||
this.label = label ? label : "drag_marker";
|
||||
};
|
||||
OSRM.inheritFrom( OSRM.DragMarker, OSRM.RouteMarker );
|
||||
OSRM.extend( OSRM.DragMarker, {
|
||||
onClick: function(e) {
|
||||
this.parent.hide();
|
||||
},
|
||||
onDragStart: function(e) {
|
||||
var new_via_index = OSRM.Via.findViaIndex( e.target.getLatLng() );
|
||||
OSRM.G.markers.route.splice(new_via_index+1,0, this.parent );
|
||||
|
||||
OSRM.RouteMarker.prototype.onDragStart.call(this,e);
|
||||
},
|
||||
onDragEnd: function(e) {
|
||||
OSRM.G.markers.route[OSRM.G.dragid] = new OSRM.RouteMarker(OSRM.C.VIA_LABEL, {draggable:true,icon:OSRM.G.icons['marker-via'],dragicon:OSRM.G.icons['marker-via-drag']}, e.target.getLatLng() );
|
||||
OSRM.G.markers.route[OSRM.G.dragid].show();
|
||||
|
||||
OSRM.RouteMarker.prototype.onDragEnd.call(this,e);
|
||||
this.parent.hide();
|
||||
},
|
||||
toString: function() {
|
||||
return "OSRM.DragMarker: \""+this.label+"\", "+this.position+")";
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
// marker management class (all route markers should only be set and deleted with these routines!)
|
||||
// [this holds the vital information of the route]
|
||||
OSRM.Markers = function() {
|
||||
this.route = new Array();
|
||||
this.highlight = new OSRM.HighlightMarker("highlight", {draggable:false,icon:OSRM.icons['marker-highlight']});;
|
||||
this.highlight = new OSRM.DragMarker("highlight", {draggable:true,icon:OSRM.G.icons['marker-highlight'],dragicon:OSRM.G.icons['marker-highlight-drag']});;
|
||||
this.dragger = new OSRM.DragMarker("drag", {draggable:true,icon:OSRM.G.icons['marker-drag'],dragicon:OSRM.G.icons['marker-drag']});;
|
||||
};
|
||||
OSRM.extend( OSRM.Markers,{
|
||||
removeAll: function() {
|
||||
for(var i=0; i<this.route.length;i++)
|
||||
this.route[i].hide();
|
||||
this.route.splice(0, this.route.length);
|
||||
document.getElementById('delete-source-marker').style.visibility = "hidden";
|
||||
document.getElementById('delete-target-marker').style.visibility = "hidden";
|
||||
},
|
||||
removeVias: function() {
|
||||
// assert correct route array s - v - t
|
||||
@ -177,7 +188,8 @@ setSource: function(position) {
|
||||
if( this.route[0] && this.route[0].label == OSRM.C.SOURCE_LABEL )
|
||||
this.route[0].setPosition(position);
|
||||
else
|
||||
this.route.splice(0,0, new OSRM.RouteMarker(OSRM.C.SOURCE_LABEL, {draggable:true,icon:OSRM.icons['marker-source']}, position));
|
||||
this.route.splice(0,0, new OSRM.RouteMarker(OSRM.C.SOURCE_LABEL, {draggable:true,icon:OSRM.G.icons['marker-source'],dragicon:OSRM.G.icons['marker-source-drag']}, position));
|
||||
document.getElementById('delete-source-marker').style.visibility = "visible";
|
||||
return 0;
|
||||
},
|
||||
setTarget: function(position) {
|
||||
@ -185,7 +197,8 @@ setTarget: function(position) {
|
||||
if( this.route[this.route.length-1] && this.route[ this.route.length-1 ].label == OSRM.C.TARGET_LABEL )
|
||||
this.route[this.route.length-1].setPosition(position);
|
||||
else
|
||||
this.route.splice( this.route.length,0, new OSRM.RouteMarker(OSRM.C.TARGET_LABEL, {draggable:true,icon:OSRM.icons['marker-target']}, position));
|
||||
this.route.splice( this.route.length,0, new OSRM.RouteMarker(OSRM.C.TARGET_LABEL, {draggable:true,icon:OSRM.G.icons['marker-target'],dragicon:OSRM.G.icons['marker-target-drag']}, position));
|
||||
document.getElementById('delete-target-marker').style.visibility = "visible";
|
||||
return this.route.length-1;
|
||||
},
|
||||
setVia: function(id, position) {
|
||||
@ -193,7 +206,7 @@ setVia: function(id, position) {
|
||||
if( this.route.length<2 || id > this.route.length-2 )
|
||||
return -1;
|
||||
|
||||
this.route.splice(id+1,0, new OSRM.RouteMarker(OSRM.C.VIA_LABEL, {draggable:true,icon:OSRM.icons['marker-via']}, position));
|
||||
this.route.splice(id+1,0, new OSRM.RouteMarker(OSRM.C.VIA_LABEL, {draggable:true,icon:OSRM.G.icons['marker-via'],dragicon:OSRM.G.icons['marker-via-drag']}, position));
|
||||
return id+1;
|
||||
},
|
||||
removeMarker: function(id) {
|
||||
@ -206,12 +219,14 @@ removeMarker: function(id) {
|
||||
document.getElementById('input-source-name').value = "";
|
||||
document.getElementById('information-box').innerHTML = "";
|
||||
document.getElementById('information-box-headline').innerHTML = "";
|
||||
document.getElementById('delete-source-marker').style.visibility = "hidden";
|
||||
} else if( id == this.route.length-1 && this.route[ this.route.length-1 ].label == OSRM.C.TARGET_LABEL ) {
|
||||
this.removeVias();
|
||||
id = this.route.length-1;
|
||||
document.getElementById('input-target-name').value = "";
|
||||
document.getElementById('information-box').innerHTML = "";
|
||||
document.getElementById('information-box-headline').innerHTML = "";
|
||||
document.getElementById('delete-target-marker').style.visibility = "hidden";
|
||||
}
|
||||
|
||||
this.route[id].hide();
|
||||
|
@ -27,8 +27,6 @@ OSRM.SimpleRoute = function (label, style) {
|
||||
if(style) this.route.setStyle( style );
|
||||
|
||||
this.shown = false;
|
||||
|
||||
this.route.on('click', this.onClick);
|
||||
};
|
||||
OSRM.extend( OSRM.SimpleRoute,{
|
||||
show: function() {
|
||||
@ -56,26 +54,7 @@ setStyle: function(style) {
|
||||
},
|
||||
centerView: function() {
|
||||
var bounds = new L.LatLngBounds( this.getPositions() );
|
||||
|
||||
var southwest = bounds.getSouthWest();
|
||||
var northeast = bounds.getNorthEast();
|
||||
var zoom = OSRM.G.map.getBoundsZoom(bounds);
|
||||
var sw_point = OSRM.G.map.project( southwest, zoom);
|
||||
if( OSRM.GUI.visible == true )
|
||||
sw_point.x-=OSRM.GUI.width/2;
|
||||
else
|
||||
sw_point.x-=10;
|
||||
sw_point.y+=10;
|
||||
var ne_point = OSRM.G.map.project( northeast, zoom);
|
||||
ne_point.y-=10;
|
||||
sw_point.x+=10;
|
||||
bounds.extend( OSRM.G.map.unproject(sw_point,zoom) );
|
||||
bounds.extend( OSRM.G.map.unproject(ne_point,zoom) );
|
||||
OSRM.G.map.fitBounds( bounds );
|
||||
},
|
||||
onClick: function(e) {
|
||||
if(OSRM.G.route.isRoute())
|
||||
OSRM.Via.findViaPosition( e.latlng );
|
||||
OSRM.g.map.fitBoundsUI( bounds );
|
||||
},
|
||||
toString: function() {
|
||||
return "OSRM.Route("+ this.label + ", " + this.route.getLatLngs().length + " points)";
|
||||
|
@ -44,7 +44,7 @@ _findNearestRouteSegment: function( new_via ) {
|
||||
|
||||
|
||||
// find the correct index among all via nodes to insert the new via node, and insert it
|
||||
findViaPosition: function( new_via_position ) {
|
||||
findViaIndex: function( new_via_position ) {
|
||||
// find route segment that is closest to click position (marked by last index)
|
||||
var nearest_index = OSRM.Via._findNearestRouteSegment( new_via_position );
|
||||
|
||||
@ -60,12 +60,62 @@ findViaPosition: function( new_via_position ) {
|
||||
}
|
||||
|
||||
// add via node
|
||||
var index = OSRM.G.markers.setVia(new_via_index, new_via_position);
|
||||
OSRM.G.markers.route[index].show();
|
||||
|
||||
getRoute(OSRM.C.FULL_DESCRIPTION);
|
||||
|
||||
return new_via_index;
|
||||
},
|
||||
|
||||
|
||||
//function that draws a drag marker
|
||||
dragTimer: new Date(),
|
||||
|
||||
drawDragMarker: function(event) {
|
||||
if( OSRM.G.route.isShown() == false)
|
||||
return;
|
||||
if( OSRM.G.dragging == true )
|
||||
return;
|
||||
|
||||
// throttle computation
|
||||
if( (new Date() - OSRM.Via.dragTimer) < 25 )
|
||||
return;
|
||||
OSRM.Via.dragTimer = new Date();
|
||||
|
||||
// get distance to route
|
||||
var minpoint = OSRM.G.route._current_route.route.closestLayerPoint( event.layerPoint );
|
||||
var min_dist = minpoint._sqDist;
|
||||
|
||||
// get distance to markers
|
||||
var mouse = event.latlng;
|
||||
for(var i=0, size=OSRM.G.markers.route.length; i<size; i++) {
|
||||
if(OSRM.G.markers.route[i].label=='drag')
|
||||
continue;
|
||||
var position = OSRM.G.markers.route[i].getPosition();
|
||||
var dist = OSRM.G.map.project(mouse).distanceTo(OSRM.G.map.project(position));
|
||||
if( dist < 20 )
|
||||
min_dist = 1000;
|
||||
}
|
||||
|
||||
// check whether mouse is over another marker
|
||||
var pos = OSRM.G.map.layerPointToContainerPoint(event.layerPoint);
|
||||
var obj = document.elementFromPoint(pos.x,pos.y);
|
||||
for(var i=0, size=OSRM.G.markers.route.length; i<size; i++) {
|
||||
if(OSRM.G.markers.route[i].label=='drag')
|
||||
continue;
|
||||
if( obj == OSRM.G.markers.route[i].marker._icon)
|
||||
min_dist = 1000;
|
||||
}
|
||||
|
||||
// special care for highlight marker
|
||||
if( OSRM.G.markers.highlight.isShown() ) {
|
||||
if( OSRM.G.map.project(mouse).distanceTo(OSRM.G.map.project( OSRM.G.markers.highlight.getPosition() ) ) < 20 )
|
||||
min_dist = 1000;
|
||||
else if( obj == OSRM.G.markers.highlight.marker._icon)
|
||||
min_dist = 1000;
|
||||
}
|
||||
|
||||
if( min_dist < 400) {
|
||||
OSRM.G.markers.dragger.setPosition( OSRM.G.map.layerPointToLatLng(minpoint) );
|
||||
OSRM.G.markers.dragger.show();
|
||||
} else
|
||||
OSRM.G.markers.dragger.hide();
|
||||
}
|
||||
|
||||
};
|
@ -19,8 +19,8 @@ or see http://www.gnu.org/licenses/agpl.txt.
|
||||
// [has to be loaded before all other OSRM classes]
|
||||
|
||||
var OSRM = {};
|
||||
OSRM.VERSION = '0.1.2';
|
||||
OSRM.DATE = '120319';
|
||||
OSRM.VERSION = '0.1.3';
|
||||
OSRM.DATE = '120402';
|
||||
OSRM.CONSTANTS = {};
|
||||
OSRM.DEFAULTS = {};
|
||||
OSRM.GLOBALS = {};
|
||||
@ -28,17 +28,20 @@ OSRM.G = OSRM.GLOBALS; // abbreviations
|
||||
OSRM.C = OSRM.CONSTANTS;
|
||||
|
||||
|
||||
// [convenience function] declare one class to be a subclass of another class
|
||||
OSRM._inheritFromHelper = function() {};
|
||||
// declare one class to be a subclass of another class
|
||||
// (runs anonymous function to prevent local functions cluttering global namespace)
|
||||
(function() {
|
||||
var _inheritFromHelper = function() {};
|
||||
OSRM.inheritFrom = function( sub_class, base_class ) {
|
||||
OSRM._inheritFromHelper.prototype = base_class.prototype;
|
||||
sub_class.prototype = new OSRM._inheritFromHelper();
|
||||
_inheritFromHelper.prototype = base_class.prototype;
|
||||
sub_class.prototype = new _inheritFromHelper();
|
||||
sub_class.prototype.constructor = sub_class;
|
||||
sub_class.prototype.base = base_class.prototype;
|
||||
};
|
||||
}());
|
||||
|
||||
|
||||
// [convenience function] extend prototypes of a class -> used to add member values and functions
|
||||
// extend prototypes of a class -> used to add member values and functions
|
||||
OSRM.extend = function( target_class, properties ) {
|
||||
for( property in properties ) {
|
||||
target_class.prototype[property] = properties[property];
|
||||
|
@ -21,7 +21,7 @@ or see http://www.gnu.org/licenses/agpl.txt.
|
||||
OSRM.debug = {};
|
||||
|
||||
|
||||
//working functions
|
||||
// access functions
|
||||
OSRM.debug.log = function(text) {
|
||||
OSRM.debug.content.innerHTML += text + "<hr style='border:none; margin:2px; height:1px; color:#F0F0F0; background:#F0F0F0;'/>";
|
||||
OSRM.debug.content.scrollTop = OSRM.debug.content.scrollHeight;
|
||||
|
BIN
WebContent/images/drag.pdf
Normal file
BIN
WebContent/images/drag.pdf
Normal file
Binary file not shown.
BIN
WebContent/images/marker-drag.png
Normal file
BIN
WebContent/images/marker-drag.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 462 B |
BIN
WebContent/images/marker-highlight-drag.png
Normal file
BIN
WebContent/images/marker-highlight-drag.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.7 KiB |
BIN
WebContent/images/marker-source-drag.png
Normal file
BIN
WebContent/images/marker-source-drag.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.7 KiB |
BIN
WebContent/images/marker-target-drag.png
Normal file
BIN
WebContent/images/marker-target-drag.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.6 KiB |
BIN
WebContent/images/marker-via-drag.png
Normal file
BIN
WebContent/images/marker-via-drag.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.7 KiB |
@ -148,8 +148,21 @@ html, body, #map {
|
||||
|
||||
.main-options
|
||||
{
|
||||
position:relative;
|
||||
font-size:10px;
|
||||
}
|
||||
.main-options-left-box
|
||||
{
|
||||
position:absolute;
|
||||
left:5px;
|
||||
top:0px;
|
||||
}
|
||||
.main-options-right-box
|
||||
{
|
||||
position:absolute;
|
||||
right:5px;
|
||||
top:5px;
|
||||
}
|
||||
#options-toggle
|
||||
{
|
||||
cursor:pointer;
|
||||
@ -334,3 +347,24 @@ html, body, #map {
|
||||
background-color:#F4F4F4;
|
||||
color:#FF0000;
|
||||
}
|
||||
|
||||
|
||||
.delete-marker
|
||||
{
|
||||
cursor:pointer;
|
||||
position:absolute;
|
||||
right:5px;
|
||||
top:3px;
|
||||
width:16px;
|
||||
height:16px;
|
||||
background-image:url("images/cancel.png");
|
||||
visibility:hidden;
|
||||
}
|
||||
.delete-marker:hover
|
||||
{
|
||||
background-image:url("images/cancel_hover.png");
|
||||
}
|
||||
.delete-marker:active
|
||||
{
|
||||
background-image:url("images/cancel_active.png");
|
||||
}
|
@ -39,32 +39,38 @@ or see http://www.gnu.org/licenses/agpl.txt.
|
||||
|
||||
<!-- scripts -->
|
||||
<script src="leaflet/leaflet-src.js" type="text/javascript"></script>
|
||||
<script src="L.Bugfixes.js" type="text/javascript"></script>
|
||||
<script src="L.DashedPolyline.js" type="text/javascript"></script>
|
||||
<script src="L.MouseMarker.js" type="text/javascript"></script>
|
||||
<script src="L.SwitchableIcon.js" type="text/javascript"></script>
|
||||
|
||||
<script src="OSRM.base.js" type="text/javascript"></script>
|
||||
<script src="OSRM.config.js" type="text/javascript"></script>
|
||||
<script defer="defer" src="OSRM.debug.js" type="text/javascript"></script>
|
||||
<!-- <script defer="defer" src="OSRM.debug.js" type="text/javascript"></script> -->
|
||||
<script src="main.js" type="text/javascript"></script>
|
||||
|
||||
<script src="OSRM.Browser.js" type="text/javascript"></script>
|
||||
<script src="OSRM.GUI.js" type="text/javascript"></script>
|
||||
<script src="OSRM.JSONP.js" type="text/javascript"></script>
|
||||
<script src="OSRM.Markers.js" type="text/javascript"></script>
|
||||
<script src="OSRM.Route.js" type="text/javascript"></script>
|
||||
<script src="OSRM.Localization.js" type="text/javascript"></script>
|
||||
|
||||
<script src="OSRM.Map.js" type="text/javascript"></script>
|
||||
<script src="OSRM.GUI.js" type="text/javascript"></script>
|
||||
<script src="routing/OSRM.Routing.js" type="text/javascript"></script>
|
||||
<script src="routing/OSRM.RoutingDescription.js" type="text/javascript"></script>
|
||||
<script src="routing/OSRM.RoutingGeometry.js" type="text/javascript"></script>
|
||||
<script src="routing/OSRM.RoutingGUI.js" type="text/javascript"></script>
|
||||
<script src="routing/OSRM.RoutingNoNames.js" type="text/javascript"></script>
|
||||
<script src="OSRM.Via.js" type="text/javascript"></script>
|
||||
<script src="OSRM.Geocoder.js" type="text/javascript"></script>
|
||||
|
||||
<script src="main.js" type="text/javascript"></script>
|
||||
<script src="routing.js" type="text/javascript"></script>
|
||||
<script src="OSRM.Via.js" type="text/javascript"></script>
|
||||
|
||||
<script src="OSRM.Browser.js" type="text/javascript"></script>
|
||||
<script src="OSRM.JSONP.js" type="text/javascript"></script>
|
||||
<script src="OSRM.Localization.js" type="text/javascript"></script>
|
||||
<script src="OSRM.Utils.js" type="text/javascript"></script>
|
||||
</head>
|
||||
|
||||
|
||||
<!-- body -->
|
||||
<body onload="init();">
|
||||
<body onload="OSRM.init();">
|
||||
|
||||
<!--map-->
|
||||
<div id="map"></div>
|
||||
@ -88,14 +94,18 @@ or see http://www.gnu.org/licenses/agpl.txt.
|
||||
<table class="full">
|
||||
<tr>
|
||||
<td id="gui-search-source-label">Start:</td>
|
||||
<td><input id="input-source-name" class="input-box" type="text" maxlength="200" value="" title="Startposition eingeben" onchange="inputChanged(OSRM.C.SOURCE_LABEL);" /></td>
|
||||
<td class="right"><a class="button not-selectable" id="gui-search-source" onclick="showMarker('source')">Zeigen</a></td>
|
||||
<td><div style="position:relative;">
|
||||
<input id="input-source-name" class="input-box" type="text" maxlength="200" value="" title="Startposition eingeben" onchange="OSRM.RoutingGUI.inputChanged(OSRM.C.SOURCE_LABEL);" />
|
||||
<div id="delete-source-marker" class="delete-marker" onclick="OSRM.RoutingGUI.deleteMarker('source')"></div></div></td>
|
||||
<td class="right"><a class="button not-selectable" id="gui-search-source" onclick="OSRM.RoutingGUI.showMarker('source')">Zeigen</a></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td id="gui-search-target-label">Ende:</td>
|
||||
<td><input id="input-target-name" class="input-box" type="text" maxlength="200" value="" title="Zielposition eingeben" onchange="inputChanged(OSRM.C.TARGET_LABEL);" /></td>
|
||||
<td class="right"><a class="button not-selectable" id="gui-search-target" onclick="showMarker('target');">Zeigen</a></td>
|
||||
<td><div style="position:relative;">
|
||||
<input id="input-target-name" class="input-box" type="text" maxlength="200" value="" title="Zielposition eingeben" onchange="OSRM.RoutingGUI.inputChanged(OSRM.C.TARGET_LABEL);" />
|
||||
<div id="delete-target-marker" class="delete-marker" onclick="OSRM.RoutingGUI.deleteMarker('target')"></div></div></td>
|
||||
<td class="right"><a class="button not-selectable" id="gui-search-target" onclick="OSRM.RoutingGUI.showMarker('target');">Zeigen</a></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
@ -103,16 +113,21 @@ or see http://www.gnu.org/licenses/agpl.txt.
|
||||
<div class="vquad"></div>
|
||||
<table style="width:100%">
|
||||
<tr>
|
||||
<td> <a class="button not-selectable" id="gui-reset" onclick="resetRouting();">Reset</a></td>
|
||||
<td class="right"> <a class="button not-selectable" id="gui-reverse" onclick="reverseRouting();">Umdrehen</a></td>
|
||||
<td> <a class="button not-selectable" id="gui-reset" onclick="OSRM.RoutingGUI.resetRouting();">Reset</a></td>
|
||||
<td class="right"> <a class="button not-selectable" id="gui-reverse" onclick="OSRM.RoutingGUI.reverseRouting();">Umdrehen</a></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<!-- options -->
|
||||
<div class="vquad"></div>
|
||||
<div class="main-options not-selectable" id="options-toggle" onclick="OSRM.GUI.toggleOptions()">Options</div>
|
||||
<div class="main-options not-selectable" id="options-box">
|
||||
<input type="checkbox" id="option-highlight-nonames" name="main-options" value="highlight-nonames" onclick="getRoute(OSRM.C.FULL_DESCRIPTION)" /><span id="gui-option-highlight-nonames-label">Unbenannte Straßen hervorheben</span>
|
||||
<span class="main-options" id="options-toggle" onclick="OSRM.GUI.toggleOptions()">Kartenwerkzeuge</span>
|
||||
<div class="main-options" id="options-box">
|
||||
<span class="main-options-left-box">
|
||||
<input type="checkbox" id="option-highlight-nonames" name="main-options" value="highlight-nonames" onclick="OSRM.Routing.getRoute();" /><span id="gui-option-highlight-nonames-label">Unbenannte Straßen hervorheben</span>
|
||||
</span>
|
||||
<span class="main-options-right-box">
|
||||
<a class="button not-selectable" id="open-josm" onclick="OSRM.RoutingGUI.openJOSM();">JOSM</a>
|
||||
<a class="button not-selectable" id="open-osmbugs" onclick="OSRM.RoutingGUI.openOSMBugs();">OSM Bugs</a>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
@ -16,34 +16,38 @@ or see http://www.gnu.org/licenses/agpl.txt.
|
||||
*/
|
||||
|
||||
// OSRM initialization
|
||||
// [initialization of maps, local strings, image prefetching]
|
||||
// [initialization, image prefetching]
|
||||
|
||||
// will hold the Leaflet map object
|
||||
OSRM.GLOBALS.map = null;
|
||||
|
||||
|
||||
// onload initialization routine
|
||||
function init() {
|
||||
prefetchImages();
|
||||
prefetchIcons();
|
||||
OSRM.init = function() {
|
||||
OSRM.prefetchImages();
|
||||
OSRM.prefetchIcons();
|
||||
|
||||
initLocale();
|
||||
initGUI();
|
||||
initMap();
|
||||
initRouting();
|
||||
OSRM.GUI.init();
|
||||
OSRM.Map.init();
|
||||
OSRM.Routing.init();
|
||||
|
||||
// check if the URL contains some GET parameter, e.g. for the route
|
||||
checkURL();
|
||||
}
|
||||
// check if the URL contains some GET parameter, e.g. for showing a route
|
||||
OSRM.checkURL();
|
||||
};
|
||||
|
||||
|
||||
// prefetch images
|
||||
OSRM.images = Array();
|
||||
function prefetchImages() {
|
||||
OSRM.GLOBALS.images = Array();
|
||||
OSRM.prefetchImages = function() {
|
||||
var images = [ 'images/marker-source.png',
|
||||
'images/marker-target.png',
|
||||
'images/marker-via.png',
|
||||
'images/marker-highlight.png',
|
||||
'images/marker-source-drag.png',
|
||||
'images/marker-target-drag.png',
|
||||
'images/marker-via-drag.png',
|
||||
'images/marker-highlight-drag.png',
|
||||
'images/marker-drag.png',
|
||||
'images/cancel.png',
|
||||
'images/cancel_active.png',
|
||||
'images/cancel_hover.png',
|
||||
@ -53,143 +57,42 @@ function prefetchImages() {
|
||||
];
|
||||
|
||||
for(var i=0; i<images.length; i++) {
|
||||
OSRM.images[i] = new Image();
|
||||
OSRM.images[i].src = images[i];
|
||||
}
|
||||
OSRM.G.images[i] = new Image();
|
||||
OSRM.G.images[i].src = images[i];
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// prefetch icons
|
||||
OSRM.icons = Array();
|
||||
function prefetchIcons() {
|
||||
OSRM.GLOBALS.icons = Array();
|
||||
OSRM.prefetchIcons = function() {
|
||||
var images = [ 'marker-source',
|
||||
'marker-target',
|
||||
'marker-via',
|
||||
'marker-highlight',
|
||||
'marker-source-drag',
|
||||
'marker-target-drag',
|
||||
'marker-via-drag',
|
||||
'marker-highlight-drag',
|
||||
'marker-drag'
|
||||
];
|
||||
|
||||
for(var i=0; i<images.length; i++)
|
||||
OSRM.icons[images[i]] = new L.Icon('images/'+images[i]+'.png');
|
||||
}
|
||||
|
||||
|
||||
// init GUI
|
||||
function initGUI() {
|
||||
OSRM.GUI.visible = true;
|
||||
OSRM.GUI.width = document.getElementById("main-wrapper").clientWidth;
|
||||
}
|
||||
|
||||
|
||||
// init localization
|
||||
function initLocale() {
|
||||
document.getElementById("gui-reset").innerHTML = OSRM.loc("GUI_RESET");
|
||||
document.getElementById("gui-reverse").innerHTML = OSRM.loc("GUI_REVERSE");
|
||||
document.getElementById("gui-option-highlight-nonames-label").innerHTML = OSRM.loc("GUI_HIGHLIGHT_UNNAMED_ROADS");
|
||||
document.getElementById("options-toggle").innerHTML = OSRM.loc("GUI_OPTIONS");
|
||||
document.getElementById("gui-search-source").innerHTML = OSRM.loc("GUI_SEARCH");
|
||||
document.getElementById("gui-search-target").innerHTML = OSRM.loc("GUI_SEARCH");
|
||||
document.getElementById("gui-search-source-label").innerHTML = OSRM.loc("GUI_START")+":";
|
||||
document.getElementById("gui-search-target-label").innerHTML = OSRM.loc("GUI_END")+":";
|
||||
document.getElementById("input-source-name").title = OSRM.loc("GUI_START_TOOLTIP");
|
||||
document.getElementById("input-target-name").title = OSRM.loc("GUI_END_TOOLTIP");
|
||||
document.getElementById("legal-notice").innerHTML = OSRM.loc("GUI_LEGAL_NOTICE");
|
||||
|
||||
document.getElementById('input-source-name').value = OSRM.DEFAULTS.ONLOAD_SOURCE;
|
||||
document.getElementById('input-target-name').value = OSRM.DEFAULTS.ONLOAD_TARGET;
|
||||
}
|
||||
|
||||
|
||||
// centering on geolocation
|
||||
function callback_centerOnGeolocation( position ) {
|
||||
OSRM.G.map.setView( new L.LatLng( position.coords.latitude, position.coords.longitude), OSRM.DEFAULTS.ZOOM_LEVEL);
|
||||
}
|
||||
function centerOnGeolocation() {
|
||||
if (navigator.geolocation)
|
||||
navigator.geolocation.getCurrentPosition( callback_centerOnGeolocation );
|
||||
}
|
||||
|
||||
|
||||
// init map
|
||||
function initMap() {
|
||||
// setup tile servers
|
||||
var osmorgURL = 'http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
|
||||
osmorgAttribution = 'Map data © 2011 OpenStreetMap contributors, Imagery © 2011 Mapnik',
|
||||
osmorgOptions = {maxZoom: 18, attribution: osmorgAttribution};
|
||||
|
||||
var osmdeURL = 'http://{s}.tile.openstreetmap.de/tiles/osmde/{z}/{x}/{y}.png',
|
||||
osmdeAttribution = 'Map data © 2011 OpenStreetMap contributors, Imagery © 2011 Mapnik',
|
||||
osmdeOptions = {maxZoom: 18, attribution: osmdeAttribution};
|
||||
|
||||
var mapquestURL = 'http://otile{s}.mqcdn.com/tiles/1.0.0/osm/{z}/{x}/{y}.png',
|
||||
mapquestAttribution = 'Map data © 2011 OpenStreetMap contributors, Imagery © 2011 MapQuest',
|
||||
mapquestOptions = {maxZoom: 18, attribution: mapquestAttribution, subdomains: '1234'};
|
||||
|
||||
var cloudmadeURL = 'http://{s}.tile.cloudmade.com/BC9A493B41014CAABB98F0471D759707/997/256/{z}/{x}/{y}.png',
|
||||
cloudmadeAttribution = 'Map data © 2011 OpenStreetMap contributors, Imagery © 2011 CloudMade',
|
||||
cloudmadeOptions = {maxZoom: 18, attribution: cloudmadeAttribution};
|
||||
|
||||
var osmorg = new L.TileLayer(osmorgURL, osmorgOptions),
|
||||
osmde = new L.TileLayer(osmdeURL, osmdeOptions),
|
||||
mapquest = new L.TileLayer(mapquestURL, mapquestOptions),
|
||||
cloudmade = new L.TileLayer(cloudmadeURL, cloudmadeOptions);
|
||||
|
||||
// setup map
|
||||
OSRM.G.map = new L.Map('map', {
|
||||
center: new L.LatLng(51.505, -0.09),
|
||||
zoom: 13,
|
||||
zoomAnimation: false, // false: removes animations and hiding of routes during zoom
|
||||
fadeAnimation: false,
|
||||
layers: [osmorg]
|
||||
});
|
||||
|
||||
// add tileservers
|
||||
var baseMaps = {
|
||||
"osm.org": osmorg,
|
||||
"osm.de": osmde,
|
||||
"MapQuest": mapquest,
|
||||
"CloudMade": cloudmade
|
||||
for(var i=0; i<images.length; i++) {
|
||||
var icon = {
|
||||
iconUrl: 'images/'+images[i]+'.png', iconSize: new L.Point(25, 41), iconAnchor: new L.Point(13, 41),
|
||||
shadowUrl: L.ROOT_URL + 'images/marker-shadow.png', shadowSize: new L.Point(41, 41),
|
||||
popupAnchor: new L.Point(0, -33)
|
||||
};
|
||||
|
||||
var overlayMaps = {};
|
||||
var layersControl = new L.Control.Layers(baseMaps, overlayMaps);
|
||||
OSRM.G.map.addControl(layersControl);
|
||||
|
||||
// move zoom markers
|
||||
getElementsByClassName(document,'leaflet-control-zoom')[0].style.left=(OSRM.GUI.width+10)+"px";
|
||||
getElementsByClassName(document,'leaflet-control-zoom')[0].style.top="5px";
|
||||
|
||||
// initial map position and zoom
|
||||
var position = new L.LatLng( OSRM.DEFAULTS.ONLOAD_LATITUDE, OSRM.DEFAULTS.ONLOAD_LONGITUDE);
|
||||
if( OSRM.GUI.visible == true ) {
|
||||
var point = OSRM.G.map.project( position, OSRM.DEFAULTS.ZOOM_LEVEL);
|
||||
point.x-=OSRM.GUI.width/2;
|
||||
position = OSRM.G.map.unproject(point,OSRM.DEFAULTS.ZOOM_LEVEL);
|
||||
OSRM.G.icons[images[i]] = new L.SwitchableIcon(icon);
|
||||
}
|
||||
OSRM.G.map.setView( position, OSRM.DEFAULTS.ZOOM_LEVEL);
|
||||
|
||||
// map events
|
||||
OSRM.G.map.on('zoomend', function(e) { getRoute(OSRM.C.FULL_DESCRIPTION); });
|
||||
OSRM.G.map.on('contextmenu', function(e) {});
|
||||
OSRM.G.map.on('click', function(e) {
|
||||
if( !OSRM.G.markers.hasSource() ) {
|
||||
var index = OSRM.G.markers.setSource( e.latlng );
|
||||
OSRM.Geocoder.updateAddress( OSRM.C.SOURCE_LABEL, OSRM.C.DO_FALLBACK_TO_LAT_LNG );
|
||||
OSRM.G.markers.route[index].show();
|
||||
OSRM.G.markers.route[index].centerView( OSRM.G.map.getZoom() );
|
||||
getRoute( OSRM.C.FULL_DESCRIPTION );
|
||||
} else if( !OSRM.G.markers.hasTarget() ) {
|
||||
var index = OSRM.G.markers.setTarget( e.latlng );
|
||||
OSRM.Geocoder.updateAddress( OSRM.C.TARGET_LABEL, OSRM.C.DO_FALLBACK_TO_LAT_LNG );
|
||||
OSRM.G.markers.route[index].show();
|
||||
OSRM.G.markers.route[index].centerView( OSRM.G.map.getZoom() );
|
||||
getRoute( OSRM.C.FULL_DESCRIPTION );
|
||||
}
|
||||
} );
|
||||
}
|
||||
// special values for drag marker
|
||||
OSRM.G.icons['marker-drag'] = new L.SwitchableIcon( {iconUrl: 'images/marker-drag.png', iconSize: new L.Point(18, 18) } );
|
||||
};
|
||||
|
||||
|
||||
// parse URL GET parameters if any exist
|
||||
function checkURL(){
|
||||
OSRM.checkURL = function(){
|
||||
var called_url = document.location.search.substr(1,document.location.search.length);
|
||||
|
||||
// reject messages that are clearly too long or too small
|
||||
@ -269,12 +172,12 @@ function checkURL(){
|
||||
// center on route (support for old links) / move to given view (new behaviour)
|
||||
if(zoom == null || center == null) {
|
||||
var bounds = new L.LatLngBounds( positions );
|
||||
OSRM.G.map.fitBounds( bounds );
|
||||
OSRM.G.map.fitBoundsUI( bounds );
|
||||
} else {
|
||||
OSRM.G.map.setView(center, zoom);
|
||||
}
|
||||
|
||||
// compute route
|
||||
getRoute(OSRM.C.FULL_DESCRIPTION);
|
||||
}
|
||||
OSRM.Routing.getRoute();
|
||||
}
|
||||
};
|
@ -1,490 +0,0 @@
|
||||
/*
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU AFFERO General Public License as published by
|
||||
the Free Software Foundation; either version 3 of the License, or
|
||||
any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
or see http://www.gnu.org/licenses/agpl.txt.
|
||||
*/
|
||||
|
||||
// OSRM routing routines
|
||||
// [management of routing/direction requests and processing of responses]
|
||||
// [TODO: major refactoring scheduled]
|
||||
|
||||
// some variables
|
||||
OSRM.GLOBALS.route = null;
|
||||
OSRM.GLOBALS.markers = null;
|
||||
|
||||
OSRM.CONSTANTS.NO_DESCRIPTION = 0;
|
||||
OSRM.CONSTANTS.FULL_DESCRIPTION = 1;
|
||||
|
||||
OSRM.G.dragging = null;
|
||||
OSRM.GLOBALS.dragid = null;
|
||||
OSRM.GLOBALS.pending = false;
|
||||
OSRM.GLOBALS.pendingTimer = null;
|
||||
|
||||
|
||||
// init routing data structures
|
||||
function initRouting() {
|
||||
OSRM.G.route = new OSRM.Route();
|
||||
OSRM.G.markers = new OSRM.Markers();
|
||||
}
|
||||
|
||||
|
||||
// -- JSONP processing --
|
||||
|
||||
// process JSONP response of routing server
|
||||
function timeoutRouteSimple() {
|
||||
showNoRouteGeometry();
|
||||
showNoRouteDescription();
|
||||
document.getElementById('information-box').innerHTML = "<br><p style='font-size:14px;font-weight:bold;text-align:center;'>"+OSRM.loc("TIMED_OUT")+".<p>";
|
||||
}
|
||||
function timeoutRoute() {
|
||||
showNoRouteGeometry();
|
||||
OSRM.G.route.hideUnnamedRoute();
|
||||
showNoRouteDescription();
|
||||
document.getElementById('information-box').innerHTML = "<br><p style='font-size:14px;font-weight:bold;text-align:center;'>"+OSRM.loc("TIMED_OUT")+".<p>";
|
||||
}
|
||||
function showRouteSimple(response) {
|
||||
if(!response)
|
||||
return;
|
||||
|
||||
if( !OSRM.G.dragging ) // prevent simple routing when no longer dragging
|
||||
return;
|
||||
|
||||
if( response.status == 207) {
|
||||
showNoRouteGeometry();
|
||||
showNoRouteDescription();
|
||||
document.getElementById('information-box').innerHTML = "<br><p style='font-size:14px;font-weight:bold;text-align:center;'>"+OSRM.loc("YOUR_ROUTE_IS_BEING_COMPUTED")+".<p>";
|
||||
} else {
|
||||
showRouteGeometry(response);
|
||||
showRouteDescriptionSimple(response);
|
||||
}
|
||||
updateHints(response);
|
||||
|
||||
// // TODO: hack to process final drag event, if it was fenced, but we are still dragging (alternative approach)
|
||||
// if(OSRM.G.pending) {
|
||||
// clearTimeout(OSRM.G.pendingTimer);
|
||||
// OSRM.G.pendingTimer = setTimeout(timeoutDrag,100);
|
||||
// }
|
||||
}
|
||||
function showRoute(response) {
|
||||
if(!response)
|
||||
return;
|
||||
|
||||
if(response.status == 207) {
|
||||
showNoRouteGeometry();
|
||||
OSRM.G.route.hideUnnamedRoute();
|
||||
showNoRouteDescription();
|
||||
document.getElementById('information-box').innerHTML = "<br><p style='font-size:14px;font-weight:bold;text-align:center;'>"+OSRM.loc("NO_ROUTE_FOUND")+".<p>";
|
||||
} else {
|
||||
showRouteGeometry(response);
|
||||
showRouteNonames(response);
|
||||
showRouteDescription(response);
|
||||
snapRoute();
|
||||
}
|
||||
updateHints(response);
|
||||
}
|
||||
|
||||
|
||||
// show route geometry
|
||||
function showNoRouteGeometry() {
|
||||
var positions = [];
|
||||
for(var i=0; i<OSRM.G.markers.route.length;i++)
|
||||
positions.push( OSRM.G.markers.route[i].getPosition() );
|
||||
|
||||
OSRM.G.route.showRoute(positions, OSRM.Route.NOROUTE);
|
||||
}
|
||||
function showRouteGeometry(response) {
|
||||
OSRM.G.via_points = response.via_points.slice(0);
|
||||
|
||||
var geometry = decodeRouteGeometry(response.route_geometry, 5);
|
||||
|
||||
var points = [];
|
||||
for( var i=0; i < geometry.length; i++) {
|
||||
points.push( new L.LatLng(geometry[i][0], geometry[i][1]) );
|
||||
}
|
||||
OSRM.G.route.showRoute(points, OSRM.Route.ROUTE);
|
||||
}
|
||||
|
||||
|
||||
// route description display (and helper functions)
|
||||
function onClickRouteDescription(geometry_index) {
|
||||
var positions = OSRM.G.route.getPositions();
|
||||
|
||||
OSRM.G.markers.highlight.setPosition( positions[geometry_index] );
|
||||
OSRM.G.markers.highlight.show();
|
||||
OSRM.G.markers.highlight.centerView(OSRM.DEFAULTS.HIGHLIGHT_ZOOM_LEVEL);
|
||||
}
|
||||
function onClickCreateShortcut(src){
|
||||
src += '&z='+ OSRM.G.map.getZoom() + '¢er=' + OSRM.G.map.getCenter().lat + ',' + OSRM.G.map.getCenter().lng;
|
||||
OSRM.JSONP.call(OSRM.DEFAULTS.HOST_SHORTENER_URL+src, showRouteLink, showRouteLink_TimeOut, 2000, 'shortener');
|
||||
document.getElementById('route-prelink').innerHTML = '['+OSRM.loc("GENERATE_LINK_TO_ROUTE")+']';
|
||||
}
|
||||
function showRouteLink(response){
|
||||
document.getElementById('route-prelink').innerHTML = '[<a id="gpx-link" class = "text-selectable" href="' +response.ShortURL+ '">'+response.ShortURL+'</a>]';
|
||||
}
|
||||
function showRouteLink_TimeOut(){
|
||||
document.getElementById('route-prelink').innerHTML = '['+OSRM.loc("LINK_TO_ROUTE_TIMEOUT")+']';
|
||||
}
|
||||
function showRouteDescription(response) {
|
||||
// compute query string
|
||||
var query_string = '?rebuild=1';
|
||||
for(var i=0; i<OSRM.G.markers.route.length; i++)
|
||||
query_string += '&loc=' + OSRM.G.markers.route[i].getLat() + ',' + OSRM.G.markers.route[i].getLng();
|
||||
|
||||
// create link to the route
|
||||
var route_link ='<span class="route-summary" id="route-prelink">[<a id="gpx-link" onclick="onClickCreateShortcut(\'' + OSRM.DEFAULTS.WEBSITE_URL + query_string + '\')">'+OSRM.loc("GET_LINK_TO_ROUTE")+'</a>]</span>';
|
||||
|
||||
// create GPX link
|
||||
var gpx_link = '<span class="route-summary">[<a id="gpx-link" onClick="document.location.href=\'' + OSRM.DEFAULTS.HOST_ROUTING_URL + query_string + '&output=gpx\';">'+OSRM.loc("GPX_FILE")+'</a>]</span>';
|
||||
|
||||
// create route description
|
||||
var route_desc = "";
|
||||
route_desc += '<table class="results-table">';
|
||||
|
||||
for(var i=0; i < response.route_instructions.length; i++){
|
||||
//odd or even ?
|
||||
var rowstyle='results-odd';
|
||||
if(i%2==0) { rowstyle='results-even'; }
|
||||
|
||||
route_desc += '<tr class="'+rowstyle+'">';
|
||||
|
||||
route_desc += '<td class="result-directions">';
|
||||
route_desc += '<img width="18px" src="images/'+getDirectionIcon(response.route_instructions[i][0])+'" alt="" />';
|
||||
route_desc += "</td>";
|
||||
|
||||
route_desc += '<td class="result-items">';
|
||||
route_desc += '<span class="result-item" onclick="onClickRouteDescription('+response.route_instructions[i][3]+')">';
|
||||
route_desc += response.route_instructions[i][0];
|
||||
if( i == 0 )
|
||||
route_desc += ' ' + OSRM.loc( response.route_instructions[i][6] );
|
||||
if( response.route_instructions[i][1] != "" ) {
|
||||
route_desc += ' on ';
|
||||
route_desc += '<b>' + response.route_instructions[i][1] + '</b>';
|
||||
}
|
||||
//route_desc += ' for ';
|
||||
route_desc += '</span>';
|
||||
route_desc += "</td>";
|
||||
|
||||
route_desc += '<td class="result-distance">';
|
||||
if( i != response.route_instructions.length-1 )
|
||||
route_desc += '<b>'+OSRM.Utils.metersToDistance(response.route_instructions[i][2])+'</b>';
|
||||
route_desc += "</td>";
|
||||
|
||||
route_desc += "</tr>";
|
||||
}
|
||||
|
||||
route_desc += '</table>';
|
||||
headline = "";
|
||||
headline += OSRM.loc("ROUTE_DESCRIPTION")+":<br>";
|
||||
headline += '<div style="float:left;width:40%">';
|
||||
headline += "<span class='route-summary'>"
|
||||
+ OSRM.loc("DISTANCE")+": " + OSRM.Utils.metersToDistance(response.route_summary.total_distance)
|
||||
+ "<br>"
|
||||
+ OSRM.loc("DURATION")+": " + OSRM.Utils.secondsToTime(response.route_summary.total_time)
|
||||
+ "</span>";
|
||||
headline += '</div>';
|
||||
headline += '<div style="float:left;text-align:right;width:60%;">'+route_link+'<br>'+gpx_link+'</div>';
|
||||
|
||||
var output = "";
|
||||
output += route_desc;
|
||||
|
||||
document.getElementById('information-box-headline').innerHTML = headline;
|
||||
document.getElementById('information-box').innerHTML = output;
|
||||
}
|
||||
function showRouteDescriptionSimple(response) {
|
||||
headline = OSRM.loc("ROUTE_DESCRIPTION")+":<br>";
|
||||
headline += "<span class='route-summary'>"
|
||||
+ OSRM.loc("DISTANCE")+": " + OSRM.Utils.metersToDistance(response.route_summary.total_distance)
|
||||
+ "<br>"
|
||||
+ OSRM.loc("DURATION")+": " + OSRM.Utils.secondsToTime(response.route_summary.total_time)
|
||||
+ "</span>";
|
||||
headline += '<br><br>';
|
||||
|
||||
document.getElementById('information-box-headline').innerHTML = headline;
|
||||
document.getElementById('information-box').innerHTML = "<br><p style='font-size:14px;font-weight:bold;text-align:center;'>"+OSRM.loc("YOUR_ROUTE_IS_BEING_COMPUTED")+".<p>";
|
||||
}
|
||||
function showNoRouteDescription() {
|
||||
headline = OSRM.loc("ROUTE_DESCRIPTION")+":<br>";
|
||||
headline += "<span class='route-summary'>"
|
||||
+ OSRM.loc("DISTANCE")+": N/A"
|
||||
+ "<br>"
|
||||
+ OSRM.loc("DURATION")+": N/A"
|
||||
+ "</span>";
|
||||
headline += '<br><br>';
|
||||
|
||||
document.getElementById('information-box-headline').innerHTML = headline;
|
||||
document.getElementById('information-box').innerHTML = "<br><p style='font-size:14px;font-weight:bold;text-align:center;'>"+OSRM.loc("YOUR_ROUTE_IS_BEING_COMPUTED")+".<p>";
|
||||
}
|
||||
|
||||
|
||||
// unnamed streets display
|
||||
function showRouteNonames(response) {
|
||||
// do not display unnamed streets?
|
||||
if( document.getElementById('option-highlight-nonames').checked == false) {
|
||||
OSRM.G.route.hideUnnamedRoute();
|
||||
return;
|
||||
}
|
||||
|
||||
// mark geometry positions where unnamed/named streets switch
|
||||
var named = [];
|
||||
for (var i = 0; i < response.route_instructions.length; i++) {
|
||||
if( response.route_instructions[i][1] == '' )
|
||||
named[ response.route_instructions[i][3] ] = false; // no street name
|
||||
else
|
||||
named[ response.route_instructions[i][3] ] = true; // yes street name
|
||||
}
|
||||
|
||||
// aggregate geometry for unnamed streets
|
||||
var geometry = decodeRouteGeometry(response.route_geometry, 5);
|
||||
var is_named = true;
|
||||
var current_positions = [];
|
||||
var all_positions = [];
|
||||
for( var i=0; i < geometry.length; i++) {
|
||||
current_positions.push( new L.LatLng(geometry[i][0], geometry[i][1]) );
|
||||
|
||||
// still named/unnamed?
|
||||
if( (named[i] == is_named || named[i] == undefined) && i != geometry.length-1 )
|
||||
continue;
|
||||
|
||||
// switch between named/unnamed!
|
||||
if(is_named == false)
|
||||
all_positions.push( current_positions );
|
||||
current_positions = [];
|
||||
current_positions.push( new L.LatLng(geometry[i][0], geometry[i][1]) );
|
||||
is_named = named[i];
|
||||
}
|
||||
|
||||
// display unnamed streets
|
||||
OSRM.G.route.showUnnamedRoute(all_positions);
|
||||
}
|
||||
|
||||
|
||||
//-- main function --
|
||||
|
||||
// generate server calls to query routes
|
||||
function getRoute(do_description) {
|
||||
|
||||
// if source or target are not set -> hide route
|
||||
if( OSRM.G.markers.route.length < 2 ) {
|
||||
OSRM.G.route.hideRoute();
|
||||
return;
|
||||
}
|
||||
|
||||
// prepare JSONP call
|
||||
var type = null;
|
||||
var callback = null;
|
||||
var timeout = null;
|
||||
|
||||
var source = OSRM.DEFAULTS.HOST_ROUTING_URL;
|
||||
source += '?z=' + OSRM.G.map.getZoom() + '&output=json' + '&geomformat=cmp';
|
||||
if(OSRM.G.markers.checksum)
|
||||
source += '&checksum=' + OSRM.G.markers.checksum;
|
||||
for(var i=0; i<OSRM.G.markers.route.length; i++) {
|
||||
source += '&loc=' + OSRM.G.markers.route[i].getLat() + ',' + OSRM.G.markers.route[i].getLng();
|
||||
if( OSRM.G.markers.route[i].hint)
|
||||
source += '&hint=' + OSRM.G.markers.route[i].hint;
|
||||
}
|
||||
|
||||
// decide whether it is a dragging call or a normal one
|
||||
if (do_description) {
|
||||
callback = showRoute;
|
||||
timeout = timeoutRoute;
|
||||
source +='&instructions=true';
|
||||
type = 'route';
|
||||
} else {
|
||||
callback = showRouteSimple;
|
||||
timeout = timeoutRouteSimple;
|
||||
source +='&instructions=false';
|
||||
type = 'dragging';
|
||||
}
|
||||
|
||||
// do call
|
||||
var called = OSRM.JSONP.call(source, callback, timeout, OSRM.DEFAULTS.JSONP_TIMEOUT, type);
|
||||
|
||||
// TODO: hack to process final drag event, if it was fenced, but we are still dragging
|
||||
if(called == false && !do_description) {
|
||||
clearTimeout(OSRM.G.pendingTimer);
|
||||
OSRM.G.pendingTimer = setTimeout(timeoutDrag,OSRM.DEFAULTS.JSONP_TIMEOUT);
|
||||
}
|
||||
else {
|
||||
clearTimeout(OSRM.G.pendingTimer);
|
||||
}
|
||||
// // TODO: hack to process final drag event, if it was fenced, but we are still dragging (alternative approach)
|
||||
// if(called == false && !do_description) {
|
||||
// OSRM.G.pending = true;
|
||||
// } else {
|
||||
// clearTimeout(OSRM.G.pendingTimer);
|
||||
// OSRM.G.pending = false;
|
||||
// }
|
||||
}
|
||||
function timeoutDrag() {
|
||||
OSRM.G.markers.route[OSRM.G.dragid].hint = null;
|
||||
getRoute(OSRM.C.NO_DESCRIPTION);
|
||||
}
|
||||
|
||||
|
||||
//-- helper functions --
|
||||
|
||||
//decode compressed route geometry
|
||||
function decodeRouteGeometry(encoded, precision) {
|
||||
precision = Math.pow(10, -precision);
|
||||
var len = encoded.length, index=0, lat=0, lng = 0, array = [];
|
||||
while (index < len) {
|
||||
var b, shift = 0, result = 0;
|
||||
do {
|
||||
b = encoded.charCodeAt(index++) - 63;
|
||||
result |= (b & 0x1f) << shift;
|
||||
shift += 5;
|
||||
} while (b >= 0x20);
|
||||
var dlat = ((result & 1) ? ~(result >> 1) : (result >> 1));
|
||||
lat += dlat;
|
||||
shift = 0;
|
||||
result = 0;
|
||||
do {
|
||||
b = encoded.charCodeAt(index++) - 63;
|
||||
result |= (b & 0x1f) << shift;
|
||||
shift += 5;
|
||||
} while (b >= 0x20);
|
||||
var dlng = ((result & 1) ? ~(result >> 1) : (result >> 1));
|
||||
lng += dlng;
|
||||
array.push([lat * precision, lng * precision]);
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
// update hints of all markers
|
||||
function updateHints(response) {
|
||||
var hint_locations = response.hint_data.locations;
|
||||
OSRM.G.markers.checksum = response.hint_data.checksum;
|
||||
for(var i=0; i<hint_locations.length; i++)
|
||||
OSRM.G.markers.route[i].hint = hint_locations[i];
|
||||
}
|
||||
|
||||
// snap all markers to the received route
|
||||
function snapRoute() {
|
||||
var positions = OSRM.G.route.getPositions();
|
||||
|
||||
OSRM.G.markers.route[0].setPosition( positions[0] );
|
||||
OSRM.G.markers.route[OSRM.G.markers.route.length-1].setPosition( positions[positions.length-1] );
|
||||
for(var i=0; i<OSRM.G.via_points.length; i++)
|
||||
OSRM.G.markers.route[i+1].setPosition( new L.LatLng(OSRM.G.via_points[i][0], OSRM.G.via_points[i][1]) );
|
||||
|
||||
OSRM.Geocoder.updateAddress(OSRM.C.SOURCE_LABEL);
|
||||
OSRM.Geocoder.updateAddress(OSRM.C.TARGET_LABEL);
|
||||
}
|
||||
|
||||
// map driving instructions to icons
|
||||
// [TODO: better implementation, language-safe]
|
||||
function getDirectionIcon(name) {
|
||||
var directions = {
|
||||
"Turn left":"turn-left.png",
|
||||
"Turn right":"turn-right.png",
|
||||
"U-Turn":"u-turn.png",
|
||||
"Head":"continue.png",
|
||||
"Continue":"continue.png",
|
||||
"Turn slight left":"slight-left.png",
|
||||
"Turn slight right":"slight-right.png",
|
||||
"Turn sharp left":"sharp-left.png",
|
||||
"Turn sharp right":"sharp-right.png",
|
||||
"Enter roundabout and leave at first exit":"round-about.png",
|
||||
"Enter roundabout and leave at second exit":"round-about.png",
|
||||
"Enter roundabout and leave at third exit":"round-about.png",
|
||||
"Enter roundabout and leave at fourth exit":"round-about.png",
|
||||
"Enter roundabout and leave at fifth exit":"round-about.png",
|
||||
"Enter roundabout and leave at sixth exit":"round-about.png",
|
||||
"Enter roundabout and leave at seventh exit":"round-about.png",
|
||||
"Enter roundabout and leave at eighth exit":"round-about.png",
|
||||
"Enter roundabout and leave at nineth exit":"round-about.png",
|
||||
"Enter roundabout and leave at tenth exit":"round-about.png",
|
||||
"Enter roundabout and leave at one of the too many exit":"round-about.png",
|
||||
"You have reached your destination":"target.png"
|
||||
};
|
||||
|
||||
if( directions[name] )
|
||||
return directions[name];
|
||||
else
|
||||
return "default.png";
|
||||
}
|
||||
|
||||
|
||||
// -- gui functions --
|
||||
|
||||
// click: button "reset"
|
||||
function resetRouting() {
|
||||
document.getElementById('input-source-name').value = "";
|
||||
document.getElementById('input-target-name').value = "";
|
||||
|
||||
OSRM.G.route.hideAll();
|
||||
OSRM.G.markers.removeAll();
|
||||
OSRM.G.markers.highlight.hide();
|
||||
|
||||
document.getElementById('information-box').innerHTML = "";
|
||||
document.getElementById('information-box-headline').innerHTML = "";
|
||||
|
||||
OSRM.JSONP.reset();
|
||||
}
|
||||
|
||||
// click: button "reverse"
|
||||
function reverseRouting() {
|
||||
// invert input boxes
|
||||
var tmp = document.getElementById("input-source-name").value;
|
||||
document.getElementById("input-source-name").value = document.getElementById("input-target-name").value;
|
||||
document.getElementById("input-target-name").value = tmp;
|
||||
|
||||
// invert route
|
||||
OSRM.G.markers.route.reverse();
|
||||
if(OSRM.G.markers.route.length == 1) {
|
||||
if(OSRM.G.markers.route[0].label == OSRM.C.TARGET_LABEL) {
|
||||
OSRM.G.markers.route[0].label = OSRM.C.SOURCE_LABEL;
|
||||
OSRM.G.markers.route[0].marker.setIcon( new L.Icon('images/marker-source.png') );
|
||||
} else if(OSRM.G.markers.route[0].label == OSRM.C.SOURCE_LABEL) {
|
||||
OSRM.G.markers.route[0].label = OSRM.C.TARGET_LABEL;
|
||||
OSRM.G.markers.route[0].marker.setIcon( new L.Icon('images/marker-target.png') );
|
||||
}
|
||||
} else if(OSRM.G.markers.route.length > 1){
|
||||
OSRM.G.markers.route[0].label = OSRM.C.SOURCE_LABEL;
|
||||
OSRM.G.markers.route[0].marker.setIcon( new L.Icon('images/marker-source.png') );
|
||||
|
||||
OSRM.G.markers.route[OSRM.G.markers.route.length-1].label = OSRM.C.TARGET_LABEL;
|
||||
OSRM.G.markers.route[OSRM.G.markers.route.length-1].marker.setIcon( new L.Icon('images/marker-target.png') );
|
||||
}
|
||||
|
||||
// recompute route
|
||||
if( OSRM.G.route.isShown() ) {
|
||||
getRoute(OSRM.C.FULL_DESCRIPTION);
|
||||
OSRM.G.markers.highlight.hide();
|
||||
} else {
|
||||
document.getElementById('information-box').innerHTML = "";
|
||||
document.getElementById('information-box-headline').innerHTML = "";
|
||||
}
|
||||
}
|
||||
|
||||
// click: button "show"
|
||||
function showMarker(marker_id) {
|
||||
if( OSRM.JSONP.fences["geocoder_source"] || OSRM.JSONP.fences["geocoder_target"] )
|
||||
return;
|
||||
|
||||
if( marker_id == OSRM.C.SOURCE_LABEL && OSRM.G.markers.hasSource() )
|
||||
OSRM.G.markers.route[0].centerView();
|
||||
else if( marker_id == OSRM.C.TARGET_LABEL && OSRM.G.markers.hasTarget() )
|
||||
OSRM.G.markers.route[OSRM.G.markers.route.length-1].centerView();
|
||||
}
|
||||
|
||||
|
||||
// changed: any inputbox (is called when return is pressed [after] or focus is lost [before])
|
||||
function inputChanged(marker_id) {
|
||||
if( marker_id == OSRM.C.SOURCE_LABEL)
|
||||
OSRM.Geocoder.call(OSRM.C.SOURCE_LABEL, document.getElementById('input-source-name').value);
|
||||
else if( marker_id == OSRM.C.TARGET_LABEL)
|
||||
OSRM.Geocoder.call(OSRM.C.TARGET_LABEL, document.getElementById('input-target-name').value);
|
||||
}
|
148
WebContent/routing/OSRM.Routing.js
Normal file
148
WebContent/routing/OSRM.Routing.js
Normal file
@ -0,0 +1,148 @@
|
||||
/*
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU AFFERO General Public License as published by
|
||||
the Free Software Foundation; either version 3 of the License, or
|
||||
any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
or see http://www.gnu.org/licenses/agpl.txt.
|
||||
*/
|
||||
|
||||
// OSRM routing
|
||||
// [management of routing requests and processing of responses]
|
||||
|
||||
// some variables
|
||||
OSRM.GLOBALS.route = null;
|
||||
OSRM.GLOBALS.markers = null;
|
||||
|
||||
OSRM.GLOBALS.dragging = null;
|
||||
OSRM.GLOBALS.dragid = null;
|
||||
OSRM.GLOBALS.pending = false;
|
||||
OSRM.GLOBALS.pendingTimer = null;
|
||||
|
||||
|
||||
OSRM.Routing = {
|
||||
|
||||
// init routing data structures
|
||||
init: function() {
|
||||
OSRM.G.route = new OSRM.Route();
|
||||
OSRM.G.markers = new OSRM.Markers();
|
||||
},
|
||||
|
||||
|
||||
// -- JSONP processing --
|
||||
|
||||
// process JSONP response of routing server
|
||||
timeoutRouteSimple: function() {
|
||||
OSRM.RoutingGeometry.showNA();
|
||||
OSRM.RoutingDescription.showNA( OSRM.loc("TIMED_OUT") );
|
||||
},
|
||||
timeoutRoute: function() {
|
||||
OSRM.RoutingGeometry.showNA();
|
||||
OSRM.RoutingNoNames.showNA();
|
||||
OSRM.RoutingDescription.showNA( OSRM.loc("TIMED_OUT") );
|
||||
},
|
||||
showRouteSimple: function(response) {
|
||||
if(!response)
|
||||
return;
|
||||
if( !OSRM.G.dragging ) // prevent simple routing when no longer dragging
|
||||
return;
|
||||
|
||||
if( response.status == 207) {
|
||||
OSRM.RoutingGeometry.showNA();
|
||||
OSRM.RoutingDescription.showNA( OSRM.loc("YOUR_ROUTE_IS_BEING_COMPUTED") );
|
||||
} else {
|
||||
OSRM.RoutingGeometry.show(response);
|
||||
OSRM.RoutingDescription.showSimple(response);
|
||||
}
|
||||
OSRM.Routing._updateHints(response);
|
||||
|
||||
if(OSRM.G.pending)
|
||||
OSRM.G.pendingTimer = setTimeout(OSRM.Routing.draggingTimeout,1);
|
||||
},
|
||||
showRoute: function(response) {
|
||||
if(!response)
|
||||
return;
|
||||
|
||||
OSRM.G.via_points = response.via_points.slice(0);
|
||||
if(response.status == 207) {
|
||||
OSRM.RoutingGeometry.showNA();
|
||||
OSRM.RoutingNoNames.showNA();
|
||||
OSRM.RoutingDescription.showNA( OSRM.loc("NO_ROUTE_FOUND") );
|
||||
} else {
|
||||
OSRM.RoutingGeometry.show(response);
|
||||
OSRM.RoutingNoNames.show(response);
|
||||
OSRM.RoutingDescription.show(response);
|
||||
OSRM.Routing._snapRoute();
|
||||
}
|
||||
OSRM.Routing._updateHints(response);
|
||||
},
|
||||
|
||||
|
||||
|
||||
//-- main function --
|
||||
|
||||
//generate server calls to query routes
|
||||
getRoute: function() {
|
||||
|
||||
// if source or target are not set -> hide route
|
||||
if( OSRM.G.markers.route.length < 2 ) {
|
||||
OSRM.G.route.hideRoute();
|
||||
return;
|
||||
}
|
||||
|
||||
OSRM.JSONP.call(OSRM.Routing._buildCall()+'&instructions=true', OSRM.Routing.showRoute, OSRM.Routing.timeoutRoute, OSRM.DEFAULTS.JSONP_TIMEOUT, 'route');
|
||||
},
|
||||
getDragRoute: function() {
|
||||
OSRM.G.pending = !OSRM.JSONP.call(OSRM.Routing._buildCall()+'&instructions=false', OSRM.Routing.showRouteSimple, OSRM.Routing.timeoutRouteSimple, OSRM.DEFAULTS.JSONP_TIMEOUT, 'dragging');;
|
||||
},
|
||||
draggingTimeout: function() {
|
||||
OSRM.G.markers.route[OSRM.G.dragid].hint = null;
|
||||
OSRM.Routing.getDragRoute();
|
||||
},
|
||||
|
||||
_buildCall: function() {
|
||||
var source = OSRM.DEFAULTS.HOST_ROUTING_URL;
|
||||
source += '?z=' + OSRM.G.map.getZoom() + '&output=json&geomformat=cmp';
|
||||
if(OSRM.G.markers.checksum)
|
||||
source += '&checksum=' + OSRM.G.markers.checksum;
|
||||
for(var i=0,size=OSRM.G.markers.route.length; i<size; i++) {
|
||||
source += '&loc=' + OSRM.G.markers.route[i].getLat() + ',' + OSRM.G.markers.route[i].getLng();
|
||||
if( OSRM.G.markers.route[i].hint)
|
||||
source += '&hint=' + OSRM.G.markers.route[i].hint;
|
||||
}
|
||||
return source;
|
||||
},
|
||||
|
||||
|
||||
//-- helper functions --
|
||||
|
||||
// update hints of all markers
|
||||
_updateHints: function(response) {
|
||||
var hint_locations = response.hint_data.locations;
|
||||
OSRM.G.markers.checksum = response.hint_data.checksum;
|
||||
for(var i=0; i<hint_locations.length; i++)
|
||||
OSRM.G.markers.route[i].hint = hint_locations[i];
|
||||
},
|
||||
|
||||
// snap all markers to the received route
|
||||
_snapRoute: function() {
|
||||
var positions = OSRM.G.route.getPositions();
|
||||
|
||||
OSRM.G.markers.route[0].setPosition( positions[0] );
|
||||
OSRM.G.markers.route[OSRM.G.markers.route.length-1].setPosition( positions[positions.length-1] );
|
||||
for(var i=0; i<OSRM.G.via_points.length; i++)
|
||||
OSRM.G.markers.route[i+1].setPosition( new L.LatLng(OSRM.G.via_points[i][0], OSRM.G.via_points[i][1]) );
|
||||
|
||||
OSRM.Geocoder.updateAddress(OSRM.C.SOURCE_LABEL);
|
||||
OSRM.Geocoder.updateAddress(OSRM.C.TARGET_LABEL);
|
||||
}
|
||||
|
||||
};
|
174
WebContent/routing/OSRM.RoutingDescription.js
Normal file
174
WebContent/routing/OSRM.RoutingDescription.js
Normal file
@ -0,0 +1,174 @@
|
||||
/*
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU AFFERO General Public License as published by
|
||||
the Free Software Foundation; either version 3 of the License, or
|
||||
any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
or see http://www.gnu.org/licenses/agpl.txt.
|
||||
*/
|
||||
|
||||
// OSRM routing description
|
||||
// [renders routing description and manages events]
|
||||
|
||||
|
||||
OSRM.RoutingDescription = {
|
||||
|
||||
// route description events
|
||||
onClickRouteDescription: function(geometry_index) {
|
||||
var positions = OSRM.G.route.getPositions();
|
||||
|
||||
OSRM.G.markers.highlight.setPosition( positions[geometry_index] );
|
||||
OSRM.G.markers.highlight.show();
|
||||
OSRM.G.markers.highlight.centerView(OSRM.DEFAULTS.HIGHLIGHT_ZOOM_LEVEL);
|
||||
},
|
||||
onClickCreateShortcut: function(src){
|
||||
src += '&z='+ OSRM.G.map.getZoom() + '¢er=' + OSRM.G.map.getCenter().lat + ',' + OSRM.G.map.getCenter().lng;
|
||||
OSRM.JSONP.call(OSRM.DEFAULTS.HOST_SHORTENER_URL+src, OSRM.RoutingDescription.showRouteLink, OSRM.RoutingDescription.showRouteLink_TimeOut, OSRM.DEFAULTS.JSONP_TIMEOUT, 'shortener');
|
||||
document.getElementById('route-prelink').innerHTML = '['+OSRM.loc("GENERATE_LINK_TO_ROUTE")+']';
|
||||
},
|
||||
showRouteLink: function(response){
|
||||
document.getElementById('route-prelink').innerHTML = '[<a id="gpx-link" class = "text-selectable" href="' +response.ShortURL+ '">'+response.ShortURL+'</a>]';
|
||||
// document.getElementById('route-prelink').innerHTML = '[<input class="text-selectable output-box" style="border:none" value="'+response.ShortURL+'" type="text" onfocus="this.select()" readonly="readonly"/>]';
|
||||
},
|
||||
showRouteLink_TimeOut: function(){
|
||||
document.getElementById('route-prelink').innerHTML = '['+OSRM.loc("LINK_TO_ROUTE_TIMEOUT")+']';
|
||||
},
|
||||
|
||||
// handling of routing description
|
||||
show: function(response) {
|
||||
// compute query string
|
||||
var query_string = '?rebuild=1';
|
||||
for(var i=0; i<OSRM.G.markers.route.length; i++)
|
||||
query_string += '&loc=' + OSRM.G.markers.route[i].getLat() + ',' + OSRM.G.markers.route[i].getLng();
|
||||
|
||||
// create link to the route
|
||||
var route_link ='<span class="route-summary" id="route-prelink">[<a id="gpx-link" onclick="OSRM.RoutingDescription.onClickCreateShortcut(\'' + OSRM.DEFAULTS.WEBSITE_URL + query_string + '\')">'+OSRM.loc("GET_LINK_TO_ROUTE")+'</a>]</span>';
|
||||
|
||||
// create GPX link
|
||||
var gpx_link = '<span class="route-summary">[<a id="gpx-link" onClick="document.location.href=\'' + OSRM.DEFAULTS.HOST_ROUTING_URL + query_string + '&output=gpx\';">'+OSRM.loc("GPX_FILE")+'</a>]</span>';
|
||||
|
||||
// create route description
|
||||
var route_desc = "";
|
||||
route_desc += '<table class="results-table">';
|
||||
|
||||
for(var i=0; i < response.route_instructions.length; i++){
|
||||
//odd or even ?
|
||||
var rowstyle='results-odd';
|
||||
if(i%2==0) { rowstyle='results-even'; }
|
||||
|
||||
route_desc += '<tr class="'+rowstyle+'">';
|
||||
|
||||
route_desc += '<td class="result-directions">';
|
||||
route_desc += '<img width="18px" src="images/'+OSRM.RoutingDescription.getDirectionIcon(response.route_instructions[i][0])+'" alt="" />';
|
||||
route_desc += "</td>";
|
||||
|
||||
route_desc += '<td class="result-items">';
|
||||
route_desc += '<span class="result-item" onclick="OSRM.RoutingDescription.onClickRouteDescription('+response.route_instructions[i][3]+')">';
|
||||
route_desc += response.route_instructions[i][0];
|
||||
if( i == 0 )
|
||||
route_desc += ' ' + OSRM.loc( response.route_instructions[i][6] );
|
||||
if( response.route_instructions[i][1] != "" ) {
|
||||
route_desc += ' on ';
|
||||
route_desc += '<b>' + response.route_instructions[i][1] + '</b>';
|
||||
}
|
||||
//route_desc += ' for ';
|
||||
route_desc += '</span>';
|
||||
route_desc += "</td>";
|
||||
|
||||
route_desc += '<td class="result-distance">';
|
||||
if( i != response.route_instructions.length-1 )
|
||||
route_desc += '<b>'+OSRM.Utils.metersToDistance(response.route_instructions[i][2])+'</b>';
|
||||
route_desc += "</td>";
|
||||
|
||||
route_desc += "</tr>";
|
||||
}
|
||||
|
||||
route_desc += '</table>';
|
||||
headline = "";
|
||||
headline += OSRM.loc("ROUTE_DESCRIPTION")+":<br>";
|
||||
headline += '<div style="float:left;width:40%">';
|
||||
headline += "<span class='route-summary'>"
|
||||
+ OSRM.loc("DISTANCE")+": " + OSRM.Utils.metersToDistance(response.route_summary.total_distance)
|
||||
+ "<br>"
|
||||
+ OSRM.loc("DURATION")+": " + OSRM.Utils.secondsToTime(response.route_summary.total_time)
|
||||
+ "</span>";
|
||||
headline += '</div>';
|
||||
headline += '<div style="float:left;text-align:right;width:60%;">'+route_link+'<br>'+gpx_link+'</div>';
|
||||
|
||||
var output = "";
|
||||
output += route_desc;
|
||||
|
||||
document.getElementById('information-box-headline').innerHTML = headline;
|
||||
document.getElementById('information-box').innerHTML = output;
|
||||
},
|
||||
|
||||
// simple description
|
||||
showSimple: function(response) {
|
||||
headline = OSRM.loc("ROUTE_DESCRIPTION")+":<br>";
|
||||
headline += "<span class='route-summary'>"
|
||||
+ OSRM.loc("DISTANCE")+": " + OSRM.Utils.metersToDistance(response.route_summary.total_distance)
|
||||
+ "<br>"
|
||||
+ OSRM.loc("DURATION")+": " + OSRM.Utils.secondsToTime(response.route_summary.total_time)
|
||||
+ "</span>";
|
||||
headline += '<br><br>';
|
||||
|
||||
document.getElementById('information-box-headline').innerHTML = headline;
|
||||
document.getElementById('information-box').innerHTML = "<br><p style='font-size:14px;font-weight:bold;text-align:center;'>"+OSRM.loc("YOUR_ROUTE_IS_BEING_COMPUTED")+".<p>";
|
||||
},
|
||||
|
||||
// no description
|
||||
showNA: function( display_text ) {
|
||||
headline = OSRM.loc("ROUTE_DESCRIPTION")+":<br>";
|
||||
headline += "<span class='route-summary'>"
|
||||
+ OSRM.loc("DISTANCE")+": N/A"
|
||||
+ "<br>"
|
||||
+ OSRM.loc("DURATION")+": N/A"
|
||||
+ "</span>";
|
||||
headline += '<br><br>';
|
||||
|
||||
document.getElementById('information-box-headline').innerHTML = headline;
|
||||
document.getElementById('information-box').innerHTML = "<br><p style='font-size:14px;font-weight:bold;text-align:center;'>"+display_text+".<p>";
|
||||
},
|
||||
|
||||
// map driving instructions to icons
|
||||
// [TODO: language-safe implementation]
|
||||
getDirectionIcon: function(name) {
|
||||
var directions = {
|
||||
"Turn left":"turn-left.png",
|
||||
"Turn right":"turn-right.png",
|
||||
"U-Turn":"u-turn.png",
|
||||
"Head":"continue.png",
|
||||
"Continue":"continue.png",
|
||||
"Turn slight left":"slight-left.png",
|
||||
"Turn slight right":"slight-right.png",
|
||||
"Turn sharp left":"sharp-left.png",
|
||||
"Turn sharp right":"sharp-right.png",
|
||||
"Enter roundabout and leave at first exit":"round-about.png",
|
||||
"Enter roundabout and leave at second exit":"round-about.png",
|
||||
"Enter roundabout and leave at third exit":"round-about.png",
|
||||
"Enter roundabout and leave at fourth exit":"round-about.png",
|
||||
"Enter roundabout and leave at fifth exit":"round-about.png",
|
||||
"Enter roundabout and leave at sixth exit":"round-about.png",
|
||||
"Enter roundabout and leave at seventh exit":"round-about.png",
|
||||
"Enter roundabout and leave at eighth exit":"round-about.png",
|
||||
"Enter roundabout and leave at nineth exit":"round-about.png",
|
||||
"Enter roundabout and leave at tenth exit":"round-about.png",
|
||||
"Enter roundabout and leave at one of the too many exit":"round-about.png",
|
||||
"You have reached your destination":"target.png"
|
||||
};
|
||||
|
||||
if( directions[name] )
|
||||
return directions[name];
|
||||
else
|
||||
return "default.png";
|
||||
}
|
||||
|
||||
};
|
129
WebContent/routing/OSRM.RoutingGUI.js
Normal file
129
WebContent/routing/OSRM.RoutingGUI.js
Normal file
@ -0,0 +1,129 @@
|
||||
/*
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU AFFERO General Public License as published by
|
||||
the Free Software Foundation; either version 3 of the License, or
|
||||
any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
or see http://www.gnu.org/licenses/agpl.txt.
|
||||
*/
|
||||
|
||||
// OSRM routing
|
||||
// [handles GUI events]
|
||||
|
||||
|
||||
OSRM.RoutingGUI = {
|
||||
|
||||
// click: button "reset"
|
||||
resetRouting: function() {
|
||||
document.getElementById('input-source-name').value = "";
|
||||
document.getElementById('input-target-name').value = "";
|
||||
|
||||
OSRM.G.route.hideAll();
|
||||
OSRM.G.markers.removeAll();
|
||||
OSRM.G.markers.highlight.hide();
|
||||
|
||||
document.getElementById('information-box').innerHTML = "";
|
||||
document.getElementById('information-box-headline').innerHTML = "";
|
||||
|
||||
OSRM.JSONP.reset();
|
||||
},
|
||||
|
||||
// click: button "reverse"
|
||||
reverseRouting: function() {
|
||||
// invert input boxes
|
||||
var tmp = document.getElementById("input-source-name").value;
|
||||
document.getElementById("input-source-name").value = document.getElementById("input-target-name").value;
|
||||
document.getElementById("input-target-name").value = tmp;
|
||||
|
||||
// invert route
|
||||
OSRM.G.markers.route.reverse();
|
||||
if(OSRM.G.markers.route.length == 1) {
|
||||
if(OSRM.G.markers.route[0].label == OSRM.C.TARGET_LABEL) {
|
||||
OSRM.G.markers.route[0].label = OSRM.C.SOURCE_LABEL;
|
||||
OSRM.G.markers.route[0].marker.setIcon( new L.Icon('images/marker-source.png') );
|
||||
} else if(OSRM.G.markers.route[0].label == OSRM.C.SOURCE_LABEL) {
|
||||
OSRM.G.markers.route[0].label = OSRM.C.TARGET_LABEL;
|
||||
OSRM.G.markers.route[0].marker.setIcon( new L.Icon('images/marker-target.png') );
|
||||
}
|
||||
} else if(OSRM.G.markers.route.length > 1){
|
||||
OSRM.G.markers.route[0].label = OSRM.C.SOURCE_LABEL;
|
||||
OSRM.G.markers.route[0].marker.setIcon( new L.Icon('images/marker-source.png') );
|
||||
|
||||
OSRM.G.markers.route[OSRM.G.markers.route.length-1].label = OSRM.C.TARGET_LABEL;
|
||||
OSRM.G.markers.route[OSRM.G.markers.route.length-1].marker.setIcon( new L.Icon('images/marker-target.png') );
|
||||
}
|
||||
|
||||
// recompute route
|
||||
if( OSRM.G.route.isShown() ) {
|
||||
OSRM.Routing.getRoute();
|
||||
OSRM.G.markers.highlight.hide();
|
||||
} else {
|
||||
document.getElementById('information-box').innerHTML = "";
|
||||
document.getElementById('information-box-headline').innerHTML = "";
|
||||
}
|
||||
},
|
||||
|
||||
// click: button "show"
|
||||
showMarker: function(marker_id) {
|
||||
if( OSRM.JSONP.fences["geocoder_source"] || OSRM.JSONP.fences["geocoder_target"] )
|
||||
return;
|
||||
|
||||
if( marker_id == OSRM.C.SOURCE_LABEL && OSRM.G.markers.hasSource() )
|
||||
OSRM.G.markers.route[0].centerView();
|
||||
else if( marker_id == OSRM.C.TARGET_LABEL && OSRM.G.markers.hasTarget() )
|
||||
OSRM.G.markers.route[OSRM.G.markers.route.length-1].centerView();
|
||||
},
|
||||
|
||||
|
||||
// changed: any inputbox (is called when return is pressed [after] or focus is lost [before])
|
||||
inputChanged: function(marker_id) {
|
||||
if( marker_id == OSRM.C.SOURCE_LABEL)
|
||||
OSRM.Geocoder.call(OSRM.C.SOURCE_LABEL, document.getElementById('input-source-name').value);
|
||||
else if( marker_id == OSRM.C.TARGET_LABEL)
|
||||
OSRM.Geocoder.call(OSRM.C.TARGET_LABEL, document.getElementById('input-target-name').value);
|
||||
},
|
||||
|
||||
// click: button "open JOSM"
|
||||
openJOSM: function() {
|
||||
var x = OSRM.G.map.getCenterUI();
|
||||
var ydelta = 0.01;
|
||||
var xdelta = ydelta * 2;
|
||||
var p = [ 'left=' + (x.lng - xdelta), 'bottom=' + (x.lat - ydelta), 'right=' + (x.lng + xdelta), 'top=' + (x.lat + ydelta)];
|
||||
var url = 'http://localhost:8111/load_and_zoom?' + p.join('&');
|
||||
|
||||
var frame = L.DomUtil.create('iframe', null, document.body);
|
||||
frame.style.width = frame.style.height = "0px";
|
||||
frame.src = url;
|
||||
frame.onload = function(e) { document.body.removeChild(frame); };
|
||||
},
|
||||
|
||||
//click: button "open OSM Bugs"
|
||||
openOSMBugs: function() {
|
||||
var position = OSRM.G.map.getCenterUI();
|
||||
window.open( "http://osmbugs.org/?lat="+position.lat.toFixed(6)+"&lon="+position.lng.toFixed(6)+"&zoom="+OSRM.G.map.getZoom() );
|
||||
},
|
||||
|
||||
//click: button "delete marker"
|
||||
deleteMarker: function(marker_id) {
|
||||
var id = null;
|
||||
if(marker_id == 'source' && OSRM.G.markers.hasSource() )
|
||||
id = 0;
|
||||
else if(marker_id == 'target' && OSRM.G.markers.hasTarget() )
|
||||
id = OSRM.G.markers.route.length-1;
|
||||
if( id == null)
|
||||
return;
|
||||
|
||||
OSRM.G.markers.removeMarker( id );
|
||||
OSRM.Routing.getRoute();
|
||||
OSRM.G.markers.highlight.hide();
|
||||
}
|
||||
|
||||
};
|
71
WebContent/routing/OSRM.RoutingGeometry.js
Normal file
71
WebContent/routing/OSRM.RoutingGeometry.js
Normal file
@ -0,0 +1,71 @@
|
||||
/*
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU AFFERO General Public License as published by
|
||||
the Free Software Foundation; either version 3 of the License, or
|
||||
any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
or see http://www.gnu.org/licenses/agpl.txt.
|
||||
*/
|
||||
|
||||
// OSRM routing geometry
|
||||
// [renders routing geometry]
|
||||
|
||||
|
||||
OSRM.RoutingGeometry = {
|
||||
|
||||
// show route geometry - if there is a route
|
||||
show: function(response) {
|
||||
var geometry = OSRM.RoutingGeometry._decode(response.route_geometry, 5);
|
||||
|
||||
var positions = [];
|
||||
for( var i=0, size=geometry.length; i < size; i++)
|
||||
positions.push( new L.LatLng(geometry[i][0], geometry[i][1]) );
|
||||
|
||||
OSRM.G.route.showRoute(positions, OSRM.Route.ROUTE);
|
||||
},
|
||||
|
||||
//show route geometry - if there is no route
|
||||
showNA: function() {
|
||||
var positions = [];
|
||||
for(var i=0, size=OSRM.G.markers.route.length; i<size; i++)
|
||||
positions.push( OSRM.G.markers.route[i].getPosition() );
|
||||
|
||||
OSRM.G.route.showRoute(positions, OSRM.Route.NOROUTE);
|
||||
},
|
||||
|
||||
//decode compressed route geometry
|
||||
_decode: function(encoded, precision) {
|
||||
precision = Math.pow(10, -precision);
|
||||
var len = encoded.length, index=0, lat=0, lng = 0, array = [];
|
||||
while (index < len) {
|
||||
var b, shift = 0, result = 0;
|
||||
do {
|
||||
b = encoded.charCodeAt(index++) - 63;
|
||||
result |= (b & 0x1f) << shift;
|
||||
shift += 5;
|
||||
} while (b >= 0x20);
|
||||
var dlat = ((result & 1) ? ~(result >> 1) : (result >> 1));
|
||||
lat += dlat;
|
||||
shift = 0;
|
||||
result = 0;
|
||||
do {
|
||||
b = encoded.charCodeAt(index++) - 63;
|
||||
result |= (b & 0x1f) << shift;
|
||||
shift += 5;
|
||||
} while (b >= 0x20);
|
||||
var dlng = ((result & 1) ? ~(result >> 1) : (result >> 1));
|
||||
lng += dlng;
|
||||
array.push([lat * precision, lng * precision]);
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
};
|
68
WebContent/routing/OSRM.RoutingNoNames.js
Normal file
68
WebContent/routing/OSRM.RoutingNoNames.js
Normal file
@ -0,0 +1,68 @@
|
||||
/*
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU AFFERO General Public License as published by
|
||||
the Free Software Foundation; either version 3 of the License, or
|
||||
any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
or see http://www.gnu.org/licenses/agpl.txt.
|
||||
*/
|
||||
|
||||
// OSRM routing
|
||||
// [renders route segments that are unnamed streets]
|
||||
|
||||
|
||||
OSRM.RoutingNoNames = {
|
||||
|
||||
// displays route segments that are unnamed streets
|
||||
show: function(response) {
|
||||
// do not display unnamed streets?
|
||||
if( document.getElementById('option-highlight-nonames').checked == false) {
|
||||
OSRM.G.route.hideUnnamedRoute();
|
||||
return;
|
||||
}
|
||||
|
||||
// mark geometry positions where unnamed/named streets switch
|
||||
var named = [];
|
||||
for (var i = 0; i < response.route_instructions.length; i++) {
|
||||
if( response.route_instructions[i][1] == '' )
|
||||
named[ response.route_instructions[i][3] ] = false; // no street name
|
||||
else
|
||||
named[ response.route_instructions[i][3] ] = true; // yes street name
|
||||
}
|
||||
|
||||
// aggregate geometry for unnamed streets
|
||||
var geometry = OSRM.RoutingGeometry._decode(response.route_geometry, 5);
|
||||
var is_named = true;
|
||||
var current_positions = [];
|
||||
var all_positions = [];
|
||||
for( var i=0; i < geometry.length; i++) {
|
||||
current_positions.push( new L.LatLng(geometry[i][0], geometry[i][1]) );
|
||||
|
||||
// still named/unnamed?
|
||||
if( (named[i] == is_named || named[i] == undefined) && i != geometry.length-1 )
|
||||
continue;
|
||||
|
||||
// switch between named/unnamed!
|
||||
if(is_named == false)
|
||||
all_positions.push( current_positions );
|
||||
current_positions = [];
|
||||
current_positions.push( new L.LatLng(geometry[i][0], geometry[i][1]) );
|
||||
is_named = named[i];
|
||||
}
|
||||
|
||||
// display unnamed streets
|
||||
OSRM.G.route.showUnnamedRoute(all_positions);
|
||||
},
|
||||
|
||||
showNA: function() {
|
||||
OSRM.G.route.hideUnnamedRoute();
|
||||
}
|
||||
};
|
Loading…
Reference in New Issue
Block a user