first code for managing alternatives

This commit is contained in:
shiin 2012-06-17 09:07:32 +02:00
parent eeec69dfab
commit 7d82661927
4 changed files with 123 additions and 3 deletions

View File

@ -20,9 +20,10 @@ or see http://www.gnu.org/licenses/agpl.txt.
OSRM.Route = function() { OSRM.Route = function() {
this._current_route = new OSRM.SimpleRoute("current" , {dashed:false} ); this._current_route = new OSRM.SimpleRoute("current" , {dashed:false} );
this._old_route = new OSRM.SimpleRoute("old", {dashed:false,color:"#123"} ); this._alternative_route = new OSRM.SimpleRoute("alternative" , {dashed:false} );
this._unnamed_route = new OSRM.MultiRoute("unnamed"); this._old_route = new OSRM.SimpleRoute("old", {dashed:false,color:"#123"} );
this._unnamed_route = new OSRM.MultiRoute("unnamed");
this._current_route_style = {dashed:false,color:'#0033FF', weight:5}; this._current_route_style = {dashed:false,color:'#0033FF', weight:5};
this._current_noroute_style = {dashed:true, color:'#222222', weight:2}; this._current_noroute_style = {dashed:true, color:'#222222', weight:2};
@ -30,6 +31,7 @@ OSRM.Route = function() {
this._old_noroute_style = {dashed:true, color:'#000000', weight:2}; this._old_noroute_style = {dashed:true, color:'#000000', weight:2};
this._unnamed_route_style = {dashed:false, color:'#FF00FF', weight:10}; this._unnamed_route_style = {dashed:false, color:'#FF00FF', weight:10};
this._old_unnamed_route_style = {dashed:false, color:'#990099', weight:10}; this._old_unnamed_route_style = {dashed:false, color:'#990099', weight:10};
this._alternative_route_style = {dashed:false,color:'#FF3300', weight:5};
this._noroute = OSRM.Route.ROUTE; this._noroute = OSRM.Route.ROUTE;
this._history = new OSRM.HistoryRoute(); this._history = new OSRM.HistoryRoute();
@ -99,6 +101,16 @@ OSRM.extend( OSRM.Route,{
this._old_route.hide(); this._old_route.hide();
}, },
// show/hide alternative route
showAlternativeRoute: function(positions) {
this._alternative_route.setPositions( positions );
this._alternative_route.setStyle( this._alternative_route_style );
this._alternative_route.show();
},
hideAlternativeRoute: function() {
this._alternative_route.hide();
},
// query routines // query routines
isShown: function() { isShown: function() {
return this._current_route.isShown(); return this._current_route.isShown();

View File

@ -532,6 +532,21 @@ html, body {
outline-style:none; outline-style:none;
vertical-align:1px; vertical-align:1px;
} }
.button-pressed
{
cursor:pointer;
padding:2px 10px 2px 10px;
border-radius:5px;
-moz-border-radius:5px;
-webkit-border-radius:5px;
background-color:#DDDDDD;
border:1px solid #999999;
color:#000000;
text-decoration:none;
font-size:9px;
outline-style:none;
vertical-align:1px;
}
/* iconic buttons */ /* iconic buttons */

View File

@ -68,6 +68,7 @@ showRoute: function(response) {
OSRM.RoutingGeometry.show(response); OSRM.RoutingGeometry.show(response);
OSRM.RoutingNoNames.show(response); OSRM.RoutingNoNames.show(response);
OSRM.RoutingDescription.show(response); OSRM.RoutingDescription.show(response);
OSRM.RoutingAlternatives.prepare(response);
OSRM.Routing._snapRoute(); OSRM.Routing._snapRoute();
} }
OSRM.Routing._updateHints(response); OSRM.Routing._updateHints(response);

View File

@ -0,0 +1,92 @@
/*
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 alternatives
// [everything about handling alternatives]
OSRM.RoutingAlternatives = {
// prepare response
prepare: function() {
OSRM.RoutingAlternatives._buildAlternatives();
},
// add alternatives
_buildAlternatives: function() {
var data =
'<a class="button top-right-button" id="gui-b">B</a>' +
'<a class="button-pressed top-right-button" id="gui-a">A</a>';
document.getElementById('information-box-header').innerHTML = data + document.getElementById('information-box-header').innerHTML;
OSRM.G.response.active = 0;
document.getElementById("gui-a").onclick = function () {
if( OSRM.G.response.active == 0 )
return;
document.getElementById("gui-a").className = "button-pressed top-right-button";
document.getElementById("gui-b").className = "button top-right-button";
OSRM.G.route.hideAlternativeRoute();
OSRM.G.response.active = 0;
// switch data
//OSRM.Routing.showRoute(OSRM.G.response);
console.log("click a");
};
document.getElementById("gui-a").onmouseover = function () {
if( OSRM.G.response.active == 0 )
return;
var geometry = OSRM.RoutingGeometry._decode(OSRM.G.response.route_geometry, 5);
OSRM.G.route.showAlternativeRoute(geometry);
console.log("over a");
};
document.getElementById("gui-a").onmouseout = function () {
if( OSRM.G.response.active == 0 )
return;
OSRM.G.route.hideAlternativeRoute();
console.log("out a");
};
document.getElementById("gui-b").onclick = function () {
if( OSRM.G.response.active == 1 )
return;
document.getElementById("gui-a").className = "button top-right-button";
document.getElementById("gui-b").className = "button-pressed top-right-button";
OSRM.G.route.hideAlternativeRoute();
OSRM.G.response.active = 1;
// switch data
//OSRM.Routing.showRoute(OSRM.G.response);
console.log("click b");
};
document.getElementById("gui-b").onmouseover = function () {
if( OSRM.G.response.active == 1 )
return;
var geometry = OSRM.RoutingGeometry._decode(OSRM.G.response.route_geometry, 5);
OSRM.G.route.showAlternativeRoute(geometry);
console.log("over b");
};
document.getElementById("gui-b").onmouseout = function () {
if( OSRM.G.response.active == 1 )
return;
OSRM.G.route.hideAlternativeRoute();
console.log("out b");
};
}
};