@nextgis/leaflet-map-adapter 3.0.0 → 4.0.0-alpha.0

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.
@@ -1,477 +1,602 @@
1
- /** Bundle of @nextgis/leaflet-map-adapter; version: 3.0.0; author: NextGIS */
1
+ /** Bundle of @nextgis/leaflet-map-adapter; version: 4.0.0-alpha.0; author: NextGIS */
2
2
  var LeafletMapAdapter = (function () {
3
3
  'use strict';
4
4
 
5
- var domain;
6
-
7
- // This constructor is used to store event handlers. Instantiating this is
8
- // faster than explicitly calling `Object.create(null)` to get a "clean" empty
9
- // object (tested with v8 v4.9).
10
- function EventHandlers() {}
11
- EventHandlers.prototype = Object.create(null);
12
-
13
- function EventEmitter() {
14
- EventEmitter.init.call(this);
5
+ function getElement(el) {
6
+ if (typeof el === "string") {
7
+ let el_ = document.getElementById(el);
8
+ if (!el_) {
9
+ try {
10
+ el_ = document.querySelector(el);
11
+ } catch (e) {
12
+ }
13
+ }
14
+ return el_ || void 0;
15
+ }
16
+ return el;
15
17
  }
16
18
 
17
- // nodejs oddity
18
- // require('events') === require('events').EventEmitter
19
- EventEmitter.EventEmitter = EventEmitter;
20
-
21
- EventEmitter.usingDomains = false;
22
-
23
- EventEmitter.prototype.domain = undefined;
24
- EventEmitter.prototype._events = undefined;
25
- EventEmitter.prototype._maxListeners = undefined;
26
-
27
- // By default EventEmitters will print a warning if more than 10 listeners are
28
- // added to it. This is a useful default which helps finding memory leaks.
29
- EventEmitter.defaultMaxListeners = 10;
19
+ var __defProp$g = Object.defineProperty;
20
+ var __defProps$8 = Object.defineProperties;
21
+ var __getOwnPropDescs$8 = Object.getOwnPropertyDescriptors;
22
+ var __getOwnPropSymbols$b = Object.getOwnPropertySymbols;
23
+ var __hasOwnProp$b = Object.prototype.hasOwnProperty;
24
+ var __propIsEnum$b = Object.prototype.propertyIsEnumerable;
25
+ var __defNormalProp$g = (obj, key, value) => key in obj ? __defProp$g(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
26
+ var __spreadValues$b = (a, b) => {
27
+ for (var prop in b || (b = {}))
28
+ if (__hasOwnProp$b.call(b, prop))
29
+ __defNormalProp$g(a, prop, b[prop]);
30
+ if (__getOwnPropSymbols$b)
31
+ for (var prop of __getOwnPropSymbols$b(b)) {
32
+ if (__propIsEnum$b.call(b, prop))
33
+ __defNormalProp$g(a, prop, b[prop]);
34
+ }
35
+ return a;
36
+ };
37
+ var __spreadProps$8 = (a, b) => __defProps$8(a, __getOwnPropDescs$8(b));
38
+ const controlOptions = /* @__PURE__ */ new WeakMap();
39
+ function resolveControlOptions(options = {}) {
40
+ var _a;
41
+ return __spreadProps$8(__spreadValues$b({}, options), {
42
+ margin: (_a = options.margin) != null ? _a : options.bar
43
+ });
44
+ }
45
+ function setControlOptions(control, options = {}) {
46
+ controlOptions.set(control, resolveControlOptions(options));
47
+ }
48
+ function getControlOptions(control) {
49
+ return control ? controlOptions.get(control) : void 0;
50
+ }
30
51
 
31
- EventEmitter.init = function() {
32
- this.domain = null;
33
- if (EventEmitter.usingDomains) {
34
- // if there is an active domain, then attach to it.
35
- if (domain.active) ;
52
+ var __defProp$f = Object.defineProperty;
53
+ var __defNormalProp$f = (obj, key, value) => key in obj ? __defProp$f(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
54
+ var __publicField$a = (obj, key, value) => __defNormalProp$f(obj, typeof key !== "symbol" ? key + "" : key, value);
55
+ class ControlContainer {
56
+ constructor(opt = {}) {
57
+ __publicField$a(this, "classPrefix", "webmap");
58
+ __publicField$a(this, "addClass");
59
+ __publicField$a(this, "map");
60
+ __publicField$a(this, "wrapperClass");
61
+ __publicField$a(this, "ownsContainer");
62
+ __publicField$a(this, "_container");
63
+ __publicField$a(this, "_positionsContainers");
64
+ __publicField$a(this, "_targets", /* @__PURE__ */ new Set());
65
+ __publicField$a(this, "_idContainers", /* @__PURE__ */ new Map());
66
+ __publicField$a(this, "_pendingChildren", /* @__PURE__ */ new Map());
67
+ __publicField$a(this, "_orders", /* @__PURE__ */ new WeakMap());
68
+ __publicField$a(this, "_targetOptions", /* @__PURE__ */ new WeakMap());
69
+ __publicField$a(this, "_switchGroups", /* @__PURE__ */ new WeakMap());
70
+ __publicField$a(this, "_switchBindings", /* @__PURE__ */ new WeakMap());
71
+ this.classPrefix = opt.classPrefix || this.classPrefix;
72
+ this.addClass = opt.addClass;
73
+ this.map = opt.map;
74
+ this.wrapperClass = opt.wrapperClass;
75
+ const externalPositions = [
76
+ "top-right",
77
+ "top-left",
78
+ "bottom-right",
79
+ "bottom-left"
80
+ ];
81
+ const positionContainers = externalPositions.some(
82
+ (position) => {
83
+ var _a;
84
+ return !!((_a = opt.positionContainers) == null ? void 0 : _a[position]);
85
+ }
86
+ ) ? opt.positionContainers : void 0;
87
+ this.ownsContainer = !opt.container && !positionContainers;
88
+ const { element, positionsContainers } = this.createContainerElement(
89
+ opt.container,
90
+ positionContainers
91
+ );
92
+ this._container = element;
93
+ this._positionsContainers = positionsContainers;
36
94
  }
37
-
38
- if (!this._events || this._events === Object.getPrototypeOf(this)._events) {
39
- this._events = new EventHandlers();
40
- this._eventsCount = 0;
95
+ addTo(el) {
96
+ if (!this.ownsContainer) {
97
+ return this;
98
+ }
99
+ const el_ = getElement(el);
100
+ if (el_) {
101
+ el_.appendChild(this._container);
102
+ }
103
+ return this;
104
+ }
105
+ detach() {
106
+ if (!this.ownsContainer) {
107
+ Array.from(this._targets).forEach((target) => this.removeTarget(target));
108
+ this._pendingChildren.clear();
109
+ return;
110
+ }
111
+ const parent = this._container.parentElement;
112
+ if (parent) {
113
+ parent.removeChild(this._container);
114
+ }
115
+ }
116
+ getContainer() {
117
+ return this._container;
118
+ }
119
+ getPositionContainer(position) {
120
+ return this._positionsContainers[position];
121
+ }
122
+ newPositionContainer(position, order = 0, control) {
123
+ var _a;
124
+ const newContainer = document.createElement("div");
125
+ newContainer.className = `${this.classPrefix}-ctrl-wrapper` + (this.wrapperClass ? " " + this.wrapperClass : "");
126
+ if ((_a = getControlOptions(control)) == null ? void 0 : _a.margin) {
127
+ newContainer.classList.add(`${this.classPrefix}-ctrl-margin`);
128
+ }
129
+ this.append(newContainer, position, order, control);
130
+ return newContainer;
131
+ }
132
+ addControl(control, position, options = {}) {
133
+ const controlContainer = control.onAdd(this.map);
134
+ if (controlContainer instanceof HTMLElement) {
135
+ const target = this.newPositionContainer(
136
+ position,
137
+ options.order,
138
+ control
139
+ );
140
+ if (target) {
141
+ target.appendChild(controlContainer);
142
+ if (options.id) {
143
+ this.registerIDContainer(options.id, controlContainer, control);
144
+ }
145
+ return target;
146
+ }
147
+ }
148
+ }
149
+ append(element, position, order = 0, control) {
150
+ const node = this._normalizeElement(element);
151
+ if (!node) return;
152
+ const positionContainer = this._resolveTargetContainer(position);
153
+ if (positionContainer) {
154
+ this._insertSorted(positionContainer, node, order);
155
+ this._registerSwitchControl(node, control, positionContainer);
156
+ return positionContainer;
157
+ } else if (typeof position !== "string") {
158
+ this._appendPending(position.inside, node, order, control);
159
+ }
160
+ }
161
+ registerIDContainer(id, controlRoot, control) {
162
+ this._idContainers.set(id, controlRoot);
163
+ this._registerTargetOptions(controlRoot, control);
164
+ this._flushPending(id, controlRoot);
165
+ }
166
+ unregisterIDContainer(id) {
167
+ const controlRoot = this._idContainers.get(id);
168
+ if (controlRoot) {
169
+ this._targetOptions.delete(controlRoot);
170
+ }
171
+ this._idContainers.delete(id);
172
+ this._pendingChildren.delete(id);
173
+ }
174
+ removeTarget(target) {
175
+ const parent = target.parentElement;
176
+ if (parent) {
177
+ parent.removeChild(target);
178
+ }
179
+ this._unregisterSwitchControl(target);
180
+ this._removePending(target);
181
+ this._targets.delete(target);
182
+ }
183
+ createContainerElement(container, positionContainers) {
184
+ const element = container || document.createElement("div");
185
+ if (!container) {
186
+ element.className = `${this.classPrefix}-control-container` + (this.addClass ? " " + this.addClass : "");
187
+ }
188
+ const positionsContainers = {};
189
+ const positions = [
190
+ "top-right",
191
+ "top-left",
192
+ "bottom-right",
193
+ "bottom-left"
194
+ ];
195
+ positions.forEach((x) => {
196
+ const positionContainer = (positionContainers == null ? void 0 : positionContainers[x]) || this._createPositionContainer(x);
197
+ positionsContainers[x] = positionContainer;
198
+ if (!(positionContainers == null ? void 0 : positionContainers[x])) {
199
+ element.appendChild(positionContainer);
200
+ }
201
+ });
202
+ return { element, positionsContainers };
203
+ }
204
+ _createPositionContainer(position) {
205
+ const positionContainer = document.createElement("div");
206
+ positionContainer.className = `${this.classPrefix}-ctrl-${position}`;
207
+ return positionContainer;
208
+ }
209
+ _resolveTargetContainer(position) {
210
+ return typeof position === "string" ? this._positionsContainers[position] : this._idContainers.get(position.inside);
211
+ }
212
+ _normalizeElement(element) {
213
+ if (typeof element !== "string") {
214
+ return element;
215
+ }
216
+ const template = document.createElement("template");
217
+ template.innerHTML = element.trim();
218
+ return template.content.firstElementChild;
219
+ }
220
+ _insertSorted(positionContainer, element, order) {
221
+ this._orders.set(element, order);
222
+ element.style.order = String(order);
223
+ const isBottomPosition = this._isBottomPositionContainer(positionContainer);
224
+ const children = Array.from(positionContainer.children);
225
+ const before = children.find((child) => {
226
+ var _a;
227
+ if (child === element) {
228
+ return false;
229
+ }
230
+ const value = (_a = this._orders.get(child)) != null ? _a : Number.POSITIVE_INFINITY;
231
+ return isBottomPosition ? value <= order : value > order;
232
+ });
233
+ if (before) {
234
+ positionContainer.insertBefore(element, before);
235
+ } else if (element.parentElement === positionContainer) {
236
+ return;
237
+ } else {
238
+ positionContainer.appendChild(element);
239
+ }
240
+ this._targets.add(element);
241
+ }
242
+ _isBottomPositionContainer(element) {
243
+ return element === this._positionsContainers["bottom-left"] || element === this._positionsContainers["bottom-right"];
244
+ }
245
+ _appendPending(parentId, element, order, control) {
246
+ const parent = element.parentElement;
247
+ if (parent) {
248
+ parent.removeChild(element);
249
+ }
250
+ const pending = this._pendingChildren.get(parentId) || [];
251
+ pending.push({ element, order, control });
252
+ pending.sort((a, b) => a.order - b.order);
253
+ this._pendingChildren.set(parentId, pending);
254
+ this._targets.add(element);
255
+ }
256
+ _flushPending(parentId, target) {
257
+ const pending = this._pendingChildren.get(parentId);
258
+ if (!pending) return;
259
+ for (const { element, order, control } of pending) {
260
+ this._insertSorted(target, element, order);
261
+ this._registerSwitchControl(element, control, target);
262
+ }
263
+ this._pendingChildren.delete(parentId);
264
+ }
265
+ _removePending(target) {
266
+ this._pendingChildren.forEach((children, parentId) => {
267
+ const filtered = children.filter(({ element }) => element !== target);
268
+ if (filtered.length) {
269
+ this._pendingChildren.set(parentId, filtered);
270
+ } else {
271
+ this._pendingChildren.delete(parentId);
272
+ }
273
+ });
274
+ }
275
+ _registerSwitchControl(element, control, target) {
276
+ if (!this._isSwitchToggleControl(control)) return;
277
+ this._unregisterSwitchControl(element);
278
+ const groupName = typeof control.switch === "string" ? control.switch : "default";
279
+ const group = this._getSwitchGroup(target, groupName);
280
+ const hadDisableOnSecondClick = Object.prototype.hasOwnProperty.call(
281
+ control,
282
+ "disableOnSecondClick"
283
+ );
284
+ const previousDisableOnSecondClick = control.disableOnSecondClick;
285
+ const targetDisableOnSecondClick = control.disableOnSecondClick === void 0 ? this._getTargetDisableOnSecondClick(target) : void 0;
286
+ if (targetDisableOnSecondClick !== void 0) {
287
+ control.disableOnSecondClick = targetDisableOnSecondClick;
288
+ }
289
+ group.add(control);
290
+ const unsubscribe = control.onStatusChange((status) => {
291
+ if (status) {
292
+ this._disableSwitchSiblings(control, group);
293
+ }
294
+ });
295
+ this._switchBindings.set(element, {
296
+ control,
297
+ group,
298
+ unsubscribe,
299
+ hadDisableOnSecondClick,
300
+ previousDisableOnSecondClick
301
+ });
302
+ if (control.getStatus()) {
303
+ this._disableSwitchSiblings(control, group);
304
+ }
305
+ }
306
+ _unregisterSwitchControl(element) {
307
+ const binding = this._switchBindings.get(element);
308
+ if (binding) {
309
+ binding.unsubscribe();
310
+ binding.group.delete(binding.control);
311
+ if (binding.hadDisableOnSecondClick) {
312
+ binding.control.disableOnSecondClick = binding.previousDisableOnSecondClick;
313
+ } else {
314
+ delete binding.control.disableOnSecondClick;
315
+ }
316
+ this._switchBindings.delete(element);
317
+ }
318
+ Array.from(element.children).forEach((child) => {
319
+ if (child instanceof HTMLElement) {
320
+ this._unregisterSwitchControl(child);
321
+ }
322
+ });
323
+ }
324
+ _getSwitchGroup(target, groupName) {
325
+ let targetGroups = this._switchGroups.get(target);
326
+ if (!targetGroups) {
327
+ targetGroups = /* @__PURE__ */ new Map();
328
+ this._switchGroups.set(target, targetGroups);
329
+ }
330
+ let group = targetGroups.get(groupName);
331
+ if (!group) {
332
+ group = /* @__PURE__ */ new Set();
333
+ targetGroups.set(groupName, group);
334
+ }
335
+ return group;
336
+ }
337
+ _disableSwitchSiblings(activeControl, group) {
338
+ group.forEach((control) => {
339
+ if (control !== activeControl && control.getStatus()) {
340
+ control.onClick(false);
341
+ }
342
+ });
343
+ }
344
+ _getTargetDisableOnSecondClick(target) {
345
+ var _a;
346
+ return (_a = this._targetOptions.get(target)) == null ? void 0 : _a.disableOnSecondClick;
347
+ }
348
+ _isSwitchToggleControl(control) {
349
+ const toggle = control;
350
+ return !!((toggle == null ? void 0 : toggle.switch) && typeof toggle.onStatusChange === "function" && typeof toggle.getStatus === "function" && typeof toggle.onClick === "function");
351
+ }
352
+ _registerTargetOptions(target, control) {
353
+ const options = getControlOptions(control) || getControlOptions(target);
354
+ if (options) {
355
+ this._targetOptions.set(target, options);
356
+ } else {
357
+ this._targetOptions.delete(target);
358
+ }
41
359
  }
42
-
43
- this._maxListeners = this._maxListeners || undefined;
44
- };
45
-
46
- // Obviously not all Emitters should be limited to 10. This function allows
47
- // that to be increased. Set to zero for unlimited.
48
- EventEmitter.prototype.setMaxListeners = function setMaxListeners(n) {
49
- if (typeof n !== 'number' || n < 0 || isNaN(n))
50
- throw new TypeError('"n" argument must be a positive number');
51
- this._maxListeners = n;
52
- return this;
53
- };
54
-
55
- function $getMaxListeners(that) {
56
- if (that._maxListeners === undefined)
57
- return EventEmitter.defaultMaxListeners;
58
- return that._maxListeners;
59
360
  }
60
361
 
61
- EventEmitter.prototype.getMaxListeners = function getMaxListeners() {
62
- return $getMaxListeners(this);
63
- };
64
-
65
- // These standalone emit* functions are used to optimize calling of event
66
- // handlers for fast cases because emit() itself often has a variable number of
67
- // arguments and can be deoptimized because of that. These functions always have
68
- // the same number of arguments and thus do not get deoptimized, so the code
69
- // inside them can execute faster.
70
- function emitNone(handler, isFn, self) {
71
- if (isFn)
72
- handler.call(self);
73
- else {
74
- var len = handler.length;
75
- var listeners = arrayClone(handler, len);
76
- for (var i = 0; i < len; ++i)
77
- listeners[i].call(self);
362
+ const STOP_PROPAGATION_EVENTS = [
363
+ "wheel",
364
+ "click",
365
+ "mouseup",
366
+ "touchend",
367
+ "dblclick",
368
+ "pointerup",
369
+ "mousedown",
370
+ "touchstart",
371
+ "pointerdown"
372
+ ];
373
+ function addClasses(element, classes) {
374
+ if (classes) {
375
+ classes.split(" ").filter(Boolean).forEach((x) => element.classList.add(x));
78
376
  }
79
377
  }
80
- function emitOne(handler, isFn, self, arg1) {
81
- if (isFn)
82
- handler.call(self, arg1);
83
- else {
84
- var len = handler.length;
85
- var listeners = arrayClone(handler, len);
86
- for (var i = 0; i < len; ++i)
87
- listeners[i].call(self, arg1);
378
+ function removeElement(element) {
379
+ if (element == null ? void 0 : element.parentNode) {
380
+ element.parentNode.removeChild(element);
88
381
  }
89
382
  }
90
- function emitTwo(handler, isFn, self, arg1, arg2) {
91
- if (isFn)
92
- handler.call(self, arg1, arg2);
93
- else {
94
- var len = handler.length;
95
- var listeners = arrayClone(handler, len);
96
- for (var i = 0; i < len; ++i)
97
- listeners[i].call(self, arg1, arg2);
383
+ function stopPropagation(event) {
384
+ event.stopPropagation();
385
+ }
386
+ function preventMapEventPropagation(element) {
387
+ STOP_PROPAGATION_EVENTS.forEach((eventName) => {
388
+ element.addEventListener(eventName, stopPropagation);
389
+ });
390
+ }
391
+ function getAlignValue(align) {
392
+ if (align === "start") return "flex-start";
393
+ if (align === "end") return "flex-end";
394
+ return align;
395
+ }
396
+ function isZeroGap(gap) {
397
+ if (typeof gap === "number") {
398
+ return gap === 0;
98
399
  }
400
+ if (typeof gap === "string") {
401
+ return gap.trim().split(/\s+/).every((x) => /^0(?:\.0+)?(?:[a-z%]+)?$/i.test(x));
402
+ }
403
+ return false;
99
404
  }
100
- function emitThree(handler, isFn, self, arg1, arg2, arg3) {
101
- if (isFn)
102
- handler.call(self, arg1, arg2, arg3);
103
- else {
104
- var len = handler.length;
105
- var listeners = arrayClone(handler, len);
106
- for (var i = 0; i < len; ++i)
107
- listeners[i].call(self, arg1, arg2, arg3);
405
+ function createControlContainer(options = {}) {
406
+ const resolvedOptions = resolveControlOptions(options);
407
+ const element = document.createElement("div");
408
+ element.className = "webmap-ctrl";
409
+ if (resolvedOptions.bar) {
410
+ element.classList.add("webmap-ctrl-group");
411
+ }
412
+ if (resolvedOptions.margin) {
413
+ element.classList.add("webmap-ctrl-margin");
414
+ }
415
+ const orientation = resolvedOptions.orientation || resolvedOptions.direction;
416
+ if (orientation) {
417
+ element.classList.add(`webmap-ctrl-${orientation}`);
108
418
  }
419
+ if (resolvedOptions.gap !== void 0) {
420
+ const gap = typeof resolvedOptions.gap === "number" ? `${resolvedOptions.gap}px` : resolvedOptions.gap;
421
+ element.style.setProperty("--webmap-ctrl-gap", gap);
422
+ if (isZeroGap(resolvedOptions.gap)) {
423
+ element.classList.add("webmap-ctrl-gapless");
424
+ }
425
+ }
426
+ const align = getAlignValue(resolvedOptions.align);
427
+ if (align) {
428
+ element.style.setProperty("--webmap-ctrl-align", align);
429
+ }
430
+ addClasses(element, resolvedOptions.addClass);
431
+ preventMapEventPropagation(element);
432
+ return element;
109
433
  }
110
-
111
- function emitMany(handler, isFn, self, args) {
112
- if (isFn)
113
- handler.apply(self, args);
114
- else {
115
- var len = handler.length;
116
- var listeners = arrayClone(handler, len);
117
- for (var i = 0; i < len; ++i)
118
- listeners[i].apply(self, args);
434
+ function appendHtml(element, html) {
435
+ if (html instanceof HTMLElement) {
436
+ element.appendChild(html);
437
+ } else if (typeof html === "string") {
438
+ element.innerHTML = html;
119
439
  }
120
440
  }
121
-
122
- EventEmitter.prototype.emit = function emit(type) {
123
- var er, handler, len, args, i, events, domain;
124
- var doError = (type === 'error');
125
-
126
- events = this._events;
127
- if (events)
128
- doError = (doError && events.error == null);
129
- else if (!doError)
130
- return false;
131
-
132
- domain = this.domain;
133
-
134
- // If there is no 'error' event listener then throw.
135
- if (doError) {
136
- er = arguments[1];
137
- if (domain) {
138
- if (!er)
139
- er = new Error('Uncaught, unspecified "error" event');
140
- er.domainEmitter = this;
141
- er.domain = domain;
142
- er.domainThrown = false;
143
- domain.emit('error', er);
144
- } else if (er instanceof Error) {
145
- throw er; // Unhandled 'error' event
146
- } else {
147
- // At least give some kind of context to the user
148
- var err = new Error('Uncaught, unspecified "error" event. (' + er + ')');
149
- err.context = er;
150
- throw err;
441
+ function createControlElement(control, options = {}, map) {
442
+ const element = createControlContainer(options);
443
+ setControlOptions(element, options);
444
+ const content = control.onAdd(map);
445
+ if (content) {
446
+ element.appendChild(content);
447
+ }
448
+ return element;
449
+ }
450
+ function createButtonControlContent(options) {
451
+ let button;
452
+ const onClick = (event) => {
453
+ event.preventDefault();
454
+ event.stopPropagation();
455
+ options.onClick();
456
+ };
457
+ const buttonControl = {
458
+ onAdd() {
459
+ button = document.createElement("button");
460
+ button.type = "button";
461
+ button.className = "webmap-ctrl-button";
462
+ addClasses(button, options.addClass);
463
+ if (options.title) {
464
+ button.title = options.title;
465
+ button.setAttribute("aria-label", options.title);
466
+ }
467
+ appendHtml(button, options.html);
468
+ button.addEventListener("click", onClick);
469
+ return button;
470
+ },
471
+ onRemove() {
472
+ if (button) {
473
+ button.removeEventListener("click", onClick);
474
+ removeElement(button);
475
+ button = void 0;
476
+ }
477
+ },
478
+ getContainer() {
479
+ return button;
151
480
  }
152
- return false;
481
+ };
482
+ buttonControl.remove = () => {
483
+ buttonControl.onRemove();
484
+ };
485
+ return buttonControl;
486
+ }
487
+ function createToggleControlContent(options) {
488
+ const link = document.createElement("div");
489
+ const statusListeners = /* @__PURE__ */ new Set();
490
+ let status = false;
491
+ if (options.getStatus) {
492
+ status = options.getStatus();
493
+ } else if (options.status) {
494
+ status = options.status;
153
495
  }
154
-
155
- handler = events[type];
156
-
157
- if (!handler)
158
- return false;
159
-
160
- var isFn = typeof handler === 'function';
161
- len = arguments.length;
162
- switch (len) {
163
- // fast cases
164
- case 1:
165
- emitNone(handler, isFn, this);
166
- break;
167
- case 2:
168
- emitOne(handler, isFn, this, arguments[1]);
169
- break;
170
- case 3:
171
- emitTwo(handler, isFn, this, arguments[1], arguments[2]);
172
- break;
173
- case 4:
174
- emitThree(handler, isFn, this, arguments[1], arguments[2], arguments[3]);
175
- break;
176
- // slower
177
- default:
178
- args = new Array(len - 1);
179
- for (i = 1; i < len; i++)
180
- args[i - 1] = arguments[i];
181
- emitMany(handler, isFn, this, args);
496
+ const title = options.title || "";
497
+ const html = options.html;
498
+ function notifyStatusChange(control) {
499
+ statusListeners.forEach((listener) => listener(status, control));
182
500
  }
183
-
184
- return true;
185
- };
186
-
187
- function _addListener(target, type, listener, prepend) {
188
- var m;
189
- var events;
190
- var existing;
191
-
192
- if (typeof listener !== 'function')
193
- throw new TypeError('"listener" argument must be a function');
194
-
195
- events = target._events;
196
- if (!events) {
197
- events = target._events = new EventHandlers();
198
- target._eventsCount = 0;
199
- } else {
200
- // To avoid recursion in the case that type === "newListener"! Before
201
- // adding it to the listeners, first emit "newListener".
202
- if (events.newListener) {
203
- target.emit('newListener', type,
204
- listener.listener ? listener.listener : listener);
205
-
206
- // Re-assign `events` because a newListener handler could have caused the
207
- // this._events to be assigned to a new object
208
- events = target._events;
501
+ function setTitle() {
502
+ if (title) {
503
+ if (typeof title === "string") {
504
+ link.title = title;
505
+ } else {
506
+ link.title = status ? title.on : title.off;
507
+ }
508
+ link.setAttribute("aria-label", link.title);
209
509
  }
210
- existing = events[type];
211
510
  }
212
-
213
- if (!existing) {
214
- // Optimize the case of one listener. Don't need the extra array object.
215
- existing = events[type] = listener;
216
- ++target._eventsCount;
217
- } else {
218
- if (typeof existing === 'function') {
219
- // Adding the second element, need to change to array.
220
- existing = events[type] = prepend ? [listener, existing] :
221
- [existing, listener];
222
- } else {
223
- // If we've already got an array, just append.
224
- if (prepend) {
225
- existing.unshift(listener);
511
+ function setHtml() {
512
+ if (html) {
513
+ link.innerHTML = "";
514
+ if (typeof html === "string" || html instanceof HTMLElement) {
515
+ appendHtml(link, html);
226
516
  } else {
227
- existing.push(listener);
517
+ appendHtml(link, status ? html.on : html.off);
228
518
  }
229
519
  }
230
-
231
- // Check for listener leak
232
- if (!existing.warned) {
233
- m = $getMaxListeners(target);
234
- if (m && m > 0 && existing.length > m) {
235
- existing.warned = true;
236
- var w = new Error('Possible EventEmitter memory leak detected. ' +
237
- existing.length + ' ' + type + ' listeners added. ' +
238
- 'Use emitter.setMaxListeners() to increase limit');
239
- w.name = 'MaxListenersExceededWarning';
240
- w.emitter = target;
241
- w.type = type;
242
- w.count = existing.length;
243
- emitWarning(w);
520
+ }
521
+ function setClasses(classes, impact) {
522
+ classes.split(" ").filter(Boolean).forEach((x) => {
523
+ if (impact) {
524
+ link.classList.add(x);
525
+ } else {
526
+ link.classList.remove(x);
244
527
  }
245
- }
528
+ });
246
529
  }
247
-
248
- return target;
249
- }
250
- function emitWarning(e) {
251
- typeof console.warn === 'function' ? console.warn(e) : console.log(e);
252
- }
253
- EventEmitter.prototype.addListener = function addListener(type, listener) {
254
- return _addListener(this, type, listener, false);
255
- };
256
-
257
- EventEmitter.prototype.on = EventEmitter.prototype.addListener;
258
-
259
- EventEmitter.prototype.prependListener =
260
- function prependListener(type, listener) {
261
- return _addListener(this, type, listener, true);
262
- };
263
-
264
- function _onceWrap(target, type, listener) {
265
- var fired = false;
266
- function g() {
267
- target.removeListener(type, g);
268
- if (!fired) {
269
- fired = true;
270
- listener.apply(target, arguments);
530
+ function setStatusClasses() {
531
+ if (options.addClassOn) {
532
+ setClasses(options.addClassOn, status);
533
+ }
534
+ if (options.addClassOff) {
535
+ setClasses(options.addClassOff, !status);
271
536
  }
272
537
  }
273
- g.listener = listener;
274
- return g;
275
- }
276
-
277
- EventEmitter.prototype.once = function once(type, listener) {
278
- if (typeof listener !== 'function')
279
- throw new TypeError('"listener" argument must be a function');
280
- this.on(type, _onceWrap(this, type, listener));
281
- return this;
282
- };
283
-
284
- EventEmitter.prototype.prependOnceListener =
285
- function prependOnceListener(type, listener) {
286
- if (typeof listener !== 'function')
287
- throw new TypeError('"listener" argument must be a function');
288
- this.prependListener(type, _onceWrap(this, type, listener));
289
- return this;
290
- };
291
-
292
- // emits a 'removeListener' event iff the listener was removed
293
- EventEmitter.prototype.removeListener =
294
- function removeListener(type, listener) {
295
- var list, events, position, i, originalListener;
296
-
297
- if (typeof listener !== 'function')
298
- throw new TypeError('"listener" argument must be a function');
299
-
300
- events = this._events;
301
- if (!events)
302
- return this;
303
-
304
- list = events[type];
305
- if (!list)
306
- return this;
307
-
308
- if (list === listener || (list.listener && list.listener === listener)) {
309
- if (--this._eventsCount === 0)
310
- this._events = new EventHandlers();
311
- else {
312
- delete events[type];
313
- if (events.removeListener)
314
- this.emit('removeListener', type, list.listener || listener);
315
- }
316
- } else if (typeof list !== 'function') {
317
- position = -1;
318
-
319
- for (i = list.length; i-- > 0;) {
320
- if (list[i] === listener ||
321
- (list[i].listener && list[i].listener === listener)) {
322
- originalListener = list[i].listener;
323
- position = i;
324
- break;
325
- }
326
- }
327
-
328
- if (position < 0)
329
- return this;
330
-
331
- if (list.length === 1) {
332
- list[0] = undefined;
333
- if (--this._eventsCount === 0) {
334
- this._events = new EventHandlers();
335
- return this;
336
- } else {
337
- delete events[type];
338
- }
339
- } else {
340
- spliceOne(list, position);
341
- }
342
-
343
- if (events.removeListener)
344
- this.emit('removeListener', type, originalListener || listener);
345
- }
346
-
347
- return this;
348
- };
349
-
350
- // Alias for removeListener added in NodeJS 10.0
351
- // https://nodejs.org/api/events.html#events_emitter_off_eventname_listener
352
- EventEmitter.prototype.off = function(type, listener){
353
- return this.removeListener(type, listener);
354
- };
355
-
356
- EventEmitter.prototype.removeAllListeners =
357
- function removeAllListeners(type) {
358
- var listeners, events;
359
-
360
- events = this._events;
361
- if (!events)
362
- return this;
363
-
364
- // not listening for removeListener, no need to emit
365
- if (!events.removeListener) {
366
- if (arguments.length === 0) {
367
- this._events = new EventHandlers();
368
- this._eventsCount = 0;
369
- } else if (events[type]) {
370
- if (--this._eventsCount === 0)
371
- this._events = new EventHandlers();
372
- else
373
- delete events[type];
374
- }
375
- return this;
538
+ setTitle();
539
+ setHtml();
540
+ if (options.addClass) {
541
+ setClasses(options.addClass, true);
542
+ }
543
+ setStatusClasses();
544
+ const changeStatus = (status_) => {
545
+ if (status_ !== void 0) {
546
+ status = status_;
547
+ }
548
+ setHtml();
549
+ setTitle();
550
+ setStatusClasses();
551
+ };
552
+ const getStatus = () => status;
553
+ const onClick = (status_) => {
554
+ if (status_ === void 0 && status && buttonControl.disableOnSecondClick) {
555
+ return;
556
+ }
557
+ const previousStatus = status;
558
+ status = status_ !== void 0 ? status_ : !status;
559
+ if (options.onClick) {
560
+ let afterClick;
561
+ try {
562
+ afterClick = options.onClick(status);
563
+ } catch (er) {
564
+ status = previousStatus;
565
+ changeStatus();
566
+ throw er;
376
567
  }
377
-
378
- // emit removeListener for all listeners on all events
379
- if (arguments.length === 0) {
380
- var keys = Object.keys(events);
381
- for (var i = 0, key; i < keys.length; ++i) {
382
- key = keys[i];
383
- if (key === 'removeListener') continue;
384
- this.removeAllListeners(key);
568
+ Promise.resolve(afterClick).then(() => {
569
+ changeStatus();
570
+ if (previousStatus !== status) {
571
+ notifyStatusChange(buttonControl);
385
572
  }
386
- this.removeAllListeners('removeListener');
387
- this._events = new EventHandlers();
388
- this._eventsCount = 0;
389
- return this;
390
- }
391
-
392
- listeners = events[type];
393
-
394
- if (typeof listeners === 'function') {
395
- this.removeListener(type, listeners);
396
- } else if (listeners) {
397
- // LIFO order
398
- do {
399
- this.removeListener(type, listeners[listeners.length - 1]);
400
- } while (listeners[0]);
573
+ }).catch(() => {
574
+ status = previousStatus;
575
+ changeStatus();
576
+ });
577
+ } else {
578
+ changeStatus();
579
+ if (previousStatus !== status) {
580
+ notifyStatusChange(buttonControl);
401
581
  }
402
-
403
- return this;
404
- };
405
-
406
- EventEmitter.prototype.listeners = function listeners(type) {
407
- var evlistener;
408
- var ret;
409
- var events = this._events;
410
-
411
- if (!events)
412
- ret = [];
413
- else {
414
- evlistener = events[type];
415
- if (!evlistener)
416
- ret = [];
417
- else if (typeof evlistener === 'function')
418
- ret = [evlistener.listener || evlistener];
419
- else
420
- ret = unwrapListeners(evlistener);
421
- }
422
-
423
- return ret;
424
- };
425
-
426
- EventEmitter.listenerCount = function(emitter, type) {
427
- if (typeof emitter.listenerCount === 'function') {
428
- return emitter.listenerCount(type);
429
- } else {
430
- return listenerCount.call(emitter, type);
431
- }
432
- };
433
-
434
- EventEmitter.prototype.listenerCount = listenerCount;
435
- function listenerCount(type) {
436
- var events = this._events;
437
-
438
- if (events) {
439
- var evlistener = events[type];
440
-
441
- if (typeof evlistener === 'function') {
442
- return 1;
443
- } else if (evlistener) {
444
- return evlistener.length;
445
- }
446
- }
447
-
448
- return 0;
449
- }
450
-
451
- EventEmitter.prototype.eventNames = function eventNames() {
452
- return this._eventsCount > 0 ? Reflect.ownKeys(this._events) : [];
453
- };
454
-
455
- // About 1.5x faster than the two-arg version of Array#splice().
456
- function spliceOne(list, index) {
457
- for (var i = index, k = i + 1, n = list.length; k < n; i += 1, k += 1)
458
- list[i] = list[k];
459
- list.pop();
460
- }
461
-
462
- function arrayClone(arr, i) {
463
- var copy = new Array(i);
464
- while (i--)
465
- copy[i] = arr[i];
466
- return copy;
467
- }
468
-
469
- function unwrapListeners(arr) {
470
- var ret = new Array(arr.length);
471
- for (var i = 0; i < ret.length; ++i) {
472
- ret[i] = arr[i].listener || arr[i];
582
+ }
583
+ };
584
+ const buttonControl = createButtonControlContent({
585
+ html: link,
586
+ onClick
587
+ });
588
+ buttonControl.onClick = onClick;
589
+ buttonControl.changeStatus = changeStatus;
590
+ buttonControl.getStatus = getStatus;
591
+ buttonControl.switch = options.switch;
592
+ if (options.disableOnSecondClick !== void 0) {
593
+ buttonControl.disableOnSecondClick = options.disableOnSecondClick;
473
594
  }
474
- return ret;
595
+ buttonControl.onStatusChange = (listener) => {
596
+ statusListeners.add(listener);
597
+ return () => statusListeners.delete(listener);
598
+ };
599
+ return buttonControl;
475
600
  }
476
601
 
477
602
  var leafletSrc$1 = {exports: {}};
@@ -13928,625 +14053,1279 @@ var LeafletMapAdapter = (function () {
13928
14053
  });
13929
14054
 
13930
14055
  // @section Handlers
13931
- // @property dragging: Handler
13932
- // Map dragging handler (by both mouse and touch).
13933
- Map.addInitHook('addHandler', 'dragging', Drag);
14056
+ // @property dragging: Handler
14057
+ // Map dragging handler (by both mouse and touch).
14058
+ Map.addInitHook('addHandler', 'dragging', Drag);
14059
+
14060
+ /*
14061
+ * L.Map.Keyboard is handling keyboard interaction with the map, enabled by default.
14062
+ */
14063
+
14064
+ // @namespace Map
14065
+ // @section Keyboard Navigation Options
14066
+ Map.mergeOptions({
14067
+ // @option keyboard: Boolean = true
14068
+ // Makes the map focusable and allows users to navigate the map with keyboard
14069
+ // arrows and `+`/`-` keys.
14070
+ keyboard: true,
14071
+
14072
+ // @option keyboardPanDelta: Number = 80
14073
+ // Amount of pixels to pan when pressing an arrow key.
14074
+ keyboardPanDelta: 80
14075
+ });
14076
+
14077
+ var Keyboard = Handler.extend({
14078
+
14079
+ keyCodes: {
14080
+ left: [37],
14081
+ right: [39],
14082
+ down: [40],
14083
+ up: [38],
14084
+ zoomIn: [187, 107, 61, 171],
14085
+ zoomOut: [189, 109, 54, 173]
14086
+ },
14087
+
14088
+ initialize: function (map) {
14089
+ this._map = map;
14090
+
14091
+ this._setPanDelta(map.options.keyboardPanDelta);
14092
+ this._setZoomDelta(map.options.zoomDelta);
14093
+ },
14094
+
14095
+ addHooks: function () {
14096
+ var container = this._map._container;
14097
+
14098
+ // make the container focusable by tabbing
14099
+ if (container.tabIndex <= 0) {
14100
+ container.tabIndex = '0';
14101
+ }
14102
+
14103
+ on(container, {
14104
+ focus: this._onFocus,
14105
+ blur: this._onBlur,
14106
+ mousedown: this._onMouseDown
14107
+ }, this);
14108
+
14109
+ this._map.on({
14110
+ focus: this._addHooks,
14111
+ blur: this._removeHooks
14112
+ }, this);
14113
+ },
14114
+
14115
+ removeHooks: function () {
14116
+ this._removeHooks();
14117
+
14118
+ off(this._map._container, {
14119
+ focus: this._onFocus,
14120
+ blur: this._onBlur,
14121
+ mousedown: this._onMouseDown
14122
+ }, this);
14123
+
14124
+ this._map.off({
14125
+ focus: this._addHooks,
14126
+ blur: this._removeHooks
14127
+ }, this);
14128
+ },
14129
+
14130
+ _onMouseDown: function () {
14131
+ if (this._focused) { return; }
14132
+
14133
+ var body = document.body,
14134
+ docEl = document.documentElement,
14135
+ top = body.scrollTop || docEl.scrollTop,
14136
+ left = body.scrollLeft || docEl.scrollLeft;
14137
+
14138
+ this._map._container.focus();
14139
+
14140
+ window.scrollTo(left, top);
14141
+ },
14142
+
14143
+ _onFocus: function () {
14144
+ this._focused = true;
14145
+ this._map.fire('focus');
14146
+ },
14147
+
14148
+ _onBlur: function () {
14149
+ this._focused = false;
14150
+ this._map.fire('blur');
14151
+ },
14152
+
14153
+ _setPanDelta: function (panDelta) {
14154
+ var keys = this._panKeys = {},
14155
+ codes = this.keyCodes,
14156
+ i, len;
14157
+
14158
+ for (i = 0, len = codes.left.length; i < len; i++) {
14159
+ keys[codes.left[i]] = [-1 * panDelta, 0];
14160
+ }
14161
+ for (i = 0, len = codes.right.length; i < len; i++) {
14162
+ keys[codes.right[i]] = [panDelta, 0];
14163
+ }
14164
+ for (i = 0, len = codes.down.length; i < len; i++) {
14165
+ keys[codes.down[i]] = [0, panDelta];
14166
+ }
14167
+ for (i = 0, len = codes.up.length; i < len; i++) {
14168
+ keys[codes.up[i]] = [0, -1 * panDelta];
14169
+ }
14170
+ },
14171
+
14172
+ _setZoomDelta: function (zoomDelta) {
14173
+ var keys = this._zoomKeys = {},
14174
+ codes = this.keyCodes,
14175
+ i, len;
14176
+
14177
+ for (i = 0, len = codes.zoomIn.length; i < len; i++) {
14178
+ keys[codes.zoomIn[i]] = zoomDelta;
14179
+ }
14180
+ for (i = 0, len = codes.zoomOut.length; i < len; i++) {
14181
+ keys[codes.zoomOut[i]] = -zoomDelta;
14182
+ }
14183
+ },
14184
+
14185
+ _addHooks: function () {
14186
+ on(document, 'keydown', this._onKeyDown, this);
14187
+ },
14188
+
14189
+ _removeHooks: function () {
14190
+ off(document, 'keydown', this._onKeyDown, this);
14191
+ },
14192
+
14193
+ _onKeyDown: function (e) {
14194
+ if (e.altKey || e.ctrlKey || e.metaKey) { return; }
14195
+
14196
+ var key = e.keyCode,
14197
+ map = this._map,
14198
+ offset;
14199
+
14200
+ if (key in this._panKeys) {
14201
+ if (!map._panAnim || !map._panAnim._inProgress) {
14202
+ offset = this._panKeys[key];
14203
+ if (e.shiftKey) {
14204
+ offset = toPoint(offset).multiplyBy(3);
14205
+ }
14206
+
14207
+ map.panBy(offset);
14208
+
14209
+ if (map.options.maxBounds) {
14210
+ map.panInsideBounds(map.options.maxBounds);
14211
+ }
14212
+ }
14213
+ } else if (key in this._zoomKeys) {
14214
+ map.setZoom(map.getZoom() + (e.shiftKey ? 3 : 1) * this._zoomKeys[key]);
14215
+
14216
+ } else if (key === 27 && map._popup && map._popup.options.closeOnEscapeKey) {
14217
+ map.closePopup();
14218
+
14219
+ } else {
14220
+ return;
14221
+ }
14222
+
14223
+ stop(e);
14224
+ }
14225
+ });
14226
+
14227
+ // @section Handlers
14228
+ // @section Handlers
14229
+ // @property keyboard: Handler
14230
+ // Keyboard navigation handler.
14231
+ Map.addInitHook('addHandler', 'keyboard', Keyboard);
14232
+
14233
+ /*
14234
+ * L.Handler.ScrollWheelZoom is used by L.Map to enable mouse scroll wheel zoom on the map.
14235
+ */
14236
+
14237
+ // @namespace Map
14238
+ // @section Interaction Options
14239
+ Map.mergeOptions({
14240
+ // @section Mouse wheel options
14241
+ // @option scrollWheelZoom: Boolean|String = true
14242
+ // Whether the map can be zoomed by using the mouse wheel. If passed `'center'`,
14243
+ // it will zoom to the center of the view regardless of where the mouse was.
14244
+ scrollWheelZoom: true,
14245
+
14246
+ // @option wheelDebounceTime: Number = 40
14247
+ // Limits the rate at which a wheel can fire (in milliseconds). By default
14248
+ // user can't zoom via wheel more often than once per 40 ms.
14249
+ wheelDebounceTime: 40,
14250
+
14251
+ // @option wheelPxPerZoomLevel: Number = 60
14252
+ // How many scroll pixels (as reported by [L.DomEvent.getWheelDelta](#domevent-getwheeldelta))
14253
+ // mean a change of one full zoom level. Smaller values will make wheel-zooming
14254
+ // faster (and vice versa).
14255
+ wheelPxPerZoomLevel: 60
14256
+ });
14257
+
14258
+ var ScrollWheelZoom = Handler.extend({
14259
+ addHooks: function () {
14260
+ on(this._map._container, 'wheel', this._onWheelScroll, this);
14261
+
14262
+ this._delta = 0;
14263
+ },
14264
+
14265
+ removeHooks: function () {
14266
+ off(this._map._container, 'wheel', this._onWheelScroll, this);
14267
+ },
14268
+
14269
+ _onWheelScroll: function (e) {
14270
+ var delta = getWheelDelta(e);
14271
+
14272
+ var debounce = this._map.options.wheelDebounceTime;
14273
+
14274
+ this._delta += delta;
14275
+ this._lastMousePos = this._map.mouseEventToContainerPoint(e);
14276
+
14277
+ if (!this._startTime) {
14278
+ this._startTime = +new Date();
14279
+ }
14280
+
14281
+ var left = Math.max(debounce - (+new Date() - this._startTime), 0);
14282
+
14283
+ clearTimeout(this._timer);
14284
+ this._timer = setTimeout(bind(this._performZoom, this), left);
14285
+
14286
+ stop(e);
14287
+ },
14288
+
14289
+ _performZoom: function () {
14290
+ var map = this._map,
14291
+ zoom = map.getZoom(),
14292
+ snap = this._map.options.zoomSnap || 0;
14293
+
14294
+ map._stop(); // stop panning and fly animations if any
14295
+
14296
+ // map the delta with a sigmoid function to -4..4 range leaning on -1..1
14297
+ var d2 = this._delta / (this._map.options.wheelPxPerZoomLevel * 4),
14298
+ d3 = 4 * Math.log(2 / (1 + Math.exp(-Math.abs(d2)))) / Math.LN2,
14299
+ d4 = snap ? Math.ceil(d3 / snap) * snap : d3,
14300
+ delta = map._limitZoom(zoom + (this._delta > 0 ? d4 : -d4)) - zoom;
14301
+
14302
+ this._delta = 0;
14303
+ this._startTime = null;
14304
+
14305
+ if (!delta) { return; }
14306
+
14307
+ if (map.options.scrollWheelZoom === 'center') {
14308
+ map.setZoom(zoom + delta);
14309
+ } else {
14310
+ map.setZoomAround(this._lastMousePos, zoom + delta);
14311
+ }
14312
+ }
14313
+ });
14314
+
14315
+ // @section Handlers
14316
+ // @property scrollWheelZoom: Handler
14317
+ // Scroll wheel zoom handler.
14318
+ Map.addInitHook('addHandler', 'scrollWheelZoom', ScrollWheelZoom);
13934
14319
 
13935
14320
  /*
13936
- * L.Map.Keyboard is handling keyboard interaction with the map, enabled by default.
14321
+ * L.Map.Tap is used to enable mobile hacks like quick taps and long hold.
13937
14322
  */
13938
14323
 
13939
14324
  // @namespace Map
13940
- // @section Keyboard Navigation Options
14325
+ // @section Interaction Options
13941
14326
  Map.mergeOptions({
13942
- // @option keyboard: Boolean = true
13943
- // Makes the map focusable and allows users to navigate the map with keyboard
13944
- // arrows and `+`/`-` keys.
13945
- keyboard: true,
14327
+ // @section Touch interaction options
14328
+ // @option tap: Boolean = true
14329
+ // Enables mobile hacks for supporting instant taps (fixing 200ms click
14330
+ // delay on iOS/Android) and touch holds (fired as `contextmenu` events).
14331
+ tap: true,
13946
14332
 
13947
- // @option keyboardPanDelta: Number = 80
13948
- // Amount of pixels to pan when pressing an arrow key.
13949
- keyboardPanDelta: 80
14333
+ // @option tapTolerance: Number = 15
14334
+ // The max number of pixels a user can shift his finger during touch
14335
+ // for it to be considered a valid tap.
14336
+ tapTolerance: 15
13950
14337
  });
13951
14338
 
13952
- var Keyboard = Handler.extend({
14339
+ var Tap = Handler.extend({
14340
+ addHooks: function () {
14341
+ on(this._map._container, 'touchstart', this._onDown, this);
14342
+ },
13953
14343
 
13954
- keyCodes: {
13955
- left: [37],
13956
- right: [39],
13957
- down: [40],
13958
- up: [38],
13959
- zoomIn: [187, 107, 61, 171],
13960
- zoomOut: [189, 109, 54, 173]
14344
+ removeHooks: function () {
14345
+ off(this._map._container, 'touchstart', this._onDown, this);
13961
14346
  },
13962
14347
 
13963
- initialize: function (map) {
13964
- this._map = map;
14348
+ _onDown: function (e) {
14349
+ if (!e.touches) { return; }
13965
14350
 
13966
- this._setPanDelta(map.options.keyboardPanDelta);
13967
- this._setZoomDelta(map.options.zoomDelta);
13968
- },
14351
+ preventDefault(e);
13969
14352
 
13970
- addHooks: function () {
13971
- var container = this._map._container;
14353
+ this._fireClick = true;
13972
14354
 
13973
- // make the container focusable by tabbing
13974
- if (container.tabIndex <= 0) {
13975
- container.tabIndex = '0';
14355
+ // don't simulate click or track longpress if more than 1 touch
14356
+ if (e.touches.length > 1) {
14357
+ this._fireClick = false;
14358
+ clearTimeout(this._holdTimeout);
14359
+ return;
13976
14360
  }
13977
14361
 
13978
- on(container, {
13979
- focus: this._onFocus,
13980
- blur: this._onBlur,
13981
- mousedown: this._onMouseDown
13982
- }, this);
14362
+ var first = e.touches[0],
14363
+ el = first.target;
13983
14364
 
13984
- this._map.on({
13985
- focus: this._addHooks,
13986
- blur: this._removeHooks
14365
+ this._startPos = this._newPos = new Point(first.clientX, first.clientY);
14366
+
14367
+ // if touching a link, highlight it
14368
+ if (el.tagName && el.tagName.toLowerCase() === 'a') {
14369
+ addClass(el, 'leaflet-active');
14370
+ }
14371
+
14372
+ // simulate long hold but setting a timeout
14373
+ this._holdTimeout = setTimeout(bind(function () {
14374
+ if (this._isTapValid()) {
14375
+ this._fireClick = false;
14376
+ this._onUp();
14377
+ this._simulateEvent('contextmenu', first);
14378
+ }
14379
+ }, this), 1000);
14380
+
14381
+ this._simulateEvent('mousedown', first);
14382
+
14383
+ on(document, {
14384
+ touchmove: this._onMove,
14385
+ touchend: this._onUp
13987
14386
  }, this);
13988
14387
  },
13989
14388
 
13990
- removeHooks: function () {
13991
- this._removeHooks();
14389
+ _onUp: function (e) {
14390
+ clearTimeout(this._holdTimeout);
13992
14391
 
13993
- off(this._map._container, {
13994
- focus: this._onFocus,
13995
- blur: this._onBlur,
13996
- mousedown: this._onMouseDown
14392
+ off(document, {
14393
+ touchmove: this._onMove,
14394
+ touchend: this._onUp
13997
14395
  }, this);
13998
14396
 
13999
- this._map.off({
14000
- focus: this._addHooks,
14001
- blur: this._removeHooks
14002
- }, this);
14003
- },
14397
+ if (this._fireClick && e && e.changedTouches) {
14004
14398
 
14005
- _onMouseDown: function () {
14006
- if (this._focused) { return; }
14399
+ var first = e.changedTouches[0],
14400
+ el = first.target;
14007
14401
 
14008
- var body = document.body,
14009
- docEl = document.documentElement,
14010
- top = body.scrollTop || docEl.scrollTop,
14011
- left = body.scrollLeft || docEl.scrollLeft;
14402
+ if (el && el.tagName && el.tagName.toLowerCase() === 'a') {
14403
+ removeClass(el, 'leaflet-active');
14404
+ }
14012
14405
 
14013
- this._map._container.focus();
14406
+ this._simulateEvent('mouseup', first);
14014
14407
 
14015
- window.scrollTo(left, top);
14408
+ // simulate click if the touch didn't move too much
14409
+ if (this._isTapValid()) {
14410
+ this._simulateEvent('click', first);
14411
+ }
14412
+ }
14016
14413
  },
14017
14414
 
14018
- _onFocus: function () {
14019
- this._focused = true;
14020
- this._map.fire('focus');
14415
+ _isTapValid: function () {
14416
+ return this._newPos.distanceTo(this._startPos) <= this._map.options.tapTolerance;
14021
14417
  },
14022
14418
 
14023
- _onBlur: function () {
14024
- this._focused = false;
14025
- this._map.fire('blur');
14419
+ _onMove: function (e) {
14420
+ var first = e.touches[0];
14421
+ this._newPos = new Point(first.clientX, first.clientY);
14422
+ this._simulateEvent('mousemove', first);
14026
14423
  },
14027
14424
 
14028
- _setPanDelta: function (panDelta) {
14029
- var keys = this._panKeys = {},
14030
- codes = this.keyCodes,
14031
- i, len;
14425
+ _simulateEvent: function (type, e) {
14426
+ var simulatedEvent = document.createEvent('MouseEvents');
14032
14427
 
14033
- for (i = 0, len = codes.left.length; i < len; i++) {
14034
- keys[codes.left[i]] = [-1 * panDelta, 0];
14035
- }
14036
- for (i = 0, len = codes.right.length; i < len; i++) {
14037
- keys[codes.right[i]] = [panDelta, 0];
14038
- }
14039
- for (i = 0, len = codes.down.length; i < len; i++) {
14040
- keys[codes.down[i]] = [0, panDelta];
14041
- }
14042
- for (i = 0, len = codes.up.length; i < len; i++) {
14043
- keys[codes.up[i]] = [0, -1 * panDelta];
14044
- }
14045
- },
14428
+ simulatedEvent._simulated = true;
14429
+ e.target._simulatedClick = true;
14046
14430
 
14047
- _setZoomDelta: function (zoomDelta) {
14048
- var keys = this._zoomKeys = {},
14049
- codes = this.keyCodes,
14050
- i, len;
14431
+ simulatedEvent.initMouseEvent(
14432
+ type, true, true, window, 1,
14433
+ e.screenX, e.screenY,
14434
+ e.clientX, e.clientY,
14435
+ false, false, false, false, 0, null);
14051
14436
 
14052
- for (i = 0, len = codes.zoomIn.length; i < len; i++) {
14053
- keys[codes.zoomIn[i]] = zoomDelta;
14054
- }
14055
- for (i = 0, len = codes.zoomOut.length; i < len; i++) {
14056
- keys[codes.zoomOut[i]] = -zoomDelta;
14057
- }
14058
- },
14437
+ e.target.dispatchEvent(simulatedEvent);
14438
+ }
14439
+ });
14059
14440
 
14060
- _addHooks: function () {
14061
- on(document, 'keydown', this._onKeyDown, this);
14062
- },
14441
+ // @section Handlers
14442
+ // @property tap: Handler
14443
+ // Mobile touch hacks (quick tap and touch hold) handler.
14444
+ if (touch && (!pointer || safari)) {
14445
+ Map.addInitHook('addHandler', 'tap', Tap);
14446
+ }
14063
14447
 
14064
- _removeHooks: function () {
14065
- off(document, 'keydown', this._onKeyDown, this);
14448
+ /*
14449
+ * L.Handler.TouchZoom is used by L.Map to add pinch zoom on supported mobile browsers.
14450
+ */
14451
+
14452
+ // @namespace Map
14453
+ // @section Interaction Options
14454
+ Map.mergeOptions({
14455
+ // @section Touch interaction options
14456
+ // @option touchZoom: Boolean|String = *
14457
+ // Whether the map can be zoomed by touch-dragging with two fingers. If
14458
+ // passed `'center'`, it will zoom to the center of the view regardless of
14459
+ // where the touch events (fingers) were. Enabled for touch-capable web
14460
+ // browsers except for old Androids.
14461
+ touchZoom: touch && !android23,
14462
+
14463
+ // @option bounceAtZoomLimits: Boolean = true
14464
+ // Set it to false if you don't want the map to zoom beyond min/max zoom
14465
+ // and then bounce back when pinch-zooming.
14466
+ bounceAtZoomLimits: true
14467
+ });
14468
+
14469
+ var TouchZoom = Handler.extend({
14470
+ addHooks: function () {
14471
+ addClass(this._map._container, 'leaflet-touch-zoom');
14472
+ on(this._map._container, 'touchstart', this._onTouchStart, this);
14066
14473
  },
14067
14474
 
14068
- _onKeyDown: function (e) {
14069
- if (e.altKey || e.ctrlKey || e.metaKey) { return; }
14475
+ removeHooks: function () {
14476
+ removeClass(this._map._container, 'leaflet-touch-zoom');
14477
+ off(this._map._container, 'touchstart', this._onTouchStart, this);
14478
+ },
14070
14479
 
14071
- var key = e.keyCode,
14072
- map = this._map,
14073
- offset;
14480
+ _onTouchStart: function (e) {
14481
+ var map = this._map;
14482
+ if (!e.touches || e.touches.length !== 2 || map._animatingZoom || this._zooming) { return; }
14074
14483
 
14075
- if (key in this._panKeys) {
14076
- if (!map._panAnim || !map._panAnim._inProgress) {
14077
- offset = this._panKeys[key];
14078
- if (e.shiftKey) {
14079
- offset = toPoint(offset).multiplyBy(3);
14080
- }
14484
+ var p1 = map.mouseEventToContainerPoint(e.touches[0]),
14485
+ p2 = map.mouseEventToContainerPoint(e.touches[1]);
14081
14486
 
14082
- map.panBy(offset);
14487
+ this._centerPoint = map.getSize()._divideBy(2);
14488
+ this._startLatLng = map.containerPointToLatLng(this._centerPoint);
14489
+ if (map.options.touchZoom !== 'center') {
14490
+ this._pinchStartLatLng = map.containerPointToLatLng(p1.add(p2)._divideBy(2));
14491
+ }
14083
14492
 
14084
- if (map.options.maxBounds) {
14085
- map.panInsideBounds(map.options.maxBounds);
14086
- }
14087
- }
14088
- } else if (key in this._zoomKeys) {
14089
- map.setZoom(map.getZoom() + (e.shiftKey ? 3 : 1) * this._zoomKeys[key]);
14493
+ this._startDist = p1.distanceTo(p2);
14494
+ this._startZoom = map.getZoom();
14090
14495
 
14091
- } else if (key === 27 && map._popup && map._popup.options.closeOnEscapeKey) {
14092
- map.closePopup();
14496
+ this._moved = false;
14497
+ this._zooming = true;
14093
14498
 
14094
- } else {
14095
- return;
14096
- }
14499
+ map._stop();
14097
14500
 
14098
- stop(e);
14099
- }
14100
- });
14501
+ on(document, 'touchmove', this._onTouchMove, this);
14502
+ on(document, 'touchend', this._onTouchEnd, this);
14101
14503
 
14102
- // @section Handlers
14103
- // @section Handlers
14104
- // @property keyboard: Handler
14105
- // Keyboard navigation handler.
14106
- Map.addInitHook('addHandler', 'keyboard', Keyboard);
14504
+ preventDefault(e);
14505
+ },
14107
14506
 
14108
- /*
14109
- * L.Handler.ScrollWheelZoom is used by L.Map to enable mouse scroll wheel zoom on the map.
14110
- */
14507
+ _onTouchMove: function (e) {
14508
+ if (!e.touches || e.touches.length !== 2 || !this._zooming) { return; }
14111
14509
 
14112
- // @namespace Map
14113
- // @section Interaction Options
14114
- Map.mergeOptions({
14115
- // @section Mouse wheel options
14116
- // @option scrollWheelZoom: Boolean|String = true
14117
- // Whether the map can be zoomed by using the mouse wheel. If passed `'center'`,
14118
- // it will zoom to the center of the view regardless of where the mouse was.
14119
- scrollWheelZoom: true,
14510
+ var map = this._map,
14511
+ p1 = map.mouseEventToContainerPoint(e.touches[0]),
14512
+ p2 = map.mouseEventToContainerPoint(e.touches[1]),
14513
+ scale = p1.distanceTo(p2) / this._startDist;
14120
14514
 
14121
- // @option wheelDebounceTime: Number = 40
14122
- // Limits the rate at which a wheel can fire (in milliseconds). By default
14123
- // user can't zoom via wheel more often than once per 40 ms.
14124
- wheelDebounceTime: 40,
14515
+ this._zoom = map.getScaleZoom(scale, this._startZoom);
14125
14516
 
14126
- // @option wheelPxPerZoomLevel: Number = 60
14127
- // How many scroll pixels (as reported by [L.DomEvent.getWheelDelta](#domevent-getwheeldelta))
14128
- // mean a change of one full zoom level. Smaller values will make wheel-zooming
14129
- // faster (and vice versa).
14130
- wheelPxPerZoomLevel: 60
14131
- });
14517
+ if (!map.options.bounceAtZoomLimits && (
14518
+ (this._zoom < map.getMinZoom() && scale < 1) ||
14519
+ (this._zoom > map.getMaxZoom() && scale > 1))) {
14520
+ this._zoom = map._limitZoom(this._zoom);
14521
+ }
14132
14522
 
14133
- var ScrollWheelZoom = Handler.extend({
14134
- addHooks: function () {
14135
- on(this._map._container, 'wheel', this._onWheelScroll, this);
14523
+ if (map.options.touchZoom === 'center') {
14524
+ this._center = this._startLatLng;
14525
+ if (scale === 1) { return; }
14526
+ } else {
14527
+ // Get delta from pinch to center, so centerLatLng is delta applied to initial pinchLatLng
14528
+ var delta = p1._add(p2)._divideBy(2)._subtract(this._centerPoint);
14529
+ if (scale === 1 && delta.x === 0 && delta.y === 0) { return; }
14530
+ this._center = map.unproject(map.project(this._pinchStartLatLng, this._zoom).subtract(delta), this._zoom);
14531
+ }
14136
14532
 
14137
- this._delta = 0;
14138
- },
14533
+ if (!this._moved) {
14534
+ map._moveStart(true, false);
14535
+ this._moved = true;
14536
+ }
14139
14537
 
14140
- removeHooks: function () {
14141
- off(this._map._container, 'wheel', this._onWheelScroll, this);
14538
+ cancelAnimFrame(this._animRequest);
14539
+
14540
+ var moveFn = bind(map._move, map, this._center, this._zoom, {pinch: true, round: false});
14541
+ this._animRequest = requestAnimFrame(moveFn, this, true);
14542
+
14543
+ preventDefault(e);
14142
14544
  },
14143
14545
 
14144
- _onWheelScroll: function (e) {
14145
- var delta = getWheelDelta(e);
14546
+ _onTouchEnd: function () {
14547
+ if (!this._moved || !this._zooming) {
14548
+ this._zooming = false;
14549
+ return;
14550
+ }
14146
14551
 
14147
- var debounce = this._map.options.wheelDebounceTime;
14552
+ this._zooming = false;
14553
+ cancelAnimFrame(this._animRequest);
14148
14554
 
14149
- this._delta += delta;
14150
- this._lastMousePos = this._map.mouseEventToContainerPoint(e);
14555
+ off(document, 'touchmove', this._onTouchMove, this);
14556
+ off(document, 'touchend', this._onTouchEnd, this);
14151
14557
 
14152
- if (!this._startTime) {
14153
- this._startTime = +new Date();
14558
+ // Pinch updates GridLayers' levels only when zoomSnap is off, so zoomSnap becomes noUpdate.
14559
+ if (this._map.options.zoomAnimation) {
14560
+ this._map._animateZoom(this._center, this._map._limitZoom(this._zoom), true, this._map.options.zoomSnap);
14561
+ } else {
14562
+ this._map._resetView(this._center, this._map._limitZoom(this._zoom));
14154
14563
  }
14564
+ }
14565
+ });
14155
14566
 
14156
- var left = Math.max(debounce - (+new Date() - this._startTime), 0);
14567
+ // @section Handlers
14568
+ // @property touchZoom: Handler
14569
+ // Touch zoom handler.
14570
+ Map.addInitHook('addHandler', 'touchZoom', TouchZoom);
14157
14571
 
14158
- clearTimeout(this._timer);
14159
- this._timer = setTimeout(bind(this._performZoom, this), left);
14572
+ Map.BoxZoom = BoxZoom;
14573
+ Map.DoubleClickZoom = DoubleClickZoom;
14574
+ Map.Drag = Drag;
14575
+ Map.Keyboard = Keyboard;
14576
+ Map.ScrollWheelZoom = ScrollWheelZoom;
14577
+ Map.Tap = Tap;
14578
+ Map.TouchZoom = TouchZoom;
14160
14579
 
14161
- stop(e);
14162
- },
14580
+ exports.version = version;
14581
+ exports.Control = Control;
14582
+ exports.control = control;
14583
+ exports.Browser = Browser;
14584
+ exports.Evented = Evented;
14585
+ exports.Mixin = Mixin;
14586
+ exports.Util = Util;
14587
+ exports.Class = Class;
14588
+ exports.Handler = Handler;
14589
+ exports.extend = extend;
14590
+ exports.bind = bind;
14591
+ exports.stamp = stamp;
14592
+ exports.setOptions = setOptions;
14593
+ exports.DomEvent = DomEvent;
14594
+ exports.DomUtil = DomUtil;
14595
+ exports.PosAnimation = PosAnimation;
14596
+ exports.Draggable = Draggable;
14597
+ exports.LineUtil = LineUtil;
14598
+ exports.PolyUtil = PolyUtil;
14599
+ exports.Point = Point;
14600
+ exports.point = toPoint;
14601
+ exports.Bounds = Bounds;
14602
+ exports.bounds = toBounds;
14603
+ exports.Transformation = Transformation;
14604
+ exports.transformation = toTransformation;
14605
+ exports.Projection = index;
14606
+ exports.LatLng = LatLng;
14607
+ exports.latLng = toLatLng;
14608
+ exports.LatLngBounds = LatLngBounds;
14609
+ exports.latLngBounds = toLatLngBounds;
14610
+ exports.CRS = CRS;
14611
+ exports.GeoJSON = GeoJSON;
14612
+ exports.geoJSON = geoJSON;
14613
+ exports.geoJson = geoJson;
14614
+ exports.Layer = Layer;
14615
+ exports.LayerGroup = LayerGroup;
14616
+ exports.layerGroup = layerGroup;
14617
+ exports.FeatureGroup = FeatureGroup;
14618
+ exports.featureGroup = featureGroup;
14619
+ exports.ImageOverlay = ImageOverlay;
14620
+ exports.imageOverlay = imageOverlay;
14621
+ exports.VideoOverlay = VideoOverlay;
14622
+ exports.videoOverlay = videoOverlay;
14623
+ exports.SVGOverlay = SVGOverlay;
14624
+ exports.svgOverlay = svgOverlay;
14625
+ exports.DivOverlay = DivOverlay;
14626
+ exports.Popup = Popup;
14627
+ exports.popup = popup;
14628
+ exports.Tooltip = Tooltip;
14629
+ exports.tooltip = tooltip;
14630
+ exports.Icon = Icon;
14631
+ exports.icon = icon;
14632
+ exports.DivIcon = DivIcon;
14633
+ exports.divIcon = divIcon;
14634
+ exports.Marker = Marker;
14635
+ exports.marker = marker;
14636
+ exports.TileLayer = TileLayer;
14637
+ exports.tileLayer = tileLayer;
14638
+ exports.GridLayer = GridLayer;
14639
+ exports.gridLayer = gridLayer;
14640
+ exports.SVG = SVG;
14641
+ exports.svg = svg$1;
14642
+ exports.Renderer = Renderer;
14643
+ exports.Canvas = Canvas;
14644
+ exports.canvas = canvas$1;
14645
+ exports.Path = Path;
14646
+ exports.CircleMarker = CircleMarker;
14647
+ exports.circleMarker = circleMarker;
14648
+ exports.Circle = Circle;
14649
+ exports.circle = circle;
14650
+ exports.Polyline = Polyline;
14651
+ exports.polyline = polyline;
14652
+ exports.Polygon = Polygon;
14653
+ exports.polygon = polygon;
14654
+ exports.Rectangle = Rectangle;
14655
+ exports.rectangle = rectangle;
14656
+ exports.Map = Map;
14657
+ exports.map = createMap;
14163
14658
 
14164
- _performZoom: function () {
14165
- var map = this._map,
14166
- zoom = map.getZoom(),
14167
- snap = this._map.options.zoomSnap || 0;
14659
+ var oldL = window.L;
14660
+ exports.noConflict = function() {
14661
+ window.L = oldL;
14662
+ return this;
14663
+ };
14168
14664
 
14169
- map._stop(); // stop panning and fly animations if any
14665
+ // Always export us to window global (see #2364)
14666
+ window.L = exports;
14170
14667
 
14171
- // map the delta with a sigmoid function to -4..4 range leaning on -1..1
14172
- var d2 = this._delta / (this._map.options.wheelPxPerZoomLevel * 4),
14173
- d3 = 4 * Math.log(2 / (1 + Math.exp(-Math.abs(d2)))) / Math.LN2,
14174
- d4 = snap ? Math.ceil(d3 / snap) * snap : d3,
14175
- delta = map._limitZoom(zoom + (this._delta > 0 ? d4 : -d4)) - zoom;
14668
+ })));
14669
+
14670
+ } (leafletSrc$1, leafletSrc$1.exports));
14671
+ return leafletSrc$1.exports;
14672
+ }
14176
14673
 
14177
- this._delta = 0;
14178
- this._startTime = null;
14674
+ var leafletSrcExports = /*@__PURE__*/ requireLeafletSrc();
14179
14675
 
14180
- if (!delta) { return; }
14676
+ var __defProp$e = Object.defineProperty;
14677
+ var __defProps$7 = Object.defineProperties;
14678
+ var __getOwnPropDescs$7 = Object.getOwnPropertyDescriptors;
14679
+ var __getOwnPropSymbols$a = Object.getOwnPropertySymbols;
14680
+ var __hasOwnProp$a = Object.prototype.hasOwnProperty;
14681
+ var __propIsEnum$a = Object.prototype.propertyIsEnumerable;
14682
+ var __defNormalProp$e = (obj, key, value) => key in obj ? __defProp$e(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
14683
+ var __spreadValues$a = (a, b) => {
14684
+ for (var prop in b || (b = {}))
14685
+ if (__hasOwnProp$a.call(b, prop))
14686
+ __defNormalProp$e(a, prop, b[prop]);
14687
+ if (__getOwnPropSymbols$a)
14688
+ for (var prop of __getOwnPropSymbols$a(b)) {
14689
+ if (__propIsEnum$a.call(b, prop))
14690
+ __defNormalProp$e(a, prop, b[prop]);
14691
+ }
14692
+ return a;
14693
+ };
14694
+ var __spreadProps$7 = (a, b) => __defProps$7(a, __getOwnPropDescs$7(b));
14695
+ function createControl(control, options = {}, map) {
14696
+ const resolvedOptions = resolveControlOptions(options);
14697
+ const C = leafletSrcExports.Control.extend({
14698
+ onAdd(leafletMap) {
14699
+ const addClass = [
14700
+ "leaflet-control",
14701
+ resolvedOptions.bar ? "leaflet-bar" : "",
14702
+ resolvedOptions.addClass
14703
+ ].filter(Boolean).join(" ");
14704
+ const element = createControlElement(
14705
+ control,
14706
+ __spreadProps$7(__spreadValues$a({}, resolvedOptions), { addClass }),
14707
+ map != null ? map : leafletMap
14708
+ );
14709
+ if (!resolvedOptions.margin) {
14710
+ element.style.margin = "0px";
14711
+ }
14712
+ return element;
14713
+ },
14714
+ onRemove(leafletMap) {
14715
+ control.onRemove(map != null ? map : leafletMap);
14716
+ }
14717
+ });
14718
+ const instance = new C();
14719
+ setControlOptions(instance, resolvedOptions);
14720
+ return instance;
14721
+ }
14722
+
14723
+ function createButtonControl(options, map) {
14724
+ return createControl(
14725
+ createButtonControlContent(options),
14726
+ { bar: true, margin: options.margin },
14727
+ map
14728
+ );
14729
+ }
14730
+
14731
+ function createToggleControl(options, map) {
14732
+ const toggleContent = createToggleControlContent(options);
14733
+ const control = createControl(
14734
+ toggleContent,
14735
+ { bar: true, margin: options.margin },
14736
+ map
14737
+ );
14738
+ control.onClick = toggleContent.onClick;
14739
+ control.changeStatus = toggleContent.changeStatus;
14740
+ control.getStatus = toggleContent.getStatus;
14741
+ control.switch = toggleContent.switch;
14742
+ Object.defineProperty(control, "disableOnSecondClick", {
14743
+ configurable: true,
14744
+ get: () => toggleContent.disableOnSecondClick,
14745
+ set: (value) => {
14746
+ toggleContent.disableOnSecondClick = value;
14747
+ }
14748
+ });
14749
+ control.onStatusChange = toggleContent.onStatusChange;
14750
+ return control;
14751
+ }
14752
+
14753
+ var __defProp$d = Object.defineProperty;
14754
+ var __defProps$6 = Object.defineProperties;
14755
+ var __getOwnPropDescs$6 = Object.getOwnPropertyDescriptors;
14756
+ var __getOwnPropSymbols$9 = Object.getOwnPropertySymbols;
14757
+ var __hasOwnProp$9 = Object.prototype.hasOwnProperty;
14758
+ var __propIsEnum$9 = Object.prototype.propertyIsEnumerable;
14759
+ var __defNormalProp$d = (obj, key, value) => key in obj ? __defProp$d(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
14760
+ var __spreadValues$9 = (a, b) => {
14761
+ for (var prop in b || (b = {}))
14762
+ if (__hasOwnProp$9.call(b, prop))
14763
+ __defNormalProp$d(a, prop, b[prop]);
14764
+ if (__getOwnPropSymbols$9)
14765
+ for (var prop of __getOwnPropSymbols$9(b)) {
14766
+ if (__propIsEnum$9.call(b, prop))
14767
+ __defNormalProp$d(a, prop, b[prop]);
14768
+ }
14769
+ return a;
14770
+ };
14771
+ var __spreadProps$6 = (a, b) => __defProps$6(a, __getOwnPropDescs$6(b));
14772
+ var __publicField$9 = (obj, key, value) => __defNormalProp$d(obj, typeof key !== "symbol" ? key + "" : key, value);
14773
+ class LeafletControlContainer {
14774
+ constructor(map, options = {}) {
14775
+ __publicField$9(this, "map");
14776
+ __publicField$9(this, "controlContainer");
14777
+ __publicField$9(this, "targets", /* @__PURE__ */ new WeakMap());
14778
+ __publicField$9(this, "ids", /* @__PURE__ */ new WeakMap());
14779
+ this.map = map;
14780
+ this.controlContainer = this.createControlContainer(options);
14781
+ this.controlContainer.addTo(map.getContainer());
14782
+ }
14783
+ addControl(control, position, options = {}) {
14784
+ const targetPosition = typeof position === "string" ? position : "top-left";
14785
+ control.options.position = targetPosition.replace(
14786
+ "-",
14787
+ ""
14788
+ );
14789
+ this.map.addControl(control);
14790
+ const container = control.getContainer();
14791
+ if (container) {
14792
+ this.controlContainer.append(container, position, options.order, control);
14793
+ this.targets.set(control, container);
14794
+ if (options.id) {
14795
+ this.controlContainer.registerIDContainer(
14796
+ options.id,
14797
+ container,
14798
+ control
14799
+ );
14800
+ this.ids.set(control, options.id);
14801
+ }
14802
+ }
14803
+ return control;
14804
+ }
14805
+ removeControl(control) {
14806
+ this.map.removeControl(control);
14807
+ const id = this.ids.get(control);
14808
+ if (id) {
14809
+ this.controlContainer.unregisterIDContainer(id);
14810
+ this.ids.delete(control);
14811
+ }
14812
+ const target = this.targets.get(control);
14813
+ if (target) {
14814
+ this.controlContainer.removeTarget(target);
14815
+ this.targets.delete(control);
14816
+ }
14817
+ }
14818
+ append(element, position, order = 0) {
14819
+ this.controlContainer.append(element, position, order);
14820
+ }
14821
+ registerIDContainer(id, controlRoot, control) {
14822
+ this.controlContainer.registerIDContainer(id, controlRoot, control);
14823
+ }
14824
+ unregisterIDContainer(id) {
14825
+ this.controlContainer.unregisterIDContainer(id);
14826
+ }
14827
+ detach() {
14828
+ this.controlContainer.detach();
14829
+ }
14830
+ getContainer() {
14831
+ return this.controlContainer.getContainer();
14832
+ }
14833
+ getControlContainer() {
14834
+ return this.controlContainer;
14835
+ }
14836
+ createControlContainer(options) {
14837
+ const mapAny = this.map;
14838
+ const controlCorners = mapAny._controlCorners || {};
14839
+ const getCorner = (key, selector) => controlCorners[key] || this.map.getContainer().querySelector(selector) || void 0;
14840
+ return new ControlContainer(__spreadProps$6(__spreadValues$9({}, options), {
14841
+ map: this.map,
14842
+ container: mapAny._controlContainer,
14843
+ positionContainers: {
14844
+ "top-left": getCorner("topleft", ".leaflet-top.leaflet-left"),
14845
+ "top-right": getCorner("topright", ".leaflet-top.leaflet-right"),
14846
+ "bottom-left": getCorner("bottomleft", ".leaflet-bottom.leaflet-left"),
14847
+ "bottom-right": getCorner(
14848
+ "bottomright",
14849
+ ".leaflet-bottom.leaflet-right"
14850
+ )
14851
+ }
14852
+ }));
14853
+ }
14854
+ }
14181
14855
 
14182
- if (map.options.scrollWheelZoom === 'center') {
14183
- map.setZoom(zoom + delta);
14184
- } else {
14185
- map.setZoomAround(this._lastMousePos, zoom + delta);
14186
- }
14187
- }
14188
- });
14856
+ var domain;
14189
14857
 
14190
- // @section Handlers
14191
- // @property scrollWheelZoom: Handler
14192
- // Scroll wheel zoom handler.
14193
- Map.addInitHook('addHandler', 'scrollWheelZoom', ScrollWheelZoom);
14858
+ // This constructor is used to store event handlers. Instantiating this is
14859
+ // faster than explicitly calling `Object.create(null)` to get a "clean" empty
14860
+ // object (tested with v8 v4.9).
14861
+ function EventHandlers() {}
14862
+ EventHandlers.prototype = Object.create(null);
14194
14863
 
14195
- /*
14196
- * L.Map.Tap is used to enable mobile hacks like quick taps and long hold.
14197
- */
14864
+ function EventEmitter() {
14865
+ EventEmitter.init.call(this);
14866
+ }
14198
14867
 
14199
- // @namespace Map
14200
- // @section Interaction Options
14201
- Map.mergeOptions({
14202
- // @section Touch interaction options
14203
- // @option tap: Boolean = true
14204
- // Enables mobile hacks for supporting instant taps (fixing 200ms click
14205
- // delay on iOS/Android) and touch holds (fired as `contextmenu` events).
14206
- tap: true,
14868
+ // nodejs oddity
14869
+ // require('events') === require('events').EventEmitter
14870
+ EventEmitter.EventEmitter = EventEmitter;
14207
14871
 
14208
- // @option tapTolerance: Number = 15
14209
- // The max number of pixels a user can shift his finger during touch
14210
- // for it to be considered a valid tap.
14211
- tapTolerance: 15
14212
- });
14872
+ EventEmitter.usingDomains = false;
14213
14873
 
14214
- var Tap = Handler.extend({
14215
- addHooks: function () {
14216
- on(this._map._container, 'touchstart', this._onDown, this);
14217
- },
14874
+ EventEmitter.prototype.domain = undefined;
14875
+ EventEmitter.prototype._events = undefined;
14876
+ EventEmitter.prototype._maxListeners = undefined;
14218
14877
 
14219
- removeHooks: function () {
14220
- off(this._map._container, 'touchstart', this._onDown, this);
14221
- },
14878
+ // By default EventEmitters will print a warning if more than 10 listeners are
14879
+ // added to it. This is a useful default which helps finding memory leaks.
14880
+ EventEmitter.defaultMaxListeners = 10;
14222
14881
 
14223
- _onDown: function (e) {
14224
- if (!e.touches) { return; }
14882
+ EventEmitter.init = function() {
14883
+ this.domain = null;
14884
+ if (EventEmitter.usingDomains) {
14885
+ // if there is an active domain, then attach to it.
14886
+ if (domain.active && !(this instanceof domain.Domain)) {
14887
+ this.domain = domain.active;
14888
+ }
14889
+ }
14225
14890
 
14226
- preventDefault(e);
14891
+ if (!this._events || this._events === Object.getPrototypeOf(this)._events) {
14892
+ this._events = new EventHandlers();
14893
+ this._eventsCount = 0;
14894
+ }
14227
14895
 
14228
- this._fireClick = true;
14896
+ this._maxListeners = this._maxListeners || undefined;
14897
+ };
14229
14898
 
14230
- // don't simulate click or track longpress if more than 1 touch
14231
- if (e.touches.length > 1) {
14232
- this._fireClick = false;
14233
- clearTimeout(this._holdTimeout);
14234
- return;
14235
- }
14899
+ // Obviously not all Emitters should be limited to 10. This function allows
14900
+ // that to be increased. Set to zero for unlimited.
14901
+ EventEmitter.prototype.setMaxListeners = function setMaxListeners(n) {
14902
+ if (typeof n !== 'number' || n < 0 || isNaN(n))
14903
+ throw new TypeError('"n" argument must be a positive number');
14904
+ this._maxListeners = n;
14905
+ return this;
14906
+ };
14236
14907
 
14237
- var first = e.touches[0],
14238
- el = first.target;
14908
+ function $getMaxListeners(that) {
14909
+ if (that._maxListeners === undefined)
14910
+ return EventEmitter.defaultMaxListeners;
14911
+ return that._maxListeners;
14912
+ }
14239
14913
 
14240
- this._startPos = this._newPos = new Point(first.clientX, first.clientY);
14914
+ EventEmitter.prototype.getMaxListeners = function getMaxListeners() {
14915
+ return $getMaxListeners(this);
14916
+ };
14241
14917
 
14242
- // if touching a link, highlight it
14243
- if (el.tagName && el.tagName.toLowerCase() === 'a') {
14244
- addClass(el, 'leaflet-active');
14245
- }
14918
+ // These standalone emit* functions are used to optimize calling of event
14919
+ // handlers for fast cases because emit() itself often has a variable number of
14920
+ // arguments and can be deoptimized because of that. These functions always have
14921
+ // the same number of arguments and thus do not get deoptimized, so the code
14922
+ // inside them can execute faster.
14923
+ function emitNone(handler, isFn, self) {
14924
+ if (isFn)
14925
+ handler.call(self);
14926
+ else {
14927
+ var len = handler.length;
14928
+ var listeners = arrayClone(handler, len);
14929
+ for (var i = 0; i < len; ++i)
14930
+ listeners[i].call(self);
14931
+ }
14932
+ }
14933
+ function emitOne(handler, isFn, self, arg1) {
14934
+ if (isFn)
14935
+ handler.call(self, arg1);
14936
+ else {
14937
+ var len = handler.length;
14938
+ var listeners = arrayClone(handler, len);
14939
+ for (var i = 0; i < len; ++i)
14940
+ listeners[i].call(self, arg1);
14941
+ }
14942
+ }
14943
+ function emitTwo(handler, isFn, self, arg1, arg2) {
14944
+ if (isFn)
14945
+ handler.call(self, arg1, arg2);
14946
+ else {
14947
+ var len = handler.length;
14948
+ var listeners = arrayClone(handler, len);
14949
+ for (var i = 0; i < len; ++i)
14950
+ listeners[i].call(self, arg1, arg2);
14951
+ }
14952
+ }
14953
+ function emitThree(handler, isFn, self, arg1, arg2, arg3) {
14954
+ if (isFn)
14955
+ handler.call(self, arg1, arg2, arg3);
14956
+ else {
14957
+ var len = handler.length;
14958
+ var listeners = arrayClone(handler, len);
14959
+ for (var i = 0; i < len; ++i)
14960
+ listeners[i].call(self, arg1, arg2, arg3);
14961
+ }
14962
+ }
14246
14963
 
14247
- // simulate long hold but setting a timeout
14248
- this._holdTimeout = setTimeout(bind(function () {
14249
- if (this._isTapValid()) {
14250
- this._fireClick = false;
14251
- this._onUp();
14252
- this._simulateEvent('contextmenu', first);
14253
- }
14254
- }, this), 1000);
14964
+ function emitMany(handler, isFn, self, args) {
14965
+ if (isFn)
14966
+ handler.apply(self, args);
14967
+ else {
14968
+ var len = handler.length;
14969
+ var listeners = arrayClone(handler, len);
14970
+ for (var i = 0; i < len; ++i)
14971
+ listeners[i].apply(self, args);
14972
+ }
14973
+ }
14255
14974
 
14256
- this._simulateEvent('mousedown', first);
14975
+ EventEmitter.prototype.emit = function emit(type) {
14976
+ var er, handler, len, args, i, events, domain;
14977
+ var doError = (type === 'error');
14257
14978
 
14258
- on(document, {
14259
- touchmove: this._onMove,
14260
- touchend: this._onUp
14261
- }, this);
14262
- },
14979
+ events = this._events;
14980
+ if (events)
14981
+ doError = (doError && events.error == null);
14982
+ else if (!doError)
14983
+ return false;
14263
14984
 
14264
- _onUp: function (e) {
14265
- clearTimeout(this._holdTimeout);
14985
+ domain = this.domain;
14266
14986
 
14267
- off(document, {
14268
- touchmove: this._onMove,
14269
- touchend: this._onUp
14270
- }, this);
14987
+ // If there is no 'error' event listener then throw.
14988
+ if (doError) {
14989
+ er = arguments[1];
14990
+ if (domain) {
14991
+ if (!er)
14992
+ er = new Error('Uncaught, unspecified "error" event');
14993
+ er.domainEmitter = this;
14994
+ er.domain = domain;
14995
+ er.domainThrown = false;
14996
+ domain.emit('error', er);
14997
+ } else if (er instanceof Error) {
14998
+ throw er; // Unhandled 'error' event
14999
+ } else {
15000
+ // At least give some kind of context to the user
15001
+ var err = new Error('Uncaught, unspecified "error" event. (' + er + ')');
15002
+ err.context = er;
15003
+ throw err;
15004
+ }
15005
+ return false;
15006
+ }
14271
15007
 
14272
- if (this._fireClick && e && e.changedTouches) {
15008
+ handler = events[type];
14273
15009
 
14274
- var first = e.changedTouches[0],
14275
- el = first.target;
15010
+ if (!handler)
15011
+ return false;
14276
15012
 
14277
- if (el && el.tagName && el.tagName.toLowerCase() === 'a') {
14278
- removeClass(el, 'leaflet-active');
14279
- }
15013
+ var isFn = typeof handler === 'function';
15014
+ len = arguments.length;
15015
+ switch (len) {
15016
+ // fast cases
15017
+ case 1:
15018
+ emitNone(handler, isFn, this);
15019
+ break;
15020
+ case 2:
15021
+ emitOne(handler, isFn, this, arguments[1]);
15022
+ break;
15023
+ case 3:
15024
+ emitTwo(handler, isFn, this, arguments[1], arguments[2]);
15025
+ break;
15026
+ case 4:
15027
+ emitThree(handler, isFn, this, arguments[1], arguments[2], arguments[3]);
15028
+ break;
15029
+ // slower
15030
+ default:
15031
+ args = new Array(len - 1);
15032
+ for (i = 1; i < len; i++)
15033
+ args[i - 1] = arguments[i];
15034
+ emitMany(handler, isFn, this, args);
15035
+ }
14280
15036
 
14281
- this._simulateEvent('mouseup', first);
15037
+ return true;
15038
+ };
14282
15039
 
14283
- // simulate click if the touch didn't move too much
14284
- if (this._isTapValid()) {
14285
- this._simulateEvent('click', first);
14286
- }
14287
- }
14288
- },
15040
+ function _addListener(target, type, listener, prepend) {
15041
+ var m;
15042
+ var events;
15043
+ var existing;
14289
15044
 
14290
- _isTapValid: function () {
14291
- return this._newPos.distanceTo(this._startPos) <= this._map.options.tapTolerance;
14292
- },
15045
+ if (typeof listener !== 'function')
15046
+ throw new TypeError('"listener" argument must be a function');
14293
15047
 
14294
- _onMove: function (e) {
14295
- var first = e.touches[0];
14296
- this._newPos = new Point(first.clientX, first.clientY);
14297
- this._simulateEvent('mousemove', first);
14298
- },
15048
+ events = target._events;
15049
+ if (!events) {
15050
+ events = target._events = new EventHandlers();
15051
+ target._eventsCount = 0;
15052
+ } else {
15053
+ // To avoid recursion in the case that type === "newListener"! Before
15054
+ // adding it to the listeners, first emit "newListener".
15055
+ if (events.newListener) {
15056
+ target.emit('newListener', type,
15057
+ listener.listener ? listener.listener : listener);
14299
15058
 
14300
- _simulateEvent: function (type, e) {
14301
- var simulatedEvent = document.createEvent('MouseEvents');
15059
+ // Re-assign `events` because a newListener handler could have caused the
15060
+ // this._events to be assigned to a new object
15061
+ events = target._events;
15062
+ }
15063
+ existing = events[type];
15064
+ }
14302
15065
 
14303
- simulatedEvent._simulated = true;
14304
- e.target._simulatedClick = true;
15066
+ if (!existing) {
15067
+ // Optimize the case of one listener. Don't need the extra array object.
15068
+ existing = events[type] = listener;
15069
+ ++target._eventsCount;
15070
+ } else {
15071
+ if (typeof existing === 'function') {
15072
+ // Adding the second element, need to change to array.
15073
+ existing = events[type] = prepend ? [listener, existing] :
15074
+ [existing, listener];
15075
+ } else {
15076
+ // If we've already got an array, just append.
15077
+ if (prepend) {
15078
+ existing.unshift(listener);
15079
+ } else {
15080
+ existing.push(listener);
15081
+ }
15082
+ }
14305
15083
 
14306
- simulatedEvent.initMouseEvent(
14307
- type, true, true, window, 1,
14308
- e.screenX, e.screenY,
14309
- e.clientX, e.clientY,
14310
- false, false, false, false, 0, null);
15084
+ // Check for listener leak
15085
+ if (!existing.warned) {
15086
+ m = $getMaxListeners(target);
15087
+ if (m && m > 0 && existing.length > m) {
15088
+ existing.warned = true;
15089
+ var w = new Error('Possible EventEmitter memory leak detected. ' +
15090
+ existing.length + ' ' + type + ' listeners added. ' +
15091
+ 'Use emitter.setMaxListeners() to increase limit');
15092
+ w.name = 'MaxListenersExceededWarning';
15093
+ w.emitter = target;
15094
+ w.type = type;
15095
+ w.count = existing.length;
15096
+ emitWarning(w);
15097
+ }
15098
+ }
15099
+ }
14311
15100
 
14312
- e.target.dispatchEvent(simulatedEvent);
14313
- }
14314
- });
15101
+ return target;
15102
+ }
15103
+ function emitWarning(e) {
15104
+ typeof console.warn === 'function' ? console.warn(e) : console.log(e);
15105
+ }
15106
+ EventEmitter.prototype.addListener = function addListener(type, listener) {
15107
+ return _addListener(this, type, listener, false);
15108
+ };
14315
15109
 
14316
- // @section Handlers
14317
- // @property tap: Handler
14318
- // Mobile touch hacks (quick tap and touch hold) handler.
14319
- if (touch && (!pointer || safari)) {
14320
- Map.addInitHook('addHandler', 'tap', Tap);
14321
- }
15110
+ EventEmitter.prototype.on = EventEmitter.prototype.addListener;
14322
15111
 
14323
- /*
14324
- * L.Handler.TouchZoom is used by L.Map to add pinch zoom on supported mobile browsers.
14325
- */
15112
+ EventEmitter.prototype.prependListener =
15113
+ function prependListener(type, listener) {
15114
+ return _addListener(this, type, listener, true);
15115
+ };
14326
15116
 
14327
- // @namespace Map
14328
- // @section Interaction Options
14329
- Map.mergeOptions({
14330
- // @section Touch interaction options
14331
- // @option touchZoom: Boolean|String = *
14332
- // Whether the map can be zoomed by touch-dragging with two fingers. If
14333
- // passed `'center'`, it will zoom to the center of the view regardless of
14334
- // where the touch events (fingers) were. Enabled for touch-capable web
14335
- // browsers except for old Androids.
14336
- touchZoom: touch && !android23,
15117
+ function _onceWrap(target, type, listener) {
15118
+ var fired = false;
15119
+ function g() {
15120
+ target.removeListener(type, g);
15121
+ if (!fired) {
15122
+ fired = true;
15123
+ listener.apply(target, arguments);
15124
+ }
15125
+ }
15126
+ g.listener = listener;
15127
+ return g;
15128
+ }
14337
15129
 
14338
- // @option bounceAtZoomLimits: Boolean = true
14339
- // Set it to false if you don't want the map to zoom beyond min/max zoom
14340
- // and then bounce back when pinch-zooming.
14341
- bounceAtZoomLimits: true
14342
- });
15130
+ EventEmitter.prototype.once = function once(type, listener) {
15131
+ if (typeof listener !== 'function')
15132
+ throw new TypeError('"listener" argument must be a function');
15133
+ this.on(type, _onceWrap(this, type, listener));
15134
+ return this;
15135
+ };
14343
15136
 
14344
- var TouchZoom = Handler.extend({
14345
- addHooks: function () {
14346
- addClass(this._map._container, 'leaflet-touch-zoom');
14347
- on(this._map._container, 'touchstart', this._onTouchStart, this);
14348
- },
15137
+ EventEmitter.prototype.prependOnceListener =
15138
+ function prependOnceListener(type, listener) {
15139
+ if (typeof listener !== 'function')
15140
+ throw new TypeError('"listener" argument must be a function');
15141
+ this.prependListener(type, _onceWrap(this, type, listener));
15142
+ return this;
15143
+ };
14349
15144
 
14350
- removeHooks: function () {
14351
- removeClass(this._map._container, 'leaflet-touch-zoom');
14352
- off(this._map._container, 'touchstart', this._onTouchStart, this);
14353
- },
15145
+ // emits a 'removeListener' event iff the listener was removed
15146
+ EventEmitter.prototype.removeListener =
15147
+ function removeListener(type, listener) {
15148
+ var list, events, position, i, originalListener;
14354
15149
 
14355
- _onTouchStart: function (e) {
14356
- var map = this._map;
14357
- if (!e.touches || e.touches.length !== 2 || map._animatingZoom || this._zooming) { return; }
15150
+ if (typeof listener !== 'function')
15151
+ throw new TypeError('"listener" argument must be a function');
14358
15152
 
14359
- var p1 = map.mouseEventToContainerPoint(e.touches[0]),
14360
- p2 = map.mouseEventToContainerPoint(e.touches[1]);
15153
+ events = this._events;
15154
+ if (!events)
15155
+ return this;
14361
15156
 
14362
- this._centerPoint = map.getSize()._divideBy(2);
14363
- this._startLatLng = map.containerPointToLatLng(this._centerPoint);
14364
- if (map.options.touchZoom !== 'center') {
14365
- this._pinchStartLatLng = map.containerPointToLatLng(p1.add(p2)._divideBy(2));
14366
- }
15157
+ list = events[type];
15158
+ if (!list)
15159
+ return this;
14367
15160
 
14368
- this._startDist = p1.distanceTo(p2);
14369
- this._startZoom = map.getZoom();
15161
+ if (list === listener || (list.listener && list.listener === listener)) {
15162
+ if (--this._eventsCount === 0)
15163
+ this._events = new EventHandlers();
15164
+ else {
15165
+ delete events[type];
15166
+ if (events.removeListener)
15167
+ this.emit('removeListener', type, list.listener || listener);
15168
+ }
15169
+ } else if (typeof list !== 'function') {
15170
+ position = -1;
14370
15171
 
14371
- this._moved = false;
14372
- this._zooming = true;
15172
+ for (i = list.length; i-- > 0;) {
15173
+ if (list[i] === listener ||
15174
+ (list[i].listener && list[i].listener === listener)) {
15175
+ originalListener = list[i].listener;
15176
+ position = i;
15177
+ break;
15178
+ }
15179
+ }
14373
15180
 
14374
- map._stop();
15181
+ if (position < 0)
15182
+ return this;
14375
15183
 
14376
- on(document, 'touchmove', this._onTouchMove, this);
14377
- on(document, 'touchend', this._onTouchEnd, this);
15184
+ if (list.length === 1) {
15185
+ list[0] = undefined;
15186
+ if (--this._eventsCount === 0) {
15187
+ this._events = new EventHandlers();
15188
+ return this;
15189
+ } else {
15190
+ delete events[type];
15191
+ }
15192
+ } else {
15193
+ spliceOne(list, position);
15194
+ }
14378
15195
 
14379
- preventDefault(e);
14380
- },
15196
+ if (events.removeListener)
15197
+ this.emit('removeListener', type, originalListener || listener);
15198
+ }
14381
15199
 
14382
- _onTouchMove: function (e) {
14383
- if (!e.touches || e.touches.length !== 2 || !this._zooming) { return; }
15200
+ return this;
15201
+ };
15202
+
15203
+ // Alias for removeListener added in NodeJS 10.0
15204
+ // https://nodejs.org/api/events.html#events_emitter_off_eventname_listener
15205
+ EventEmitter.prototype.off = function(type, listener){
15206
+ return this.removeListener(type, listener);
15207
+ };
14384
15208
 
14385
- var map = this._map,
14386
- p1 = map.mouseEventToContainerPoint(e.touches[0]),
14387
- p2 = map.mouseEventToContainerPoint(e.touches[1]),
14388
- scale = p1.distanceTo(p2) / this._startDist;
15209
+ EventEmitter.prototype.removeAllListeners =
15210
+ function removeAllListeners(type) {
15211
+ var listeners, events;
14389
15212
 
14390
- this._zoom = map.getScaleZoom(scale, this._startZoom);
15213
+ events = this._events;
15214
+ if (!events)
15215
+ return this;
14391
15216
 
14392
- if (!map.options.bounceAtZoomLimits && (
14393
- (this._zoom < map.getMinZoom() && scale < 1) ||
14394
- (this._zoom > map.getMaxZoom() && scale > 1))) {
14395
- this._zoom = map._limitZoom(this._zoom);
14396
- }
15217
+ // not listening for removeListener, no need to emit
15218
+ if (!events.removeListener) {
15219
+ if (arguments.length === 0) {
15220
+ this._events = new EventHandlers();
15221
+ this._eventsCount = 0;
15222
+ } else if (events[type]) {
15223
+ if (--this._eventsCount === 0)
15224
+ this._events = new EventHandlers();
15225
+ else
15226
+ delete events[type];
15227
+ }
15228
+ return this;
15229
+ }
14397
15230
 
14398
- if (map.options.touchZoom === 'center') {
14399
- this._center = this._startLatLng;
14400
- if (scale === 1) { return; }
14401
- } else {
14402
- // Get delta from pinch to center, so centerLatLng is delta applied to initial pinchLatLng
14403
- var delta = p1._add(p2)._divideBy(2)._subtract(this._centerPoint);
14404
- if (scale === 1 && delta.x === 0 && delta.y === 0) { return; }
14405
- this._center = map.unproject(map.project(this._pinchStartLatLng, this._zoom).subtract(delta), this._zoom);
14406
- }
15231
+ // emit removeListener for all listeners on all events
15232
+ if (arguments.length === 0) {
15233
+ var keys = Object.keys(events);
15234
+ for (var i = 0, key; i < keys.length; ++i) {
15235
+ key = keys[i];
15236
+ if (key === 'removeListener') continue;
15237
+ this.removeAllListeners(key);
15238
+ }
15239
+ this.removeAllListeners('removeListener');
15240
+ this._events = new EventHandlers();
15241
+ this._eventsCount = 0;
15242
+ return this;
15243
+ }
14407
15244
 
14408
- if (!this._moved) {
14409
- map._moveStart(true, false);
14410
- this._moved = true;
14411
- }
15245
+ listeners = events[type];
14412
15246
 
14413
- cancelAnimFrame(this._animRequest);
15247
+ if (typeof listeners === 'function') {
15248
+ this.removeListener(type, listeners);
15249
+ } else if (listeners) {
15250
+ // LIFO order
15251
+ do {
15252
+ this.removeListener(type, listeners[listeners.length - 1]);
15253
+ } while (listeners[0]);
15254
+ }
14414
15255
 
14415
- var moveFn = bind(map._move, map, this._center, this._zoom, {pinch: true, round: false});
14416
- this._animRequest = requestAnimFrame(moveFn, this, true);
15256
+ return this;
15257
+ };
14417
15258
 
14418
- preventDefault(e);
14419
- },
15259
+ EventEmitter.prototype.listeners = function listeners(type) {
15260
+ var evlistener;
15261
+ var ret;
15262
+ var events = this._events;
14420
15263
 
14421
- _onTouchEnd: function () {
14422
- if (!this._moved || !this._zooming) {
14423
- this._zooming = false;
14424
- return;
14425
- }
15264
+ if (!events)
15265
+ ret = [];
15266
+ else {
15267
+ evlistener = events[type];
15268
+ if (!evlistener)
15269
+ ret = [];
15270
+ else if (typeof evlistener === 'function')
15271
+ ret = [evlistener.listener || evlistener];
15272
+ else
15273
+ ret = unwrapListeners(evlistener);
15274
+ }
14426
15275
 
14427
- this._zooming = false;
14428
- cancelAnimFrame(this._animRequest);
15276
+ return ret;
15277
+ };
14429
15278
 
14430
- off(document, 'touchmove', this._onTouchMove, this);
14431
- off(document, 'touchend', this._onTouchEnd, this);
15279
+ EventEmitter.listenerCount = function(emitter, type) {
15280
+ if (typeof emitter.listenerCount === 'function') {
15281
+ return emitter.listenerCount(type);
15282
+ } else {
15283
+ return listenerCount.call(emitter, type);
15284
+ }
15285
+ };
14432
15286
 
14433
- // Pinch updates GridLayers' levels only when zoomSnap is off, so zoomSnap becomes noUpdate.
14434
- if (this._map.options.zoomAnimation) {
14435
- this._map._animateZoom(this._center, this._map._limitZoom(this._zoom), true, this._map.options.zoomSnap);
14436
- } else {
14437
- this._map._resetView(this._center, this._map._limitZoom(this._zoom));
14438
- }
14439
- }
14440
- });
15287
+ EventEmitter.prototype.listenerCount = listenerCount;
15288
+ function listenerCount(type) {
15289
+ var events = this._events;
14441
15290
 
14442
- // @section Handlers
14443
- // @property touchZoom: Handler
14444
- // Touch zoom handler.
14445
- Map.addInitHook('addHandler', 'touchZoom', TouchZoom);
15291
+ if (events) {
15292
+ var evlistener = events[type];
14446
15293
 
14447
- Map.BoxZoom = BoxZoom;
14448
- Map.DoubleClickZoom = DoubleClickZoom;
14449
- Map.Drag = Drag;
14450
- Map.Keyboard = Keyboard;
14451
- Map.ScrollWheelZoom = ScrollWheelZoom;
14452
- Map.Tap = Tap;
14453
- Map.TouchZoom = TouchZoom;
15294
+ if (typeof evlistener === 'function') {
15295
+ return 1;
15296
+ } else if (evlistener) {
15297
+ return evlistener.length;
15298
+ }
15299
+ }
14454
15300
 
14455
- exports.version = version;
14456
- exports.Control = Control;
14457
- exports.control = control;
14458
- exports.Browser = Browser;
14459
- exports.Evented = Evented;
14460
- exports.Mixin = Mixin;
14461
- exports.Util = Util;
14462
- exports.Class = Class;
14463
- exports.Handler = Handler;
14464
- exports.extend = extend;
14465
- exports.bind = bind;
14466
- exports.stamp = stamp;
14467
- exports.setOptions = setOptions;
14468
- exports.DomEvent = DomEvent;
14469
- exports.DomUtil = DomUtil;
14470
- exports.PosAnimation = PosAnimation;
14471
- exports.Draggable = Draggable;
14472
- exports.LineUtil = LineUtil;
14473
- exports.PolyUtil = PolyUtil;
14474
- exports.Point = Point;
14475
- exports.point = toPoint;
14476
- exports.Bounds = Bounds;
14477
- exports.bounds = toBounds;
14478
- exports.Transformation = Transformation;
14479
- exports.transformation = toTransformation;
14480
- exports.Projection = index;
14481
- exports.LatLng = LatLng;
14482
- exports.latLng = toLatLng;
14483
- exports.LatLngBounds = LatLngBounds;
14484
- exports.latLngBounds = toLatLngBounds;
14485
- exports.CRS = CRS;
14486
- exports.GeoJSON = GeoJSON;
14487
- exports.geoJSON = geoJSON;
14488
- exports.geoJson = geoJson;
14489
- exports.Layer = Layer;
14490
- exports.LayerGroup = LayerGroup;
14491
- exports.layerGroup = layerGroup;
14492
- exports.FeatureGroup = FeatureGroup;
14493
- exports.featureGroup = featureGroup;
14494
- exports.ImageOverlay = ImageOverlay;
14495
- exports.imageOverlay = imageOverlay;
14496
- exports.VideoOverlay = VideoOverlay;
14497
- exports.videoOverlay = videoOverlay;
14498
- exports.SVGOverlay = SVGOverlay;
14499
- exports.svgOverlay = svgOverlay;
14500
- exports.DivOverlay = DivOverlay;
14501
- exports.Popup = Popup;
14502
- exports.popup = popup;
14503
- exports.Tooltip = Tooltip;
14504
- exports.tooltip = tooltip;
14505
- exports.Icon = Icon;
14506
- exports.icon = icon;
14507
- exports.DivIcon = DivIcon;
14508
- exports.divIcon = divIcon;
14509
- exports.Marker = Marker;
14510
- exports.marker = marker;
14511
- exports.TileLayer = TileLayer;
14512
- exports.tileLayer = tileLayer;
14513
- exports.GridLayer = GridLayer;
14514
- exports.gridLayer = gridLayer;
14515
- exports.SVG = SVG;
14516
- exports.svg = svg$1;
14517
- exports.Renderer = Renderer;
14518
- exports.Canvas = Canvas;
14519
- exports.canvas = canvas$1;
14520
- exports.Path = Path;
14521
- exports.CircleMarker = CircleMarker;
14522
- exports.circleMarker = circleMarker;
14523
- exports.Circle = Circle;
14524
- exports.circle = circle;
14525
- exports.Polyline = Polyline;
14526
- exports.polyline = polyline;
14527
- exports.Polygon = Polygon;
14528
- exports.polygon = polygon;
14529
- exports.Rectangle = Rectangle;
14530
- exports.rectangle = rectangle;
14531
- exports.Map = Map;
14532
- exports.map = createMap;
15301
+ return 0;
15302
+ }
14533
15303
 
14534
- var oldL = window.L;
14535
- exports.noConflict = function() {
14536
- window.L = oldL;
14537
- return this;
14538
- };
15304
+ EventEmitter.prototype.eventNames = function eventNames() {
15305
+ return this._eventsCount > 0 ? Reflect.ownKeys(this._events) : [];
15306
+ };
14539
15307
 
14540
- // Always export us to window global (see #2364)
14541
- window.L = exports;
15308
+ // About 1.5x faster than the two-arg version of Array#splice().
15309
+ function spliceOne(list, index) {
15310
+ for (var i = index, k = i + 1, n = list.length; k < n; i += 1, k += 1)
15311
+ list[i] = list[k];
15312
+ list.pop();
15313
+ }
14542
15314
 
14543
- })));
14544
-
14545
- } (leafletSrc$1, leafletSrc$1.exports));
14546
- return leafletSrc$1.exports;
15315
+ function arrayClone(arr, i) {
15316
+ var copy = new Array(i);
15317
+ while (i--)
15318
+ copy[i] = arr[i];
15319
+ return copy;
14547
15320
  }
14548
15321
 
14549
- var leafletSrcExports = /*@__PURE__*/ requireLeafletSrc();
15322
+ function unwrapListeners(arr) {
15323
+ var ret = new Array(arr.length);
15324
+ for (var i = 0; i < ret.length; ++i) {
15325
+ ret[i] = arr[i].listener || arr[i];
15326
+ }
15327
+ return ret;
15328
+ }
14550
15329
 
14551
15330
  class AttributionControl extends leafletSrcExports.Control.Attribution {
14552
15331
  // options: AttributionControlOptions
@@ -14565,81 +15344,6 @@ var LeafletMapAdapter = (function () {
14565
15344
  }
14566
15345
  }
14567
15346
 
14568
- function createControl(control, options = {}, map) {
14569
- const C = leafletSrcExports.Control.extend({
14570
- onAdd() {
14571
- const element = document.createElement("div");
14572
- const content = control.onAdd(map);
14573
- element.classList.add("leaflet-control");
14574
- if (options.bar) {
14575
- element.classList.add("leaflet-bar");
14576
- }
14577
- if (options.addClass) {
14578
- element.classList.add(options.addClass);
14579
- }
14580
- if (!options.margin && !options.bar) {
14581
- element.style.marginBottom = "0px";
14582
- element.style.marginTop = "0px";
14583
- element.style.marginLeft = "0px";
14584
- element.style.marginRight = "0px";
14585
- }
14586
- if (content) {
14587
- element.appendChild(content);
14588
- }
14589
- leafletSrcExports.DomEvent.disableClickPropagation(element);
14590
- return element;
14591
- },
14592
- onRemove() {
14593
- control.onRemove();
14594
- }
14595
- });
14596
- return new C();
14597
- }
14598
-
14599
- function createButtonControl(options, map) {
14600
- const link = document.createElement("a");
14601
- const title = options.title || "";
14602
- link.href = "#";
14603
- link.title = title;
14604
- link.setAttribute("role", "button");
14605
- link.setAttribute("aria-label", title);
14606
- if (options.addClass) {
14607
- link.classList.add(options.addClass);
14608
- }
14609
- leafletSrcExports.DomEvent.disableClickPropagation(link);
14610
- leafletSrcExports.DomEvent.on(link, "click", leafletSrcExports.DomEvent.stop);
14611
- if (options.html instanceof HTMLElement) {
14612
- link.appendChild(options.html);
14613
- } else if (typeof options.html === "string") {
14614
- link.innerHTML = options.html;
14615
- }
14616
- const onClick = (e) => {
14617
- e.stopPropagation();
14618
- options.onClick();
14619
- };
14620
- return createControl(
14621
- {
14622
- onAdd() {
14623
- if (options.onClick !== void 0) {
14624
- link.addEventListener("click", onClick);
14625
- }
14626
- return link;
14627
- },
14628
- onRemove() {
14629
- const parent = link.parentNode;
14630
- if (parent) {
14631
- parent.removeChild(link);
14632
- }
14633
- if (options.onClick !== void 0) {
14634
- link.removeEventListener("click", onClick);
14635
- }
14636
- }
14637
- },
14638
- { bar: true },
14639
- map
14640
- );
14641
- }
14642
-
14643
15347
  function debounce(cb, wait = 10) {
14644
15348
  let timeoutId;
14645
15349
  function wrapper(...args) {
@@ -16354,6 +17058,7 @@ var LeafletMapAdapter = (function () {
16354
17058
  __publicField(this, "emitter", new EventEmitter());
16355
17059
  __publicField(this, "map");
16356
17060
  __publicField(this, "_resizeObserver");
17061
+ __publicField(this, "_controlContainer");
16357
17062
  __publicField(this, "_unselectCb", []);
16358
17063
  __publicField(this, "_universalEvents", [
16359
17064
  "move",
@@ -16392,6 +17097,7 @@ var LeafletMapAdapter = (function () {
16392
17097
  this._updateMinZoomForBounds(minZoom);
16393
17098
  this._watchSizeChangeToUpdateMinZoom();
16394
17099
  const defPane = this.map.createPane("order-0");
17100
+ this._controlContainer = new LeafletControlContainer(this.map);
16395
17101
  this.map._addUnselectCb = (def) => {
16396
17102
  this._addUnselectCb(def);
16397
17103
  };
@@ -16404,12 +17110,19 @@ var LeafletMapAdapter = (function () {
16404
17110
  if (this.map) {
16405
17111
  this.map.remove();
16406
17112
  }
17113
+ if (this._controlContainer) {
17114
+ this._controlContainer.detach();
17115
+ this._controlContainer = void 0;
17116
+ }
16407
17117
  this._stopWatchSizeChangeToUpdateMinZoom();
16408
17118
  }
16409
17119
  getContainer() {
16410
17120
  return this.map && this.map.getContainer();
16411
17121
  }
16412
17122
  getControlContainer() {
17123
+ if (this._controlContainer) {
17124
+ return this._controlContainer.getContainer();
17125
+ }
16413
17126
  const controlContainer = this.map && this.map._controlContainer;
16414
17127
  if (controlContainer) {
16415
17128
  return controlContainer;
@@ -16523,16 +17236,17 @@ var LeafletMapAdapter = (function () {
16523
17236
  createButtonControl(options) {
16524
17237
  return createButtonControl(options, this);
16525
17238
  }
16526
- addControl(control, position) {
16527
- control.options.position = position.replace("-", "");
16528
- if (this.map) {
16529
- this.map.addControl(control);
16530
- return control;
17239
+ createToggleControl(options) {
17240
+ return createToggleControl(options, this);
17241
+ }
17242
+ addControl(control, position, options) {
17243
+ if (this._controlContainer) {
17244
+ return this._controlContainer.addControl(control, position, options);
16531
17245
  }
16532
17246
  }
16533
17247
  removeControl(control) {
16534
- if (this.map) {
16535
- this.map.removeControl(control);
17248
+ if (this._controlContainer) {
17249
+ this._controlContainer.removeControl(control);
16536
17250
  }
16537
17251
  }
16538
17252
  removeLayer(layer) {