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