@evergis/common 1.0.0 → 1.0.2-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/common.esm.js +1681 -1679
- package/dist/common.esm.js.map +1 -1
- package/dist/index.js +1690 -1688
- package/dist/index.js.map +1 -1
- package/package.json +17 -5
package/dist/index.js
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var mapboxGlStyleSpec = require('@mapbox/mapbox-gl-style-spec');
|
|
4
|
-
var
|
|
5
|
-
var
|
|
6
|
-
var
|
|
4
|
+
var isEmpty = require('lodash.isempty');
|
|
5
|
+
var isEqual = require('lodash.isequal');
|
|
6
|
+
var isNil = require('lodash.isnil');
|
|
7
7
|
var dateFns = require('date-fns');
|
|
8
8
|
var locale = require('date-fns/locale');
|
|
9
9
|
var api = require('@evergis/api');
|
|
10
10
|
var wkt = require('wkt');
|
|
11
|
+
var turf = require('@turf/turf');
|
|
12
|
+
var uuid = require('uuid');
|
|
11
13
|
|
|
12
14
|
/* ---------------------------------------------------------------------------------------------------------------- *
|
|
13
15
|
* Data-driven style information provided according to https://docs.mapbox.com/style-spec/reference/layers/ *
|
|
@@ -349,1793 +351,1793 @@ const SPEC_PROP_VALUE_OPTIONS = {
|
|
|
349
351
|
},
|
|
350
352
|
};
|
|
351
353
|
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
354
|
+
/**
|
|
355
|
+
* Returns true if n is a finite number, otherwise false
|
|
356
|
+
* @param n
|
|
357
|
+
*/
|
|
358
|
+
const isNumber = function (n) {
|
|
359
|
+
return typeof n === 'number' && isFinite(n);
|
|
360
|
+
};
|
|
361
|
+
/**
|
|
362
|
+
* Returns true if s is a string, otherwise false
|
|
363
|
+
* @param s
|
|
364
|
+
*/
|
|
365
|
+
const isString = function (s) {
|
|
366
|
+
return typeof s === 'string';
|
|
367
|
+
};
|
|
368
|
+
|
|
369
|
+
/**
|
|
370
|
+
* Utility class for working with different representations of colors in browsers
|
|
371
|
+
* @alias sGis.utils.Color
|
|
372
|
+
*/
|
|
373
|
+
class Color {
|
|
374
|
+
/**
|
|
375
|
+
* @param string - any valid css color string
|
|
376
|
+
*/
|
|
377
|
+
constructor(string) {
|
|
378
|
+
this._original = string;
|
|
379
|
+
if (!isString(string))
|
|
380
|
+
string = string.toString();
|
|
381
|
+
this._color = string && string.trim() || 'transparent';
|
|
382
|
+
this._setChannels();
|
|
357
383
|
}
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
384
|
+
_setChannels() {
|
|
385
|
+
let format = this.format;
|
|
386
|
+
if (format && formats[format]) {
|
|
387
|
+
this._channels = formats[format](this._color);
|
|
361
388
|
}
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
console.error("Validate client style:", "`paint` prop is mandatory", "\n");
|
|
365
|
-
}
|
|
366
|
-
return false;
|
|
389
|
+
else {
|
|
390
|
+
this._channels = { r: NaN, g: NaN, b: NaN, a: NaN };
|
|
367
391
|
}
|
|
368
|
-
return clientStyle.items.every(item => Object.entries({ ...item.layout, ...item.paint }).every(([key, value]) => this.validateSpecPropValue(key, value)));
|
|
369
|
-
}
|
|
370
|
-
getSpecPropValueOptions(key) {
|
|
371
|
-
return SPEC_PROP_VALUE_OPTIONS[key];
|
|
372
|
-
}
|
|
373
|
-
isHeatmapColorValid(value) {
|
|
374
|
-
return (mapboxGlStyleSpec.expression.isExpression(value) &&
|
|
375
|
-
lodash.isEqual(value[0], "interpolate") &&
|
|
376
|
-
lodash.isEqual(value[1], ["linear"]) &&
|
|
377
|
-
lodash.isEqual(value[2], ["heatmap-density"]) &&
|
|
378
|
-
value.length % 2 !== 0 &&
|
|
379
|
-
value.length > 3 &&
|
|
380
|
-
value
|
|
381
|
-
.slice(3)
|
|
382
|
-
.filter((_, i) => i % 2 === 0)
|
|
383
|
-
.every(e => typeof e === "number") &&
|
|
384
|
-
value
|
|
385
|
-
.slice(3)
|
|
386
|
-
.filter((_, i) => i % 2 !== 0)
|
|
387
|
-
.every(e => typeof e === "string"));
|
|
388
|
-
}
|
|
389
|
-
isZoomInterpolate(value) {
|
|
390
|
-
return Array.isArray(value) && value[0] === "interpolate" && Array.isArray(value[2]) && value[2][0] === "zoom";
|
|
391
392
|
}
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
393
|
+
get _min() { return Math.min(this._channels.r, this._channels.g, this._channels.b); }
|
|
394
|
+
get _max() { return Math.max(this._channels.r, this._channels.g, this._channels.b); }
|
|
395
|
+
get _delta() { return this._max - this._min; }
|
|
396
|
+
/**
|
|
397
|
+
* Returns the color as a string in the requested format
|
|
398
|
+
* @param format - target format. Available values: "hex" - #AARRGGBB, "rgb" - "rgb(r, g, b)", "rgba" - "rgba(r, g, b, a)"
|
|
399
|
+
*/
|
|
400
|
+
toString(format) {
|
|
401
|
+
if (format === 'hex') {
|
|
402
|
+
return '#' + decToHex(this.r) + decToHex(this.g) + decToHex(this.b) + decToHex(this.a);
|
|
398
403
|
}
|
|
399
|
-
if (
|
|
400
|
-
|
|
401
|
-
console.error("Validate supported concat expression:", "not an expression", key, value, "\n");
|
|
402
|
-
}
|
|
403
|
-
return false;
|
|
404
|
+
else if (format === 'rgb') {
|
|
405
|
+
return 'rgb(' + this.r + ',' + this.g + ',' + this.b + ')';
|
|
404
406
|
}
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
value
|
|
408
|
-
.slice(1)
|
|
409
|
-
.every(i => typeof i === "string" || (Array.isArray(i) && i[0] === "get" && typeof i[1] === "string"));
|
|
410
|
-
if (!result) {
|
|
411
|
-
if (this.options.verbose) {
|
|
412
|
-
console.error("Validate supported concat expression:", "invalid expression", key, value, "\n");
|
|
413
|
-
}
|
|
407
|
+
else {
|
|
408
|
+
return 'rgba(' + this.r + ',' + this.g + ',' + this.b + ',' + (this.a / 255).toFixed(2).replace(/\.*0+$/, '') + ')';
|
|
414
409
|
}
|
|
415
|
-
return result;
|
|
416
410
|
}
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
411
|
+
/**
|
|
412
|
+
* Returns the string given to the constructor of the instance
|
|
413
|
+
* @type {String}
|
|
414
|
+
*/
|
|
415
|
+
get original() { return this._original; }
|
|
416
|
+
/**
|
|
417
|
+
* Returns true if the instance represents a valid color, i.e. that after parsing of the string given to the constructor,
|
|
418
|
+
* the format is recognized and values of all channels are resolved to valid numbers.
|
|
419
|
+
* @returns {Boolean}
|
|
420
|
+
*/
|
|
421
|
+
get isValid() { return isNumber(this._channels.a) && isNumber(this._channels.r) && isNumber(this._channels.g) && isNumber(this._channels.b); }
|
|
422
|
+
/**
|
|
423
|
+
* Converts HSV color value into RGB
|
|
424
|
+
* @param h - hue value
|
|
425
|
+
* @param s - saturation value
|
|
426
|
+
* @param v - 'value' value
|
|
427
|
+
*/
|
|
428
|
+
setHsv(h, s, v) {
|
|
429
|
+
let rgbColors = [];
|
|
430
|
+
h /= 60;
|
|
431
|
+
s /= 100;
|
|
432
|
+
v /= 100;
|
|
433
|
+
let floor = Math.floor(h);
|
|
434
|
+
let mod = floor % 6;
|
|
435
|
+
let f = h - floor;
|
|
436
|
+
let p = Math.round(255 * v * (1 - s));
|
|
437
|
+
let q = Math.round(255 * v * (1 - s * f));
|
|
438
|
+
let t = Math.round(255 * v * (1 - s * (1 - f)));
|
|
439
|
+
v = Math.round(255 * v);
|
|
440
|
+
switch (mod) {
|
|
441
|
+
case 0:
|
|
442
|
+
rgbColors = [v, t, p];
|
|
443
|
+
break;
|
|
444
|
+
case 1:
|
|
445
|
+
rgbColors = [q, v, p];
|
|
446
|
+
break;
|
|
447
|
+
case 2:
|
|
448
|
+
rgbColors = [p, v, t];
|
|
449
|
+
break;
|
|
450
|
+
case 3:
|
|
451
|
+
rgbColors = [p, q, v];
|
|
452
|
+
break;
|
|
453
|
+
case 4:
|
|
454
|
+
rgbColors = [t, p, v];
|
|
455
|
+
break;
|
|
456
|
+
case 5:
|
|
457
|
+
rgbColors = [v, p, q];
|
|
458
|
+
break;
|
|
446
459
|
}
|
|
447
|
-
|
|
460
|
+
this._channels.r = rgbColors[0];
|
|
461
|
+
this._channels.g = rgbColors[1];
|
|
462
|
+
this._channels.b = rgbColors[2];
|
|
463
|
+
return this;
|
|
448
464
|
}
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
465
|
+
/**
|
|
466
|
+
* Returns the format of the input color sting. Possible values: hex3, hex6, hex4, hex8, rgb, rgba, name.
|
|
467
|
+
* (name is the named css color values like "white")
|
|
468
|
+
*/
|
|
469
|
+
get format() {
|
|
470
|
+
if (this._color.substr(0, 1) === '#' && this._color.search(/[^#0-9a-fA-F]/) === -1) {
|
|
471
|
+
if (this._color.length === 4) {
|
|
472
|
+
return 'hex3';
|
|
453
473
|
}
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
if (!mapboxGlStyleSpec.expression.isExpression(value)) {
|
|
457
|
-
if (this.options.verbose) {
|
|
458
|
-
console.error("Validate supported case expression:", "not an expression", key, value, "\n");
|
|
474
|
+
else if (this._color.length === 7) {
|
|
475
|
+
return 'hex6';
|
|
459
476
|
}
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
const result = value[0] === "case" &&
|
|
463
|
-
value.length > 3 &&
|
|
464
|
-
value.length % 2 === 0 &&
|
|
465
|
-
value
|
|
466
|
-
.slice(1)
|
|
467
|
-
.filter((_, i) => i % 2 === 0 && i < value.slice(1).length - 1)
|
|
468
|
-
.every(e => Array.isArray(e) &&
|
|
469
|
-
e[0] === "all" &&
|
|
470
|
-
e.length > 1 &&
|
|
471
|
-
e
|
|
472
|
-
.slice(1)
|
|
473
|
-
.every(ce => Array.isArray(ce) &&
|
|
474
|
-
ce.length === 3 &&
|
|
475
|
-
[">=", ">", "<", "<="].includes(ce[0]) &&
|
|
476
|
-
ce[1][0] === "get" &&
|
|
477
|
-
typeof ce[1][1] === "string" &&
|
|
478
|
-
typeof ce[2] === "number")) &&
|
|
479
|
-
value
|
|
480
|
-
.slice(1)
|
|
481
|
-
.filter((_, i) => i % 2 !== 0)
|
|
482
|
-
.every(e => typeof e === "number" ||
|
|
483
|
-
typeof e === "string" ||
|
|
484
|
-
(key === "text-field" && this.validateSupportedConcatExpression(key, e))) &&
|
|
485
|
-
(typeof value[value.slice(1).length - 1] === "number" ||
|
|
486
|
-
typeof value[value.slice(1).length - 1] === "string" ||
|
|
487
|
-
(key === "text-field" && this.validateSupportedConcatExpression(key, value)));
|
|
488
|
-
if (!result) {
|
|
489
|
-
if (this.options.verbose) {
|
|
490
|
-
console.error("Validate supported case expression:", "invalid expression", key, value, "\n");
|
|
477
|
+
else if (this._color.length === 5) {
|
|
478
|
+
return 'hex4';
|
|
491
479
|
}
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
}
|
|
495
|
-
validateSupportedStepExpression(key, value) {
|
|
496
|
-
if (!this.getSpecPropValueOptions(key)?.dataExpressionSupport) {
|
|
497
|
-
if (this.options.verbose) {
|
|
498
|
-
console.error("Validate supported step expression:", "expression not supported", key, value, "\n");
|
|
480
|
+
else if (this._color.length === 9) {
|
|
481
|
+
return 'hex8';
|
|
499
482
|
}
|
|
500
|
-
return false;
|
|
501
483
|
}
|
|
502
|
-
if (
|
|
503
|
-
|
|
504
|
-
console.error("Validate supported step expression:", "not an expression", key, value, "\n");
|
|
505
|
-
}
|
|
506
|
-
return false;
|
|
484
|
+
else if (this._color.substr(0, 4) === 'rgb(') {
|
|
485
|
+
return 'rgb';
|
|
507
486
|
}
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
value[1].length === 2 &&
|
|
511
|
-
value[1][0] === "get" &&
|
|
512
|
-
typeof value[1][1] === "string" &&
|
|
513
|
-
value.length > 3 &&
|
|
514
|
-
value.length % 2 !== 0 &&
|
|
515
|
-
value
|
|
516
|
-
.slice(2)
|
|
517
|
-
.filter((_, i) => i % 2 === 0)
|
|
518
|
-
.every(e => typeof e === "number" ||
|
|
519
|
-
typeof e === "string" ||
|
|
520
|
-
(key === "text-field" && this.validateSupportedConcatExpression(key, e))) &&
|
|
521
|
-
value
|
|
522
|
-
.slice(2)
|
|
523
|
-
.filter((_, i) => i % 2 !== 0)
|
|
524
|
-
.every(e => typeof e === "number");
|
|
525
|
-
if (!result) {
|
|
526
|
-
if (this.options.verbose) {
|
|
527
|
-
console.error("Validate supported step expression:", "invalid expression", key, value, "\n");
|
|
528
|
-
}
|
|
529
|
-
}
|
|
530
|
-
return result;
|
|
531
|
-
}
|
|
532
|
-
validateLinearZoomInterpolate(key, value) {
|
|
533
|
-
return (this.getSpecPropValueOptions(key)?.interpolateExpressionSupport &&
|
|
534
|
-
lodash.isEqual(value[0], "interpolate") &&
|
|
535
|
-
lodash.isEqual(value[1], ["linear"]) &&
|
|
536
|
-
lodash.isEqual(value[2], ["zoom"]) &&
|
|
537
|
-
value.length % 2 !== 0 &&
|
|
538
|
-
value.length > 4 &&
|
|
539
|
-
value
|
|
540
|
-
.slice(3)
|
|
541
|
-
.filter((_, i) => i % 2 === 0)
|
|
542
|
-
.every(e => typeof e === "number") &&
|
|
543
|
-
value
|
|
544
|
-
.slice(3)
|
|
545
|
-
.filter((_, i) => i % 2 !== 0)
|
|
546
|
-
.every(e => {
|
|
547
|
-
return (typeof e === "number" ||
|
|
548
|
-
typeof e === "string" ||
|
|
549
|
-
this.validateSupportedExpression(key, e, true) ||
|
|
550
|
-
(key === "text-field" && this.validateSupportedConcatExpression(key, e)));
|
|
551
|
-
}));
|
|
552
|
-
}
|
|
553
|
-
validateExponentialZoomInterpolate(key, value) {
|
|
554
|
-
return (this.getSpecPropValueOptions(key)?.interpolateExpressionSupport &&
|
|
555
|
-
lodash.isEqual(value[0], "interpolate") &&
|
|
556
|
-
Array.isArray(value[1]) &&
|
|
557
|
-
value[1].length === 2 &&
|
|
558
|
-
value[1][0] === "exponential" &&
|
|
559
|
-
typeof value[1][1] === "number" &&
|
|
560
|
-
lodash.isEqual(value[2], ["zoom"]) &&
|
|
561
|
-
value.length % 2 !== 0 &&
|
|
562
|
-
value.length > 4 &&
|
|
563
|
-
value
|
|
564
|
-
.slice(3)
|
|
565
|
-
.filter((_, i) => i % 2 === 0)
|
|
566
|
-
.every(e => typeof e === "number") &&
|
|
567
|
-
value
|
|
568
|
-
.slice(3)
|
|
569
|
-
.filter((_, i) => i % 2 !== 0)
|
|
570
|
-
.every(e => {
|
|
571
|
-
return (typeof e === "number" ||
|
|
572
|
-
typeof e === "string" ||
|
|
573
|
-
this.validateSupportedExpression(key, e, true) ||
|
|
574
|
-
(key === "text-field" && this.validateSupportedConcatExpression(key, e)));
|
|
575
|
-
}));
|
|
576
|
-
}
|
|
577
|
-
validateCubicBezierZoomInterpolate(key, value) {
|
|
578
|
-
return (this.getSpecPropValueOptions(key)?.interpolateExpressionSupport &&
|
|
579
|
-
lodash.isEqual(value[0], "interpolate") &&
|
|
580
|
-
Array.isArray(value[1]) &&
|
|
581
|
-
value[1].length === 5 &&
|
|
582
|
-
value[1][0] === "cubic-bezier" &&
|
|
583
|
-
value[1].slice(1).every(e => typeof e === "number") &&
|
|
584
|
-
lodash.isEqual(value[2], ["zoom"]) &&
|
|
585
|
-
value.length % 2 !== 0 &&
|
|
586
|
-
value.length > 4 &&
|
|
587
|
-
value
|
|
588
|
-
.slice(3)
|
|
589
|
-
.filter((_, i) => i % 2 === 0)
|
|
590
|
-
.every(e => typeof e === "number") &&
|
|
591
|
-
value
|
|
592
|
-
.slice(3)
|
|
593
|
-
.filter((_, i) => i % 2 !== 0)
|
|
594
|
-
.every(e => {
|
|
595
|
-
return (typeof e === "number" ||
|
|
596
|
-
typeof e === "string" ||
|
|
597
|
-
this.validateSupportedExpression(key, e, true) ||
|
|
598
|
-
(key === "text-field" && this.validateSupportedConcatExpression(key, e)));
|
|
599
|
-
}));
|
|
600
|
-
}
|
|
601
|
-
validateLinearDataInterpolate(key, value) {
|
|
602
|
-
return (this.getSpecPropValueOptions(key)?.dataExpressionSupport &&
|
|
603
|
-
lodash.isEqual(value[0], "interpolate") &&
|
|
604
|
-
lodash.isEqual(value[1], ["linear"]) &&
|
|
605
|
-
Array.isArray(value[2]) &&
|
|
606
|
-
value[2].length === 2 &&
|
|
607
|
-
value[2][0] === "get" &&
|
|
608
|
-
typeof value[2][1] === "string" &&
|
|
609
|
-
value.length % 2 !== 0 &&
|
|
610
|
-
value.length > 4 &&
|
|
611
|
-
value
|
|
612
|
-
.slice(3)
|
|
613
|
-
.filter((_, i) => i % 2 === 0)
|
|
614
|
-
.every(e => typeof e === "number") &&
|
|
615
|
-
value
|
|
616
|
-
.slice(3)
|
|
617
|
-
.filter((_, i) => i % 2 !== 0)
|
|
618
|
-
.every(e => typeof e === "number" ||
|
|
619
|
-
typeof e === "string" ||
|
|
620
|
-
(key === "text-field" && this.validateSupportedConcatExpression(key, e))));
|
|
621
|
-
}
|
|
622
|
-
validateExponentialDataInterpolate(key, value) {
|
|
623
|
-
return (this.getSpecPropValueOptions(key)?.dataExpressionSupport &&
|
|
624
|
-
lodash.isEqual(value[0], "interpolate") &&
|
|
625
|
-
Array.isArray(value[1]) &&
|
|
626
|
-
value[1].length === 2 &&
|
|
627
|
-
value[1][0] === "exponential" &&
|
|
628
|
-
typeof value[1][1] === "number" &&
|
|
629
|
-
Array.isArray(value[2]) &&
|
|
630
|
-
value[2].length === 2 &&
|
|
631
|
-
value[2][0] === "get" &&
|
|
632
|
-
typeof value[2][1] === "string" &&
|
|
633
|
-
value.length % 2 !== 0 &&
|
|
634
|
-
value.length > 4 &&
|
|
635
|
-
value
|
|
636
|
-
.slice(3)
|
|
637
|
-
.filter((_, i) => i % 2 === 0)
|
|
638
|
-
.every(e => typeof e === "number") &&
|
|
639
|
-
value
|
|
640
|
-
.slice(3)
|
|
641
|
-
.filter((_, i) => i % 2 !== 0)
|
|
642
|
-
.every(e => typeof e === "number" ||
|
|
643
|
-
typeof e === "string" ||
|
|
644
|
-
(key === "text-field" && this.validateSupportedConcatExpression(key, e))));
|
|
645
|
-
}
|
|
646
|
-
validateCubicBezierDataInterpolate(key, value) {
|
|
647
|
-
return (this.getSpecPropValueOptions(key)?.dataExpressionSupport &&
|
|
648
|
-
lodash.isEqual(value[0], "interpolate") &&
|
|
649
|
-
Array.isArray(value[1]) &&
|
|
650
|
-
value[1].length === 5 &&
|
|
651
|
-
value[1][0] === "cubic-bezier" &&
|
|
652
|
-
value[1].slice(1).every(e => typeof e === "number") &&
|
|
653
|
-
Array.isArray(value[2]) &&
|
|
654
|
-
value[2].length === 2 &&
|
|
655
|
-
value[2][0] === "get" &&
|
|
656
|
-
typeof value[2][1] === "string" &&
|
|
657
|
-
value.length % 2 !== 0 &&
|
|
658
|
-
value.length > 4 &&
|
|
659
|
-
value
|
|
660
|
-
.slice(3)
|
|
661
|
-
.filter((_, i) => i % 2 === 0)
|
|
662
|
-
.every(e => typeof e === "number") &&
|
|
663
|
-
value
|
|
664
|
-
.slice(3)
|
|
665
|
-
.filter((_, i) => i % 2 !== 0)
|
|
666
|
-
.every(e => typeof e === "number" ||
|
|
667
|
-
typeof e === "string" ||
|
|
668
|
-
(key === "text-field" && this.validateSupportedConcatExpression(key, e))));
|
|
669
|
-
}
|
|
670
|
-
validateZoomInterpolate(key, value) {
|
|
671
|
-
return (this.validateLinearZoomInterpolate(key, value) ||
|
|
672
|
-
this.validateExponentialZoomInterpolate(key, value) ||
|
|
673
|
-
this.validateCubicBezierZoomInterpolate(key, value));
|
|
674
|
-
}
|
|
675
|
-
validateDataInterpolate(key, value) {
|
|
676
|
-
return (this.validateLinearDataInterpolate(key, value) ||
|
|
677
|
-
this.validateExponentialDataInterpolate(key, value) ||
|
|
678
|
-
this.validateCubicBezierDataInterpolate(key, value));
|
|
679
|
-
}
|
|
680
|
-
validateSupportedInterpolateExpression(key, value, excludeZoomInterpolate) {
|
|
681
|
-
if (!mapboxGlStyleSpec.expression.isExpression(value)) {
|
|
682
|
-
if (this.options.verbose) {
|
|
683
|
-
console.error("Validate supported interpolate expression:", "not an expression", key, value, "\n");
|
|
684
|
-
}
|
|
685
|
-
return false;
|
|
686
|
-
}
|
|
687
|
-
if (key === "heatmap-color") {
|
|
688
|
-
const isColorValid = this.isHeatmapColorValid(value);
|
|
689
|
-
if (!isColorValid) {
|
|
690
|
-
if (this.options.verbose) {
|
|
691
|
-
console.error("Validate supported interpolate expression:", "invalid color value", key, value, "\n");
|
|
692
|
-
}
|
|
693
|
-
}
|
|
694
|
-
return this.isHeatmapColorValid(value);
|
|
695
|
-
}
|
|
696
|
-
if (!this.getSpecPropValueOptions(key)?.interpolateExpressionSupport &&
|
|
697
|
-
!this.getSpecPropValueOptions(key)?.dataExpressionSupport) {
|
|
698
|
-
if (this.options.verbose) {
|
|
699
|
-
console.error("Validate supported interpolate expression:", "interpolate not supported", key, value, "\n");
|
|
700
|
-
}
|
|
701
|
-
}
|
|
702
|
-
const result = (!excludeZoomInterpolate && this.validateZoomInterpolate(key, value)) || this.validateDataInterpolate(key, value);
|
|
703
|
-
if (!result) {
|
|
704
|
-
if (this.options.verbose) {
|
|
705
|
-
console.error("Validate supported interpolate expression:", "invalid expression", key, value, "\n");
|
|
706
|
-
}
|
|
707
|
-
}
|
|
708
|
-
return result;
|
|
709
|
-
}
|
|
710
|
-
validateSupportedExpression(key, value, excludeZoomInterpolate) {
|
|
711
|
-
if (!mapboxGlStyleSpec.expression.isExpression(value)) {
|
|
712
|
-
if (this.options.verbose) {
|
|
713
|
-
console.error("Validate supported expression:", "not an expression", key, value, "\n");
|
|
714
|
-
}
|
|
715
|
-
return false;
|
|
716
|
-
}
|
|
717
|
-
const expressionType = value[0];
|
|
718
|
-
if (typeof expressionType !== "string" ||
|
|
719
|
-
!["match", "case", "step", "interpolate", "concat"].includes(expressionType)) {
|
|
720
|
-
if (this.options.verbose) {
|
|
721
|
-
console.error("Validate supported expression:", "expression type not supported", key, value, "\n");
|
|
722
|
-
}
|
|
723
|
-
return false;
|
|
724
|
-
}
|
|
725
|
-
switch (expressionType) {
|
|
726
|
-
case "match":
|
|
727
|
-
return this.validateSupportedMatchExpression(key, value);
|
|
728
|
-
case "case":
|
|
729
|
-
return this.validateSupportedCaseExpression(key, value);
|
|
730
|
-
case "step":
|
|
731
|
-
return this.validateSupportedStepExpression(key, value);
|
|
732
|
-
case "concat":
|
|
733
|
-
return this.validateSupportedConcatExpression(key, value);
|
|
734
|
-
case "interpolate":
|
|
735
|
-
return this.validateSupportedInterpolateExpression(key, value, excludeZoomInterpolate);
|
|
736
|
-
default:
|
|
737
|
-
return false;
|
|
487
|
+
else if (this._color.substr(0, 5) === 'rgba(') {
|
|
488
|
+
return 'rgba';
|
|
738
489
|
}
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
const propValueOptions = this.getSpecPropValueOptions(key.replace(/-transition$/, ""));
|
|
742
|
-
if (propValueOptions && propValueOptions.transitionable === false) {
|
|
743
|
-
if (this.options.verbose) {
|
|
744
|
-
console.error("Validate transition value:", "transition not supported", key, value, "\n");
|
|
745
|
-
}
|
|
746
|
-
return false;
|
|
490
|
+
else if (this._color.substr(0, 4) === 'hsv(') {
|
|
491
|
+
return 'hsv';
|
|
747
492
|
}
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
("duration" in value && typeof value.duration === "number"));
|
|
751
|
-
if (!result) {
|
|
752
|
-
if (this.options.verbose) {
|
|
753
|
-
console.error("Validate transition value:", "invalid transition value", key, value, "\n");
|
|
754
|
-
}
|
|
493
|
+
else if (this._color in Color.names) {
|
|
494
|
+
return 'name';
|
|
755
495
|
}
|
|
756
|
-
return result;
|
|
757
496
|
}
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
}
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
497
|
+
/**
|
|
498
|
+
* Returns red channel value as integer from 0 to 255.
|
|
499
|
+
*/
|
|
500
|
+
get r() { return this._channels.r; }
|
|
501
|
+
set r(v) { this._channels.r = v; }
|
|
502
|
+
/**
|
|
503
|
+
* Returns green channel value as integer from 0 to 255.
|
|
504
|
+
*/
|
|
505
|
+
get g() { return this._channels.g; }
|
|
506
|
+
set g(v) { this._channels.g = v; }
|
|
507
|
+
/**
|
|
508
|
+
* Returns blue channel value as integer from 0 to 255.
|
|
509
|
+
*/
|
|
510
|
+
get b() { return this._channels.b; }
|
|
511
|
+
set b(v) { this._channels.b = v; }
|
|
512
|
+
/**
|
|
513
|
+
* Returns opacity channel value as integer from 0 to 255.
|
|
514
|
+
*/
|
|
515
|
+
get a() { return this._channels.a; }
|
|
516
|
+
set a(v) { this._channels.a = v; }
|
|
517
|
+
/**
|
|
518
|
+
* Returns hue channel value as integer from 0 to 360.
|
|
519
|
+
*/
|
|
520
|
+
get h() {
|
|
521
|
+
let max = this._max;
|
|
522
|
+
let min = this._min;
|
|
523
|
+
let delta = this._delta;
|
|
524
|
+
let h;
|
|
525
|
+
let { r, g, b } = this._channels;
|
|
526
|
+
if (max === min)
|
|
527
|
+
h = 0;
|
|
528
|
+
else if (r === max)
|
|
529
|
+
h = (g - b) / delta;
|
|
530
|
+
else if (g === max)
|
|
531
|
+
h = 2 + (b - r) / delta;
|
|
532
|
+
else if (b === max)
|
|
533
|
+
h = 4 + (r - g) / delta;
|
|
534
|
+
h = Math.min(h * 60, 360);
|
|
535
|
+
if (h < 0)
|
|
536
|
+
h += 360;
|
|
537
|
+
h = Math.round(h);
|
|
538
|
+
return h;
|
|
797
539
|
}
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
540
|
+
/**
|
|
541
|
+
* Returns saturation channel value as integer from 0 to 100.
|
|
542
|
+
*/
|
|
543
|
+
get s() {
|
|
544
|
+
let s;
|
|
545
|
+
let max = this._max;
|
|
546
|
+
if (max === 0)
|
|
547
|
+
s = 0;
|
|
548
|
+
else
|
|
549
|
+
s = this._delta / max * 1000 / 10;
|
|
550
|
+
s = Math.round(s);
|
|
551
|
+
return s;
|
|
802
552
|
}
|
|
803
|
-
|
|
553
|
+
/**
|
|
554
|
+
* Returns 'value' channel of hsv space as integer from 0 to 100.
|
|
555
|
+
*/
|
|
556
|
+
get v() { return Math.round(this._max / 255 * 1000 / 10); }
|
|
557
|
+
/**
|
|
558
|
+
* Returns values of the channels as integers from 0 to 255. Format is { r: r, g: g, b: b, a: a }.
|
|
559
|
+
*/
|
|
560
|
+
get channels() { return Object.assign({}, this._channels); }
|
|
561
|
+
}
|
|
562
|
+
// Big List of Colors
|
|
563
|
+
// ------------------
|
|
564
|
+
// <http://www.w3.org/TR/css3-color/#svg-color>
|
|
565
|
+
//noinspection SpellCheckingInspection
|
|
566
|
+
Color.names = {
|
|
567
|
+
aliceblue: "f0f8ff",
|
|
568
|
+
antiquewhite: "faebd7",
|
|
569
|
+
aqua: "0ff",
|
|
570
|
+
aquamarine: "7fffd4",
|
|
571
|
+
azure: "f0ffff",
|
|
572
|
+
beige: "f5f5dc",
|
|
573
|
+
bisque: "ffe4c4",
|
|
574
|
+
black: "000",
|
|
575
|
+
blanchedalmond: "ffebcd",
|
|
576
|
+
blue: "00f",
|
|
577
|
+
blueviolet: "8a2be2",
|
|
578
|
+
brown: "a52a2a",
|
|
579
|
+
burlywood: "deb887",
|
|
580
|
+
burntsienna: "ea7e5d",
|
|
581
|
+
cadetblue: "5f9ea0",
|
|
582
|
+
chartreuse: "7fff00",
|
|
583
|
+
chocolate: "d2691e",
|
|
584
|
+
coral: "ff7f50",
|
|
585
|
+
cornflowerblue: "6495ed",
|
|
586
|
+
cornsilk: "fff8dc",
|
|
587
|
+
crimson: "dc143c",
|
|
588
|
+
cyan: "0ff",
|
|
589
|
+
darkblue: "00008b",
|
|
590
|
+
darkcyan: "008b8b",
|
|
591
|
+
darkgoldenrod: "b8860b",
|
|
592
|
+
darkgray: "a9a9a9",
|
|
593
|
+
darkgreen: "006400",
|
|
594
|
+
darkgrey: "a9a9a9",
|
|
595
|
+
darkkhaki: "bdb76b",
|
|
596
|
+
darkmagenta: "8b008b",
|
|
597
|
+
darkolivegreen: "556b2f",
|
|
598
|
+
darkorange: "ff8c00",
|
|
599
|
+
darkorchid: "9932cc",
|
|
600
|
+
darkred: "8b0000",
|
|
601
|
+
darksalmon: "e9967a",
|
|
602
|
+
darkseagreen: "8fbc8f",
|
|
603
|
+
darkslateblue: "483d8b",
|
|
604
|
+
darkslategray: "2f4f4f",
|
|
605
|
+
darkslategrey: "2f4f4f",
|
|
606
|
+
darkturquoise: "00ced1",
|
|
607
|
+
darkviolet: "9400d3",
|
|
608
|
+
deeppink: "ff1493",
|
|
609
|
+
deepskyblue: "00bfff",
|
|
610
|
+
dimgray: "696969",
|
|
611
|
+
dimgrey: "696969",
|
|
612
|
+
dodgerblue: "1e90ff",
|
|
613
|
+
firebrick: "b22222",
|
|
614
|
+
floralwhite: "fffaf0",
|
|
615
|
+
forestgreen: "228b22",
|
|
616
|
+
fuchsia: "f0f",
|
|
617
|
+
gainsboro: "dcdcdc",
|
|
618
|
+
ghostwhite: "f8f8ff",
|
|
619
|
+
gold: "ffd700",
|
|
620
|
+
goldenrod: "daa520",
|
|
621
|
+
gray: "808080",
|
|
622
|
+
green: "008000",
|
|
623
|
+
greenyellow: "adff2f",
|
|
624
|
+
grey: "808080",
|
|
625
|
+
honeydew: "f0fff0",
|
|
626
|
+
hotpink: "ff69b4",
|
|
627
|
+
indianred: "cd5c5c",
|
|
628
|
+
indigo: "4b0082",
|
|
629
|
+
ivory: "fffff0",
|
|
630
|
+
khaki: "f0e68c",
|
|
631
|
+
lavender: "e6e6fa",
|
|
632
|
+
lavenderblush: "fff0f5",
|
|
633
|
+
lawngreen: "7cfc00",
|
|
634
|
+
lemonchiffon: "fffacd",
|
|
635
|
+
lightblue: "add8e6",
|
|
636
|
+
lightcoral: "f08080",
|
|
637
|
+
lightcyan: "e0ffff",
|
|
638
|
+
lightgoldenrodyellow: "fafad2",
|
|
639
|
+
lightgray: "d3d3d3",
|
|
640
|
+
lightgreen: "90ee90",
|
|
641
|
+
lightgrey: "d3d3d3",
|
|
642
|
+
lightpink: "ffb6c1",
|
|
643
|
+
lightsalmon: "ffa07a",
|
|
644
|
+
lightseagreen: "20b2aa",
|
|
645
|
+
lightskyblue: "87cefa",
|
|
646
|
+
lightslategray: "789",
|
|
647
|
+
lightslategrey: "789",
|
|
648
|
+
lightsteelblue: "b0c4de",
|
|
649
|
+
lightyellow: "ffffe0",
|
|
650
|
+
lime: "0f0",
|
|
651
|
+
limegreen: "32cd32",
|
|
652
|
+
linen: "faf0e6",
|
|
653
|
+
magenta: "f0f",
|
|
654
|
+
maroon: "800000",
|
|
655
|
+
mediumaquamarine: "66cdaa",
|
|
656
|
+
mediumblue: "0000cd",
|
|
657
|
+
mediumorchid: "ba55d3",
|
|
658
|
+
mediumpurple: "9370db",
|
|
659
|
+
mediumseagreen: "3cb371",
|
|
660
|
+
mediumslateblue: "7b68ee",
|
|
661
|
+
mediumspringgreen: "00fa9a",
|
|
662
|
+
mediumturquoise: "48d1cc",
|
|
663
|
+
mediumvioletred: "c71585",
|
|
664
|
+
midnightblue: "191970",
|
|
665
|
+
mintcream: "f5fffa",
|
|
666
|
+
mistyrose: "ffe4e1",
|
|
667
|
+
moccasin: "ffe4b5",
|
|
668
|
+
navajowhite: "ffdead",
|
|
669
|
+
navy: "000080",
|
|
670
|
+
oldlace: "fdf5e6",
|
|
671
|
+
olive: "808000",
|
|
672
|
+
olivedrab: "6b8e23",
|
|
673
|
+
orange: "ffa500",
|
|
674
|
+
orangered: "ff4500",
|
|
675
|
+
orchid: "da70d6",
|
|
676
|
+
palegoldenrod: "eee8aa",
|
|
677
|
+
palegreen: "98fb98",
|
|
678
|
+
paleturquoise: "afeeee",
|
|
679
|
+
palevioletred: "db7093",
|
|
680
|
+
papayawhip: "ffefd5",
|
|
681
|
+
peachpuff: "ffdab9",
|
|
682
|
+
peru: "cd853f",
|
|
683
|
+
pink: "ffc0cb",
|
|
684
|
+
plum: "dda0dd",
|
|
685
|
+
powderblue: "b0e0e6",
|
|
686
|
+
purple: "800080",
|
|
687
|
+
rebeccapurple: "663399",
|
|
688
|
+
red: "f00",
|
|
689
|
+
rosybrown: "bc8f8f",
|
|
690
|
+
royalblue: "4169e1",
|
|
691
|
+
saddlebrown: "8b4513",
|
|
692
|
+
salmon: "fa8072",
|
|
693
|
+
sandybrown: "f4a460",
|
|
694
|
+
seagreen: "2e8b57",
|
|
695
|
+
seashell: "fff5ee",
|
|
696
|
+
sienna: "a0522d",
|
|
697
|
+
silver: "c0c0c0",
|
|
698
|
+
skyblue: "87ceeb",
|
|
699
|
+
slateblue: "6a5acd",
|
|
700
|
+
slategray: "708090",
|
|
701
|
+
slategrey: "708090",
|
|
702
|
+
snow: "fffafa",
|
|
703
|
+
springgreen: "00ff7f",
|
|
704
|
+
steelblue: "4682b4",
|
|
705
|
+
tan: "d2b48c",
|
|
706
|
+
teal: "008080",
|
|
707
|
+
thistle: "d8bfd8",
|
|
708
|
+
tomato: "ff6347",
|
|
709
|
+
turquoise: "40e0d0",
|
|
710
|
+
violet: "ee82ee",
|
|
711
|
+
wheat: "f5deb3",
|
|
712
|
+
white: "fff",
|
|
713
|
+
whitesmoke: "f5f5f5",
|
|
714
|
+
yellow: "ff0",
|
|
715
|
+
yellowgreen: "9acd32",
|
|
716
|
+
transparent: '0000'
|
|
804
717
|
};
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
return
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
};
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
return [];
|
|
861
|
-
}
|
|
862
|
-
return style?.items?.reduce((acc, curr) => {
|
|
863
|
-
const paintAttributes = extractAttributesFromObject(curr.paint);
|
|
864
|
-
const layoutAttributes = extractAttributesFromObject(curr.layout);
|
|
865
|
-
const filterAttributes = curr.filter
|
|
866
|
-
? findAttributeInExpression(curr.filter)
|
|
867
|
-
: [];
|
|
868
|
-
return [...new Set([...acc, ...paintAttributes, ...layoutAttributes, ...filterAttributes])];
|
|
869
|
-
}, []);
|
|
870
|
-
};
|
|
871
|
-
|
|
872
|
-
const DEFAULT_COLOR = "#00ffff";
|
|
873
|
-
const DEFAULT_BLUR = 0;
|
|
874
|
-
const DEFAULT_OPACITY = 0.5;
|
|
875
|
-
const DEFAULT_TRANSLATE = [0, 0];
|
|
876
|
-
const DEFAULT_FILL_EXTRUSION_BASE = 0;
|
|
877
|
-
const DEFAULT_FILL_EXTRUSION_VERTICAL_GRADIENT = true;
|
|
878
|
-
const DEFAULT_FILL_EXTRUSION_HEIGHT = 0;
|
|
879
|
-
const DEFAULT_CIRCLE_RADIUS = 4;
|
|
880
|
-
const DEFAULT_CIRCLE_STROKE_WIDTH = 0;
|
|
881
|
-
const DEFAULT_LINE_WIDTH = 1;
|
|
882
|
-
const DEFAULT_LINE_CAP = "butt";
|
|
883
|
-
const DEFAULT_LINE_JOIN = "miter";
|
|
884
|
-
const DEFAULT_SYMBOL_COLOR = "#000000";
|
|
885
|
-
const DEFAULT_SYMBOL_HALO_COLOR = "#ffffff";
|
|
886
|
-
const DEFAULT_SYMBOL_PLACEMENT = "point";
|
|
887
|
-
const DEFAULT_SYMBOL_SPACING = 250;
|
|
888
|
-
const DEFAULT_ICON_OVERLAP = "never";
|
|
889
|
-
const DEFAULT_ICON_SIZE = 0.5;
|
|
890
|
-
const DEFAULT_ICON_ANCHOR = "center";
|
|
891
|
-
const DEFAULT_ICON_PADDING = [2];
|
|
892
|
-
const DEFAULT_ICON_ROTATE = 0;
|
|
893
|
-
const DEFAULT_TEXT_SIZE = 16;
|
|
894
|
-
const DEFAULT_TEXT_ANCHOR = "center";
|
|
895
|
-
const DEFAULT_TEXT_JUSTIFY = "center";
|
|
896
|
-
const DEFAULT_TEXT_TRANSFORM = "none";
|
|
897
|
-
const DEFAULT_HEATMAP_RADIUS = 30;
|
|
898
|
-
const DEFAULT_HEATMAP_WEIGHT = 1;
|
|
899
|
-
const DEFAULT_HEATMAP_INTENSITY = 1;
|
|
900
|
-
const DEFAULT_HEATMAP_COLOR = [
|
|
901
|
-
"interpolate",
|
|
902
|
-
["linear"],
|
|
903
|
-
["heatmap-density"],
|
|
904
|
-
0, "rgba(0, 0, 255, 0)",
|
|
905
|
-
0.1, "royalblue",
|
|
906
|
-
0.3, "cyan",
|
|
907
|
-
0.5, "lime",
|
|
908
|
-
0.7, "yellow",
|
|
909
|
-
1, "red",
|
|
910
|
-
];
|
|
911
|
-
const DEFAULT_FILL_STYLE = {
|
|
912
|
-
items: [
|
|
913
|
-
{
|
|
914
|
-
type: "fill",
|
|
915
|
-
layout: {},
|
|
916
|
-
paint: {
|
|
917
|
-
"fill-color": DEFAULT_COLOR,
|
|
918
|
-
"fill-opacity": DEFAULT_OPACITY,
|
|
919
|
-
},
|
|
920
|
-
},
|
|
921
|
-
],
|
|
922
|
-
};
|
|
923
|
-
const DEFAULT_FILL_EXTRUSION_STYLE = {
|
|
924
|
-
items: [
|
|
925
|
-
{
|
|
926
|
-
type: "fill-extrusion",
|
|
927
|
-
layout: {},
|
|
928
|
-
paint: {
|
|
929
|
-
"fill-extrusion-base": DEFAULT_FILL_EXTRUSION_BASE,
|
|
930
|
-
"fill-extrusion-vertical-gradient": DEFAULT_FILL_EXTRUSION_VERTICAL_GRADIENT,
|
|
931
|
-
"fill-extrusion-color": DEFAULT_COLOR,
|
|
932
|
-
"fill-extrusion-opacity": DEFAULT_OPACITY,
|
|
933
|
-
"fill-extrusion-height": DEFAULT_FILL_EXTRUSION_HEIGHT,
|
|
934
|
-
},
|
|
935
|
-
},
|
|
936
|
-
],
|
|
937
|
-
};
|
|
938
|
-
const DEFAULT_LINE_STYLE = {
|
|
939
|
-
items: [
|
|
940
|
-
{
|
|
941
|
-
type: "line",
|
|
942
|
-
layout: {
|
|
943
|
-
"line-cap": DEFAULT_LINE_CAP,
|
|
944
|
-
"line-join": DEFAULT_LINE_JOIN,
|
|
945
|
-
},
|
|
946
|
-
paint: {
|
|
947
|
-
"line-color": DEFAULT_COLOR,
|
|
948
|
-
"line-width": DEFAULT_LINE_WIDTH,
|
|
949
|
-
"line-blur": DEFAULT_BLUR,
|
|
950
|
-
"line-opacity": DEFAULT_OPACITY,
|
|
951
|
-
"line-translate": DEFAULT_TRANSLATE,
|
|
952
|
-
},
|
|
953
|
-
},
|
|
954
|
-
],
|
|
955
|
-
};
|
|
956
|
-
const DEFAULT_CIRCLE_STYLE = {
|
|
957
|
-
items: [
|
|
958
|
-
{
|
|
959
|
-
type: "circle",
|
|
960
|
-
layout: {},
|
|
961
|
-
paint: {
|
|
962
|
-
"circle-radius": DEFAULT_CIRCLE_RADIUS,
|
|
963
|
-
"circle-color": DEFAULT_COLOR,
|
|
964
|
-
"circle-blur": DEFAULT_BLUR,
|
|
965
|
-
"circle-opacity": DEFAULT_OPACITY,
|
|
966
|
-
"circle-translate": DEFAULT_TRANSLATE,
|
|
967
|
-
"circle-stroke-width": DEFAULT_CIRCLE_STROKE_WIDTH,
|
|
968
|
-
"circle-stroke-color": DEFAULT_COLOR,
|
|
969
|
-
"circle-stroke-opacity": DEFAULT_OPACITY,
|
|
970
|
-
},
|
|
971
|
-
},
|
|
972
|
-
],
|
|
973
|
-
};
|
|
974
|
-
const DEFAULT_SYMBOL_STYLE = {
|
|
975
|
-
items: [
|
|
976
|
-
{
|
|
977
|
-
type: "symbol",
|
|
978
|
-
layout: {
|
|
979
|
-
"symbol-placement": DEFAULT_SYMBOL_PLACEMENT,
|
|
980
|
-
"symbol-spacing": DEFAULT_SYMBOL_SPACING,
|
|
981
|
-
"icon-overlap": DEFAULT_ICON_OVERLAP,
|
|
982
|
-
"icon-size": DEFAULT_ICON_SIZE,
|
|
983
|
-
"icon-anchor": DEFAULT_ICON_ANCHOR,
|
|
984
|
-
"icon-padding": DEFAULT_ICON_PADDING,
|
|
985
|
-
"icon-rotate": DEFAULT_ICON_ROTATE,
|
|
986
|
-
"text-size": DEFAULT_TEXT_SIZE,
|
|
987
|
-
"text-anchor": DEFAULT_TEXT_ANCHOR,
|
|
988
|
-
"text-justify": DEFAULT_TEXT_JUSTIFY,
|
|
989
|
-
"text-transform": DEFAULT_TEXT_TRANSFORM,
|
|
990
|
-
},
|
|
991
|
-
paint: {
|
|
992
|
-
"icon-color": DEFAULT_SYMBOL_COLOR,
|
|
993
|
-
"icon-halo-color": DEFAULT_SYMBOL_HALO_COLOR,
|
|
994
|
-
"icon-opacity": DEFAULT_OPACITY,
|
|
995
|
-
"text-color": DEFAULT_SYMBOL_COLOR,
|
|
996
|
-
"text-halo-color": DEFAULT_SYMBOL_HALO_COLOR,
|
|
997
|
-
"text-opacity": DEFAULT_OPACITY,
|
|
998
|
-
},
|
|
999
|
-
},
|
|
1000
|
-
],
|
|
1001
|
-
};
|
|
1002
|
-
const DEFAULT_HEATMAP_STYLE = {
|
|
1003
|
-
items: [
|
|
1004
|
-
{
|
|
1005
|
-
type: "heatmap",
|
|
1006
|
-
layout: {},
|
|
1007
|
-
paint: {
|
|
1008
|
-
"heatmap-radius": DEFAULT_HEATMAP_RADIUS,
|
|
1009
|
-
"heatmap-weight": DEFAULT_HEATMAP_WEIGHT,
|
|
1010
|
-
"heatmap-intensity": DEFAULT_HEATMAP_INTENSITY,
|
|
1011
|
-
"heatmap-color": DEFAULT_HEATMAP_COLOR,
|
|
1012
|
-
"heatmap-opacity": DEFAULT_OPACITY,
|
|
1013
|
-
},
|
|
1014
|
-
},
|
|
1015
|
-
],
|
|
1016
|
-
};
|
|
1017
|
-
|
|
1018
|
-
/**
|
|
1019
|
-
* Извлекает имена иконок из выражения icon-image.
|
|
1020
|
-
*
|
|
1021
|
-
* Поддерживает:
|
|
1022
|
-
* - Строки: "parking" → ["parking"]
|
|
1023
|
-
* - match: ["match", ["get", "type"], "a", "icon-a", "b", "icon-b", "default"] → ["icon-a", "icon-b", "default"]
|
|
1024
|
-
* - case: ["case", [...], "icon-a", "icon-b"] → ["icon-a", "icon-b"]
|
|
1025
|
-
* - coalesce: ["coalesce", ["image", "icon-a"], ["image", "icon-b"]] → ["icon-a", "icon-b"]
|
|
1026
|
-
* - image: ["image", "icon-a"] → ["icon-a"]
|
|
1027
|
-
*
|
|
1028
|
-
* @param iconImage - значение icon-image из layout
|
|
1029
|
-
* @returns массив имён иконок
|
|
1030
|
-
*/
|
|
1031
|
-
const parseIconNames = (iconImage) => {
|
|
1032
|
-
if (!iconImage) {
|
|
1033
|
-
return [];
|
|
1034
|
-
}
|
|
1035
|
-
// Простая строка: "parking"
|
|
1036
|
-
if (typeof iconImage === "string") {
|
|
1037
|
-
return [iconImage];
|
|
1038
|
-
}
|
|
1039
|
-
// Выражение Mapbox
|
|
1040
|
-
if (Array.isArray(iconImage) && iconImage.length > 0) {
|
|
1041
|
-
const [operator, ...args] = iconImage;
|
|
1042
|
-
switch (operator) {
|
|
1043
|
-
// ["match", input, label1, output1, label2, output2, ..., fallback]
|
|
1044
|
-
case "match": {
|
|
1045
|
-
const results = [];
|
|
1046
|
-
// Пропускаем первый аргумент (input), берём каждый второй начиная с индекса 2
|
|
1047
|
-
for (let i = 2; i < args.length; i += 2) {
|
|
1048
|
-
if (typeof args[i] === "string") {
|
|
1049
|
-
results.push(args[i]);
|
|
718
|
+
function decToHex(dec) {
|
|
719
|
+
let hex = Math.floor(dec).toString(16);
|
|
720
|
+
return hex.length === 1 ? '0' + hex : hex;
|
|
721
|
+
}
|
|
722
|
+
let formats = {
|
|
723
|
+
hex3: function (string) {
|
|
724
|
+
return {
|
|
725
|
+
r: parseInt(string.substr(1, 1) + string.substr(1, 1), 16),
|
|
726
|
+
g: parseInt(string.substr(2, 1) + string.substr(2, 1), 16),
|
|
727
|
+
b: parseInt(string.substr(3, 1) + string.substr(3, 1), 16),
|
|
728
|
+
a: 255
|
|
729
|
+
};
|
|
730
|
+
},
|
|
731
|
+
hex6: function (string) {
|
|
732
|
+
return {
|
|
733
|
+
r: parseInt(string.substr(1, 2), 16),
|
|
734
|
+
g: parseInt(string.substr(3, 2), 16),
|
|
735
|
+
b: parseInt(string.substr(5, 2), 16),
|
|
736
|
+
a: 255
|
|
737
|
+
};
|
|
738
|
+
},
|
|
739
|
+
hex4: function (string) {
|
|
740
|
+
return {
|
|
741
|
+
r: parseInt(string.substr(1, 1) + string.substr(1, 1), 16),
|
|
742
|
+
g: parseInt(string.substr(2, 1) + string.substr(2, 1), 16),
|
|
743
|
+
b: parseInt(string.substr(3, 1) + string.substr(3, 1), 16),
|
|
744
|
+
a: parseInt(string.substr(4, 1) + string.substr(4, 1), 16)
|
|
745
|
+
};
|
|
746
|
+
},
|
|
747
|
+
hex8: function (string) {
|
|
748
|
+
return {
|
|
749
|
+
r: parseInt(string.substr(1, 2), 16),
|
|
750
|
+
g: parseInt(string.substr(3, 2), 16),
|
|
751
|
+
b: parseInt(string.substr(5, 2), 16),
|
|
752
|
+
a: parseInt(string.substr(7, 2), 16)
|
|
753
|
+
};
|
|
754
|
+
},
|
|
755
|
+
rgb: function (string) {
|
|
756
|
+
let percents = string.match(/%/g);
|
|
757
|
+
if (!percents || percents.length === 3) {
|
|
758
|
+
var channels = string.substring(string.search(/\(/) + 1, string.length - 1).split(',');
|
|
759
|
+
for (var i = 0; i < 3; i++) {
|
|
760
|
+
if (channels[i]) {
|
|
761
|
+
channels[i] = channels[i].trim();
|
|
762
|
+
var percent = channels[i].match(/[.\d\-]+%/);
|
|
763
|
+
if (percent) {
|
|
764
|
+
var points = channels[i].match(/\./g);
|
|
765
|
+
channels[i] = channels[i].search(/[^\d.\-%]/) === -1 && (!points || points.length < 2) ? parseFloat(percent[0]) : NaN;
|
|
766
|
+
if (channels[i] < 0) {
|
|
767
|
+
channels[i] = 0;
|
|
768
|
+
}
|
|
769
|
+
else if (channels[i] > 100) {
|
|
770
|
+
channels[i] = 100;
|
|
771
|
+
}
|
|
772
|
+
channels[i] = Math.floor(channels[i] * 255 / 100);
|
|
1050
773
|
}
|
|
1051
|
-
else
|
|
1052
|
-
|
|
774
|
+
else {
|
|
775
|
+
channels[i] = channels[i] && (channels[i].match(/[^ \-0-9]/) === null) && channels[i].match(/[0-9]+/g).length === 1 ? parseInt(channels[i]) : NaN;
|
|
776
|
+
if (channels[i] < 0) {
|
|
777
|
+
channels[i] = 0;
|
|
778
|
+
}
|
|
779
|
+
else if (channels[i] > 255) {
|
|
780
|
+
channels[i] = 255;
|
|
781
|
+
}
|
|
1053
782
|
}
|
|
1054
783
|
}
|
|
1055
|
-
// Последний аргумент - fallback (если нечётное количество после input)
|
|
1056
|
-
const lastArg = args[args.length - 1];
|
|
1057
|
-
if (typeof lastArg === "string") {
|
|
1058
|
-
results.push(lastArg);
|
|
1059
|
-
}
|
|
1060
|
-
else if (Array.isArray(lastArg)) {
|
|
1061
|
-
results.push(...parseIconNames(lastArg));
|
|
1062
|
-
}
|
|
1063
|
-
return [...new Set(results)];
|
|
1064
784
|
}
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
785
|
+
}
|
|
786
|
+
else {
|
|
787
|
+
channels = [];
|
|
788
|
+
}
|
|
789
|
+
return {
|
|
790
|
+
r: channels[0],
|
|
791
|
+
g: channels[1],
|
|
792
|
+
b: channels[2],
|
|
793
|
+
a: 255
|
|
794
|
+
};
|
|
795
|
+
},
|
|
796
|
+
rgba: function (string) {
|
|
797
|
+
let channels = formats.rgb(string);
|
|
798
|
+
channels.a = undefined;
|
|
799
|
+
let match = string.match(/[\-0-9\.]+/g);
|
|
800
|
+
if (match && match[3]) {
|
|
801
|
+
let points = match[3].match(/\./g);
|
|
802
|
+
if (!points || points.length === 1) {
|
|
803
|
+
channels.a = parseFloat(match[3]);
|
|
804
|
+
if (channels.a < 0) {
|
|
805
|
+
channels.a = 0;
|
|
1075
806
|
}
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
const lastArg = args[args.length - 1];
|
|
1079
|
-
if (typeof lastArg === "string") {
|
|
1080
|
-
results.push(lastArg);
|
|
1081
|
-
}
|
|
1082
|
-
else if (Array.isArray(lastArg)) {
|
|
1083
|
-
results.push(...parseIconNames(lastArg));
|
|
1084
|
-
}
|
|
807
|
+
else if (channels.a > 1) {
|
|
808
|
+
channels.a = 1;
|
|
1085
809
|
}
|
|
1086
|
-
|
|
1087
|
-
}
|
|
1088
|
-
// ["coalesce", expr1, expr2, ...]
|
|
1089
|
-
case "coalesce": {
|
|
1090
|
-
const results = [];
|
|
1091
|
-
args.forEach(arg => {
|
|
1092
|
-
if (typeof arg === "string") {
|
|
1093
|
-
results.push(arg);
|
|
1094
|
-
}
|
|
1095
|
-
else if (Array.isArray(arg)) {
|
|
1096
|
-
results.push(...parseIconNames(arg));
|
|
1097
|
-
}
|
|
1098
|
-
});
|
|
1099
|
-
return [...new Set(results)];
|
|
1100
|
-
}
|
|
1101
|
-
// ["image", name] или ["image", name1, name2, ...]
|
|
1102
|
-
case "image": {
|
|
1103
|
-
return args.filter((arg) => typeof arg === "string");
|
|
810
|
+
channels.a = Math.round(channels.a * 255);
|
|
1104
811
|
}
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
812
|
+
}
|
|
813
|
+
return channels;
|
|
814
|
+
},
|
|
815
|
+
name: function (string) {
|
|
816
|
+
let color = new Color('#' + Color.names[string]);
|
|
817
|
+
return color.channels;
|
|
818
|
+
}
|
|
819
|
+
};
|
|
820
|
+
|
|
821
|
+
class ColorScale {
|
|
822
|
+
constructor(palette) {
|
|
823
|
+
this.palette = palette;
|
|
824
|
+
}
|
|
825
|
+
getColor(p) {
|
|
826
|
+
const palette = this.palette.slice();
|
|
827
|
+
palette[0][0] = 0;
|
|
828
|
+
palette[palette.length - 1][0] = 1;
|
|
829
|
+
let colors = palette.map(item => { return new Color(item[1]); });
|
|
830
|
+
if (p >= 1) {
|
|
831
|
+
let color = new Color(palette[palette.length - 1][1]);
|
|
832
|
+
color.a = 255;
|
|
833
|
+
return color.toString();
|
|
834
|
+
}
|
|
835
|
+
for (let i = 0; i < palette.length; i++) {
|
|
836
|
+
if (palette[i][0] > p) {
|
|
837
|
+
let width = palette[i][0] - palette[i - 1][0];
|
|
838
|
+
let color1 = colors[i - 1];
|
|
839
|
+
let color2 = colors[i];
|
|
840
|
+
let k = (p - palette[i - 1][0]) / width;
|
|
841
|
+
let channels = ['r', 'g', 'b', 'a'].map(function (ch) { return Math.round(color1[ch] + (color2[ch] - color1[ch]) * k); });
|
|
842
|
+
channels[3] = 1;
|
|
843
|
+
return 'rgba(' + channels.join(',') + ')';
|
|
1114
844
|
}
|
|
1115
845
|
}
|
|
846
|
+
return null;
|
|
1116
847
|
}
|
|
1117
|
-
|
|
848
|
+
;
|
|
849
|
+
}
|
|
850
|
+
|
|
851
|
+
const transparentizeColor = (originalColor, percent) => {
|
|
852
|
+
const color = new Color(originalColor);
|
|
853
|
+
color.a = Math.round((255 / 100) * percent);
|
|
854
|
+
return color.toString("hex");
|
|
1118
855
|
};
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
856
|
+
const hexToRgba = (hexCode, opacity = 1) => {
|
|
857
|
+
let hex = hexCode.replace("#", "");
|
|
858
|
+
if (hex.length === 3) {
|
|
859
|
+
hex = `${hex[0]}${hex[0]}${hex[1]}${hex[1]}${hex[2]}${hex[2]}`;
|
|
860
|
+
}
|
|
861
|
+
const r = parseInt(hex.substring(0, 2), 16);
|
|
862
|
+
const g = parseInt(hex.substring(2, 4), 16);
|
|
863
|
+
const b = parseInt(hex.substring(4, 6), 16);
|
|
864
|
+
return `rgba(${r}, ${g}, ${b}, ${opacity})`;
|
|
865
|
+
};
|
|
866
|
+
const rgbToHex = (r, g, b) => {
|
|
867
|
+
const componentToHex = (c) => {
|
|
868
|
+
const hex = c.toString(16);
|
|
869
|
+
return hex.padStart(2, "0");
|
|
870
|
+
};
|
|
871
|
+
return `#${componentToHex(r)}${componentToHex(g)}${componentToHex(b)}`;
|
|
872
|
+
};
|
|
873
|
+
const decimalOpacityToHex = (opacity) => {
|
|
874
|
+
const hex = Math.round(opacity * 255).toString(16);
|
|
875
|
+
return hex.padStart(2, "0");
|
|
1125
876
|
};
|
|
877
|
+
const GRADIENT_COLORS = [
|
|
878
|
+
"#00C2FF",
|
|
879
|
+
"#67ADFE",
|
|
880
|
+
"#766EFB",
|
|
881
|
+
"#9D60F2",
|
|
882
|
+
"#EC63D6",
|
|
883
|
+
"#F35991",
|
|
884
|
+
"#EC474C",
|
|
885
|
+
"#FF7144",
|
|
886
|
+
"#FF9F33",
|
|
887
|
+
"#DEDE56",
|
|
888
|
+
"#A1E062",
|
|
889
|
+
"#51D8A5",
|
|
890
|
+
];
|
|
891
|
+
const HEX_RRGGBB_LENGTH = 7;
|
|
1126
892
|
/**
|
|
1127
|
-
*
|
|
1128
|
-
*
|
|
1129
|
-
*
|
|
1130
|
-
* @param
|
|
1131
|
-
* @returns массив
|
|
893
|
+
* Растягивает палитру на нужное количество цветов: опорные цвета равномерно
|
|
894
|
+
* раскладываются по шкале, недостающие интерполируются между ними.
|
|
895
|
+
* @param colors - опорные цвета палитры в hex
|
|
896
|
+
* @param count - требуемое количество цветов
|
|
897
|
+
* @returns массив ровно из count цветов
|
|
1132
898
|
*/
|
|
1133
|
-
const
|
|
1134
|
-
if (!
|
|
899
|
+
const stretchPalette = (colors, count) => {
|
|
900
|
+
if (!colors?.length || count <= 0)
|
|
1135
901
|
return [];
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
if (value) {
|
|
1143
|
-
parseIconNames(value).forEach(name => imageNames.add(name));
|
|
1144
|
-
}
|
|
1145
|
-
});
|
|
1146
|
-
// Парсим fill-pattern, line-pattern, fill-extrusion-pattern из paint
|
|
1147
|
-
IMAGE_PROPERTIES.paint.forEach(prop => {
|
|
1148
|
-
const value = item.paint?.[prop];
|
|
1149
|
-
if (value) {
|
|
1150
|
-
parseIconNames(value).forEach(name => imageNames.add(name));
|
|
1151
|
-
}
|
|
1152
|
-
});
|
|
902
|
+
if (colors.length === 1)
|
|
903
|
+
return Array.from({ length: count }, () => colors[0]);
|
|
904
|
+
const scale = new ColorScale(colors.map((color, index) => [index / (colors.length - 1), color]));
|
|
905
|
+
return Array.from({ length: count }, (_, index) => {
|
|
906
|
+
const color = scale.getColor(count === 1 ? 0 : index / (count - 1));
|
|
907
|
+
return color ? new Color(color).toString("hex").slice(0, HEX_RRGGBB_LENGTH) : colors[colors.length - 1];
|
|
1153
908
|
});
|
|
1154
|
-
return [...imageNames];
|
|
1155
909
|
};
|
|
1156
|
-
|
|
1157
|
-
/** Предел широты сферического меркатора (EPSG:3857): дальше проекция уходит в бесконечность. */
|
|
1158
|
-
const MERCATOR_MAX_LATITUDE = 85.05112878;
|
|
1159
|
-
/** Предел долготы: карта рендерит копии мира, но экстент за пределами ±180° бэкенду не нужен. */
|
|
1160
|
-
const MERCATOR_MAX_LONGITUDE = 180;
|
|
1161
|
-
|
|
910
|
+
const getGradientColors = (colorsCount) => stretchPalette(GRADIENT_COLORS, colorsCount === undefined || colorsCount < GRADIENT_COLORS.length ? GRADIENT_COLORS.length : colorsCount);
|
|
1162
911
|
/**
|
|
1163
|
-
*
|
|
1164
|
-
* @param
|
|
912
|
+
* Converts HSL hue value to RGB
|
|
913
|
+
* @param p - lower bound
|
|
914
|
+
* @param q - upper bound
|
|
915
|
+
* @param t - hue value
|
|
916
|
+
* @returns RGB component value (0-1)
|
|
1165
917
|
*/
|
|
1166
|
-
const
|
|
1167
|
-
|
|
918
|
+
const hue2rgb = (p, q, t) => {
|
|
919
|
+
if (t < 0)
|
|
920
|
+
t += 1;
|
|
921
|
+
if (t > 1)
|
|
922
|
+
t -= 1;
|
|
923
|
+
if (t < 1 / 6)
|
|
924
|
+
return p + (q - p) * 6 * t;
|
|
925
|
+
if (t < 1 / 2)
|
|
926
|
+
return q;
|
|
927
|
+
if (t < 2 / 3)
|
|
928
|
+
return p + (q - p) * (2 / 3 - t) * 6;
|
|
929
|
+
return p;
|
|
1168
930
|
};
|
|
1169
931
|
/**
|
|
1170
|
-
*
|
|
1171
|
-
* @param
|
|
932
|
+
* Converts RGB component (0-1) to hex string
|
|
933
|
+
* @param value - RGB component value (0-1)
|
|
934
|
+
* @returns hex string (00-ff)
|
|
1172
935
|
*/
|
|
1173
|
-
const
|
|
1174
|
-
|
|
936
|
+
const toHex = (value) => {
|
|
937
|
+
const hex = Math.round(value * 255).toString(16);
|
|
938
|
+
return hex.padStart(2, "0");
|
|
1175
939
|
};
|
|
1176
|
-
|
|
1177
940
|
/**
|
|
1178
|
-
*
|
|
1179
|
-
* @
|
|
941
|
+
* Adjusts color brightness
|
|
942
|
+
* @param color - hex color string (e.g., "#2196f3")
|
|
943
|
+
* @param lightnessAdjustment - lightness adjustment in HSL units (e.g., 5 or -5)
|
|
944
|
+
* @returns adjusted color in hex format
|
|
1180
945
|
*/
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
}
|
|
1200
|
-
}
|
|
1201
|
-
get _min() { return Math.min(this._channels.r, this._channels.g, this._channels.b); }
|
|
1202
|
-
get _max() { return Math.max(this._channels.r, this._channels.g, this._channels.b); }
|
|
1203
|
-
get _delta() { return this._max - this._min; }
|
|
1204
|
-
/**
|
|
1205
|
-
* Returns the color as a string in the requested format
|
|
1206
|
-
* @param format - target format. Available values: "hex" - #AARRGGBB, "rgb" - "rgb(r, g, b)", "rgba" - "rgba(r, g, b, a)"
|
|
1207
|
-
*/
|
|
1208
|
-
toString(format) {
|
|
1209
|
-
if (format === 'hex') {
|
|
1210
|
-
return '#' + decToHex(this.r) + decToHex(this.g) + decToHex(this.b) + decToHex(this.a);
|
|
1211
|
-
}
|
|
1212
|
-
else if (format === 'rgb') {
|
|
1213
|
-
return 'rgb(' + this.r + ',' + this.g + ',' + this.b + ')';
|
|
1214
|
-
}
|
|
1215
|
-
else {
|
|
1216
|
-
return 'rgba(' + this.r + ',' + this.g + ',' + this.b + ',' + (this.a / 255).toFixed(2).replace(/\.*0+$/, '') + ')';
|
|
1217
|
-
}
|
|
1218
|
-
}
|
|
1219
|
-
/**
|
|
1220
|
-
* Returns the string given to the constructor of the instance
|
|
1221
|
-
* @type {String}
|
|
1222
|
-
*/
|
|
1223
|
-
get original() { return this._original; }
|
|
1224
|
-
/**
|
|
1225
|
-
* Returns true if the instance represents a valid color, i.e. that after parsing of the string given to the constructor,
|
|
1226
|
-
* the format is recognized and values of all channels are resolved to valid numbers.
|
|
1227
|
-
* @returns {Boolean}
|
|
1228
|
-
*/
|
|
1229
|
-
get isValid() { return isNumber(this._channels.a) && isNumber(this._channels.r) && isNumber(this._channels.g) && isNumber(this._channels.b); }
|
|
1230
|
-
/**
|
|
1231
|
-
* Converts HSV color value into RGB
|
|
1232
|
-
* @param h - hue value
|
|
1233
|
-
* @param s - saturation value
|
|
1234
|
-
* @param v - 'value' value
|
|
1235
|
-
*/
|
|
1236
|
-
setHsv(h, s, v) {
|
|
1237
|
-
let rgbColors = [];
|
|
1238
|
-
h /= 60;
|
|
1239
|
-
s /= 100;
|
|
1240
|
-
v /= 100;
|
|
1241
|
-
let floor = Math.floor(h);
|
|
1242
|
-
let mod = floor % 6;
|
|
1243
|
-
let f = h - floor;
|
|
1244
|
-
let p = Math.round(255 * v * (1 - s));
|
|
1245
|
-
let q = Math.round(255 * v * (1 - s * f));
|
|
1246
|
-
let t = Math.round(255 * v * (1 - s * (1 - f)));
|
|
1247
|
-
v = Math.round(255 * v);
|
|
1248
|
-
switch (mod) {
|
|
1249
|
-
case 0:
|
|
1250
|
-
rgbColors = [v, t, p];
|
|
1251
|
-
break;
|
|
1252
|
-
case 1:
|
|
1253
|
-
rgbColors = [q, v, p];
|
|
1254
|
-
break;
|
|
1255
|
-
case 2:
|
|
1256
|
-
rgbColors = [p, v, t];
|
|
1257
|
-
break;
|
|
1258
|
-
case 3:
|
|
1259
|
-
rgbColors = [p, q, v];
|
|
946
|
+
const adjustColor = (color, lightnessAdjustment = 5) => {
|
|
947
|
+
// Convert hex to RGB
|
|
948
|
+
const hex = color.replace("#", "");
|
|
949
|
+
const r = parseInt(hex.substring(0, 2), 16) / 255;
|
|
950
|
+
const g = parseInt(hex.substring(2, 4), 16) / 255;
|
|
951
|
+
const b = parseInt(hex.substring(4, 6), 16) / 255;
|
|
952
|
+
// Convert RGB to HSL
|
|
953
|
+
const max = Math.max(r, g, b);
|
|
954
|
+
const min = Math.min(r, g, b);
|
|
955
|
+
let h = 0;
|
|
956
|
+
let s = 0;
|
|
957
|
+
const l = (max + min) / 2;
|
|
958
|
+
if (max !== min) {
|
|
959
|
+
const d = max - min;
|
|
960
|
+
s = l > 0.5 ? d / (2 - max - min) : d / (max + min);
|
|
961
|
+
switch (max) {
|
|
962
|
+
case r:
|
|
963
|
+
h = ((g - b) / d + (g < b ? 6 : 0)) / 6;
|
|
1260
964
|
break;
|
|
1261
|
-
case
|
|
1262
|
-
|
|
965
|
+
case g:
|
|
966
|
+
h = ((b - r) / d + 2) / 6;
|
|
1263
967
|
break;
|
|
1264
|
-
case
|
|
1265
|
-
|
|
968
|
+
case b:
|
|
969
|
+
h = ((r - g) / d + 4) / 6;
|
|
1266
970
|
break;
|
|
1267
971
|
}
|
|
1268
|
-
this._channels.r = rgbColors[0];
|
|
1269
|
-
this._channels.g = rgbColors[1];
|
|
1270
|
-
this._channels.b = rgbColors[2];
|
|
1271
|
-
return this;
|
|
1272
972
|
}
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
return 'hex3';
|
|
1281
|
-
}
|
|
1282
|
-
else if (this._color.length === 7) {
|
|
1283
|
-
return 'hex6';
|
|
1284
|
-
}
|
|
1285
|
-
else if (this._color.length === 5) {
|
|
1286
|
-
return 'hex4';
|
|
1287
|
-
}
|
|
1288
|
-
else if (this._color.length === 9) {
|
|
1289
|
-
return 'hex8';
|
|
1290
|
-
}
|
|
1291
|
-
}
|
|
1292
|
-
else if (this._color.substr(0, 4) === 'rgb(') {
|
|
1293
|
-
return 'rgb';
|
|
1294
|
-
}
|
|
1295
|
-
else if (this._color.substr(0, 5) === 'rgba(') {
|
|
1296
|
-
return 'rgba';
|
|
1297
|
-
}
|
|
1298
|
-
else if (this._color.substr(0, 4) === 'hsv(') {
|
|
1299
|
-
return 'hsv';
|
|
1300
|
-
}
|
|
1301
|
-
else if (this._color in Color.names) {
|
|
1302
|
-
return 'name';
|
|
1303
|
-
}
|
|
973
|
+
const adjustedL = Math.max(0, Math.min(100, (l * 100) + lightnessAdjustment)) / 100;
|
|
974
|
+
// Convert HSL back to RGB
|
|
975
|
+
let rNew;
|
|
976
|
+
let gNew;
|
|
977
|
+
let bNew;
|
|
978
|
+
if (s === 0) {
|
|
979
|
+
rNew = gNew = bNew = adjustedL;
|
|
1304
980
|
}
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
return
|
|
981
|
+
else {
|
|
982
|
+
const q = adjustedL < 0.5 ? adjustedL * (1 + s) : adjustedL + s - adjustedL * s;
|
|
983
|
+
const p = 2 * adjustedL - q;
|
|
984
|
+
rNew = hue2rgb(p, q, h + 1 / 3);
|
|
985
|
+
gNew = hue2rgb(p, q, h);
|
|
986
|
+
bNew = hue2rgb(p, q, h - 1 / 3);
|
|
987
|
+
}
|
|
988
|
+
return `#${toHex(rNew)}${toHex(gNew)}${toHex(bNew)}`;
|
|
989
|
+
};
|
|
990
|
+
const OPAQUE_ALPHA = "ff";
|
|
991
|
+
/**
|
|
992
|
+
* Цвет в hex: `#rrggbb`, а при неполной непрозрачности — `#rrggbbaa`.
|
|
993
|
+
*
|
|
994
|
+
* Полностью непрозрачная альфа отбрасывается: в значении она ничего не уточняет, а строку
|
|
995
|
+
* удлиняет — и в конфиге, и в данных удобнее короткая запись.
|
|
996
|
+
*/
|
|
997
|
+
const colorToHex = (color) => {
|
|
998
|
+
const hex = color.toString("hex");
|
|
999
|
+
return hex.slice(HEX_RRGGBB_LENGTH).toLowerCase() === OPAQUE_ALPHA ? hex.slice(0, HEX_RRGGBB_LENGTH) : hex;
|
|
1000
|
+
};
|
|
1001
|
+
|
|
1002
|
+
const NO_CONTENT_VALUE = "—";
|
|
1003
|
+
exports.DateFormat = void 0;
|
|
1004
|
+
(function (DateFormat) {
|
|
1005
|
+
DateFormat["ClientDefaultFormat"] = "dd.MM.yyyy HH:mm";
|
|
1006
|
+
DateFormat["DateTime"] = "dd.MM.yyyy HH:mm:ss";
|
|
1007
|
+
DateFormat["UTC"] = "yyyy-MM-dd'T'HH:mm:ss.sssxxx";
|
|
1008
|
+
DateFormat["AxisTooltip"] = "d MMMM yyyy";
|
|
1009
|
+
})(exports.DateFormat || (exports.DateFormat = {}));
|
|
1010
|
+
const stringDateParsers = [dateFns.parseJSON, dateFns.parseISO, rawDate => new Date(rawDate)];
|
|
1011
|
+
const getDate = (rawDate) => {
|
|
1012
|
+
if (!rawDate) {
|
|
1013
|
+
return null;
|
|
1014
|
+
}
|
|
1015
|
+
if (typeof rawDate === "string") {
|
|
1016
|
+
for (const parser of stringDateParsers) {
|
|
1017
|
+
const date = parser(rawDate);
|
|
1018
|
+
if (dateFns.isValid(date)) {
|
|
1019
|
+
return dateFns.toDate(date);
|
|
1020
|
+
}
|
|
1021
|
+
}
|
|
1022
|
+
return null;
|
|
1347
1023
|
}
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
s = 0;
|
|
1356
|
-
else
|
|
1357
|
-
s = this._delta / max * 1000 / 10;
|
|
1358
|
-
s = Math.round(s);
|
|
1359
|
-
return s;
|
|
1024
|
+
const parsedDate = dateFns.toDate(rawDate);
|
|
1025
|
+
return dateFns.isValid(parsedDate) ? parsedDate : null;
|
|
1026
|
+
};
|
|
1027
|
+
const formatDate$1 = (date, { dateFormat = exports.DateFormat.ClientDefaultFormat, defaultValue = NO_CONTENT_VALUE } = {}) => {
|
|
1028
|
+
const dateValue = date ? getDate(date) : null;
|
|
1029
|
+
if (dateFns.isValid(dateValue)) {
|
|
1030
|
+
return dateFns.format(dateValue, dateFormat);
|
|
1360
1031
|
}
|
|
1361
|
-
|
|
1362
|
-
* Returns 'value' channel of hsv space as integer from 0 to 100.
|
|
1363
|
-
*/
|
|
1364
|
-
get v() { return Math.round(this._max / 255 * 1000 / 10); }
|
|
1365
|
-
/**
|
|
1366
|
-
* Returns values of the channels as integers from 0 to 255. Format is { r: r, g: g, b: b, a: a }.
|
|
1367
|
-
*/
|
|
1368
|
-
get channels() { return Object.assign({}, this._channels); }
|
|
1369
|
-
}
|
|
1370
|
-
// Big List of Colors
|
|
1371
|
-
// ------------------
|
|
1372
|
-
// <http://www.w3.org/TR/css3-color/#svg-color>
|
|
1373
|
-
//noinspection SpellCheckingInspection
|
|
1374
|
-
Color.names = {
|
|
1375
|
-
aliceblue: "f0f8ff",
|
|
1376
|
-
antiquewhite: "faebd7",
|
|
1377
|
-
aqua: "0ff",
|
|
1378
|
-
aquamarine: "7fffd4",
|
|
1379
|
-
azure: "f0ffff",
|
|
1380
|
-
beige: "f5f5dc",
|
|
1381
|
-
bisque: "ffe4c4",
|
|
1382
|
-
black: "000",
|
|
1383
|
-
blanchedalmond: "ffebcd",
|
|
1384
|
-
blue: "00f",
|
|
1385
|
-
blueviolet: "8a2be2",
|
|
1386
|
-
brown: "a52a2a",
|
|
1387
|
-
burlywood: "deb887",
|
|
1388
|
-
burntsienna: "ea7e5d",
|
|
1389
|
-
cadetblue: "5f9ea0",
|
|
1390
|
-
chartreuse: "7fff00",
|
|
1391
|
-
chocolate: "d2691e",
|
|
1392
|
-
coral: "ff7f50",
|
|
1393
|
-
cornflowerblue: "6495ed",
|
|
1394
|
-
cornsilk: "fff8dc",
|
|
1395
|
-
crimson: "dc143c",
|
|
1396
|
-
cyan: "0ff",
|
|
1397
|
-
darkblue: "00008b",
|
|
1398
|
-
darkcyan: "008b8b",
|
|
1399
|
-
darkgoldenrod: "b8860b",
|
|
1400
|
-
darkgray: "a9a9a9",
|
|
1401
|
-
darkgreen: "006400",
|
|
1402
|
-
darkgrey: "a9a9a9",
|
|
1403
|
-
darkkhaki: "bdb76b",
|
|
1404
|
-
darkmagenta: "8b008b",
|
|
1405
|
-
darkolivegreen: "556b2f",
|
|
1406
|
-
darkorange: "ff8c00",
|
|
1407
|
-
darkorchid: "9932cc",
|
|
1408
|
-
darkred: "8b0000",
|
|
1409
|
-
darksalmon: "e9967a",
|
|
1410
|
-
darkseagreen: "8fbc8f",
|
|
1411
|
-
darkslateblue: "483d8b",
|
|
1412
|
-
darkslategray: "2f4f4f",
|
|
1413
|
-
darkslategrey: "2f4f4f",
|
|
1414
|
-
darkturquoise: "00ced1",
|
|
1415
|
-
darkviolet: "9400d3",
|
|
1416
|
-
deeppink: "ff1493",
|
|
1417
|
-
deepskyblue: "00bfff",
|
|
1418
|
-
dimgray: "696969",
|
|
1419
|
-
dimgrey: "696969",
|
|
1420
|
-
dodgerblue: "1e90ff",
|
|
1421
|
-
firebrick: "b22222",
|
|
1422
|
-
floralwhite: "fffaf0",
|
|
1423
|
-
forestgreen: "228b22",
|
|
1424
|
-
fuchsia: "f0f",
|
|
1425
|
-
gainsboro: "dcdcdc",
|
|
1426
|
-
ghostwhite: "f8f8ff",
|
|
1427
|
-
gold: "ffd700",
|
|
1428
|
-
goldenrod: "daa520",
|
|
1429
|
-
gray: "808080",
|
|
1430
|
-
green: "008000",
|
|
1431
|
-
greenyellow: "adff2f",
|
|
1432
|
-
grey: "808080",
|
|
1433
|
-
honeydew: "f0fff0",
|
|
1434
|
-
hotpink: "ff69b4",
|
|
1435
|
-
indianred: "cd5c5c",
|
|
1436
|
-
indigo: "4b0082",
|
|
1437
|
-
ivory: "fffff0",
|
|
1438
|
-
khaki: "f0e68c",
|
|
1439
|
-
lavender: "e6e6fa",
|
|
1440
|
-
lavenderblush: "fff0f5",
|
|
1441
|
-
lawngreen: "7cfc00",
|
|
1442
|
-
lemonchiffon: "fffacd",
|
|
1443
|
-
lightblue: "add8e6",
|
|
1444
|
-
lightcoral: "f08080",
|
|
1445
|
-
lightcyan: "e0ffff",
|
|
1446
|
-
lightgoldenrodyellow: "fafad2",
|
|
1447
|
-
lightgray: "d3d3d3",
|
|
1448
|
-
lightgreen: "90ee90",
|
|
1449
|
-
lightgrey: "d3d3d3",
|
|
1450
|
-
lightpink: "ffb6c1",
|
|
1451
|
-
lightsalmon: "ffa07a",
|
|
1452
|
-
lightseagreen: "20b2aa",
|
|
1453
|
-
lightskyblue: "87cefa",
|
|
1454
|
-
lightslategray: "789",
|
|
1455
|
-
lightslategrey: "789",
|
|
1456
|
-
lightsteelblue: "b0c4de",
|
|
1457
|
-
lightyellow: "ffffe0",
|
|
1458
|
-
lime: "0f0",
|
|
1459
|
-
limegreen: "32cd32",
|
|
1460
|
-
linen: "faf0e6",
|
|
1461
|
-
magenta: "f0f",
|
|
1462
|
-
maroon: "800000",
|
|
1463
|
-
mediumaquamarine: "66cdaa",
|
|
1464
|
-
mediumblue: "0000cd",
|
|
1465
|
-
mediumorchid: "ba55d3",
|
|
1466
|
-
mediumpurple: "9370db",
|
|
1467
|
-
mediumseagreen: "3cb371",
|
|
1468
|
-
mediumslateblue: "7b68ee",
|
|
1469
|
-
mediumspringgreen: "00fa9a",
|
|
1470
|
-
mediumturquoise: "48d1cc",
|
|
1471
|
-
mediumvioletred: "c71585",
|
|
1472
|
-
midnightblue: "191970",
|
|
1473
|
-
mintcream: "f5fffa",
|
|
1474
|
-
mistyrose: "ffe4e1",
|
|
1475
|
-
moccasin: "ffe4b5",
|
|
1476
|
-
navajowhite: "ffdead",
|
|
1477
|
-
navy: "000080",
|
|
1478
|
-
oldlace: "fdf5e6",
|
|
1479
|
-
olive: "808000",
|
|
1480
|
-
olivedrab: "6b8e23",
|
|
1481
|
-
orange: "ffa500",
|
|
1482
|
-
orangered: "ff4500",
|
|
1483
|
-
orchid: "da70d6",
|
|
1484
|
-
palegoldenrod: "eee8aa",
|
|
1485
|
-
palegreen: "98fb98",
|
|
1486
|
-
paleturquoise: "afeeee",
|
|
1487
|
-
palevioletred: "db7093",
|
|
1488
|
-
papayawhip: "ffefd5",
|
|
1489
|
-
peachpuff: "ffdab9",
|
|
1490
|
-
peru: "cd853f",
|
|
1491
|
-
pink: "ffc0cb",
|
|
1492
|
-
plum: "dda0dd",
|
|
1493
|
-
powderblue: "b0e0e6",
|
|
1494
|
-
purple: "800080",
|
|
1495
|
-
rebeccapurple: "663399",
|
|
1496
|
-
red: "f00",
|
|
1497
|
-
rosybrown: "bc8f8f",
|
|
1498
|
-
royalblue: "4169e1",
|
|
1499
|
-
saddlebrown: "8b4513",
|
|
1500
|
-
salmon: "fa8072",
|
|
1501
|
-
sandybrown: "f4a460",
|
|
1502
|
-
seagreen: "2e8b57",
|
|
1503
|
-
seashell: "fff5ee",
|
|
1504
|
-
sienna: "a0522d",
|
|
1505
|
-
silver: "c0c0c0",
|
|
1506
|
-
skyblue: "87ceeb",
|
|
1507
|
-
slateblue: "6a5acd",
|
|
1508
|
-
slategray: "708090",
|
|
1509
|
-
slategrey: "708090",
|
|
1510
|
-
snow: "fffafa",
|
|
1511
|
-
springgreen: "00ff7f",
|
|
1512
|
-
steelblue: "4682b4",
|
|
1513
|
-
tan: "d2b48c",
|
|
1514
|
-
teal: "008080",
|
|
1515
|
-
thistle: "d8bfd8",
|
|
1516
|
-
tomato: "ff6347",
|
|
1517
|
-
turquoise: "40e0d0",
|
|
1518
|
-
violet: "ee82ee",
|
|
1519
|
-
wheat: "f5deb3",
|
|
1520
|
-
white: "fff",
|
|
1521
|
-
whitesmoke: "f5f5f5",
|
|
1522
|
-
yellow: "ff0",
|
|
1523
|
-
yellowgreen: "9acd32",
|
|
1524
|
-
transparent: '0000'
|
|
1032
|
+
return `${defaultValue}`;
|
|
1525
1033
|
};
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1034
|
+
|
|
1035
|
+
const debounce = (callback, delay) => {
|
|
1036
|
+
let timeId;
|
|
1037
|
+
return (...args) => {
|
|
1038
|
+
if (timeId) {
|
|
1039
|
+
window.clearTimeout(timeId);
|
|
1040
|
+
}
|
|
1041
|
+
timeId = window.setTimeout(() => {
|
|
1042
|
+
callback(...args);
|
|
1043
|
+
}, delay);
|
|
1044
|
+
};
|
|
1045
|
+
};
|
|
1046
|
+
|
|
1047
|
+
const MILLION = 1000000;
|
|
1048
|
+
const TEN_THOUSANDS = 10000;
|
|
1049
|
+
const THOUSAND = 1000;
|
|
1050
|
+
const COMPACT_FRACTION_DIGITS = 1;
|
|
1051
|
+
const roundTotalSum = (value, fractionDigits) => {
|
|
1052
|
+
if (!value)
|
|
1053
|
+
return "";
|
|
1054
|
+
const digits = fractionDigits ?? COMPACT_FRACTION_DIGITS;
|
|
1055
|
+
if (value >= MILLION) {
|
|
1056
|
+
return `${(value / MILLION).toFixed(digits)}M`;
|
|
1057
|
+
}
|
|
1058
|
+
if (value >= TEN_THOUSANDS) {
|
|
1059
|
+
return `${(value / THOUSAND).toFixed(digits)}K`;
|
|
1060
|
+
}
|
|
1061
|
+
return value;
|
|
1062
|
+
};
|
|
1063
|
+
|
|
1064
|
+
const TIME_ZONE_FORMAT = ' "GMT"z'; // eslint-disable-line
|
|
1065
|
+
exports.ScalingFactor = void 0;
|
|
1066
|
+
(function (ScalingFactor) {
|
|
1067
|
+
ScalingFactor[ScalingFactor["Default"] = 1] = "Default";
|
|
1068
|
+
ScalingFactor[ScalingFactor["Thousands"] = 0.001] = "Thousands";
|
|
1069
|
+
ScalingFactor[ScalingFactor["Millions"] = 0.000001] = "Millions";
|
|
1070
|
+
ScalingFactor[ScalingFactor["Acres"] = 0.01] = "Acres";
|
|
1071
|
+
ScalingFactor[ScalingFactor["Hectares"] = 0.0001] = "Hectares";
|
|
1072
|
+
})(exports.ScalingFactor || (exports.ScalingFactor = {}));
|
|
1073
|
+
const formatDate = (str, isRuLocale) => dateFns.format(Date.now(), str, { locale: isRuLocale ? locale.ru : locale.enUS });
|
|
1074
|
+
const timeOptions = [
|
|
1075
|
+
{
|
|
1076
|
+
text: formatDate("kk:mm:ss"),
|
|
1077
|
+
value: "hh:mm:ss",
|
|
1078
|
+
},
|
|
1079
|
+
{
|
|
1080
|
+
text: formatDate("hh:mm:ss aa"),
|
|
1081
|
+
value: "hh:mm:ss tt",
|
|
1082
|
+
},
|
|
1083
|
+
{
|
|
1084
|
+
text: formatDate("kk:mm"),
|
|
1085
|
+
value: "hh:mm",
|
|
1086
|
+
},
|
|
1087
|
+
{
|
|
1088
|
+
text: formatDate("hh:mm aa"),
|
|
1089
|
+
value: "hh:mm tt",
|
|
1090
|
+
},
|
|
1091
|
+
];
|
|
1092
|
+
const dateOptions = [
|
|
1093
|
+
{
|
|
1094
|
+
text: formatDate("dd.MM.yyyy"),
|
|
1095
|
+
value: "dd.MM.yyyy",
|
|
1538
1096
|
},
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
g: parseInt(string.substr(3, 2), 16),
|
|
1543
|
-
b: parseInt(string.substr(5, 2), 16),
|
|
1544
|
-
a: 255
|
|
1545
|
-
};
|
|
1097
|
+
{
|
|
1098
|
+
text: formatDate("dd MMMM yyyy", true),
|
|
1099
|
+
value: "dd MMMM yyyy",
|
|
1546
1100
|
},
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
g: parseInt(string.substr(2, 1) + string.substr(2, 1), 16),
|
|
1551
|
-
b: parseInt(string.substr(3, 1) + string.substr(3, 1), 16),
|
|
1552
|
-
a: parseInt(string.substr(4, 1) + string.substr(4, 1), 16)
|
|
1553
|
-
};
|
|
1101
|
+
{
|
|
1102
|
+
text: formatDate("yyyy, dd MMMM", true),
|
|
1103
|
+
value: "yyyy, dd MMMM",
|
|
1554
1104
|
},
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
a: parseInt(string.substr(7, 2), 16)
|
|
1561
|
-
};
|
|
1105
|
+
];
|
|
1106
|
+
const pointOptions = [
|
|
1107
|
+
{
|
|
1108
|
+
value: "default",
|
|
1109
|
+
localizationKey: "defaultValue",
|
|
1562
1110
|
},
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1111
|
+
{
|
|
1112
|
+
value: "DD MM SS",
|
|
1113
|
+
localizationKey: "degreesMinutesSeconds",
|
|
1114
|
+
},
|
|
1115
|
+
{
|
|
1116
|
+
value: "DD.",
|
|
1117
|
+
localizationKey: "decimalDegrees",
|
|
1118
|
+
},
|
|
1119
|
+
];
|
|
1120
|
+
const numberOptions = [
|
|
1121
|
+
{
|
|
1122
|
+
value: exports.ScalingFactor.Default.toString(),
|
|
1123
|
+
localizationKey: "defaultValue",
|
|
1124
|
+
},
|
|
1125
|
+
{
|
|
1126
|
+
value: exports.ScalingFactor.Thousands.toString(),
|
|
1127
|
+
localizationKey: "inThousands",
|
|
1128
|
+
},
|
|
1129
|
+
{
|
|
1130
|
+
value: exports.ScalingFactor.Millions.toString(),
|
|
1131
|
+
localizationKey: "inMillions",
|
|
1132
|
+
},
|
|
1133
|
+
{
|
|
1134
|
+
value: exports.ScalingFactor.Acres.toString(),
|
|
1135
|
+
localizationKey: "inAcres",
|
|
1136
|
+
},
|
|
1137
|
+
{
|
|
1138
|
+
value: exports.ScalingFactor.Hectares.toString(),
|
|
1139
|
+
localizationKey: "inHectares",
|
|
1140
|
+
},
|
|
1141
|
+
];
|
|
1142
|
+
const convertDDToDMS = (value) => {
|
|
1143
|
+
const absolute = Math.abs(value);
|
|
1144
|
+
const degrees = Math.floor(absolute);
|
|
1145
|
+
const minutesNotTruncated = (absolute - degrees) * 60;
|
|
1146
|
+
const minutes = Math.floor(minutesNotTruncated);
|
|
1147
|
+
const seconds = Math.floor((minutesNotTruncated - minutes) * 60);
|
|
1148
|
+
return `${degrees}° ${minutes}' ${seconds}"`;
|
|
1149
|
+
};
|
|
1150
|
+
const formatPointValue = ({ t, stringFormat, value }) => {
|
|
1151
|
+
if (stringFormat.format === pointOptions[1].value) {
|
|
1152
|
+
const lon = value[1];
|
|
1153
|
+
const lat = value[0];
|
|
1154
|
+
const lonDirection = lon >= 0 ? t("east", { ns: "common" }) : t("west", { ns: "common" });
|
|
1155
|
+
const latDirection = lat >= 0 ? t("north", { ns: "common" }) : t("south", { ns: "common" });
|
|
1156
|
+
return `${convertDDToDMS(lon)} ${lonDirection}, ${convertDDToDMS(lat)} ${latDirection}`;
|
|
1157
|
+
}
|
|
1158
|
+
if (stringFormat.format.includes("DD.") && value.length) {
|
|
1159
|
+
const rounding = stringFormat.format.replace("DD.", "").length;
|
|
1160
|
+
return `${value[0].toFixed(rounding)}, ${value[1].toFixed(rounding)}`;
|
|
1161
|
+
}
|
|
1162
|
+
return null;
|
|
1163
|
+
};
|
|
1164
|
+
const getValueFromOptions = (options, format) => options.find(({ value }) => format && format.includes(value));
|
|
1165
|
+
const numberWithSpaces = (input, precision) => {
|
|
1166
|
+
if (input === null || input === undefined) {
|
|
1167
|
+
return "";
|
|
1168
|
+
}
|
|
1169
|
+
return parseFloat((typeof input === "string" ? parseFloat(input) : input).toString()).toLocaleString("ru-RU", {
|
|
1170
|
+
maximumFractionDigits: precision ?? 10,
|
|
1171
|
+
});
|
|
1172
|
+
};
|
|
1173
|
+
const formatDateValue = (stringFormat, dateValue) => {
|
|
1174
|
+
let value = dateValue;
|
|
1175
|
+
if (typeof value === "string") {
|
|
1176
|
+
value = new Date(value).getTime();
|
|
1177
|
+
}
|
|
1178
|
+
const isRuLocale = stringFormat.culture && stringFormat.culture === "ru-RU";
|
|
1179
|
+
const showTimeZone = stringFormat.format.includes(TIME_ZONE_FORMAT);
|
|
1180
|
+
const dateOption = getValueFromOptions(dateOptions, stringFormat.format);
|
|
1181
|
+
const dateOptionValue = dateOption && dateOption.value;
|
|
1182
|
+
const dateFormat = value && dateOptionValue
|
|
1183
|
+
? dateFns.format(value, dateOptionValue, {
|
|
1184
|
+
locale: locale.ru,
|
|
1185
|
+
})
|
|
1186
|
+
: "";
|
|
1187
|
+
const timeOption = getValueFromOptions(timeOptions, stringFormat.format);
|
|
1188
|
+
const timeOptionValue = timeOption && (isRuLocale ? timeOption.value : `${timeOption.value} aa`);
|
|
1189
|
+
const timeFormat = (timeOptionValue && dateFns.format(value, showTimeZone ? `${timeOptionValue} zz` : timeOptionValue)) || "";
|
|
1190
|
+
return dateFormat ? [dateFormat, timeFormat].filter(Boolean).join(" ") : "";
|
|
1191
|
+
};
|
|
1192
|
+
const appendUnitsLabel = (value, unitsLabel, noUnits) => (unitsLabel && !noUnits ? `${value} ${unitsLabel}` : value)?.toString() || "";
|
|
1193
|
+
const formatNumberValue = (stringFormat, value, type, noUnits = false) => {
|
|
1194
|
+
const { scalingFactor, rounding, splitDigitGroup, roundDigitGroup, unitsLabel } = stringFormat || {};
|
|
1195
|
+
const isIntValue = [api.AttributeType.Int32, api.AttributeType.Int64].includes(type);
|
|
1196
|
+
const isDefaultScaling = stringFormat && stringFormat.scalingFactor === +numberOptions[0].value;
|
|
1197
|
+
let currentValue = value;
|
|
1198
|
+
if (isIntValue && isDefaultScaling && currentValue) {
|
|
1199
|
+
currentValue = parseInt(currentValue.toString(), 10);
|
|
1200
|
+
}
|
|
1201
|
+
if (scalingFactor) {
|
|
1202
|
+
currentValue *= scalingFactor;
|
|
1203
|
+
}
|
|
1204
|
+
const hasRounding = !isNil(rounding);
|
|
1205
|
+
const compactValue = roundDigitGroup
|
|
1206
|
+
? roundTotalSum(Number(currentValue), hasRounding ? rounding : undefined)
|
|
1207
|
+
: null;
|
|
1208
|
+
if (typeof compactValue === "string" && compactValue) {
|
|
1209
|
+
return appendUnitsLabel(compactValue, unitsLabel, noUnits);
|
|
1210
|
+
}
|
|
1211
|
+
if (hasRounding && (!isIntValue || !isDefaultScaling) && !isNil(currentValue)) {
|
|
1212
|
+
currentValue = Number(currentValue).toFixed(rounding);
|
|
1213
|
+
}
|
|
1214
|
+
if (splitDigitGroup) {
|
|
1215
|
+
currentValue = numberWithSpaces(currentValue);
|
|
1216
|
+
}
|
|
1217
|
+
if (currentValue) {
|
|
1218
|
+
currentValue = currentValue.toString().replace(".", ",");
|
|
1219
|
+
}
|
|
1220
|
+
return appendUnitsLabel(currentValue, unitsLabel, noUnits);
|
|
1221
|
+
};
|
|
1222
|
+
const formatAttributeValue = ({ t, type, value, stringFormat, noUnits = false }) => {
|
|
1223
|
+
const isNilValue = isNil(value);
|
|
1224
|
+
if (type === api.AttributeType.Point) {
|
|
1225
|
+
if (!stringFormat?.format || isNilValue) {
|
|
1226
|
+
return null;
|
|
1227
|
+
}
|
|
1228
|
+
return formatPointValue({ t, stringFormat, value: value?.coordinates });
|
|
1229
|
+
}
|
|
1230
|
+
if (type === api.AttributeType.DateTime) {
|
|
1231
|
+
if (isNilValue) {
|
|
1232
|
+
return null;
|
|
1233
|
+
}
|
|
1234
|
+
if (!stringFormat?.format) {
|
|
1235
|
+
return value;
|
|
1236
|
+
}
|
|
1237
|
+
return formatDateValue(stringFormat, value);
|
|
1238
|
+
}
|
|
1239
|
+
if ([
|
|
1240
|
+
api.AttributeType.Int32,
|
|
1241
|
+
api.AttributeType.Int64,
|
|
1242
|
+
api.AttributeType.Double,
|
|
1243
|
+
api.AttributeType.Polygon,
|
|
1244
|
+
api.AttributeType.LineString,
|
|
1245
|
+
api.AttributeType.MultiPoint,
|
|
1246
|
+
api.AttributeType.MultiPolygon,
|
|
1247
|
+
api.AttributeType.MultiLineString,
|
|
1248
|
+
].includes(type) &&
|
|
1249
|
+
!isNaN(value)) {
|
|
1250
|
+
if (!stringFormat && !isNilValue) {
|
|
1251
|
+
return value.toString();
|
|
1252
|
+
}
|
|
1253
|
+
return formatNumberValue(stringFormat, value, type, noUnits);
|
|
1254
|
+
}
|
|
1255
|
+
if (type === api.AttributeType.Json) {
|
|
1256
|
+
if (isNilValue || value?.length === 0) {
|
|
1257
|
+
return "";
|
|
1258
|
+
}
|
|
1259
|
+
return `${t("total", { ns: "table" })} ${value.length}`;
|
|
1260
|
+
}
|
|
1261
|
+
return !isNilValue ? value.toString() : "";
|
|
1262
|
+
};
|
|
1263
|
+
const formatNumber = (number) => {
|
|
1264
|
+
let result = "";
|
|
1265
|
+
const gapSize = 3;
|
|
1266
|
+
if (typeof number === "number") {
|
|
1267
|
+
const numsArray = String(number).split(".");
|
|
1268
|
+
const numeral = numsArray[0];
|
|
1269
|
+
let spaceBefore = numeral.length % gapSize;
|
|
1270
|
+
for (let i = 0; i < numeral.length; i += 1) {
|
|
1271
|
+
if (i === spaceBefore) {
|
|
1272
|
+
result = `${result} `;
|
|
1273
|
+
spaceBefore += 3;
|
|
1274
|
+
}
|
|
1275
|
+
result += numeral[i];
|
|
1276
|
+
}
|
|
1277
|
+
if (numsArray[1]) {
|
|
1278
|
+
return [result.trim(), numsArray[1]].join(".");
|
|
1279
|
+
}
|
|
1280
|
+
return result.trim();
|
|
1281
|
+
}
|
|
1282
|
+
return number || "0";
|
|
1283
|
+
};
|
|
1284
|
+
const formatArea = (t, num) => {
|
|
1285
|
+
let result = num;
|
|
1286
|
+
let measure = t("sqMeter", { ns: "common" });
|
|
1287
|
+
if (num >= 10000000) {
|
|
1288
|
+
result = num / 1000000;
|
|
1289
|
+
measure = t("sqKilometer", { ns: "common" });
|
|
1290
|
+
}
|
|
1291
|
+
else if (num >= 10000) {
|
|
1292
|
+
result = num / 10000;
|
|
1293
|
+
measure = t("hectare", { ns: "common" });
|
|
1294
|
+
}
|
|
1295
|
+
return `${numberWithSpaces(result, 2)} ${measure}`;
|
|
1296
|
+
};
|
|
1297
|
+
const formatLength = (t, num) => {
|
|
1298
|
+
let result = num;
|
|
1299
|
+
let measure = t("meter", { ns: "common" });
|
|
1300
|
+
if (num > 10000) {
|
|
1301
|
+
result = num / 1000;
|
|
1302
|
+
measure = t("kilometer", { ns: "common" });
|
|
1303
|
+
}
|
|
1304
|
+
return `${numberWithSpaces(result, 2)} ${measure}`;
|
|
1305
|
+
};
|
|
1306
|
+
const formatPolygonMeasure = (t, area, perimiter) => {
|
|
1307
|
+
return `S : ${formatArea(t, area)} P : ${formatLength(t, perimiter)}`;
|
|
1308
|
+
};
|
|
1309
|
+
|
|
1310
|
+
const geometryToEwkt = (geometry) => {
|
|
1311
|
+
if (!geometry) {
|
|
1312
|
+
return "";
|
|
1313
|
+
}
|
|
1314
|
+
const projected = turf.toMercator({ type: "Feature", geometry, properties: {} });
|
|
1315
|
+
const projectedCoords = projected?.geometry?.coordinates;
|
|
1316
|
+
const wkt$1 = wkt.stringify({ ...geometry, coordinates: projectedCoords });
|
|
1317
|
+
return `SRID=3857;${wkt$1}`;
|
|
1318
|
+
};
|
|
1319
|
+
|
|
1320
|
+
function isObject(value) {
|
|
1321
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
1322
|
+
}
|
|
1323
|
+
|
|
1324
|
+
const isLayerService = (value) => isObject(value) && "name" in value;
|
|
1325
|
+
|
|
1326
|
+
const isNumeric = (number) => !isNaN(parseFloat(number)) && isFinite(number);
|
|
1327
|
+
|
|
1328
|
+
const metersPerPixel = (zoom, lat) => {
|
|
1329
|
+
return (156543.03 * Math.cos(lat * (Math.PI / 180))) / 2 ** zoom;
|
|
1330
|
+
};
|
|
1331
|
+
|
|
1332
|
+
/* eslint-disable max-lines, no-console, class-methods-use-this, @typescript-eslint/no-magic-numbers */
|
|
1333
|
+
class ClientStyleValidator {
|
|
1334
|
+
options;
|
|
1335
|
+
constructor(options) {
|
|
1336
|
+
this.options = options || {};
|
|
1337
|
+
}
|
|
1338
|
+
validate(clientStyle) {
|
|
1339
|
+
if (isNil(clientStyle) || isEmpty(clientStyle) || isNil(clientStyle?.items) || isEmpty(clientStyle?.items)) {
|
|
1340
|
+
return true;
|
|
1341
|
+
}
|
|
1342
|
+
if (clientStyle.items.some(item => isNil(item.paint))) {
|
|
1343
|
+
if (this.options.verbose) {
|
|
1344
|
+
console.error("Validate client style:", "`paint` prop is mandatory", "\n");
|
|
1592
1345
|
}
|
|
1346
|
+
return false;
|
|
1593
1347
|
}
|
|
1594
|
-
|
|
1595
|
-
|
|
1348
|
+
return clientStyle.items.every(item => Object.entries({ ...item.layout, ...item.paint }).every(([key, value]) => this.validateSpecPropValue(key, value)));
|
|
1349
|
+
}
|
|
1350
|
+
getSpecPropValueOptions(key) {
|
|
1351
|
+
return SPEC_PROP_VALUE_OPTIONS[key];
|
|
1352
|
+
}
|
|
1353
|
+
isHeatmapColorValid(value) {
|
|
1354
|
+
return (mapboxGlStyleSpec.expression.isExpression(value) &&
|
|
1355
|
+
isEqual(value[0], "interpolate") &&
|
|
1356
|
+
isEqual(value[1], ["linear"]) &&
|
|
1357
|
+
isEqual(value[2], ["heatmap-density"]) &&
|
|
1358
|
+
value.length % 2 !== 0 &&
|
|
1359
|
+
value.length > 3 &&
|
|
1360
|
+
value
|
|
1361
|
+
.slice(3)
|
|
1362
|
+
.filter((_, i) => i % 2 === 0)
|
|
1363
|
+
.every(e => typeof e === "number") &&
|
|
1364
|
+
value
|
|
1365
|
+
.slice(3)
|
|
1366
|
+
.filter((_, i) => i % 2 !== 0)
|
|
1367
|
+
.every(e => typeof e === "string"));
|
|
1368
|
+
}
|
|
1369
|
+
isZoomInterpolate(value) {
|
|
1370
|
+
return Array.isArray(value) && value[0] === "interpolate" && Array.isArray(value[2]) && value[2][0] === "zoom";
|
|
1371
|
+
}
|
|
1372
|
+
validateSupportedConcatExpression(key, value) {
|
|
1373
|
+
if (key !== "text-field") {
|
|
1374
|
+
if (this.options.verbose) {
|
|
1375
|
+
console.error("Validate supported concat expression:", "supported only for `text-field`", key, value, "\n");
|
|
1376
|
+
}
|
|
1377
|
+
return false;
|
|
1596
1378
|
}
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
b: channels[2],
|
|
1601
|
-
a: 255
|
|
1602
|
-
};
|
|
1603
|
-
},
|
|
1604
|
-
rgba: function (string) {
|
|
1605
|
-
let channels = formats.rgb(string);
|
|
1606
|
-
channels.a = undefined;
|
|
1607
|
-
let match = string.match(/[\-0-9\.]+/g);
|
|
1608
|
-
if (match && match[3]) {
|
|
1609
|
-
let points = match[3].match(/\./g);
|
|
1610
|
-
if (!points || points.length === 1) {
|
|
1611
|
-
channels.a = parseFloat(match[3]);
|
|
1612
|
-
if (channels.a < 0) {
|
|
1613
|
-
channels.a = 0;
|
|
1614
|
-
}
|
|
1615
|
-
else if (channels.a > 1) {
|
|
1616
|
-
channels.a = 1;
|
|
1617
|
-
}
|
|
1618
|
-
channels.a = Math.round(channels.a * 255);
|
|
1379
|
+
if (!mapboxGlStyleSpec.expression.isExpression(value)) {
|
|
1380
|
+
if (this.options.verbose) {
|
|
1381
|
+
console.error("Validate supported concat expression:", "not an expression", key, value, "\n");
|
|
1619
1382
|
}
|
|
1383
|
+
return false;
|
|
1620
1384
|
}
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1385
|
+
const result = value[0] === "concat" &&
|
|
1386
|
+
value.length > 2 &&
|
|
1387
|
+
value
|
|
1388
|
+
.slice(1)
|
|
1389
|
+
.every(i => typeof i === "string" || (Array.isArray(i) && i[0] === "get" && typeof i[1] === "string"));
|
|
1390
|
+
if (!result) {
|
|
1391
|
+
if (this.options.verbose) {
|
|
1392
|
+
console.error("Validate supported concat expression:", "invalid expression", key, value, "\n");
|
|
1393
|
+
}
|
|
1394
|
+
}
|
|
1395
|
+
return result;
|
|
1626
1396
|
}
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1397
|
+
validateSupportedMatchExpression(key, value) {
|
|
1398
|
+
if (!this.getSpecPropValueOptions(key)?.dataExpressionSupport) {
|
|
1399
|
+
if (this.options.verbose) {
|
|
1400
|
+
console.error("Validate supported match expression:", "expression not supported", key, value, "\n");
|
|
1401
|
+
}
|
|
1402
|
+
return false;
|
|
1403
|
+
}
|
|
1404
|
+
if (!mapboxGlStyleSpec.expression.isExpression(value)) {
|
|
1405
|
+
if (this.options.verbose) {
|
|
1406
|
+
console.error("Validate supported match expression:", "not an expression", key, value, "\n");
|
|
1407
|
+
}
|
|
1408
|
+
return false;
|
|
1409
|
+
}
|
|
1410
|
+
const result = value[0] === "match" &&
|
|
1411
|
+
Array.isArray(value[1]) &&
|
|
1412
|
+
value[1].length === 2 &&
|
|
1413
|
+
value[1][0] === "get" &&
|
|
1414
|
+
typeof value[1][1] === "string" &&
|
|
1415
|
+
value.length > 3 &&
|
|
1416
|
+
value.length % 2 !== 0 &&
|
|
1417
|
+
value
|
|
1418
|
+
.slice(2)
|
|
1419
|
+
.every(e => typeof e === "number" ||
|
|
1420
|
+
typeof e === "string" ||
|
|
1421
|
+
(key === "text-field" && this.validateSupportedConcatExpression(key, e)));
|
|
1422
|
+
if (!result) {
|
|
1423
|
+
if (this.options.verbose) {
|
|
1424
|
+
console.error("Validate supported match expression:", "invalid expression", key, value, "\n");
|
|
1425
|
+
}
|
|
1426
|
+
}
|
|
1427
|
+
return result;
|
|
1428
|
+
}
|
|
1429
|
+
validateSupportedCaseExpression(key, value) {
|
|
1430
|
+
if (!this.getSpecPropValueOptions(key)?.dataExpressionSupport) {
|
|
1431
|
+
if (this.options.verbose) {
|
|
1432
|
+
console.error("Validate supported case expression:", "expression not supported", key, value, "\n");
|
|
1433
|
+
}
|
|
1434
|
+
return false;
|
|
1435
|
+
}
|
|
1436
|
+
if (!mapboxGlStyleSpec.expression.isExpression(value)) {
|
|
1437
|
+
if (this.options.verbose) {
|
|
1438
|
+
console.error("Validate supported case expression:", "not an expression", key, value, "\n");
|
|
1439
|
+
}
|
|
1440
|
+
return false;
|
|
1441
|
+
}
|
|
1442
|
+
const result = value[0] === "case" &&
|
|
1443
|
+
value.length > 3 &&
|
|
1444
|
+
value.length % 2 === 0 &&
|
|
1445
|
+
value
|
|
1446
|
+
.slice(1)
|
|
1447
|
+
.filter((_, i) => i % 2 === 0 && i < value.slice(1).length - 1)
|
|
1448
|
+
.every(e => Array.isArray(e) &&
|
|
1449
|
+
e[0] === "all" &&
|
|
1450
|
+
e.length > 1 &&
|
|
1451
|
+
e
|
|
1452
|
+
.slice(1)
|
|
1453
|
+
.every(ce => Array.isArray(ce) &&
|
|
1454
|
+
ce.length === 3 &&
|
|
1455
|
+
[">=", ">", "<", "<="].includes(ce[0]) &&
|
|
1456
|
+
ce[1][0] === "get" &&
|
|
1457
|
+
typeof ce[1][1] === "string" &&
|
|
1458
|
+
typeof ce[2] === "number")) &&
|
|
1459
|
+
value
|
|
1460
|
+
.slice(1)
|
|
1461
|
+
.filter((_, i) => i % 2 !== 0)
|
|
1462
|
+
.every(e => typeof e === "number" ||
|
|
1463
|
+
typeof e === "string" ||
|
|
1464
|
+
(key === "text-field" && this.validateSupportedConcatExpression(key, e))) &&
|
|
1465
|
+
(typeof value[value.slice(1).length - 1] === "number" ||
|
|
1466
|
+
typeof value[value.slice(1).length - 1] === "string" ||
|
|
1467
|
+
(key === "text-field" && this.validateSupportedConcatExpression(key, value)));
|
|
1468
|
+
if (!result) {
|
|
1469
|
+
if (this.options.verbose) {
|
|
1470
|
+
console.error("Validate supported case expression:", "invalid expression", key, value, "\n");
|
|
1471
|
+
}
|
|
1472
|
+
}
|
|
1473
|
+
return result;
|
|
1474
|
+
}
|
|
1475
|
+
validateSupportedStepExpression(key, value) {
|
|
1476
|
+
if (!this.getSpecPropValueOptions(key)?.dataExpressionSupport) {
|
|
1477
|
+
if (this.options.verbose) {
|
|
1478
|
+
console.error("Validate supported step expression:", "expression not supported", key, value, "\n");
|
|
1479
|
+
}
|
|
1480
|
+
return false;
|
|
1481
|
+
}
|
|
1482
|
+
if (!mapboxGlStyleSpec.expression.isExpression(value)) {
|
|
1483
|
+
if (this.options.verbose) {
|
|
1484
|
+
console.error("Validate supported step expression:", "not an expression", key, value, "\n");
|
|
1485
|
+
}
|
|
1486
|
+
return false;
|
|
1487
|
+
}
|
|
1488
|
+
const result = value[0] === "step" &&
|
|
1489
|
+
Array.isArray(value[1]) &&
|
|
1490
|
+
value[1].length === 2 &&
|
|
1491
|
+
value[1][0] === "get" &&
|
|
1492
|
+
typeof value[1][1] === "string" &&
|
|
1493
|
+
value.length > 3 &&
|
|
1494
|
+
value.length % 2 !== 0 &&
|
|
1495
|
+
value
|
|
1496
|
+
.slice(2)
|
|
1497
|
+
.filter((_, i) => i % 2 === 0)
|
|
1498
|
+
.every(e => typeof e === "number" ||
|
|
1499
|
+
typeof e === "string" ||
|
|
1500
|
+
(key === "text-field" && this.validateSupportedConcatExpression(key, e))) &&
|
|
1501
|
+
value
|
|
1502
|
+
.slice(2)
|
|
1503
|
+
.filter((_, i) => i % 2 !== 0)
|
|
1504
|
+
.every(e => typeof e === "number");
|
|
1505
|
+
if (!result) {
|
|
1506
|
+
if (this.options.verbose) {
|
|
1507
|
+
console.error("Validate supported step expression:", "invalid expression", key, value, "\n");
|
|
1508
|
+
}
|
|
1509
|
+
}
|
|
1510
|
+
return result;
|
|
1511
|
+
}
|
|
1512
|
+
validateLinearZoomInterpolate(key, value) {
|
|
1513
|
+
return (this.getSpecPropValueOptions(key)?.interpolateExpressionSupport &&
|
|
1514
|
+
isEqual(value[0], "interpolate") &&
|
|
1515
|
+
isEqual(value[1], ["linear"]) &&
|
|
1516
|
+
isEqual(value[2], ["zoom"]) &&
|
|
1517
|
+
value.length % 2 !== 0 &&
|
|
1518
|
+
value.length > 4 &&
|
|
1519
|
+
value
|
|
1520
|
+
.slice(3)
|
|
1521
|
+
.filter((_, i) => i % 2 === 0)
|
|
1522
|
+
.every(e => typeof e === "number") &&
|
|
1523
|
+
value
|
|
1524
|
+
.slice(3)
|
|
1525
|
+
.filter((_, i) => i % 2 !== 0)
|
|
1526
|
+
.every(e => {
|
|
1527
|
+
return (typeof e === "number" ||
|
|
1528
|
+
typeof e === "string" ||
|
|
1529
|
+
this.validateSupportedExpression(key, e, true) ||
|
|
1530
|
+
(key === "text-field" && this.validateSupportedConcatExpression(key, e)));
|
|
1531
|
+
}));
|
|
1532
|
+
}
|
|
1533
|
+
validateExponentialZoomInterpolate(key, value) {
|
|
1534
|
+
return (this.getSpecPropValueOptions(key)?.interpolateExpressionSupport &&
|
|
1535
|
+
isEqual(value[0], "interpolate") &&
|
|
1536
|
+
Array.isArray(value[1]) &&
|
|
1537
|
+
value[1].length === 2 &&
|
|
1538
|
+
value[1][0] === "exponential" &&
|
|
1539
|
+
typeof value[1][1] === "number" &&
|
|
1540
|
+
isEqual(value[2], ["zoom"]) &&
|
|
1541
|
+
value.length % 2 !== 0 &&
|
|
1542
|
+
value.length > 4 &&
|
|
1543
|
+
value
|
|
1544
|
+
.slice(3)
|
|
1545
|
+
.filter((_, i) => i % 2 === 0)
|
|
1546
|
+
.every(e => typeof e === "number") &&
|
|
1547
|
+
value
|
|
1548
|
+
.slice(3)
|
|
1549
|
+
.filter((_, i) => i % 2 !== 0)
|
|
1550
|
+
.every(e => {
|
|
1551
|
+
return (typeof e === "number" ||
|
|
1552
|
+
typeof e === "string" ||
|
|
1553
|
+
this.validateSupportedExpression(key, e, true) ||
|
|
1554
|
+
(key === "text-field" && this.validateSupportedConcatExpression(key, e)));
|
|
1555
|
+
}));
|
|
1632
1556
|
}
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
return
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
|
|
1557
|
+
validateCubicBezierZoomInterpolate(key, value) {
|
|
1558
|
+
return (this.getSpecPropValueOptions(key)?.interpolateExpressionSupport &&
|
|
1559
|
+
isEqual(value[0], "interpolate") &&
|
|
1560
|
+
Array.isArray(value[1]) &&
|
|
1561
|
+
value[1].length === 5 &&
|
|
1562
|
+
value[1][0] === "cubic-bezier" &&
|
|
1563
|
+
value[1].slice(1).every(e => typeof e === "number") &&
|
|
1564
|
+
isEqual(value[2], ["zoom"]) &&
|
|
1565
|
+
value.length % 2 !== 0 &&
|
|
1566
|
+
value.length > 4 &&
|
|
1567
|
+
value
|
|
1568
|
+
.slice(3)
|
|
1569
|
+
.filter((_, i) => i % 2 === 0)
|
|
1570
|
+
.every(e => typeof e === "number") &&
|
|
1571
|
+
value
|
|
1572
|
+
.slice(3)
|
|
1573
|
+
.filter((_, i) => i % 2 !== 0)
|
|
1574
|
+
.every(e => {
|
|
1575
|
+
return (typeof e === "number" ||
|
|
1576
|
+
typeof e === "string" ||
|
|
1577
|
+
this.validateSupportedExpression(key, e, true) ||
|
|
1578
|
+
(key === "text-field" && this.validateSupportedConcatExpression(key, e)));
|
|
1579
|
+
}));
|
|
1655
1580
|
}
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
|
|
1581
|
+
validateLinearDataInterpolate(key, value) {
|
|
1582
|
+
return (this.getSpecPropValueOptions(key)?.dataExpressionSupport &&
|
|
1583
|
+
isEqual(value[0], "interpolate") &&
|
|
1584
|
+
isEqual(value[1], ["linear"]) &&
|
|
1585
|
+
Array.isArray(value[2]) &&
|
|
1586
|
+
value[2].length === 2 &&
|
|
1587
|
+
value[2][0] === "get" &&
|
|
1588
|
+
typeof value[2][1] === "string" &&
|
|
1589
|
+
value.length % 2 !== 0 &&
|
|
1590
|
+
value.length > 4 &&
|
|
1591
|
+
value
|
|
1592
|
+
.slice(3)
|
|
1593
|
+
.filter((_, i) => i % 2 === 0)
|
|
1594
|
+
.every(e => typeof e === "number") &&
|
|
1595
|
+
value
|
|
1596
|
+
.slice(3)
|
|
1597
|
+
.filter((_, i) => i % 2 !== 0)
|
|
1598
|
+
.every(e => typeof e === "number" ||
|
|
1599
|
+
typeof e === "string" ||
|
|
1600
|
+
(key === "text-field" && this.validateSupportedConcatExpression(key, e))));
|
|
1668
1601
|
}
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
"#EC474C",
|
|
1693
|
-
"#FF7144",
|
|
1694
|
-
"#FF9F33",
|
|
1695
|
-
"#DEDE56",
|
|
1696
|
-
"#A1E062",
|
|
1697
|
-
"#51D8A5",
|
|
1698
|
-
];
|
|
1699
|
-
const HEX_RRGGBB_LENGTH = 7;
|
|
1700
|
-
/**
|
|
1701
|
-
* Растягивает палитру на нужное количество цветов: опорные цвета равномерно
|
|
1702
|
-
* раскладываются по шкале, недостающие интерполируются между ними.
|
|
1703
|
-
* @param colors - опорные цвета палитры в hex
|
|
1704
|
-
* @param count - требуемое количество цветов
|
|
1705
|
-
* @returns массив ровно из count цветов
|
|
1706
|
-
*/
|
|
1707
|
-
const stretchPalette = (colors, count) => {
|
|
1708
|
-
if (!colors?.length || count <= 0)
|
|
1709
|
-
return [];
|
|
1710
|
-
if (colors.length === 1)
|
|
1711
|
-
return Array.from({ length: count }, () => colors[0]);
|
|
1712
|
-
const scale = new ColorScale(colors.map((color, index) => [index / (colors.length - 1), color]));
|
|
1713
|
-
return Array.from({ length: count }, (_, index) => {
|
|
1714
|
-
const color = scale.getColor(count === 1 ? 0 : index / (count - 1));
|
|
1715
|
-
return color ? new Color(color).toString("hex").slice(0, HEX_RRGGBB_LENGTH) : colors[colors.length - 1];
|
|
1716
|
-
});
|
|
1717
|
-
};
|
|
1718
|
-
const getGradientColors = (colorsCount) => stretchPalette(GRADIENT_COLORS, colorsCount === undefined || colorsCount < GRADIENT_COLORS.length ? GRADIENT_COLORS.length : colorsCount);
|
|
1719
|
-
/**
|
|
1720
|
-
* Converts HSL hue value to RGB
|
|
1721
|
-
* @param p - lower bound
|
|
1722
|
-
* @param q - upper bound
|
|
1723
|
-
* @param t - hue value
|
|
1724
|
-
* @returns RGB component value (0-1)
|
|
1725
|
-
*/
|
|
1726
|
-
const hue2rgb = (p, q, t) => {
|
|
1727
|
-
if (t < 0)
|
|
1728
|
-
t += 1;
|
|
1729
|
-
if (t > 1)
|
|
1730
|
-
t -= 1;
|
|
1731
|
-
if (t < 1 / 6)
|
|
1732
|
-
return p + (q - p) * 6 * t;
|
|
1733
|
-
if (t < 1 / 2)
|
|
1734
|
-
return q;
|
|
1735
|
-
if (t < 2 / 3)
|
|
1736
|
-
return p + (q - p) * (2 / 3 - t) * 6;
|
|
1737
|
-
return p;
|
|
1738
|
-
};
|
|
1739
|
-
/**
|
|
1740
|
-
* Converts RGB component (0-1) to hex string
|
|
1741
|
-
* @param value - RGB component value (0-1)
|
|
1742
|
-
* @returns hex string (00-ff)
|
|
1743
|
-
*/
|
|
1744
|
-
const toHex = (value) => {
|
|
1745
|
-
const hex = Math.round(value * 255).toString(16);
|
|
1746
|
-
return hex.padStart(2, "0");
|
|
1747
|
-
};
|
|
1748
|
-
/**
|
|
1749
|
-
* Adjusts color brightness
|
|
1750
|
-
* @param color - hex color string (e.g., "#2196f3")
|
|
1751
|
-
* @param lightnessAdjustment - lightness adjustment in HSL units (e.g., 5 or -5)
|
|
1752
|
-
* @returns adjusted color in hex format
|
|
1753
|
-
*/
|
|
1754
|
-
const adjustColor = (color, lightnessAdjustment = 5) => {
|
|
1755
|
-
// Convert hex to RGB
|
|
1756
|
-
const hex = color.replace("#", "");
|
|
1757
|
-
const r = parseInt(hex.substring(0, 2), 16) / 255;
|
|
1758
|
-
const g = parseInt(hex.substring(2, 4), 16) / 255;
|
|
1759
|
-
const b = parseInt(hex.substring(4, 6), 16) / 255;
|
|
1760
|
-
// Convert RGB to HSL
|
|
1761
|
-
const max = Math.max(r, g, b);
|
|
1762
|
-
const min = Math.min(r, g, b);
|
|
1763
|
-
let h = 0;
|
|
1764
|
-
let s = 0;
|
|
1765
|
-
const l = (max + min) / 2;
|
|
1766
|
-
if (max !== min) {
|
|
1767
|
-
const d = max - min;
|
|
1768
|
-
s = l > 0.5 ? d / (2 - max - min) : d / (max + min);
|
|
1769
|
-
switch (max) {
|
|
1770
|
-
case r:
|
|
1771
|
-
h = ((g - b) / d + (g < b ? 6 : 0)) / 6;
|
|
1772
|
-
break;
|
|
1773
|
-
case g:
|
|
1774
|
-
h = ((b - r) / d + 2) / 6;
|
|
1775
|
-
break;
|
|
1776
|
-
case b:
|
|
1777
|
-
h = ((r - g) / d + 4) / 6;
|
|
1778
|
-
break;
|
|
1779
|
-
}
|
|
1602
|
+
validateExponentialDataInterpolate(key, value) {
|
|
1603
|
+
return (this.getSpecPropValueOptions(key)?.dataExpressionSupport &&
|
|
1604
|
+
isEqual(value[0], "interpolate") &&
|
|
1605
|
+
Array.isArray(value[1]) &&
|
|
1606
|
+
value[1].length === 2 &&
|
|
1607
|
+
value[1][0] === "exponential" &&
|
|
1608
|
+
typeof value[1][1] === "number" &&
|
|
1609
|
+
Array.isArray(value[2]) &&
|
|
1610
|
+
value[2].length === 2 &&
|
|
1611
|
+
value[2][0] === "get" &&
|
|
1612
|
+
typeof value[2][1] === "string" &&
|
|
1613
|
+
value.length % 2 !== 0 &&
|
|
1614
|
+
value.length > 4 &&
|
|
1615
|
+
value
|
|
1616
|
+
.slice(3)
|
|
1617
|
+
.filter((_, i) => i % 2 === 0)
|
|
1618
|
+
.every(e => typeof e === "number") &&
|
|
1619
|
+
value
|
|
1620
|
+
.slice(3)
|
|
1621
|
+
.filter((_, i) => i % 2 !== 0)
|
|
1622
|
+
.every(e => typeof e === "number" ||
|
|
1623
|
+
typeof e === "string" ||
|
|
1624
|
+
(key === "text-field" && this.validateSupportedConcatExpression(key, e))));
|
|
1780
1625
|
}
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
|
|
1626
|
+
validateCubicBezierDataInterpolate(key, value) {
|
|
1627
|
+
return (this.getSpecPropValueOptions(key)?.dataExpressionSupport &&
|
|
1628
|
+
isEqual(value[0], "interpolate") &&
|
|
1629
|
+
Array.isArray(value[1]) &&
|
|
1630
|
+
value[1].length === 5 &&
|
|
1631
|
+
value[1][0] === "cubic-bezier" &&
|
|
1632
|
+
value[1].slice(1).every(e => typeof e === "number") &&
|
|
1633
|
+
Array.isArray(value[2]) &&
|
|
1634
|
+
value[2].length === 2 &&
|
|
1635
|
+
value[2][0] === "get" &&
|
|
1636
|
+
typeof value[2][1] === "string" &&
|
|
1637
|
+
value.length % 2 !== 0 &&
|
|
1638
|
+
value.length > 4 &&
|
|
1639
|
+
value
|
|
1640
|
+
.slice(3)
|
|
1641
|
+
.filter((_, i) => i % 2 === 0)
|
|
1642
|
+
.every(e => typeof e === "number") &&
|
|
1643
|
+
value
|
|
1644
|
+
.slice(3)
|
|
1645
|
+
.filter((_, i) => i % 2 !== 0)
|
|
1646
|
+
.every(e => typeof e === "number" ||
|
|
1647
|
+
typeof e === "string" ||
|
|
1648
|
+
(key === "text-field" && this.validateSupportedConcatExpression(key, e))));
|
|
1788
1649
|
}
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
|
|
1792
|
-
|
|
1793
|
-
gNew = hue2rgb(p, q, h);
|
|
1794
|
-
bNew = hue2rgb(p, q, h - 1 / 3);
|
|
1650
|
+
validateZoomInterpolate(key, value) {
|
|
1651
|
+
return (this.validateLinearZoomInterpolate(key, value) ||
|
|
1652
|
+
this.validateExponentialZoomInterpolate(key, value) ||
|
|
1653
|
+
this.validateCubicBezierZoomInterpolate(key, value));
|
|
1795
1654
|
}
|
|
1796
|
-
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
* Цвет в hex: `#rrggbb`, а при неполной непрозрачности — `#rrggbbaa`.
|
|
1801
|
-
*
|
|
1802
|
-
* Полностью непрозрачная альфа отбрасывается: в значении она ничего не уточняет, а строку
|
|
1803
|
-
* удлиняет — и в конфиге, и в данных удобнее короткая запись.
|
|
1804
|
-
*/
|
|
1805
|
-
const colorToHex = (color) => {
|
|
1806
|
-
const hex = color.toString("hex");
|
|
1807
|
-
return hex.slice(HEX_RRGGBB_LENGTH).toLowerCase() === OPAQUE_ALPHA ? hex.slice(0, HEX_RRGGBB_LENGTH) : hex;
|
|
1808
|
-
};
|
|
1809
|
-
|
|
1810
|
-
const NO_CONTENT_VALUE = "—";
|
|
1811
|
-
exports.DateFormat = void 0;
|
|
1812
|
-
(function (DateFormat) {
|
|
1813
|
-
DateFormat["ClientDefaultFormat"] = "dd.MM.yyyy HH:mm";
|
|
1814
|
-
DateFormat["DateTime"] = "dd.MM.yyyy HH:mm:ss";
|
|
1815
|
-
DateFormat["UTC"] = "yyyy-MM-dd'T'HH:mm:ss.sssxxx";
|
|
1816
|
-
DateFormat["AxisTooltip"] = "d MMMM yyyy";
|
|
1817
|
-
})(exports.DateFormat || (exports.DateFormat = {}));
|
|
1818
|
-
const stringDateParsers = [dateFns.parseJSON, dateFns.parseISO, rawDate => new Date(rawDate)];
|
|
1819
|
-
const getDate = (rawDate) => {
|
|
1820
|
-
if (!rawDate) {
|
|
1821
|
-
return null;
|
|
1655
|
+
validateDataInterpolate(key, value) {
|
|
1656
|
+
return (this.validateLinearDataInterpolate(key, value) ||
|
|
1657
|
+
this.validateExponentialDataInterpolate(key, value) ||
|
|
1658
|
+
this.validateCubicBezierDataInterpolate(key, value));
|
|
1822
1659
|
}
|
|
1823
|
-
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
|
|
1827
|
-
return dateFns.toDate(date);
|
|
1660
|
+
validateSupportedInterpolateExpression(key, value, excludeZoomInterpolate) {
|
|
1661
|
+
if (!mapboxGlStyleSpec.expression.isExpression(value)) {
|
|
1662
|
+
if (this.options.verbose) {
|
|
1663
|
+
console.error("Validate supported interpolate expression:", "not an expression", key, value, "\n");
|
|
1828
1664
|
}
|
|
1665
|
+
return false;
|
|
1829
1666
|
}
|
|
1830
|
-
|
|
1667
|
+
if (key === "heatmap-color") {
|
|
1668
|
+
const isColorValid = this.isHeatmapColorValid(value);
|
|
1669
|
+
if (!isColorValid) {
|
|
1670
|
+
if (this.options.verbose) {
|
|
1671
|
+
console.error("Validate supported interpolate expression:", "invalid color value", key, value, "\n");
|
|
1672
|
+
}
|
|
1673
|
+
}
|
|
1674
|
+
return this.isHeatmapColorValid(value);
|
|
1675
|
+
}
|
|
1676
|
+
if (!this.getSpecPropValueOptions(key)?.interpolateExpressionSupport &&
|
|
1677
|
+
!this.getSpecPropValueOptions(key)?.dataExpressionSupport) {
|
|
1678
|
+
if (this.options.verbose) {
|
|
1679
|
+
console.error("Validate supported interpolate expression:", "interpolate not supported", key, value, "\n");
|
|
1680
|
+
}
|
|
1681
|
+
}
|
|
1682
|
+
const result = (!excludeZoomInterpolate && this.validateZoomInterpolate(key, value)) || this.validateDataInterpolate(key, value);
|
|
1683
|
+
if (!result) {
|
|
1684
|
+
if (this.options.verbose) {
|
|
1685
|
+
console.error("Validate supported interpolate expression:", "invalid expression", key, value, "\n");
|
|
1686
|
+
}
|
|
1687
|
+
}
|
|
1688
|
+
return result;
|
|
1831
1689
|
}
|
|
1832
|
-
|
|
1833
|
-
|
|
1834
|
-
|
|
1835
|
-
|
|
1836
|
-
|
|
1837
|
-
|
|
1838
|
-
|
|
1690
|
+
validateSupportedExpression(key, value, excludeZoomInterpolate) {
|
|
1691
|
+
if (!mapboxGlStyleSpec.expression.isExpression(value)) {
|
|
1692
|
+
if (this.options.verbose) {
|
|
1693
|
+
console.error("Validate supported expression:", "not an expression", key, value, "\n");
|
|
1694
|
+
}
|
|
1695
|
+
return false;
|
|
1696
|
+
}
|
|
1697
|
+
const expressionType = value[0];
|
|
1698
|
+
if (typeof expressionType !== "string" ||
|
|
1699
|
+
!["match", "case", "step", "interpolate", "concat"].includes(expressionType)) {
|
|
1700
|
+
if (this.options.verbose) {
|
|
1701
|
+
console.error("Validate supported expression:", "expression type not supported", key, value, "\n");
|
|
1702
|
+
}
|
|
1703
|
+
return false;
|
|
1704
|
+
}
|
|
1705
|
+
switch (expressionType) {
|
|
1706
|
+
case "match":
|
|
1707
|
+
return this.validateSupportedMatchExpression(key, value);
|
|
1708
|
+
case "case":
|
|
1709
|
+
return this.validateSupportedCaseExpression(key, value);
|
|
1710
|
+
case "step":
|
|
1711
|
+
return this.validateSupportedStepExpression(key, value);
|
|
1712
|
+
case "concat":
|
|
1713
|
+
return this.validateSupportedConcatExpression(key, value);
|
|
1714
|
+
case "interpolate":
|
|
1715
|
+
return this.validateSupportedInterpolateExpression(key, value, excludeZoomInterpolate);
|
|
1716
|
+
default:
|
|
1717
|
+
return false;
|
|
1718
|
+
}
|
|
1839
1719
|
}
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
|
|
1843
|
-
|
|
1844
|
-
|
|
1845
|
-
|
|
1846
|
-
|
|
1847
|
-
window.clearTimeout(timeId);
|
|
1720
|
+
validateTransitionValue(key, value) {
|
|
1721
|
+
const propValueOptions = this.getSpecPropValueOptions(key.replace(/-transition$/, ""));
|
|
1722
|
+
if (propValueOptions && propValueOptions.transitionable === false) {
|
|
1723
|
+
if (this.options.verbose) {
|
|
1724
|
+
console.error("Validate transition value:", "transition not supported", key, value, "\n");
|
|
1725
|
+
}
|
|
1726
|
+
return false;
|
|
1848
1727
|
}
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
const COMPACT_FRACTION_DIGITS = 1;
|
|
1859
|
-
const roundTotalSum = (value, fractionDigits) => {
|
|
1860
|
-
if (!value)
|
|
1861
|
-
return "";
|
|
1862
|
-
const digits = fractionDigits ?? COMPACT_FRACTION_DIGITS;
|
|
1863
|
-
if (value >= MILLION) {
|
|
1864
|
-
return `${(value / MILLION).toFixed(digits)}M`;
|
|
1728
|
+
const result = isObject(value) &&
|
|
1729
|
+
(("delay" in value && typeof value.delay === "number") ||
|
|
1730
|
+
("duration" in value && typeof value.duration === "number"));
|
|
1731
|
+
if (!result) {
|
|
1732
|
+
if (this.options.verbose) {
|
|
1733
|
+
console.error("Validate transition value:", "invalid transition value", key, value, "\n");
|
|
1734
|
+
}
|
|
1735
|
+
}
|
|
1736
|
+
return result;
|
|
1865
1737
|
}
|
|
1866
|
-
|
|
1867
|
-
|
|
1738
|
+
validateSpecPropValue(key, value) {
|
|
1739
|
+
if (key.endsWith("-transition")) {
|
|
1740
|
+
return this.validateTransitionValue(key, value);
|
|
1741
|
+
}
|
|
1742
|
+
const propValueOptions = this.getSpecPropValueOptions(key);
|
|
1743
|
+
if (!propValueOptions) {
|
|
1744
|
+
return (typeof value === "string" ||
|
|
1745
|
+
typeof value === "number" ||
|
|
1746
|
+
typeof value === "boolean" ||
|
|
1747
|
+
(Array.isArray(value) && value.every(item => typeof item === "number")) ||
|
|
1748
|
+
(Array.isArray(value) && value.every(item => typeof item === "string")) ||
|
|
1749
|
+
mapboxGlStyleSpec.expression.isExpression(value));
|
|
1750
|
+
}
|
|
1751
|
+
if (propValueOptions.arrayValue) {
|
|
1752
|
+
return (typeof value === propValueOptions.valueTypeAllowed ||
|
|
1753
|
+
(Array.isArray(value) && value.every(item => typeof item === propValueOptions.valueTypeAllowed)) ||
|
|
1754
|
+
this.validateSupportedExpression(key, value));
|
|
1755
|
+
}
|
|
1756
|
+
return typeof value === propValueOptions.valueTypeAllowed || this.validateSupportedExpression(key, value);
|
|
1868
1757
|
}
|
|
1869
|
-
|
|
1870
|
-
};
|
|
1758
|
+
}
|
|
1871
1759
|
|
|
1872
|
-
const
|
|
1873
|
-
|
|
1874
|
-
|
|
1875
|
-
|
|
1876
|
-
|
|
1877
|
-
|
|
1878
|
-
|
|
1879
|
-
|
|
1880
|
-
})
|
|
1881
|
-
|
|
1882
|
-
const timeOptions = [
|
|
1883
|
-
{
|
|
1884
|
-
text: formatDate("kk:mm:ss"),
|
|
1885
|
-
value: "hh:mm:ss",
|
|
1886
|
-
},
|
|
1887
|
-
{
|
|
1888
|
-
text: formatDate("hh:mm:ss aa"),
|
|
1889
|
-
value: "hh:mm:ss tt",
|
|
1890
|
-
},
|
|
1891
|
-
{
|
|
1892
|
-
text: formatDate("kk:mm"),
|
|
1893
|
-
value: "hh:mm",
|
|
1894
|
-
},
|
|
1895
|
-
{
|
|
1896
|
-
text: formatDate("hh:mm aa"),
|
|
1897
|
-
value: "hh:mm tt",
|
|
1898
|
-
},
|
|
1899
|
-
];
|
|
1900
|
-
const dateOptions = [
|
|
1901
|
-
{
|
|
1902
|
-
text: formatDate("dd.MM.yyyy"),
|
|
1903
|
-
value: "dd.MM.yyyy",
|
|
1904
|
-
},
|
|
1905
|
-
{
|
|
1906
|
-
text: formatDate("dd MMMM yyyy", true),
|
|
1907
|
-
value: "dd MMMM yyyy",
|
|
1908
|
-
},
|
|
1909
|
-
{
|
|
1910
|
-
text: formatDate("yyyy, dd MMMM", true),
|
|
1911
|
-
value: "yyyy, dd MMMM",
|
|
1912
|
-
},
|
|
1913
|
-
];
|
|
1914
|
-
const pointOptions = [
|
|
1915
|
-
{
|
|
1916
|
-
value: "default",
|
|
1917
|
-
localizationKey: "defaultValue",
|
|
1918
|
-
},
|
|
1919
|
-
{
|
|
1920
|
-
value: "DD MM SS",
|
|
1921
|
-
localizationKey: "degreesMinutesSeconds",
|
|
1922
|
-
},
|
|
1923
|
-
{
|
|
1924
|
-
value: "DD.",
|
|
1925
|
-
localizationKey: "decimalDegrees",
|
|
1926
|
-
},
|
|
1927
|
-
];
|
|
1928
|
-
const numberOptions = [
|
|
1929
|
-
{
|
|
1930
|
-
value: exports.ScalingFactor.Default.toString(),
|
|
1931
|
-
localizationKey: "defaultValue",
|
|
1932
|
-
},
|
|
1933
|
-
{
|
|
1934
|
-
value: exports.ScalingFactor.Thousands.toString(),
|
|
1935
|
-
localizationKey: "inThousands",
|
|
1936
|
-
},
|
|
1937
|
-
{
|
|
1938
|
-
value: exports.ScalingFactor.Millions.toString(),
|
|
1939
|
-
localizationKey: "inMillions",
|
|
1940
|
-
},
|
|
1941
|
-
{
|
|
1942
|
-
value: exports.ScalingFactor.Acres.toString(),
|
|
1943
|
-
localizationKey: "inAcres",
|
|
1944
|
-
},
|
|
1945
|
-
{
|
|
1946
|
-
value: exports.ScalingFactor.Hectares.toString(),
|
|
1947
|
-
localizationKey: "inHectares",
|
|
1948
|
-
},
|
|
1949
|
-
];
|
|
1950
|
-
const convertDDToDMS = (value) => {
|
|
1951
|
-
const absolute = Math.abs(value);
|
|
1952
|
-
const degrees = Math.floor(absolute);
|
|
1953
|
-
const minutesNotTruncated = (absolute - degrees) * 60;
|
|
1954
|
-
const minutes = Math.floor(minutesNotTruncated);
|
|
1955
|
-
const seconds = Math.floor((minutesNotTruncated - minutes) * 60);
|
|
1956
|
-
return `${degrees}° ${minutes}' ${seconds}"`;
|
|
1760
|
+
const enrichStyleItemsWithIds = (style) => {
|
|
1761
|
+
return {
|
|
1762
|
+
...style,
|
|
1763
|
+
items: style.items.map(item => {
|
|
1764
|
+
return {
|
|
1765
|
+
...item,
|
|
1766
|
+
id: item.id || uuid.v4(),
|
|
1767
|
+
};
|
|
1768
|
+
}),
|
|
1769
|
+
};
|
|
1957
1770
|
};
|
|
1958
|
-
|
|
1959
|
-
|
|
1960
|
-
|
|
1961
|
-
|
|
1962
|
-
|
|
1963
|
-
|
|
1964
|
-
return `${convertDDToDMS(lon)} ${lonDirection}, ${convertDDToDMS(lat)} ${latDirection}`;
|
|
1771
|
+
|
|
1772
|
+
/** Стабильный ID элемента стиля для MapLibre, в том числе когда `item.id` не задан. */
|
|
1773
|
+
const getClientStyleItemId = (items, index) => {
|
|
1774
|
+
const explicitId = items[index]?.id;
|
|
1775
|
+
if (explicitId) {
|
|
1776
|
+
return explicitId;
|
|
1965
1777
|
}
|
|
1966
|
-
|
|
1967
|
-
|
|
1968
|
-
|
|
1778
|
+
const explicitIds = new Set(items.map(item => item.id).filter(Boolean));
|
|
1779
|
+
let generatedId = `__item_${index}`;
|
|
1780
|
+
while (explicitIds.has(generatedId)) {
|
|
1781
|
+
generatedId = `_${generatedId}`;
|
|
1969
1782
|
}
|
|
1970
|
-
return
|
|
1783
|
+
return generatedId;
|
|
1971
1784
|
};
|
|
1972
|
-
|
|
1973
|
-
const
|
|
1974
|
-
|
|
1975
|
-
|
|
1976
|
-
|
|
1977
|
-
|
|
1978
|
-
|
|
1979
|
-
|
|
1785
|
+
|
|
1786
|
+
const enrichStyleModelsWithIds = (style) => {
|
|
1787
|
+
return {
|
|
1788
|
+
...style,
|
|
1789
|
+
models: style.models.map(model => {
|
|
1790
|
+
return {
|
|
1791
|
+
...model,
|
|
1792
|
+
id: model.id || uuid.v4(),
|
|
1793
|
+
};
|
|
1794
|
+
}),
|
|
1795
|
+
};
|
|
1980
1796
|
};
|
|
1981
|
-
|
|
1982
|
-
|
|
1983
|
-
if (
|
|
1984
|
-
|
|
1797
|
+
|
|
1798
|
+
const findAttributeInExpression = (expression) => {
|
|
1799
|
+
if (Array.isArray(expression) && expression.length === 2 && expression[0] === "get") {
|
|
1800
|
+
return [expression[1]];
|
|
1985
1801
|
}
|
|
1986
|
-
|
|
1987
|
-
|
|
1988
|
-
|
|
1989
|
-
|
|
1990
|
-
|
|
1991
|
-
|
|
1992
|
-
|
|
1993
|
-
|
|
1994
|
-
|
|
1995
|
-
const timeOption = getValueFromOptions(timeOptions, stringFormat.format);
|
|
1996
|
-
const timeOptionValue = timeOption && (isRuLocale ? timeOption.value : `${timeOption.value} aa`);
|
|
1997
|
-
const timeFormat = (timeOptionValue && dateFns.format(value, showTimeZone ? `${timeOptionValue} zz` : timeOptionValue)) || "";
|
|
1998
|
-
return dateFormat ? [dateFormat, timeFormat].filter(Boolean).join(" ") : "";
|
|
1802
|
+
return expression.reduce((acc, curr) => {
|
|
1803
|
+
if (!Array.isArray(curr)) {
|
|
1804
|
+
return acc;
|
|
1805
|
+
}
|
|
1806
|
+
if (curr[0] === "get") {
|
|
1807
|
+
return [...new Set([...acc, curr[1]])];
|
|
1808
|
+
}
|
|
1809
|
+
return [...new Set([...acc, ...findAttributeInExpression(curr)])];
|
|
1810
|
+
}, []);
|
|
1999
1811
|
};
|
|
2000
|
-
|
|
2001
|
-
const
|
|
2002
|
-
|
|
2003
|
-
|
|
2004
|
-
|
|
2005
|
-
|
|
2006
|
-
|
|
2007
|
-
|
|
2008
|
-
|
|
2009
|
-
|
|
2010
|
-
|
|
2011
|
-
|
|
2012
|
-
|
|
2013
|
-
|
|
2014
|
-
|
|
2015
|
-
|
|
2016
|
-
if (
|
|
2017
|
-
return
|
|
2018
|
-
}
|
|
2019
|
-
if (hasRounding && (!isIntValue || !isDefaultScaling) && !lodash.isNil(currentValue)) {
|
|
2020
|
-
currentValue = Number(currentValue).toFixed(rounding);
|
|
2021
|
-
}
|
|
2022
|
-
if (splitDigitGroup) {
|
|
2023
|
-
currentValue = numberWithSpaces(currentValue);
|
|
1812
|
+
|
|
1813
|
+
const getActualExtrusionHeight = (paint) => {
|
|
1814
|
+
return Array.isArray(paint?.["fill-extrusion-height"]) && paint?.["fill-extrusion-height"][0] === "+"
|
|
1815
|
+
? paint?.["fill-extrusion-height"][1]
|
|
1816
|
+
: paint?.["fill-extrusion-height"];
|
|
1817
|
+
};
|
|
1818
|
+
|
|
1819
|
+
const getLayerClientStyle = (layer) => {
|
|
1820
|
+
const clientStyle = layer?.configuration?.clientStyle;
|
|
1821
|
+
return {
|
|
1822
|
+
...clientStyle,
|
|
1823
|
+
items: clientStyle?.items ?? [],
|
|
1824
|
+
};
|
|
1825
|
+
};
|
|
1826
|
+
|
|
1827
|
+
const extractAttributesFromObject = (obj) => {
|
|
1828
|
+
if (!obj || isEmpty(obj)) {
|
|
1829
|
+
return [];
|
|
2024
1830
|
}
|
|
2025
|
-
|
|
2026
|
-
|
|
1831
|
+
return Object.entries(obj).reduce((acc, [, value]) => {
|
|
1832
|
+
if (!Array.isArray(value)) {
|
|
1833
|
+
return acc;
|
|
1834
|
+
}
|
|
1835
|
+
return [...new Set([...acc, ...findAttributeInExpression(value)])];
|
|
1836
|
+
}, []);
|
|
1837
|
+
};
|
|
1838
|
+
const getStyleAttributes = (style) => {
|
|
1839
|
+
if (!style) {
|
|
1840
|
+
return [];
|
|
2027
1841
|
}
|
|
2028
|
-
return
|
|
1842
|
+
return style?.items?.reduce((acc, curr) => {
|
|
1843
|
+
const paintAttributes = extractAttributesFromObject(curr.paint);
|
|
1844
|
+
const layoutAttributes = extractAttributesFromObject(curr.layout);
|
|
1845
|
+
const filterAttributes = curr.filter
|
|
1846
|
+
? findAttributeInExpression(curr.filter)
|
|
1847
|
+
: [];
|
|
1848
|
+
return [...new Set([...acc, ...paintAttributes, ...layoutAttributes, ...filterAttributes])];
|
|
1849
|
+
}, []);
|
|
1850
|
+
};
|
|
1851
|
+
|
|
1852
|
+
const DEFAULT_COLOR = "#00ffff";
|
|
1853
|
+
const DEFAULT_BLUR = 0;
|
|
1854
|
+
const DEFAULT_OPACITY = 0.5;
|
|
1855
|
+
const DEFAULT_TRANSLATE = [0, 0];
|
|
1856
|
+
const DEFAULT_FILL_EXTRUSION_BASE = 0;
|
|
1857
|
+
const DEFAULT_FILL_EXTRUSION_VERTICAL_GRADIENT = true;
|
|
1858
|
+
const DEFAULT_FILL_EXTRUSION_HEIGHT = 0;
|
|
1859
|
+
const DEFAULT_CIRCLE_RADIUS = 4;
|
|
1860
|
+
const DEFAULT_CIRCLE_STROKE_WIDTH = 0;
|
|
1861
|
+
const DEFAULT_LINE_WIDTH = 1;
|
|
1862
|
+
const DEFAULT_LINE_CAP = "butt";
|
|
1863
|
+
const DEFAULT_LINE_JOIN = "miter";
|
|
1864
|
+
const DEFAULT_SYMBOL_COLOR = "#000000";
|
|
1865
|
+
const DEFAULT_SYMBOL_HALO_COLOR = "#ffffff";
|
|
1866
|
+
const DEFAULT_SYMBOL_PLACEMENT = "point";
|
|
1867
|
+
const DEFAULT_SYMBOL_SPACING = 250;
|
|
1868
|
+
const DEFAULT_ICON_OVERLAP = "never";
|
|
1869
|
+
const DEFAULT_ICON_SIZE = 0.5;
|
|
1870
|
+
const DEFAULT_ICON_ANCHOR = "center";
|
|
1871
|
+
const DEFAULT_ICON_PADDING = [2];
|
|
1872
|
+
const DEFAULT_ICON_ROTATE = 0;
|
|
1873
|
+
const DEFAULT_TEXT_SIZE = 16;
|
|
1874
|
+
const DEFAULT_TEXT_ANCHOR = "center";
|
|
1875
|
+
const DEFAULT_TEXT_JUSTIFY = "center";
|
|
1876
|
+
const DEFAULT_TEXT_TRANSFORM = "none";
|
|
1877
|
+
const DEFAULT_HEATMAP_RADIUS = 30;
|
|
1878
|
+
const DEFAULT_HEATMAP_WEIGHT = 1;
|
|
1879
|
+
const DEFAULT_HEATMAP_INTENSITY = 1;
|
|
1880
|
+
const DEFAULT_HEATMAP_COLOR = [
|
|
1881
|
+
"interpolate",
|
|
1882
|
+
["linear"],
|
|
1883
|
+
["heatmap-density"],
|
|
1884
|
+
0, "rgba(0, 0, 255, 0)",
|
|
1885
|
+
0.1, "royalblue",
|
|
1886
|
+
0.3, "cyan",
|
|
1887
|
+
0.5, "lime",
|
|
1888
|
+
0.7, "yellow",
|
|
1889
|
+
1, "red",
|
|
1890
|
+
];
|
|
1891
|
+
const DEFAULT_FILL_STYLE = {
|
|
1892
|
+
items: [
|
|
1893
|
+
{
|
|
1894
|
+
type: "fill",
|
|
1895
|
+
layout: {},
|
|
1896
|
+
paint: {
|
|
1897
|
+
"fill-color": DEFAULT_COLOR,
|
|
1898
|
+
"fill-opacity": DEFAULT_OPACITY,
|
|
1899
|
+
},
|
|
1900
|
+
},
|
|
1901
|
+
],
|
|
1902
|
+
};
|
|
1903
|
+
const DEFAULT_FILL_EXTRUSION_STYLE = {
|
|
1904
|
+
items: [
|
|
1905
|
+
{
|
|
1906
|
+
type: "fill-extrusion",
|
|
1907
|
+
layout: {},
|
|
1908
|
+
paint: {
|
|
1909
|
+
"fill-extrusion-base": DEFAULT_FILL_EXTRUSION_BASE,
|
|
1910
|
+
"fill-extrusion-vertical-gradient": DEFAULT_FILL_EXTRUSION_VERTICAL_GRADIENT,
|
|
1911
|
+
"fill-extrusion-color": DEFAULT_COLOR,
|
|
1912
|
+
"fill-extrusion-opacity": DEFAULT_OPACITY,
|
|
1913
|
+
"fill-extrusion-height": DEFAULT_FILL_EXTRUSION_HEIGHT,
|
|
1914
|
+
},
|
|
1915
|
+
},
|
|
1916
|
+
],
|
|
1917
|
+
};
|
|
1918
|
+
const DEFAULT_LINE_STYLE = {
|
|
1919
|
+
items: [
|
|
1920
|
+
{
|
|
1921
|
+
type: "line",
|
|
1922
|
+
layout: {
|
|
1923
|
+
"line-cap": DEFAULT_LINE_CAP,
|
|
1924
|
+
"line-join": DEFAULT_LINE_JOIN,
|
|
1925
|
+
},
|
|
1926
|
+
paint: {
|
|
1927
|
+
"line-color": DEFAULT_COLOR,
|
|
1928
|
+
"line-width": DEFAULT_LINE_WIDTH,
|
|
1929
|
+
"line-blur": DEFAULT_BLUR,
|
|
1930
|
+
"line-opacity": DEFAULT_OPACITY,
|
|
1931
|
+
"line-translate": DEFAULT_TRANSLATE,
|
|
1932
|
+
},
|
|
1933
|
+
},
|
|
1934
|
+
],
|
|
1935
|
+
};
|
|
1936
|
+
const DEFAULT_CIRCLE_STYLE = {
|
|
1937
|
+
items: [
|
|
1938
|
+
{
|
|
1939
|
+
type: "circle",
|
|
1940
|
+
layout: {},
|
|
1941
|
+
paint: {
|
|
1942
|
+
"circle-radius": DEFAULT_CIRCLE_RADIUS,
|
|
1943
|
+
"circle-color": DEFAULT_COLOR,
|
|
1944
|
+
"circle-blur": DEFAULT_BLUR,
|
|
1945
|
+
"circle-opacity": DEFAULT_OPACITY,
|
|
1946
|
+
"circle-translate": DEFAULT_TRANSLATE,
|
|
1947
|
+
"circle-stroke-width": DEFAULT_CIRCLE_STROKE_WIDTH,
|
|
1948
|
+
"circle-stroke-color": DEFAULT_COLOR,
|
|
1949
|
+
"circle-stroke-opacity": DEFAULT_OPACITY,
|
|
1950
|
+
},
|
|
1951
|
+
},
|
|
1952
|
+
],
|
|
1953
|
+
};
|
|
1954
|
+
const DEFAULT_SYMBOL_STYLE = {
|
|
1955
|
+
items: [
|
|
1956
|
+
{
|
|
1957
|
+
type: "symbol",
|
|
1958
|
+
layout: {
|
|
1959
|
+
"symbol-placement": DEFAULT_SYMBOL_PLACEMENT,
|
|
1960
|
+
"symbol-spacing": DEFAULT_SYMBOL_SPACING,
|
|
1961
|
+
"icon-overlap": DEFAULT_ICON_OVERLAP,
|
|
1962
|
+
"icon-size": DEFAULT_ICON_SIZE,
|
|
1963
|
+
"icon-anchor": DEFAULT_ICON_ANCHOR,
|
|
1964
|
+
"icon-padding": DEFAULT_ICON_PADDING,
|
|
1965
|
+
"icon-rotate": DEFAULT_ICON_ROTATE,
|
|
1966
|
+
"text-size": DEFAULT_TEXT_SIZE,
|
|
1967
|
+
"text-anchor": DEFAULT_TEXT_ANCHOR,
|
|
1968
|
+
"text-justify": DEFAULT_TEXT_JUSTIFY,
|
|
1969
|
+
"text-transform": DEFAULT_TEXT_TRANSFORM,
|
|
1970
|
+
},
|
|
1971
|
+
paint: {
|
|
1972
|
+
"icon-color": DEFAULT_SYMBOL_COLOR,
|
|
1973
|
+
"icon-halo-color": DEFAULT_SYMBOL_HALO_COLOR,
|
|
1974
|
+
"icon-opacity": DEFAULT_OPACITY,
|
|
1975
|
+
"text-color": DEFAULT_SYMBOL_COLOR,
|
|
1976
|
+
"text-halo-color": DEFAULT_SYMBOL_HALO_COLOR,
|
|
1977
|
+
"text-opacity": DEFAULT_OPACITY,
|
|
1978
|
+
},
|
|
1979
|
+
},
|
|
1980
|
+
],
|
|
2029
1981
|
};
|
|
2030
|
-
const
|
|
2031
|
-
|
|
2032
|
-
|
|
2033
|
-
|
|
2034
|
-
|
|
2035
|
-
|
|
2036
|
-
|
|
2037
|
-
|
|
2038
|
-
|
|
2039
|
-
|
|
2040
|
-
|
|
2041
|
-
|
|
2042
|
-
|
|
2043
|
-
|
|
2044
|
-
|
|
2045
|
-
|
|
2046
|
-
|
|
2047
|
-
|
|
2048
|
-
|
|
2049
|
-
|
|
2050
|
-
|
|
2051
|
-
|
|
2052
|
-
|
|
2053
|
-
|
|
2054
|
-
|
|
2055
|
-
|
|
2056
|
-
|
|
2057
|
-
|
|
2058
|
-
|
|
2059
|
-
|
|
2060
|
-
|
|
2061
|
-
return
|
|
1982
|
+
const DEFAULT_HEATMAP_STYLE = {
|
|
1983
|
+
items: [
|
|
1984
|
+
{
|
|
1985
|
+
type: "heatmap",
|
|
1986
|
+
layout: {},
|
|
1987
|
+
paint: {
|
|
1988
|
+
"heatmap-radius": DEFAULT_HEATMAP_RADIUS,
|
|
1989
|
+
"heatmap-weight": DEFAULT_HEATMAP_WEIGHT,
|
|
1990
|
+
"heatmap-intensity": DEFAULT_HEATMAP_INTENSITY,
|
|
1991
|
+
"heatmap-color": DEFAULT_HEATMAP_COLOR,
|
|
1992
|
+
"heatmap-opacity": DEFAULT_OPACITY,
|
|
1993
|
+
},
|
|
1994
|
+
},
|
|
1995
|
+
],
|
|
1996
|
+
};
|
|
1997
|
+
|
|
1998
|
+
/**
|
|
1999
|
+
* Извлекает имена иконок из выражения icon-image.
|
|
2000
|
+
*
|
|
2001
|
+
* Поддерживает:
|
|
2002
|
+
* - Строки: "parking" → ["parking"]
|
|
2003
|
+
* - match: ["match", ["get", "type"], "a", "icon-a", "b", "icon-b", "default"] → ["icon-a", "icon-b", "default"]
|
|
2004
|
+
* - case: ["case", [...], "icon-a", "icon-b"] → ["icon-a", "icon-b"]
|
|
2005
|
+
* - coalesce: ["coalesce", ["image", "icon-a"], ["image", "icon-b"]] → ["icon-a", "icon-b"]
|
|
2006
|
+
* - image: ["image", "icon-a"] → ["icon-a"]
|
|
2007
|
+
*
|
|
2008
|
+
* @param iconImage - значение icon-image из layout
|
|
2009
|
+
* @returns массив имён иконок
|
|
2010
|
+
*/
|
|
2011
|
+
const parseIconNames = (iconImage) => {
|
|
2012
|
+
if (!iconImage) {
|
|
2013
|
+
return [];
|
|
2062
2014
|
}
|
|
2063
|
-
|
|
2064
|
-
|
|
2065
|
-
|
|
2066
|
-
}
|
|
2067
|
-
return `${t("total", { ns: "table" })} ${value.length}`;
|
|
2015
|
+
// Простая строка: "parking"
|
|
2016
|
+
if (typeof iconImage === "string") {
|
|
2017
|
+
return [iconImage];
|
|
2068
2018
|
}
|
|
2069
|
-
|
|
2070
|
-
|
|
2071
|
-
const
|
|
2072
|
-
|
|
2073
|
-
|
|
2074
|
-
|
|
2075
|
-
|
|
2076
|
-
|
|
2077
|
-
|
|
2078
|
-
|
|
2079
|
-
|
|
2080
|
-
|
|
2081
|
-
|
|
2019
|
+
// Выражение Mapbox
|
|
2020
|
+
if (Array.isArray(iconImage) && iconImage.length > 0) {
|
|
2021
|
+
const [operator, ...args] = iconImage;
|
|
2022
|
+
switch (operator) {
|
|
2023
|
+
// ["match", input, label1, output1, label2, output2, ..., fallback]
|
|
2024
|
+
case "match": {
|
|
2025
|
+
const results = [];
|
|
2026
|
+
// Пропускаем первый аргумент (input), берём каждый второй начиная с индекса 2
|
|
2027
|
+
for (let i = 2; i < args.length; i += 2) {
|
|
2028
|
+
if (typeof args[i] === "string") {
|
|
2029
|
+
results.push(args[i]);
|
|
2030
|
+
}
|
|
2031
|
+
else if (Array.isArray(args[i])) {
|
|
2032
|
+
results.push(...parseIconNames(args[i]));
|
|
2033
|
+
}
|
|
2034
|
+
}
|
|
2035
|
+
// Последний аргумент - fallback (если нечётное количество после input)
|
|
2036
|
+
const lastArg = args[args.length - 1];
|
|
2037
|
+
if (typeof lastArg === "string") {
|
|
2038
|
+
results.push(lastArg);
|
|
2039
|
+
}
|
|
2040
|
+
else if (Array.isArray(lastArg)) {
|
|
2041
|
+
results.push(...parseIconNames(lastArg));
|
|
2042
|
+
}
|
|
2043
|
+
return [...new Set(results)];
|
|
2044
|
+
}
|
|
2045
|
+
// ["case", condition1, output1, condition2, output2, ..., fallback]
|
|
2046
|
+
case "case": {
|
|
2047
|
+
const results = [];
|
|
2048
|
+
for (let i = 1; i < args.length; i += 2) {
|
|
2049
|
+
if (typeof args[i] === "string") {
|
|
2050
|
+
results.push(args[i]);
|
|
2051
|
+
}
|
|
2052
|
+
else if (Array.isArray(args[i])) {
|
|
2053
|
+
results.push(...parseIconNames(args[i]));
|
|
2054
|
+
}
|
|
2055
|
+
}
|
|
2056
|
+
// Fallback
|
|
2057
|
+
if (args.length % 2 === 0) {
|
|
2058
|
+
const lastArg = args[args.length - 1];
|
|
2059
|
+
if (typeof lastArg === "string") {
|
|
2060
|
+
results.push(lastArg);
|
|
2061
|
+
}
|
|
2062
|
+
else if (Array.isArray(lastArg)) {
|
|
2063
|
+
results.push(...parseIconNames(lastArg));
|
|
2064
|
+
}
|
|
2065
|
+
}
|
|
2066
|
+
return [...new Set(results)];
|
|
2067
|
+
}
|
|
2068
|
+
// ["coalesce", expr1, expr2, ...]
|
|
2069
|
+
case "coalesce": {
|
|
2070
|
+
const results = [];
|
|
2071
|
+
args.forEach(arg => {
|
|
2072
|
+
if (typeof arg === "string") {
|
|
2073
|
+
results.push(arg);
|
|
2074
|
+
}
|
|
2075
|
+
else if (Array.isArray(arg)) {
|
|
2076
|
+
results.push(...parseIconNames(arg));
|
|
2077
|
+
}
|
|
2078
|
+
});
|
|
2079
|
+
return [...new Set(results)];
|
|
2080
|
+
}
|
|
2081
|
+
// ["image", name] или ["image", name1, name2, ...]
|
|
2082
|
+
case "image": {
|
|
2083
|
+
return args.filter((arg) => typeof arg === "string");
|
|
2084
|
+
}
|
|
2085
|
+
// ["concat", ...] или другие - рекурсивно ищем строки
|
|
2086
|
+
default: {
|
|
2087
|
+
const results = [];
|
|
2088
|
+
args.forEach(arg => {
|
|
2089
|
+
if (Array.isArray(arg)) {
|
|
2090
|
+
results.push(...parseIconNames(arg));
|
|
2091
|
+
}
|
|
2092
|
+
});
|
|
2093
|
+
return [...new Set(results)];
|
|
2082
2094
|
}
|
|
2083
|
-
result += numeral[i];
|
|
2084
|
-
}
|
|
2085
|
-
if (numsArray[1]) {
|
|
2086
|
-
return [result.trim(), numsArray[1]].join(".");
|
|
2087
2095
|
}
|
|
2088
|
-
return result.trim();
|
|
2089
|
-
}
|
|
2090
|
-
return number || "0";
|
|
2091
|
-
};
|
|
2092
|
-
const formatArea = (t, num) => {
|
|
2093
|
-
let result = num;
|
|
2094
|
-
let measure = t("sqMeter", { ns: "common" });
|
|
2095
|
-
if (num >= 10000000) {
|
|
2096
|
-
result = num / 1000000;
|
|
2097
|
-
measure = t("sqKilometer", { ns: "common" });
|
|
2098
|
-
}
|
|
2099
|
-
else if (num >= 10000) {
|
|
2100
|
-
result = num / 10000;
|
|
2101
|
-
measure = t("hectare", { ns: "common" });
|
|
2102
|
-
}
|
|
2103
|
-
return `${numberWithSpaces(result, 2)} ${measure}`;
|
|
2104
|
-
};
|
|
2105
|
-
const formatLength = (t, num) => {
|
|
2106
|
-
let result = num;
|
|
2107
|
-
let measure = t("meter", { ns: "common" });
|
|
2108
|
-
if (num > 10000) {
|
|
2109
|
-
result = num / 1000;
|
|
2110
|
-
measure = t("kilometer", { ns: "common" });
|
|
2111
2096
|
}
|
|
2112
|
-
return
|
|
2097
|
+
return [];
|
|
2113
2098
|
};
|
|
2114
|
-
|
|
2115
|
-
|
|
2099
|
+
/**
|
|
2100
|
+
* Свойства, содержащие имена изображений (иконки и паттерны).
|
|
2101
|
+
*/
|
|
2102
|
+
const IMAGE_PROPERTIES = {
|
|
2103
|
+
layout: ["icon-image"],
|
|
2104
|
+
paint: ["fill-pattern", "line-pattern", "fill-extrusion-pattern"],
|
|
2116
2105
|
};
|
|
2117
|
-
|
|
2118
|
-
|
|
2119
|
-
|
|
2120
|
-
|
|
2106
|
+
/**
|
|
2107
|
+
* Извлекает все имена изображений из clientStyle.
|
|
2108
|
+
* Включает иконки (icon-image) и паттерны (fill-pattern, line-pattern, fill-extrusion-pattern).
|
|
2109
|
+
*
|
|
2110
|
+
* @param clientStyle - конфигурация стиля слоя
|
|
2111
|
+
* @returns массив уникальных имён изображений
|
|
2112
|
+
*/
|
|
2113
|
+
const parseIconNamesFromClientStyle = (clientStyle) => {
|
|
2114
|
+
if (!clientStyle?.items) {
|
|
2115
|
+
return [];
|
|
2121
2116
|
}
|
|
2122
|
-
const
|
|
2123
|
-
|
|
2124
|
-
|
|
2125
|
-
|
|
2117
|
+
const imageNames = new Set();
|
|
2118
|
+
clientStyle.items.forEach(item => {
|
|
2119
|
+
// Парсим icon-image из layout
|
|
2120
|
+
IMAGE_PROPERTIES.layout.forEach(prop => {
|
|
2121
|
+
const value = item.layout?.[prop];
|
|
2122
|
+
if (value) {
|
|
2123
|
+
parseIconNames(value).forEach(name => imageNames.add(name));
|
|
2124
|
+
}
|
|
2125
|
+
});
|
|
2126
|
+
// Парсим fill-pattern, line-pattern, fill-extrusion-pattern из paint
|
|
2127
|
+
IMAGE_PROPERTIES.paint.forEach(prop => {
|
|
2128
|
+
const value = item.paint?.[prop];
|
|
2129
|
+
if (value) {
|
|
2130
|
+
parseIconNames(value).forEach(name => imageNames.add(name));
|
|
2131
|
+
}
|
|
2132
|
+
});
|
|
2133
|
+
});
|
|
2134
|
+
return [...imageNames];
|
|
2126
2135
|
};
|
|
2127
2136
|
|
|
2128
|
-
|
|
2129
|
-
|
|
2130
|
-
|
|
2131
|
-
|
|
2132
|
-
const isLayerService = (value) => isObject(value) && "name" in value;
|
|
2133
|
-
|
|
2134
|
-
const isNumeric = (number) => !isNaN(parseFloat(number)) && isFinite(number);
|
|
2135
|
-
|
|
2136
|
-
const metersPerPixel = (zoom, lat) => {
|
|
2137
|
-
return (156543.03 * Math.cos(lat * (Math.PI / 180))) / 2 ** zoom;
|
|
2138
|
-
};
|
|
2137
|
+
/** Предел широты сферического меркатора (EPSG:3857): дальше проекция уходит в бесконечность. */
|
|
2138
|
+
const MERCATOR_MAX_LATITUDE = 85.05112878;
|
|
2139
|
+
/** Предел долготы: карта рендерит копии мира, но экстент за пределами ±180° бэкенду не нужен. */
|
|
2140
|
+
const MERCATOR_MAX_LONGITUDE = 180;
|
|
2139
2141
|
|
|
2140
2142
|
const clamp = (value, limit) => Math.min(Math.max(value, -limit), limit);
|
|
2141
2143
|
/**
|