Skip to content

Commit

Permalink
allow parsing of projection definition object
Browse files Browse the repository at this point in the history
  • Loading branch information
birkskyum committed Nov 17, 2024
1 parent cdc0307 commit 537eb32
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/expression/types/projection_definition.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,16 @@ describe('Projection class', () => {
expect(projection.to).toBe('vertical-perspective');
expect(projection.transition).toBe(0.5);
});

test('should parse projection object', () => {
const projection = ProjectionDefinition.parse({from: 'mercator', to: 'vertical-perspective', transition: 0.5});
expect(projection.from).toBe('mercator');
expect(projection.to).toBe('vertical-perspective');
expect(projection.transition).toBe(0.5);
});

test('should serialize projection', () => {
const projection = ProjectionDefinition.parse(['mercator', 'vertical-perspective', 0.5]);
expect(JSON.stringify(projection)).toBe('{\"from\":\"mercator\",\"to\":\"vertical-perspective\",\"transition\":0.5}');
});
});
5 changes: 5 additions & 0 deletions src/expression/types/projection_definition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ export class ProjectionDefinition {
if (Array.isArray(input) && input.length === 3 && typeof input[0] === 'string' && typeof input[1] === 'string' && typeof input[2] === 'number') {
return new ProjectionDefinition(input[0], input[1], input[2]);
}

if (typeof input === 'object' && typeof input.from === 'string' && typeof input.to === 'string' && typeof input.transition === 'number') {
return new ProjectionDefinition(input.from, input.to, input.transition);
}

if (typeof input === 'string') {
return new ProjectionDefinition(input, input, 1);
}
Expand Down

0 comments on commit 537eb32

Please sign in to comment.