diff --git a/SliderControl.js b/SliderControl.js index ed14c0e..8505b51 100644 --- a/SliderControl.js +++ b/SliderControl.js @@ -112,35 +112,24 @@ L.Control.SliderControl = L.Control.extend({ } var i; + // clear markers + for (i = _options.minValue; i <= _options.maxValue; i++) { + if(_options.markers[i]) map.removeLayer(_options.markers[i]); + } if(_options.range){ // jquery ui using range for (i = ui.values[0]; i <= ui.values[1]; i++){ if(_options.markers[i]) map.addLayer(_options.markers[i]); } - for (i = _options.maxValue; i > ui.values[1]; i--) { - if(_options.markers[i]) map.removeLayer(_options.markers[i]); - } - for (i = _options.minValue; i < ui.values[0]; i++) { - if(_options.markers[i]) map.removeLayer(_options.markers[i]); - } }else if(_options.follow){ - for (i = _options.minValue; i < (ui.value - _options.follow); i++) { - if(_options.markers[i]) map.removeLayer(_options.markers[i]); - } - for (i = (ui.value - _options.follow); i < ui.value ; i++) { + for (i = ui.value - _options.follow + 1; i <= ui.value ; i++) { if(_options.markers[i]) map.addLayer(_options.markers[i]); } - for (i = ui.value; i <= _options.maxValue; i++) { - if(_options.markers[i]) map.removeLayer(_options.markers[i]); - } }else{ // jquery ui for point before for (i = _options.minValue; i <= ui.value ; i++) { if(_options.markers[i]) map.addLayer(_options.markers[i]); } - for (i = (ui.value + 1); i <= _options.maxValue; i++) { - if(_options.markers[i]) map.removeLayer(_options.markers[i]); - } } } } @@ -156,4 +145,4 @@ L.Control.SliderControl = L.Control.extend({ L.control.sliderControl = function (options) { return new L.Control.SliderControl(options); -}; \ No newline at end of file +};