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 = {
// default state
// defaults
visible: true,
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
toggleMain: function() {

View File

@ -158,7 +158,7 @@ toString: function() {
// [this holds the vital information of the route]
OSRM.Markers = function() {
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,{
removeAll: function() {
@ -177,7 +177,7 @@ setSource: function(position) {
if( this.route[0] && this.route[0].label == OSRM.C.SOURCE_LABEL )
this.route[0].setPosition(position);
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;
},
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 )
this.route[this.route.length-1].setPosition(position);
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;
},
setVia: function(id, position) {
@ -193,7 +193,7 @@ setVia: function(id, position) {
if( this.route.length<2 || id > this.route.length-2 )
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;
},
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.config.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.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="main.js" type="text/javascript"></script>
<script src="OSRM.GUI.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.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>
</head>
<!-- body -->
<body onload="init();">
<body onload="OSRM.init();">
<!--map-->
<div id="map"></div>

View File

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