further restructuring of gui buttons

This commit is contained in:
DennisSchiefer
2012-08-23 17:08:55 +01:00
parent f2cd56b329
commit e1cb34cf38
9 changed files with 152 additions and 56 deletions
+5 -1
View File
@@ -55,9 +55,13 @@ init: function() {
fadeAnimation: false
});
// add locations control
var locationsControl = new L.Control.Locations();
OSRM.G.map.addControl(locationsControl);
// add layer control
var layerControl = new L.Control.QueryableLayers(base_maps, {});
OSRM.G.map.addLayerControl(layerControl);
OSRM.G.map.addLayerControl(layerControl);
// move zoom markers
OSRM.Browser.getElementsByClassName(document,'leaflet-control-zoom')[0].style.left=(OSRM.G.main_handle.boxWidth()+10)+"px";
@@ -15,32 +15,34 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
or see http://www.gnu.org/licenses/agpl.txt.
*/
// goto Layers control
// [used to add clickable buttons to the map]
L.Control.Goto = L.Control.extend({
// locations control
// [buttons to important locations - zoom on route, zoom on user]
L.Control.Locations = L.Control.extend({
options: {
position: 'topright'
},
onAdd: function (map) {
var className = 'leaflet-control-goto',
var className = 'leaflet-control-locations',
container = L.DomUtil.create('div', className);
this._createButton('Goto Location', className + '-my-location', container, map.zoomIn, map);
this._createButton('Goto Route', className + '-route', container, map.zoomOut, map);
this._createButton('Goto Location', className + '-user', container, OSRM.GUI.zoomOnUser, map);
this._createButton('Goto Route', className + '-route', container, OSRM.GUI.zoomOnRoute, map);
return container;
},
_createButton: function (title, className, container, fn, context) {
var link = L.DomUtil.create('a', className, container);
link.href = '#';
link.id = className;
link.title = title;
L.DomEvent
.on(link, 'click', L.DomEvent.stopPropagation)
.on(link, 'click', L.DomEvent.preventDefault)
.on(link, 'click', fn, context)
.on(link, 'mousedown', function() { this.className = this.id + "-active"; } )
.on(link, 'mouseup', function() { this.className = this.id + ""; } )
.on(link, 'dblclick', L.DomEvent.stopPropagation);
return link;
@@ -48,16 +50,16 @@ L.Control.Goto = L.Control.extend({
});
L.Map.mergeOptions({
gotoControl: true
locationsControl: false
});
L.Map.addInitHook(function () {
if (this.options.gotoControl) {
this.gotoControl = new L.Control.Goto();
this.addControl(this.gotoControl);
if (this.options.locationsControl) {
this.locationsControl = new L.Control.Locations();
this.addControl(this.locationsControl);
}
});
L.control.Goto = function (options) {
return new L.Control.Goto(options);
L.control.locations = function (options) {
return new L.Control.Locations(options);
};
+19
View File
@@ -1,3 +1,22 @@
/*
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.
*/
// zoom control
// [control moves with sidebar and changes color when clicked]
L.Control.Zoom = L.Control.extend({
options: {
position: 'topleft'