@elastic/ems-client 8.2.0 → 8.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,13 @@
1
1
  function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
2
2
 
3
+ function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
4
+
5
+ function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
6
+
7
+ function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
8
+
9
+ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
10
+
3
11
  function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
4
12
 
5
13
  function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
@@ -44,11 +52,22 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
44
52
  */
45
53
  import _ from 'lodash';
46
54
  import { AbstractEmsService } from './ems_service';
55
+ import { colorizeColor } from './utils';
47
56
  export var TMSService = /*#__PURE__*/function (_AbstractEmsService) {
48
57
  _inherits(TMSService, _AbstractEmsService);
49
58
 
50
59
  var _super = _createSuper(TMSService);
51
60
 
61
+ /*
62
+ List of supported languages with labels and OMT codes extracted
63
+ from https://openmaptiles.org/languages
64
+ Keys are values for i18.locale from Kibana settings
65
+ and OMT codes for the rest.
66
+ */
67
+
68
+ /*
69
+ Suggested default operations for the different EMS styles
70
+ */
52
71
  function TMSService(config, emsClient, proxyPath) {
53
72
  var _this;
54
73
 
@@ -230,6 +249,11 @@ export var TMSService = /*#__PURE__*/function (_AbstractEmsService) {
230
249
  _this._config = config;
231
250
  return _this;
232
251
  }
252
+ /*
253
+ This method returns an array of objects with the layers and the new
254
+ layout['text-field'] to apply using map.setLayoutProperty
255
+ */
256
+
233
257
 
234
258
  _createClass(TMSService, [{
235
259
  key: "getDefaultRasterStyle",
@@ -572,28 +596,71 @@ export var TMSService = /*#__PURE__*/function (_AbstractEmsService) {
572
596
  key: "getMinZoom",
573
597
  value: function () {
574
598
  var _getMinZoom = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee12() {
575
- var tileJson;
599
+ var format,
600
+ _ref4,
601
+ sources,
602
+ _ref6,
603
+ minzoom,
604
+ _args12 = arguments;
605
+
576
606
  return regeneratorRuntime.wrap(function _callee12$(_context12) {
577
607
  while (1) {
578
608
  switch (_context12.prev = _context12.next) {
579
609
  case 0:
580
- _context12.next = 2;
610
+ format = _args12.length > 0 && _args12[0] !== undefined ? _args12[0] : 'vector';
611
+ _context12.t0 = format;
612
+ _context12.next = _context12.t0 === 'vector' ? 4 : _context12.t0 === 'raster' ? 12 : 20;
613
+ break;
614
+
615
+ case 4:
616
+ _context12.next = 6;
617
+ return this._getVectorStyleJsonInlined();
618
+
619
+ case 6:
620
+ _context12.t1 = _context12.sent;
621
+
622
+ if (_context12.t1) {
623
+ _context12.next = 9;
624
+ break;
625
+ }
626
+
627
+ _context12.t1 = {
628
+ sources: {}
629
+ };
630
+
631
+ case 9:
632
+ _ref4 = _context12.t1;
633
+ sources = _ref4.sources;
634
+ return _context12.abrupt("return", Math.min.apply(Math, _toConsumableArray(Object.values(sources).map(function (_ref5) {
635
+ var minzoom = _ref5.minzoom;
636
+ return minzoom;
637
+ }).filter(function (minzoom) {
638
+ return Number.isFinite(minzoom);
639
+ }))));
640
+
641
+ case 12:
642
+ _context12.next = 14;
581
643
  return this._getRasterStyleJson();
582
644
 
583
- case 2:
584
- tileJson = _context12.sent;
645
+ case 14:
646
+ _context12.t2 = _context12.sent;
585
647
 
586
- if (!tileJson) {
587
- _context12.next = 7;
648
+ if (_context12.t2) {
649
+ _context12.next = 17;
588
650
  break;
589
651
  }
590
652
 
591
- return _context12.abrupt("return", tileJson.minzoom);
653
+ _context12.t2 = {};
592
654
 
593
- case 7:
655
+ case 17:
656
+ _ref6 = _context12.t2;
657
+ minzoom = _ref6.minzoom;
658
+ return _context12.abrupt("return", minzoom);
659
+
660
+ case 20:
594
661
  return _context12.abrupt("return");
595
662
 
596
- case 8:
663
+ case 21:
597
664
  case "end":
598
665
  return _context12.stop();
599
666
  }
@@ -611,28 +678,71 @@ export var TMSService = /*#__PURE__*/function (_AbstractEmsService) {
611
678
  key: "getMaxZoom",
612
679
  value: function () {
613
680
  var _getMaxZoom = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee13() {
614
- var tileJson;
681
+ var format,
682
+ _ref7,
683
+ sources,
684
+ _ref9,
685
+ maxzoom,
686
+ _args13 = arguments;
687
+
615
688
  return regeneratorRuntime.wrap(function _callee13$(_context13) {
616
689
  while (1) {
617
690
  switch (_context13.prev = _context13.next) {
618
691
  case 0:
619
- _context13.next = 2;
692
+ format = _args13.length > 0 && _args13[0] !== undefined ? _args13[0] : 'vector';
693
+ _context13.t0 = format;
694
+ _context13.next = _context13.t0 === 'vector' ? 4 : _context13.t0 === 'raster' ? 12 : 20;
695
+ break;
696
+
697
+ case 4:
698
+ _context13.next = 6;
699
+ return this._getVectorStyleJsonInlined();
700
+
701
+ case 6:
702
+ _context13.t1 = _context13.sent;
703
+
704
+ if (_context13.t1) {
705
+ _context13.next = 9;
706
+ break;
707
+ }
708
+
709
+ _context13.t1 = {
710
+ sources: {}
711
+ };
712
+
713
+ case 9:
714
+ _ref7 = _context13.t1;
715
+ sources = _ref7.sources;
716
+ return _context13.abrupt("return", Math.max.apply(Math, _toConsumableArray(Object.values(sources).map(function (_ref8) {
717
+ var maxzoom = _ref8.maxzoom;
718
+ return maxzoom;
719
+ }).filter(function (maxzoom) {
720
+ return Number.isFinite(maxzoom);
721
+ }))));
722
+
723
+ case 12:
724
+ _context13.next = 14;
620
725
  return this._getRasterStyleJson();
621
726
 
622
- case 2:
623
- tileJson = _context13.sent;
727
+ case 14:
728
+ _context13.t2 = _context13.sent;
624
729
 
625
- if (!tileJson) {
626
- _context13.next = 7;
730
+ if (_context13.t2) {
731
+ _context13.next = 17;
627
732
  break;
628
733
  }
629
734
 
630
- return _context13.abrupt("return", tileJson.maxzoom);
735
+ _context13.t2 = {};
631
736
 
632
- case 7:
737
+ case 17:
738
+ _ref9 = _context13.t2;
739
+ maxzoom = _ref9.maxzoom;
740
+ return _context13.abrupt("return", maxzoom);
741
+
742
+ case 20:
633
743
  return _context13.abrupt("return");
634
744
 
635
- case 8:
745
+ case 21:
636
746
  case "end":
637
747
  return _context13.stop();
638
748
  }
@@ -767,7 +877,264 @@ export var TMSService = /*#__PURE__*/function (_AbstractEmsService) {
767
877
 
768
878
  return _getUrlTemplateForGlyphs;
769
879
  }()
880
+ }], [{
881
+ key: "transformLanguageProperty",
882
+ value: function transformLanguageProperty(layer, lang) {
883
+ var supportedLang = this.SupportedLanguages.find(function (l) {
884
+ return l.key === lang;
885
+ });
886
+
887
+ if (layer.type === 'symbol' && layer.layout !== undefined && supportedLang !== undefined) {
888
+ var omtLang = supportedLang.omt;
889
+ var textField = layer.layout['text-field'];
890
+
891
+ if (textField && typeof textField === 'string') {
892
+ return TMSService._getTextField(textField, omtLang);
893
+ }
894
+ }
895
+
896
+ return;
897
+ }
898
+ /*
899
+ This method returns an array of objects per layer, containing a list of
900
+ properties with new colors to apply using map.setPaintProperty
901
+ */
902
+
903
+ }, {
904
+ key: "transformColorProperties",
905
+ value: function transformColorProperties(layer, color, operation, percentage) {
906
+ if (['background', 'fill', 'line', 'symbol'].indexOf(layer.type) !== -1 && layer.paint) {
907
+ var paint = layer.paint;
908
+
909
+ if (layer.type === 'symbol' && Object.keys(paint).length === 0) {
910
+ paint['text-color'] = 'rgb(0,0,0)';
911
+ }
912
+
913
+ var types = Object.keys(paint).filter(function (key) {
914
+ return ['background-color', 'circle-color', 'circle-stroke-color', 'fill-color', 'fill-extrusion-color', 'fill-outline-color', 'icon-color', 'icon-halo-color', 'line-color', 'text-color', 'text-halo-color'].indexOf(key) !== -1;
915
+ });
916
+ return types.map(function (type) {
917
+ var paintColor = paint[type];
918
+ return {
919
+ property: type,
920
+ color: paintColor ? colorizeColor(paintColor, color, operation, percentage) : paintColor
921
+ };
922
+ });
923
+ } else {
924
+ return [];
925
+ }
926
+ }
927
+ }, {
928
+ key: "_getTextField",
929
+ value: function _getTextField(label, lang) {
930
+ // Capture {name:xx} labels
931
+ var labelMatch = label.match(/\{name([:_])(.{2})\}/);
932
+
933
+ if (labelMatch && labelMatch[1] != lang) {
934
+ // Only apply if the languages are different
935
+ return ['coalesce', ['get', "name:".concat(lang)], ['get', "name".concat(labelMatch[1]).concat(labelMatch[2])]];
936
+ } else if (label.includes('latin') && label.includes('nonlatin')) {
937
+ // Capture the common pattern {name:latin}\n{name:nonlatin}
938
+ return ['coalesce', ['get', "name:".concat(lang)], ['concat', ['get', 'name:latin'], '\n', ['get', 'name:nonlatin']]];
939
+ } // If no case is found, return the input label
940
+
941
+
942
+ return label;
943
+ }
770
944
  }]);
771
945
 
772
946
  return TMSService;
773
- }(AbstractEmsService);
947
+ }(AbstractEmsService);
948
+
949
+ _defineProperty(TMSService, "SupportedLanguages", [{
950
+ key: 'ar',
951
+ omt: 'ar'
952
+ }, {
953
+ key: 'az',
954
+ omt: 'az'
955
+ }, {
956
+ key: 'be',
957
+ omt: 'be'
958
+ }, {
959
+ key: 'bg',
960
+ omt: 'bg'
961
+ }, {
962
+ key: 'br',
963
+ omt: 'br'
964
+ }, {
965
+ key: 'bs',
966
+ omt: 'bs'
967
+ }, {
968
+ key: 'ca',
969
+ omt: 'ca'
970
+ }, {
971
+ key: 'cs',
972
+ omt: 'cs'
973
+ }, {
974
+ key: 'cy',
975
+ omt: 'cy'
976
+ }, {
977
+ key: 'da',
978
+ omt: 'da'
979
+ }, {
980
+ key: 'de',
981
+ omt: 'de'
982
+ }, {
983
+ key: 'el',
984
+ omt: 'el'
985
+ }, {
986
+ key: 'en',
987
+ omt: 'en'
988
+ }, {
989
+ key: 'eo',
990
+ omt: 'eo'
991
+ }, {
992
+ key: 'es',
993
+ omt: 'es'
994
+ }, {
995
+ key: 'et',
996
+ omt: 'et'
997
+ }, {
998
+ key: 'fi',
999
+ omt: 'fi'
1000
+ }, {
1001
+ key: 'fr-fr',
1002
+ omt: 'fr'
1003
+ }, {
1004
+ key: 'fy',
1005
+ omt: 'fy'
1006
+ }, {
1007
+ key: 'ga',
1008
+ omt: 'ga'
1009
+ }, {
1010
+ key: 'gd',
1011
+ omt: 'gd'
1012
+ }, {
1013
+ key: 'he',
1014
+ omt: 'he'
1015
+ }, {
1016
+ key: 'hi-in',
1017
+ omt: 'hi'
1018
+ }, {
1019
+ key: 'hr',
1020
+ omt: 'hr'
1021
+ }, {
1022
+ key: 'hu',
1023
+ omt: 'hu'
1024
+ }, {
1025
+ key: 'hy',
1026
+ omt: 'hy'
1027
+ }, {
1028
+ key: 'is',
1029
+ omt: 'is'
1030
+ }, {
1031
+ key: 'it',
1032
+ omt: 'it'
1033
+ }, {
1034
+ key: 'ja_kana',
1035
+ omt: 'ja_kana'
1036
+ }, {
1037
+ key: 'ja_rm',
1038
+ omt: 'ja_rm'
1039
+ }, {
1040
+ key: 'ja-jp',
1041
+ omt: 'ja'
1042
+ }, {
1043
+ key: 'ka',
1044
+ omt: 'ka'
1045
+ }, {
1046
+ key: 'kk',
1047
+ omt: 'kk'
1048
+ }, {
1049
+ key: 'kn',
1050
+ omt: 'kn'
1051
+ }, {
1052
+ key: 'ko_rm',
1053
+ omt: 'ko_rm'
1054
+ }, {
1055
+ key: 'ko',
1056
+ omt: 'ko'
1057
+ }, {
1058
+ key: 'la',
1059
+ omt: 'la'
1060
+ }, {
1061
+ key: 'lb',
1062
+ omt: 'lb'
1063
+ }, {
1064
+ key: 'lt',
1065
+ omt: 'lt'
1066
+ }, {
1067
+ key: 'lv',
1068
+ omt: 'lv'
1069
+ }, {
1070
+ key: 'mk',
1071
+ omt: 'mk'
1072
+ }, {
1073
+ key: 'mt',
1074
+ omt: 'mt'
1075
+ }, {
1076
+ key: 'nl',
1077
+ omt: 'nl'
1078
+ }, {
1079
+ key: 'no',
1080
+ omt: 'no'
1081
+ }, {
1082
+ key: 'pl',
1083
+ omt: 'pl'
1084
+ }, {
1085
+ key: 'pt-pt',
1086
+ omt: 'pt'
1087
+ }, {
1088
+ key: 'rm',
1089
+ omt: 'rm'
1090
+ }, {
1091
+ key: 'ro',
1092
+ omt: 'ro'
1093
+ }, {
1094
+ key: 'ru-ru',
1095
+ omt: 'ru'
1096
+ }, {
1097
+ key: 'sk',
1098
+ omt: 'sk'
1099
+ }, {
1100
+ key: 'sl',
1101
+ omt: 'sl'
1102
+ }, {
1103
+ key: 'sq',
1104
+ omt: 'sq'
1105
+ }, {
1106
+ key: 'sr-Ltn',
1107
+ omt: 'sr-Ltn'
1108
+ }, {
1109
+ key: 'sr',
1110
+ omt: 'sr'
1111
+ }, {
1112
+ key: 'sv',
1113
+ omt: 'sv'
1114
+ }, {
1115
+ key: 'th',
1116
+ omt: 'th'
1117
+ }, {
1118
+ key: 'tr',
1119
+ omt: 'tr'
1120
+ }, {
1121
+ key: 'uk',
1122
+ omt: 'uk'
1123
+ }, {
1124
+ key: 'zh-cn',
1125
+ omt: 'zh'
1126
+ }]);
1127
+
1128
+ _defineProperty(TMSService, "colorOperationDefaults", [{
1129
+ style: 'road_map',
1130
+ operation: 'mix',
1131
+ percentage: 0.25
1132
+ }, {
1133
+ style: 'road_map_desaturated',
1134
+ operation: 'screen',
1135
+ percentage: 0.25
1136
+ }, {
1137
+ style: 'dark_map',
1138
+ operation: 'dodge',
1139
+ percentage: 0.25
1140
+ }]);
@@ -1,9 +1,18 @@
1
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
2
+
3
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
4
+
5
+ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
6
+
7
+ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
8
+
1
9
  /*
2
10
  * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3
11
  * or more contributor license agreements. Licensed under the Elastic License
4
12
  * 2.0; you may not use this file except in compliance with the Elastic License
5
13
  * 2.0.
6
14
  */
15
+ import chroma from 'chroma-js';
7
16
 
8
17
  /**
9
18
  * Resolves a target URL path relative to the host.
@@ -25,4 +34,58 @@ export function toAbsoluteUrl(host, path) {
25
34
  } else {
26
35
  return host + '/' + path;
27
36
  }
37
+ }
38
+ /*
39
+ Type with the possible ways to define a color in maplibre
40
+ */
41
+
42
+ /*
43
+ Function to transform a maplibre color definition by a given function.
44
+ */
45
+ function transformColor(paintColor, func) {
46
+ if (typeof paintColor == 'string') {
47
+ var modifiedColor = func(paintColor);
48
+ return "rgba(".concat(modifiedColor.rgba().join(','), ")");
49
+ } else if (_typeof(paintColor) == 'object' && 'stops' in paintColor && Array.isArray(paintColor === null || paintColor === void 0 ? void 0 : paintColor.stops)) {
50
+ var stops = paintColor['stops'].map(function (stop) {
51
+ var newColor = transformColor(stop[1], func);
52
+ return [stop[0], newColor];
53
+ });
54
+
55
+ var newPaintColor = _objectSpread(_objectSpread({}, paintColor), stops);
56
+
57
+ return newPaintColor;
58
+ } else return paintColor;
59
+ }
60
+ /*
61
+ This is the function used to generate the current EMS desaturated roadmap
62
+ */
63
+
64
+
65
+ export function desaturateColor(paintColor) {
66
+ return transformColor(paintColor, function (color) {
67
+ return chroma(color).desaturate(1.1).brighten(0.33);
68
+ });
69
+ }
70
+ /*
71
+ Blends an original maplibre color definition with a destination
72
+ color. Accepts different blending modes and an additional `mix`
73
+ option that needs a percentage.
74
+
75
+ More details:
76
+
77
+ https://gka.github.io/chroma.js/#chroma-blend
78
+ https://gka.github.io/chroma.js/#chroma-mix
79
+ */
80
+
81
+ export function colorizeColor(sourceColor, destColor) {
82
+ var operation = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'screen';
83
+ var percentage = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0.5;
84
+ return transformColor(sourceColor, function (color) {
85
+ if (operation !== 'mix') {
86
+ return chroma.blend(chroma(color), destColor, operation);
87
+ } else {
88
+ return chroma.mix(chroma(color), destColor, percentage);
89
+ }
90
+ });
28
91
  }
@@ -52,8 +52,15 @@ it('should get the tile service', async () => {
52
52
  'https://tiles.foobar/raster/styles/osm-bright/{z}/{x}/{y}.png?elastic_tile_service_tos=agree&my_app_name=tester&my_app_version=7.x.x'
53
53
  );
54
54
 
55
- expect(await tileService.getMinZoom()).toBe(0);
56
- expect(await tileService.getMaxZoom()).toBe(10);
55
+ expect(await tileService.getUrlTemplateForVector('openmaptiles')).toBe(
56
+ 'https://tiles.foobar/data/v3/{z}/{x}/{y}.pbf?elastic_tile_service_tos=agree&my_app_name=tester&my_app_version=7.x.x'
57
+ );
58
+
59
+ expect(await tileService.getMinZoom('raster')).toBe(0);
60
+ expect(await tileService.getMaxZoom('raster')).toBe(10);
61
+
62
+ expect(await tileService.getMinZoom('vector')).toBe(3);
63
+ expect(await tileService.getMaxZoom('vector')).toBe(15);
57
64
  expect(tileService.hasId('road_map')).toBe(true);
58
65
  });
59
66
 
@@ -73,8 +80,8 @@ it('tile service- localized (fallback)', async () => {
73
80
  'https://tiles.foobar/raster/styles/osm-bright/{z}/{x}/{y}.png?elastic_tile_service_tos=agree&my_app_name=tester&my_app_version=7.x.x'
74
81
  );
75
82
 
76
- expect(await tileService.getMinZoom()).toBe(0);
77
- expect(await tileService.getMaxZoom()).toBe(10);
83
+ expect(await tileService.getMinZoom('raster')).toBe(0);
84
+ expect(await tileService.getMaxZoom('raster')).toBe(10);
78
85
  expect(tileService.hasId('road_map')).toBe(true);
79
86
  });
80
87
 
@@ -0,0 +1,79 @@
1
+ /*
2
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3
+ * or more contributor license agreements. Licensed under the Elastic License
4
+ * 2.0; you may not use this file except in compliance with the Elastic License
5
+ * 2.0.
6
+ */
7
+
8
+ import { LayerSpecification } from 'maplibre-gl';
9
+ import { TMSService } from '../src';
10
+ import { mlLayerTypes } from './ems_client_util';
11
+ import chroma from 'chroma-js';
12
+
13
+ function chroma2css(color: chroma.Color): string {
14
+ return `rgba(${color.rgba().join(',')})`;
15
+ }
16
+
17
+ describe('Transform colours', () => {
18
+ it('should return an empty array for non symbol layers without any paint property to update', () => {
19
+ mlLayerTypes
20
+ .filter((l) => l != 'symbol')
21
+ .forEach((type) => {
22
+ const layer = {
23
+ id: 'layer',
24
+ type,
25
+ layout: {},
26
+ } as LayerSpecification;
27
+ expect(TMSService.transformColorProperties(layer, '#FF0000', 'burn', 0)).toEqual([]);
28
+ });
29
+ });
30
+
31
+ it('should return an empty array for non symbol layer with an empty paint property', () => {
32
+ const layer = {
33
+ id: 'layer',
34
+ type: 'fill',
35
+ paint: {},
36
+ } as LayerSpecification;
37
+
38
+ expect(TMSService.transformColorProperties(layer, '#FF0000', 'lighten', 0)).toEqual([]);
39
+ });
40
+
41
+ it('should return a text-color for symbol layers without a paint property', () => {
42
+ const inColor = chroma('#D36086');
43
+ const textColor = chroma('rgba(0,0,0,1)');
44
+ const inOp = 'lighten';
45
+ const outColor = chroma.blend(textColor, inColor, inOp);
46
+
47
+ const transform = TMSService.transformColorProperties;
48
+
49
+ const layerWithTextColor = {
50
+ id: 'layer',
51
+ type: 'symbol',
52
+ paint: {
53
+ 'text-color': chroma2css(textColor),
54
+ },
55
+ } as LayerSpecification;
56
+
57
+ const layerWithoutTextColor = {
58
+ id: 'layer',
59
+ type: 'symbol',
60
+ paint: {},
61
+ } as LayerSpecification;
62
+
63
+ const resultWithTextColor = transform(layerWithTextColor, inColor.hex('rgba'), inOp, 0);
64
+ const resultWithoutTextColor = transform(layerWithoutTextColor, inColor.hex('rgba'), inOp, 0);
65
+
66
+ expect(resultWithTextColor).toEqual([
67
+ {
68
+ color: chroma2css(outColor),
69
+ property: 'text-color',
70
+ },
71
+ ]);
72
+ expect(resultWithoutTextColor).toEqual([
73
+ {
74
+ color: chroma2css(outColor),
75
+ property: 'text-color',
76
+ },
77
+ ]);
78
+ });
79
+ });