leaflet-with-dashoffset-canvas-fix 1.9.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (90) hide show
  1. package/CHANGELOG.md +2191 -0
  2. package/LICENSE +26 -0
  3. package/README.md +3 -0
  4. package/package.json +149 -0
  5. package/src/Leaflet.js +24 -0
  6. package/src/control/Control.Attribution.js +148 -0
  7. package/src/control/Control.Layers.js +443 -0
  8. package/src/control/Control.Scale.js +132 -0
  9. package/src/control/Control.Zoom.js +146 -0
  10. package/src/control/Control.js +174 -0
  11. package/src/control/index.js +17 -0
  12. package/src/core/Browser.js +220 -0
  13. package/src/core/Class.js +135 -0
  14. package/src/core/Events.js +344 -0
  15. package/src/core/Handler.js +57 -0
  16. package/src/core/Util.js +241 -0
  17. package/src/core/index.js +15 -0
  18. package/src/dom/DomEvent.DoubleTap.js +91 -0
  19. package/src/dom/DomEvent.Pointer.js +97 -0
  20. package/src/dom/DomEvent.js +315 -0
  21. package/src/dom/DomUtil.js +349 -0
  22. package/src/dom/Draggable.js +220 -0
  23. package/src/dom/PosAnimation.js +113 -0
  24. package/src/dom/index.js +9 -0
  25. package/src/geo/LatLng.js +137 -0
  26. package/src/geo/LatLngBounds.js +251 -0
  27. package/src/geo/crs/CRS.EPSG3395.js +20 -0
  28. package/src/geo/crs/CRS.EPSG3857.js +27 -0
  29. package/src/geo/crs/CRS.EPSG4326.js +23 -0
  30. package/src/geo/crs/CRS.Earth.js +33 -0
  31. package/src/geo/crs/CRS.Simple.js +36 -0
  32. package/src/geo/crs/CRS.js +139 -0
  33. package/src/geo/crs/index.js +15 -0
  34. package/src/geo/index.js +7 -0
  35. package/src/geo/projection/Projection.LonLat.js +28 -0
  36. package/src/geo/projection/Projection.Mercator.js +49 -0
  37. package/src/geo/projection/Projection.SphericalMercator.js +44 -0
  38. package/src/geo/projection/index.js +26 -0
  39. package/src/geometry/Bounds.js +219 -0
  40. package/src/geometry/LineUtil.js +306 -0
  41. package/src/geometry/Point.js +222 -0
  42. package/src/geometry/PolyUtil.js +129 -0
  43. package/src/geometry/Transformation.js +79 -0
  44. package/src/geometry/index.js +8 -0
  45. package/src/images/layers.svg +1 -0
  46. package/src/images/logo.svg +1 -0
  47. package/src/images/marker.svg +1 -0
  48. package/src/layer/DivOverlay.js +348 -0
  49. package/src/layer/FeatureGroup.js +94 -0
  50. package/src/layer/GeoJSON.js +452 -0
  51. package/src/layer/ImageOverlay.js +270 -0
  52. package/src/layer/Layer.js +275 -0
  53. package/src/layer/LayerGroup.js +159 -0
  54. package/src/layer/Popup.js +506 -0
  55. package/src/layer/SVGOverlay.js +50 -0
  56. package/src/layer/Tooltip.js +444 -0
  57. package/src/layer/VideoOverlay.js +106 -0
  58. package/src/layer/index.js +24 -0
  59. package/src/layer/marker/DivIcon.js +74 -0
  60. package/src/layer/marker/Icon.Default.js +66 -0
  61. package/src/layer/marker/Icon.js +165 -0
  62. package/src/layer/marker/Marker.Drag.js +161 -0
  63. package/src/layer/marker/Marker.js +419 -0
  64. package/src/layer/marker/index.js +8 -0
  65. package/src/layer/tile/GridLayer.js +923 -0
  66. package/src/layer/tile/TileLayer.WMS.js +137 -0
  67. package/src/layer/tile/TileLayer.js +289 -0
  68. package/src/layer/tile/index.js +6 -0
  69. package/src/layer/vector/Canvas.js +493 -0
  70. package/src/layer/vector/Circle.js +113 -0
  71. package/src/layer/vector/CircleMarker.js +109 -0
  72. package/src/layer/vector/Path.js +148 -0
  73. package/src/layer/vector/Polygon.js +159 -0
  74. package/src/layer/vector/Polyline.js +307 -0
  75. package/src/layer/vector/Rectangle.js +57 -0
  76. package/src/layer/vector/Renderer.getRenderer.js +45 -0
  77. package/src/layer/vector/Renderer.js +133 -0
  78. package/src/layer/vector/SVG.Util.js +39 -0
  79. package/src/layer/vector/SVG.VML.js +144 -0
  80. package/src/layer/vector/SVG.js +207 -0
  81. package/src/layer/vector/index.js +14 -0
  82. package/src/map/Map.js +1751 -0
  83. package/src/map/handler/Map.BoxZoom.js +152 -0
  84. package/src/map/handler/Map.DoubleClickZoom.js +55 -0
  85. package/src/map/handler/Map.Drag.js +235 -0
  86. package/src/map/handler/Map.Keyboard.js +183 -0
  87. package/src/map/handler/Map.ScrollWheelZoom.js +91 -0
  88. package/src/map/handler/Map.TapHold.js +102 -0
  89. package/src/map/handler/Map.TouchZoom.js +130 -0
  90. package/src/map/index.js +17 -0
@@ -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,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
+ });
@@ -0,0 +1,159 @@
1
+
2
+ import {Layer} from './Layer';
3
+ import * as Util from '../core/Util';
4
+
5
+ /*
6
+ * @class LayerGroup
7
+ * @aka L.LayerGroup
8
+ * @inherits Interactive layer
9
+ *
10
+ * Used to group several layers and handle them as one. If you add it to the map,
11
+ * any layers added or removed from the group will be added/removed on the map as
12
+ * well. Extends `Layer`.
13
+ *
14
+ * @example
15
+ *
16
+ * ```js
17
+ * L.layerGroup([marker1, marker2])
18
+ * .addLayer(polyline)
19
+ * .addTo(map);
20
+ * ```
21
+ */
22
+
23
+ export var LayerGroup = Layer.extend({
24
+
25
+ initialize: function (layers, options) {
26
+ Util.setOptions(this, options);
27
+
28
+ this._layers = {};
29
+
30
+ var i, len;
31
+
32
+ if (layers) {
33
+ for (i = 0, len = layers.length; i < len; i++) {
34
+ this.addLayer(layers[i]);
35
+ }
36
+ }
37
+ },
38
+
39
+ // @method addLayer(layer: Layer): this
40
+ // Adds the given layer to the group.
41
+ addLayer: function (layer) {
42
+ var id = this.getLayerId(layer);
43
+
44
+ this._layers[id] = layer;
45
+
46
+ if (this._map) {
47
+ this._map.addLayer(layer);
48
+ }
49
+
50
+ return this;
51
+ },
52
+
53
+ // @method removeLayer(layer: Layer): this
54
+ // Removes the given layer from the group.
55
+ // @alternative
56
+ // @method removeLayer(id: Number): this
57
+ // Removes the layer with the given internal ID from the group.
58
+ removeLayer: function (layer) {
59
+ var id = layer in this._layers ? layer : this.getLayerId(layer);
60
+
61
+ if (this._map && this._layers[id]) {
62
+ this._map.removeLayer(this._layers[id]);
63
+ }
64
+
65
+ delete this._layers[id];
66
+
67
+ return this;
68
+ },
69
+
70
+ // @method hasLayer(layer: Layer): Boolean
71
+ // Returns `true` if the given layer is currently added to the group.
72
+ // @alternative
73
+ // @method hasLayer(id: Number): Boolean
74
+ // Returns `true` if the given internal ID is currently added to the group.
75
+ hasLayer: function (layer) {
76
+ var layerId = typeof layer === 'number' ? layer : this.getLayerId(layer);
77
+ return layerId in this._layers;
78
+ },
79
+
80
+ // @method clearLayers(): this
81
+ // Removes all the layers from the group.
82
+ clearLayers: function () {
83
+ return this.eachLayer(this.removeLayer, this);
84
+ },
85
+
86
+ // @method invoke(methodName: String, …): this
87
+ // Calls `methodName` on every layer contained in this group, passing any
88
+ // additional parameters. Has no effect if the layers contained do not
89
+ // implement `methodName`.
90
+ invoke: function (methodName) {
91
+ var args = Array.prototype.slice.call(arguments, 1),
92
+ i, layer;
93
+
94
+ for (i in this._layers) {
95
+ layer = this._layers[i];
96
+
97
+ if (layer[methodName]) {
98
+ layer[methodName].apply(layer, args);
99
+ }
100
+ }
101
+
102
+ return this;
103
+ },
104
+
105
+ onAdd: function (map) {
106
+ this.eachLayer(map.addLayer, map);
107
+ },
108
+
109
+ onRemove: function (map) {
110
+ this.eachLayer(map.removeLayer, map);
111
+ },
112
+
113
+ // @method eachLayer(fn: Function, context?: Object): this
114
+ // Iterates over the layers of the group, optionally specifying context of the iterator function.
115
+ // ```js
116
+ // group.eachLayer(function (layer) {
117
+ // layer.bindPopup('Hello');
118
+ // });
119
+ // ```
120
+ eachLayer: function (method, context) {
121
+ for (var i in this._layers) {
122
+ method.call(context, this._layers[i]);
123
+ }
124
+ return this;
125
+ },
126
+
127
+ // @method getLayer(id: Number): Layer
128
+ // Returns the layer with the given internal ID.
129
+ getLayer: function (id) {
130
+ return this._layers[id];
131
+ },
132
+
133
+ // @method getLayers(): Layer[]
134
+ // Returns an array of all the layers added to the group.
135
+ getLayers: function () {
136
+ var layers = [];
137
+ this.eachLayer(layers.push, layers);
138
+ return layers;
139
+ },
140
+
141
+ // @method setZIndex(zIndex: Number): this
142
+ // Calls `setZIndex` on every layer contained in this group, passing the z-index.
143
+ setZIndex: function (zIndex) {
144
+ return this.invoke('setZIndex', zIndex);
145
+ },
146
+
147
+ // @method getLayerId(layer: Layer): Number
148
+ // Returns the internal ID for a layer
149
+ getLayerId: function (layer) {
150
+ return Util.stamp(layer);
151
+ }
152
+ });
153
+
154
+
155
+ // @factory L.layerGroup(layers?: Layer[], options?: Object)
156
+ // Create a layer group, optionally given an initial set of layers and an `options` object.
157
+ export var layerGroup = function (layers, options) {
158
+ return new LayerGroup(layers, options);
159
+ };