From e132ac5c53c0f320debc29e266b957ccd67c7004 Mon Sep 17 00:00:00 2001 From: DennisSchiefer Date: Wed, 28 Mar 2012 12:57:42 +0100 Subject: [PATCH 01/13] moved routing functions to OSRM namespace, added functions to measure JSONP timings --- WebContent/OSRM.Geocoder.js | 2 +- WebContent/OSRM.JSONP.js | 7 +- WebContent/OSRM.Markers.js | 6 +- WebContent/OSRM.Via.js | 2 +- WebContent/main.html | 16 ++-- WebContent/main.js | 12 +-- WebContent/routing.js | 162 ++++++++++++++++++------------------ 7 files changed, 107 insertions(+), 100 deletions(-) diff --git a/WebContent/OSRM.Geocoder.js b/WebContent/OSRM.Geocoder.js index fef263524..bc1a6f14e 100644 --- a/WebContent/OSRM.Geocoder.js +++ b/WebContent/OSRM.Geocoder.js @@ -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(OSRM.C.FULL_DESCRIPTION); }, diff --git a/WebContent/OSRM.JSONP.js b/WebContent/OSRM.JSONP.js index 3a337bd57..430fc8beb 100644 --- a/WebContent/OSRM.JSONP.js +++ b/WebContent/OSRM.JSONP.js @@ -26,6 +26,7 @@ OSRM.JSONP = { callbacks: {}, timeouts: {}, timers: {}, + durations: {}, // default callback routines @@ -50,7 +51,7 @@ OSRM.JSONP = { OSRM.JSONP.fences[id] = undefined; // clean fence } -// OSRM.debug.log("[jsonp] timout handling: "+id); + OSRM.debug.log("[jsonp] timout handling: "+id+" "+ (new Date() - OSRM.JSONP.durations[id]) ); }; // wrap callback function @@ -66,7 +67,7 @@ OSRM.JSONP = { OSRM.JSONP.fences[id] = undefined; // clean fence } -// OSRM.debug.log("[jsonp] response handling: "+id); + OSRM.debug.log("[jsonp] response handling: "+id+" "+ (new Date() - OSRM.JSONP.durations[id]) ); }; // clean DOM (unfortunately, script elements cannot be reused by all browsers) @@ -83,6 +84,7 @@ OSRM.JSONP = { // start timeout timer OSRM.JSONP.timers[id] = setTimeout(OSRM.JSONP.timeouts[id], timeout); + OSRM.JSONP.durations[id] = new Date(); // OSRM.debug.log("[jsonp] init: "+id); return true; @@ -94,5 +96,6 @@ OSRM.JSONP = { OSRM.JSONP.callbacks = {}; OSRM.JSONP.timeouts = {}; OSRM.JSONP.timers = {}; + OSRM.JSONP.durations = {}; } }; \ No newline at end of file diff --git a/WebContent/OSRM.Markers.js b/WebContent/OSRM.Markers.js index 801b2359e..e8fb8256a 100644 --- a/WebContent/OSRM.Markers.js +++ b/WebContent/OSRM.Markers.js @@ -114,12 +114,12 @@ onClick: function(e) { } } - getRoute(OSRM.C.FULL_DESCRIPTION); + OSRM.Routing.getRoute(OSRM.C.FULL_DESCRIPTION); OSRM.G.markers.highlight.hide(); }, onDrag: function(e) { this.parent.setPosition( e.target.getLatLng() ); - getRoute(OSRM.C.NO_DESCRIPTION); + OSRM.Routing.getRoute(OSRM.C.NO_DESCRIPTION); OSRM.Geocoder.updateLocation( this.parent.label ); }, onDragStart: function(e) { @@ -139,7 +139,7 @@ onDragStart: function(e) { onDragEnd: function(e) { OSRM.G.dragging = false; this.parent.setPosition( e.target.getLatLng() ); - getRoute(OSRM.C.FULL_DESCRIPTION); + OSRM.Routing.getRoute(OSRM.C.FULL_DESCRIPTION); if (OSRM.G.route.isShown()) { OSRM.G.route.hideOldRoute(); OSRM.G.route.hideUnnamedRoute(); diff --git a/WebContent/OSRM.Via.js b/WebContent/OSRM.Via.js index d072b9797..e8ab0ee32 100644 --- a/WebContent/OSRM.Via.js +++ b/WebContent/OSRM.Via.js @@ -63,7 +63,7 @@ findViaPosition: function( new_via_position ) { var index = OSRM.G.markers.setVia(new_via_index, new_via_position); OSRM.G.markers.route[index].show(); - getRoute(OSRM.C.FULL_DESCRIPTION); + OSRM.Routing.getRoute(OSRM.C.FULL_DESCRIPTION); return new_via_index; } diff --git a/WebContent/main.html b/WebContent/main.html index c42a10374..696a25d5f 100644 --- a/WebContent/main.html +++ b/WebContent/main.html @@ -44,7 +44,7 @@ or see http://www.gnu.org/licenses/agpl.txt. - + @@ -88,14 +88,14 @@ or see http://www.gnu.org/licenses/agpl.txt. - - + + - - + +
Start:ZeigenZeigen
Ende:ZeigenZeigen
@@ -103,8 +103,8 @@ or see http://www.gnu.org/licenses/agpl.txt.
- - + +
Reset Umdrehen Reset Umdrehen
@@ -112,7 +112,7 @@ or see http://www.gnu.org/licenses/agpl.txt.
Options
- Unbenannte Straßen hervorheben + Unbenannte Straßen hervorheben
diff --git a/WebContent/main.js b/WebContent/main.js index dd97ca4eb..03987f151 100644 --- a/WebContent/main.js +++ b/WebContent/main.js @@ -30,8 +30,8 @@ function init() { initLocale(); initGUI(); initMap(); - initRouting(); - + OSRM.Routing.init(); + // check if the URL contains some GET parameter, e.g. for the route checkURL(); } @@ -168,7 +168,7 @@ function initMap() { 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('zoomend', function(e) { OSRM.Routing.getRoute(OSRM.C.FULL_DESCRIPTION); }); OSRM.G.map.on('contextmenu', function(e) {}); OSRM.G.map.on('click', function(e) { if( !OSRM.G.markers.hasSource() ) { @@ -176,13 +176,13 @@ function initMap() { 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 ); + OSRM.Routing.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 ); + OSRM.Routing.getRoute( OSRM.C.FULL_DESCRIPTION ); } } ); } @@ -275,6 +275,6 @@ function checkURL(){ } // compute route - getRoute(OSRM.C.FULL_DESCRIPTION); + OSRM.Routing.getRoute(OSRM.C.FULL_DESCRIPTION); } } diff --git a/WebContent/routing.js b/WebContent/routing.js index 7a44fd013..1f330fea8 100644 --- a/WebContent/routing.js +++ b/WebContent/routing.js @@ -32,28 +32,30 @@ OSRM.GLOBALS.pending = false; OSRM.GLOBALS.pendingTimer = null; +OSRM.Routing = { + // init routing data structures -function initRouting() { +init: function() { OSRM.G.route = new OSRM.Route(); OSRM.G.markers = new OSRM.Markers(); -} +}, // -- JSONP processing -- // process JSONP response of routing server -function timeoutRouteSimple() { - showNoRouteGeometry(); - showNoRouteDescription(); +timeoutRouteSimple: function() { + OSRM.Routing.showNoRouteGeometry(); + OSRM.Routing.showNoRouteDescription(); document.getElementById('information-box').innerHTML = "

"+OSRM.loc("TIMED_OUT")+".

"; -} -function timeoutRoute() { - showNoRouteGeometry(); +}, +timeoutRoute: function() { + OSRM.Routing.showNoRouteGeometry(); OSRM.G.route.hideUnnamedRoute(); - showNoRouteDescription(); + OSRM.Routing.showNoRouteDescription(); document.getElementById('information-box').innerHTML = "

"+OSRM.loc("TIMED_OUT")+".

"; -} -function showRouteSimple(response) { +}, +showRouteSimple: function(response) { if(!response) return; @@ -61,88 +63,88 @@ function showRouteSimple(response) { return; if( response.status == 207) { - showNoRouteGeometry(); - showNoRouteDescription(); + OSRM.Routing.showNoRouteGeometry(); + OSRM.Routing.showNoRouteDescription(); document.getElementById('information-box').innerHTML = "

"+OSRM.loc("YOUR_ROUTE_IS_BEING_COMPUTED")+".

"; } else { - showRouteGeometry(response); - showRouteDescriptionSimple(response); + OSRM.Routing.showRouteGeometry(response); + OSRM.Routing.showRouteDescriptionSimple(response); } - updateHints(response); + OSRM.Routing.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); +// OSRM.G.pendingTimer = setTimeout(OSRM.Routing.timeoutDrag,100); // } -} -function showRoute(response) { +}, +showRoute: function(response) { if(!response) return; if(response.status == 207) { - showNoRouteGeometry(); + OSRM.Routing.showNoRouteGeometry(); OSRM.G.route.hideUnnamedRoute(); - showNoRouteDescription(); + OSRM.Routing.showNoRouteDescription(); document.getElementById('information-box').innerHTML = "

"+OSRM.loc("NO_ROUTE_FOUND")+".

"; } else { - showRouteGeometry(response); - showRouteNonames(response); - showRouteDescription(response); - snapRoute(); + OSRM.Routing.showRouteGeometry(response); + OSRM.Routing.showRouteNonames(response); + OSRM.Routing.showRouteDescription(response); + OSRM.Routing.snapRoute(); } - updateHints(response); -} + OSRM.Routing.updateHints(response); +}, // show route geometry -function showNoRouteGeometry() { +showNoRouteGeometry: function() { var positions = []; for(var i=0; i'+response.ShortURL+']'; -} -function showRouteLink_TimeOut(){ +}, +showRouteLink_TimeOut: function(){ document.getElementById('route-prelink').innerHTML = '['+OSRM.loc("LINK_TO_ROUTE_TIMEOUT")+']'; -} -function showRouteDescription(response) { +}, +showRouteDescription: function(response) { // compute query string var query_string = '?rebuild=1'; for(var i=0; i'+OSRM.loc("GET_LINK_TO_ROUTE")+']'; + var route_link ='['+OSRM.loc("GET_LINK_TO_ROUTE")+']'; // create GPX link var gpx_link = '['+OSRM.loc("GPX_FILE")+']'; @@ -159,11 +161,11 @@ function showRouteDescription(response) { route_desc += ''; route_desc += ''; - route_desc += ''; + route_desc += ''; route_desc += ""; route_desc += ''; - route_desc += ''; + route_desc += ''; route_desc += response.route_instructions[i][0]; if( i == 0 ) route_desc += ' ' + OSRM.loc( response.route_instructions[i][6] ); @@ -200,8 +202,8 @@ function showRouteDescription(response) { document.getElementById('information-box-headline').innerHTML = headline; document.getElementById('information-box').innerHTML = output; -} -function showRouteDescriptionSimple(response) { +}, +showRouteDescriptionSimple: function(response) { headline = OSRM.loc("ROUTE_DESCRIPTION")+":
"; headline += "" + OSRM.loc("DISTANCE")+": " + OSRM.Utils.metersToDistance(response.route_summary.total_distance) @@ -212,8 +214,8 @@ function showRouteDescriptionSimple(response) { document.getElementById('information-box-headline').innerHTML = headline; document.getElementById('information-box').innerHTML = "

"+OSRM.loc("YOUR_ROUTE_IS_BEING_COMPUTED")+".

"; -} -function showNoRouteDescription() { +}, +showNoRouteDescription: function() { headline = OSRM.loc("ROUTE_DESCRIPTION")+":
"; headline += "" + OSRM.loc("DISTANCE")+": N/A" @@ -224,11 +226,11 @@ function showNoRouteDescription() { document.getElementById('information-box-headline').innerHTML = headline; document.getElementById('information-box').innerHTML = "

"+OSRM.loc("YOUR_ROUTE_IS_BEING_COMPUTED")+".

"; -} +}, // unnamed streets display -function showRouteNonames(response) { +showRouteNonames: function(response) { // do not display unnamed streets? if( document.getElementById('option-highlight-nonames').checked == false) { OSRM.G.route.hideUnnamedRoute(); @@ -245,7 +247,7 @@ function showRouteNonames(response) { } // aggregate geometry for unnamed streets - var geometry = decodeRouteGeometry(response.route_geometry, 5); + var geometry = OSRM.Routing.decodeRouteGeometry(response.route_geometry, 5); var is_named = true; var current_positions = []; var all_positions = []; @@ -266,13 +268,13 @@ function showRouteNonames(response) { // display unnamed streets OSRM.G.route.showUnnamedRoute(all_positions); -} +}, //-- main function -- // generate server calls to query routes -function getRoute(do_description) { +getRoute: function(do_description) { // if source or target are not set -> hide route if( OSRM.G.markers.route.length < 2 ) { @@ -297,13 +299,13 @@ function getRoute(do_description) { // decide whether it is a dragging call or a normal one if (do_description) { - callback = showRoute; - timeout = timeoutRoute; + callback = OSRM.Routing.showRoute; + timeout = OSRM.Routing.timeoutRoute; source +='&instructions=true'; type = 'route'; } else { - callback = showRouteSimple; - timeout = timeoutRouteSimple; + callback = OSRM.Routing.showRouteSimple; + timeout = OSRM.Routing.timeoutRouteSimple; source +='&instructions=false'; type = 'dragging'; } @@ -314,7 +316,7 @@ function getRoute(do_description) { // 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); + OSRM.G.pendingTimer = setTimeout(OSRM.Routing.timeoutDrag,OSRM.DEFAULTS.JSONP_TIMEOUT); } else { clearTimeout(OSRM.G.pendingTimer); @@ -326,17 +328,17 @@ function getRoute(do_description) { // clearTimeout(OSRM.G.pendingTimer); // OSRM.G.pending = false; // } -} -function timeoutDrag() { +}, +timeoutDrag: function() { OSRM.G.markers.route[OSRM.G.dragid].hint = null; - getRoute(OSRM.C.NO_DESCRIPTION); -} + OSRM.Routing.getRoute(OSRM.C.NO_DESCRIPTION); +}, //-- helper functions -- //decode compressed route geometry -function decodeRouteGeometry(encoded, precision) { +decodeRouteGeometry: function(encoded, precision) { precision = Math.pow(10, -precision); var len = encoded.length, index=0, lat=0, lng = 0, array = []; while (index < len) { @@ -360,18 +362,18 @@ function decodeRouteGeometry(encoded, precision) { array.push([lat * precision, lng * precision]); } return array; -} +}, // update hints of all markers -function updateHints(response) { +updateHints: function(response) { var hint_locations = response.hint_data.locations; OSRM.G.markers.checksum = response.hint_data.checksum; for(var i=0; i Date: Wed, 28 Mar 2012 14:06:18 +0100 Subject: [PATCH 02/13] changed OSRM debug to work with IE6, deactivated JSONP timing routines --- WebContent/OSRM.JSONP.js | 16 +++++++++------- WebContent/OSRM.debug.js | 22 +++++++++++----------- WebContent/main.html | 2 +- 3 files changed, 21 insertions(+), 19 deletions(-) diff --git a/WebContent/OSRM.JSONP.js b/WebContent/OSRM.JSONP.js index 430fc8beb..c29e634e6 100644 --- a/WebContent/OSRM.JSONP.js +++ b/WebContent/OSRM.JSONP.js @@ -26,7 +26,6 @@ OSRM.JSONP = { callbacks: {}, timeouts: {}, timers: {}, - durations: {}, // default callback routines @@ -51,7 +50,7 @@ OSRM.JSONP = { OSRM.JSONP.fences[id] = undefined; // clean fence } - OSRM.debug.log("[jsonp] timout handling: "+id+" "+ (new Date() - OSRM.JSONP.durations[id]) ); +// OSRM.debug.log("[jsonp] timout handling: "+id); }; // wrap callback function @@ -67,7 +66,8 @@ OSRM.JSONP = { OSRM.JSONP.fences[id] = undefined; // clean fence } - OSRM.debug.log("[jsonp] response handling: "+id+" "+ (new Date() - OSRM.JSONP.durations[id]) ); +// 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) @@ -84,9 +84,12 @@ OSRM.JSONP = { // start timeout timer OSRM.JSONP.timers[id] = setTimeout(OSRM.JSONP.timeouts[id], timeout); - OSRM.JSONP.durations[id] = new Date(); - -// OSRM.debug.log("[jsonp] init: "+id); + +// 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; }, @@ -96,6 +99,5 @@ OSRM.JSONP = { OSRM.JSONP.callbacks = {}; OSRM.JSONP.timeouts = {}; OSRM.JSONP.timers = {}; - OSRM.JSONP.durations = {}; } }; \ No newline at end of file diff --git a/WebContent/OSRM.debug.js b/WebContent/OSRM.debug.js index 3ef9465a3..be438a1ed 100644 --- a/WebContent/OSRM.debug.js +++ b/WebContent/OSRM.debug.js @@ -21,6 +21,16 @@ or see http://www.gnu.org/licenses/agpl.txt. OSRM.debug = {}; +// access functions +OSRM.debug.log = function(text) { + OSRM.debug.content.innerHTML += text + "


"; + OSRM.debug.content.scrollTop = OSRM.debug.content.scrollHeight; +}; +OSRM.debug.clear = function() { + OSRM.debug.content.innerHTML = ""; +}; + + // add elements to DOM OSRM.debug.init = function() { //create DOM objects for debug output @@ -53,14 +63,4 @@ OSRM.debug.init = function() { if(document.addEventListener) // FF, CH document.addEventListener("DOMContentLoaded", OSRM.debug.init, false); else // IE - OSRM.debug.init(); - - -// working functions -OSRM.debug.log = function(text) { - OSRM.debug.content.innerHTML += text + "
"; - OSRM.debug.content.scrollTop = OSRM.debug.content.scrollHeight; -}; -OSRM.debug.clear = function() { - OSRM.debug.content.innerHTML = ""; -}; + OSRM.debug.init(); \ No newline at end of file diff --git a/WebContent/main.html b/WebContent/main.html index 696a25d5f..2b5ba7740 100644 --- a/WebContent/main.html +++ b/WebContent/main.html @@ -44,7 +44,7 @@ or see http://www.gnu.org/licenses/agpl.txt. - + From c5bd2b0b1dbb2f8d591580d9f9438fdc810cce7c Mon Sep 17 00:00:00 2001 From: DennisSchiefer Date: Wed, 28 Mar 2012 14:30:26 +0100 Subject: [PATCH 03/13] renamed routing.js, encapsulated local helper functions in OSRM.base --- WebContent/{routing.js => OSRM.Routing.js} | 0 WebContent/OSRM.base.js | 13 ++++++++----- WebContent/main.html | 2 +- 3 files changed, 9 insertions(+), 6 deletions(-) rename WebContent/{routing.js => OSRM.Routing.js} (100%) diff --git a/WebContent/routing.js b/WebContent/OSRM.Routing.js similarity index 100% rename from WebContent/routing.js rename to WebContent/OSRM.Routing.js diff --git a/WebContent/OSRM.base.js b/WebContent/OSRM.base.js index 8555c073f..6fab319cd 100644 --- a/WebContent/OSRM.base.js +++ b/WebContent/OSRM.base.js @@ -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]; diff --git a/WebContent/main.html b/WebContent/main.html index 2b5ba7740..c53a8e78f 100644 --- a/WebContent/main.html +++ b/WebContent/main.html @@ -56,7 +56,7 @@ or see http://www.gnu.org/licenses/agpl.txt. - + From 4fe634614660fdb3750efa3f32a3d71daa387d90 Mon Sep 17 00:00:00 2001 From: DennisSchiefer Date: Wed, 28 Mar 2012 15:02:09 +0100 Subject: [PATCH 04/13] reordered styles in main.html, readded default values to GUI, made TODO marker to check whether GUI is initilaized --- WebContent/OSRM.GUI.js | 25 +++++++++++-- WebContent/OSRM.Markers.js | 8 ++--- WebContent/main.html | 15 ++++---- WebContent/main.js | 73 +++++++++++++------------------------- 4 files changed, 58 insertions(+), 63 deletions(-) diff --git a/WebContent/OSRM.GUI.js b/WebContent/OSRM.GUI.js index e2096f664..093e557ce 100644 --- a/WebContent/OSRM.GUI.js +++ b/WebContent/OSRM.GUI.js @@ -20,10 +20,31 @@ or see http://www.gnu.org/licenses/agpl.txt. OSRM.GUI = { - -// default state + +// defaults visible: true, width: 410, + +// init GUI +init: function() { + OSRM.GUI.visible = true; + OSRM.GUI.width = document.getElementById("main-wrapper").clientWidth; + + 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() { diff --git a/WebContent/OSRM.Markers.js b/WebContent/OSRM.Markers.js index e8fb8256a..feaee67b7 100644 --- a/WebContent/OSRM.Markers.js +++ b/WebContent/OSRM.Markers.js @@ -158,7 +158,7 @@ toString: function() { // [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.HighlightMarker("highlight", {draggable:false,icon:OSRM.G.icons['marker-highlight']});; }; OSRM.extend( OSRM.Markers,{ removeAll: function() { @@ -177,7 +177,7 @@ 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']}, position)); return 0; }, setTarget: function(position) { @@ -185,7 +185,7 @@ 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']}, position)); return this.route.length-1; }, setVia: function(id, position) { @@ -193,7 +193,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']}, position)); return id+1; }, removeMarker: function(id) { diff --git a/WebContent/main.html b/WebContent/main.html index c53a8e78f..be1c3c099 100644 --- a/WebContent/main.html +++ b/WebContent/main.html @@ -45,26 +45,25 @@ or see http://www.gnu.org/licenses/agpl.txt. + - - - - - - - + + + + + - +
diff --git a/WebContent/main.js b/WebContent/main.js index 03987f151..c53ca5c08 100644 --- a/WebContent/main.js +++ b/WebContent/main.js @@ -16,30 +16,29 @@ or see http://www.gnu.org/licenses/agpl.txt. */ // OSRM initialization -// [initialization of maps, local strings, image prefetching] +// [initialization of maps, gui, 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(); + OSRM.GUI.init(); OSRM.Routing.init(); + OSRM.initMap(); - // 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', @@ -53,15 +52,15 @@ function prefetchImages() { ]; for(var i=0; i Date: Thu, 29 Mar 2012 14:34:55 +0100 Subject: [PATCH 05/13] extracted OSRM.Map and OSRM.MapView classes, moved centering that respects UI visibility to OSRM.MapView --- WebContent/OSRM.GUI.js | 4 +- WebContent/OSRM.Map.js | 143 +++++++++++++++++++++++++++++++++++++ WebContent/OSRM.Markers.js | 11 +-- WebContent/OSRM.Route.js | 17 +---- WebContent/main.html | 1 + WebContent/main.js | 101 ++------------------------ 6 files changed, 153 insertions(+), 124 deletions(-) create mode 100644 WebContent/OSRM.Map.js diff --git a/WebContent/OSRM.GUI.js b/WebContent/OSRM.GUI.js index 093e557ce..76ec2b682 100644 --- a/WebContent/OSRM.GUI.js +++ b/WebContent/OSRM.GUI.js @@ -22,8 +22,8 @@ or see http://www.gnu.org/licenses/agpl.txt. OSRM.GUI = { // defaults -visible: true, -width: 410, +visible: null, +width: null, // init GUI init: function() { diff --git a/WebContent/OSRM.Map.js b/WebContent/OSRM.Map.js new file mode 100644 index 000000000..91a4740ab --- /dev/null +++ b/WebContent/OSRM.Map.js @@ -0,0 +1,143 @@ +/* +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 ); + } +}); + + +// 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('click', OSRM.Map.mousemove ); +}, + +// map event handlers +zoomed: function(e) { OSRM.Routing.getRoute(OSRM.C.FULL_DESCRIPTION); }, +contextmenu: function(e) {;}, +mousemove: function(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( 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() ); + OSRM.Routing.getRoute( OSRM.C.FULL_DESCRIPTION ); + } +} +}; \ No newline at end of file diff --git a/WebContent/OSRM.Markers.js b/WebContent/OSRM.Markers.js index feaee67b7..71ae6f7d2 100644 --- a/WebContent/OSRM.Markers.js +++ b/WebContent/OSRM.Markers.js @@ -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+")"; diff --git a/WebContent/OSRM.Route.js b/WebContent/OSRM.Route.js index 19810636c..2750f33f9 100644 --- a/WebContent/OSRM.Route.js +++ b/WebContent/OSRM.Route.js @@ -56,22 +56,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 ); + OSRM.g.map.fitBoundsUI( bounds ); }, onClick: function(e) { if(OSRM.G.route.isRoute()) diff --git a/WebContent/main.html b/WebContent/main.html index be1c3c099..b52aebf1b 100644 --- a/WebContent/main.html +++ b/WebContent/main.html @@ -50,6 +50,7 @@ or see http://www.gnu.org/licenses/agpl.txt. + diff --git a/WebContent/main.js b/WebContent/main.js index c53ca5c08..a7140c69f 100644 --- a/WebContent/main.js +++ b/WebContent/main.js @@ -16,7 +16,7 @@ or see http://www.gnu.org/licenses/agpl.txt. */ // OSRM initialization -// [initialization of maps, gui, image prefetching] +// [initialization, image prefetching] // will hold the Leaflet map object OSRM.GLOBALS.map = null; @@ -28,8 +28,8 @@ OSRM.init = function() { OSRM.prefetchIcons(); OSRM.GUI.init(); - OSRM.Routing.init(); - OSRM.initMap(); + OSRM.Map.init(); + OSRM.Routing.init(); // check if the URL contains some GET parameter, e.g. for showing a route OSRM.checkURL(); @@ -72,97 +72,6 @@ OSRM.prefetchIcons = function() { }; -// 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 -OSRM.initMap = function() { - // TODO: check if GUI is initialized! - - // 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 - }; - - 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.map.setView( position, OSRM.DEFAULTS.ZOOM_LEVEL); - - // map events - OSRM.G.map.on('zoomend', function(e) { OSRM.Routing.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() ); - OSRM.Routing.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() ); - OSRM.Routing.getRoute( OSRM.C.FULL_DESCRIPTION ); - } - } ); -}; - - // parse URL GET parameters if any exist OSRM.checkURL = function(){ var called_url = document.location.search.substr(1,document.location.search.length); @@ -244,9 +153,9 @@ OSRM.checkURL = function(){ // 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); + OSRM.g.map.setView(center, zoom); } // compute route From fd3cf02af4f3369252f1cec2c1a11e0f996eb715 Mon Sep 17 00:00:00 2001 From: DennisSchiefer Date: Thu, 29 Mar 2012 16:55:12 +0100 Subject: [PATCH 06/13] complete restructure of OSRM.Routing --- WebContent/OSRM.Geocoder.js | 2 +- WebContent/OSRM.Map.js | 6 +- WebContent/OSRM.Markers.js | 7 +- WebContent/OSRM.Routing.js | 45 +++-- WebContent/OSRM.Via.js | 2 +- WebContent/main.html | 20 +- WebContent/main.js | 2 +- WebContent/routing/OSRM.Routing.js | 148 +++++++++++++++ WebContent/routing/OSRM.RoutingDescription.js | 173 ++++++++++++++++++ WebContent/routing/OSRM.RoutingGUI.js | 94 ++++++++++ WebContent/routing/OSRM.RoutingGeometry.js | 71 +++++++ WebContent/routing/OSRM.RoutingNoNames.js | 68 +++++++ 12 files changed, 608 insertions(+), 30 deletions(-) create mode 100644 WebContent/routing/OSRM.Routing.js create mode 100644 WebContent/routing/OSRM.RoutingDescription.js create mode 100644 WebContent/routing/OSRM.RoutingGUI.js create mode 100644 WebContent/routing/OSRM.RoutingGeometry.js create mode 100644 WebContent/routing/OSRM.RoutingNoNames.js diff --git a/WebContent/OSRM.Geocoder.js b/WebContent/OSRM.Geocoder.js index bc1a6f14e..6896d702c 100644 --- a/WebContent/OSRM.Geocoder.js +++ b/WebContent/OSRM.Geocoder.js @@ -60,7 +60,7 @@ _onclickResult: function(marker_id, lat, lon) { OSRM.G.markers.route[index].show(); OSRM.G.markers.route[index].centerView(); - OSRM.Routing.getRoute(OSRM.C.FULL_DESCRIPTION); + OSRM.Routing.getRoute(); }, diff --git a/WebContent/OSRM.Map.js b/WebContent/OSRM.Map.js index 91a4740ab..727ad35aa 100644 --- a/WebContent/OSRM.Map.js +++ b/WebContent/OSRM.Map.js @@ -122,7 +122,7 @@ init: function() { }, // map event handlers -zoomed: function(e) { OSRM.Routing.getRoute(OSRM.C.FULL_DESCRIPTION); }, +zoomed: function(e) { OSRM.Routing.getRoute(); }, contextmenu: function(e) {;}, mousemove: function(e) {;}, click: function(e) { @@ -131,13 +131,13 @@ click: function(e) { 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( OSRM.C.FULL_DESCRIPTION ); + 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( OSRM.C.FULL_DESCRIPTION ); + OSRM.Routing.getRoute(); } } }; \ No newline at end of file diff --git a/WebContent/OSRM.Markers.js b/WebContent/OSRM.Markers.js index 71ae6f7d2..f7395ff5e 100644 --- a/WebContent/OSRM.Markers.js +++ b/WebContent/OSRM.Markers.js @@ -105,12 +105,13 @@ onClick: function(e) { } } - OSRM.Routing.getRoute(OSRM.C.FULL_DESCRIPTION); + OSRM.Routing.getRoute(); OSRM.G.markers.highlight.hide(); }, onDrag: function(e) { this.parent.setPosition( e.target.getLatLng() ); - OSRM.Routing.getRoute(OSRM.C.NO_DESCRIPTION); + if(OSRM.G.markers.route.length>1) + OSRM.Routing.getDragRoute(); OSRM.Geocoder.updateLocation( this.parent.label ); }, onDragStart: function(e) { @@ -130,7 +131,7 @@ onDragStart: function(e) { onDragEnd: function(e) { OSRM.G.dragging = false; this.parent.setPosition( e.target.getLatLng() ); - OSRM.Routing.getRoute(OSRM.C.FULL_DESCRIPTION); + OSRM.Routing.getRoute(); if (OSRM.G.route.isShown()) { OSRM.G.route.hideOldRoute(); OSRM.G.route.hideUnnamedRoute(); diff --git a/WebContent/OSRM.Routing.js b/WebContent/OSRM.Routing.js index 1f330fea8..9ef99968c 100644 --- a/WebContent/OSRM.Routing.js +++ b/WebContent/OSRM.Routing.js @@ -70,13 +70,13 @@ showRouteSimple: function(response) { OSRM.Routing.showRouteGeometry(response); OSRM.Routing.showRouteDescriptionSimple(response); } - OSRM.Routing.updateHints(response); + OSRM.Routing._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(OSRM.Routing.timeoutDrag,100); -// } + // 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(OSRM.Routing.draggingTimeout,1); + } }, showRoute: function(response) { if(!response) @@ -91,16 +91,16 @@ showRoute: function(response) { OSRM.Routing.showRouteGeometry(response); OSRM.Routing.showRouteNonames(response); OSRM.Routing.showRouteDescription(response); - OSRM.Routing.snapRoute(); + OSRM.Routing._snapRoute(); } - OSRM.Routing.updateHints(response); + OSRM.Routing._updateHints(response); }, // show route geometry showNoRouteGeometry: function() { var positions = []; - for(var i=0; i - + + + + + @@ -88,14 +92,14 @@ or see http://www.gnu.org/licenses/agpl.txt. - - + + - - + +
Start:ZeigenZeigen
Ende:ZeigenZeigen
@@ -103,8 +107,8 @@ or see http://www.gnu.org/licenses/agpl.txt.
- - + +
Reset Umdrehen Reset Umdrehen
@@ -112,7 +116,7 @@ or see http://www.gnu.org/licenses/agpl.txt.
Options
- Unbenannte Straßen hervorheben + Unbenannte Straßen hervorheben
diff --git a/WebContent/main.js b/WebContent/main.js index a7140c69f..0b4eaf714 100644 --- a/WebContent/main.js +++ b/WebContent/main.js @@ -159,6 +159,6 @@ OSRM.checkURL = function(){ } // compute route - OSRM.Routing.getRoute(OSRM.C.FULL_DESCRIPTION); + OSRM.Routing.getRoute(); } }; \ No newline at end of file diff --git a/WebContent/routing/OSRM.Routing.js b/WebContent/routing/OSRM.Routing.js new file mode 100644 index 000000000..ed5b8fd8e --- /dev/null +++ b/WebContent/routing/OSRM.Routing.js @@ -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'+response.ShortURL+']'; +}, +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.loc("GET_LINK_TO_ROUTE")+']'; + + // create GPX link + var gpx_link = '['+OSRM.loc("GPX_FILE")+']'; + + // create route description + var route_desc = ""; + route_desc += ''; + + 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 += ''; + + route_desc += '"; + + route_desc += '"; + + route_desc += '"; + + route_desc += ""; + } + + route_desc += '
'; + route_desc += ''; + route_desc += "'; + route_desc += ''; + 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 += '' + response.route_instructions[i][1] + ''; + } + //route_desc += ' for '; + route_desc += ''; + route_desc += "'; + if( i != response.route_instructions.length-1 ) + route_desc += ''+OSRM.Utils.metersToDistance(response.route_instructions[i][2])+''; + route_desc += "
'; + headline = ""; + headline += OSRM.loc("ROUTE_DESCRIPTION")+":
"; + headline += '
'; + headline += "" + + OSRM.loc("DISTANCE")+": " + OSRM.Utils.metersToDistance(response.route_summary.total_distance) + + "
" + + OSRM.loc("DURATION")+": " + OSRM.Utils.secondsToTime(response.route_summary.total_time) + + "
"; + headline += '
'; + headline += '
'+route_link+'
'+gpx_link+'
'; + + 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")+":
"; + headline += "" + + OSRM.loc("DISTANCE")+": " + OSRM.Utils.metersToDistance(response.route_summary.total_distance) + + "
" + + OSRM.loc("DURATION")+": " + OSRM.Utils.secondsToTime(response.route_summary.total_time) + + "
"; + headline += '

'; + + document.getElementById('information-box-headline').innerHTML = headline; + document.getElementById('information-box').innerHTML = "

"+OSRM.loc("YOUR_ROUTE_IS_BEING_COMPUTED")+".

"; +}, + +// no description +showNA: function( display_text ) { + headline = OSRM.loc("ROUTE_DESCRIPTION")+":
"; + headline += "" + + OSRM.loc("DISTANCE")+": N/A" + + "
" + + OSRM.loc("DURATION")+": N/A" + + "
"; + headline += '

'; + + document.getElementById('information-box-headline').innerHTML = headline; + document.getElementById('information-box').innerHTML = "

"+display_text+".

"; +}, + +// 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"; +} + +}; \ No newline at end of file diff --git a/WebContent/routing/OSRM.RoutingGUI.js b/WebContent/routing/OSRM.RoutingGUI.js new file mode 100644 index 000000000..ea5329270 --- /dev/null +++ b/WebContent/routing/OSRM.RoutingGUI.js @@ -0,0 +1,94 @@ +/* +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); +} + +}; \ No newline at end of file diff --git a/WebContent/routing/OSRM.RoutingGeometry.js b/WebContent/routing/OSRM.RoutingGeometry.js new file mode 100644 index 000000000..adfdca2e1 --- /dev/null +++ b/WebContent/routing/OSRM.RoutingGeometry.js @@ -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= 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; +} + +}; \ No newline at end of file diff --git a/WebContent/routing/OSRM.RoutingNoNames.js b/WebContent/routing/OSRM.RoutingNoNames.js new file mode 100644 index 000000000..1d67dac0b --- /dev/null +++ b/WebContent/routing/OSRM.RoutingNoNames.js @@ -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(); +} +}; \ No newline at end of file From 007dd19ceceaef523ac0f0da4f167462f8e3c2a1 Mon Sep 17 00:00:00 2001 From: DennisSchiefer Date: Fri, 30 Mar 2012 10:10:51 +0100 Subject: [PATCH 07/13] added buttons to switch to JOSM and OSM Bugs, added getCenter function that respects UI visibility --- WebContent/OSRM.GUI.js | 3 +++ WebContent/OSRM.Localization.js | 8 ++++++-- WebContent/OSRM.Map.js | 8 ++++++++ WebContent/main.css | 13 +++++++++++++ WebContent/main.html | 15 ++++++++++----- WebContent/routing/OSRM.Routing.js | 2 +- WebContent/routing/OSRM.RoutingGUI.js | 21 +++++++++++++++++++++ 7 files changed, 62 insertions(+), 8 deletions(-) diff --git a/WebContent/OSRM.GUI.js b/WebContent/OSRM.GUI.js index 76ec2b682..b1ede611b 100644 --- a/WebContent/OSRM.GUI.js +++ b/WebContent/OSRM.GUI.js @@ -30,6 +30,9 @@ 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"); diff --git a/WebContent/OSRM.Localization.js b/WebContent/OSRM.Localization.js index 110d16bbb..6d377f38a 100644 --- a/WebContent/OSRM.Localization.js +++ b/WebContent/OSRM.Localization.js @@ -39,12 +39,14 @@ OSRM.loc = OSRM.Localization.translate; // German language support OSRM.Localization["de"] = { //gui +"OPEN_JOSM": "JOSM Öffnen", +"OPEN_OSMBUGS": "OSM Bugs Öffnen", "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": "Open JOSM", +"OPEN_OSMBUGS": "Open 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", diff --git a/WebContent/OSRM.Map.js b/WebContent/OSRM.Map.js index 727ad35aa..b57ab30cb 100644 --- a/WebContent/OSRM.Map.js +++ b/WebContent/OSRM.Map.js @@ -49,6 +49,14 @@ OSRM.MapView = L.Map.extend({ 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); } }); diff --git a/WebContent/main.css b/WebContent/main.css index 062bb3f9d..8d890f639 100644 --- a/WebContent/main.css +++ b/WebContent/main.css @@ -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; diff --git a/WebContent/main.html b/WebContent/main.html index 7aa2047e2..cc451d7e9 100644 --- a/WebContent/main.html +++ b/WebContent/main.html @@ -113,11 +113,16 @@ or see http://www.gnu.org/licenses/agpl.txt. -

-
Options
-
- Unbenannte Straßen hervorheben -
+ Kartenwerkzeuge +
+ + Unbenannte Straßen hervorheben + + + JOSM Öffnen + OSM Bugs Öffnen + +
diff --git a/WebContent/routing/OSRM.Routing.js b/WebContent/routing/OSRM.Routing.js index ed5b8fd8e..2796d187d 100644 --- a/WebContent/routing/OSRM.Routing.js +++ b/WebContent/routing/OSRM.Routing.js @@ -143,6 +143,6 @@ _snapRoute: function() { OSRM.Geocoder.updateAddress(OSRM.C.SOURCE_LABEL); OSRM.Geocoder.updateAddress(OSRM.C.TARGET_LABEL); -}, +} }; \ No newline at end of file diff --git a/WebContent/routing/OSRM.RoutingGUI.js b/WebContent/routing/OSRM.RoutingGUI.js index ea5329270..bb2da16ad 100644 --- a/WebContent/routing/OSRM.RoutingGUI.js +++ b/WebContent/routing/OSRM.RoutingGUI.js @@ -89,6 +89,27 @@ inputChanged: function(marker_id) { 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(); + document.location.href = "http://osmbugs.org/?lat="+position.lat.toFixed(6)+"&lon="+position.lng.toFixed(6)+"&zoom="+OSRM.G.map.getZoom(); + //window.open( "http://osmbugs.org/?lat="+position.lat.toFixed(6)+"&lon="+position.lng.toFixed(6)+"&zoom="+OSRM.G.map.getZoom() ); } }; \ No newline at end of file From 7b4e923ec4889cac3be9eb24e921d6f8891479a4 Mon Sep 17 00:00:00 2001 From: DennisSchiefer Date: Fri, 30 Mar 2012 10:35:14 +0100 Subject: [PATCH 08/13] added option (commented out) to use input box for route links to get a marked url when clicking in it -> test what is better --- WebContent/routing/OSRM.RoutingDescription.js | 1 + 1 file changed, 1 insertion(+) diff --git a/WebContent/routing/OSRM.RoutingDescription.js b/WebContent/routing/OSRM.RoutingDescription.js index a57c26b8f..04c367337 100644 --- a/WebContent/routing/OSRM.RoutingDescription.js +++ b/WebContent/routing/OSRM.RoutingDescription.js @@ -36,6 +36,7 @@ onClickCreateShortcut: function(src){ }, showRouteLink: function(response){ document.getElementById('route-prelink').innerHTML = '['+response.ShortURL+']'; +// document.getElementById('route-prelink').innerHTML = '[]'; }, showRouteLink_TimeOut: function(){ document.getElementById('route-prelink').innerHTML = '['+OSRM.loc("LINK_TO_ROUTE_TIMEOUT")+']'; From 5165e01a5c2a1324b6f878a17e61bc87a2cdee4e Mon Sep 17 00:00:00 2001 From: DennisSchiefer Date: Fri, 30 Mar 2012 16:30:16 +0100 Subject: [PATCH 09/13] added draggable routes, changed findViaPosition to only return the index and not set the node, IMPORTANT: changed leaflet-src.js for a bugfix!, --- README.md | 2 +- WebContent/OSRM.Map.js | 4 +- WebContent/OSRM.Markers.js | 44 ++++++++++++++- WebContent/OSRM.Route.js | 8 ++- WebContent/OSRM.Via.js | 52 ++++++++++++++++-- WebContent/images/drag.pdf | Bin 0 -> 2978 bytes WebContent/images/marker-drag.png | Bin 0 -> 444 bytes WebContent/leaflet/leaflet-src.js | 9 ++- WebContent/main.js | 7 +++ WebContent/routing/OSRM.RoutingDescription.js | 2 +- 10 files changed, 112 insertions(+), 16 deletions(-) create mode 100644 WebContent/images/drag.pdf create mode 100644 WebContent/images/marker-drag.png diff --git a/README.md b/README.md index 5dce2e12c..2dc09ed0d 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/WebContent/OSRM.Map.js b/WebContent/OSRM.Map.js index b57ab30cb..1031f3f0a 100644 --- a/WebContent/OSRM.Map.js +++ b/WebContent/OSRM.Map.js @@ -126,13 +126,13 @@ init: function() { 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('click', OSRM.Map.mousemove ); + OSRM.G.map.on('mousemove', OSRM.Map.mousemove ); }, // map event handlers zoomed: function(e) { OSRM.Routing.getRoute(); }, contextmenu: function(e) {;}, -mousemove: 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 ); diff --git a/WebContent/OSRM.Markers.js b/WebContent/OSRM.Markers.js index f7395ff5e..4d2dab54c 100644 --- a/WebContent/OSRM.Markers.js +++ b/WebContent/OSRM.Markers.js @@ -94,6 +94,8 @@ OSRM.RouteMarker = function ( label, style, position ) { this.marker.on( 'drag', this.onDrag ); this.marker.on( 'dragstart', this.onDragStart ); this.marker.on( 'dragend', this.onDragEnd ); +// this.marker.on( 'mouseover', this.onMouseOver ); +// this.marker.on( 'mouseout', this.onMouseOut ); }; OSRM.inheritFrom( OSRM.RouteMarker, OSRM.Marker ); OSRM.extend( OSRM.RouteMarker, { @@ -122,9 +124,9 @@ onDragStart: function(e) { if( OSRM.G.markers.route[i].marker === this ) { OSRM.G.dragid = i; break; - } + } - OSRM.G.markers.highlight.hide(); + //OSRM.G.markers.highlight.hide(); if (OSRM.G.route.isShown()) OSRM.G.route.showOldRoute(); }, @@ -140,17 +142,53 @@ onDragEnd: function(e) { if(OSRM.G.route.isShown()==false) OSRM.Geocoder.updateAddress(this.parent.label); }, +onMouseOver: function(e) { + OSRM.G.onmouse = true; +}, +onMouseOut: function(e) { + OSRM.G.onmouse = false; +}, toString: function() { return "OSRM.RouteMarker: \""+this.label+"\", "+this.position+")"; } }); +//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].hide(); + OSRM.G.markers.route[OSRM.G.dragid] = new OSRM.RouteMarker(OSRM.C.VIA_LABEL, {draggable:true,icon:OSRM.G.icons['marker-via']}, e.target.getLatLng() ); + OSRM.G.markers.route[OSRM.G.dragid].show(); + + OSRM.RouteMarker.prototype.onDragEnd.call(this,e); +}, +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.G.icons['marker-highlight']});; + this.highlight = new OSRM.DragMarker("highlight", {draggable:true,icon:OSRM.G.icons['marker-highlight']});; + this.dragger = new OSRM.DragMarker("drag", {draggable:true,icon:OSRM.G.icons['marker-drag']});; }; OSRM.extend( OSRM.Markers,{ removeAll: function() { diff --git a/WebContent/OSRM.Route.js b/WebContent/OSRM.Route.js index 2750f33f9..71e88a110 100644 --- a/WebContent/OSRM.Route.js +++ b/WebContent/OSRM.Route.js @@ -59,8 +59,12 @@ centerView: function() { OSRM.g.map.fitBoundsUI( bounds ); }, onClick: function(e) { - if(OSRM.G.route.isRoute()) - OSRM.Via.findViaPosition( e.latlng ); + if(OSRM.G.route.isRoute()) { + var via_index = OSRM.Via.findViaIndex( e.latlng ); + var marker_index = OSRM.G.markers.setVia(via_index, e.latlng); + OSRM.G.markers.route[marker_index].show(); + OSRM.Routing.getRoute(); + } }, toString: function() { return "OSRM.Route("+ this.label + ", " + this.route.getLatLngs().length + " points)"; diff --git a/WebContent/OSRM.Via.js b/WebContent/OSRM.Via.js index 940a470f8..429703789 100644 --- a/WebContent/OSRM.Via.js +++ b/WebContent/OSRM.Via.js @@ -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,52 @@ 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(); - - OSRM.Routing.getRoute(); - 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; + if( (new Date() - OSRM.Via.dragTimer) < 25 ) + return; + if( OSRM.G.onmouse ) { + OSRM.G.markers.dragger.hide(); + return; + } + OSRM.Via.dragTimer = new Date(); + +// var mouse = event.latlng; +// for(var i=0, size=OSRM.G.markers.route.length; i580;eFlad3$M>_iAO*c2g{(dh`82G4i_0*nA+)u~V3vvMuH5{vBtPvo<|x4{tKjimP8B9h%&R{y?64aq}97B|@{V zlEMdJM7wPpHe>}C6Otn~DnddBdQx~%@3jx-jfc^-;bE6!x7WW@sQo~WyHreTQSr=Z zGUnQ5mpIm@DCBq@A9rd~drCjpm-a+?5#BZ_Ix1dm`nsa=DCvl$$x z10e*1h)j_X$Aq{PmKgz9XlCd_Fh~-Ki06snAn1u8_h1n40JM+79X)Xnmar@jQ5nP( zg^47dVh#_JXQ4aO6ZV@S*gP3t^esKXMP2c}lilo+KDw!1YunXcT%$v;mh5XtZpdjMIls=%o|C`xxG}L~%~15kM}@BHY-v^G=H#ZfaW>N5 zEEH4?x-IBBnIE_rva%ViS3f+es+T!t+UK#c$2OAa>|LO{O0ng7ch}w2;5(ZlS{Qj} zd{)fa!VcQk=k@S6qb~OSH(SeCqu+&o8`+<^u%;+2H#<G8^gI;Kiml_v9dK2E-swMaTVuc+$b)!kNCZID2ILYUg&o`k17JioOzu)e=g z>+M-oZBBu)hN=Z8a)-sz#B&1c?=9IA6&DvMv(lC6CJO~ygNsw&xBGkRYQ^4RRxKQ>`r$M<@YKGuO@6x>s{;q#zlx=?z ztDY>sC(ulP1idiDbM{GcuQW@qXiwsF?(9;xDH`9Yq%nb1M9p?wcW$*qsQqY=2Ybu% zJ_nQ;n(Gs=VTBkV`<){U-^mRas?Nz6a8u|+U7e}w)6sApK&<6=AgLpLv>82LB{QON9YZ| z8#W(2eu1?fwI3%9mUi5(eLJjasnkz)Dm9~=;AXWwJLiY`MO42#RibAv3Xf>DnZ*2e z-7L7>NjEgu+j&Oyjd7mckv&OqI~3Iaa-k!ntf0TvaP9bmmbd{g(_ZcUQ{?OK-d+{` zvLUaGRoCG0W9bI1q0_744;TKLFnIANR^7r!5tlbM^FsFRtw;{^E>AlE@Uj;_AFOJB``YF<<-hFFU!5SXiENe6?SR2 z0oN(L>q^?nLv>*S%MM%qRg3R7xE>@_SEEgZR}feTBV6 zFMVcJmL%Wdo4;7c8f%s^#sH_gv?lF}0Q1E2UB4WdKXCf%h9WDapO;Q|P6#HIb(9ED zX~7)jBH&9w-;i}46!eWxRoDEhtxOKi2@{3L8Z^-Hb(xk8T+=^eg82s*Nnm48s$m8J zA&`*eV53CDkKloM>2p}VSRfMG$(oh1odp>okr4_7+`*F!_PL4p|LNPO14l`)UR^{Awzb-!fA|5rGf_eIR+%a|4WSaHAX?eobtsw8Vz);FEMjq z;V&>VGH9%yV`LfvT=pe4Qy(tj2*NN4B%7%{1u>Y6FA)`qa9HLrFdH}vgGFHOl?(Do Vlq13ArXkZA=FqZb_G=xWe*yDgU%>zX literal 0 HcmV?d00001 diff --git a/WebContent/images/marker-drag.png b/WebContent/images/marker-drag.png new file mode 100644 index 0000000000000000000000000000000000000000..2e067fbd5a42203151f105c6fbd42b424694e554 GIT binary patch literal 444 zcmV;t0YmV8d12{F`y?d7dn6NPXWsV-Y$T5H%6F}#qs4FZi?1lOJHhN6Vo;~~Tl`B`k zh5;?X&;P4@T!(C?b{_4Tz{ mT3VMu27&?$6xb*k2nqoIZ5dQcr>yD#0000xwnG= literal 0 HcmV?d00001 diff --git a/WebContent/leaflet/leaflet-src.js b/WebContent/leaflet/leaflet-src.js index 4f0b7c1f0..3330a17d9 100644 --- a/WebContent/leaflet/leaflet-src.js +++ b/WebContent/leaflet/leaflet-src.js @@ -3382,7 +3382,14 @@ L.LineUtil = { dx = p.x - x; dy = p.y - y; - return sqDist ? dx * dx + dy * dy : new L.Point(x, y); + //return sqDist ? dx * dx + dy * dy : new L.Point(x, y); // DS_CHANGE + if(sqDist) + return dx*dx + dy*dy; + else { + var p = new L.Point(x,y); + p._sqDist = dx*dx + dy*dy; + return p; + } } }; diff --git a/WebContent/main.js b/WebContent/main.js index 0b4eaf714..1bfc55096 100644 --- a/WebContent/main.js +++ b/WebContent/main.js @@ -65,10 +65,17 @@ OSRM.prefetchIcons = function() { 'marker-target', 'marker-via', 'marker-highlight', + 'marker-drag' ]; for(var i=0; i'+response.ShortURL+']'; -// document.getElementById('route-prelink').innerHTML = '[]'; +// document.getElementById('route-prelink').innerHTML = '[]'; }, showRouteLink_TimeOut: function(){ document.getElementById('route-prelink').innerHTML = '['+OSRM.loc("LINK_TO_ROUTE_TIMEOUT")+']'; From 3b485f1426407fc892f4c93ea89443b476ea125c Mon Sep 17 00:00:00 2001 From: DennisSchiefer Date: Sun, 1 Apr 2012 19:13:54 +0200 Subject: [PATCH 10/13] finished dragging of routes, moved corrected bugs in Leaflet to their own file (drag after dragend, distance to path), open osmbugs in new window --- WebContent/L.Bugfixes.js | 80 ++++ WebContent/OSRM.Localization.js | 8 +- WebContent/OSRM.Markers.js | 33 +- WebContent/OSRM.Route.js | 10 - WebContent/OSRM.Routing.js | 513 -------------------------- WebContent/OSRM.Via.js | 30 +- WebContent/leaflet/leaflet-src.js | 9 +- WebContent/main.html | 7 +- WebContent/routing/OSRM.RoutingGUI.js | 3 +- 9 files changed, 110 insertions(+), 583 deletions(-) create mode 100644 WebContent/L.Bugfixes.js delete mode 100644 WebContent/OSRM.Routing.js diff --git a/WebContent/L.Bugfixes.js b/WebContent/L.Bugfixes.js new file mode 100644 index 000000000..e1979df15 --- /dev/null +++ b/WebContent/L.Bugfixes.js @@ -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); + } + }; +}()); diff --git a/WebContent/OSRM.Localization.js b/WebContent/OSRM.Localization.js index 6d377f38a..ffe7ec9ec 100644 --- a/WebContent/OSRM.Localization.js +++ b/WebContent/OSRM.Localization.js @@ -39,8 +39,8 @@ OSRM.loc = OSRM.Localization.translate; // German language support OSRM.Localization["de"] = { //gui -"OPEN_JOSM": "JOSM Öffnen", -"OPEN_OSMBUGS": "OSM Bugs Öffnen", +"OPEN_JOSM": "JOSM", +"OPEN_OSMBUGS": "OSM Bugs", "GUI_START": "Start", "GUI_END": "Ziel", "GUI_RESET": "Reset", @@ -82,8 +82,8 @@ OSRM.Localization["de"] = { // English language support OSRM.Localization["en"] = { //gui -"OPEN_JOSM": "Open JOSM", -"OPEN_OSMBUGS": "Open OSM Bugs", +"OPEN_JOSM": "JOSM", +"OPEN_OSMBUGS": "OSM Bugs", "GUI_START": "Start", "GUI_END": "End", "GUI_RESET": "  Reset  ", diff --git a/WebContent/OSRM.Markers.js b/WebContent/OSRM.Markers.js index 4d2dab54c..4b7d153c2 100644 --- a/WebContent/OSRM.Markers.js +++ b/WebContent/OSRM.Markers.js @@ -67,24 +67,6 @@ 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 ) { OSRM.RouteMarker.prototype.base.constructor.apply( this, arguments ); @@ -94,8 +76,6 @@ OSRM.RouteMarker = function ( label, style, position ) { this.marker.on( 'drag', this.onDrag ); this.marker.on( 'dragstart', this.onDragStart ); this.marker.on( 'dragend', this.onDragEnd ); -// this.marker.on( 'mouseover', this.onMouseOver ); -// this.marker.on( 'mouseout', this.onMouseOut ); }; OSRM.inheritFrom( OSRM.RouteMarker, OSRM.Marker ); OSRM.extend( OSRM.RouteMarker, { @@ -126,7 +106,8 @@ onDragStart: function(e) { break; } - //OSRM.G.markers.highlight.hide(); + if( this.parent != OSRM.G.markers.highlight) + OSRM.G.markers.highlight.hide(); if (OSRM.G.route.isShown()) OSRM.G.route.showOldRoute(); }, @@ -142,12 +123,6 @@ onDragEnd: function(e) { if(OSRM.G.route.isShown()==false) OSRM.Geocoder.updateAddress(this.parent.label); }, -onMouseOver: function(e) { - OSRM.G.onmouse = true; -}, -onMouseOut: function(e) { - OSRM.G.onmouse = false; -}, toString: function() { return "OSRM.RouteMarker: \""+this.label+"\", "+this.position+")"; } @@ -171,11 +146,11 @@ onDragStart: function(e) { OSRM.RouteMarker.prototype.onDragStart.call(this,e); }, onDragEnd: function(e) { - OSRM.G.markers.route[OSRM.G.dragid].hide(); OSRM.G.markers.route[OSRM.G.dragid] = new OSRM.RouteMarker(OSRM.C.VIA_LABEL, {draggable:true,icon:OSRM.G.icons['marker-via']}, e.target.getLatLng() ); OSRM.G.markers.route[OSRM.G.dragid].show(); - OSRM.RouteMarker.prototype.onDragEnd.call(this,e); + OSRM.RouteMarker.prototype.onDragEnd.call(this,e); + this.parent.hide(); }, toString: function() { return "OSRM.DragMarker: \""+this.label+"\", "+this.position+")"; diff --git a/WebContent/OSRM.Route.js b/WebContent/OSRM.Route.js index 71e88a110..54a1097e8 100644 --- a/WebContent/OSRM.Route.js +++ b/WebContent/OSRM.Route.js @@ -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() { @@ -58,14 +56,6 @@ centerView: function() { var bounds = new L.LatLngBounds( this.getPositions() ); OSRM.g.map.fitBoundsUI( bounds ); }, -onClick: function(e) { - if(OSRM.G.route.isRoute()) { - var via_index = OSRM.Via.findViaIndex( e.latlng ); - var marker_index = OSRM.G.markers.setVia(via_index, e.latlng); - OSRM.G.markers.route[marker_index].show(); - OSRM.Routing.getRoute(); - } -}, toString: function() { return "OSRM.Route("+ this.label + ", " + this.route.getLatLngs().length + " points)"; } diff --git a/WebContent/OSRM.Routing.js b/WebContent/OSRM.Routing.js deleted file mode 100644 index 9ef99968c..000000000 --- a/WebContent/OSRM.Routing.js +++ /dev/null @@ -1,513 +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; - - -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.Routing.showNoRouteGeometry(); - OSRM.Routing.showNoRouteDescription(); - document.getElementById('information-box').innerHTML = "

"+OSRM.loc("TIMED_OUT")+".

"; -}, -timeoutRoute: function() { - OSRM.Routing.showNoRouteGeometry(); - OSRM.G.route.hideUnnamedRoute(); - OSRM.Routing.showNoRouteDescription(); - document.getElementById('information-box').innerHTML = "

"+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.Routing.showNoRouteGeometry(); - OSRM.Routing.showNoRouteDescription(); - document.getElementById('information-box').innerHTML = "

"+OSRM.loc("YOUR_ROUTE_IS_BEING_COMPUTED")+".

"; - } else { - OSRM.Routing.showRouteGeometry(response); - OSRM.Routing.showRouteDescriptionSimple(response); - } - OSRM.Routing._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(OSRM.Routing.draggingTimeout,1); - } -}, -showRoute: function(response) { - if(!response) - return; - - if(response.status == 207) { - OSRM.Routing.showNoRouteGeometry(); - OSRM.G.route.hideUnnamedRoute(); - OSRM.Routing.showNoRouteDescription(); - document.getElementById('information-box').innerHTML = "

"+OSRM.loc("NO_ROUTE_FOUND")+".

"; - } else { - OSRM.Routing.showRouteGeometry(response); - OSRM.Routing.showRouteNonames(response); - OSRM.Routing.showRouteDescription(response); - OSRM.Routing._snapRoute(); - } - OSRM.Routing._updateHints(response); -}, - - -// show route geometry -showNoRouteGeometry: function() { - var positions = []; - for(var i=0, size=OSRM.G.markers.route.length; i'+response.ShortURL+']'; -}, -showRouteLink_TimeOut: function(){ - document.getElementById('route-prelink').innerHTML = '['+OSRM.loc("LINK_TO_ROUTE_TIMEOUT")+']'; -}, -showRouteDescription: function(response) { - // compute query string - var query_string = '?rebuild=1'; - for(var i=0; i'+OSRM.loc("GET_LINK_TO_ROUTE")+']'; - - // create GPX link - var gpx_link = '['+OSRM.loc("GPX_FILE")+']'; - - // create route description - var route_desc = ""; - route_desc += ''; - - 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 += ''; - - route_desc += '"; - - route_desc += '"; - - route_desc += '"; - - route_desc += ""; - } - - route_desc += '
'; - route_desc += ''; - route_desc += "'; - route_desc += ''; - 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 += '' + response.route_instructions[i][1] + ''; - } - //route_desc += ' for '; - route_desc += ''; - route_desc += "'; - if( i != response.route_instructions.length-1 ) - route_desc += ''+OSRM.Utils.metersToDistance(response.route_instructions[i][2])+''; - route_desc += "
'; - headline = ""; - headline += OSRM.loc("ROUTE_DESCRIPTION")+":
"; - headline += '

'; - headline += "" - + OSRM.loc("DISTANCE")+": " + OSRM.Utils.metersToDistance(response.route_summary.total_distance) - + "
" - + OSRM.loc("DURATION")+": " + OSRM.Utils.secondsToTime(response.route_summary.total_time) - + "
"; - headline += '
'; - headline += '
'+route_link+'
'+gpx_link+'
'; - - var output = ""; - output += route_desc; - - document.getElementById('information-box-headline').innerHTML = headline; - document.getElementById('information-box').innerHTML = output; -}, -showRouteDescriptionSimple: function(response) { - headline = OSRM.loc("ROUTE_DESCRIPTION")+":
"; - headline += "" - + OSRM.loc("DISTANCE")+": " + OSRM.Utils.metersToDistance(response.route_summary.total_distance) - + "
" - + OSRM.loc("DURATION")+": " + OSRM.Utils.secondsToTime(response.route_summary.total_time) - + "
"; - headline += '

'; - - document.getElementById('information-box-headline').innerHTML = headline; - document.getElementById('information-box').innerHTML = "

"+OSRM.loc("YOUR_ROUTE_IS_BEING_COMPUTED")+".

"; -}, -showNoRouteDescription: function() { - headline = OSRM.loc("ROUTE_DESCRIPTION")+":
"; - headline += "" - + OSRM.loc("DISTANCE")+": N/A" - + "
" - + OSRM.loc("DURATION")+": N/A" - + "
"; - headline += '

'; - - document.getElementById('information-box-headline').innerHTML = headline; - document.getElementById('information-box').innerHTML = "

"+OSRM.loc("YOUR_ROUTE_IS_BEING_COMPUTED")+".

"; -}, - - -// unnamed streets display -showRouteNonames: 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.Routing.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 -getDragRoute: function() { - // prepare JSONP call - var source = OSRM.DEFAULTS.HOST_ROUTING_URL; - source += '?z=' + OSRM.G.map.getZoom() + '&output=json&geomformat=cmp&instructions=false'; - if(OSRM.G.markers.checksum) - source += '&checksum=' + OSRM.G.markers.checksum; - for(var i=0, size=OSRM.G.markers.route.length; i 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= 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 -_updateHints: function(response) { - var hint_locations = response.hint_data.locations; - OSRM.G.markers.checksum = response.hint_data.checksum; - for(var i=0; i 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.C.FULL_DESCRIPTION); - 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); -} - -}; \ No newline at end of file diff --git a/WebContent/OSRM.Via.js b/WebContent/OSRM.Via.js index 429703789..4471b4b56 100644 --- a/WebContent/OSRM.Via.js +++ b/WebContent/OSRM.Via.js @@ -68,30 +68,32 @@ findViaIndex: function( new_via_position ) { dragTimer: new Date(), drawDragMarker: function(event) { - if( OSRM.G.route.isShown() == false ) + if( OSRM.G.route.isShown() == false) return; if( OSRM.G.dragging == true ) return; + + // throttle computation if( (new Date() - OSRM.Via.dragTimer) < 25 ) return; - if( OSRM.G.onmouse ) { - OSRM.G.markers.dragger.hide(); - return; - } OSRM.Via.dragTimer = new Date(); -// var mouse = event.latlng; -// for(var i=0, size=OSRM.G.markers.route.length; i + @@ -116,11 +117,11 @@ or see http://www.gnu.org/licenses/agpl.txt. Kartenwerkzeuge

- Unbenannte Straßen hervorheben + Unbenannte Straßen hervorheben - JOSM Öffnen - OSM Bugs Öffnen + JOSM + OSM Bugs
diff --git a/WebContent/routing/OSRM.RoutingGUI.js b/WebContent/routing/OSRM.RoutingGUI.js index bb2da16ad..4d23a0e54 100644 --- a/WebContent/routing/OSRM.RoutingGUI.js +++ b/WebContent/routing/OSRM.RoutingGUI.js @@ -108,8 +108,7 @@ openJOSM: function() { //click: button "open OSM Bugs" openOSMBugs: function() { var position = OSRM.G.map.getCenterUI(); - document.location.href = "http://osmbugs.org/?lat="+position.lat.toFixed(6)+"&lon="+position.lng.toFixed(6)+"&zoom="+OSRM.G.map.getZoom(); - //window.open( "http://osmbugs.org/?lat="+position.lat.toFixed(6)+"&lon="+position.lng.toFixed(6)+"&zoom="+OSRM.G.map.getZoom() ); + window.open( "http://osmbugs.org/?lat="+position.lat.toFixed(6)+"&lon="+position.lng.toFixed(6)+"&zoom="+OSRM.G.map.getZoom() ); } }; \ No newline at end of file From 93ae928236314e9afe893dedd756a03c685f43e5 Mon Sep 17 00:00:00 2001 From: DennisSchiefer Date: Mon, 2 Apr 2012 08:29:03 +0200 Subject: [PATCH 11/13] added icons that can change their image, added image change while dragging markers, increased (invisible) size of drag marker, fixed issues with drag marker and highlight marker overlapping --- WebContent/L.MouseMarker.js | 43 +++++--- WebContent/L.SwitchableIcon.js | 115 ++++++++++++++++++++ WebContent/OSRM.Markers.js | 16 ++- WebContent/OSRM.Via.js | 10 +- WebContent/images/marker-drag.png | Bin 444 -> 462 bytes WebContent/images/marker-highlight-drag.png | Bin 0 -> 1725 bytes WebContent/images/marker-source-drag.png | Bin 0 -> 1786 bytes WebContent/images/marker-target-drag.png | Bin 0 -> 1678 bytes WebContent/images/marker-via-drag.png | Bin 0 -> 1791 bytes WebContent/main.html | 1 + WebContent/main.js | 26 +++-- 11 files changed, 181 insertions(+), 30 deletions(-) create mode 100644 WebContent/L.SwitchableIcon.js create mode 100644 WebContent/images/marker-highlight-drag.png create mode 100644 WebContent/images/marker-source-drag.png create mode 100644 WebContent/images/marker-target-drag.png create mode 100644 WebContent/images/marker-via-drag.png diff --git a/WebContent/L.MouseMarker.js b/WebContent/L.MouseMarker.js index 87eaed1a7..b19d96861 100644 --- a/WebContent/L.MouseMarker.js +++ b/WebContent/L.MouseMarker.js @@ -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 @@ -25,21 +24,33 @@ L.MouseMarker = L.Marker.extend({ initialize: function (latlng, options) { 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); -// }, - -// _fireMouseEvent: function (e) { -// this.fire(e.type, { -// latlng: this._map.mouseEventToLatLng(e), -// layerPoint: this._map.mouseEventToLayerPoint(e) -// }); -// L.DomEvent.stopPropagation(e); -// }, + switchIcon: function( icon ) { + this.options.icon = icon; + + 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); if (this.dragging && this.dragging.moved()) { return; } diff --git a/WebContent/L.SwitchableIcon.js b/WebContent/L.SwitchableIcon.js new file mode 100644 index 000000000..8a93d863e --- /dev/null +++ b/WebContent/L.SwitchableIcon.js @@ -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; + } +}); diff --git a/WebContent/OSRM.Markers.js b/WebContent/OSRM.Markers.js index 4b7d153c2..529bf80b2 100644 --- a/WebContent/OSRM.Markers.js +++ b/WebContent/OSRM.Markers.js @@ -69,6 +69,7 @@ toString: function() { // 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"; @@ -98,6 +99,7 @@ onDrag: function(e) { }, onDragStart: function(e) { OSRM.G.dragging = true; + this.switchIcon(this.options.dragicon); // store id of dragged marker for( var i=0; i this.route.length-2 ) return -1; - this.route.splice(id+1,0, new OSRM.RouteMarker(OSRM.C.VIA_LABEL, {draggable:true,icon:OSRM.G.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) { diff --git a/WebContent/OSRM.Via.js b/WebContent/OSRM.Via.js index 4471b4b56..0b307de7d 100644 --- a/WebContent/OSRM.Via.js +++ b/WebContent/OSRM.Via.js @@ -91,7 +91,7 @@ drawDragMarker: function(event) { 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); @@ -103,6 +103,14 @@ drawDragMarker: function(event) { 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(); diff --git a/WebContent/images/marker-drag.png b/WebContent/images/marker-drag.png index 2e067fbd5a42203151f105c6fbd42b424694e554..9832ead70e464bfca4119fce845c812b27126e55 100644 GIT binary patch literal 462 zcmV;<0WtoGP)Xpy000SaNLh0L00O)K00O)LTL$4-00004XF*Lt006O%3;baP00049Nkl+9=_Vc6NTXZ7I*tz5Y>7~KURjW9!yv7wl+?G;|fR;DG}Na2j&=?p+380>v%~^tU;BY#_%Na?Am}g`%#ou&@`! zFi-+RkGa{iXaBu&K(iBZ02nr!_4W0&T3T9{K?Z{Y6%;90Gb%L!04fd{RF()i_@% literal 444 zcmV;t0YmV8d12{F`y?d7dn6NPXWsV-Y$T5H%6F}#qs4FZi?1lOJHhN6Vo;~~Tl`B`k zh5;?X&;P4@T!(C?b{_4Tz{ mT3VMu27&?$6xb*k2nqoIZ5dQcr>yD#0000xwnG= diff --git a/WebContent/images/marker-highlight-drag.png b/WebContent/images/marker-highlight-drag.png new file mode 100644 index 0000000000000000000000000000000000000000..70e558b99cd8aa3952b7605a730ae0b2d7f86109 GIT binary patch literal 1725 zcmV;u215CXP)P001cn1^@s6z>|W`00007bV*G`2iyb# z1{oHe_;^GB000SaNLh0L01EH`01EH{Laa2H00004XF*Lt006O%3;baP000I|Nkl9bU%Ee_N4GVvb- zcqc9pGA^g#DDih3r_*Y+N!YUatth#{!9keJeR$MmLUvZ-4chvKz}jC5GU5GSqAX?S z>XoaJnVCt(2JmFCKMF*ZsKFcSH%Rl_ckjUG8Fth3a{@X)E6Bn9^BBN=j!Vtmy=M>H z&T+K1HNG_GUY8eJw-=+fwiaz|Ml8*m_vP72->E1N0$?e+NdSf0ckV!2YeOtGji7aF zH=(}19(H@bK+7Tms%86JNPy>kM+GrO0vZ|XN-HV@--bYr z1Vr8Ol9D1)>WNYq9kHUhxfuie2o`7PVX^SYT%totvQF~+1yC@oqfF2Mq7p65x1P~* zkz!*1lLaYSj9P~x0F((@{9At?58F-n{)e+rDD$vsV}W$m)OZD3w|)S(+l_Y%w?#PT z_c|r#9-9NYrCEvs?$80bmf|Ydw!M&&=Y=v+8D@R|(YT9cN`ng z-E3x=Y{^MatfRwNy($+cjvLU}6xo;|07eyOjzK~7aJgL5G6CsQF#8N-SSEwRY&L@v z!@UVF-H@!TEbRMq0nGh|h$uoN!U|K*1HAvsNzBtQh>LPeDxWHI2z%Rb;M5Jj%B!ZwT8SNflMZafMq#4sXx?eb(D@ul`6@b zdqxa3wI~W#BO@L6Kis>hVDHBt!D{8Bil|cQqHY;vez;w>sBH#v>EbyUZus7@4B?() z%Gu9ukNu)TDVLgSI=MZ=n31M^k2M^LClE3gqpYp9>E!A)c}Pw|++-UEE?%fY^$lMm*)vQgdurxIRMuQ| zSse}+?BlG-0&y`t2HR)3?b*zbJaeyn+0+ z>+|Un1f<@Wi!Bxp+B>@O`&pjv>%kXxMKk*!2qLPk82mtUx3}Fq(TN~pDFez;-=!As5<^zo=D^Ec=Y0lgi)EX^U?no#gu5y#H;fkI3f*W T$g|Ul00000NkvXXu0mjfa`QZ@ literal 0 HcmV?d00001 diff --git a/WebContent/images/marker-source-drag.png b/WebContent/images/marker-source-drag.png new file mode 100644 index 0000000000000000000000000000000000000000..cc72f6fca90cdc237e97fa48e8bcd441e5c1528c GIT binary patch literal 1786 zcmVP001cn1^@s6z>|W`00007bV*G`2iyb# z1{gF^g9zaO000SaNLh0L01EH`01EH{Laa2H00004XF*Lt006O%3;baP000JwNklvwjw=8?bm@NBa(IxuFl4TmA zlLY7HWAl+M5lxg$vpF9DQ4vvbVnpR72&IZeDYT`xx3{-<=e8E8fUqn|9SxN{$USDX86k*57hRqp z93sN=0g+I0hED4Vn_ki7YqB!3pjNB>`~*Qjd#4^17b@`3rawiGHW1mZF-e}z{_x`T zmzU)&$b(F#fJ=11%=P(^1SwSrVZz3K(3|)zvM5m|Rxi^n zpO=%92fM&g@*dcoc8J3qPQeM**$;=nA|ZY42CJ6j*TBQEYUTFX)Er-TS3!ZZ0< z1xvHDvthFJz{c4FsS8Ysj0ev-u6O}ie9d+!M78mUrqVnnwlB}D?@zZExZ}(a1E^?X3A;0QH-?VAkYrx z2N0?Zg}$v71=)qe5_osKhKoVnovTmp2jf`>3r1=jGDOHpfI|?S^e&ygEko|2O(={? zAejq1bp^&RJ~%ko<0FEVlo*VUJq|8O^{G8aD6y8rN=I^XplnD7s+^HX?nN z4o=SL6Aw`algT70F-S_f94=TL4hIx+&BAz~;P zrxI+C1;#Kv3U|DLWs4R;8yk(z?v8;tg+c+TdQbdyjy?zY+|#?hz|s&U%Ga&^2sc`4 zeP)ytn}q0yI5gEa;8bNbNHr9+o+(q}keinWtyb$7qnkF@?SJB2^;wi4f3VfBL-nc^ z3v-fFr=hO-hEGrsWlf(l+ph?^Ek@{#oj%WG)E*>~?@IR5;$b0vM3rL5__oV8tIN`| z(y3B-pFlg6WNqse3~SGPk#aK@;neZd5)JBR5addgv*BOl<%xRiN_8;xX*W6Ed9_b zqiJShK#(@z$@4W*o}!^ieMxqKr77*LJYSAUv5D^eJYGx=dl3db{k-&}k#hVtGKqUT zqr}kcVC{B0G-5cMw0p+`6{Ez-$|@xSpV!V)hM}Zg>*OcocW(9pE^Qx++G5RE4L`)=2(4 zu@~0BNDkmUg1|P{ZVT>JHuHDWfhmf{je#v6AMdUivh+sDj{!SxFf< zecIh_c40sIo{xmZQ5ewD(9nQ*KFnt*OpsACr0@<}XqFay6dRqS)Ln`tZ4JFhnKT_d z&E5;$#5p*5rdskkNPb<$Pk#h7iju!VMipEMXHc2ThsvLWp zTOK1VcBcE$oY+~oe!E_ZK0@Pd|DHs$ek#v;&n62M>C32MV5@gOA5%qOwi0_nN+2$| zm?>($rxv&pe~dSDd`di4BF+Auz8zN2&&z+T!fORMj&Dds0V)Ft3q*-z#d!38su)!B cbD$yr0Eu|c34VkBJpcdz07*qoM6N<$f?e1=6#xJL literal 0 HcmV?d00001 diff --git a/WebContent/images/marker-target-drag.png b/WebContent/images/marker-target-drag.png new file mode 100644 index 0000000000000000000000000000000000000000..c3c6f7c0860d9efd0563272639792d8b4f51061b GIT binary patch literal 1678 zcmV;9266d`P)P001cn1^@s6z>|W`00007bV*G`2iyb# z1{oN7KvhEk000SaNLh0L01EH`01EH{Laa2H00004XF*Lt006O%3;baP000IZNklncK3(AIr8M+hVe0S;l^7_QO95 z$rdsaqnX*1%*?sOXcS4@Tu_HNZq-B#Qsh=jp%*})Ep5-~>Dl|80;N!(b=jM|={eu` zz3=nhzf%Qbpoykz=LIW0 z-Xgw2fDd8r`0?n&Tj8=PI;cWB{j0&80mWXk%hn*Do^ zV9h!po&$J4;EWKNcqNdM9DE+1fb(XJhn_wlplb_)I8J`S03PYyD9c4w79cF3JQ8Ws zD26_u<2i<#TTbfF{cwIB2m!DV{Yd~N$Xp4Gjgyc!I)G`)$^g7R4F7VO;)tUJRL7RN zndpjQx$fYB5P)+6l-c>5sE)kOxZez@RM5SBJdX5TwSM}!b_T@q(Pvtb7fxf%TEOL| z#1Mdl5NqjdR(6nC0Zc!y%nCopm;t4xA>-gdJ?Si;?a7I(!zIb!C}I{1g~=0QmYetl zpz8&OFJ6=-?3XS9tu0g#zTiHi*)o$Ux<~;pzFJ~1JvnriRXC;>Le)Ne}|0g1~f_G@?(_OcnPGxfTJ4L z1|$l!L{@wG5T{d@TPP&j6%hd#1p*|Ks6@bI4Q|Yqx7%qik@ZL_NA~laf({E}xF(U_ z75>EmGyC_AYgG0j|MjcKE!q#pd)XZnyDV#Ve$+>k|deo_CS%X zC+jD}<=M!gLSp(kzt3wO8ys@Um8DdMG>yKb#-g6E4nXY~3-e-{5+_}7p8Juii~7rC z3il*QBUd2l@8|Mrt}#FF!c0w+vkCC|Lfq2@t*VbZX}S>0Cl#C_aKps=>GB) zH2HMJcxb+jjD+OmzM<0Z=wVMcWYa~#cXrtD^evs9YF_Y#tT6|z<2L64b#<^kZUcD@ zRazR>7Up6D>zhQnUz(f3y(pmbeP)c9`tEMNQ`0^(Alu81Kgxge=su*8o5mO6LM*Xc zx6CU73{l=}w(vEkaa$niDxJ^TA0~V2qVcaRCUz7>NdRV>o5TZ)s4cgqPMHrx71_R3tH^FSDhlCSc4Q;Td( zoH_vtg|sNM5i($CmF0@+|Kg(p+4->E7$*g4{k?riI&cWWq<2Bq5B*=d!yhgjV%TWgBublS%{(6!Sbkqoj+UD(BO&*guHp+bG!b5+l>`vWu#D;$IEka zWfeB_pbJzm3+Y-AMBel(t2&!n*abpYsyL6i4eMcPZD!}r?`&)weLJ{!Kuqrd1q&e7o%{-l}T-4abHg~kj6;{STPBClVRDGHU$K;mB|&x=8eEd-xzO9#h?Jsj)X^ezrKPeL zwEjEo_x@)P*>VNWjt;*JHW~X0p$~{rhn=l2=|$8ayPiB|F|QtY`~@&x={!{1mIq Yzf|AAYP001cn1^@s6z>|W`00007bV*G`2iyb# z1{oLX|47mR000SaNLh0L01EH`01EH{Laa2H00004XF*Lt006O%3;baP000J#Nklh49PJ*49HKZj(_;pw$1g@sfA<`pUY_eg)hK-0_wQ8o}=oq?Mo6vZp0V>{AM-5p`WI@OJAA4!t23Seh!g|66+rT}{`$)Z9%(6?2l5{(coB z_;+N&ij1rS2Y`SN=-vc2@$XqeMtlxvktxq zSUVT8r%Fj&MvEFi+1ZmK^)?exy@KR?Ui#sv#FfW$-ukUf&}+5Mij%T*>6~-&{Q4Ks zb^SWNxl}$#-POBJcRDm|qU;aLS(=XIy#6XMWC!ma!J@dB$=oka4($yShXW}uWQN*- z0Qd*3%G9-fhqQHTal7$mg3r;#isw(Nagw(+@#%lf*}o6An+*!5q_vqcSXJ>k2*cgb zCjA70tqEFVBC>LR4RzvTnaJsMPWq&;0OCyeyx^#VB~ddz{z^{P%fN^ePKRT{c+F2Y z$T`07Q6XN>|0lfKrx2-+4^56eKw18NL>qM2p1TXqFU=Ev3}emaZHS0kZ1Q`CGBy9m zTV@Cd{!FAKgTH?l%U3R+48v$d)%o*8Kt~`p1Cdihj9G!~Bc-T5wq1^N&HDA=hXy9+ zH5zdGXarogEu1KdsVc2Ojews*9-dHrES&-8AOiXXnP9pIfjY7#>ga7{UNE))6)ZnHQ9u&sh@OZ|<3rWX=`#@wAA|pJ| z^KFVK9*Hi{kLu$GvGuiAVQ>CU840D^AMk?kySdz=VV20twN+JEvi5n{Y`qie>$V_! z#|~6~m&4`>C~v* znhi0Cq~wH&#k99KgBA3z=#ZMvo`AEr3ludtodL0lNqFPEcjOhfT)wFA`_aZtFn@9Z zk}!HXx5&{flk6^X)EDK74Rz;AGPms7iI#uWDu_%jJGSM%HlqmOcA}-;jM>CDHbm(X zkI6@7%J>Q1|uE-Z|PJQ}anGynYEAG;Nm zqn>VC)hKwjWk{(ud;fFKzO)tn%{Re&J&)D6lpkZDZveNiUF{bA;(?m~1r;Qk*%l>5 zs0wWDE&JFaQlEW>&ci&>q%Omax{qYP{pY6LJ(yYMvXJ4u2u@|b^l33*NCUfR=Tt)y zy&Wz%t?h&4Q#2ditRzhQL8-vm*8%pJK|Y*wsNRU$%2H;3YEQAx9To{i^R?jhG+e2y zrdMzE>_*Y_7vm4W-r3<+Ln@pLYfcg-0iVCn=c3;yE!BtQpQ%yts4f4D*`3~d&Oh=* zB%B%*c5AoAX0gzZLz;3@6-5t>h(61Gf$Rz%i}Se2H%sKi7dC!N_newQqa!BOn1;H~ zOPE#Xa{s27UB+!V?i1^pJ`oI$JCv&F9aDF)vA81>9O4&RjLqO<|yo ze(09V`buRPXuOQ(JH9sw6S}=mby<2shs;3Ft%k$UKtCIwH;M(594wP_UVNppoZjwa zTq&=>sMBkv@daJe3nCepLbiJPeSvex#`+72B5XOc6JLDwm*opRN{{f2&J5i7|I + diff --git a/WebContent/main.js b/WebContent/main.js index 1bfc55096..d9f4da010 100644 --- a/WebContent/main.js +++ b/WebContent/main.js @@ -43,6 +43,11 @@ OSRM.prefetchImages = function() { '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', @@ -65,17 +70,24 @@ OSRM.prefetchIcons = function() { '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 Date: Mon, 2 Apr 2012 08:54:25 +0200 Subject: [PATCH 12/13] added buttons to delete source and target --- WebContent/OSRM.Markers.js | 10 ++++++++-- WebContent/main.css | 21 +++++++++++++++++++++ WebContent/main.html | 8 ++++++-- WebContent/routing/OSRM.RoutingGUI.js | 15 +++++++++++++++ 4 files changed, 50 insertions(+), 4 deletions(-) diff --git a/WebContent/OSRM.Markers.js b/WebContent/OSRM.Markers.js index 529bf80b2..bc8ff1bd8 100644 --- a/WebContent/OSRM.Markers.js +++ b/WebContent/OSRM.Markers.js @@ -174,6 +174,8 @@ removeAll: function() { for(var i=0; i Start: - +
+ +
Zeigen Ende: - +
+ +
Zeigen diff --git a/WebContent/routing/OSRM.RoutingGUI.js b/WebContent/routing/OSRM.RoutingGUI.js index 4d23a0e54..da0f20289 100644 --- a/WebContent/routing/OSRM.RoutingGUI.js +++ b/WebContent/routing/OSRM.RoutingGUI.js @@ -109,6 +109,21 @@ openJOSM: function() { 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(); } }; \ No newline at end of file From 4638e7c24da45273c70320867ba584902fcaacff Mon Sep 17 00:00:00 2001 From: DennisSchiefer Date: Mon, 2 Apr 2012 20:57:39 +0200 Subject: [PATCH 13/13] corrected error and bumped version to 0.1.3 --- WebContent/OSRM.base.js | 4 ++-- WebContent/main.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/WebContent/OSRM.base.js b/WebContent/OSRM.base.js index 6fab319cd..91a910a4b 100644 --- a/WebContent/OSRM.base.js +++ b/WebContent/OSRM.base.js @@ -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 = {}; diff --git a/WebContent/main.js b/WebContent/main.js index d9f4da010..76471caa7 100644 --- a/WebContent/main.js +++ b/WebContent/main.js @@ -172,9 +172,9 @@ OSRM.checkURL = function(){ // 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.fitBoundsUI( bounds ); + OSRM.G.map.fitBoundsUI( bounds ); } else { - OSRM.g.map.setView(center, zoom); + OSRM.G.map.setView(center, zoom); } // compute route