reordered styles in main.html,

readded default values to GUI,
made TODO marker to check whether GUI is initilaized
This commit is contained in:
DennisSchiefer 2012-03-28 15:02:09 +01:00
parent c5bd2b0b1d
commit 4fe6346146
4 changed files with 58 additions and 63 deletions

View File

@ -20,10 +20,31 @@ or see http://www.gnu.org/licenses/agpl.txt.
OSRM.GUI = { OSRM.GUI = {
// default state // defaults
visible: true, visible: true,
width: 410, 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 // show/hide main-gui
toggleMain: function() { toggleMain: function() {

View File

@ -158,7 +158,7 @@ toString: function() {
// [this holds the vital information of the route] // [this holds the vital information of the route]
OSRM.Markers = function() { OSRM.Markers = function() {
this.route = new Array(); 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,{ OSRM.extend( OSRM.Markers,{
removeAll: function() { removeAll: function() {
@ -177,7 +177,7 @@ setSource: function(position) {
if( this.route[0] && this.route[0].label == OSRM.C.SOURCE_LABEL ) if( this.route[0] && this.route[0].label == OSRM.C.SOURCE_LABEL )
this.route[0].setPosition(position); this.route[0].setPosition(position);
else 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; return 0;
}, },
setTarget: function(position) { 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 ) 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); this.route[this.route.length-1].setPosition(position);
else 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; return this.route.length-1;
}, },
setVia: function(id, position) { setVia: function(id, position) {
@ -193,7 +193,7 @@ setVia: function(id, position) {
if( this.route.length<2 || id > this.route.length-2 ) if( this.route.length<2 || id > this.route.length-2 )
return -1; 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; return id+1;
}, },
removeMarker: function(id) { removeMarker: function(id) {

View File

@ -45,26 +45,25 @@ or see http://www.gnu.org/licenses/agpl.txt.
<script src="OSRM.base.js" type="text/javascript"></script> <script src="OSRM.base.js" type="text/javascript"></script>
<script src="OSRM.config.js" type="text/javascript"></script> <script src="OSRM.config.js" type="text/javascript"></script>
<!-- <script defer="defer" src="OSRM.debug.js" type="text/javascript"></script> --> <!-- <script defer="defer" src="OSRM.debug.js" type="text/javascript"></script> -->
<script src="main.js" type="text/javascript"></script>
<script src="OSRM.Browser.js" type="text/javascript"></script>
<script src="OSRM.GUI.js" type="text/javascript"></script>
<script src="OSRM.JSONP.js" type="text/javascript"></script>
<script src="OSRM.Markers.js" type="text/javascript"></script> <script src="OSRM.Markers.js" type="text/javascript"></script>
<script src="OSRM.Route.js" type="text/javascript"></script> <script src="OSRM.Route.js" type="text/javascript"></script>
<script src="OSRM.Localization.js" type="text/javascript"></script>
<script src="OSRM.Geocoder.js" type="text/javascript"></script> <script src="OSRM.GUI.js" type="text/javascript"></script>
<script src="main.js" type="text/javascript"></script>
<script src="OSRM.Routing.js" type="text/javascript"></script> <script src="OSRM.Routing.js" type="text/javascript"></script>
<script src="OSRM.Via.js" type="text/javascript"></script> <script src="OSRM.Via.js" type="text/javascript"></script>
<script src="OSRM.Geocoder.js" type="text/javascript"></script>
<script src="OSRM.Browser.js" type="text/javascript"></script>
<script src="OSRM.JSONP.js" type="text/javascript"></script>
<script src="OSRM.Localization.js" type="text/javascript"></script>
<script src="OSRM.Utils.js" type="text/javascript"></script> <script src="OSRM.Utils.js" type="text/javascript"></script>
</head> </head>
<!-- body --> <!-- body -->
<body onload="init();"> <body onload="OSRM.init();">
<!--map--> <!--map-->
<div id="map"></div> <div id="map"></div>

View File

@ -16,30 +16,29 @@ or see http://www.gnu.org/licenses/agpl.txt.
*/ */
// OSRM initialization // OSRM initialization
// [initialization of maps, local strings, image prefetching] // [initialization of maps, gui, image prefetching]
// will hold the Leaflet map object // will hold the Leaflet map object
OSRM.GLOBALS.map = null; OSRM.GLOBALS.map = null;
// onload initialization routine // onload initialization routine
function init() { OSRM.init = function() {
prefetchImages(); OSRM.prefetchImages();
prefetchIcons(); OSRM.prefetchIcons();
initLocale(); OSRM.GUI.init();
initGUI();
initMap();
OSRM.Routing.init(); OSRM.Routing.init();
OSRM.initMap();
// check if the URL contains some GET parameter, e.g. for the route // check if the URL contains some GET parameter, e.g. for showing a route
checkURL(); OSRM.checkURL();
} };
// prefetch images // prefetch images
OSRM.images = Array(); OSRM.GLOBALS.images = Array();
function prefetchImages() { OSRM.prefetchImages = function() {
var images = [ 'images/marker-source.png', var images = [ 'images/marker-source.png',
'images/marker-target.png', 'images/marker-target.png',
'images/marker-via.png', 'images/marker-via.png',
@ -53,15 +52,15 @@ function prefetchImages() {
]; ];
for(var i=0; i<images.length; i++) { for(var i=0; i<images.length; i++) {
OSRM.images[i] = new Image(); OSRM.G.images[i] = new Image();
OSRM.images[i].src = images[i]; OSRM.G.images[i].src = images[i];
} }
} };
// prefetch icons // prefetch icons
OSRM.icons = Array(); OSRM.GLOBALS.icons = Array();
function prefetchIcons() { OSRM.prefetchIcons = function() {
var images = [ 'marker-source', var images = [ 'marker-source',
'marker-target', 'marker-target',
'marker-via', 'marker-via',
@ -69,34 +68,8 @@ function prefetchIcons() {
]; ];
for(var i=0; i<images.length; i++) for(var i=0; i<images.length; i++)
OSRM.icons[images[i]] = new L.Icon('images/'+images[i]+'.png'); OSRM.G.icons[images[i]] = new L.Icon('images/'+images[i]+'.png');
} };
// init GUI
function initGUI() {
OSRM.GUI.visible = true;
OSRM.GUI.width = document.getElementById("main-wrapper").clientWidth;
}
// init localization
function initLocale() {
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;
}
// centering on geolocation // centering on geolocation
@ -110,7 +83,9 @@ function centerOnGeolocation() {
// init map // init map
function initMap() { OSRM.initMap = function() {
// TODO: check if GUI is initialized!
// setup tile servers // setup tile servers
var osmorgURL = 'http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', var osmorgURL = 'http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
osmorgAttribution = 'Map data &copy; 2011 OpenStreetMap contributors, Imagery &copy; 2011 Mapnik', osmorgAttribution = 'Map data &copy; 2011 OpenStreetMap contributors, Imagery &copy; 2011 Mapnik',
@ -185,11 +160,11 @@ function initMap() {
OSRM.Routing.getRoute( OSRM.C.FULL_DESCRIPTION ); OSRM.Routing.getRoute( OSRM.C.FULL_DESCRIPTION );
} }
} ); } );
} };
// parse URL GET parameters if any exist // parse URL GET parameters if any exist
function checkURL(){ OSRM.checkURL = function(){
var called_url = document.location.search.substr(1,document.location.search.length); var called_url = document.location.search.substr(1,document.location.search.length);
// reject messages that are clearly too long or too small // reject messages that are clearly too long or too small
@ -277,4 +252,4 @@ function checkURL(){
// compute route // compute route
OSRM.Routing.getRoute(OSRM.C.FULL_DESCRIPTION); OSRM.Routing.getRoute(OSRM.C.FULL_DESCRIPTION);
} }
} };