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