Skip to content

Commit a4f1e7b

Browse files
committed
use projection class
1 parent 2579b0b commit a4f1e7b

File tree

5 files changed

+10
-13
lines changed

5 files changed

+10
-13
lines changed

build/generate-style-spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,8 @@ export type ColorSpecification = string;
126126
127127
export type ProjectionSpecification = {"mode":ProjectionType}
128128
export type PrimitiveProjection = 'mercator' | 'globe';
129-
export type ProjectionTransition = [PrimitiveProjection, PrimitiveProjection, number];
130-
export type ProjectionType = PrimitiveProjection | ProjectionTransition | PropertyValueSpecification<ProjectionTransition>
129+
export type PrimitiveTransition = [PrimitiveProjection, PrimitiveProjection, number];
130+
export type ProjectionType = PrimitiveProjection | PrimitiveTransition | PropertyValueSpecification<PrimitiveTransition>
131131
132132
133133
export type PaddingSpecification = number | number[];

src/expression/values.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ import ResolvedImage from './types/resolved_image';
88
import {NullType, NumberType, StringType, BooleanType, ColorType, ObjectType, ValueType, CollatorType, FormattedType, ResolvedImageType, array, PaddingType, VariableAnchorOffsetCollectionType, ProjectionType} from './types';
99

1010
import type {Type} from './types';
11-
import {ProjectionTransition, isProjectionTransition} from '../types.g';
12-
import { Projection } from '../util/projection';
11+
import {Projection} from '../util/projection';
1312

1413
export function validateRGBA(r: unknown, g: unknown, b: unknown, a?: unknown): string | null {
1514
if (!(
@@ -30,7 +29,7 @@ export function validateRGBA(r: unknown, g: unknown, b: unknown, a?: unknown): s
3029
return null;
3130
}
3231

33-
export type Value = null | string | boolean | number | Color | ProjectionTransition | Collator | Formatted | Padding | ResolvedImage | VariableAnchorOffsetCollection | ReadonlyArray<Value> | {
32+
export type Value = null | string | boolean | number | Color | Projection | Collator | Formatted | Padding | ResolvedImage | VariableAnchorOffsetCollection | ReadonlyArray<Value> | {
3433
readonly [x: string]: Value;
3534
};
3635

@@ -77,7 +76,7 @@ export function typeOf(value: Value): Type {
7776
return NumberType;
7877
} else if (value instanceof Color) {
7978
return ColorType;
80-
} else if (isProjectionTransition(value)) {
79+
} else if (value instanceof Projection) {
8180
return ProjectionType;
8281
} else if (value instanceof Collator) {
8382
return CollatorType;
@@ -117,11 +116,11 @@ export function toString(value: Value) {
117116
return '';
118117
} else if (type === 'string' || type === 'number' || type === 'boolean') {
119118
return String(value);
120-
} else if (value instanceof Color || isProjectionTransition(value) || value instanceof Formatted || value instanceof Padding || value instanceof VariableAnchorOffsetCollection || value instanceof ResolvedImage) {
119+
} else if (value instanceof Color || value instanceof Projection || value instanceof Formatted || value instanceof Padding || value instanceof VariableAnchorOffsetCollection || value instanceof ResolvedImage) {
121120
return value.toString();
122121
} else {
123122
return JSON.stringify(value);
124123
}
125124
}
126125

127-
export {Color, Collator, ProjectionTransition as Projection, Padding, VariableAnchorOffsetCollection};
126+
export {Color, Collator, Projection, Padding, VariableAnchorOffsetCollection};

src/util/interpolate.test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ import interpolate, {isSupportedInterpolationColorSpace} from './interpolate';
33
import Color from './color';
44
import Padding from './padding';
55
import VariableAnchorOffsetCollection from './variable_anchor_offset_collection';
6-
import {isProjectionTransition} from '../types.g';
7-
import { Projection } from './projection';
6+
import {Projection} from './projection';
87

98
describe('interpolate', () => {
109

src/util/projection.test.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,10 @@ import {Projection} from './projection';
22

33
describe('Projection class', () => {
44

5-
65
test('should serialize to rgba format', () => {
76
expect(`${new Projection('mercator', 'globe', 1)}`).toBe('["mercator", "globe", 1]');
87
expect(`${new Projection('globe', 'mercator', 0.3)}`).toBe('["globe", "mercator", 0.3]');
98
expect(`${Projection.parse('globe')}`).toBe('["globe", "globe", 1]');
109
expect(`${Projection.parse('mercator')}`).toBe('["mercator", "mercator", 1]');
1110
});
12-
1311
});

src/validate/validate_projection-mode.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import ValidationError from '../error/validation_error';
22
import getType from '../util/get_type';
33
import v8 from '../reference/v8.json' with {type: 'json'};
4-
import {isPrimitiveProjection, isProjectionTransition, isProjectionType, ProjectionType, StyleSpecification} from '../types.g';
4+
import {ProjectionType, StyleSpecification} from '../types.g';
5+
import { isPrimitiveProjection, isProjectionTransition, isProjectionType } from '../util/projection';
56

67
interface ValidateProjectionOptions {
78
sourceName?: string;

0 commit comments

Comments
 (0)