@mapwhit/tilerenderer 0.49.0 → 0.51.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (147) hide show
  1. package/build/min/package.json +1 -1
  2. package/build/min/src/shaders/.dir +0 -0
  3. package/build/min/src/shaders/_prelude.fragment.glsl.js +14 -0
  4. package/build/min/src/shaders/_prelude.vertex.glsl.js +14 -0
  5. package/build/min/src/shaders/background.fragment.glsl.js +5 -0
  6. package/build/min/src/shaders/background.vertex.glsl.js +1 -0
  7. package/build/min/src/shaders/background_pattern.fragment.glsl.js +5 -0
  8. package/build/min/src/shaders/background_pattern.vertex.glsl.js +1 -0
  9. package/build/min/src/shaders/circle.fragment.glsl.js +20 -0
  10. package/build/min/src/shaders/circle.vertex.glsl.js +17 -0
  11. package/build/min/src/shaders/clipping_mask.fragment.glsl.js +1 -0
  12. package/build/min/src/shaders/clipping_mask.vertex.glsl.js +1 -0
  13. package/build/min/src/shaders/collision_box.fragment.glsl.js +1 -0
  14. package/build/min/src/shaders/collision_box.vertex.glsl.js +1 -0
  15. package/build/min/src/shaders/collision_circle.fragment.glsl.js +1 -0
  16. package/build/min/src/shaders/collision_circle.vertex.glsl.js +1 -0
  17. package/build/min/src/shaders/debug.fragment.glsl.js +1 -0
  18. package/build/min/src/shaders/debug.vertex.glsl.js +1 -0
  19. package/build/min/src/shaders/fill.fragment.glsl.js +10 -0
  20. package/build/min/src/shaders/fill.vertex.glsl.js +7 -0
  21. package/build/min/src/shaders/fill_extrusion.fragment.glsl.js +5 -0
  22. package/build/min/src/shaders/fill_extrusion.fragment.glsl.txt +1 -9
  23. package/build/min/src/shaders/fill_extrusion.vertex.glsl.js +9 -0
  24. package/build/min/src/shaders/fill_extrusion.vertex.glsl.txt +4 -4
  25. package/build/min/src/shaders/fill_extrusion_pattern.fragment.glsl.js +15 -0
  26. package/build/min/src/shaders/fill_extrusion_pattern.vertex.glsl.js +11 -0
  27. package/build/min/src/shaders/fill_outline.fragment.glsl.js +10 -0
  28. package/build/min/src/shaders/fill_outline.vertex.glsl.js +7 -0
  29. package/build/min/src/shaders/fill_outline_pattern.fragment.glsl.js +13 -0
  30. package/build/min/src/shaders/fill_outline_pattern.vertex.glsl.js +9 -0
  31. package/build/min/src/shaders/fill_pattern.fragment.glsl.js +13 -0
  32. package/build/min/src/shaders/fill_pattern.vertex.glsl.js +9 -0
  33. package/build/min/src/shaders/heatmap.fragment.glsl.js +10 -0
  34. package/build/min/src/shaders/heatmap.vertex.glsl.js +8 -0
  35. package/build/min/src/shaders/heatmap_texture.fragment.glsl.js +5 -0
  36. package/build/min/src/shaders/heatmap_texture.vertex.glsl.js +1 -0
  37. package/build/min/src/shaders/hillshade.fragment.glsl.js +7 -0
  38. package/build/min/src/shaders/hillshade.vertex.glsl.js +1 -0
  39. package/build/min/src/shaders/hillshade_prepare.fragment.glsl.js +8 -0
  40. package/build/min/src/shaders/hillshade_prepare.vertex.glsl.js +1 -0
  41. package/build/min/src/shaders/line.fragment.glsl.js +12 -0
  42. package/build/min/src/shaders/line.vertex.glsl.js +17 -0
  43. package/build/min/src/shaders/line_gradient.fragment.glsl.js +10 -0
  44. package/build/min/src/shaders/line_gradient.vertex.glsl.js +16 -0
  45. package/build/min/src/shaders/line_pattern.fragment.glsl.js +15 -0
  46. package/build/min/src/shaders/line_pattern.vertex.glsl.js +20 -0
  47. package/build/min/src/shaders/line_sdf.fragment.glsl.js +17 -0
  48. package/build/min/src/shaders/line_sdf.vertex.glsl.js +20 -0
  49. package/build/min/src/shaders/raster.fragment.glsl.js +5 -0
  50. package/build/min/src/shaders/raster.vertex.glsl.js +1 -0
  51. package/build/min/src/shaders/symbol_icon.fragment.glsl.js +9 -0
  52. package/build/min/src/shaders/symbol_icon.vertex.glsl.js +5 -0
  53. package/build/min/src/shaders/symbol_sdf.fragment.glsl.js +19 -0
  54. package/build/min/src/shaders/symbol_sdf.vertex.glsl.js +13 -0
  55. package/package.json +7 -7
  56. package/src/data/bucket/fill_bucket.js +1 -1
  57. package/src/data/bucket/fill_extrusion_bucket.js +2 -2
  58. package/src/data/bucket/line_bucket.js +1 -1
  59. package/src/data/bucket/symbol_bucket.js +16 -15
  60. package/src/data/feature_index.js +1 -1
  61. package/src/data/program_configuration.js +1 -1
  62. package/src/gl/color_mode.js +1 -1
  63. package/src/gl/value.js +1 -1
  64. package/src/render/draw_debug.js +1 -1
  65. package/src/render/draw_fill.js +1 -1
  66. package/src/render/draw_heatmap.js +1 -1
  67. package/src/render/glyph_manager.js +6 -130
  68. package/src/render/painter.js +1 -1
  69. package/src/render/uniform_binding.js +1 -1
  70. package/src/shaders/fill_extrusion.fragment.glsl +0 -7
  71. package/src/shaders/fill_extrusion.vertex.glsl +4 -4
  72. package/src/shaders/index.js +50 -50
  73. package/src/source/geojson_worker_source.js +4 -4
  74. package/src/source/geojson_wrapper.js +34 -26
  75. package/src/source/resources/glyphs.js +73 -0
  76. package/src/source/resources/images.js +68 -0
  77. package/src/source/resources/index.js +22 -0
  78. package/src/source/vector_tile_worker_source.js +5 -5
  79. package/src/source/worker.js +6 -5
  80. package/src/source/worker_tile.js +4 -4
  81. package/src/style/properties.js +1 -2
  82. package/src/style/style.js +3 -3
  83. package/src/style/style_layer/symbol_style_layer.js +1 -1
  84. package/src/style/style_layer.js +1 -1
  85. package/src/style-spec/feature_filter/index.js +43 -34
  86. package/src/style-spec/group_by_layout.js +10 -32
  87. package/src/style-spec/reference/v8.json +1 -1
  88. package/src/symbol/mergelines.js +1 -3
  89. package/src/symbol/placement.js +21 -2
  90. package/src/symbol/shaping.js +9 -18
  91. package/src/symbol/symbol_layout.js +1 -2
  92. package/src/symbol/symbol_size.js +1 -1
  93. package/src/symbol/transform_text.js +4 -8
  94. package/src/ui/map.js +11 -39
  95. package/src/util/browser.js +3 -18
  96. package/src/util/classify_rings.js +1 -1
  97. package/src/util/dom.js +0 -88
  98. package/src/util/find_pole_of_inaccessibility.js +2 -2
  99. package/src/util/web_worker_transfer.js +4 -4
  100. package/src/style/load_glyph_range.js +0 -17
  101. package/src/style-spec/expression/compound_expression.js +0 -132
  102. package/src/style-spec/expression/definitions/assertion.js +0 -116
  103. package/src/style-spec/expression/definitions/at.js +0 -57
  104. package/src/style-spec/expression/definitions/case.js +0 -73
  105. package/src/style-spec/expression/definitions/coalesce.js +0 -68
  106. package/src/style-spec/expression/definitions/coercion.js +0 -109
  107. package/src/style-spec/expression/definitions/collator.js +0 -102
  108. package/src/style-spec/expression/definitions/comparison.js +0 -193
  109. package/src/style-spec/expression/definitions/formatted.js +0 -123
  110. package/src/style-spec/expression/definitions/index.js +0 -356
  111. package/src/style-spec/expression/definitions/interpolate.js +0 -245
  112. package/src/style-spec/expression/definitions/length.js +0 -54
  113. package/src/style-spec/expression/definitions/let.js +0 -60
  114. package/src/style-spec/expression/definitions/literal.js +0 -69
  115. package/src/style-spec/expression/definitions/match.js +0 -142
  116. package/src/style-spec/expression/definitions/step.js +0 -116
  117. package/src/style-spec/expression/definitions/var.js +0 -38
  118. package/src/style-spec/expression/evaluation_context.js +0 -35
  119. package/src/style-spec/expression/index.js +0 -329
  120. package/src/style-spec/expression/is_constant.js +0 -63
  121. package/src/style-spec/expression/parsing_context.js +0 -212
  122. package/src/style-spec/expression/parsing_error.js +0 -9
  123. package/src/style-spec/expression/runtime_error.js +0 -12
  124. package/src/style-spec/expression/scope.js +0 -34
  125. package/src/style-spec/expression/stops.js +0 -37
  126. package/src/style-spec/expression/types.js +0 -88
  127. package/src/style-spec/expression/values.js +0 -126
  128. package/src/style-spec/function/convert.js +0 -234
  129. package/src/style-spec/function/index.js +0 -299
  130. package/src/style-spec/util/color.js +0 -73
  131. package/src/style-spec/util/color_spaces.js +0 -128
  132. package/src/style-spec/util/get_type.js +0 -18
  133. package/src/style-spec/util/interpolate.js +0 -21
  134. package/src/style-spec/util/properties.js +0 -17
  135. package/src/style-spec/util/result.js +0 -19
  136. package/src/ui/anchor.js +0 -24
  137. package/src/ui/bind_handlers.js +0 -199
  138. package/src/ui/events.js +0 -210
  139. package/src/ui/handler/box_zoom.js +0 -151
  140. package/src/ui/handler/dblclick_zoom.js +0 -91
  141. package/src/ui/handler/drag_pan.js +0 -285
  142. package/src/ui/handler/drag_rotate.js +0 -290
  143. package/src/ui/handler/frame.js +0 -28
  144. package/src/ui/handler/inertia.js +0 -45
  145. package/src/ui/handler/keyboard.js +0 -148
  146. package/src/ui/handler/scroll_zoom.js +0 -284
  147. package/src/ui/handler/touch_zoom_rotate.js +0 -263
@@ -1,34 +0,0 @@
1
- /**
2
- * Tracks `let` bindings during expression parsing.
3
- * @private
4
- */
5
- class Scope {
6
- constructor(parent, bindings = []) {
7
- this.parent = parent;
8
- this.bindings = {};
9
- for (const [name, expression] of bindings) {
10
- this.bindings[name] = expression;
11
- }
12
- }
13
-
14
- concat(bindings) {
15
- return new Scope(this, bindings);
16
- }
17
-
18
- get(name) {
19
- if (this.bindings[name]) {
20
- return this.bindings[name];
21
- }
22
- if (this.parent) {
23
- return this.parent.get(name);
24
- }
25
- throw new Error(`${name} not found in scope.`);
26
- }
27
-
28
- has(name) {
29
- if (this.bindings[name]) return true;
30
- return this.parent ? this.parent.has(name) : false;
31
- }
32
- }
33
-
34
- module.exports = Scope;
@@ -1,37 +0,0 @@
1
- const RuntimeError = require('./runtime_error');
2
-
3
- /**
4
- * Returns the index of the last stop <= input, or 0 if it doesn't exist.
5
- * @private
6
- */
7
- function findStopLessThanOrEqualTo(stops, input) {
8
- const n = stops.length;
9
- let lowerIndex = 0;
10
- let upperIndex = n - 1;
11
- let currentIndex = 0;
12
- let currentValue;
13
- let upperValue;
14
-
15
- while (lowerIndex <= upperIndex) {
16
- currentIndex = Math.floor((lowerIndex + upperIndex) / 2);
17
- currentValue = stops[currentIndex];
18
- upperValue = stops[currentIndex + 1];
19
- if (input === currentValue || (input > currentValue && input < upperValue)) {
20
- // Search complete
21
- return currentIndex;
22
- }
23
- if (currentValue < input) {
24
- lowerIndex = currentIndex + 1;
25
- } else if (currentValue > input) {
26
- upperIndex = currentIndex - 1;
27
- } else {
28
- throw new RuntimeError('Input is not a number.');
29
- }
30
- }
31
-
32
- return Math.max(currentIndex - 1, 0);
33
- }
34
-
35
- module.exports = {
36
- findStopLessThanOrEqualTo
37
- };
@@ -1,88 +0,0 @@
1
- const NullType = { kind: 'null' };
2
- const NumberType = { kind: 'number' };
3
- const StringType = { kind: 'string' };
4
- const BooleanType = { kind: 'boolean' };
5
- const ColorType = { kind: 'color' };
6
- const ObjectType = { kind: 'object' };
7
- const ValueType = { kind: 'value' };
8
- const ErrorType = { kind: 'error' };
9
- const CollatorType = { kind: 'collator' };
10
- const FormattedType = { kind: 'formatted' };
11
-
12
- function array(itemType, N) {
13
- return {
14
- kind: 'array',
15
- itemType,
16
- N
17
- };
18
- }
19
-
20
- function toString(type) {
21
- if (type.kind === 'array') {
22
- const itemType = toString(type.itemType);
23
- return typeof type.N === 'number'
24
- ? `array<${itemType}, ${type.N}>`
25
- : type.itemType.kind === 'value'
26
- ? 'array'
27
- : `array<${itemType}>`;
28
- }
29
- return type.kind;
30
- }
31
-
32
- const valueMemberTypes = [
33
- NullType,
34
- NumberType,
35
- StringType,
36
- BooleanType,
37
- ColorType,
38
- FormattedType,
39
- ObjectType,
40
- array(ValueType)
41
- ];
42
-
43
- /**
44
- * Returns null if `t` is a subtype of `expected`; otherwise returns an
45
- * error message.
46
- * @private
47
- */
48
- function checkSubtype(expected, t) {
49
- if (t.kind === 'error') {
50
- // Error is a subtype of every type
51
- return null;
52
- }
53
- if (expected.kind === 'array') {
54
- if (
55
- t.kind === 'array' &&
56
- !checkSubtype(expected.itemType, t.itemType) &&
57
- (typeof expected.N !== 'number' || expected.N === t.N)
58
- ) {
59
- return null;
60
- }
61
- } else if (expected.kind === t.kind) {
62
- return null;
63
- } else if (expected.kind === 'value') {
64
- for (const memberType of valueMemberTypes) {
65
- if (!checkSubtype(memberType, t)) {
66
- return null;
67
- }
68
- }
69
- }
70
-
71
- return `Expected ${toString(expected)} but found ${toString(t)} instead.`;
72
- }
73
-
74
- module.exports = {
75
- NullType,
76
- NumberType,
77
- StringType,
78
- BooleanType,
79
- ColorType,
80
- FormattedType,
81
- ObjectType,
82
- ValueType,
83
- ErrorType,
84
- CollatorType,
85
- array,
86
- toString,
87
- checkSubtype
88
- };
@@ -1,126 +0,0 @@
1
- const assert = require('assert');
2
-
3
- const Color = require('../util/color');
4
- const { Collator } = require('./definitions/collator');
5
- const {
6
- NullType,
7
- NumberType,
8
- StringType,
9
- BooleanType,
10
- ColorType,
11
- ObjectType,
12
- ValueType,
13
- CollatorType,
14
- array
15
- } = require('./types');
16
-
17
- function validateRGBA(r, g, b, a) {
18
- if (
19
- !(
20
- typeof r === 'number' &&
21
- r >= 0 &&
22
- r <= 255 &&
23
- typeof g === 'number' &&
24
- g >= 0 &&
25
- g <= 255 &&
26
- typeof b === 'number' &&
27
- b >= 0 &&
28
- b <= 255
29
- )
30
- ) {
31
- const value = typeof a === 'number' ? [r, g, b, a] : [r, g, b];
32
- return `Invalid rgba value [${value.join(', ')}]: 'r', 'g', and 'b' must be between 0 and 255.`;
33
- }
34
-
35
- if (!(typeof a === 'undefined' || (typeof a === 'number' && a >= 0 && a <= 1))) {
36
- return `Invalid rgba value [${[r, g, b, a].join(', ')}]: 'a' must be between 0 and 1.`;
37
- }
38
-
39
- return null;
40
- }
41
-
42
- function isValue(mixed) {
43
- if (mixed === null) {
44
- return true;
45
- }
46
- if (typeof mixed === 'string') {
47
- return true;
48
- }
49
- if (typeof mixed === 'boolean') {
50
- return true;
51
- }
52
- if (typeof mixed === 'number') {
53
- return true;
54
- }
55
- if (mixed instanceof Color) {
56
- return true;
57
- }
58
- if (mixed instanceof Collator) {
59
- return true;
60
- }
61
- if (Array.isArray(mixed)) {
62
- for (const item of mixed) {
63
- if (!isValue(item)) {
64
- return false;
65
- }
66
- }
67
- return true;
68
- }
69
- if (typeof mixed === 'object') {
70
- for (const key in mixed) {
71
- if (!isValue(mixed[key])) {
72
- return false;
73
- }
74
- }
75
- return true;
76
- }
77
- return false;
78
- }
79
-
80
- function typeOf(value) {
81
- if (value === null) {
82
- return NullType;
83
- }
84
- if (typeof value === 'string') {
85
- return StringType;
86
- }
87
- if (typeof value === 'boolean') {
88
- return BooleanType;
89
- }
90
- if (typeof value === 'number') {
91
- return NumberType;
92
- }
93
- if (value instanceof Color) {
94
- return ColorType;
95
- }
96
- if (value instanceof Collator) {
97
- return CollatorType;
98
- }
99
- if (Array.isArray(value)) {
100
- const length = value.length;
101
- let itemType;
102
-
103
- for (const item of value) {
104
- const t = typeOf(item);
105
- if (!itemType) {
106
- itemType = t;
107
- } else if (itemType === t) {
108
- } else {
109
- itemType = ValueType;
110
- break;
111
- }
112
- }
113
-
114
- return array(itemType || ValueType, length);
115
- }
116
- assert(typeof value === 'object');
117
- return ObjectType;
118
- }
119
-
120
- module.exports = {
121
- Color,
122
- Collator,
123
- validateRGBA,
124
- isValue,
125
- typeOf
126
- };
@@ -1,234 +0,0 @@
1
- const assert = require('assert');
2
-
3
- module.exports = convertFunction;
4
-
5
- function convertFunction(parameters, propertySpec) {
6
- let stops = parameters.stops;
7
- if (!stops) {
8
- // identity function
9
- return convertIdentityFunction(parameters, propertySpec);
10
- }
11
-
12
- const zoomAndFeatureDependent = stops && typeof stops[0][0] === 'object';
13
- const featureDependent = zoomAndFeatureDependent || parameters.property !== undefined;
14
- const zoomDependent = zoomAndFeatureDependent || !featureDependent;
15
-
16
- stops = stops.map(stop => {
17
- if (!featureDependent && propertySpec.tokens && typeof stop[1] === 'string') {
18
- return [stop[0], convertTokenString(stop[1])];
19
- }
20
- return [stop[0], ['literal', stop[1]]];
21
- });
22
-
23
- if (zoomAndFeatureDependent) {
24
- return convertZoomAndPropertyFunction(parameters, propertySpec, stops);
25
- }
26
- if (zoomDependent) {
27
- return convertZoomFunction(parameters, propertySpec, stops);
28
- }
29
- return convertPropertyFunction(parameters, propertySpec, stops);
30
- }
31
-
32
- function convertIdentityFunction(parameters, propertySpec) {
33
- const get = ['get', parameters.property];
34
-
35
- if (parameters.default === undefined) {
36
- return get;
37
- }
38
- if (propertySpec.type === 'enum') {
39
- return ['match', get, Object.keys(propertySpec.values), get, parameters.default];
40
- }
41
- const expression = [
42
- propertySpec.type === 'color' ? 'to-color' : propertySpec.type,
43
- get,
44
- ['literal', parameters.default]
45
- ];
46
- if (propertySpec.type === 'array') {
47
- expression.splice(1, 0, propertySpec.value, propertySpec.length || null);
48
- }
49
- return expression;
50
- }
51
-
52
- function getInterpolateOperator(parameters) {
53
- switch (parameters.colorSpace) {
54
- case 'hcl':
55
- return 'interpolate-hcl';
56
- case 'lab':
57
- return 'interpolate-lab';
58
- default:
59
- return 'interpolate';
60
- }
61
- }
62
-
63
- function convertZoomAndPropertyFunction(parameters, propertySpec, stops) {
64
- const featureFunctionParameters = {};
65
- const featureFunctionStops = {};
66
- const zoomStops = [];
67
- for (let s = 0; s < stops.length; s++) {
68
- const stop = stops[s];
69
- const zoom = stop[0].zoom;
70
- if (featureFunctionParameters[zoom] === undefined) {
71
- featureFunctionParameters[zoom] = {
72
- zoom: zoom,
73
- type: parameters.type,
74
- property: parameters.property,
75
- default: parameters.default
76
- };
77
- featureFunctionStops[zoom] = [];
78
- zoomStops.push(zoom);
79
- }
80
- featureFunctionStops[zoom].push([stop[0].value, stop[1]]);
81
- }
82
-
83
- // the interpolation type for the zoom dimension of a zoom-and-property
84
- // function is determined directly from the style property specification
85
- // for which it's being used: linear for interpolatable properties, step
86
- // otherwise.
87
- const functionType = getFunctionType({}, propertySpec);
88
- if (functionType === 'exponential') {
89
- const expression = [getInterpolateOperator(parameters), ['linear'], ['zoom']];
90
-
91
- for (const z of zoomStops) {
92
- const output = convertPropertyFunction(featureFunctionParameters[z], propertySpec, featureFunctionStops[z]);
93
- appendStopPair(expression, z, output, false);
94
- }
95
-
96
- return expression;
97
- }
98
- const expression = ['step', ['zoom']];
99
-
100
- for (const z of zoomStops) {
101
- const output = convertPropertyFunction(featureFunctionParameters[z], propertySpec, featureFunctionStops[z]);
102
- appendStopPair(expression, z, output, true);
103
- }
104
-
105
- fixupDegenerateStepCurve(expression);
106
-
107
- return expression;
108
- }
109
-
110
- function coalesce(a, b) {
111
- if (a !== undefined) return a;
112
- if (b !== undefined) return b;
113
- }
114
-
115
- function convertPropertyFunction(parameters, propertySpec, stops) {
116
- const type = getFunctionType(parameters, propertySpec);
117
- const get = ['get', parameters.property];
118
- if (type === 'categorical' && typeof stops[0][0] === 'boolean') {
119
- assert(parameters.stops.length > 0 && parameters.stops.length <= 2);
120
- const expression = ['case'];
121
- for (const stop of stops) {
122
- expression.push(['==', get, stop[0]], stop[1]);
123
- }
124
- expression.push(['literal', coalesce(parameters.default, propertySpec.default)]);
125
- return expression;
126
- }
127
- if (type === 'categorical') {
128
- const expression = ['match', get];
129
- for (const stop of stops) {
130
- appendStopPair(expression, stop[0], stop[1], false);
131
- }
132
- expression.push(['literal', coalesce(parameters.default, propertySpec.default)]);
133
- return expression;
134
- }
135
- if (type === 'interval') {
136
- const expression = ['step', ['number', get]];
137
- for (const stop of stops) {
138
- appendStopPair(expression, stop[0], stop[1], true);
139
- }
140
- fixupDegenerateStepCurve(expression);
141
- return parameters.default === undefined
142
- ? expression
143
- : ['case', ['==', ['typeof', get], 'number'], expression, ['literal', parameters.default]];
144
- }
145
- if (type === 'exponential') {
146
- const base = parameters.base !== undefined ? parameters.base : 1;
147
- const expression = [getInterpolateOperator(parameters), ['exponential', base], ['number', get]];
148
- for (const stop of stops) {
149
- appendStopPair(expression, stop[0], stop[1], false);
150
- }
151
- return parameters.default === undefined
152
- ? expression
153
- : ['case', ['==', ['typeof', get], 'number'], expression, ['literal', parameters.default]];
154
- }
155
- throw new Error(`Unknown property function type ${type}`);
156
- }
157
-
158
- function convertZoomFunction(parameters, propertySpec, stops, input = ['zoom']) {
159
- const type = getFunctionType(parameters, propertySpec);
160
- let expression;
161
- let isStep = false;
162
- if (type === 'interval') {
163
- expression = ['step', input];
164
- isStep = true;
165
- } else if (type === 'exponential') {
166
- const base = parameters.base !== undefined ? parameters.base : 1;
167
- expression = [getInterpolateOperator(parameters), ['exponential', base], input];
168
- } else {
169
- throw new Error(`Unknown zoom function type "${type}"`);
170
- }
171
-
172
- for (const stop of stops) {
173
- appendStopPair(expression, stop[0], stop[1], isStep);
174
- }
175
-
176
- fixupDegenerateStepCurve(expression);
177
-
178
- return expression;
179
- }
180
-
181
- function fixupDegenerateStepCurve(expression) {
182
- // degenerate step curve (i.e. a constant function): add a noop stop
183
- if (expression[0] === 'step' && expression.length === 3) {
184
- expression.push(0);
185
- expression.push(expression[3]);
186
- }
187
- }
188
-
189
- function appendStopPair(curve, input, output, isStep) {
190
- // Skip duplicate stop values. They were not validated for functions, but they are for expressions.
191
- // https://github.com/mapbox/mapbox-gl-js/issues/4107
192
- if (curve.length > 3 && input === curve[curve.length - 2]) {
193
- return;
194
- }
195
- // step curves don't get the first input value, as it is redundant.
196
- if (!(isStep && curve.length === 2)) {
197
- curve.push(input);
198
- }
199
- curve.push(output);
200
- }
201
-
202
- function getFunctionType(parameters, propertySpec) {
203
- if (parameters.type) {
204
- return parameters.type;
205
- }
206
- assert(propertySpec.expression);
207
- return propertySpec.expression.interpolated ? 'exponential' : 'interval';
208
- }
209
-
210
- // "String with {name} token" => ["concat", "String with ", ["get", "name"], " token"]
211
- function convertTokenString(s) {
212
- const result = ['concat'];
213
- const re = /{([^{}]+)}/g;
214
- let pos = 0;
215
- let match;
216
- while ((match = re.exec(s)) !== null) {
217
- const literal = s.slice(pos, re.lastIndex - match[0].length);
218
- pos = re.lastIndex;
219
- if (literal.length > 0) result.push(literal);
220
- result.push(['to-string', ['get', match[1]]]);
221
- }
222
-
223
- if (result.length === 1) {
224
- return s;
225
- }
226
-
227
- if (pos < s.length) {
228
- result.push(s.slice(pos));
229
- } else if (result.length === 2) {
230
- return result[1];
231
- }
232
-
233
- return result;
234
- }