changed many names for jsonp routing functions

This commit is contained in:
DennisSchiefer 2012-05-11 12:30:00 +01:00
parent 4a8c2f323c
commit c0e86c47c2
5 changed files with 117 additions and 56 deletions

View File

@ -75,9 +75,10 @@ initPosition: function() {
// map event handlers
zoomed: function(e) {
if(OSRM.G.dragging)
OSRM.Routing.getDragRoute();
OSRM.Routing.getRoute_Dragging();
else
OSRM.Routing.getZoomRoute();
OSRM.Routing.getRoute_Redraw();
// OSRM.Routing.getRoute_History();
},
contextmenu: function(e) {;},
mousemove: function(e) { OSRM.Via.drawDragMarker(e); },

View File

@ -18,6 +18,17 @@ 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.SimplePosition = function(lat, lng, hint) {
// this.lat = lat;
// this.lng = lng;
// this.hint = hint;
//};
//OSRM.extend( OSRM.SimplePosition,{
//getLat: function() { return this.lat; },
//getLng: function() { return this.lng; }
//});
OSRM.Route = function() {
this._current_route = new OSRM.SimpleRoute("current" , {dashed:false} );
this._old_route = new OSRM.SimpleRoute("old", {dashed:false,color:"#123"} );
@ -32,20 +43,24 @@ OSRM.Route = function() {
this._noroute = OSRM.Route.ROUTE;
this._route_history_styles = [{dashed:false, color:'#FF0000', weight:5},
{dashed:false, color:'#00FF00', weight:5},
{dashed:false, color:'#0000FF', weight:5},
{dashed:false, color:'#FF00FF', weight:5},
{dashed:false, color:'#00FFFF', weight:5},
{dashed:false, color:'#770000', weight:5},
{dashed:false, color:'#007700', weight:5},
{dashed:false, color:'#000077', weight:5},
{dashed:false, color:'#770077', weight:5},
{dashed:false, color:'#007777', weight:5}
];
this._route_history = [];
for(var i=0, size=this._route_history_styles.length; i<size; i++)
this._route_history.push( new OSRM.SimpleRoute("current" , {dashed:false} ) );
this._history_styles = [{dashed:false, color:'#FF0000', weight:5},
{dashed:false, color:'#00FF00', weight:5},
{dashed:false, color:'#0000FF', weight:5},
{dashed:false, color:'#FF00FF', weight:5},
{dashed:false, color:'#00FFFF', weight:5},
{dashed:false, color:'#770000', weight:5},
{dashed:false, color:'#007700', weight:5},
{dashed:false, color:'#000077', weight:5},
{dashed:false, color:'#770077', weight:5},
{dashed:false, color:'#007777', weight:5}
];
this._history_routes = this._history_styles.length;
this._history_route = [];
this._history_data = [];
for(var i=0, size=this._history_routes; i<size; i++) {
this._history_route.push( new OSRM.SimpleRoute("current" , {dashed:false} ) );
this._history_data[i] = [];
}
};
OSRM.Route.NOROUTE = true;
OSRM.Route.ROUTE = false;
@ -130,26 +145,41 @@ OSRM.extend( OSRM.Route,{
// history route handling
storeHistoryRoute: function() {
if( document.getElementById('option-show-previous-routes').checked == false)
return;
if(this.isShown() && this.isRoute()) {
for(var i=this._route_history.length-1; i>0; i--)
this._route_history[i].setPositions( this._route_history[i-1].getPositions() );
this._route_history[0].setPositions( this._current_route.getPositions() );
}
// if( document.getElementById('option-show-previous-routes').checked == false)
// return;
// if(this.isShown() && this.isRoute()) {
// // move route and positions
// for(var i=this._history_routes-1; i>0; i--) {
// this._history_route[i].setPositions( this._history_route[i-1].getPositions() );
// this._history_data[i] = this._history_data[i-1];
// }
// // store new route and positions
// this._history_route[0].setPositions( this._current_route.getPositions() );
// this._history_data[0] = [];
// var markers = OSRM.G.markers.route;
// for(var i=0,size=markers.length; i<size; i++) {
// var position = new OSRM.SimplePosition(markers[i].getLat(), markers[i].getLng(), markers[i].hint);
//// lat:markers[i].getLat(),
//// lng:markers[i].getLng(),
//// hint:markers[i].hint
//// };
// this._history_data[0].push(position);
// }
// }
},
showHistoryRoutes: function() {
if( document.getElementById('option-show-previous-routes').checked == false)
return;
for(var i=1,size=this._route_history.length; i<size; i++) {
this._route_history[i].setStyle( this._route_history_styles[i] );
this._route_history[i].show();
}
// if( document.getElementById('option-show-previous-routes').checked == false)
// return;
// for(var i=1,size=this._history_routes; i<size; i++) {
// this._history_route[i].setStyle( this._history_styles[i] );
// this._history_route[i].show();
// }
},
clearHistoryRoutes: function() {
for(var i=0,size=this._route_history.length; i<size; i++) {
this._route_history[i].hide();
this._route_history[i].setPositions( [] );
}
// for(var i=0,size=this._history_route.length; i<size; i++) {
// this._history_route[i].hide();
// this._history_route[i].setPositions( [] );
// this._history_data[i] = [];
// }
}
});

View File

@ -95,7 +95,7 @@ onClick: function(e) {
onDrag: function(e) {
this.parent.setPosition( e.target.getLatLng() );
if(OSRM.G.markers.route.length>1)
OSRM.Routing.getDragRoute();
OSRM.Routing.getRoute_Dragging();
OSRM.Geocoder.updateLocation( this.parent.label );
},
onDragStart: function(e) {

View File

@ -39,7 +39,7 @@ init: function() {
document.getElementById("gui-reverse").onclick = OSRM.GUI.reverseRouting;
document.getElementById("open-josm").onclick = OSRM.GUI.openJOSM;
document.getElementById("open-osmbugs").onclick = OSRM.GUI.openOSMBugs;
document.getElementById("option-highlight-nonames").onclick = OSRM.Routing.getZoomRoute;
document.getElementById("option-highlight-nonames").onclick = OSRM.Routing.getRoute_Redraw;
document.getElementById("option-show-previous-routes").onclick = OSRM.GUI.showPreviousRoutes;
},
@ -67,7 +67,7 @@ reverseRouting: function() {
// recompute route if needed
if( OSRM.G.route.isShown() ) {
OSRM.G.markers.route.reverse();
OSRM.Routing.getRoute(); // temporary route reversal for query, actual reversal done after receiving response
OSRM.Routing.getRoute_Reversed(); // temporary route reversal for query, actual reversal done after receiving response
OSRM.G.markers.route.reverse();
OSRM.G.markers.highlight.hide();
OSRM.RoutingDescription.showSimple( OSRM.G.response );

View File

@ -92,7 +92,7 @@ showRoute: function(response) {
}
OSRM.Routing._updateHints(response);
},
showRouteZooming: function(response) {
showRouteRedraw: function(response) {
if(!response)
return;
@ -102,6 +102,15 @@ showRouteZooming: function(response) {
}
OSRM.Routing._updateHints(response);
},
showRouteHistory: 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);
}
},
@ -116,33 +125,40 @@ getRoute: function() {
return;
}
OSRM.JSONP.clear('dragging');
OSRM.JSONP.clear('zooming');
OSRM.JSONP.clear('redraw');
OSRM.JSONP.clear('route');
OSRM.JSONP.call(OSRM.Routing._buildCall()+'&instructions=true', OSRM.Routing.showRoute, OSRM.Routing.timeoutRoute, OSRM.DEFAULTS.JSONP_TIMEOUT, 'route');
},
getZoomRoute: function() {
getRoute_Reversed: function() {
if( OSRM.G.markers.route.length < 2 )
return;
OSRM.JSONP.clear('dragging');
OSRM.JSONP.clear('zooming');
OSRM.JSONP.call(OSRM.Routing._buildCall()+'&instructions=true', OSRM.Routing.showRouteZooming, OSRM.Routing.timeoutRoute, OSRM.DEFAULTS.JSONP_TIMEOUT, 'zooming');
},
getDragRoute: function() {
OSRM.G.pending = !OSRM.JSONP.call(OSRM.Routing._buildCall()+'&instructions=false', OSRM.Routing.showRouteSimple, OSRM.Routing.timeoutRouteSimple, OSRM.DEFAULTS.JSONP_TIMEOUT, 'dragging');;
},
getReverseRoute: function() {
if( OSRM.G.markers.route.length < 2 )
return;
OSRM.JSONP.clear('dragging');
OSRM.JSONP.clear('zooming');
OSRM.JSONP.clear('redraw');
OSRM.JSONP.clear('route');
OSRM.JSONP.call(OSRM.Routing._buildCall()+'&instructions=true', OSRM.Routing.showRoute, OSRM.Routing.timeoutRouteReverse, OSRM.DEFAULTS.JSONP_TIMEOUT, 'route');
},
getRoute_Redraw: function() {
if( OSRM.G.markers.route.length < 2 )
return;
OSRM.JSONP.clear('dragging');
OSRM.JSONP.clear('redraw');
OSRM.JSONP.call(OSRM.Routing._buildCall()+'&instructions=true', OSRM.Routing.showRouteRedraw, OSRM.Routing.timeoutRoute, OSRM.DEFAULTS.JSONP_TIMEOUT, 'redraw');
},
getRoute_History: 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.showRouteHistory, 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.showRouteSimple, OSRM.Routing.timeoutRouteSimple, OSRM.DEFAULTS.JSONP_TIMEOUT, 'dragging');;
},
draggingTimeout: function() {
OSRM.G.markers.route[OSRM.G.dragid].hint = null;
OSRM.Routing.getDragRoute();
OSRM.Routing.getRoute_Dragging();
},
_buildCall: function() {
@ -150,10 +166,24 @@ _buildCall: function() {
source += '?z=' + OSRM.G.map.getZoom() + '&output=json&jsonp=%jsonp&geomformat=cmp';
if(OSRM.G.markers.checksum)
source += '&checksum=' + OSRM.G.markers.checksum;
for(var i=0,size=OSRM.G.markers.route.length; i<size; i++) {
source += '&loc=' + OSRM.G.markers.route[i].getLat().toFixed(6) + ',' + OSRM.G.markers.route[i].getLng().toFixed(6);
if( OSRM.G.markers.route[i].hint)
source += '&hint=' + OSRM.G.markers.route[i].hint;
var markers = OSRM.G.markers.route;
for(var i=0,size=markers.length; i<size; i++) {
source += '&loc=' + markers[i].getLat().toFixed(6) + ',' + markers[i].getLng().toFixed(6);
if( markers[i].hint)
source += '&hint=' + markers[i].hint;
}
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<size; i++) {
source += '&loc=' + markers[i].lat.toFixed(6) + ',' + markers[i].lng.toFixed(6);
if( markers[i].hint)
source += '&hint=' + markers[i].hint;
}
return source;
},