tileserver-gl 5.7.0-pre.0 → 5.7.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.
Files changed (36) hide show
  1. package/CHANGELOG.md +12 -1
  2. package/docs/config.rst +43 -2
  3. package/docs/usage.rst +2 -1
  4. package/package.json +33 -28
  5. package/public/resources/elevation-control.js +8 -4
  6. package/public/resources/maplibre-gl-inspect.mjs +2286 -0
  7. package/public/resources/maplibre-gl-inspect.mjs.map +1 -0
  8. package/public/resources/maplibre-gl-shared.mjs +6 -0
  9. package/public/resources/maplibre-gl-shared.mjs.map +1 -0
  10. package/public/resources/maplibre-gl-worker.mjs +10 -0
  11. package/public/resources/maplibre-gl-worker.mjs.map +1 -0
  12. package/public/resources/maplibre-gl.css +1 -1
  13. package/public/resources/maplibre-gl.mjs +819 -0
  14. package/public/resources/maplibre-gl.mjs.map +1 -0
  15. package/public/templates/data.tmpl +12 -6
  16. package/public/templates/viewer.tmpl +12 -8
  17. package/src/main.js +53 -7
  18. package/src/render_mode.js +38 -0
  19. package/src/serve_data.js +29 -11
  20. package/src/serve_rendered.js +317 -249
  21. package/src/server.js +10 -10
  22. package/src/utils.js +51 -0
  23. package/test/data_decorator.js +156 -0
  24. package/test/fixtures/data-decorator-async.js +17 -0
  25. package/test/fixtures/data-decorator.js +29 -0
  26. package/test/fixtures/visual/static-512px-path-alignment-2x.png +0 -0
  27. package/test/fixtures/visual/static-marker-low-zoom-large-viewport.png +0 -0
  28. package/test/render_mode.js +48 -0
  29. package/test/sparse.js +411 -0
  30. package/test/static.js +20 -0
  31. package/test/static_images.js +10 -0
  32. package/test/tiles_data_compression.js +145 -0
  33. package/public/resources/maplibre-gl-inspect.js +0 -2934
  34. package/public/resources/maplibre-gl-inspect.js.map +0 -1
  35. package/public/resources/maplibre-gl.js +0 -59
  36. package/public/resources/maplibre-gl.js.map +0 -1
@@ -1,2934 +0,0 @@
1
- (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
3
- typeof define === 'function' && define.amd ? define(factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.MaplibreInspect = factory());
5
- })(this, (function () { 'use strict';
6
-
7
- /******************************************************************************
8
- Copyright (c) Microsoft Corporation.
9
-
10
- Permission to use, copy, modify, and/or distribute this software for any
11
- purpose with or without fee is hereby granted.
12
-
13
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
14
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
15
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
16
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
17
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
18
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
19
- PERFORMANCE OF THIS SOFTWARE.
20
- ***************************************************************************** */
21
- /* global Reflect, Promise, SuppressedError, Symbol, Iterator */
22
-
23
-
24
- function __awaiter(thisArg, _arguments, P, generator) {
25
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
26
- return new (P || (P = Promise))(function (resolve, reject) {
27
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
28
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
29
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
30
- step((generator = generator.apply(thisArg, _arguments || [])).next());
31
- });
32
- }
33
-
34
- typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
35
- var e = new Error(message);
36
- return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
37
- };
38
-
39
- var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
40
-
41
- function getDefaultExportFromCjs (x) {
42
- return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
43
- }
44
-
45
- var lodash_isequal = {exports: {}};
46
-
47
- /**
48
- * Lodash (Custom Build) <https://lodash.com/>
49
- * Build: `lodash modularize exports="npm" -o ./`
50
- * Copyright JS Foundation and other contributors <https://js.foundation/>
51
- * Released under MIT license <https://lodash.com/license>
52
- * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
53
- * Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
54
- */
55
- lodash_isequal.exports;
56
-
57
- var hasRequiredLodash_isequal;
58
-
59
- function requireLodash_isequal () {
60
- if (hasRequiredLodash_isequal) return lodash_isequal.exports;
61
- hasRequiredLodash_isequal = 1;
62
- (function (module, exports$1) {
63
- /** Used as the size to enable large array optimizations. */
64
- var LARGE_ARRAY_SIZE = 200;
65
-
66
- /** Used to stand-in for `undefined` hash values. */
67
- var HASH_UNDEFINED = '__lodash_hash_undefined__';
68
-
69
- /** Used to compose bitmasks for value comparisons. */
70
- var COMPARE_PARTIAL_FLAG = 1,
71
- COMPARE_UNORDERED_FLAG = 2;
72
-
73
- /** Used as references for various `Number` constants. */
74
- var MAX_SAFE_INTEGER = 9007199254740991;
75
-
76
- /** `Object#toString` result references. */
77
- var argsTag = '[object Arguments]',
78
- arrayTag = '[object Array]',
79
- asyncTag = '[object AsyncFunction]',
80
- boolTag = '[object Boolean]',
81
- dateTag = '[object Date]',
82
- errorTag = '[object Error]',
83
- funcTag = '[object Function]',
84
- genTag = '[object GeneratorFunction]',
85
- mapTag = '[object Map]',
86
- numberTag = '[object Number]',
87
- nullTag = '[object Null]',
88
- objectTag = '[object Object]',
89
- promiseTag = '[object Promise]',
90
- proxyTag = '[object Proxy]',
91
- regexpTag = '[object RegExp]',
92
- setTag = '[object Set]',
93
- stringTag = '[object String]',
94
- symbolTag = '[object Symbol]',
95
- undefinedTag = '[object Undefined]',
96
- weakMapTag = '[object WeakMap]';
97
-
98
- var arrayBufferTag = '[object ArrayBuffer]',
99
- dataViewTag = '[object DataView]',
100
- float32Tag = '[object Float32Array]',
101
- float64Tag = '[object Float64Array]',
102
- int8Tag = '[object Int8Array]',
103
- int16Tag = '[object Int16Array]',
104
- int32Tag = '[object Int32Array]',
105
- uint8Tag = '[object Uint8Array]',
106
- uint8ClampedTag = '[object Uint8ClampedArray]',
107
- uint16Tag = '[object Uint16Array]',
108
- uint32Tag = '[object Uint32Array]';
109
-
110
- /**
111
- * Used to match `RegExp`
112
- * [syntax characters](http://ecma-international.org/ecma-262/7.0/#sec-patterns).
113
- */
114
- var reRegExpChar = /[\\^$.*+?()[\]{}|]/g;
115
-
116
- /** Used to detect host constructors (Safari). */
117
- var reIsHostCtor = /^\[object .+?Constructor\]$/;
118
-
119
- /** Used to detect unsigned integer values. */
120
- var reIsUint = /^(?:0|[1-9]\d*)$/;
121
-
122
- /** Used to identify `toStringTag` values of typed arrays. */
123
- var typedArrayTags = {};
124
- typedArrayTags[float32Tag] = typedArrayTags[float64Tag] =
125
- typedArrayTags[int8Tag] = typedArrayTags[int16Tag] =
126
- typedArrayTags[int32Tag] = typedArrayTags[uint8Tag] =
127
- typedArrayTags[uint8ClampedTag] = typedArrayTags[uint16Tag] =
128
- typedArrayTags[uint32Tag] = true;
129
- typedArrayTags[argsTag] = typedArrayTags[arrayTag] =
130
- typedArrayTags[arrayBufferTag] = typedArrayTags[boolTag] =
131
- typedArrayTags[dataViewTag] = typedArrayTags[dateTag] =
132
- typedArrayTags[errorTag] = typedArrayTags[funcTag] =
133
- typedArrayTags[mapTag] = typedArrayTags[numberTag] =
134
- typedArrayTags[objectTag] = typedArrayTags[regexpTag] =
135
- typedArrayTags[setTag] = typedArrayTags[stringTag] =
136
- typedArrayTags[weakMapTag] = false;
137
-
138
- /** Detect free variable `global` from Node.js. */
139
- var freeGlobal = typeof commonjsGlobal == 'object' && commonjsGlobal && commonjsGlobal.Object === Object && commonjsGlobal;
140
-
141
- /** Detect free variable `self`. */
142
- var freeSelf = typeof self == 'object' && self && self.Object === Object && self;
143
-
144
- /** Used as a reference to the global object. */
145
- var root = freeGlobal || freeSelf || Function('return this')();
146
-
147
- /** Detect free variable `exports`. */
148
- var freeExports = exports$1 && !exports$1.nodeType && exports$1;
149
-
150
- /** Detect free variable `module`. */
151
- var freeModule = freeExports && 'object' == 'object' && module && !module.nodeType && module;
152
-
153
- /** Detect the popular CommonJS extension `module.exports`. */
154
- var moduleExports = freeModule && freeModule.exports === freeExports;
155
-
156
- /** Detect free variable `process` from Node.js. */
157
- var freeProcess = moduleExports && freeGlobal.process;
158
-
159
- /** Used to access faster Node.js helpers. */
160
- var nodeUtil = (function() {
161
- try {
162
- return freeProcess && freeProcess.binding && freeProcess.binding('util');
163
- } catch (e) {}
164
- }());
165
-
166
- /* Node.js helper references. */
167
- var nodeIsTypedArray = nodeUtil && nodeUtil.isTypedArray;
168
-
169
- /**
170
- * A specialized version of `_.filter` for arrays without support for
171
- * iteratee shorthands.
172
- *
173
- * @private
174
- * @param {Array} [array] The array to iterate over.
175
- * @param {Function} predicate The function invoked per iteration.
176
- * @returns {Array} Returns the new filtered array.
177
- */
178
- function arrayFilter(array, predicate) {
179
- var index = -1,
180
- length = array == null ? 0 : array.length,
181
- resIndex = 0,
182
- result = [];
183
-
184
- while (++index < length) {
185
- var value = array[index];
186
- if (predicate(value, index, array)) {
187
- result[resIndex++] = value;
188
- }
189
- }
190
- return result;
191
- }
192
-
193
- /**
194
- * Appends the elements of `values` to `array`.
195
- *
196
- * @private
197
- * @param {Array} array The array to modify.
198
- * @param {Array} values The values to append.
199
- * @returns {Array} Returns `array`.
200
- */
201
- function arrayPush(array, values) {
202
- var index = -1,
203
- length = values.length,
204
- offset = array.length;
205
-
206
- while (++index < length) {
207
- array[offset + index] = values[index];
208
- }
209
- return array;
210
- }
211
-
212
- /**
213
- * A specialized version of `_.some` for arrays without support for iteratee
214
- * shorthands.
215
- *
216
- * @private
217
- * @param {Array} [array] The array to iterate over.
218
- * @param {Function} predicate The function invoked per iteration.
219
- * @returns {boolean} Returns `true` if any element passes the predicate check,
220
- * else `false`.
221
- */
222
- function arraySome(array, predicate) {
223
- var index = -1,
224
- length = array == null ? 0 : array.length;
225
-
226
- while (++index < length) {
227
- if (predicate(array[index], index, array)) {
228
- return true;
229
- }
230
- }
231
- return false;
232
- }
233
-
234
- /**
235
- * The base implementation of `_.times` without support for iteratee shorthands
236
- * or max array length checks.
237
- *
238
- * @private
239
- * @param {number} n The number of times to invoke `iteratee`.
240
- * @param {Function} iteratee The function invoked per iteration.
241
- * @returns {Array} Returns the array of results.
242
- */
243
- function baseTimes(n, iteratee) {
244
- var index = -1,
245
- result = Array(n);
246
-
247
- while (++index < n) {
248
- result[index] = iteratee(index);
249
- }
250
- return result;
251
- }
252
-
253
- /**
254
- * The base implementation of `_.unary` without support for storing metadata.
255
- *
256
- * @private
257
- * @param {Function} func The function to cap arguments for.
258
- * @returns {Function} Returns the new capped function.
259
- */
260
- function baseUnary(func) {
261
- return function(value) {
262
- return func(value);
263
- };
264
- }
265
-
266
- /**
267
- * Checks if a `cache` value for `key` exists.
268
- *
269
- * @private
270
- * @param {Object} cache The cache to query.
271
- * @param {string} key The key of the entry to check.
272
- * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
273
- */
274
- function cacheHas(cache, key) {
275
- return cache.has(key);
276
- }
277
-
278
- /**
279
- * Gets the value at `key` of `object`.
280
- *
281
- * @private
282
- * @param {Object} [object] The object to query.
283
- * @param {string} key The key of the property to get.
284
- * @returns {*} Returns the property value.
285
- */
286
- function getValue(object, key) {
287
- return object == null ? undefined : object[key];
288
- }
289
-
290
- /**
291
- * Converts `map` to its key-value pairs.
292
- *
293
- * @private
294
- * @param {Object} map The map to convert.
295
- * @returns {Array} Returns the key-value pairs.
296
- */
297
- function mapToArray(map) {
298
- var index = -1,
299
- result = Array(map.size);
300
-
301
- map.forEach(function(value, key) {
302
- result[++index] = [key, value];
303
- });
304
- return result;
305
- }
306
-
307
- /**
308
- * Creates a unary function that invokes `func` with its argument transformed.
309
- *
310
- * @private
311
- * @param {Function} func The function to wrap.
312
- * @param {Function} transform The argument transform.
313
- * @returns {Function} Returns the new function.
314
- */
315
- function overArg(func, transform) {
316
- return function(arg) {
317
- return func(transform(arg));
318
- };
319
- }
320
-
321
- /**
322
- * Converts `set` to an array of its values.
323
- *
324
- * @private
325
- * @param {Object} set The set to convert.
326
- * @returns {Array} Returns the values.
327
- */
328
- function setToArray(set) {
329
- var index = -1,
330
- result = Array(set.size);
331
-
332
- set.forEach(function(value) {
333
- result[++index] = value;
334
- });
335
- return result;
336
- }
337
-
338
- /** Used for built-in method references. */
339
- var arrayProto = Array.prototype,
340
- funcProto = Function.prototype,
341
- objectProto = Object.prototype;
342
-
343
- /** Used to detect overreaching core-js shims. */
344
- var coreJsData = root['__core-js_shared__'];
345
-
346
- /** Used to resolve the decompiled source of functions. */
347
- var funcToString = funcProto.toString;
348
-
349
- /** Used to check objects for own properties. */
350
- var hasOwnProperty = objectProto.hasOwnProperty;
351
-
352
- /** Used to detect methods masquerading as native. */
353
- var maskSrcKey = (function() {
354
- var uid = /[^.]+$/.exec(coreJsData && coreJsData.keys && coreJsData.keys.IE_PROTO || '');
355
- return uid ? ('Symbol(src)_1.' + uid) : '';
356
- }());
357
-
358
- /**
359
- * Used to resolve the
360
- * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring)
361
- * of values.
362
- */
363
- var nativeObjectToString = objectProto.toString;
364
-
365
- /** Used to detect if a method is native. */
366
- var reIsNative = RegExp('^' +
367
- funcToString.call(hasOwnProperty).replace(reRegExpChar, '\\$&')
368
- .replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$'
369
- );
370
-
371
- /** Built-in value references. */
372
- var Buffer = moduleExports ? root.Buffer : undefined,
373
- Symbol = root.Symbol,
374
- Uint8Array = root.Uint8Array,
375
- propertyIsEnumerable = objectProto.propertyIsEnumerable,
376
- splice = arrayProto.splice,
377
- symToStringTag = Symbol ? Symbol.toStringTag : undefined;
378
-
379
- /* Built-in method references for those with the same name as other `lodash` methods. */
380
- var nativeGetSymbols = Object.getOwnPropertySymbols,
381
- nativeIsBuffer = Buffer ? Buffer.isBuffer : undefined,
382
- nativeKeys = overArg(Object.keys, Object);
383
-
384
- /* Built-in method references that are verified to be native. */
385
- var DataView = getNative(root, 'DataView'),
386
- Map = getNative(root, 'Map'),
387
- Promise = getNative(root, 'Promise'),
388
- Set = getNative(root, 'Set'),
389
- WeakMap = getNative(root, 'WeakMap'),
390
- nativeCreate = getNative(Object, 'create');
391
-
392
- /** Used to detect maps, sets, and weakmaps. */
393
- var dataViewCtorString = toSource(DataView),
394
- mapCtorString = toSource(Map),
395
- promiseCtorString = toSource(Promise),
396
- setCtorString = toSource(Set),
397
- weakMapCtorString = toSource(WeakMap);
398
-
399
- /** Used to convert symbols to primitives and strings. */
400
- var symbolProto = Symbol ? Symbol.prototype : undefined,
401
- symbolValueOf = symbolProto ? symbolProto.valueOf : undefined;
402
-
403
- /**
404
- * Creates a hash object.
405
- *
406
- * @private
407
- * @constructor
408
- * @param {Array} [entries] The key-value pairs to cache.
409
- */
410
- function Hash(entries) {
411
- var index = -1,
412
- length = entries == null ? 0 : entries.length;
413
-
414
- this.clear();
415
- while (++index < length) {
416
- var entry = entries[index];
417
- this.set(entry[0], entry[1]);
418
- }
419
- }
420
-
421
- /**
422
- * Removes all key-value entries from the hash.
423
- *
424
- * @private
425
- * @name clear
426
- * @memberOf Hash
427
- */
428
- function hashClear() {
429
- this.__data__ = nativeCreate ? nativeCreate(null) : {};
430
- this.size = 0;
431
- }
432
-
433
- /**
434
- * Removes `key` and its value from the hash.
435
- *
436
- * @private
437
- * @name delete
438
- * @memberOf Hash
439
- * @param {Object} hash The hash to modify.
440
- * @param {string} key The key of the value to remove.
441
- * @returns {boolean} Returns `true` if the entry was removed, else `false`.
442
- */
443
- function hashDelete(key) {
444
- var result = this.has(key) && delete this.__data__[key];
445
- this.size -= result ? 1 : 0;
446
- return result;
447
- }
448
-
449
- /**
450
- * Gets the hash value for `key`.
451
- *
452
- * @private
453
- * @name get
454
- * @memberOf Hash
455
- * @param {string} key The key of the value to get.
456
- * @returns {*} Returns the entry value.
457
- */
458
- function hashGet(key) {
459
- var data = this.__data__;
460
- if (nativeCreate) {
461
- var result = data[key];
462
- return result === HASH_UNDEFINED ? undefined : result;
463
- }
464
- return hasOwnProperty.call(data, key) ? data[key] : undefined;
465
- }
466
-
467
- /**
468
- * Checks if a hash value for `key` exists.
469
- *
470
- * @private
471
- * @name has
472
- * @memberOf Hash
473
- * @param {string} key The key of the entry to check.
474
- * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
475
- */
476
- function hashHas(key) {
477
- var data = this.__data__;
478
- return nativeCreate ? (data[key] !== undefined) : hasOwnProperty.call(data, key);
479
- }
480
-
481
- /**
482
- * Sets the hash `key` to `value`.
483
- *
484
- * @private
485
- * @name set
486
- * @memberOf Hash
487
- * @param {string} key The key of the value to set.
488
- * @param {*} value The value to set.
489
- * @returns {Object} Returns the hash instance.
490
- */
491
- function hashSet(key, value) {
492
- var data = this.__data__;
493
- this.size += this.has(key) ? 0 : 1;
494
- data[key] = (nativeCreate && value === undefined) ? HASH_UNDEFINED : value;
495
- return this;
496
- }
497
-
498
- // Add methods to `Hash`.
499
- Hash.prototype.clear = hashClear;
500
- Hash.prototype['delete'] = hashDelete;
501
- Hash.prototype.get = hashGet;
502
- Hash.prototype.has = hashHas;
503
- Hash.prototype.set = hashSet;
504
-
505
- /**
506
- * Creates an list cache object.
507
- *
508
- * @private
509
- * @constructor
510
- * @param {Array} [entries] The key-value pairs to cache.
511
- */
512
- function ListCache(entries) {
513
- var index = -1,
514
- length = entries == null ? 0 : entries.length;
515
-
516
- this.clear();
517
- while (++index < length) {
518
- var entry = entries[index];
519
- this.set(entry[0], entry[1]);
520
- }
521
- }
522
-
523
- /**
524
- * Removes all key-value entries from the list cache.
525
- *
526
- * @private
527
- * @name clear
528
- * @memberOf ListCache
529
- */
530
- function listCacheClear() {
531
- this.__data__ = [];
532
- this.size = 0;
533
- }
534
-
535
- /**
536
- * Removes `key` and its value from the list cache.
537
- *
538
- * @private
539
- * @name delete
540
- * @memberOf ListCache
541
- * @param {string} key The key of the value to remove.
542
- * @returns {boolean} Returns `true` if the entry was removed, else `false`.
543
- */
544
- function listCacheDelete(key) {
545
- var data = this.__data__,
546
- index = assocIndexOf(data, key);
547
-
548
- if (index < 0) {
549
- return false;
550
- }
551
- var lastIndex = data.length - 1;
552
- if (index == lastIndex) {
553
- data.pop();
554
- } else {
555
- splice.call(data, index, 1);
556
- }
557
- --this.size;
558
- return true;
559
- }
560
-
561
- /**
562
- * Gets the list cache value for `key`.
563
- *
564
- * @private
565
- * @name get
566
- * @memberOf ListCache
567
- * @param {string} key The key of the value to get.
568
- * @returns {*} Returns the entry value.
569
- */
570
- function listCacheGet(key) {
571
- var data = this.__data__,
572
- index = assocIndexOf(data, key);
573
-
574
- return index < 0 ? undefined : data[index][1];
575
- }
576
-
577
- /**
578
- * Checks if a list cache value for `key` exists.
579
- *
580
- * @private
581
- * @name has
582
- * @memberOf ListCache
583
- * @param {string} key The key of the entry to check.
584
- * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
585
- */
586
- function listCacheHas(key) {
587
- return assocIndexOf(this.__data__, key) > -1;
588
- }
589
-
590
- /**
591
- * Sets the list cache `key` to `value`.
592
- *
593
- * @private
594
- * @name set
595
- * @memberOf ListCache
596
- * @param {string} key The key of the value to set.
597
- * @param {*} value The value to set.
598
- * @returns {Object} Returns the list cache instance.
599
- */
600
- function listCacheSet(key, value) {
601
- var data = this.__data__,
602
- index = assocIndexOf(data, key);
603
-
604
- if (index < 0) {
605
- ++this.size;
606
- data.push([key, value]);
607
- } else {
608
- data[index][1] = value;
609
- }
610
- return this;
611
- }
612
-
613
- // Add methods to `ListCache`.
614
- ListCache.prototype.clear = listCacheClear;
615
- ListCache.prototype['delete'] = listCacheDelete;
616
- ListCache.prototype.get = listCacheGet;
617
- ListCache.prototype.has = listCacheHas;
618
- ListCache.prototype.set = listCacheSet;
619
-
620
- /**
621
- * Creates a map cache object to store key-value pairs.
622
- *
623
- * @private
624
- * @constructor
625
- * @param {Array} [entries] The key-value pairs to cache.
626
- */
627
- function MapCache(entries) {
628
- var index = -1,
629
- length = entries == null ? 0 : entries.length;
630
-
631
- this.clear();
632
- while (++index < length) {
633
- var entry = entries[index];
634
- this.set(entry[0], entry[1]);
635
- }
636
- }
637
-
638
- /**
639
- * Removes all key-value entries from the map.
640
- *
641
- * @private
642
- * @name clear
643
- * @memberOf MapCache
644
- */
645
- function mapCacheClear() {
646
- this.size = 0;
647
- this.__data__ = {
648
- 'hash': new Hash,
649
- 'map': new (Map || ListCache),
650
- 'string': new Hash
651
- };
652
- }
653
-
654
- /**
655
- * Removes `key` and its value from the map.
656
- *
657
- * @private
658
- * @name delete
659
- * @memberOf MapCache
660
- * @param {string} key The key of the value to remove.
661
- * @returns {boolean} Returns `true` if the entry was removed, else `false`.
662
- */
663
- function mapCacheDelete(key) {
664
- var result = getMapData(this, key)['delete'](key);
665
- this.size -= result ? 1 : 0;
666
- return result;
667
- }
668
-
669
- /**
670
- * Gets the map value for `key`.
671
- *
672
- * @private
673
- * @name get
674
- * @memberOf MapCache
675
- * @param {string} key The key of the value to get.
676
- * @returns {*} Returns the entry value.
677
- */
678
- function mapCacheGet(key) {
679
- return getMapData(this, key).get(key);
680
- }
681
-
682
- /**
683
- * Checks if a map value for `key` exists.
684
- *
685
- * @private
686
- * @name has
687
- * @memberOf MapCache
688
- * @param {string} key The key of the entry to check.
689
- * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
690
- */
691
- function mapCacheHas(key) {
692
- return getMapData(this, key).has(key);
693
- }
694
-
695
- /**
696
- * Sets the map `key` to `value`.
697
- *
698
- * @private
699
- * @name set
700
- * @memberOf MapCache
701
- * @param {string} key The key of the value to set.
702
- * @param {*} value The value to set.
703
- * @returns {Object} Returns the map cache instance.
704
- */
705
- function mapCacheSet(key, value) {
706
- var data = getMapData(this, key),
707
- size = data.size;
708
-
709
- data.set(key, value);
710
- this.size += data.size == size ? 0 : 1;
711
- return this;
712
- }
713
-
714
- // Add methods to `MapCache`.
715
- MapCache.prototype.clear = mapCacheClear;
716
- MapCache.prototype['delete'] = mapCacheDelete;
717
- MapCache.prototype.get = mapCacheGet;
718
- MapCache.prototype.has = mapCacheHas;
719
- MapCache.prototype.set = mapCacheSet;
720
-
721
- /**
722
- *
723
- * Creates an array cache object to store unique values.
724
- *
725
- * @private
726
- * @constructor
727
- * @param {Array} [values] The values to cache.
728
- */
729
- function SetCache(values) {
730
- var index = -1,
731
- length = values == null ? 0 : values.length;
732
-
733
- this.__data__ = new MapCache;
734
- while (++index < length) {
735
- this.add(values[index]);
736
- }
737
- }
738
-
739
- /**
740
- * Adds `value` to the array cache.
741
- *
742
- * @private
743
- * @name add
744
- * @memberOf SetCache
745
- * @alias push
746
- * @param {*} value The value to cache.
747
- * @returns {Object} Returns the cache instance.
748
- */
749
- function setCacheAdd(value) {
750
- this.__data__.set(value, HASH_UNDEFINED);
751
- return this;
752
- }
753
-
754
- /**
755
- * Checks if `value` is in the array cache.
756
- *
757
- * @private
758
- * @name has
759
- * @memberOf SetCache
760
- * @param {*} value The value to search for.
761
- * @returns {number} Returns `true` if `value` is found, else `false`.
762
- */
763
- function setCacheHas(value) {
764
- return this.__data__.has(value);
765
- }
766
-
767
- // Add methods to `SetCache`.
768
- SetCache.prototype.add = SetCache.prototype.push = setCacheAdd;
769
- SetCache.prototype.has = setCacheHas;
770
-
771
- /**
772
- * Creates a stack cache object to store key-value pairs.
773
- *
774
- * @private
775
- * @constructor
776
- * @param {Array} [entries] The key-value pairs to cache.
777
- */
778
- function Stack(entries) {
779
- var data = this.__data__ = new ListCache(entries);
780
- this.size = data.size;
781
- }
782
-
783
- /**
784
- * Removes all key-value entries from the stack.
785
- *
786
- * @private
787
- * @name clear
788
- * @memberOf Stack
789
- */
790
- function stackClear() {
791
- this.__data__ = new ListCache;
792
- this.size = 0;
793
- }
794
-
795
- /**
796
- * Removes `key` and its value from the stack.
797
- *
798
- * @private
799
- * @name delete
800
- * @memberOf Stack
801
- * @param {string} key The key of the value to remove.
802
- * @returns {boolean} Returns `true` if the entry was removed, else `false`.
803
- */
804
- function stackDelete(key) {
805
- var data = this.__data__,
806
- result = data['delete'](key);
807
-
808
- this.size = data.size;
809
- return result;
810
- }
811
-
812
- /**
813
- * Gets the stack value for `key`.
814
- *
815
- * @private
816
- * @name get
817
- * @memberOf Stack
818
- * @param {string} key The key of the value to get.
819
- * @returns {*} Returns the entry value.
820
- */
821
- function stackGet(key) {
822
- return this.__data__.get(key);
823
- }
824
-
825
- /**
826
- * Checks if a stack value for `key` exists.
827
- *
828
- * @private
829
- * @name has
830
- * @memberOf Stack
831
- * @param {string} key The key of the entry to check.
832
- * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
833
- */
834
- function stackHas(key) {
835
- return this.__data__.has(key);
836
- }
837
-
838
- /**
839
- * Sets the stack `key` to `value`.
840
- *
841
- * @private
842
- * @name set
843
- * @memberOf Stack
844
- * @param {string} key The key of the value to set.
845
- * @param {*} value The value to set.
846
- * @returns {Object} Returns the stack cache instance.
847
- */
848
- function stackSet(key, value) {
849
- var data = this.__data__;
850
- if (data instanceof ListCache) {
851
- var pairs = data.__data__;
852
- if (!Map || (pairs.length < LARGE_ARRAY_SIZE - 1)) {
853
- pairs.push([key, value]);
854
- this.size = ++data.size;
855
- return this;
856
- }
857
- data = this.__data__ = new MapCache(pairs);
858
- }
859
- data.set(key, value);
860
- this.size = data.size;
861
- return this;
862
- }
863
-
864
- // Add methods to `Stack`.
865
- Stack.prototype.clear = stackClear;
866
- Stack.prototype['delete'] = stackDelete;
867
- Stack.prototype.get = stackGet;
868
- Stack.prototype.has = stackHas;
869
- Stack.prototype.set = stackSet;
870
-
871
- /**
872
- * Creates an array of the enumerable property names of the array-like `value`.
873
- *
874
- * @private
875
- * @param {*} value The value to query.
876
- * @param {boolean} inherited Specify returning inherited property names.
877
- * @returns {Array} Returns the array of property names.
878
- */
879
- function arrayLikeKeys(value, inherited) {
880
- var isArr = isArray(value),
881
- isArg = !isArr && isArguments(value),
882
- isBuff = !isArr && !isArg && isBuffer(value),
883
- isType = !isArr && !isArg && !isBuff && isTypedArray(value),
884
- skipIndexes = isArr || isArg || isBuff || isType,
885
- result = skipIndexes ? baseTimes(value.length, String) : [],
886
- length = result.length;
887
-
888
- for (var key in value) {
889
- if ((hasOwnProperty.call(value, key)) &&
890
- !(skipIndexes && (
891
- // Safari 9 has enumerable `arguments.length` in strict mode.
892
- key == 'length' ||
893
- // Node.js 0.10 has enumerable non-index properties on buffers.
894
- (isBuff && (key == 'offset' || key == 'parent')) ||
895
- // PhantomJS 2 has enumerable non-index properties on typed arrays.
896
- (isType && (key == 'buffer' || key == 'byteLength' || key == 'byteOffset')) ||
897
- // Skip index properties.
898
- isIndex(key, length)
899
- ))) {
900
- result.push(key);
901
- }
902
- }
903
- return result;
904
- }
905
-
906
- /**
907
- * Gets the index at which the `key` is found in `array` of key-value pairs.
908
- *
909
- * @private
910
- * @param {Array} array The array to inspect.
911
- * @param {*} key The key to search for.
912
- * @returns {number} Returns the index of the matched value, else `-1`.
913
- */
914
- function assocIndexOf(array, key) {
915
- var length = array.length;
916
- while (length--) {
917
- if (eq(array[length][0], key)) {
918
- return length;
919
- }
920
- }
921
- return -1;
922
- }
923
-
924
- /**
925
- * The base implementation of `getAllKeys` and `getAllKeysIn` which uses
926
- * `keysFunc` and `symbolsFunc` to get the enumerable property names and
927
- * symbols of `object`.
928
- *
929
- * @private
930
- * @param {Object} object The object to query.
931
- * @param {Function} keysFunc The function to get the keys of `object`.
932
- * @param {Function} symbolsFunc The function to get the symbols of `object`.
933
- * @returns {Array} Returns the array of property names and symbols.
934
- */
935
- function baseGetAllKeys(object, keysFunc, symbolsFunc) {
936
- var result = keysFunc(object);
937
- return isArray(object) ? result : arrayPush(result, symbolsFunc(object));
938
- }
939
-
940
- /**
941
- * The base implementation of `getTag` without fallbacks for buggy environments.
942
- *
943
- * @private
944
- * @param {*} value The value to query.
945
- * @returns {string} Returns the `toStringTag`.
946
- */
947
- function baseGetTag(value) {
948
- if (value == null) {
949
- return value === undefined ? undefinedTag : nullTag;
950
- }
951
- return (symToStringTag && symToStringTag in Object(value))
952
- ? getRawTag(value)
953
- : objectToString(value);
954
- }
955
-
956
- /**
957
- * The base implementation of `_.isArguments`.
958
- *
959
- * @private
960
- * @param {*} value The value to check.
961
- * @returns {boolean} Returns `true` if `value` is an `arguments` object,
962
- */
963
- function baseIsArguments(value) {
964
- return isObjectLike(value) && baseGetTag(value) == argsTag;
965
- }
966
-
967
- /**
968
- * The base implementation of `_.isEqual` which supports partial comparisons
969
- * and tracks traversed objects.
970
- *
971
- * @private
972
- * @param {*} value The value to compare.
973
- * @param {*} other The other value to compare.
974
- * @param {boolean} bitmask The bitmask flags.
975
- * 1 - Unordered comparison
976
- * 2 - Partial comparison
977
- * @param {Function} [customizer] The function to customize comparisons.
978
- * @param {Object} [stack] Tracks traversed `value` and `other` objects.
979
- * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
980
- */
981
- function baseIsEqual(value, other, bitmask, customizer, stack) {
982
- if (value === other) {
983
- return true;
984
- }
985
- if (value == null || other == null || (!isObjectLike(value) && !isObjectLike(other))) {
986
- return value !== value && other !== other;
987
- }
988
- return baseIsEqualDeep(value, other, bitmask, customizer, baseIsEqual, stack);
989
- }
990
-
991
- /**
992
- * A specialized version of `baseIsEqual` for arrays and objects which performs
993
- * deep comparisons and tracks traversed objects enabling objects with circular
994
- * references to be compared.
995
- *
996
- * @private
997
- * @param {Object} object The object to compare.
998
- * @param {Object} other The other object to compare.
999
- * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details.
1000
- * @param {Function} customizer The function to customize comparisons.
1001
- * @param {Function} equalFunc The function to determine equivalents of values.
1002
- * @param {Object} [stack] Tracks traversed `object` and `other` objects.
1003
- * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
1004
- */
1005
- function baseIsEqualDeep(object, other, bitmask, customizer, equalFunc, stack) {
1006
- var objIsArr = isArray(object),
1007
- othIsArr = isArray(other),
1008
- objTag = objIsArr ? arrayTag : getTag(object),
1009
- othTag = othIsArr ? arrayTag : getTag(other);
1010
-
1011
- objTag = objTag == argsTag ? objectTag : objTag;
1012
- othTag = othTag == argsTag ? objectTag : othTag;
1013
-
1014
- var objIsObj = objTag == objectTag,
1015
- othIsObj = othTag == objectTag,
1016
- isSameTag = objTag == othTag;
1017
-
1018
- if (isSameTag && isBuffer(object)) {
1019
- if (!isBuffer(other)) {
1020
- return false;
1021
- }
1022
- objIsArr = true;
1023
- objIsObj = false;
1024
- }
1025
- if (isSameTag && !objIsObj) {
1026
- stack || (stack = new Stack);
1027
- return (objIsArr || isTypedArray(object))
1028
- ? equalArrays(object, other, bitmask, customizer, equalFunc, stack)
1029
- : equalByTag(object, other, objTag, bitmask, customizer, equalFunc, stack);
1030
- }
1031
- if (!(bitmask & COMPARE_PARTIAL_FLAG)) {
1032
- var objIsWrapped = objIsObj && hasOwnProperty.call(object, '__wrapped__'),
1033
- othIsWrapped = othIsObj && hasOwnProperty.call(other, '__wrapped__');
1034
-
1035
- if (objIsWrapped || othIsWrapped) {
1036
- var objUnwrapped = objIsWrapped ? object.value() : object,
1037
- othUnwrapped = othIsWrapped ? other.value() : other;
1038
-
1039
- stack || (stack = new Stack);
1040
- return equalFunc(objUnwrapped, othUnwrapped, bitmask, customizer, stack);
1041
- }
1042
- }
1043
- if (!isSameTag) {
1044
- return false;
1045
- }
1046
- stack || (stack = new Stack);
1047
- return equalObjects(object, other, bitmask, customizer, equalFunc, stack);
1048
- }
1049
-
1050
- /**
1051
- * The base implementation of `_.isNative` without bad shim checks.
1052
- *
1053
- * @private
1054
- * @param {*} value The value to check.
1055
- * @returns {boolean} Returns `true` if `value` is a native function,
1056
- * else `false`.
1057
- */
1058
- function baseIsNative(value) {
1059
- if (!isObject(value) || isMasked(value)) {
1060
- return false;
1061
- }
1062
- var pattern = isFunction(value) ? reIsNative : reIsHostCtor;
1063
- return pattern.test(toSource(value));
1064
- }
1065
-
1066
- /**
1067
- * The base implementation of `_.isTypedArray` without Node.js optimizations.
1068
- *
1069
- * @private
1070
- * @param {*} value The value to check.
1071
- * @returns {boolean} Returns `true` if `value` is a typed array, else `false`.
1072
- */
1073
- function baseIsTypedArray(value) {
1074
- return isObjectLike(value) &&
1075
- isLength(value.length) && !!typedArrayTags[baseGetTag(value)];
1076
- }
1077
-
1078
- /**
1079
- * The base implementation of `_.keys` which doesn't treat sparse arrays as dense.
1080
- *
1081
- * @private
1082
- * @param {Object} object The object to query.
1083
- * @returns {Array} Returns the array of property names.
1084
- */
1085
- function baseKeys(object) {
1086
- if (!isPrototype(object)) {
1087
- return nativeKeys(object);
1088
- }
1089
- var result = [];
1090
- for (var key in Object(object)) {
1091
- if (hasOwnProperty.call(object, key) && key != 'constructor') {
1092
- result.push(key);
1093
- }
1094
- }
1095
- return result;
1096
- }
1097
-
1098
- /**
1099
- * A specialized version of `baseIsEqualDeep` for arrays with support for
1100
- * partial deep comparisons.
1101
- *
1102
- * @private
1103
- * @param {Array} array The array to compare.
1104
- * @param {Array} other The other array to compare.
1105
- * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details.
1106
- * @param {Function} customizer The function to customize comparisons.
1107
- * @param {Function} equalFunc The function to determine equivalents of values.
1108
- * @param {Object} stack Tracks traversed `array` and `other` objects.
1109
- * @returns {boolean} Returns `true` if the arrays are equivalent, else `false`.
1110
- */
1111
- function equalArrays(array, other, bitmask, customizer, equalFunc, stack) {
1112
- var isPartial = bitmask & COMPARE_PARTIAL_FLAG,
1113
- arrLength = array.length,
1114
- othLength = other.length;
1115
-
1116
- if (arrLength != othLength && !(isPartial && othLength > arrLength)) {
1117
- return false;
1118
- }
1119
- // Assume cyclic values are equal.
1120
- var stacked = stack.get(array);
1121
- if (stacked && stack.get(other)) {
1122
- return stacked == other;
1123
- }
1124
- var index = -1,
1125
- result = true,
1126
- seen = (bitmask & COMPARE_UNORDERED_FLAG) ? new SetCache : undefined;
1127
-
1128
- stack.set(array, other);
1129
- stack.set(other, array);
1130
-
1131
- // Ignore non-index properties.
1132
- while (++index < arrLength) {
1133
- var arrValue = array[index],
1134
- othValue = other[index];
1135
-
1136
- if (customizer) {
1137
- var compared = isPartial
1138
- ? customizer(othValue, arrValue, index, other, array, stack)
1139
- : customizer(arrValue, othValue, index, array, other, stack);
1140
- }
1141
- if (compared !== undefined) {
1142
- if (compared) {
1143
- continue;
1144
- }
1145
- result = false;
1146
- break;
1147
- }
1148
- // Recursively compare arrays (susceptible to call stack limits).
1149
- if (seen) {
1150
- if (!arraySome(other, function(othValue, othIndex) {
1151
- if (!cacheHas(seen, othIndex) &&
1152
- (arrValue === othValue || equalFunc(arrValue, othValue, bitmask, customizer, stack))) {
1153
- return seen.push(othIndex);
1154
- }
1155
- })) {
1156
- result = false;
1157
- break;
1158
- }
1159
- } else if (!(
1160
- arrValue === othValue ||
1161
- equalFunc(arrValue, othValue, bitmask, customizer, stack)
1162
- )) {
1163
- result = false;
1164
- break;
1165
- }
1166
- }
1167
- stack['delete'](array);
1168
- stack['delete'](other);
1169
- return result;
1170
- }
1171
-
1172
- /**
1173
- * A specialized version of `baseIsEqualDeep` for comparing objects of
1174
- * the same `toStringTag`.
1175
- *
1176
- * **Note:** This function only supports comparing values with tags of
1177
- * `Boolean`, `Date`, `Error`, `Number`, `RegExp`, or `String`.
1178
- *
1179
- * @private
1180
- * @param {Object} object The object to compare.
1181
- * @param {Object} other The other object to compare.
1182
- * @param {string} tag The `toStringTag` of the objects to compare.
1183
- * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details.
1184
- * @param {Function} customizer The function to customize comparisons.
1185
- * @param {Function} equalFunc The function to determine equivalents of values.
1186
- * @param {Object} stack Tracks traversed `object` and `other` objects.
1187
- * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
1188
- */
1189
- function equalByTag(object, other, tag, bitmask, customizer, equalFunc, stack) {
1190
- switch (tag) {
1191
- case dataViewTag:
1192
- if ((object.byteLength != other.byteLength) ||
1193
- (object.byteOffset != other.byteOffset)) {
1194
- return false;
1195
- }
1196
- object = object.buffer;
1197
- other = other.buffer;
1198
-
1199
- case arrayBufferTag:
1200
- if ((object.byteLength != other.byteLength) ||
1201
- !equalFunc(new Uint8Array(object), new Uint8Array(other))) {
1202
- return false;
1203
- }
1204
- return true;
1205
-
1206
- case boolTag:
1207
- case dateTag:
1208
- case numberTag:
1209
- // Coerce booleans to `1` or `0` and dates to milliseconds.
1210
- // Invalid dates are coerced to `NaN`.
1211
- return eq(+object, +other);
1212
-
1213
- case errorTag:
1214
- return object.name == other.name && object.message == other.message;
1215
-
1216
- case regexpTag:
1217
- case stringTag:
1218
- // Coerce regexes to strings and treat strings, primitives and objects,
1219
- // as equal. See http://www.ecma-international.org/ecma-262/7.0/#sec-regexp.prototype.tostring
1220
- // for more details.
1221
- return object == (other + '');
1222
-
1223
- case mapTag:
1224
- var convert = mapToArray;
1225
-
1226
- case setTag:
1227
- var isPartial = bitmask & COMPARE_PARTIAL_FLAG;
1228
- convert || (convert = setToArray);
1229
-
1230
- if (object.size != other.size && !isPartial) {
1231
- return false;
1232
- }
1233
- // Assume cyclic values are equal.
1234
- var stacked = stack.get(object);
1235
- if (stacked) {
1236
- return stacked == other;
1237
- }
1238
- bitmask |= COMPARE_UNORDERED_FLAG;
1239
-
1240
- // Recursively compare objects (susceptible to call stack limits).
1241
- stack.set(object, other);
1242
- var result = equalArrays(convert(object), convert(other), bitmask, customizer, equalFunc, stack);
1243
- stack['delete'](object);
1244
- return result;
1245
-
1246
- case symbolTag:
1247
- if (symbolValueOf) {
1248
- return symbolValueOf.call(object) == symbolValueOf.call(other);
1249
- }
1250
- }
1251
- return false;
1252
- }
1253
-
1254
- /**
1255
- * A specialized version of `baseIsEqualDeep` for objects with support for
1256
- * partial deep comparisons.
1257
- *
1258
- * @private
1259
- * @param {Object} object The object to compare.
1260
- * @param {Object} other The other object to compare.
1261
- * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details.
1262
- * @param {Function} customizer The function to customize comparisons.
1263
- * @param {Function} equalFunc The function to determine equivalents of values.
1264
- * @param {Object} stack Tracks traversed `object` and `other` objects.
1265
- * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
1266
- */
1267
- function equalObjects(object, other, bitmask, customizer, equalFunc, stack) {
1268
- var isPartial = bitmask & COMPARE_PARTIAL_FLAG,
1269
- objProps = getAllKeys(object),
1270
- objLength = objProps.length,
1271
- othProps = getAllKeys(other),
1272
- othLength = othProps.length;
1273
-
1274
- if (objLength != othLength && !isPartial) {
1275
- return false;
1276
- }
1277
- var index = objLength;
1278
- while (index--) {
1279
- var key = objProps[index];
1280
- if (!(isPartial ? key in other : hasOwnProperty.call(other, key))) {
1281
- return false;
1282
- }
1283
- }
1284
- // Assume cyclic values are equal.
1285
- var stacked = stack.get(object);
1286
- if (stacked && stack.get(other)) {
1287
- return stacked == other;
1288
- }
1289
- var result = true;
1290
- stack.set(object, other);
1291
- stack.set(other, object);
1292
-
1293
- var skipCtor = isPartial;
1294
- while (++index < objLength) {
1295
- key = objProps[index];
1296
- var objValue = object[key],
1297
- othValue = other[key];
1298
-
1299
- if (customizer) {
1300
- var compared = isPartial
1301
- ? customizer(othValue, objValue, key, other, object, stack)
1302
- : customizer(objValue, othValue, key, object, other, stack);
1303
- }
1304
- // Recursively compare objects (susceptible to call stack limits).
1305
- if (!(compared === undefined
1306
- ? (objValue === othValue || equalFunc(objValue, othValue, bitmask, customizer, stack))
1307
- : compared
1308
- )) {
1309
- result = false;
1310
- break;
1311
- }
1312
- skipCtor || (skipCtor = key == 'constructor');
1313
- }
1314
- if (result && !skipCtor) {
1315
- var objCtor = object.constructor,
1316
- othCtor = other.constructor;
1317
-
1318
- // Non `Object` object instances with different constructors are not equal.
1319
- if (objCtor != othCtor &&
1320
- ('constructor' in object && 'constructor' in other) &&
1321
- !(typeof objCtor == 'function' && objCtor instanceof objCtor &&
1322
- typeof othCtor == 'function' && othCtor instanceof othCtor)) {
1323
- result = false;
1324
- }
1325
- }
1326
- stack['delete'](object);
1327
- stack['delete'](other);
1328
- return result;
1329
- }
1330
-
1331
- /**
1332
- * Creates an array of own enumerable property names and symbols of `object`.
1333
- *
1334
- * @private
1335
- * @param {Object} object The object to query.
1336
- * @returns {Array} Returns the array of property names and symbols.
1337
- */
1338
- function getAllKeys(object) {
1339
- return baseGetAllKeys(object, keys, getSymbols);
1340
- }
1341
-
1342
- /**
1343
- * Gets the data for `map`.
1344
- *
1345
- * @private
1346
- * @param {Object} map The map to query.
1347
- * @param {string} key The reference key.
1348
- * @returns {*} Returns the map data.
1349
- */
1350
- function getMapData(map, key) {
1351
- var data = map.__data__;
1352
- return isKeyable(key)
1353
- ? data[typeof key == 'string' ? 'string' : 'hash']
1354
- : data.map;
1355
- }
1356
-
1357
- /**
1358
- * Gets the native function at `key` of `object`.
1359
- *
1360
- * @private
1361
- * @param {Object} object The object to query.
1362
- * @param {string} key The key of the method to get.
1363
- * @returns {*} Returns the function if it's native, else `undefined`.
1364
- */
1365
- function getNative(object, key) {
1366
- var value = getValue(object, key);
1367
- return baseIsNative(value) ? value : undefined;
1368
- }
1369
-
1370
- /**
1371
- * A specialized version of `baseGetTag` which ignores `Symbol.toStringTag` values.
1372
- *
1373
- * @private
1374
- * @param {*} value The value to query.
1375
- * @returns {string} Returns the raw `toStringTag`.
1376
- */
1377
- function getRawTag(value) {
1378
- var isOwn = hasOwnProperty.call(value, symToStringTag),
1379
- tag = value[symToStringTag];
1380
-
1381
- try {
1382
- value[symToStringTag] = undefined;
1383
- var unmasked = true;
1384
- } catch (e) {}
1385
-
1386
- var result = nativeObjectToString.call(value);
1387
- if (unmasked) {
1388
- if (isOwn) {
1389
- value[symToStringTag] = tag;
1390
- } else {
1391
- delete value[symToStringTag];
1392
- }
1393
- }
1394
- return result;
1395
- }
1396
-
1397
- /**
1398
- * Creates an array of the own enumerable symbols of `object`.
1399
- *
1400
- * @private
1401
- * @param {Object} object The object to query.
1402
- * @returns {Array} Returns the array of symbols.
1403
- */
1404
- var getSymbols = !nativeGetSymbols ? stubArray : function(object) {
1405
- if (object == null) {
1406
- return [];
1407
- }
1408
- object = Object(object);
1409
- return arrayFilter(nativeGetSymbols(object), function(symbol) {
1410
- return propertyIsEnumerable.call(object, symbol);
1411
- });
1412
- };
1413
-
1414
- /**
1415
- * Gets the `toStringTag` of `value`.
1416
- *
1417
- * @private
1418
- * @param {*} value The value to query.
1419
- * @returns {string} Returns the `toStringTag`.
1420
- */
1421
- var getTag = baseGetTag;
1422
-
1423
- // Fallback for data views, maps, sets, and weak maps in IE 11 and promises in Node.js < 6.
1424
- if ((DataView && getTag(new DataView(new ArrayBuffer(1))) != dataViewTag) ||
1425
- (Map && getTag(new Map) != mapTag) ||
1426
- (Promise && getTag(Promise.resolve()) != promiseTag) ||
1427
- (Set && getTag(new Set) != setTag) ||
1428
- (WeakMap && getTag(new WeakMap) != weakMapTag)) {
1429
- getTag = function(value) {
1430
- var result = baseGetTag(value),
1431
- Ctor = result == objectTag ? value.constructor : undefined,
1432
- ctorString = Ctor ? toSource(Ctor) : '';
1433
-
1434
- if (ctorString) {
1435
- switch (ctorString) {
1436
- case dataViewCtorString: return dataViewTag;
1437
- case mapCtorString: return mapTag;
1438
- case promiseCtorString: return promiseTag;
1439
- case setCtorString: return setTag;
1440
- case weakMapCtorString: return weakMapTag;
1441
- }
1442
- }
1443
- return result;
1444
- };
1445
- }
1446
-
1447
- /**
1448
- * Checks if `value` is a valid array-like index.
1449
- *
1450
- * @private
1451
- * @param {*} value The value to check.
1452
- * @param {number} [length=MAX_SAFE_INTEGER] The upper bounds of a valid index.
1453
- * @returns {boolean} Returns `true` if `value` is a valid index, else `false`.
1454
- */
1455
- function isIndex(value, length) {
1456
- length = length == null ? MAX_SAFE_INTEGER : length;
1457
- return !!length &&
1458
- (typeof value == 'number' || reIsUint.test(value)) &&
1459
- (value > -1 && value % 1 == 0 && value < length);
1460
- }
1461
-
1462
- /**
1463
- * Checks if `value` is suitable for use as unique object key.
1464
- *
1465
- * @private
1466
- * @param {*} value The value to check.
1467
- * @returns {boolean} Returns `true` if `value` is suitable, else `false`.
1468
- */
1469
- function isKeyable(value) {
1470
- var type = typeof value;
1471
- return (type == 'string' || type == 'number' || type == 'symbol' || type == 'boolean')
1472
- ? (value !== '__proto__')
1473
- : (value === null);
1474
- }
1475
-
1476
- /**
1477
- * Checks if `func` has its source masked.
1478
- *
1479
- * @private
1480
- * @param {Function} func The function to check.
1481
- * @returns {boolean} Returns `true` if `func` is masked, else `false`.
1482
- */
1483
- function isMasked(func) {
1484
- return !!maskSrcKey && (maskSrcKey in func);
1485
- }
1486
-
1487
- /**
1488
- * Checks if `value` is likely a prototype object.
1489
- *
1490
- * @private
1491
- * @param {*} value The value to check.
1492
- * @returns {boolean} Returns `true` if `value` is a prototype, else `false`.
1493
- */
1494
- function isPrototype(value) {
1495
- var Ctor = value && value.constructor,
1496
- proto = (typeof Ctor == 'function' && Ctor.prototype) || objectProto;
1497
-
1498
- return value === proto;
1499
- }
1500
-
1501
- /**
1502
- * Converts `value` to a string using `Object.prototype.toString`.
1503
- *
1504
- * @private
1505
- * @param {*} value The value to convert.
1506
- * @returns {string} Returns the converted string.
1507
- */
1508
- function objectToString(value) {
1509
- return nativeObjectToString.call(value);
1510
- }
1511
-
1512
- /**
1513
- * Converts `func` to its source code.
1514
- *
1515
- * @private
1516
- * @param {Function} func The function to convert.
1517
- * @returns {string} Returns the source code.
1518
- */
1519
- function toSource(func) {
1520
- if (func != null) {
1521
- try {
1522
- return funcToString.call(func);
1523
- } catch (e) {}
1524
- try {
1525
- return (func + '');
1526
- } catch (e) {}
1527
- }
1528
- return '';
1529
- }
1530
-
1531
- /**
1532
- * Performs a
1533
- * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
1534
- * comparison between two values to determine if they are equivalent.
1535
- *
1536
- * @static
1537
- * @memberOf _
1538
- * @since 4.0.0
1539
- * @category Lang
1540
- * @param {*} value The value to compare.
1541
- * @param {*} other The other value to compare.
1542
- * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
1543
- * @example
1544
- *
1545
- * var object = { 'a': 1 };
1546
- * var other = { 'a': 1 };
1547
- *
1548
- * _.eq(object, object);
1549
- * // => true
1550
- *
1551
- * _.eq(object, other);
1552
- * // => false
1553
- *
1554
- * _.eq('a', 'a');
1555
- * // => true
1556
- *
1557
- * _.eq('a', Object('a'));
1558
- * // => false
1559
- *
1560
- * _.eq(NaN, NaN);
1561
- * // => true
1562
- */
1563
- function eq(value, other) {
1564
- return value === other || (value !== value && other !== other);
1565
- }
1566
-
1567
- /**
1568
- * Checks if `value` is likely an `arguments` object.
1569
- *
1570
- * @static
1571
- * @memberOf _
1572
- * @since 0.1.0
1573
- * @category Lang
1574
- * @param {*} value The value to check.
1575
- * @returns {boolean} Returns `true` if `value` is an `arguments` object,
1576
- * else `false`.
1577
- * @example
1578
- *
1579
- * _.isArguments(function() { return arguments; }());
1580
- * // => true
1581
- *
1582
- * _.isArguments([1, 2, 3]);
1583
- * // => false
1584
- */
1585
- var isArguments = baseIsArguments(function() { return arguments; }()) ? baseIsArguments : function(value) {
1586
- return isObjectLike(value) && hasOwnProperty.call(value, 'callee') &&
1587
- !propertyIsEnumerable.call(value, 'callee');
1588
- };
1589
-
1590
- /**
1591
- * Checks if `value` is classified as an `Array` object.
1592
- *
1593
- * @static
1594
- * @memberOf _
1595
- * @since 0.1.0
1596
- * @category Lang
1597
- * @param {*} value The value to check.
1598
- * @returns {boolean} Returns `true` if `value` is an array, else `false`.
1599
- * @example
1600
- *
1601
- * _.isArray([1, 2, 3]);
1602
- * // => true
1603
- *
1604
- * _.isArray(document.body.children);
1605
- * // => false
1606
- *
1607
- * _.isArray('abc');
1608
- * // => false
1609
- *
1610
- * _.isArray(_.noop);
1611
- * // => false
1612
- */
1613
- var isArray = Array.isArray;
1614
-
1615
- /**
1616
- * Checks if `value` is array-like. A value is considered array-like if it's
1617
- * not a function and has a `value.length` that's an integer greater than or
1618
- * equal to `0` and less than or equal to `Number.MAX_SAFE_INTEGER`.
1619
- *
1620
- * @static
1621
- * @memberOf _
1622
- * @since 4.0.0
1623
- * @category Lang
1624
- * @param {*} value The value to check.
1625
- * @returns {boolean} Returns `true` if `value` is array-like, else `false`.
1626
- * @example
1627
- *
1628
- * _.isArrayLike([1, 2, 3]);
1629
- * // => true
1630
- *
1631
- * _.isArrayLike(document.body.children);
1632
- * // => true
1633
- *
1634
- * _.isArrayLike('abc');
1635
- * // => true
1636
- *
1637
- * _.isArrayLike(_.noop);
1638
- * // => false
1639
- */
1640
- function isArrayLike(value) {
1641
- return value != null && isLength(value.length) && !isFunction(value);
1642
- }
1643
-
1644
- /**
1645
- * Checks if `value` is a buffer.
1646
- *
1647
- * @static
1648
- * @memberOf _
1649
- * @since 4.3.0
1650
- * @category Lang
1651
- * @param {*} value The value to check.
1652
- * @returns {boolean} Returns `true` if `value` is a buffer, else `false`.
1653
- * @example
1654
- *
1655
- * _.isBuffer(new Buffer(2));
1656
- * // => true
1657
- *
1658
- * _.isBuffer(new Uint8Array(2));
1659
- * // => false
1660
- */
1661
- var isBuffer = nativeIsBuffer || stubFalse;
1662
-
1663
- /**
1664
- * Performs a deep comparison between two values to determine if they are
1665
- * equivalent.
1666
- *
1667
- * **Note:** This method supports comparing arrays, array buffers, booleans,
1668
- * date objects, error objects, maps, numbers, `Object` objects, regexes,
1669
- * sets, strings, symbols, and typed arrays. `Object` objects are compared
1670
- * by their own, not inherited, enumerable properties. Functions and DOM
1671
- * nodes are compared by strict equality, i.e. `===`.
1672
- *
1673
- * @static
1674
- * @memberOf _
1675
- * @since 0.1.0
1676
- * @category Lang
1677
- * @param {*} value The value to compare.
1678
- * @param {*} other The other value to compare.
1679
- * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
1680
- * @example
1681
- *
1682
- * var object = { 'a': 1 };
1683
- * var other = { 'a': 1 };
1684
- *
1685
- * _.isEqual(object, other);
1686
- * // => true
1687
- *
1688
- * object === other;
1689
- * // => false
1690
- */
1691
- function isEqual(value, other) {
1692
- return baseIsEqual(value, other);
1693
- }
1694
-
1695
- /**
1696
- * Checks if `value` is classified as a `Function` object.
1697
- *
1698
- * @static
1699
- * @memberOf _
1700
- * @since 0.1.0
1701
- * @category Lang
1702
- * @param {*} value The value to check.
1703
- * @returns {boolean} Returns `true` if `value` is a function, else `false`.
1704
- * @example
1705
- *
1706
- * _.isFunction(_);
1707
- * // => true
1708
- *
1709
- * _.isFunction(/abc/);
1710
- * // => false
1711
- */
1712
- function isFunction(value) {
1713
- if (!isObject(value)) {
1714
- return false;
1715
- }
1716
- // The use of `Object#toString` avoids issues with the `typeof` operator
1717
- // in Safari 9 which returns 'object' for typed arrays and other constructors.
1718
- var tag = baseGetTag(value);
1719
- return tag == funcTag || tag == genTag || tag == asyncTag || tag == proxyTag;
1720
- }
1721
-
1722
- /**
1723
- * Checks if `value` is a valid array-like length.
1724
- *
1725
- * **Note:** This method is loosely based on
1726
- * [`ToLength`](http://ecma-international.org/ecma-262/7.0/#sec-tolength).
1727
- *
1728
- * @static
1729
- * @memberOf _
1730
- * @since 4.0.0
1731
- * @category Lang
1732
- * @param {*} value The value to check.
1733
- * @returns {boolean} Returns `true` if `value` is a valid length, else `false`.
1734
- * @example
1735
- *
1736
- * _.isLength(3);
1737
- * // => true
1738
- *
1739
- * _.isLength(Number.MIN_VALUE);
1740
- * // => false
1741
- *
1742
- * _.isLength(Infinity);
1743
- * // => false
1744
- *
1745
- * _.isLength('3');
1746
- * // => false
1747
- */
1748
- function isLength(value) {
1749
- return typeof value == 'number' &&
1750
- value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER;
1751
- }
1752
-
1753
- /**
1754
- * Checks if `value` is the
1755
- * [language type](http://www.ecma-international.org/ecma-262/7.0/#sec-ecmascript-language-types)
1756
- * of `Object`. (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
1757
- *
1758
- * @static
1759
- * @memberOf _
1760
- * @since 0.1.0
1761
- * @category Lang
1762
- * @param {*} value The value to check.
1763
- * @returns {boolean} Returns `true` if `value` is an object, else `false`.
1764
- * @example
1765
- *
1766
- * _.isObject({});
1767
- * // => true
1768
- *
1769
- * _.isObject([1, 2, 3]);
1770
- * // => true
1771
- *
1772
- * _.isObject(_.noop);
1773
- * // => true
1774
- *
1775
- * _.isObject(null);
1776
- * // => false
1777
- */
1778
- function isObject(value) {
1779
- var type = typeof value;
1780
- return value != null && (type == 'object' || type == 'function');
1781
- }
1782
-
1783
- /**
1784
- * Checks if `value` is object-like. A value is object-like if it's not `null`
1785
- * and has a `typeof` result of "object".
1786
- *
1787
- * @static
1788
- * @memberOf _
1789
- * @since 4.0.0
1790
- * @category Lang
1791
- * @param {*} value The value to check.
1792
- * @returns {boolean} Returns `true` if `value` is object-like, else `false`.
1793
- * @example
1794
- *
1795
- * _.isObjectLike({});
1796
- * // => true
1797
- *
1798
- * _.isObjectLike([1, 2, 3]);
1799
- * // => true
1800
- *
1801
- * _.isObjectLike(_.noop);
1802
- * // => false
1803
- *
1804
- * _.isObjectLike(null);
1805
- * // => false
1806
- */
1807
- function isObjectLike(value) {
1808
- return value != null && typeof value == 'object';
1809
- }
1810
-
1811
- /**
1812
- * Checks if `value` is classified as a typed array.
1813
- *
1814
- * @static
1815
- * @memberOf _
1816
- * @since 3.0.0
1817
- * @category Lang
1818
- * @param {*} value The value to check.
1819
- * @returns {boolean} Returns `true` if `value` is a typed array, else `false`.
1820
- * @example
1821
- *
1822
- * _.isTypedArray(new Uint8Array);
1823
- * // => true
1824
- *
1825
- * _.isTypedArray([]);
1826
- * // => false
1827
- */
1828
- var isTypedArray = nodeIsTypedArray ? baseUnary(nodeIsTypedArray) : baseIsTypedArray;
1829
-
1830
- /**
1831
- * Creates an array of the own enumerable property names of `object`.
1832
- *
1833
- * **Note:** Non-object values are coerced to objects. See the
1834
- * [ES spec](http://ecma-international.org/ecma-262/7.0/#sec-object.keys)
1835
- * for more details.
1836
- *
1837
- * @static
1838
- * @since 0.1.0
1839
- * @memberOf _
1840
- * @category Object
1841
- * @param {Object} object The object to query.
1842
- * @returns {Array} Returns the array of property names.
1843
- * @example
1844
- *
1845
- * function Foo() {
1846
- * this.a = 1;
1847
- * this.b = 2;
1848
- * }
1849
- *
1850
- * Foo.prototype.c = 3;
1851
- *
1852
- * _.keys(new Foo);
1853
- * // => ['a', 'b'] (iteration order is not guaranteed)
1854
- *
1855
- * _.keys('hi');
1856
- * // => ['0', '1']
1857
- */
1858
- function keys(object) {
1859
- return isArrayLike(object) ? arrayLikeKeys(object) : baseKeys(object);
1860
- }
1861
-
1862
- /**
1863
- * This method returns a new empty array.
1864
- *
1865
- * @static
1866
- * @memberOf _
1867
- * @since 4.13.0
1868
- * @category Util
1869
- * @returns {Array} Returns the new empty array.
1870
- * @example
1871
- *
1872
- * var arrays = _.times(2, _.stubArray);
1873
- *
1874
- * console.log(arrays);
1875
- * // => [[], []]
1876
- *
1877
- * console.log(arrays[0] === arrays[1]);
1878
- * // => false
1879
- */
1880
- function stubArray() {
1881
- return [];
1882
- }
1883
-
1884
- /**
1885
- * This method returns `false`.
1886
- *
1887
- * @static
1888
- * @memberOf _
1889
- * @since 4.13.0
1890
- * @category Util
1891
- * @returns {boolean} Returns `false`.
1892
- * @example
1893
- *
1894
- * _.times(2, _.stubFalse);
1895
- * // => [false, false]
1896
- */
1897
- function stubFalse() {
1898
- return false;
1899
- }
1900
-
1901
- module.exports = isEqual;
1902
- } (lodash_isequal, lodash_isequal.exports));
1903
- return lodash_isequal.exports;
1904
- }
1905
-
1906
- var lodash_isequalExports = requireLodash_isequal();
1907
- var isEqual = /*@__PURE__*/getDefaultExportFromCjs(lodash_isequalExports);
1908
-
1909
- function circleLayer(color, source, vectorLayer) {
1910
- const layer = {
1911
- id: [source, vectorLayer, 'circle'].join('_'),
1912
- source,
1913
- type: 'circle',
1914
- paint: {
1915
- 'circle-color': color,
1916
- 'circle-radius': 2
1917
- },
1918
- filter: ['==', '$type', 'Point']
1919
- };
1920
- if (vectorLayer) {
1921
- layer['source-layer'] = vectorLayer;
1922
- }
1923
- return layer;
1924
- }
1925
- function polygonLayer(color, _outlineColor, source, vectorLayer) {
1926
- const layer = {
1927
- id: [source, vectorLayer, 'polygon'].join('_'),
1928
- source,
1929
- type: 'fill',
1930
- paint: {
1931
- 'fill-color': color,
1932
- 'fill-antialias': true,
1933
- 'fill-outline-color': color
1934
- },
1935
- filter: ['==', '$type', 'Polygon']
1936
- };
1937
- if (vectorLayer) {
1938
- layer['source-layer'] = vectorLayer;
1939
- }
1940
- return layer;
1941
- }
1942
- function lineLayer(color, source, vectorLayer) {
1943
- const layer = {
1944
- id: [source, vectorLayer, 'line'].join('_'),
1945
- source,
1946
- layout: {
1947
- 'line-join': 'round',
1948
- 'line-cap': 'round'
1949
- },
1950
- type: 'line',
1951
- paint: {
1952
- 'line-color': color
1953
- },
1954
- filter: ['==', '$type', 'LineString']
1955
- };
1956
- if (vectorLayer) {
1957
- layer['source-layer'] = vectorLayer;
1958
- }
1959
- return layer;
1960
- }
1961
- function alphaColors(layerId, assignLayerColor) {
1962
- return {
1963
- circle: assignLayerColor(layerId, 0.8),
1964
- line: assignLayerColor(layerId, 0.6),
1965
- polygon: assignLayerColor(layerId, 0.3),
1966
- polygonOutline: assignLayerColor(layerId, 0.6),
1967
- default: assignLayerColor(layerId, 1)
1968
- };
1969
- }
1970
- /**
1971
- * Generate colored layer styles for the given sources
1972
- * @param sources dictionary containing the vector layer IDs
1973
- * @param assignLayerColor to generate a color for a layer
1974
- * @return Array of Maplibre GL layers
1975
- */
1976
- function generateColoredLayers(sources, assignLayerColor) {
1977
- const polyLayers = [];
1978
- const circleLayers = [];
1979
- const lineLayers = [];
1980
- for (const sourceId of Object.keys(sources)) {
1981
- const layers = sources[sourceId];
1982
- if (!layers || layers.length === 0) {
1983
- const colors = alphaColors(sourceId, assignLayerColor);
1984
- circleLayers.push(circleLayer(colors.circle, sourceId));
1985
- lineLayers.push(lineLayer(colors.line, sourceId));
1986
- polyLayers.push(polygonLayer(colors.polygon, colors.polygonOutline, sourceId));
1987
- }
1988
- else {
1989
- for (const layerId of layers) {
1990
- const colors = alphaColors(layerId, assignLayerColor);
1991
- circleLayers.push(circleLayer(colors.circle, sourceId, layerId));
1992
- lineLayers.push(lineLayer(colors.line, sourceId, layerId));
1993
- polyLayers.push(polygonLayer(colors.polygon, colors.polygonOutline, sourceId, layerId));
1994
- }
1995
- }
1996
- }
1997
- return polyLayers.concat(lineLayers).concat(circleLayers);
1998
- }
1999
- /**
2000
- * Create inspection style out of the original style and the new colored layers
2001
- * @param originalMapStyle - map style
2002
- * @param coloredLayers - array of colored Maplibre GL layers
2003
- * @param opts - options
2004
- * @return {Object} Colored inspect style
2005
- */
2006
- function generateInspectStyle(originalMapStyle, coloredLayers, opts) {
2007
- opts = Object.assign({
2008
- backgroundColor: '#fff'
2009
- }, opts);
2010
- const backgroundLayer = {
2011
- 'id': 'background',
2012
- 'type': 'background',
2013
- 'paint': {
2014
- 'background-color': opts.backgroundColor
2015
- }
2016
- };
2017
- const sources = {};
2018
- for (const sourceId of Object.keys(originalMapStyle.sources)) {
2019
- const source = originalMapStyle.sources[sourceId];
2020
- if (source.type === 'vector' || source.type === 'geojson') {
2021
- sources[sourceId] = source;
2022
- }
2023
- }
2024
- return Object.assign(originalMapStyle, {
2025
- layers: [backgroundLayer].concat(coloredLayers),
2026
- sources
2027
- });
2028
- }
2029
- var stylegen = {
2030
- polygonLayer,
2031
- lineLayer,
2032
- circleLayer,
2033
- generateInspectStyle,
2034
- generateColoredLayers
2035
- };
2036
-
2037
- /**
2038
- * A button to toggle the inspect mode
2039
- */
2040
- class InspectButton {
2041
- constructor(options) {
2042
- options = Object.assign({
2043
- show: true,
2044
- onToggle() { }
2045
- }, options);
2046
- this._btn = this.createButton();
2047
- this._btn.onclick = options.onToggle;
2048
- this.elem = this.createContainer(this._btn, options.show);
2049
- }
2050
- createButton() {
2051
- const btn = document.createElement('button');
2052
- btn.className = 'maplibregl-ctrl-icon maplibregl-ctrl-inspect';
2053
- btn.type = 'button';
2054
- btn.title = 'Toggle Inspect';
2055
- btn.setAttribute('aria-label', 'Toggle Inspect');
2056
- return btn;
2057
- }
2058
- createContainer(child, show) {
2059
- const container = document.createElement('div');
2060
- container.className = 'maplibregl-ctrl maplibregl-ctrl-group';
2061
- container.appendChild(child);
2062
- if (!show) {
2063
- container.style.display = 'none';
2064
- }
2065
- return container;
2066
- }
2067
- setInspectIcon() {
2068
- this._btn.className = 'maplibregl-ctrl-icon maplibregl-ctrl-inspect';
2069
- }
2070
- setMapIcon() {
2071
- this._btn.className = 'maplibregl-ctrl-icon maplibregl-ctrl-map';
2072
- }
2073
- }
2074
-
2075
- function displayValue(value) {
2076
- if (typeof value === 'undefined' || value === null)
2077
- return value;
2078
- if (value instanceof Date)
2079
- return value.toLocaleString();
2080
- if (typeof value === 'object' ||
2081
- typeof value === 'number' ||
2082
- typeof value === 'string')
2083
- return value.toString();
2084
- return value;
2085
- }
2086
- function renderProperty(propertyName, property) {
2087
- return `${'<div class="maplibregl-inspect_property">' +
2088
- '<div class="maplibregl-inspect_property-name">'}${propertyName}</div>` +
2089
- `<div class="maplibregl-inspect_property-value">${displayValue(property)}</div>` +
2090
- '</div>';
2091
- }
2092
- function renderLayer(layerId) {
2093
- return `<div class="maplibregl-inspect_layer">${layerId}</div>`;
2094
- }
2095
- function renderProperties(feature) {
2096
- const sourceProperty = renderLayer(feature.layer['source-layer'] || feature.layer.source);
2097
- const idProperty = renderProperty('$id', feature.id);
2098
- const typeProperty = renderProperty('$type', feature.geometry.type);
2099
- const properties = Object.keys(feature.properties).map(propertyName => renderProperty(propertyName, feature.properties[propertyName]));
2100
- return [sourceProperty, idProperty, typeProperty].concat(properties).join('');
2101
- }
2102
- function renderFeatures(features) {
2103
- return features.map(ft => `<div class="maplibregl-inspect_feature">${renderProperties(ft)}</div>`).join('');
2104
- }
2105
- function renderPopup(features) {
2106
- return `<div class="maplibregl-inspect_popup">${renderFeatures(features)}</div>`;
2107
- }
2108
-
2109
- var randomColor$1 = {exports: {}};
2110
-
2111
- var randomColor_1 = randomColor$1.exports;
2112
-
2113
- var hasRequiredRandomColor;
2114
-
2115
- function requireRandomColor () {
2116
- if (hasRequiredRandomColor) return randomColor$1.exports;
2117
- hasRequiredRandomColor = 1;
2118
- (function (module, exports$1) {
2119
- (function(root, factory) {
2120
-
2121
- // Support CommonJS
2122
- {
2123
- var randomColor = factory();
2124
-
2125
- // Support NodeJS & Component, which allow module.exports to be a function
2126
- if (module && module.exports) {
2127
- exports$1 = module.exports = randomColor;
2128
- }
2129
-
2130
- // Support CommonJS 1.1.1 spec
2131
- exports$1.randomColor = randomColor;
2132
-
2133
- // Support AMD
2134
- }
2135
-
2136
- }(randomColor_1, function() {
2137
-
2138
- // Seed to get repeatable colors
2139
- var seed = null;
2140
-
2141
- // Shared color dictionary
2142
- var colorDictionary = {};
2143
-
2144
- // Populate the color dictionary
2145
- loadColorBounds();
2146
-
2147
- // check if a range is taken
2148
- var colorRanges = [];
2149
-
2150
- var randomColor = function (options) {
2151
-
2152
- options = options || {};
2153
-
2154
- // Check if there is a seed and ensure it's an
2155
- // integer. Otherwise, reset the seed value.
2156
- if (options.seed !== undefined && options.seed !== null && options.seed === parseInt(options.seed, 10)) {
2157
- seed = options.seed;
2158
-
2159
- // A string was passed as a seed
2160
- } else if (typeof options.seed === 'string') {
2161
- seed = stringToInteger(options.seed);
2162
-
2163
- // Something was passed as a seed but it wasn't an integer or string
2164
- } else if (options.seed !== undefined && options.seed !== null) {
2165
- throw new TypeError('The seed value must be an integer or string');
2166
-
2167
- // No seed, reset the value outside.
2168
- } else {
2169
- seed = null;
2170
- }
2171
-
2172
- var H,S,B;
2173
-
2174
- // Check if we need to generate multiple colors
2175
- if (options.count !== null && options.count !== undefined) {
2176
-
2177
- var totalColors = options.count,
2178
- colors = [];
2179
- // Value false at index i means the range i is not taken yet.
2180
- for (var i = 0; i < options.count; i++) {
2181
- colorRanges.push(false);
2182
- }
2183
- options.count = null;
2184
-
2185
- while (totalColors > colors.length) {
2186
-
2187
- var color = randomColor(options);
2188
-
2189
- if (seed !== null) {
2190
- options.seed = seed;
2191
- }
2192
-
2193
- colors.push(color);
2194
- }
2195
-
2196
- options.count = totalColors;
2197
-
2198
- return colors;
2199
- }
2200
-
2201
- // First we pick a hue (H)
2202
- H = pickHue(options);
2203
-
2204
- // Then use H to determine saturation (S)
2205
- S = pickSaturation(H, options);
2206
-
2207
- // Then use S and H to determine brightness (B).
2208
- B = pickBrightness(H, S, options);
2209
-
2210
- // Then we return the HSB color in the desired format
2211
- return setFormat([H,S,B], options);
2212
- };
2213
-
2214
- function pickHue(options) {
2215
- if (colorRanges.length > 0) {
2216
- var hueRange = getRealHueRange(options.hue);
2217
-
2218
- var hue = randomWithin(hueRange);
2219
-
2220
- //Each of colorRanges.length ranges has a length equal approximatelly one step
2221
- var step = (hueRange[1] - hueRange[0]) / colorRanges.length;
2222
-
2223
- var j = parseInt((hue - hueRange[0]) / step);
2224
-
2225
- //Check if the range j is taken
2226
- if (colorRanges[j] === true) {
2227
- j = (j + 2) % colorRanges.length;
2228
- }
2229
- else {
2230
- colorRanges[j] = true;
2231
- }
2232
-
2233
- var min = (hueRange[0] + j * step) % 359,
2234
- max = (hueRange[0] + (j + 1) * step) % 359;
2235
-
2236
- hueRange = [min, max];
2237
-
2238
- hue = randomWithin(hueRange);
2239
-
2240
- if (hue < 0) {hue = 360 + hue;}
2241
- return hue
2242
- }
2243
- else {
2244
- var hueRange = getHueRange(options.hue);
2245
-
2246
- hue = randomWithin(hueRange);
2247
- // Instead of storing red as two seperate ranges,
2248
- // we group them, using negative numbers
2249
- if (hue < 0) {
2250
- hue = 360 + hue;
2251
- }
2252
-
2253
- return hue;
2254
- }
2255
- }
2256
-
2257
- function pickSaturation (hue, options) {
2258
-
2259
- if (options.hue === 'monochrome') {
2260
- return 0;
2261
- }
2262
-
2263
- if (options.luminosity === 'random') {
2264
- return randomWithin([0,100]);
2265
- }
2266
-
2267
- var saturationRange = getSaturationRange(hue);
2268
-
2269
- var sMin = saturationRange[0],
2270
- sMax = saturationRange[1];
2271
-
2272
- switch (options.luminosity) {
2273
-
2274
- case 'bright':
2275
- sMin = 55;
2276
- break;
2277
-
2278
- case 'dark':
2279
- sMin = sMax - 10;
2280
- break;
2281
-
2282
- case 'light':
2283
- sMax = 55;
2284
- break;
2285
- }
2286
-
2287
- return randomWithin([sMin, sMax]);
2288
-
2289
- }
2290
-
2291
- function pickBrightness (H, S, options) {
2292
-
2293
- var bMin = getMinimumBrightness(H, S),
2294
- bMax = 100;
2295
-
2296
- switch (options.luminosity) {
2297
-
2298
- case 'dark':
2299
- bMax = bMin + 20;
2300
- break;
2301
-
2302
- case 'light':
2303
- bMin = (bMax + bMin)/2;
2304
- break;
2305
-
2306
- case 'random':
2307
- bMin = 0;
2308
- bMax = 100;
2309
- break;
2310
- }
2311
-
2312
- return randomWithin([bMin, bMax]);
2313
- }
2314
-
2315
- function setFormat (hsv, options) {
2316
-
2317
- switch (options.format) {
2318
-
2319
- case 'hsvArray':
2320
- return hsv;
2321
-
2322
- case 'hslArray':
2323
- return HSVtoHSL(hsv);
2324
-
2325
- case 'hsl':
2326
- var hsl = HSVtoHSL(hsv);
2327
- return 'hsl('+hsl[0]+', '+hsl[1]+'%, '+hsl[2]+'%)';
2328
-
2329
- case 'hsla':
2330
- var hslColor = HSVtoHSL(hsv);
2331
- var alpha = options.alpha || Math.random();
2332
- return 'hsla('+hslColor[0]+', '+hslColor[1]+'%, '+hslColor[2]+'%, ' + alpha + ')';
2333
-
2334
- case 'rgbArray':
2335
- return HSVtoRGB(hsv);
2336
-
2337
- case 'rgb':
2338
- var rgb = HSVtoRGB(hsv);
2339
- return 'rgb(' + rgb.join(', ') + ')';
2340
-
2341
- case 'rgba':
2342
- var rgbColor = HSVtoRGB(hsv);
2343
- var alpha = options.alpha || Math.random();
2344
- return 'rgba(' + rgbColor.join(', ') + ', ' + alpha + ')';
2345
-
2346
- default:
2347
- return HSVtoHex(hsv);
2348
- }
2349
-
2350
- }
2351
-
2352
- function getMinimumBrightness(H, S) {
2353
-
2354
- var lowerBounds = getColorInfo(H).lowerBounds;
2355
-
2356
- for (var i = 0; i < lowerBounds.length - 1; i++) {
2357
-
2358
- var s1 = lowerBounds[i][0],
2359
- v1 = lowerBounds[i][1];
2360
-
2361
- var s2 = lowerBounds[i+1][0],
2362
- v2 = lowerBounds[i+1][1];
2363
-
2364
- if (S >= s1 && S <= s2) {
2365
-
2366
- var m = (v2 - v1)/(s2 - s1),
2367
- b = v1 - m*s1;
2368
-
2369
- return m*S + b;
2370
- }
2371
-
2372
- }
2373
-
2374
- return 0;
2375
- }
2376
-
2377
- function getHueRange (colorInput) {
2378
-
2379
- if (typeof parseInt(colorInput) === 'number') {
2380
-
2381
- var number = parseInt(colorInput);
2382
-
2383
- if (number < 360 && number > 0) {
2384
- return [number, number];
2385
- }
2386
-
2387
- }
2388
-
2389
- if (typeof colorInput === 'string') {
2390
-
2391
- if (colorDictionary[colorInput]) {
2392
- var color = colorDictionary[colorInput];
2393
- if (color.hueRange) {return color.hueRange;}
2394
- } else if (colorInput.match(/^#?([0-9A-F]{3}|[0-9A-F]{6})$/i)) {
2395
- var hue = HexToHSB(colorInput)[0];
2396
- return [ hue, hue ];
2397
- }
2398
- }
2399
-
2400
- return [0,360];
2401
-
2402
- }
2403
-
2404
- function getSaturationRange (hue) {
2405
- return getColorInfo(hue).saturationRange;
2406
- }
2407
-
2408
- function getColorInfo (hue) {
2409
-
2410
- // Maps red colors to make picking hue easier
2411
- if (hue >= 334 && hue <= 360) {
2412
- hue-= 360;
2413
- }
2414
-
2415
- for (var colorName in colorDictionary) {
2416
- var color = colorDictionary[colorName];
2417
- if (color.hueRange &&
2418
- hue >= color.hueRange[0] &&
2419
- hue <= color.hueRange[1]) {
2420
- return colorDictionary[colorName];
2421
- }
2422
- } return 'Color not found';
2423
- }
2424
-
2425
- function randomWithin (range) {
2426
- if (seed === null) {
2427
- //generate random evenly destinct number from : https://martin.ankerl.com/2009/12/09/how-to-create-random-colors-programmatically/
2428
- var golden_ratio = 0.618033988749895;
2429
- var r=Math.random();
2430
- r += golden_ratio;
2431
- r %= 1;
2432
- return Math.floor(range[0] + r*(range[1] + 1 - range[0]));
2433
- } else {
2434
- //Seeded random algorithm from http://indiegamr.com/generate-repeatable-random-numbers-in-js/
2435
- var max = range[1] || 1;
2436
- var min = range[0] || 0;
2437
- seed = (seed * 9301 + 49297) % 233280;
2438
- var rnd = seed / 233280.0;
2439
- return Math.floor(min + rnd * (max - min));
2440
- }
2441
- }
2442
-
2443
- function HSVtoHex (hsv){
2444
-
2445
- var rgb = HSVtoRGB(hsv);
2446
-
2447
- function componentToHex(c) {
2448
- var hex = c.toString(16);
2449
- return hex.length == 1 ? '0' + hex : hex;
2450
- }
2451
-
2452
- var hex = '#' + componentToHex(rgb[0]) + componentToHex(rgb[1]) + componentToHex(rgb[2]);
2453
-
2454
- return hex;
2455
-
2456
- }
2457
-
2458
- function defineColor (name, hueRange, lowerBounds) {
2459
-
2460
- var sMin = lowerBounds[0][0],
2461
- sMax = lowerBounds[lowerBounds.length - 1][0],
2462
-
2463
- bMin = lowerBounds[lowerBounds.length - 1][1],
2464
- bMax = lowerBounds[0][1];
2465
-
2466
- colorDictionary[name] = {
2467
- hueRange: hueRange,
2468
- lowerBounds: lowerBounds,
2469
- saturationRange: [sMin, sMax],
2470
- brightnessRange: [bMin, bMax]
2471
- };
2472
-
2473
- }
2474
-
2475
- function loadColorBounds () {
2476
-
2477
- defineColor(
2478
- 'monochrome',
2479
- null,
2480
- [[0,0],[100,0]]
2481
- );
2482
-
2483
- defineColor(
2484
- 'red',
2485
- [-26,18],
2486
- [[20,100],[30,92],[40,89],[50,85],[60,78],[70,70],[80,60],[90,55],[100,50]]
2487
- );
2488
-
2489
- defineColor(
2490
- 'orange',
2491
- [18,46],
2492
- [[20,100],[30,93],[40,88],[50,86],[60,85],[70,70],[100,70]]
2493
- );
2494
-
2495
- defineColor(
2496
- 'yellow',
2497
- [46,62],
2498
- [[25,100],[40,94],[50,89],[60,86],[70,84],[80,82],[90,80],[100,75]]
2499
- );
2500
-
2501
- defineColor(
2502
- 'green',
2503
- [62,178],
2504
- [[30,100],[40,90],[50,85],[60,81],[70,74],[80,64],[90,50],[100,40]]
2505
- );
2506
-
2507
- defineColor(
2508
- 'blue',
2509
- [178, 257],
2510
- [[20,100],[30,86],[40,80],[50,74],[60,60],[70,52],[80,44],[90,39],[100,35]]
2511
- );
2512
-
2513
- defineColor(
2514
- 'purple',
2515
- [257, 282],
2516
- [[20,100],[30,87],[40,79],[50,70],[60,65],[70,59],[80,52],[90,45],[100,42]]
2517
- );
2518
-
2519
- defineColor(
2520
- 'pink',
2521
- [282, 334],
2522
- [[20,100],[30,90],[40,86],[60,84],[80,80],[90,75],[100,73]]
2523
- );
2524
-
2525
- }
2526
-
2527
- function HSVtoRGB (hsv) {
2528
-
2529
- // this doesn't work for the values of 0 and 360
2530
- // here's the hacky fix
2531
- var h = hsv[0];
2532
- if (h === 0) {h = 1;}
2533
- if (h === 360) {h = 359;}
2534
-
2535
- // Rebase the h,s,v values
2536
- h = h/360;
2537
- var s = hsv[1]/100,
2538
- v = hsv[2]/100;
2539
-
2540
- var h_i = Math.floor(h*6),
2541
- f = h * 6 - h_i,
2542
- p = v * (1 - s),
2543
- q = v * (1 - f*s),
2544
- t = v * (1 - (1 - f)*s),
2545
- r = 256,
2546
- g = 256,
2547
- b = 256;
2548
-
2549
- switch(h_i) {
2550
- case 0: r = v; g = t; b = p; break;
2551
- case 1: r = q; g = v; b = p; break;
2552
- case 2: r = p; g = v; b = t; break;
2553
- case 3: r = p; g = q; b = v; break;
2554
- case 4: r = t; g = p; b = v; break;
2555
- case 5: r = v; g = p; b = q; break;
2556
- }
2557
-
2558
- var result = [Math.floor(r*255), Math.floor(g*255), Math.floor(b*255)];
2559
- return result;
2560
- }
2561
-
2562
- function HexToHSB (hex) {
2563
- hex = hex.replace(/^#/, '');
2564
- hex = hex.length === 3 ? hex.replace(/(.)/g, '$1$1') : hex;
2565
-
2566
- var red = parseInt(hex.substr(0, 2), 16) / 255,
2567
- green = parseInt(hex.substr(2, 2), 16) / 255,
2568
- blue = parseInt(hex.substr(4, 2), 16) / 255;
2569
-
2570
- var cMax = Math.max(red, green, blue),
2571
- delta = cMax - Math.min(red, green, blue),
2572
- saturation = cMax ? (delta / cMax) : 0;
2573
-
2574
- switch (cMax) {
2575
- case red: return [ 60 * (((green - blue) / delta) % 6) || 0, saturation, cMax ];
2576
- case green: return [ 60 * (((blue - red) / delta) + 2) || 0, saturation, cMax ];
2577
- case blue: return [ 60 * (((red - green) / delta) + 4) || 0, saturation, cMax ];
2578
- }
2579
- }
2580
-
2581
- function HSVtoHSL (hsv) {
2582
- var h = hsv[0],
2583
- s = hsv[1]/100,
2584
- v = hsv[2]/100,
2585
- k = (2-s)*v;
2586
-
2587
- return [
2588
- h,
2589
- Math.round(s*v / (k<1 ? k : 2-k) * 10000) / 100,
2590
- k/2 * 100
2591
- ];
2592
- }
2593
-
2594
- function stringToInteger (string) {
2595
- var total = 0;
2596
- for (var i = 0; i !== string.length; i++) {
2597
- if (total >= Number.MAX_SAFE_INTEGER) break;
2598
- total += string.charCodeAt(i);
2599
- }
2600
- return total
2601
- }
2602
-
2603
- // get The range of given hue when options.count!=0
2604
- function getRealHueRange(colorHue)
2605
- { if (!isNaN(colorHue)) {
2606
- var number = parseInt(colorHue);
2607
-
2608
- if (number < 360 && number > 0) {
2609
- return getColorInfo(colorHue).hueRange
2610
- }
2611
- }
2612
- else if (typeof colorHue === 'string') {
2613
-
2614
- if (colorDictionary[colorHue]) {
2615
- var color = colorDictionary[colorHue];
2616
-
2617
- if (color.hueRange) {
2618
- return color.hueRange
2619
- }
2620
- } else if (colorHue.match(/^#?([0-9A-F]{3}|[0-9A-F]{6})$/i)) {
2621
- var hue = HexToHSB(colorHue)[0];
2622
- return getColorInfo(hue).hueRange
2623
- }
2624
- }
2625
-
2626
- return [0,360]
2627
- }
2628
- return randomColor;
2629
- }));
2630
- } (randomColor$1, randomColor$1.exports));
2631
- return randomColor$1.exports;
2632
- }
2633
-
2634
- var randomColorExports = requireRandomColor();
2635
- var randomColor = /*@__PURE__*/getDefaultExportFromCjs(randomColorExports);
2636
-
2637
- /**
2638
- * Assign a color to a unique layer ID and also considering
2639
- * common layer names such as water or wood.
2640
- * @param layerId - a layer ID
2641
- * @param alpha - alpha value for the color, default is 1
2642
- * @return a color in rgba string format
2643
- */
2644
- function brightColor(layerId, alpha) {
2645
- let luminosity = 'bright';
2646
- let hue = undefined;
2647
- if (/water|ocean|lake|sea|river/.test(layerId)) {
2648
- hue = 'blue';
2649
- }
2650
- if (/state|country|place/.test(layerId)) {
2651
- hue = 'pink';
2652
- }
2653
- if (/road|highway|transport|streets/.test(layerId)) {
2654
- hue = 'orange';
2655
- }
2656
- if (/contour|building|earth/.test(layerId)) {
2657
- hue = 'monochrome';
2658
- }
2659
- if (/building/.test(layerId)) {
2660
- luminosity = 'dark';
2661
- }
2662
- if (/earth/.test(layerId)) {
2663
- luminosity = 'light';
2664
- }
2665
- if (/contour|landuse/.test(layerId)) {
2666
- hue = 'yellow';
2667
- }
2668
- if (/wood|forest|park|landcover|land|natural/.test(layerId)) {
2669
- hue = 'green';
2670
- }
2671
- const rgb = randomColor({
2672
- luminosity,
2673
- hue,
2674
- seed: layerId,
2675
- format: 'rgbArray'
2676
- });
2677
- return `rgba(${rgb.join(', ')}, ${alpha || "1"})`;
2678
- }
2679
- var colors = { brightColor };
2680
-
2681
- function isInspectStyle(style) {
2682
- return style.metadata && style.metadata['maplibregl-inspect:inspect'];
2683
- }
2684
- function markInspectStyle(style) {
2685
- return Object.assign(style, {
2686
- metadata: Object.assign({}, style.metadata, {
2687
- 'maplibregl-inspect:inspect': true
2688
- })
2689
- });
2690
- }
2691
- /**
2692
- * Maplibre Inspect Control
2693
- */
2694
- class MaplibreInspect {
2695
- constructor(options) {
2696
- this._onSourceChange = (e) => __awaiter(this, void 0, void 0, function* () {
2697
- if (e.sourceDataType === 'visibility' || !e.isSourceLoaded) {
2698
- return;
2699
- }
2700
- const previousSources = Object.assign({}, this.sources);
2701
- yield this._setSourcesFromMap();
2702
- if (!isEqual(previousSources, this.sources) && Object.keys(this.sources).length > 0) {
2703
- // If the sources have changed, we need to re-render the inspect style but not too fast
2704
- setTimeout(() => this.render(), 1000);
2705
- }
2706
- });
2707
- this._onStyleChange = () => {
2708
- const style = this._map.getStyle();
2709
- if (!isInspectStyle(style)) {
2710
- this._originalStyle = style;
2711
- }
2712
- };
2713
- this._onRightClick = () => {
2714
- if (!this.options.showMapPopupOnHover && !this.options.showInspectMapPopupOnHover && !this.options.blockHoverPopupOnClick) {
2715
- if (this._popup)
2716
- this._popup.remove();
2717
- }
2718
- };
2719
- this._onMousemove = (e) => {
2720
- if (this._showInspectMap) {
2721
- if (!this.options.showInspectMapPopup)
2722
- return;
2723
- if (e.type === 'mousemove' && !this.options.showInspectMapPopupOnHover)
2724
- return;
2725
- if (e.type === 'click' && this.options.showInspectMapPopupOnHover && this.options.blockHoverPopupOnClick) {
2726
- this._popupBlocked = !this._popupBlocked;
2727
- }
2728
- }
2729
- else {
2730
- if (!this.options.showMapPopup)
2731
- return;
2732
- if (e.type === 'mousemove' && !this.options.showMapPopupOnHover)
2733
- return;
2734
- if (e.type === 'click' && this.options.showMapPopupOnHover && this.options.blockHoverPopupOnClick) {
2735
- this._popupBlocked = !this._popupBlocked;
2736
- }
2737
- }
2738
- if (!this._popupBlocked && this._popup) {
2739
- let queryBox;
2740
- if (this.options.selectThreshold === 0) {
2741
- queryBox = e.point;
2742
- }
2743
- else {
2744
- // set a bbox around the pointer
2745
- queryBox = [
2746
- [
2747
- e.point.x - this.options.selectThreshold,
2748
- e.point.y + this.options.selectThreshold
2749
- ], // bottom left (SW)
2750
- [
2751
- e.point.x + this.options.selectThreshold,
2752
- e.point.y - this.options.selectThreshold
2753
- ] // top right (NE)
2754
- ];
2755
- }
2756
- const features = this._map.queryRenderedFeatures(queryBox, this.options.queryParameters) || [];
2757
- this._map.getCanvas().style.cursor = (features.length) ? 'pointer' : '';
2758
- if (!features.length) {
2759
- this._popup.remove();
2760
- }
2761
- else {
2762
- this._popup.setLngLat(e.lngLat);
2763
- const renderedPopup = this.options.renderPopup(features);
2764
- if (typeof renderedPopup === 'string') {
2765
- this._popup.setHTML(renderedPopup);
2766
- }
2767
- else {
2768
- this._popup.setDOMContent(renderedPopup);
2769
- }
2770
- this._popup.addTo(this._map);
2771
- }
2772
- }
2773
- };
2774
- if (!(this instanceof MaplibreInspect)) {
2775
- throw new Error('MaplibreInspect needs to be called with the new keyword');
2776
- }
2777
- let popup = null;
2778
- if (window.maplibregl) {
2779
- popup = new window.maplibregl.Popup({
2780
- closeButton: false,
2781
- closeOnClick: false
2782
- });
2783
- }
2784
- else if (!options.popup) {
2785
- console.error('Maplibre GL JS can not be found. Make sure to include it or pass an initialized MaplibreGL Popup to MaplibreInspect if you are using moduleis.');
2786
- }
2787
- this.options = Object.assign({
2788
- showInspectMap: false,
2789
- showInspectButton: true,
2790
- showInspectMapPopup: true,
2791
- showMapPopup: false,
2792
- showMapPopupOnHover: true,
2793
- showInspectMapPopupOnHover: true,
2794
- blockHoverPopupOnClick: false,
2795
- backgroundColor: '#fff',
2796
- assignLayerColor: colors.brightColor,
2797
- buildInspectStyle: stylegen.generateInspectStyle,
2798
- renderPopup,
2799
- popup,
2800
- selectThreshold: 5,
2801
- useInspectStyle: true,
2802
- queryParameters: {},
2803
- sources: {},
2804
- toggleCallback() { },
2805
- manageStyleOutside: false
2806
- }, options);
2807
- this.sources = this.options.sources;
2808
- this.assignLayerColor = this.options.assignLayerColor;
2809
- this._popup = this.options.popup;
2810
- this._popupBlocked = false;
2811
- this._showInspectMap = this.options.showInspectMap;
2812
- this._toggle = new InspectButton({
2813
- show: this.options.showInspectButton,
2814
- onToggle: () => this.toggleInspector()
2815
- });
2816
- }
2817
- toggleInspector() {
2818
- this._showInspectMap = !this._showInspectMap;
2819
- this._popupBlocked = false;
2820
- this.options.toggleCallback(this._showInspectMap);
2821
- this.render();
2822
- }
2823
- _inspectStyle() {
2824
- const coloredLayers = stylegen.generateColoredLayers(this.sources, this.assignLayerColor);
2825
- return this.options.buildInspectStyle(this._map.getStyle(), coloredLayers, {
2826
- backgroundColor: this.options.backgroundColor
2827
- });
2828
- }
2829
- render() {
2830
- if (this._showInspectMap) {
2831
- if (this.options.useInspectStyle) {
2832
- this._map.setStyle(markInspectStyle(this._inspectStyle()));
2833
- }
2834
- this._toggle.setMapIcon();
2835
- }
2836
- else if (this._originalStyle) {
2837
- if (this._popup)
2838
- this._popup.remove();
2839
- if (this.options.useInspectStyle) {
2840
- this._map.setStyle(this._originalStyle);
2841
- }
2842
- this._toggle.setInspectIcon();
2843
- }
2844
- }
2845
- _setSourcesFromMap() {
2846
- return __awaiter(this, void 0, void 0, function* () {
2847
- var _a;
2848
- const style = this._map.getStyle();
2849
- const mapStyleSourcesNames = Object.keys(style.sources);
2850
- for (const sourceId of mapStyleSourcesNames) {
2851
- if (style.sources[sourceId].type === 'geojson') {
2852
- this.sources[sourceId] = [];
2853
- }
2854
- else if (style.sources[sourceId].type === 'vector' && style.sources[sourceId].url) {
2855
- try {
2856
- const response = yield fetch(style.sources[sourceId].url);
2857
- const tileJSON = yield response.json();
2858
- const vectorLayerIds = (_a = tileJSON === null || tileJSON === void 0 ? void 0 : tileJSON.vector_layers) === null || _a === void 0 ? void 0 : _a.map((layer) => { return layer.id; });
2859
- if (vectorLayerIds) {
2860
- this.sources[sourceId] = vectorLayerIds;
2861
- }
2862
- else {
2863
- throw new Error("Missing vector_layers in source: " + sourceId);
2864
- }
2865
- }
2866
- catch (_b) {
2867
- console.warn("Unable to retrieve tileJSON from " + style.sources[sourceId].url + " using style's layers");
2868
- for (const layer of style.layers) {
2869
- if ('source-layer' in layer && layer['source-layer']) {
2870
- const layerId = layer['source-layer'];
2871
- if (!this.sources[sourceId]) {
2872
- this.sources[sourceId] = [];
2873
- }
2874
- this.sources[sourceId].push(layerId);
2875
- }
2876
- }
2877
- }
2878
- }
2879
- }
2880
- for (const sourceId of Object.keys(this.sources)) {
2881
- if (mapStyleSourcesNames.indexOf(sourceId) === -1) {
2882
- delete this.sources[sourceId];
2883
- }
2884
- else {
2885
- // uniqify the list of layer names
2886
- this.sources[sourceId] = [...new Set(this.sources[sourceId])];
2887
- }
2888
- }
2889
- });
2890
- }
2891
- /**
2892
- * This will set the original style of the map
2893
- * It will also update the sources assuming the map has already been loaded
2894
- * @param style - The original style
2895
- */
2896
- setOriginalStyle(style) {
2897
- this._originalStyle = style;
2898
- this._setSourcesFromMap();
2899
- }
2900
- /** @inheritdoc */
2901
- onAdd(map) {
2902
- this._map = map;
2903
- // if sources have already been passed as options
2904
- // we do not need to figure out the sources ourselves
2905
- if (Object.keys(this.sources).length === 0) {
2906
- map.on('tiledata', this._onSourceChange);
2907
- map.on('sourcedata', this._onSourceChange);
2908
- }
2909
- map.on('styledata', this._onStyleChange);
2910
- map.on('load', this._onStyleChange);
2911
- map.on('mousemove', this._onMousemove);
2912
- map.on('click', this._onMousemove);
2913
- map.on('contextmenu', this._onRightClick);
2914
- return this._toggle.elem;
2915
- }
2916
- /** @inheritdoc */
2917
- onRemove() {
2918
- this._map.off('styledata', this._onStyleChange);
2919
- this._map.off('load', this._onStyleChange);
2920
- this._map.off('tiledata', this._onSourceChange);
2921
- this._map.off('sourcedata', this._onSourceChange);
2922
- this._map.off('mousemove', this._onMousemove);
2923
- this._map.off('click', this._onMousemove);
2924
- this._map.off('contextmenu', this._onRightClick);
2925
- const elem = this._toggle.elem;
2926
- elem.parentNode.removeChild(elem);
2927
- this._map = undefined;
2928
- }
2929
- }
2930
-
2931
- return MaplibreInspect;
2932
-
2933
- }));
2934
- //# sourceMappingURL=maplibre-gl-inspect.js.map