From 40adeee18cb50856944bea7e9fb7c99d19b81b94 Mon Sep 17 00:00:00 2001 From: Bryan Shelton Date: Tue, 20 Nov 2012 15:55:31 -0600 Subject: [PATCH] Incorporate Leaflet 0.5 changes into L.Control.Zoomslider. --- src/L.Control.Zoomslider.js | 35 +++++++++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 8 deletions(-) diff --git a/src/L.Control.Zoomslider.js b/src/L.Control.Zoomslider.js index 38d0e5a..2fe1ddf 100644 --- a/src/L.Control.Zoomslider.js +++ b/src/L.Control.Zoomslider.js @@ -7,14 +7,14 @@ L.Control.Zoomslider = L.Control.extend({ onAdd: function (map) { var className = 'leaflet-control-zoomslider', - container = L.DomUtil.create('div', className); + container = L.DomUtil.create('div', className); - this._map = map; + this._map = map; - this._createButton('Zoom in', className + '-in' + this._zoomInButton = this._createButton('+', 'Zoom in', className + '-in' , container, this._zoomIn , this); this._createSlider(className + '-slider', container, map); - this._createButton('Zoom out', className + '-out' + this._zoomOutButton = this._createButton('-', 'Zoom out', className + '-out' , container, this._zoomOut, this); map.on('zoomend', this._snapToSliderValue, this); @@ -69,15 +69,18 @@ L.Control.Zoomslider = L.Control.extend({ this._map.zoomOut(e.shiftKey ? 3 : 1); }, - _createButton: function (title, className, container, fn, context) { + _createButton: function (html, title, className, container, fn, context) { var link = L.DomUtil.create('a', className, container); + link.innerHTML = html; link.href = '#'; link.title = title; L.DomEvent - .on(link, 'click', L.DomEvent.stopPropagation) - .on(link, 'click', L.DomEvent.preventDefault) - .on(link, 'click', fn, context); + .on(link, 'click', L.DomEvent.stopPropagation) + .on(link, 'mousedown', L.DomEvent.stopPropagation) + .on(link, 'dblclick', L.DomEvent.stopPropagation) + .on(link, 'click', L.DomEvent.preventDefault) + .on(link, 'click', fn, context); return link; }, @@ -129,6 +132,7 @@ L.Control.Zoomslider = L.Control.extend({ }, _snapToSliderValue: function(sliderValue) { + this._updateDisabled(); if(this._knob) { sliderValue = isNaN(sliderValue) ? this._getSliderValue() @@ -146,6 +150,21 @@ L.Control.Zoomslider = L.Control.extend({ }, _getSliderValue: function(){ return this._toSliderValue(this._map.getZoom()); + }, + + _updateDisabled: function () { + var map = this._map, + className = 'leaflet-control-zoomslider-disabled'; + + L.DomUtil.removeClass(this._zoomInButton, className); + L.DomUtil.removeClass(this._zoomOutButton, className); + + if (map._zoom === map.getMinZoom()) { + L.DomUtil.addClass(this._zoomOutButton, className); + } + if (map._zoom === map.getMaxZoom()) { + L.DomUtil.addClass(this._zoomInButton, className); + } } });