From 979327ec82fb03ef945d3695ee9d74fc80b785fa Mon Sep 17 00:00:00 2001 From: DennisSchiefer Date: Mon, 14 May 2012 12:18:04 +0100 Subject: [PATCH] refactored code for history routes --- WebContent/base/Backup.OSRM.HistoryRoutes.js | 178 ------------------- WebContent/base/OSRM.HistoryRoutes.js | 69 +++---- WebContent/base/OSRM.Via.js | 10 +- WebContent/routing/OSRM.Routing.js | 14 +- 4 files changed, 38 insertions(+), 233 deletions(-) delete mode 100644 WebContent/base/Backup.OSRM.HistoryRoutes.js diff --git a/WebContent/base/Backup.OSRM.HistoryRoutes.js b/WebContent/base/Backup.OSRM.HistoryRoutes.js deleted file mode 100644 index 0a89d8caa..000000000 --- a/WebContent/base/Backup.OSRM.HistoryRoutes.js +++ /dev/null @@ -1,178 +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 route management (handles drawing of route geometry - current route, old route, unnamed route, highlight unnamed streets) -// [this holds the route geometry] - - -OSRM.HistoryRoute = function() { - // how to draw history routes and how many - this._history_styles = [{dashed:false, color:'#FFFFFF', opacity:0.5, weight:5}, - {dashed:false, color:'#0000DD', opacity:0.45, weight:5}, - {dashed:false, color:'#0000BB', opacity:0.40, weight:5}, - {dashed:false, color:'#000099', opacity:0.35, weight:5}, - {dashed:false, color:'#000077', opacity:0.30, weight:5}, - {dashed:false, color:'#000055', opacity:0.25, weight:5}, - {dashed:false, color:'#000033', opacity:0.20, weight:5}, - {dashed:false, color:'#000011', opacity:0.15, weight:5}, - {dashed:false, color:'#FF0000', opacity:0.50, weight:5} - ]; - this._history_routes = this._history_styles.length; - - // actual history data - this._history_route = []; - this._history_data = []; - for(var i=0, size=this._history_routes; i0; i--) { - this._history_route[i].setPositions( this._history_route[i-1].getPositions() ); - this._history_data[i] = this._history_data[i-1]; - } - // reset staging spot - this._history_route[0].setPositions( [] ); - this._history_data[0] = []; - }, - _equalRoute: function() { - var lhs = OSRM.G.markers.route; - var rhs = this._history_data[0]; - for(var i=0,size=Math.min(rhs.length,lhs.length); i 0 ) { - OSRM.JSONP.clear('history'+i); - OSRM.JSONP.call(this._buildCall(i)+'&instructions=false', this._callback_redrawHistory, OSRM.JSONP.empty, OSRM.DEFAULTS.JSONP_TIMEOUT, 'history'+i, i); - } - }, - _buildCall: function(history_id) { - var source = OSRM.DEFAULTS.HOST_ROUTING_URL; - source += '?z=' + OSRM.G.map.getZoom() + '&output=json&jsonp=%jsonp&geomformat=cmp'; - var data = this._history_data[history_id]; - if(data.checksum) - source += '&checksum=' + data.checksum; - for(var i=0,size=data.length; i0; i--) { @@ -118,18 +111,15 @@ OSRM.extend( OSRM.HistoryRoute,{ this._history[0].route.setPositions( [] ); this._history[0].markers = []; this._history[0].checksum = null; - - console.log("fetch", this._history[1].markers); }, _showHistoryRoutes: function() { - console.log("show"); for(var i=1,size=this._history_length; i nearest_index) { new_via_index = i; break; diff --git a/WebContent/routing/OSRM.Routing.js b/WebContent/routing/OSRM.Routing.js index a3318922c..9c3bd8ff8 100644 --- a/WebContent/routing/OSRM.Routing.js +++ b/WebContent/routing/OSRM.Routing.js @@ -58,7 +58,6 @@ showRoute: function(response) { return; OSRM.G.response = response; // needed for printing & history routes! - OSRM.G.via_points = response.via_points.slice(0); if(response.status == 207) { OSRM.RoutingGeometry.showNA(); OSRM.RoutingNoNames.showNA(); @@ -95,6 +94,7 @@ showRoute_Redraw: function(response) { if(!response) return; + //OSRM.G.response = response; // not needed, even harmful as important information is not stored! if(response.status != 207) { OSRM.RoutingGeometry.show(response); OSRM.RoutingNoNames.show(response); @@ -171,11 +171,13 @@ _updateHints: function(response) { // snap all markers to the received route _snapRoute: function() { var positions = OSRM.G.route.getPositions(); - - OSRM.G.markers.route[0].setPosition( positions[0] ); - OSRM.G.markers.route[OSRM.G.markers.route.length-1].setPosition( positions[positions.length-1] ); - for(var i=0; i