extended mapview to give information about the current visible tile

layer,
continued work on printing
This commit is contained in:
shiin
2012-04-24 00:56:41 +02:00
parent dffd67ef72
commit 7421117278
6 changed files with 81 additions and 47 deletions
+2 -19
View File
@@ -22,22 +22,6 @@ or see http://www.gnu.org/licenses/agpl.txt.
OSRM.GLOBALS.map = null;
L.MyLayers = L.Control.Layers.extend({
getActive: function () {
var i, input, obj,
inputs = this._form.getElementsByTagName('input'),
inputsLen = inputs.length;
for (i = 0; i < inputsLen; i++) {
input = inputs[i];
obj = this._layers[input.layerId];
if (input.checked && !obj.overlay) {
return obj.name;
}
}
}
});
// map controller
// [map initialization, event handling]
OSRM.Map = {
@@ -66,9 +50,8 @@ init: function() {
});
// add layer control
var layersControl = new L.MyLayers(base_maps, {});
OSRM.G.map.layerControl = layersControl;
OSRM.G.map.addControl(layersControl);
var layerControl = new L.Control.QueryableLayers(base_maps, {});
OSRM.G.map.addLayerControl(layerControl);
// move zoom markers
OSRM.Browser.getElementsByClassName(document,'leaflet-control-zoom')[0].style.left=(OSRM.GUI.width+10)+"px";
@@ -0,0 +1,34 @@
/*
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.
*/
// queryable Layers control
// [simply Control.Layers extended by query functions]
L.Control.QueryableLayers = L.Control.Layers.extend({
getActiveLayerName: function () {
var i, input, obj,
inputs = this._form.getElementsByTagName('input'),
inputsLen = inputs.length;
for (i = 0; i < inputsLen; i++) {
input = inputs[i];
obj = this._layers[input.layerId];
if (input.checked && !obj.overlay) {
return obj.name;
}
}
}
});
+21 -1
View File
@@ -16,7 +16,7 @@ or see http://www.gnu.org/licenses/agpl.txt.
*/
// map view/model
// [extending Leaflet L.Map with setView/fitBounds methods that respect UI visibility]
// [extending Leaflet L.Map with setView/fitBounds methods that respect UI visibility, better layerControl]
OSRM.MapView = L.Map.extend({
setViewUI: function(position, zoom, no_animation) {
if( OSRM.GUI.visible == true ) {
@@ -50,5 +50,25 @@ OSRM.MapView = L.Map.extend({
var centerPoint = this._getTopLeftPoint().add(viewHalf.divideBy(2));
return this.unproject(centerPoint, this._zoom, unbounded);
},
addLayerControl: function( layerControl ) {
if( this.layerControl )
return;
this.layerControl = layerControl;
this.addControl(this.layerControl);
},
getActiveLayerId: function() {
var tile_server_id = 0;
var tile_servers = OSRM.DEFAULTS.TILE_SERVERS;
var tile_server_name = this.layerControl.getActiveLayerName();
for(var i=0, size=tile_servers.length; i<size; i++)
if( tile_servers[tile_server_id].display_name == tile_server_name ) {
tile_server_id = i;
break;
}
return tile_server_id;
}
});