decidim 0.26.9 → 0.26.10
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of decidim might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/lib/decidim/version.rb +1 -1
- data/package-lock.json +7 -7
- data/packages/browserslist-config/package.json +1 -1
- data/packages/core/node_modules/leaflet/CHANGELOG.md +2191 -0
- data/packages/core/node_modules/leaflet/LICENSE +26 -0
- data/packages/core/node_modules/leaflet/README.md +55 -0
- data/packages/core/node_modules/leaflet/dist/images/layers-2x.png +0 -0
- data/packages/core/node_modules/leaflet/dist/images/layers.png +0 -0
- data/packages/core/node_modules/leaflet/dist/images/marker-icon-2x.png +0 -0
- data/packages/core/node_modules/leaflet/dist/images/marker-icon.png +0 -0
- data/packages/core/node_modules/leaflet/dist/images/marker-shadow.png +0 -0
- data/packages/core/node_modules/leaflet/dist/leaflet-src.esm.js +14419 -0
- data/packages/core/node_modules/leaflet/dist/leaflet-src.esm.js.map +1 -0
- data/packages/core/node_modules/leaflet/dist/leaflet-src.js +14512 -0
- data/packages/core/node_modules/leaflet/dist/leaflet-src.js.map +1 -0
- data/packages/core/node_modules/leaflet/dist/leaflet.css +661 -0
- data/packages/core/node_modules/leaflet/dist/leaflet.js +6 -0
- data/packages/core/node_modules/leaflet/dist/leaflet.js.map +1 -0
- data/packages/core/node_modules/leaflet/package.json +149 -0
- data/packages/core/node_modules/leaflet/src/Leaflet.js +24 -0
- data/packages/core/node_modules/leaflet/src/control/Control.Attribution.js +148 -0
- data/packages/core/node_modules/leaflet/src/control/Control.Layers.js +443 -0
- data/packages/core/node_modules/leaflet/src/control/Control.Scale.js +132 -0
- data/packages/core/node_modules/leaflet/src/control/Control.Zoom.js +146 -0
- data/packages/core/node_modules/leaflet/src/control/Control.js +174 -0
- data/packages/core/node_modules/leaflet/src/control/index.js +17 -0
- data/packages/core/node_modules/leaflet/src/core/Browser.js +220 -0
- data/packages/core/node_modules/leaflet/src/core/Class.js +135 -0
- data/packages/core/node_modules/leaflet/src/core/Class.leafdoc +197 -0
- data/packages/core/node_modules/leaflet/src/core/Events.js +344 -0
- data/packages/core/node_modules/leaflet/src/core/Events.leafdoc +143 -0
- data/packages/core/node_modules/leaflet/src/core/Handler.js +57 -0
- data/packages/core/node_modules/leaflet/src/core/Util.js +241 -0
- data/packages/core/node_modules/leaflet/src/core/index.js +15 -0
- data/packages/core/node_modules/leaflet/src/dom/DomEvent.DoubleTap.js +91 -0
- data/packages/core/node_modules/leaflet/src/dom/DomEvent.Pointer.js +97 -0
- data/packages/core/node_modules/leaflet/src/dom/DomEvent.js +315 -0
- data/packages/core/node_modules/leaflet/src/dom/DomUtil.js +349 -0
- data/packages/core/node_modules/leaflet/src/dom/Draggable.js +220 -0
- data/packages/core/node_modules/leaflet/src/dom/PosAnimation.js +113 -0
- data/packages/core/node_modules/leaflet/src/dom/index.js +9 -0
- data/packages/core/node_modules/leaflet/src/geo/LatLng.js +137 -0
- data/packages/core/node_modules/leaflet/src/geo/LatLngBounds.js +251 -0
- data/packages/core/node_modules/leaflet/src/geo/crs/CRS.EPSG3395.js +20 -0
- data/packages/core/node_modules/leaflet/src/geo/crs/CRS.EPSG3857.js +27 -0
- data/packages/core/node_modules/leaflet/src/geo/crs/CRS.EPSG4326.js +23 -0
- data/packages/core/node_modules/leaflet/src/geo/crs/CRS.Earth.js +33 -0
- data/packages/core/node_modules/leaflet/src/geo/crs/CRS.Simple.js +36 -0
- data/packages/core/node_modules/leaflet/src/geo/crs/CRS.js +139 -0
- data/packages/core/node_modules/leaflet/src/geo/crs/index.js +15 -0
- data/packages/core/node_modules/leaflet/src/geo/index.js +7 -0
- data/packages/core/node_modules/leaflet/src/geo/projection/Projection.LonLat.js +28 -0
- data/packages/core/node_modules/leaflet/src/geo/projection/Projection.Mercator.js +49 -0
- data/packages/core/node_modules/leaflet/src/geo/projection/Projection.SphericalMercator.js +44 -0
- data/packages/core/node_modules/leaflet/src/geo/projection/index.js +26 -0
- data/packages/core/node_modules/leaflet/src/geometry/Bounds.js +219 -0
- data/packages/core/node_modules/leaflet/src/geometry/LineUtil.js +306 -0
- data/packages/core/node_modules/leaflet/src/geometry/Point.js +222 -0
- data/packages/core/node_modules/leaflet/src/geometry/PolyUtil.js +129 -0
- data/packages/core/node_modules/leaflet/src/geometry/Transformation.js +79 -0
- data/packages/core/node_modules/leaflet/src/geometry/index.js +8 -0
- data/packages/core/node_modules/leaflet/src/images/layers.svg +1 -0
- data/packages/core/node_modules/leaflet/src/images/logo.svg +1 -0
- data/packages/core/node_modules/leaflet/src/images/marker.svg +1 -0
- data/packages/core/node_modules/leaflet/src/layer/DivOverlay.js +348 -0
- data/packages/core/node_modules/leaflet/src/layer/FeatureGroup.js +94 -0
- data/packages/core/node_modules/leaflet/src/layer/GeoJSON.js +452 -0
- data/packages/core/node_modules/leaflet/src/layer/ImageOverlay.js +270 -0
- data/packages/core/node_modules/leaflet/src/layer/Layer.Interactive.leafdoc +39 -0
- data/packages/core/node_modules/leaflet/src/layer/Layer.js +275 -0
- data/packages/core/node_modules/leaflet/src/layer/LayerGroup.js +159 -0
- data/packages/core/node_modules/leaflet/src/layer/Popup.js +506 -0
- data/packages/core/node_modules/leaflet/src/layer/SVGOverlay.js +50 -0
- data/packages/core/node_modules/leaflet/src/layer/Tooltip.js +444 -0
- data/packages/core/node_modules/leaflet/src/layer/VideoOverlay.js +106 -0
- data/packages/core/node_modules/leaflet/src/layer/index.js +24 -0
- data/packages/core/node_modules/leaflet/src/layer/marker/DivIcon.js +74 -0
- data/packages/core/node_modules/leaflet/src/layer/marker/Icon.Default.js +66 -0
- data/packages/core/node_modules/leaflet/src/layer/marker/Icon.js +165 -0
- data/packages/core/node_modules/leaflet/src/layer/marker/Marker.Drag.js +161 -0
- data/packages/core/node_modules/leaflet/src/layer/marker/Marker.js +419 -0
- data/packages/core/node_modules/leaflet/src/layer/marker/index.js +8 -0
- data/packages/core/node_modules/leaflet/src/layer/tile/GridLayer.js +923 -0
- data/packages/core/node_modules/leaflet/src/layer/tile/TileLayer.WMS.js +137 -0
- data/packages/core/node_modules/leaflet/src/layer/tile/TileLayer.js +289 -0
- data/packages/core/node_modules/leaflet/src/layer/tile/index.js +6 -0
- data/packages/core/node_modules/leaflet/src/layer/vector/Canvas.js +492 -0
- data/packages/core/node_modules/leaflet/src/layer/vector/Circle.js +113 -0
- data/packages/core/node_modules/leaflet/src/layer/vector/CircleMarker.js +109 -0
- data/packages/core/node_modules/leaflet/src/layer/vector/Path.js +148 -0
- data/packages/core/node_modules/leaflet/src/layer/vector/Polygon.js +159 -0
- data/packages/core/node_modules/leaflet/src/layer/vector/Polyline.js +307 -0
- data/packages/core/node_modules/leaflet/src/layer/vector/Rectangle.js +57 -0
- data/packages/core/node_modules/leaflet/src/layer/vector/Renderer.getRenderer.js +45 -0
- data/packages/core/node_modules/leaflet/src/layer/vector/Renderer.js +133 -0
- data/packages/core/node_modules/leaflet/src/layer/vector/SVG.Util.js +39 -0
- data/packages/core/node_modules/leaflet/src/layer/vector/SVG.VML.js +144 -0
- data/packages/core/node_modules/leaflet/src/layer/vector/SVG.js +207 -0
- data/packages/core/node_modules/leaflet/src/layer/vector/index.js +14 -0
- data/packages/core/node_modules/leaflet/src/map/Map.js +1751 -0
- data/packages/core/node_modules/leaflet/src/map/Map.methodOptions.leafdoc +112 -0
- data/packages/core/node_modules/leaflet/src/map/handler/Map.BoxZoom.js +152 -0
- data/packages/core/node_modules/leaflet/src/map/handler/Map.DoubleClickZoom.js +55 -0
- data/packages/core/node_modules/leaflet/src/map/handler/Map.Drag.js +235 -0
- data/packages/core/node_modules/leaflet/src/map/handler/Map.Keyboard.js +183 -0
- data/packages/core/node_modules/leaflet/src/map/handler/Map.ScrollWheelZoom.js +91 -0
- data/packages/core/node_modules/leaflet/src/map/handler/Map.TapHold.js +102 -0
- data/packages/core/node_modules/leaflet/src/map/handler/Map.TouchZoom.js +130 -0
- data/packages/core/node_modules/leaflet/src/map/index.js +17 -0
- data/packages/core/package.json +1 -1
- data/packages/dev/package.json +1 -1
- data/packages/elections/package.json +1 -1
- data/packages/eslint-config/package.json +1 -1
- data/packages/stylelint-config/package.json +1 -1
- data/packages/webpacker/package.json +1 -1
- metadata +148 -42
@@ -0,0 +1,270 @@
|
|
1
|
+
import {Layer} from './Layer';
|
2
|
+
import * as Util from '../core/Util';
|
3
|
+
import {toLatLngBounds} from '../geo/LatLngBounds';
|
4
|
+
import {Bounds} from '../geometry/Bounds';
|
5
|
+
import * as DomUtil from '../dom/DomUtil';
|
6
|
+
|
7
|
+
/*
|
8
|
+
* @class ImageOverlay
|
9
|
+
* @aka L.ImageOverlay
|
10
|
+
* @inherits Interactive layer
|
11
|
+
*
|
12
|
+
* Used to load and display a single image over specific bounds of the map. Extends `Layer`.
|
13
|
+
*
|
14
|
+
* @example
|
15
|
+
*
|
16
|
+
* ```js
|
17
|
+
* var imageUrl = 'https://maps.lib.utexas.edu/maps/historical/newark_nj_1922.jpg',
|
18
|
+
* imageBounds = [[40.712216, -74.22655], [40.773941, -74.12544]];
|
19
|
+
* L.imageOverlay(imageUrl, imageBounds).addTo(map);
|
20
|
+
* ```
|
21
|
+
*/
|
22
|
+
|
23
|
+
export var ImageOverlay = Layer.extend({
|
24
|
+
|
25
|
+
// @section
|
26
|
+
// @aka ImageOverlay options
|
27
|
+
options: {
|
28
|
+
// @option opacity: Number = 1.0
|
29
|
+
// The opacity of the image overlay.
|
30
|
+
opacity: 1,
|
31
|
+
|
32
|
+
// @option alt: String = ''
|
33
|
+
// Text for the `alt` attribute of the image (useful for accessibility).
|
34
|
+
alt: '',
|
35
|
+
|
36
|
+
// @option interactive: Boolean = false
|
37
|
+
// If `true`, the image overlay will emit [mouse events](#interactive-layer) when clicked or hovered.
|
38
|
+
interactive: false,
|
39
|
+
|
40
|
+
// @option crossOrigin: Boolean|String = false
|
41
|
+
// Whether the crossOrigin attribute will be added to the image.
|
42
|
+
// If a String is provided, the image will have its crossOrigin attribute set to the String provided. This is needed if you want to access image pixel data.
|
43
|
+
// Refer to [CORS Settings](https://developer.mozilla.org/en-US/docs/Web/HTML/CORS_settings_attributes) for valid String values.
|
44
|
+
crossOrigin: false,
|
45
|
+
|
46
|
+
// @option errorOverlayUrl: String = ''
|
47
|
+
// URL to the overlay image to show in place of the overlay that failed to load.
|
48
|
+
errorOverlayUrl: '',
|
49
|
+
|
50
|
+
// @option zIndex: Number = 1
|
51
|
+
// The explicit [zIndex](https://developer.mozilla.org/docs/Web/CSS/CSS_Positioning/Understanding_z_index) of the overlay layer.
|
52
|
+
zIndex: 1,
|
53
|
+
|
54
|
+
// @option className: String = ''
|
55
|
+
// A custom class name to assign to the image. Empty by default.
|
56
|
+
className: ''
|
57
|
+
},
|
58
|
+
|
59
|
+
initialize: function (url, bounds, options) { // (String, LatLngBounds, Object)
|
60
|
+
this._url = url;
|
61
|
+
this._bounds = toLatLngBounds(bounds);
|
62
|
+
|
63
|
+
Util.setOptions(this, options);
|
64
|
+
},
|
65
|
+
|
66
|
+
onAdd: function () {
|
67
|
+
if (!this._image) {
|
68
|
+
this._initImage();
|
69
|
+
|
70
|
+
if (this.options.opacity < 1) {
|
71
|
+
this._updateOpacity();
|
72
|
+
}
|
73
|
+
}
|
74
|
+
|
75
|
+
if (this.options.interactive) {
|
76
|
+
DomUtil.addClass(this._image, 'leaflet-interactive');
|
77
|
+
this.addInteractiveTarget(this._image);
|
78
|
+
}
|
79
|
+
|
80
|
+
this.getPane().appendChild(this._image);
|
81
|
+
this._reset();
|
82
|
+
},
|
83
|
+
|
84
|
+
onRemove: function () {
|
85
|
+
DomUtil.remove(this._image);
|
86
|
+
if (this.options.interactive) {
|
87
|
+
this.removeInteractiveTarget(this._image);
|
88
|
+
}
|
89
|
+
},
|
90
|
+
|
91
|
+
// @method setOpacity(opacity: Number): this
|
92
|
+
// Sets the opacity of the overlay.
|
93
|
+
setOpacity: function (opacity) {
|
94
|
+
this.options.opacity = opacity;
|
95
|
+
|
96
|
+
if (this._image) {
|
97
|
+
this._updateOpacity();
|
98
|
+
}
|
99
|
+
return this;
|
100
|
+
},
|
101
|
+
|
102
|
+
setStyle: function (styleOpts) {
|
103
|
+
if (styleOpts.opacity) {
|
104
|
+
this.setOpacity(styleOpts.opacity);
|
105
|
+
}
|
106
|
+
return this;
|
107
|
+
},
|
108
|
+
|
109
|
+
// @method bringToFront(): this
|
110
|
+
// Brings the layer to the top of all overlays.
|
111
|
+
bringToFront: function () {
|
112
|
+
if (this._map) {
|
113
|
+
DomUtil.toFront(this._image);
|
114
|
+
}
|
115
|
+
return this;
|
116
|
+
},
|
117
|
+
|
118
|
+
// @method bringToBack(): this
|
119
|
+
// Brings the layer to the bottom of all overlays.
|
120
|
+
bringToBack: function () {
|
121
|
+
if (this._map) {
|
122
|
+
DomUtil.toBack(this._image);
|
123
|
+
}
|
124
|
+
return this;
|
125
|
+
},
|
126
|
+
|
127
|
+
// @method setUrl(url: String): this
|
128
|
+
// Changes the URL of the image.
|
129
|
+
setUrl: function (url) {
|
130
|
+
this._url = url;
|
131
|
+
|
132
|
+
if (this._image) {
|
133
|
+
this._image.src = url;
|
134
|
+
}
|
135
|
+
return this;
|
136
|
+
},
|
137
|
+
|
138
|
+
// @method setBounds(bounds: LatLngBounds): this
|
139
|
+
// Update the bounds that this ImageOverlay covers
|
140
|
+
setBounds: function (bounds) {
|
141
|
+
this._bounds = toLatLngBounds(bounds);
|
142
|
+
|
143
|
+
if (this._map) {
|
144
|
+
this._reset();
|
145
|
+
}
|
146
|
+
return this;
|
147
|
+
},
|
148
|
+
|
149
|
+
getEvents: function () {
|
150
|
+
var events = {
|
151
|
+
zoom: this._reset,
|
152
|
+
viewreset: this._reset
|
153
|
+
};
|
154
|
+
|
155
|
+
if (this._zoomAnimated) {
|
156
|
+
events.zoomanim = this._animateZoom;
|
157
|
+
}
|
158
|
+
|
159
|
+
return events;
|
160
|
+
},
|
161
|
+
|
162
|
+
// @method setZIndex(value: Number): this
|
163
|
+
// Changes the [zIndex](#imageoverlay-zindex) of the image overlay.
|
164
|
+
setZIndex: function (value) {
|
165
|
+
this.options.zIndex = value;
|
166
|
+
this._updateZIndex();
|
167
|
+
return this;
|
168
|
+
},
|
169
|
+
|
170
|
+
// @method getBounds(): LatLngBounds
|
171
|
+
// Get the bounds that this ImageOverlay covers
|
172
|
+
getBounds: function () {
|
173
|
+
return this._bounds;
|
174
|
+
},
|
175
|
+
|
176
|
+
// @method getElement(): HTMLElement
|
177
|
+
// Returns the instance of [`HTMLImageElement`](https://developer.mozilla.org/docs/Web/API/HTMLImageElement)
|
178
|
+
// used by this overlay.
|
179
|
+
getElement: function () {
|
180
|
+
return this._image;
|
181
|
+
},
|
182
|
+
|
183
|
+
_initImage: function () {
|
184
|
+
var wasElementSupplied = this._url.tagName === 'IMG';
|
185
|
+
var img = this._image = wasElementSupplied ? this._url : DomUtil.create('img');
|
186
|
+
|
187
|
+
DomUtil.addClass(img, 'leaflet-image-layer');
|
188
|
+
if (this._zoomAnimated) { DomUtil.addClass(img, 'leaflet-zoom-animated'); }
|
189
|
+
if (this.options.className) { DomUtil.addClass(img, this.options.className); }
|
190
|
+
|
191
|
+
img.onselectstart = Util.falseFn;
|
192
|
+
img.onmousemove = Util.falseFn;
|
193
|
+
|
194
|
+
// @event load: Event
|
195
|
+
// Fired when the ImageOverlay layer has loaded its image
|
196
|
+
img.onload = Util.bind(this.fire, this, 'load');
|
197
|
+
img.onerror = Util.bind(this._overlayOnError, this, 'error');
|
198
|
+
|
199
|
+
if (this.options.crossOrigin || this.options.crossOrigin === '') {
|
200
|
+
img.crossOrigin = this.options.crossOrigin === true ? '' : this.options.crossOrigin;
|
201
|
+
}
|
202
|
+
|
203
|
+
if (this.options.zIndex) {
|
204
|
+
this._updateZIndex();
|
205
|
+
}
|
206
|
+
|
207
|
+
if (wasElementSupplied) {
|
208
|
+
this._url = img.src;
|
209
|
+
return;
|
210
|
+
}
|
211
|
+
|
212
|
+
img.src = this._url;
|
213
|
+
img.alt = this.options.alt;
|
214
|
+
},
|
215
|
+
|
216
|
+
_animateZoom: function (e) {
|
217
|
+
var scale = this._map.getZoomScale(e.zoom),
|
218
|
+
offset = this._map._latLngBoundsToNewLayerBounds(this._bounds, e.zoom, e.center).min;
|
219
|
+
|
220
|
+
DomUtil.setTransform(this._image, offset, scale);
|
221
|
+
},
|
222
|
+
|
223
|
+
_reset: function () {
|
224
|
+
var image = this._image,
|
225
|
+
bounds = new Bounds(
|
226
|
+
this._map.latLngToLayerPoint(this._bounds.getNorthWest()),
|
227
|
+
this._map.latLngToLayerPoint(this._bounds.getSouthEast())),
|
228
|
+
size = bounds.getSize();
|
229
|
+
|
230
|
+
DomUtil.setPosition(image, bounds.min);
|
231
|
+
|
232
|
+
image.style.width = size.x + 'px';
|
233
|
+
image.style.height = size.y + 'px';
|
234
|
+
},
|
235
|
+
|
236
|
+
_updateOpacity: function () {
|
237
|
+
DomUtil.setOpacity(this._image, this.options.opacity);
|
238
|
+
},
|
239
|
+
|
240
|
+
_updateZIndex: function () {
|
241
|
+
if (this._image && this.options.zIndex !== undefined && this.options.zIndex !== null) {
|
242
|
+
this._image.style.zIndex = this.options.zIndex;
|
243
|
+
}
|
244
|
+
},
|
245
|
+
|
246
|
+
_overlayOnError: function () {
|
247
|
+
// @event error: Event
|
248
|
+
// Fired when the ImageOverlay layer fails to load its image
|
249
|
+
this.fire('error');
|
250
|
+
|
251
|
+
var errorUrl = this.options.errorOverlayUrl;
|
252
|
+
if (errorUrl && this._url !== errorUrl) {
|
253
|
+
this._url = errorUrl;
|
254
|
+
this._image.src = errorUrl;
|
255
|
+
}
|
256
|
+
},
|
257
|
+
|
258
|
+
// @method getCenter(): LatLng
|
259
|
+
// Returns the center of the ImageOverlay.
|
260
|
+
getCenter: function () {
|
261
|
+
return this._bounds.getCenter();
|
262
|
+
}
|
263
|
+
});
|
264
|
+
|
265
|
+
// @factory L.imageOverlay(imageUrl: String, bounds: LatLngBounds, options?: ImageOverlay options)
|
266
|
+
// Instantiates an image overlay object given the URL of the image and the
|
267
|
+
// geographical bounds it is tied to.
|
268
|
+
export var imageOverlay = function (url, bounds, options) {
|
269
|
+
return new ImageOverlay(url, bounds, options);
|
270
|
+
};
|
@@ -0,0 +1,39 @@
|
|
1
|
+
@class Interactive layer
|
2
|
+
@inherits Layer
|
3
|
+
|
4
|
+
Some `Layer`s can be made interactive - when the user interacts
|
5
|
+
with such a layer, mouse events like `click` and `mouseover` can be handled.
|
6
|
+
Use the [event handling methods](#evented-method) to handle these events.
|
7
|
+
|
8
|
+
@option interactive: Boolean = true
|
9
|
+
If `false`, the layer will not emit mouse events and will act as a part of the underlying map.
|
10
|
+
|
11
|
+
@option bubblingMouseEvents: Boolean = true
|
12
|
+
When `true`, a mouse event on this layer will trigger the same event on the map
|
13
|
+
(unless [`L.DomEvent.stopPropagation`](#domevent-stoppropagation) is used).
|
14
|
+
|
15
|
+
@section Mouse events
|
16
|
+
|
17
|
+
@event click: MouseEvent
|
18
|
+
Fired when the user clicks (or taps) the layer.
|
19
|
+
|
20
|
+
@event dblclick: MouseEvent
|
21
|
+
Fired when the user double-clicks (or double-taps) the layer.
|
22
|
+
|
23
|
+
@event mousedown: MouseEvent
|
24
|
+
Fired when the user pushes the mouse button on the layer.
|
25
|
+
|
26
|
+
@event mouseup: MouseEvent
|
27
|
+
Fired when the user releases the mouse button pushed on the layer.
|
28
|
+
|
29
|
+
@event mouseover: MouseEvent
|
30
|
+
Fired when the mouse enters the layer.
|
31
|
+
|
32
|
+
@event mouseout: MouseEvent
|
33
|
+
Fired when the mouse leaves the layer.
|
34
|
+
|
35
|
+
@event contextmenu: MouseEvent
|
36
|
+
Fired when the user right-clicks on the layer, prevents
|
37
|
+
default browser context menu from showing if there are listeners on
|
38
|
+
this event. Also fired on mobile when the user holds a single touch
|
39
|
+
for a second (also called long press).
|
@@ -0,0 +1,275 @@
|
|
1
|
+
import {Evented} from '../core/Events';
|
2
|
+
import {Map} from '../map/Map';
|
3
|
+
import * as Util from '../core/Util';
|
4
|
+
|
5
|
+
/*
|
6
|
+
* @class Layer
|
7
|
+
* @inherits Evented
|
8
|
+
* @aka L.Layer
|
9
|
+
* @aka ILayer
|
10
|
+
*
|
11
|
+
* A set of methods from the Layer base class that all Leaflet layers use.
|
12
|
+
* Inherits all methods, options and events from `L.Evented`.
|
13
|
+
*
|
14
|
+
* @example
|
15
|
+
*
|
16
|
+
* ```js
|
17
|
+
* var layer = L.marker(latlng).addTo(map);
|
18
|
+
* layer.addTo(map);
|
19
|
+
* layer.remove();
|
20
|
+
* ```
|
21
|
+
*
|
22
|
+
* @event add: Event
|
23
|
+
* Fired after the layer is added to a map
|
24
|
+
*
|
25
|
+
* @event remove: Event
|
26
|
+
* Fired after the layer is removed from a map
|
27
|
+
*/
|
28
|
+
|
29
|
+
|
30
|
+
export var Layer = Evented.extend({
|
31
|
+
|
32
|
+
// Classes extending `L.Layer` will inherit the following options:
|
33
|
+
options: {
|
34
|
+
// @option pane: String = 'overlayPane'
|
35
|
+
// By default the layer will be added to the map's [overlay pane](#map-overlaypane). Overriding this option will cause the layer to be placed on another pane by default.
|
36
|
+
pane: 'overlayPane',
|
37
|
+
|
38
|
+
// @option attribution: String = null
|
39
|
+
// String to be shown in the attribution control, e.g. "© OpenStreetMap contributors". It describes the layer data and is often a legal obligation towards copyright holders and tile providers.
|
40
|
+
attribution: null,
|
41
|
+
|
42
|
+
bubblingMouseEvents: true
|
43
|
+
},
|
44
|
+
|
45
|
+
/* @section
|
46
|
+
* Classes extending `L.Layer` will inherit the following methods:
|
47
|
+
*
|
48
|
+
* @method addTo(map: Map|LayerGroup): this
|
49
|
+
* Adds the layer to the given map or layer group.
|
50
|
+
*/
|
51
|
+
addTo: function (map) {
|
52
|
+
map.addLayer(this);
|
53
|
+
return this;
|
54
|
+
},
|
55
|
+
|
56
|
+
// @method remove: this
|
57
|
+
// Removes the layer from the map it is currently active on.
|
58
|
+
remove: function () {
|
59
|
+
return this.removeFrom(this._map || this._mapToAdd);
|
60
|
+
},
|
61
|
+
|
62
|
+
// @method removeFrom(map: Map): this
|
63
|
+
// Removes the layer from the given map
|
64
|
+
//
|
65
|
+
// @alternative
|
66
|
+
// @method removeFrom(group: LayerGroup): this
|
67
|
+
// Removes the layer from the given `LayerGroup`
|
68
|
+
removeFrom: function (obj) {
|
69
|
+
if (obj) {
|
70
|
+
obj.removeLayer(this);
|
71
|
+
}
|
72
|
+
return this;
|
73
|
+
},
|
74
|
+
|
75
|
+
// @method getPane(name? : String): HTMLElement
|
76
|
+
// Returns the `HTMLElement` representing the named pane on the map. If `name` is omitted, returns the pane for this layer.
|
77
|
+
getPane: function (name) {
|
78
|
+
return this._map.getPane(name ? (this.options[name] || name) : this.options.pane);
|
79
|
+
},
|
80
|
+
|
81
|
+
addInteractiveTarget: function (targetEl) {
|
82
|
+
this._map._targets[Util.stamp(targetEl)] = this;
|
83
|
+
return this;
|
84
|
+
},
|
85
|
+
|
86
|
+
removeInteractiveTarget: function (targetEl) {
|
87
|
+
delete this._map._targets[Util.stamp(targetEl)];
|
88
|
+
return this;
|
89
|
+
},
|
90
|
+
|
91
|
+
// @method getAttribution: String
|
92
|
+
// Used by the `attribution control`, returns the [attribution option](#gridlayer-attribution).
|
93
|
+
getAttribution: function () {
|
94
|
+
return this.options.attribution;
|
95
|
+
},
|
96
|
+
|
97
|
+
_layerAdd: function (e) {
|
98
|
+
var map = e.target;
|
99
|
+
|
100
|
+
// check in case layer gets added and then removed before the map is ready
|
101
|
+
if (!map.hasLayer(this)) { return; }
|
102
|
+
|
103
|
+
this._map = map;
|
104
|
+
this._zoomAnimated = map._zoomAnimated;
|
105
|
+
|
106
|
+
if (this.getEvents) {
|
107
|
+
var events = this.getEvents();
|
108
|
+
map.on(events, this);
|
109
|
+
this.once('remove', function () {
|
110
|
+
map.off(events, this);
|
111
|
+
}, this);
|
112
|
+
}
|
113
|
+
|
114
|
+
this.onAdd(map);
|
115
|
+
|
116
|
+
this.fire('add');
|
117
|
+
map.fire('layeradd', {layer: this});
|
118
|
+
}
|
119
|
+
});
|
120
|
+
|
121
|
+
/* @section Extension methods
|
122
|
+
* @uninheritable
|
123
|
+
*
|
124
|
+
* Every layer should extend from `L.Layer` and (re-)implement the following methods.
|
125
|
+
*
|
126
|
+
* @method onAdd(map: Map): this
|
127
|
+
* Should contain code that creates DOM elements for the layer, adds them to `map panes` where they should belong and puts listeners on relevant map events. Called on [`map.addLayer(layer)`](#map-addlayer).
|
128
|
+
*
|
129
|
+
* @method onRemove(map: Map): this
|
130
|
+
* Should contain all clean up code that removes the layer's elements from the DOM and removes listeners previously added in [`onAdd`](#layer-onadd). Called on [`map.removeLayer(layer)`](#map-removelayer).
|
131
|
+
*
|
132
|
+
* @method getEvents(): Object
|
133
|
+
* This optional method should return an object like `{ viewreset: this._reset }` for [`addEventListener`](#evented-addeventlistener). The event handlers in this object will be automatically added and removed from the map with your layer.
|
134
|
+
*
|
135
|
+
* @method getAttribution(): String
|
136
|
+
* This optional method should return a string containing HTML to be shown on the `Attribution control` whenever the layer is visible.
|
137
|
+
*
|
138
|
+
* @method beforeAdd(map: Map): this
|
139
|
+
* Optional method. Called on [`map.addLayer(layer)`](#map-addlayer), before the layer is added to the map, before events are initialized, without waiting until the map is in a usable state. Use for early initialization only.
|
140
|
+
*/
|
141
|
+
|
142
|
+
|
143
|
+
/* @namespace Map
|
144
|
+
* @section Layer events
|
145
|
+
*
|
146
|
+
* @event layeradd: LayerEvent
|
147
|
+
* Fired when a new layer is added to the map.
|
148
|
+
*
|
149
|
+
* @event layerremove: LayerEvent
|
150
|
+
* Fired when some layer is removed from the map
|
151
|
+
*
|
152
|
+
* @section Methods for Layers and Controls
|
153
|
+
*/
|
154
|
+
Map.include({
|
155
|
+
// @method addLayer(layer: Layer): this
|
156
|
+
// Adds the given layer to the map
|
157
|
+
addLayer: function (layer) {
|
158
|
+
if (!layer._layerAdd) {
|
159
|
+
throw new Error('The provided object is not a Layer.');
|
160
|
+
}
|
161
|
+
|
162
|
+
var id = Util.stamp(layer);
|
163
|
+
if (this._layers[id]) { return this; }
|
164
|
+
this._layers[id] = layer;
|
165
|
+
|
166
|
+
layer._mapToAdd = this;
|
167
|
+
|
168
|
+
if (layer.beforeAdd) {
|
169
|
+
layer.beforeAdd(this);
|
170
|
+
}
|
171
|
+
|
172
|
+
this.whenReady(layer._layerAdd, layer);
|
173
|
+
|
174
|
+
return this;
|
175
|
+
},
|
176
|
+
|
177
|
+
// @method removeLayer(layer: Layer): this
|
178
|
+
// Removes the given layer from the map.
|
179
|
+
removeLayer: function (layer) {
|
180
|
+
var id = Util.stamp(layer);
|
181
|
+
|
182
|
+
if (!this._layers[id]) { return this; }
|
183
|
+
|
184
|
+
if (this._loaded) {
|
185
|
+
layer.onRemove(this);
|
186
|
+
}
|
187
|
+
|
188
|
+
delete this._layers[id];
|
189
|
+
|
190
|
+
if (this._loaded) {
|
191
|
+
this.fire('layerremove', {layer: layer});
|
192
|
+
layer.fire('remove');
|
193
|
+
}
|
194
|
+
|
195
|
+
layer._map = layer._mapToAdd = null;
|
196
|
+
|
197
|
+
return this;
|
198
|
+
},
|
199
|
+
|
200
|
+
// @method hasLayer(layer: Layer): Boolean
|
201
|
+
// Returns `true` if the given layer is currently added to the map
|
202
|
+
hasLayer: function (layer) {
|
203
|
+
return Util.stamp(layer) in this._layers;
|
204
|
+
},
|
205
|
+
|
206
|
+
/* @method eachLayer(fn: Function, context?: Object): this
|
207
|
+
* Iterates over the layers of the map, optionally specifying context of the iterator function.
|
208
|
+
* ```
|
209
|
+
* map.eachLayer(function(layer){
|
210
|
+
* layer.bindPopup('Hello');
|
211
|
+
* });
|
212
|
+
* ```
|
213
|
+
*/
|
214
|
+
eachLayer: function (method, context) {
|
215
|
+
for (var i in this._layers) {
|
216
|
+
method.call(context, this._layers[i]);
|
217
|
+
}
|
218
|
+
return this;
|
219
|
+
},
|
220
|
+
|
221
|
+
_addLayers: function (layers) {
|
222
|
+
layers = layers ? (Util.isArray(layers) ? layers : [layers]) : [];
|
223
|
+
|
224
|
+
for (var i = 0, len = layers.length; i < len; i++) {
|
225
|
+
this.addLayer(layers[i]);
|
226
|
+
}
|
227
|
+
},
|
228
|
+
|
229
|
+
_addZoomLimit: function (layer) {
|
230
|
+
if (!isNaN(layer.options.maxZoom) || !isNaN(layer.options.minZoom)) {
|
231
|
+
this._zoomBoundLayers[Util.stamp(layer)] = layer;
|
232
|
+
this._updateZoomLevels();
|
233
|
+
}
|
234
|
+
},
|
235
|
+
|
236
|
+
_removeZoomLimit: function (layer) {
|
237
|
+
var id = Util.stamp(layer);
|
238
|
+
|
239
|
+
if (this._zoomBoundLayers[id]) {
|
240
|
+
delete this._zoomBoundLayers[id];
|
241
|
+
this._updateZoomLevels();
|
242
|
+
}
|
243
|
+
},
|
244
|
+
|
245
|
+
_updateZoomLevels: function () {
|
246
|
+
var minZoom = Infinity,
|
247
|
+
maxZoom = -Infinity,
|
248
|
+
oldZoomSpan = this._getZoomSpan();
|
249
|
+
|
250
|
+
for (var i in this._zoomBoundLayers) {
|
251
|
+
var options = this._zoomBoundLayers[i].options;
|
252
|
+
|
253
|
+
minZoom = options.minZoom === undefined ? minZoom : Math.min(minZoom, options.minZoom);
|
254
|
+
maxZoom = options.maxZoom === undefined ? maxZoom : Math.max(maxZoom, options.maxZoom);
|
255
|
+
}
|
256
|
+
|
257
|
+
this._layersMaxZoom = maxZoom === -Infinity ? undefined : maxZoom;
|
258
|
+
this._layersMinZoom = minZoom === Infinity ? undefined : minZoom;
|
259
|
+
|
260
|
+
// @section Map state change events
|
261
|
+
// @event zoomlevelschange: Event
|
262
|
+
// Fired when the number of zoomlevels on the map is changed due
|
263
|
+
// to adding or removing a layer.
|
264
|
+
if (oldZoomSpan !== this._getZoomSpan()) {
|
265
|
+
this.fire('zoomlevelschange');
|
266
|
+
}
|
267
|
+
|
268
|
+
if (this.options.maxZoom === undefined && this._layersMaxZoom && this.getZoom() > this._layersMaxZoom) {
|
269
|
+
this.setZoom(this._layersMaxZoom);
|
270
|
+
}
|
271
|
+
if (this.options.minZoom === undefined && this._layersMinZoom && this.getZoom() < this._layersMinZoom) {
|
272
|
+
this.setZoom(this._layersMinZoom);
|
273
|
+
}
|
274
|
+
}
|
275
|
+
});
|