@elastic/ems-client 8.3.0 → 8.3.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/.backportrc.json +2 -1
- package/CHANGELOG.md +17 -2
- package/package.json +3 -1
- package/src/index.ts +1 -0
- package/src/tms_service.ts +202 -13
- package/src/utils.ts +89 -0
- package/target/index.d.ts +1 -0
- package/target/node/index.js +9 -1
- package/target/node/tms_service.js +308 -13
- package/target/node/utils.js +60 -0
- package/target/tms_service.d.ts +19 -3
- package/target/utils.d.ts +19 -0
- package/target/web/index.js +2 -1
- package/target/web/tms_service.js +386 -19
- package/target/web/utils.js +57 -0
- package/test/ems_client.test.ts +11 -4
- package/test/ems_client_colour.test.ts +140 -0
- package/test/ems_client_lang.test.ts +122 -0
- package/test/ems_client_util.ts +12 -0
- package/test/ems_mocks/sample_style_bright_vector_source.json +2 -2
- package/target/origin.d.ts +0 -4
|
@@ -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
|
|
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
|
-
|
|
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
|
|
584
|
-
|
|
645
|
+
case 14:
|
|
646
|
+
_context12.t2 = _context12.sent;
|
|
585
647
|
|
|
586
|
-
if (
|
|
587
|
-
_context12.next =
|
|
648
|
+
if (_context12.t2) {
|
|
649
|
+
_context12.next = 17;
|
|
588
650
|
break;
|
|
589
651
|
}
|
|
590
652
|
|
|
591
|
-
|
|
653
|
+
_context12.t2 = {};
|
|
592
654
|
|
|
593
|
-
case
|
|
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
|
|
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
|
|
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
|
-
|
|
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
|
|
623
|
-
|
|
727
|
+
case 14:
|
|
728
|
+
_context13.t2 = _context13.sent;
|
|
624
729
|
|
|
625
|
-
if (
|
|
626
|
-
_context13.next =
|
|
730
|
+
if (_context13.t2) {
|
|
731
|
+
_context13.next = 17;
|
|
627
732
|
break;
|
|
628
733
|
}
|
|
629
734
|
|
|
630
|
-
|
|
735
|
+
_context13.t2 = {};
|
|
631
736
|
|
|
632
|
-
case
|
|
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
|
|
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 && color ? 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
|
+
}]);
|
package/target/web/utils.js
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
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
|
+
|
|
1
3
|
/*
|
|
2
4
|
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
|
3
5
|
* or more contributor license agreements. Licensed under the Elastic License
|
|
4
6
|
* 2.0; you may not use this file except in compliance with the Elastic License
|
|
5
7
|
* 2.0.
|
|
6
8
|
*/
|
|
9
|
+
import chroma from 'chroma-js';
|
|
7
10
|
|
|
8
11
|
/**
|
|
9
12
|
* Resolves a target URL path relative to the host.
|
|
@@ -25,4 +28,58 @@ export function toAbsoluteUrl(host, path) {
|
|
|
25
28
|
} else {
|
|
26
29
|
return host + '/' + path;
|
|
27
30
|
}
|
|
31
|
+
}
|
|
32
|
+
/*
|
|
33
|
+
Type with the possible ways to define a color in maplibre
|
|
34
|
+
*/
|
|
35
|
+
|
|
36
|
+
/*
|
|
37
|
+
Function to transform a maplibre color definition by a given function.
|
|
38
|
+
*/
|
|
39
|
+
function transformColor(paintColor, func) {
|
|
40
|
+
if (typeof paintColor == 'string') {
|
|
41
|
+
var modifiedColor = func(paintColor);
|
|
42
|
+
return "rgba(".concat(modifiedColor.rgba().join(','), ")");
|
|
43
|
+
} else if (_typeof(paintColor) == 'object' && 'stops' in paintColor && Array.isArray(paintColor === null || paintColor === void 0 ? void 0 : paintColor.stops)) {
|
|
44
|
+
var stops = paintColor['stops'].map(function (stop) {
|
|
45
|
+
var newColor = transformColor(stop[1], func);
|
|
46
|
+
return [stop[0], newColor];
|
|
47
|
+
});
|
|
48
|
+
var newPaintColor = Object.assign({}, paintColor, {
|
|
49
|
+
stops: stops
|
|
50
|
+
});
|
|
51
|
+
return newPaintColor;
|
|
52
|
+
} else return paintColor;
|
|
53
|
+
}
|
|
54
|
+
/*
|
|
55
|
+
This is the function used to generate the current EMS desaturated roadmap
|
|
56
|
+
*/
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
export function desaturateColor(paintColor) {
|
|
60
|
+
return transformColor(paintColor, function (color) {
|
|
61
|
+
return chroma(color).desaturate(1.1).brighten(0.33);
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
/*
|
|
65
|
+
Blends an original maplibre color definition with a destination
|
|
66
|
+
color. Accepts different blending modes and an additional `mix`
|
|
67
|
+
option that needs a percentage.
|
|
68
|
+
|
|
69
|
+
More details:
|
|
70
|
+
|
|
71
|
+
https://gka.github.io/chroma.js/#chroma-blend
|
|
72
|
+
https://gka.github.io/chroma.js/#chroma-mix
|
|
73
|
+
*/
|
|
74
|
+
|
|
75
|
+
export function colorizeColor(sourceColor, destColor) {
|
|
76
|
+
var operation = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'screen';
|
|
77
|
+
var percentage = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0.5;
|
|
78
|
+
return transformColor(sourceColor, function (color) {
|
|
79
|
+
if (operation !== 'mix') {
|
|
80
|
+
return chroma.blend(chroma(color), destColor, operation);
|
|
81
|
+
} else {
|
|
82
|
+
return chroma.mix(chroma(color), destColor, percentage);
|
|
83
|
+
}
|
|
84
|
+
});
|
|
28
85
|
}
|
package/test/ems_client.test.ts
CHANGED
|
@@ -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.
|
|
56
|
-
|
|
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
|
|