Skip to content

Commit df8d6a9

Browse files
committed
pull values from spec
1 parent 8bc1cf4 commit df8d6a9

File tree

6 files changed

+18
-17
lines changed

6 files changed

+18
-17
lines changed

build/generate-style-spec.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,14 +118,16 @@ function layerType(key) {
118118

119119
const layerTypes = Object.keys(spec.layer.type.values);
120120

121+
const projectionTypes = spec.projection.type.values;
122+
121123
fs.writeFileSync('src/types.g.ts',
122124
`// Generated code; do not edit. Edit build/generate-style-spec.ts instead.
123125
/* eslint-disable */
124126
125127
export type ColorSpecification = string;
126128
127-
export type ProjectionPreset = 'globe';
128-
export type ProjectionPrimitive = 'mercator' | 'stereographic';
129+
export type ProjectionPreset = ${projectionTypes.presets.map(p => `'${p}'`).join(' | ')};
130+
export type ProjectionPrimitive = ${projectionTypes.projections.map(p => `'${p}'`).join(' | ')};
129131
export type ProjectionTransition = [ProjectionPrimitive, ProjectionPrimitive, number];
130132
export type ProjectionTransitionSpecification = ProjectionPreset | ProjectionPrimitive | ProjectionTransition | PropertyValueSpecification<ProjectionTransition>
131133

docs/types.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,13 +168,13 @@ Use a [`camera expression`](./expressions.md#camera-expressions), to discretely
168168

169169
```ts
170170
type: ["step", ["zoom"],
171-
"globe",
171+
"stereographic",
172172
11, "mercator"
173173
]
174174
```
175175

176-
`output at zoom 10.9: ["globe", "globe", 1]`
177-
`output at zoom 11.0: ["globe", "globe", 1]`
176+
`output at zoom 10.9: ["stereographic", "stereographic", 1]`
177+
`output at zoom 11.0: ["stereographic", "stereographic", 1]`
178178
`output at zoom 11.1: ["mercator", "mercator", 1]`
179179

180180
#### Animate between different projections based on zoom level**

src/util/interpolate.test.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,11 @@ describe('interpolate', () => {
119119
});
120120

121121
test('interpolate projection', () => {
122-
const i11nFn = (t: number) => interpolate.projection('globe', 'mercator', t);
122+
const i11nFn = (t: number) => interpolate.projection('stereographic', 'mercator', t);
123123
expect(i11nFn(0.5)).toBeInstanceOf(Projection);
124-
expect(`${i11nFn(0.5)}`).toBe('["globe", "mercator", 0.5]');
124+
expect(`${i11nFn(0.5)}`).toBe('["stereographic", "mercator", 0.5]');
125125
});
126+
126127

127128
describe('interpolate variableAnchorOffsetCollection', () => {
128129
const i11nFn = interpolate.variableAnchorOffsetCollection;

src/util/projection.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {Projection} from './projection';
33
describe('Projection class', () => {
44

55
test('should serialize to rgba format', () => {
6-
expect(`${new Projection('mercator', 'globe', 1)}`).toBe('["mercator", "globe", 1]');
7-
expect(`${new Projection('globe', 'mercator', 0.3)}`).toBe('["globe", "mercator", 0.3]');
6+
expect(`${new Projection('mercator', 'stereographic', 1)}`).toBe('["mercator", "stereographic", 1]');
7+
expect(`${new Projection('stereographic', 'mercator', 0.3)}`).toBe('["stereographic", "mercator", 0.3]');
88
});
99
});

src/util/projection.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import v8 from '../reference/v8.json' with { type: 'json' };
12
import {ProjectionPrimitive, ProjectionTransition, ProjectionTransitionSpecification, PropertyValueSpecification} from '../types.g';
23

34
export class Projection {
@@ -36,9 +37,9 @@ export function isProjectionTransitionValue(value: unknown): value is Projection
3637
}
3738

3839
export function isProjectionPrimitive(value: unknown): value is ProjectionPrimitive {
39-
return value === 'mercator' || value === 'stereographic';
40+
return v8.projection.type.values.projections.includes(value as string);
4041
}
4142

4243
export function isProjectionPreset(value: unknown): value is ProjectionPrimitive {
43-
return value === 'globe';
44+
return v8.projection.type.values.presets.includes(value as string);
4445
}

src/validate/validate_projection_type.test.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import v8 from '../reference/v8.json' with {type: 'json'};
12
import validateProjectionTransition from './validate_projection_type';
23

34
describe('validateProjectionTransition function', () => {
@@ -23,12 +24,8 @@ describe('validateProjectionTransition function', () => {
2324
});
2425

2526
test('should return no errors when projectionTransition is valid projection string', () => {
26-
const validProjectionTransitionString = [
27-
'mercator',
28-
'stereographic',
29-
'globe',
30-
];
31-
27+
const validProjectionTransitionString = [...v8.projection.type.values.presets, ...v8.projection.type.values.projections]
28+
3229
for (const value of validProjectionTransitionString) {
3330
const errors = validateProjectionTransition({key, value});
3431
expect(errors).toHaveLength(0);

0 commit comments

Comments
 (0)