Skip to content

Commit 5d25160

Browse files
authored
Remove interpolate-projection (#901)
1 parent 107bd0e commit 5d25160

File tree

17 files changed

+101
-45
lines changed

17 files changed

+101
-45
lines changed

build/generate-style-spec.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -207,9 +207,7 @@ export type ExpressionSpecification =
207207
| ['distance', unknown | ExpressionSpecification]
208208
// Ramps, scales, curves
209209
| ['interpolate', InterpolationSpecification, number | ExpressionSpecification,
210-
...(number | number[] | ColorSpecification | ExpressionSpecification)[]] // alternating number and number | number[] | ColorSpecification
211-
| ['interpolate-projection', InterpolationSpecification, number | ExpressionSpecification,
212-
...(number | string)[]] // alternating Projection
210+
...(number | number[] | ColorSpecification | ExpressionSpecification | ProjectionSpecification )[]] // alternating number and number | number[] | ColorSpecification
213211
| ['interpolate-hcl', InterpolationSpecification, number | ExpressionSpecification,
214212
...(number | ColorSpecification)[]] // alternating number and ColorSpecificaton
215213
| ['interpolate-lab', InterpolationSpecification, number | ExpressionSpecification,

docs/types.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,10 +176,10 @@ output at zoom 11.1: "mercator"
176176

177177
#### Animate between different projections based on zoom level**
178178

179-
Use a [`camera expression`](./expressions.md#camera-expressions), to animate between projections based on zoom, using [`interpolate-projection`](./expressions.md#interpolate-projection) function. The example below will yield an adaptive globe that interpolates from `vertical-perspective` to `mercator` between zoom 10 and 12.
179+
Use a [`camera expression`](./expressions.md#camera-expressions), to animate between projections based on zoom, using [`interpolate`](./expressions.md#interpolate) function. The example below will yield an adaptive globe that interpolates from `vertical-perspective` to `mercator` between zoom 10 and 12.
180180

181181
```ts
182-
type: ["interpolate-projection", ["linear"], ["zoom"],
182+
type: ["interpolate", ["linear"], ["zoom"],
183183
10,"vertical-perspective",
184184
12,"mercator"
185185
]
@@ -205,4 +205,4 @@ There are also additional presets that yield commonly used expressions:
205205

206206
| Preset | Full value | Description |
207207
|--------|------------|-------------|
208-
| `globe` | `["interpolate-projection", ["linear"], ["zoom"],`<br>`10, "vertical-perspective", 12, "mercator"]` | Adaptive globe: interpolates from vertical-perspective to mercator projection between zoom levels 10 and 12. |
208+
| `globe` | `["interpolate", ["linear"], ["zoom"],`<br>`10, "vertical-perspective", 12, "mercator"]` | Adaptive globe: interpolates from vertical-perspective to mercator projection between zoom levels 10 and 12. |

src/expression/definitions/coercion.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,8 @@ class Coercion implements Expression {
123123
return Formatted.fromString(valueToString(this.args[0].evaluate(ctx)));
124124
case 'resolvedImage':
125125
return ResolvedImage.fromString(valueToString(this.args[0].evaluate(ctx)));
126+
case 'projection':
127+
return this.args[0].evaluate(ctx);
126128
default:
127129
return valueToString(this.args[0].evaluate(ctx));
128130
}

src/expression/definitions/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ export const expressions: ExpressionRegistry = {
5252
'interpolate': Interpolate,
5353
'interpolate-hcl': Interpolate,
5454
'interpolate-lab': Interpolate,
55-
'interpolate-projection': Interpolate,
5655
'length': Length,
5756
'let': Let,
5857
'literal': Literal,

src/expression/definitions/interpolate.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export type InterpolationType = {
2020
controlPoints: [number, number, number, number];
2121
};
2222
type InterpolatedValueType = NumberTypeT | ColorTypeT | ProjectionTypeT | PaddingTypeT | VariableAnchorOffsetCollectionTypeT | ArrayType<NumberTypeT>;
23-
type InterpolationOperator = 'interpolate' | 'interpolate-hcl' | 'interpolate-lab' | 'interpolate-projection';
23+
type InterpolationOperator = 'interpolate' | 'interpolate-hcl' | 'interpolate-lab';
2424
class Interpolate implements Expression {
2525
type: InterpolatedValueType;
2626

@@ -108,8 +108,6 @@ class Interpolate implements Expression {
108108
let outputType: Type = null;
109109
if (operator === 'interpolate-hcl' || operator === 'interpolate-lab') {
110110
outputType = ColorType;
111-
} else if (operator === 'interpolate-projection') {
112-
outputType = ProjectionType;
113111
} else if (context.expectedType && context.expectedType.kind !== 'value') {
114112
outputType = context.expectedType;
115113
}
@@ -128,7 +126,6 @@ class Interpolate implements Expression {
128126
if (stops.length && stops[stops.length - 1][0] >= label) {
129127
return context.error('Input/output pairs for "interpolate" expressions must be arranged with input values in strictly ascending order.', labelKey) as null;
130128
}
131-
132129
const parsed = context.parse(value, valueKey, outputType);
133130
if (!parsed) return null;
134131
outputType = outputType || parsed.type;
@@ -187,14 +184,13 @@ class Interpolate implements Expression {
187184
return interpolate.padding(outputLower, outputUpper, t);
188185
case 'variableAnchorOffsetCollection':
189186
return interpolate.variableAnchorOffsetCollection(outputLower, outputUpper, t);
187+
case 'projection':
188+
return interpolate.projection(outputLower, outputUpper, t);
190189
}
191190
case 'interpolate-hcl':
192191
return interpolate.color(outputLower, outputUpper, t, 'hcl');
193192
case 'interpolate-lab':
194193
return interpolate.color(outputLower, outputUpper, t, 'lab');
195-
case 'interpolate-projection': {
196-
return interpolate.projection(outputLower, outputUpper, t);
197-
}
198194
}
199195
}
200196

src/expression/index.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ export function createPropertyExpression(expressionInput: unknown, propertySpec:
334334
}
335335

336336
import {isFunction, createFunction} from '../function';
337-
import {Color, VariableAnchorOffsetCollection} from './values';
337+
import {Color, Projection, VariableAnchorOffsetCollection} from './values';
338338

339339
// serialization wrapper for old-style stop functions normalized to the
340340
// expression interface
@@ -391,6 +391,8 @@ export function normalizePropertyExpression<T>(
391391
constant = Padding.parse(value as (number | number[]));
392392
} else if (specification.type === 'variableAnchorOffsetCollection' && Array.isArray(value)) {
393393
constant = VariableAnchorOffsetCollection.parse(value as VariableAnchorOffsetCollectionSpecification);
394+
} else if (specification.type === 'projection' && typeof value === 'string') {
395+
constant = value;
394396
}
395397
return {
396398
kind: 'constant',
@@ -477,6 +479,8 @@ function getDefaultValue(spec: StylePropertySpecification): Value {
477479
return Padding.parse(spec.default) || null;
478480
} else if (spec.type === 'variableAnchorOffsetCollection') {
479481
return VariableAnchorOffsetCollection.parse(spec.default) || null;
482+
} else if (spec.type === 'projection') {
483+
return Projection.parse(spec.default) || null;
480484
} else if (spec.default === undefined) {
481485
return null;
482486
} else {

src/expression/parsing_context.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ class ParsingContext {
120120
//
121121
if ((expected.kind === 'string' || expected.kind === 'number' || expected.kind === 'boolean' || expected.kind === 'object' || expected.kind === 'array') && actual.kind === 'value') {
122122
parsed = annotate(parsed, expected, options.typeAnnotation || 'assert');
123-
} else if ((expected.kind === 'projection') && (actual.kind === 'string')) {
123+
} else if ((expected.kind === 'projection') && (actual.kind === 'string' || actual.kind === 'array')) {
124124
parsed = annotate(parsed, expected, options.typeAnnotation || 'coerce');
125125
} else if ((expected.kind === 'color' || expected.kind === 'formatted' || expected.kind === 'resolvedImage') && (actual.kind === 'value' || actual.kind === 'string')) {
126126
parsed = annotate(parsed, expected, options.typeAnnotation || 'coerce');

src/index.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,12 @@ export type StylePropertySpecification = {
6767
expression?: ExpressionSpecificationDefinition;
6868
transition: boolean;
6969
default?: VariableAnchorOffsetCollectionSpecification;
70+
} | {
71+
type: 'projection';
72+
'property-type': ExpressionType;
73+
expression?: ExpressionSpecificationDefinition;
74+
transition: boolean;
75+
default?: ProjectionSpecification;
7076
};
7177

7278
import v8Spec from './reference/v8.json' with {type: 'json'};
@@ -107,7 +113,7 @@ import {typeOf} from './expression/values';
107113
import FormatExpression from './expression/definitions/format';
108114
import Literal from './expression/definitions/literal';
109115
import CompoundExpression from './expression/compound_expression';
110-
import {VariableAnchorOffsetCollectionSpecification} from './types.g';
116+
import {ProjectionSpecification, VariableAnchorOffsetCollectionSpecification} from './types.g';
111117
import format from './format';
112118
import validate from './validate/validate';
113119
import migrate from './migrate';

src/reference/v8.json

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@
130130
"doc": "The projection configuration",
131131
"example": {
132132
"type": [
133-
"interpolate-projection",
133+
"interpolate",
134134
["linear"],
135135
["zoom"],
136136
10, "globe",
@@ -3063,24 +3063,6 @@
30633063
}
30643064
}
30653065
},
3066-
"interpolate-projection": {
3067-
"doc": "Produces continuous, smooth results by interpolating between pairs of input and output values (\"stops\"). Works like `interpolate`, but the output type must be a [`projection`](./types.md#projection).",
3068-
"example": {
3069-
"syntax": {
3070-
"method": ["[\"linear\"] | [\"exponential\", base] | [\"cubic-bezier\", x1, y1, x2, y2]", "number", "string", "number", "..."],
3071-
"result": "projection"
3072-
},
3073-
"value": ["interpolate-projection", ["linear"], ["zoom"], 10, "vertical-perspective", 12, "mercator"]
3074-
},
3075-
"group": "Ramps, scales, curves",
3076-
"sdk-support": {
3077-
"basic functionality": {
3078-
"js": "https://github.com/maplibre/maplibre-gl-js/issues/5039",
3079-
"ios": "https://github.com/maplibre/maplibre-native/issues/3013",
3080-
"android": "https://github.com/maplibre/maplibre-native/issues/3013"
3081-
}
3082-
}
3083-
},
30843066
"ln2": {
30853067
"doc": "Returns mathematical constant ln(2).",
30863068
"example": {
@@ -4597,7 +4579,13 @@
45974579
"type": "projection",
45984580
"doc": "The projection type. Can be specified as a string, a transition state, or an expression.",
45994581
"default": "mercator",
4600-
"property-type": "data-constant"
4582+
"property-type": "data-constant",
4583+
"expression": {
4584+
"interpolated": true,
4585+
"parameters": [
4586+
"zoom"
4587+
]
4588+
}
46014589
}
46024590
},
46034591
"paint": [

src/util/projection.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,19 @@ export default class Projection extends Array {
1515
toString() {
1616
return `["${this[0]}", "${this[1]}", ${this[2]}]`;
1717
}
18+
19+
static parse(input: any): Projection {
20+
if (input instanceof Projection) {
21+
return input;
22+
}
23+
if (Array.isArray(input) && input.length === 3) {
24+
return new Projection(input[0], input[1], input[2]);
25+
}
26+
if (typeof input === 'string') {
27+
return new Projection(input, input, 1);
28+
}
29+
return undefined;
30+
}
1831
}
1932

2033
export function isProjectionConfig(value: unknown): value is ProjectionSpecification {
@@ -23,7 +36,7 @@ export function isProjectionConfig(value: unknown): value is ProjectionSpecifica
2336

2437
export function isPropertyValueSpecification(value: unknown): value is PropertyValueSpecification<ProjectionT> {
2538

26-
if (['interpolate-projection', 'step', 'literal'].includes(value[0])) {
39+
if (['interpolate', 'step', 'literal'].includes(value[0])) {
2740
return true
2841
}
2942
return false

0 commit comments

Comments
 (0)