Skip to content

Commit

Permalink
Incorporate Leaflet 0.5 changes into L.Control.Zoomslider.
Browse files Browse the repository at this point in the history
  • Loading branch information
bshelton229 authored and Mattias Bengtsson committed Nov 21, 2012
1 parent 21a730e commit 40adeee
Showing 1 changed file with 27 additions and 8 deletions.
35 changes: 27 additions & 8 deletions src/L.Control.Zoomslider.js
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
},
Expand Down Expand Up @@ -129,6 +132,7 @@ L.Control.Zoomslider = L.Control.extend({
},

_snapToSliderValue: function(sliderValue) {
this._updateDisabled();
if(this._knob) {
sliderValue = isNaN(sliderValue)
? this._getSliderValue()
Expand All @@ -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);
}
}
});

Expand Down

0 comments on commit 40adeee

Please sign in to comment.