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.

Files changed (117) hide show
  1. checksums.yaml +4 -4
  2. data/lib/decidim/version.rb +1 -1
  3. data/package-lock.json +7 -7
  4. data/packages/browserslist-config/package.json +1 -1
  5. data/packages/core/node_modules/leaflet/CHANGELOG.md +2191 -0
  6. data/packages/core/node_modules/leaflet/LICENSE +26 -0
  7. data/packages/core/node_modules/leaflet/README.md +55 -0
  8. data/packages/core/node_modules/leaflet/dist/images/layers-2x.png +0 -0
  9. data/packages/core/node_modules/leaflet/dist/images/layers.png +0 -0
  10. data/packages/core/node_modules/leaflet/dist/images/marker-icon-2x.png +0 -0
  11. data/packages/core/node_modules/leaflet/dist/images/marker-icon.png +0 -0
  12. data/packages/core/node_modules/leaflet/dist/images/marker-shadow.png +0 -0
  13. data/packages/core/node_modules/leaflet/dist/leaflet-src.esm.js +14419 -0
  14. data/packages/core/node_modules/leaflet/dist/leaflet-src.esm.js.map +1 -0
  15. data/packages/core/node_modules/leaflet/dist/leaflet-src.js +14512 -0
  16. data/packages/core/node_modules/leaflet/dist/leaflet-src.js.map +1 -0
  17. data/packages/core/node_modules/leaflet/dist/leaflet.css +661 -0
  18. data/packages/core/node_modules/leaflet/dist/leaflet.js +6 -0
  19. data/packages/core/node_modules/leaflet/dist/leaflet.js.map +1 -0
  20. data/packages/core/node_modules/leaflet/package.json +149 -0
  21. data/packages/core/node_modules/leaflet/src/Leaflet.js +24 -0
  22. data/packages/core/node_modules/leaflet/src/control/Control.Attribution.js +148 -0
  23. data/packages/core/node_modules/leaflet/src/control/Control.Layers.js +443 -0
  24. data/packages/core/node_modules/leaflet/src/control/Control.Scale.js +132 -0
  25. data/packages/core/node_modules/leaflet/src/control/Control.Zoom.js +146 -0
  26. data/packages/core/node_modules/leaflet/src/control/Control.js +174 -0
  27. data/packages/core/node_modules/leaflet/src/control/index.js +17 -0
  28. data/packages/core/node_modules/leaflet/src/core/Browser.js +220 -0
  29. data/packages/core/node_modules/leaflet/src/core/Class.js +135 -0
  30. data/packages/core/node_modules/leaflet/src/core/Class.leafdoc +197 -0
  31. data/packages/core/node_modules/leaflet/src/core/Events.js +344 -0
  32. data/packages/core/node_modules/leaflet/src/core/Events.leafdoc +143 -0
  33. data/packages/core/node_modules/leaflet/src/core/Handler.js +57 -0
  34. data/packages/core/node_modules/leaflet/src/core/Util.js +241 -0
  35. data/packages/core/node_modules/leaflet/src/core/index.js +15 -0
  36. data/packages/core/node_modules/leaflet/src/dom/DomEvent.DoubleTap.js +91 -0
  37. data/packages/core/node_modules/leaflet/src/dom/DomEvent.Pointer.js +97 -0
  38. data/packages/core/node_modules/leaflet/src/dom/DomEvent.js +315 -0
  39. data/packages/core/node_modules/leaflet/src/dom/DomUtil.js +349 -0
  40. data/packages/core/node_modules/leaflet/src/dom/Draggable.js +220 -0
  41. data/packages/core/node_modules/leaflet/src/dom/PosAnimation.js +113 -0
  42. data/packages/core/node_modules/leaflet/src/dom/index.js +9 -0
  43. data/packages/core/node_modules/leaflet/src/geo/LatLng.js +137 -0
  44. data/packages/core/node_modules/leaflet/src/geo/LatLngBounds.js +251 -0
  45. data/packages/core/node_modules/leaflet/src/geo/crs/CRS.EPSG3395.js +20 -0
  46. data/packages/core/node_modules/leaflet/src/geo/crs/CRS.EPSG3857.js +27 -0
  47. data/packages/core/node_modules/leaflet/src/geo/crs/CRS.EPSG4326.js +23 -0
  48. data/packages/core/node_modules/leaflet/src/geo/crs/CRS.Earth.js +33 -0
  49. data/packages/core/node_modules/leaflet/src/geo/crs/CRS.Simple.js +36 -0
  50. data/packages/core/node_modules/leaflet/src/geo/crs/CRS.js +139 -0
  51. data/packages/core/node_modules/leaflet/src/geo/crs/index.js +15 -0
  52. data/packages/core/node_modules/leaflet/src/geo/index.js +7 -0
  53. data/packages/core/node_modules/leaflet/src/geo/projection/Projection.LonLat.js +28 -0
  54. data/packages/core/node_modules/leaflet/src/geo/projection/Projection.Mercator.js +49 -0
  55. data/packages/core/node_modules/leaflet/src/geo/projection/Projection.SphericalMercator.js +44 -0
  56. data/packages/core/node_modules/leaflet/src/geo/projection/index.js +26 -0
  57. data/packages/core/node_modules/leaflet/src/geometry/Bounds.js +219 -0
  58. data/packages/core/node_modules/leaflet/src/geometry/LineUtil.js +306 -0
  59. data/packages/core/node_modules/leaflet/src/geometry/Point.js +222 -0
  60. data/packages/core/node_modules/leaflet/src/geometry/PolyUtil.js +129 -0
  61. data/packages/core/node_modules/leaflet/src/geometry/Transformation.js +79 -0
  62. data/packages/core/node_modules/leaflet/src/geometry/index.js +8 -0
  63. data/packages/core/node_modules/leaflet/src/images/layers.svg +1 -0
  64. data/packages/core/node_modules/leaflet/src/images/logo.svg +1 -0
  65. data/packages/core/node_modules/leaflet/src/images/marker.svg +1 -0
  66. data/packages/core/node_modules/leaflet/src/layer/DivOverlay.js +348 -0
  67. data/packages/core/node_modules/leaflet/src/layer/FeatureGroup.js +94 -0
  68. data/packages/core/node_modules/leaflet/src/layer/GeoJSON.js +452 -0
  69. data/packages/core/node_modules/leaflet/src/layer/ImageOverlay.js +270 -0
  70. data/packages/core/node_modules/leaflet/src/layer/Layer.Interactive.leafdoc +39 -0
  71. data/packages/core/node_modules/leaflet/src/layer/Layer.js +275 -0
  72. data/packages/core/node_modules/leaflet/src/layer/LayerGroup.js +159 -0
  73. data/packages/core/node_modules/leaflet/src/layer/Popup.js +506 -0
  74. data/packages/core/node_modules/leaflet/src/layer/SVGOverlay.js +50 -0
  75. data/packages/core/node_modules/leaflet/src/layer/Tooltip.js +444 -0
  76. data/packages/core/node_modules/leaflet/src/layer/VideoOverlay.js +106 -0
  77. data/packages/core/node_modules/leaflet/src/layer/index.js +24 -0
  78. data/packages/core/node_modules/leaflet/src/layer/marker/DivIcon.js +74 -0
  79. data/packages/core/node_modules/leaflet/src/layer/marker/Icon.Default.js +66 -0
  80. data/packages/core/node_modules/leaflet/src/layer/marker/Icon.js +165 -0
  81. data/packages/core/node_modules/leaflet/src/layer/marker/Marker.Drag.js +161 -0
  82. data/packages/core/node_modules/leaflet/src/layer/marker/Marker.js +419 -0
  83. data/packages/core/node_modules/leaflet/src/layer/marker/index.js +8 -0
  84. data/packages/core/node_modules/leaflet/src/layer/tile/GridLayer.js +923 -0
  85. data/packages/core/node_modules/leaflet/src/layer/tile/TileLayer.WMS.js +137 -0
  86. data/packages/core/node_modules/leaflet/src/layer/tile/TileLayer.js +289 -0
  87. data/packages/core/node_modules/leaflet/src/layer/tile/index.js +6 -0
  88. data/packages/core/node_modules/leaflet/src/layer/vector/Canvas.js +492 -0
  89. data/packages/core/node_modules/leaflet/src/layer/vector/Circle.js +113 -0
  90. data/packages/core/node_modules/leaflet/src/layer/vector/CircleMarker.js +109 -0
  91. data/packages/core/node_modules/leaflet/src/layer/vector/Path.js +148 -0
  92. data/packages/core/node_modules/leaflet/src/layer/vector/Polygon.js +159 -0
  93. data/packages/core/node_modules/leaflet/src/layer/vector/Polyline.js +307 -0
  94. data/packages/core/node_modules/leaflet/src/layer/vector/Rectangle.js +57 -0
  95. data/packages/core/node_modules/leaflet/src/layer/vector/Renderer.getRenderer.js +45 -0
  96. data/packages/core/node_modules/leaflet/src/layer/vector/Renderer.js +133 -0
  97. data/packages/core/node_modules/leaflet/src/layer/vector/SVG.Util.js +39 -0
  98. data/packages/core/node_modules/leaflet/src/layer/vector/SVG.VML.js +144 -0
  99. data/packages/core/node_modules/leaflet/src/layer/vector/SVG.js +207 -0
  100. data/packages/core/node_modules/leaflet/src/layer/vector/index.js +14 -0
  101. data/packages/core/node_modules/leaflet/src/map/Map.js +1751 -0
  102. data/packages/core/node_modules/leaflet/src/map/Map.methodOptions.leafdoc +112 -0
  103. data/packages/core/node_modules/leaflet/src/map/handler/Map.BoxZoom.js +152 -0
  104. data/packages/core/node_modules/leaflet/src/map/handler/Map.DoubleClickZoom.js +55 -0
  105. data/packages/core/node_modules/leaflet/src/map/handler/Map.Drag.js +235 -0
  106. data/packages/core/node_modules/leaflet/src/map/handler/Map.Keyboard.js +183 -0
  107. data/packages/core/node_modules/leaflet/src/map/handler/Map.ScrollWheelZoom.js +91 -0
  108. data/packages/core/node_modules/leaflet/src/map/handler/Map.TapHold.js +102 -0
  109. data/packages/core/node_modules/leaflet/src/map/handler/Map.TouchZoom.js +130 -0
  110. data/packages/core/node_modules/leaflet/src/map/index.js +17 -0
  111. data/packages/core/package.json +1 -1
  112. data/packages/dev/package.json +1 -1
  113. data/packages/elections/package.json +1 -1
  114. data/packages/eslint-config/package.json +1 -1
  115. data/packages/stylelint-config/package.json +1 -1
  116. data/packages/webpacker/package.json +1 -1
  117. metadata +148 -42
@@ -0,0 +1,443 @@
1
+
2
+ import {Control} from './Control';
3
+ import * as Util from '../core/Util';
4
+ import * as DomEvent from '../dom/DomEvent';
5
+ import * as DomUtil from '../dom/DomUtil';
6
+
7
+ /*
8
+ * @class Control.Layers
9
+ * @aka L.Control.Layers
10
+ * @inherits Control
11
+ *
12
+ * The layers control gives users the ability to switch between different base layers and switch overlays on/off (check out the [detailed example](https://leafletjs.com/examples/layers-control/)). Extends `Control`.
13
+ *
14
+ * @example
15
+ *
16
+ * ```js
17
+ * var baseLayers = {
18
+ * "Mapbox": mapbox,
19
+ * "OpenStreetMap": osm
20
+ * };
21
+ *
22
+ * var overlays = {
23
+ * "Marker": marker,
24
+ * "Roads": roadsLayer
25
+ * };
26
+ *
27
+ * L.control.layers(baseLayers, overlays).addTo(map);
28
+ * ```
29
+ *
30
+ * The `baseLayers` and `overlays` parameters are object literals with layer names as keys and `Layer` objects as values:
31
+ *
32
+ * ```js
33
+ * {
34
+ * "<someName1>": layer1,
35
+ * "<someName2>": layer2
36
+ * }
37
+ * ```
38
+ *
39
+ * The layer names can contain HTML, which allows you to add additional styling to the items:
40
+ *
41
+ * ```js
42
+ * {"<img src='my-layer-icon' /> <span class='my-layer-item'>My Layer</span>": myLayer}
43
+ * ```
44
+ */
45
+
46
+ export var Layers = Control.extend({
47
+ // @section
48
+ // @aka Control.Layers options
49
+ options: {
50
+ // @option collapsed: Boolean = true
51
+ // If `true`, the control will be collapsed into an icon and expanded on mouse hover, touch, or keyboard activation.
52
+ collapsed: true,
53
+ position: 'topright',
54
+
55
+ // @option autoZIndex: Boolean = true
56
+ // If `true`, the control will assign zIndexes in increasing order to all of its layers so that the order is preserved when switching them on/off.
57
+ autoZIndex: true,
58
+
59
+ // @option hideSingleBase: Boolean = false
60
+ // If `true`, the base layers in the control will be hidden when there is only one.
61
+ hideSingleBase: false,
62
+
63
+ // @option sortLayers: Boolean = false
64
+ // Whether to sort the layers. When `false`, layers will keep the order
65
+ // in which they were added to the control.
66
+ sortLayers: false,
67
+
68
+ // @option sortFunction: Function = *
69
+ // A [compare function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array/sort)
70
+ // that will be used for sorting the layers, when `sortLayers` is `true`.
71
+ // The function receives both the `L.Layer` instances and their names, as in
72
+ // `sortFunction(layerA, layerB, nameA, nameB)`.
73
+ // By default, it sorts layers alphabetically by their name.
74
+ sortFunction: function (layerA, layerB, nameA, nameB) {
75
+ return nameA < nameB ? -1 : (nameB < nameA ? 1 : 0);
76
+ }
77
+ },
78
+
79
+ initialize: function (baseLayers, overlays, options) {
80
+ Util.setOptions(this, options);
81
+
82
+ this._layerControlInputs = [];
83
+ this._layers = [];
84
+ this._lastZIndex = 0;
85
+ this._handlingClick = false;
86
+ this._preventClick = false;
87
+
88
+ for (var i in baseLayers) {
89
+ this._addLayer(baseLayers[i], i);
90
+ }
91
+
92
+ for (i in overlays) {
93
+ this._addLayer(overlays[i], i, true);
94
+ }
95
+ },
96
+
97
+ onAdd: function (map) {
98
+ this._initLayout();
99
+ this._update();
100
+
101
+ this._map = map;
102
+ map.on('zoomend', this._checkDisabledLayers, this);
103
+
104
+ for (var i = 0; i < this._layers.length; i++) {
105
+ this._layers[i].layer.on('add remove', this._onLayerChange, this);
106
+ }
107
+
108
+ return this._container;
109
+ },
110
+
111
+ addTo: function (map) {
112
+ Control.prototype.addTo.call(this, map);
113
+ // Trigger expand after Layers Control has been inserted into DOM so that is now has an actual height.
114
+ return this._expandIfNotCollapsed();
115
+ },
116
+
117
+ onRemove: function () {
118
+ this._map.off('zoomend', this._checkDisabledLayers, this);
119
+
120
+ for (var i = 0; i < this._layers.length; i++) {
121
+ this._layers[i].layer.off('add remove', this._onLayerChange, this);
122
+ }
123
+ },
124
+
125
+ // @method addBaseLayer(layer: Layer, name: String): this
126
+ // Adds a base layer (radio button entry) with the given name to the control.
127
+ addBaseLayer: function (layer, name) {
128
+ this._addLayer(layer, name);
129
+ return (this._map) ? this._update() : this;
130
+ },
131
+
132
+ // @method addOverlay(layer: Layer, name: String): this
133
+ // Adds an overlay (checkbox entry) with the given name to the control.
134
+ addOverlay: function (layer, name) {
135
+ this._addLayer(layer, name, true);
136
+ return (this._map) ? this._update() : this;
137
+ },
138
+
139
+ // @method removeLayer(layer: Layer): this
140
+ // Remove the given layer from the control.
141
+ removeLayer: function (layer) {
142
+ layer.off('add remove', this._onLayerChange, this);
143
+
144
+ var obj = this._getLayer(Util.stamp(layer));
145
+ if (obj) {
146
+ this._layers.splice(this._layers.indexOf(obj), 1);
147
+ }
148
+ return (this._map) ? this._update() : this;
149
+ },
150
+
151
+ // @method expand(): this
152
+ // Expand the control container if collapsed.
153
+ expand: function () {
154
+ DomUtil.addClass(this._container, 'leaflet-control-layers-expanded');
155
+ this._section.style.height = null;
156
+ var acceptableHeight = this._map.getSize().y - (this._container.offsetTop + 50);
157
+ if (acceptableHeight < this._section.clientHeight) {
158
+ DomUtil.addClass(this._section, 'leaflet-control-layers-scrollbar');
159
+ this._section.style.height = acceptableHeight + 'px';
160
+ } else {
161
+ DomUtil.removeClass(this._section, 'leaflet-control-layers-scrollbar');
162
+ }
163
+ this._checkDisabledLayers();
164
+ return this;
165
+ },
166
+
167
+ // @method collapse(): this
168
+ // Collapse the control container if expanded.
169
+ collapse: function () {
170
+ DomUtil.removeClass(this._container, 'leaflet-control-layers-expanded');
171
+ return this;
172
+ },
173
+
174
+ _initLayout: function () {
175
+ var className = 'leaflet-control-layers',
176
+ container = this._container = DomUtil.create('div', className),
177
+ collapsed = this.options.collapsed;
178
+
179
+ // makes this work on IE touch devices by stopping it from firing a mouseout event when the touch is released
180
+ container.setAttribute('aria-haspopup', true);
181
+
182
+ DomEvent.disableClickPropagation(container);
183
+ DomEvent.disableScrollPropagation(container);
184
+
185
+ var section = this._section = DomUtil.create('section', className + '-list');
186
+
187
+ if (collapsed) {
188
+ this._map.on('click', this.collapse, this);
189
+
190
+ DomEvent.on(container, {
191
+ mouseenter: this._expandSafely,
192
+ mouseleave: this.collapse
193
+ }, this);
194
+ }
195
+
196
+ var link = this._layersLink = DomUtil.create('a', className + '-toggle', container);
197
+ link.href = '#';
198
+ link.title = 'Layers';
199
+ link.setAttribute('role', 'button');
200
+
201
+ DomEvent.on(link, {
202
+ keydown: function (e) {
203
+ if (e.keyCode === 13) {
204
+ this._expandSafely();
205
+ }
206
+ },
207
+ // Certain screen readers intercept the key event and instead send a click event
208
+ click: function (e) {
209
+ DomEvent.preventDefault(e);
210
+ this._expandSafely();
211
+ }
212
+ }, this);
213
+
214
+ if (!collapsed) {
215
+ this.expand();
216
+ }
217
+
218
+ this._baseLayersList = DomUtil.create('div', className + '-base', section);
219
+ this._separator = DomUtil.create('div', className + '-separator', section);
220
+ this._overlaysList = DomUtil.create('div', className + '-overlays', section);
221
+
222
+ container.appendChild(section);
223
+ },
224
+
225
+ _getLayer: function (id) {
226
+ for (var i = 0; i < this._layers.length; i++) {
227
+
228
+ if (this._layers[i] && Util.stamp(this._layers[i].layer) === id) {
229
+ return this._layers[i];
230
+ }
231
+ }
232
+ },
233
+
234
+ _addLayer: function (layer, name, overlay) {
235
+ if (this._map) {
236
+ layer.on('add remove', this._onLayerChange, this);
237
+ }
238
+
239
+ this._layers.push({
240
+ layer: layer,
241
+ name: name,
242
+ overlay: overlay
243
+ });
244
+
245
+ if (this.options.sortLayers) {
246
+ this._layers.sort(Util.bind(function (a, b) {
247
+ return this.options.sortFunction(a.layer, b.layer, a.name, b.name);
248
+ }, this));
249
+ }
250
+
251
+ if (this.options.autoZIndex && layer.setZIndex) {
252
+ this._lastZIndex++;
253
+ layer.setZIndex(this._lastZIndex);
254
+ }
255
+
256
+ this._expandIfNotCollapsed();
257
+ },
258
+
259
+ _update: function () {
260
+ if (!this._container) { return this; }
261
+
262
+ DomUtil.empty(this._baseLayersList);
263
+ DomUtil.empty(this._overlaysList);
264
+
265
+ this._layerControlInputs = [];
266
+ var baseLayersPresent, overlaysPresent, i, obj, baseLayersCount = 0;
267
+
268
+ for (i = 0; i < this._layers.length; i++) {
269
+ obj = this._layers[i];
270
+ this._addItem(obj);
271
+ overlaysPresent = overlaysPresent || obj.overlay;
272
+ baseLayersPresent = baseLayersPresent || !obj.overlay;
273
+ baseLayersCount += !obj.overlay ? 1 : 0;
274
+ }
275
+
276
+ // Hide base layers section if there's only one layer.
277
+ if (this.options.hideSingleBase) {
278
+ baseLayersPresent = baseLayersPresent && baseLayersCount > 1;
279
+ this._baseLayersList.style.display = baseLayersPresent ? '' : 'none';
280
+ }
281
+
282
+ this._separator.style.display = overlaysPresent && baseLayersPresent ? '' : 'none';
283
+
284
+ return this;
285
+ },
286
+
287
+ _onLayerChange: function (e) {
288
+ if (!this._handlingClick) {
289
+ this._update();
290
+ }
291
+
292
+ var obj = this._getLayer(Util.stamp(e.target));
293
+
294
+ // @namespace Map
295
+ // @section Layer events
296
+ // @event baselayerchange: LayersControlEvent
297
+ // Fired when the base layer is changed through the [layers control](#control-layers).
298
+ // @event overlayadd: LayersControlEvent
299
+ // Fired when an overlay is selected through the [layers control](#control-layers).
300
+ // @event overlayremove: LayersControlEvent
301
+ // Fired when an overlay is deselected through the [layers control](#control-layers).
302
+ // @namespace Control.Layers
303
+ var type = obj.overlay ?
304
+ (e.type === 'add' ? 'overlayadd' : 'overlayremove') :
305
+ (e.type === 'add' ? 'baselayerchange' : null);
306
+
307
+ if (type) {
308
+ this._map.fire(type, obj);
309
+ }
310
+ },
311
+
312
+ // IE7 bugs out if you create a radio dynamically, so you have to do it this hacky way (see https://stackoverflow.com/a/119079)
313
+ _createRadioElement: function (name, checked) {
314
+
315
+ var radioHtml = '<input type="radio" class="leaflet-control-layers-selector" name="' +
316
+ name + '"' + (checked ? ' checked="checked"' : '') + '/>';
317
+
318
+ var radioFragment = document.createElement('div');
319
+ radioFragment.innerHTML = radioHtml;
320
+
321
+ return radioFragment.firstChild;
322
+ },
323
+
324
+ _addItem: function (obj) {
325
+ var label = document.createElement('label'),
326
+ checked = this._map.hasLayer(obj.layer),
327
+ input;
328
+
329
+ if (obj.overlay) {
330
+ input = document.createElement('input');
331
+ input.type = 'checkbox';
332
+ input.className = 'leaflet-control-layers-selector';
333
+ input.defaultChecked = checked;
334
+ } else {
335
+ input = this._createRadioElement('leaflet-base-layers_' + Util.stamp(this), checked);
336
+ }
337
+
338
+ this._layerControlInputs.push(input);
339
+ input.layerId = Util.stamp(obj.layer);
340
+
341
+ DomEvent.on(input, 'click', this._onInputClick, this);
342
+
343
+ var name = document.createElement('span');
344
+ name.innerHTML = ' ' + obj.name;
345
+
346
+ // Helps from preventing layer control flicker when checkboxes are disabled
347
+ // https://github.com/Leaflet/Leaflet/issues/2771
348
+ var holder = document.createElement('span');
349
+
350
+ label.appendChild(holder);
351
+ holder.appendChild(input);
352
+ holder.appendChild(name);
353
+
354
+ var container = obj.overlay ? this._overlaysList : this._baseLayersList;
355
+ container.appendChild(label);
356
+
357
+ this._checkDisabledLayers();
358
+ return label;
359
+ },
360
+
361
+ _onInputClick: function () {
362
+ // expanding the control on mobile with a click can cause adding a layer - we don't want this
363
+ if (this._preventClick) {
364
+ return;
365
+ }
366
+
367
+ var inputs = this._layerControlInputs,
368
+ input, layer;
369
+ var addedLayers = [],
370
+ removedLayers = [];
371
+
372
+ this._handlingClick = true;
373
+
374
+ for (var i = inputs.length - 1; i >= 0; i--) {
375
+ input = inputs[i];
376
+ layer = this._getLayer(input.layerId).layer;
377
+
378
+ if (input.checked) {
379
+ addedLayers.push(layer);
380
+ } else if (!input.checked) {
381
+ removedLayers.push(layer);
382
+ }
383
+ }
384
+
385
+ // Bugfix issue 2318: Should remove all old layers before readding new ones
386
+ for (i = 0; i < removedLayers.length; i++) {
387
+ if (this._map.hasLayer(removedLayers[i])) {
388
+ this._map.removeLayer(removedLayers[i]);
389
+ }
390
+ }
391
+ for (i = 0; i < addedLayers.length; i++) {
392
+ if (!this._map.hasLayer(addedLayers[i])) {
393
+ this._map.addLayer(addedLayers[i]);
394
+ }
395
+ }
396
+
397
+ this._handlingClick = false;
398
+
399
+ this._refocusOnMap();
400
+ },
401
+
402
+ _checkDisabledLayers: function () {
403
+ var inputs = this._layerControlInputs,
404
+ input,
405
+ layer,
406
+ zoom = this._map.getZoom();
407
+
408
+ for (var i = inputs.length - 1; i >= 0; i--) {
409
+ input = inputs[i];
410
+ layer = this._getLayer(input.layerId).layer;
411
+ input.disabled = (layer.options.minZoom !== undefined && zoom < layer.options.minZoom) ||
412
+ (layer.options.maxZoom !== undefined && zoom > layer.options.maxZoom);
413
+
414
+ }
415
+ },
416
+
417
+ _expandIfNotCollapsed: function () {
418
+ if (this._map && !this.options.collapsed) {
419
+ this.expand();
420
+ }
421
+ return this;
422
+ },
423
+
424
+ _expandSafely: function () {
425
+ var section = this._section;
426
+ this._preventClick = true;
427
+ DomEvent.on(section, 'click', DomEvent.preventDefault);
428
+ this.expand();
429
+ var that = this;
430
+ setTimeout(function () {
431
+ DomEvent.off(section, 'click', DomEvent.preventDefault);
432
+ that._preventClick = false;
433
+ });
434
+ }
435
+
436
+ });
437
+
438
+
439
+ // @factory L.control.layers(baselayers?: Object, overlays?: Object, options?: Control.Layers options)
440
+ // Creates a layers control with the given layers. Base layers will be switched with radio buttons, while overlays will be switched with checkboxes. Note that all base layers should be passed in the base layers object, but only one should be added to the map during map instantiation.
441
+ export var layers = function (baseLayers, overlays, options) {
442
+ return new Layers(baseLayers, overlays, options);
443
+ };
@@ -0,0 +1,132 @@
1
+
2
+ import {Control} from './Control';
3
+ import * as DomUtil from '../dom/DomUtil';
4
+
5
+ /*
6
+ * @class Control.Scale
7
+ * @aka L.Control.Scale
8
+ * @inherits Control
9
+ *
10
+ * A simple scale control that shows the scale of the current center of screen in metric (m/km) and imperial (mi/ft) systems. Extends `Control`.
11
+ *
12
+ * @example
13
+ *
14
+ * ```js
15
+ * L.control.scale().addTo(map);
16
+ * ```
17
+ */
18
+
19
+ export var Scale = Control.extend({
20
+ // @section
21
+ // @aka Control.Scale options
22
+ options: {
23
+ position: 'bottomleft',
24
+
25
+ // @option maxWidth: Number = 100
26
+ // Maximum width of the control in pixels. The width is set dynamically to show round values (e.g. 100, 200, 500).
27
+ maxWidth: 100,
28
+
29
+ // @option metric: Boolean = True
30
+ // Whether to show the metric scale line (m/km).
31
+ metric: true,
32
+
33
+ // @option imperial: Boolean = True
34
+ // Whether to show the imperial scale line (mi/ft).
35
+ imperial: true
36
+
37
+ // @option updateWhenIdle: Boolean = false
38
+ // If `true`, the control is updated on [`moveend`](#map-moveend), otherwise it's always up-to-date (updated on [`move`](#map-move)).
39
+ },
40
+
41
+ onAdd: function (map) {
42
+ var className = 'leaflet-control-scale',
43
+ container = DomUtil.create('div', className),
44
+ options = this.options;
45
+
46
+ this._addScales(options, className + '-line', container);
47
+
48
+ map.on(options.updateWhenIdle ? 'moveend' : 'move', this._update, this);
49
+ map.whenReady(this._update, this);
50
+
51
+ return container;
52
+ },
53
+
54
+ onRemove: function (map) {
55
+ map.off(this.options.updateWhenIdle ? 'moveend' : 'move', this._update, this);
56
+ },
57
+
58
+ _addScales: function (options, className, container) {
59
+ if (options.metric) {
60
+ this._mScale = DomUtil.create('div', className, container);
61
+ }
62
+ if (options.imperial) {
63
+ this._iScale = DomUtil.create('div', className, container);
64
+ }
65
+ },
66
+
67
+ _update: function () {
68
+ var map = this._map,
69
+ y = map.getSize().y / 2;
70
+
71
+ var maxMeters = map.distance(
72
+ map.containerPointToLatLng([0, y]),
73
+ map.containerPointToLatLng([this.options.maxWidth, y]));
74
+
75
+ this._updateScales(maxMeters);
76
+ },
77
+
78
+ _updateScales: function (maxMeters) {
79
+ if (this.options.metric && maxMeters) {
80
+ this._updateMetric(maxMeters);
81
+ }
82
+ if (this.options.imperial && maxMeters) {
83
+ this._updateImperial(maxMeters);
84
+ }
85
+ },
86
+
87
+ _updateMetric: function (maxMeters) {
88
+ var meters = this._getRoundNum(maxMeters),
89
+ label = meters < 1000 ? meters + ' m' : (meters / 1000) + ' km';
90
+
91
+ this._updateScale(this._mScale, label, meters / maxMeters);
92
+ },
93
+
94
+ _updateImperial: function (maxMeters) {
95
+ var maxFeet = maxMeters * 3.2808399,
96
+ maxMiles, miles, feet;
97
+
98
+ if (maxFeet > 5280) {
99
+ maxMiles = maxFeet / 5280;
100
+ miles = this._getRoundNum(maxMiles);
101
+ this._updateScale(this._iScale, miles + ' mi', miles / maxMiles);
102
+
103
+ } else {
104
+ feet = this._getRoundNum(maxFeet);
105
+ this._updateScale(this._iScale, feet + ' ft', feet / maxFeet);
106
+ }
107
+ },
108
+
109
+ _updateScale: function (scale, text, ratio) {
110
+ scale.style.width = Math.round(this.options.maxWidth * ratio) + 'px';
111
+ scale.innerHTML = text;
112
+ },
113
+
114
+ _getRoundNum: function (num) {
115
+ var pow10 = Math.pow(10, (Math.floor(num) + '').length - 1),
116
+ d = num / pow10;
117
+
118
+ d = d >= 10 ? 10 :
119
+ d >= 5 ? 5 :
120
+ d >= 3 ? 3 :
121
+ d >= 2 ? 2 : 1;
122
+
123
+ return pow10 * d;
124
+ }
125
+ });
126
+
127
+
128
+ // @factory L.control.scale(options?: Control.Scale options)
129
+ // Creates an scale control with the given options.
130
+ export var scale = function (options) {
131
+ return new Scale(options);
132
+ };