X-Git-Url: https://git.openstreetmap.org/rails.git/blobdiff_plain/378d08f2c92adf0c1d14bbe09fcebe9f5e786409..10294f4849b5d97185c618687a710a2dfc19f148:/vendor/assets/leaflet/leaflet.locationfilter.js diff --git a/vendor/assets/leaflet/leaflet.locationfilter.js b/vendor/assets/leaflet/leaflet.locationfilter.js index a0019678c..64ca34712 100644 --- a/vendor/assets/leaflet/leaflet.locationfilter.js +++ b/vendor/assets/leaflet/leaflet.locationfilter.js @@ -90,9 +90,7 @@ L.Control.ButtonContainer = L.Control.extend({ } }); -L.LocationFilter = L.Class.extend({ - includes: L.Mixin.Events, - +L.LocationFilter = L.Layer.extend({ options: { enableButton: { enableText: "Select area", @@ -100,7 +98,8 @@ L.LocationFilter = L.Class.extend({ }, adjustButton: { text: "Select area within current zoom" - } + }, + buttonPosition: 'topleft' }, initialize: function(options) { @@ -114,8 +113,10 @@ L.LocationFilter = L.Class.extend({ onAdd: function(map) { this._map = map; - this._layer = new L.LayerGroup(); - this._initializeButtonContainer(); + + if (this.options.enableButton || this.options.adjustButton) { + this._initializeButtonContainer(); + } if (this.options.enable) { this.enable(); @@ -124,7 +125,9 @@ L.LocationFilter = L.Class.extend({ onRemove: function(map) { this.disable(); - this._buttonContainer.removeFrom(map); + if (this._buttonContainer) { + this._buttonContainer.removeFrom(map); + } }, /* Get the current filter bounds */ @@ -137,8 +140,10 @@ L.LocationFilter = L.Class.extend({ this._ne = bounds.getNorthEast(); this._sw = bounds.getSouthWest(); this._se = bounds.getSouthEast(); - this._draw(); - this.fire("change", {bounds: bounds}); + if (this.isEnabled()) { + this._draw(); + this.fire("change", {bounds: bounds}); + } }, isEnabled: function() { @@ -278,6 +283,8 @@ L.LocationFilter = L.Class.extend({ return; } + this._layer = new L.LayerGroup(); + // Calculate filter bounds this._calculateBounds(); @@ -287,7 +294,7 @@ L.LocationFilter = L.Class.extend({ this._eastRect = this._drawRectangle(this._eastBounds); this._southRect = this._drawRectangle(this._southBounds); this._innerRect = this._drawRectangle(this.getBounds(), { - fillColor: "transparent", + fillOpacity: 0, stroke: true, color: "white", weight: 1, @@ -371,7 +378,9 @@ L.LocationFilter = L.Class.extend({ // Update buttons - this._buttonContainer.addClass("enabled"); + if (this._buttonContainer) { + this._buttonContainer.addClass("enabled"); + } if (this._enableButton) { this._enableButton.setText(this.options.enableButton.disableText); @@ -415,7 +424,9 @@ L.LocationFilter = L.Class.extend({ } // Update buttons - this._buttonContainer.removeClass("enabled"); + if (this._buttonContainer) { + this._buttonContainer.removeClass("enabled"); + } if (this._enableButton) { this._enableButton.setText(this.options.enableButton.enableText); @@ -456,7 +467,10 @@ L.LocationFilter = L.Class.extend({ toggles the location filter */ _initializeButtonContainer: function() { var that = this; - this._buttonContainer = new L.Control.ButtonContainer({className: "location-filter button-container"}); + this._buttonContainer = new L.Control.ButtonContainer({ + className: "location-filter button-container", + position: this.options.buttonPosition + }); if (this.options.enableButton) { this._enableButton = new L.Control.Button({ @@ -477,8 +491,6 @@ L.LocationFilter = L.Class.extend({ }).addTo(this._buttonContainer); } - if (this.options.enableButton || this.options.adjustButton) { - this._buttonContainer.addTo(this._map); - } + this._buttonContainer.addTo(this._map); } });