From 36f5b36c6b55f3830ed7b6695921a7515e2aaa42 Mon Sep 17 00:00:00 2001 From: shiin Date: Sun, 13 May 2012 20:28:24 +0200 Subject: [PATCH] more work on history routes --- WebContent/base/Backup.OSRM.HistoryRoutes.js | 178 ++++++++++++++++ WebContent/base/OSRM.HistoryRoutes.js | 212 +++++++++++++++++++ WebContent/base/OSRM.Map.js | 1 - WebContent/base/OSRM.Routes.js | 127 +++-------- WebContent/gui/OSRM.RoutingGUI.js | 6 +- WebContent/main.html | 1 + WebContent/routing/OSRM.Routing.js | 35 +-- 7 files changed, 427 insertions(+), 133 deletions(-) create mode 100644 WebContent/base/Backup.OSRM.HistoryRoutes.js create mode 100644 WebContent/base/OSRM.HistoryRoutes.js diff --git a/WebContent/base/Backup.OSRM.HistoryRoutes.js b/WebContent/base/Backup.OSRM.HistoryRoutes.js new file mode 100644 index 000000000..0a89d8caa --- /dev/null +++ b/WebContent/base/Backup.OSRM.HistoryRoutes.js @@ -0,0 +1,178 @@ +/* +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--) { + this._history[i].route.setPositions( this._history[i-1].route.getPositions() ); // copying positions quicker than creating new route! + this._history[i].markers = this._history[i-1].markers; + this._history[i].checksum = this._history[i-1].checksum; + } + // reset staging spot + 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 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'; + + if(this._history[history_id].checksum) + source += '&checksum=' + this._history[history_id].checksum; + + var history_markers = this._history[history_id].markers; + for(var i=0,size=history_markers.length; 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 + diff --git a/WebContent/routing/OSRM.Routing.js b/WebContent/routing/OSRM.Routing.js index a0193681d..e6f29700f 100644 --- a/WebContent/routing/OSRM.Routing.js +++ b/WebContent/routing/OSRM.Routing.js @@ -69,7 +69,6 @@ showRoute: function(response) { OSRM.RoutingNoNames.show(response); OSRM.RoutingDescription.show(response); OSRM.Routing._snapRoute(); - OSRM.G.route.storeHistoryRoute(); } OSRM.Routing._updateHints(response); }, @@ -78,14 +77,14 @@ showRoute_Dragging: function(response) { return; if( !OSRM.G.dragging ) // prevent simple routing when not dragging (required as there can be drag events after a dragstop event!) return; - + + OSRM.G.response = response; 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.G.route.storeHistoryRoute(); } OSRM.Routing._updateHints(response); @@ -102,16 +101,6 @@ showRoute_Redraw: function(response) { } OSRM.Routing._updateHints(response); }, -showRoute_RedrawHistory: function(response, history_id) { - if(!response) - return; - - if(response.status != 207) { - var positions = OSRM.RoutingGeometry._decode(response.route_geometry, 5); - OSRM.G.route._history_route[history_id].setPositions(positions); - } -}, - //-- main function -- @@ -146,13 +135,6 @@ getRoute_Redraw: function() { OSRM.JSONP.clear('redraw'); OSRM.JSONP.call(OSRM.Routing._buildCall()+'&instructions=true', OSRM.Routing.showRoute_Redraw, OSRM.Routing.timeoutRoute, OSRM.DEFAULTS.JSONP_TIMEOUT, 'redraw'); }, -getRoute_RedrawHistory: function() { - for(var i=0; i<10; i++) - if( OSRM.G.route._history_data[i].length > 0 ) { - OSRM.JSONP.clear('history'+i); - OSRM.JSONP.call(OSRM.Routing._buildHistoryCall(i)+'&instructions=false', OSRM.Routing.showRoute_RedrawHistory, OSRM.JSONP.empty, OSRM.DEFAULTS.JSONP_TIMEOUT, 'history'+i, i); - } -}, getRoute_Dragging: function() { OSRM.G.pending = !OSRM.JSONP.call(OSRM.Routing._buildCall()+'&instructions=false', OSRM.Routing.showRoute_Dragging, OSRM.Routing.timeoutRoute_Dragging, OSRM.DEFAULTS.JSONP_TIMEOUT, 'dragging');; }, @@ -174,19 +156,6 @@ _buildCall: function() { } return source; }, -_buildHistoryCall: function(history_id) { - var source = OSRM.DEFAULTS.HOST_ROUTING_URL; - source += '?z=' + OSRM.G.map.getZoom() + '&output=json&jsonp=%jsonp&geomformat=cmp'; - if(OSRM.G.markers.checksum) - source += '&checksum=' + OSRM.G.markers.checksum; - var markers = OSRM.G.route._history_data[history_id]; - for(var i=0,size=markers.length; i