From d1cad9dcd539acc36fede0f42d8ea70e3ed32070 Mon Sep 17 00:00:00 2001 From: Birk Skyum Date: Tue, 5 Nov 2024 02:22:12 +0100 Subject: [PATCH] Make globe a spherical projection Add projection expression --- CHANGELOG.md | 3 +- src/diff.test.ts | 4 +- src/reference/v8.json | 58 ++++++++++++++++++++---- src/validate/validate_projection.test.ts | 4 +- 4 files changed, 55 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e44dee3dd..87625ea77 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,8 +1,7 @@ ## main ### ✨ Features and improvements -- Rename adaptive globe from `globe` to `globe-to-mercator` ([#878](https://github.com/maplibre/maplibre-style-spec/pull/878)) -- Add non-adaptive `globe` ([#878](https://github.com/maplibre/maplibre-style-spec/pull/878)) +- Add projection type expression syntax ([#888](https://github.com/maplibre/maplibre-style-spec/pull/888)) - _...Add new stuff here..._ ### 🐞 Bug fixes diff --git a/src/diff.test.ts b/src/diff.test.ts index a1db3e48a..3a35fdb92 100644 --- a/src/diff.test.ts +++ b/src/diff.test.ts @@ -607,10 +607,10 @@ describe('diff', () => { } as StyleSpecification, { projection: { - type: 'globe-to-mercator' + type: 'globe' } } as StyleSpecification)).toEqual([ - {command: 'setProjection', args: [{type: 'globe-to-mercator'}]}, + {command: 'setProjection', args: [{type: 'globe'}]}, ]); }); }); diff --git a/src/reference/v8.json b/src/reference/v8.json index 71129ca02..f983708fe 100644 --- a/src/reference/v8.json +++ b/src/reference/v8.json @@ -126,10 +126,55 @@ } }, "projection": { - "type": "projection", - "doc": "The projection configuration. **Note:** this definition is still experimental and is under development in maplibre-gl-js.", - "example": { - "type": "globe-to-mercator" + "type": { + "type": ["enum", "expression"], + "doc": "The projection type. Can be specified as a string, or as an expression for supported projection types.", + "default": "mercator", + "values": { + "mercator": { + "doc": "Web Mercator projection.", + "expression-compatible": true + }, + "globe": { + "doc": "Spherical projection.", + "expression-compatible": true + }, + "utm32": { + "doc": "Metric central europe.", + "expression-compatible": false + }, + "albers": { + "doc": "Albers equal-area conic projection.", + "expression-compatible": true + }, + "equalEarth": { + "doc": "Equal Earth projection.", + "expression-compatible": true + } + }, + "expression": { + "interpolated": true, + "parameters": ["zoom"], + "validate": "return value.expressionCompatible === true" + }, + "example": { + "simple": { + "projection": { + "type": "albers" + } + }, + "expression": { + "projection": { + "type": [ + "interpolate", + ["linear"], + ["zoom"], + 10, "globe", + 12, "mercator" + ] + } + } + } } }, "terrain": { @@ -4538,7 +4583,7 @@ ] }, "transition": true, - "doc": "How to blend the atmosphere. Where 1 is visible atmosphere and 0 is hidden. It is best to interpolate this expression when using globe-to-mercator projection." + "doc": "How to blend the atmosphere. Where 1 is visible atmosphere and 0 is hidden. It is best to interpolate this expression when using globe projection." } }, "terrain": { @@ -4579,9 +4624,6 @@ }, "globe": { "doc": "Spherical projection." - }, - "globe-to-mercator": { - "doc": "Spherical projection with zoom transition to Web Mercator projection." } } } diff --git a/src/validate/validate_projection.test.ts b/src/validate/validate_projection.test.ts index c872edf0f..a0c02f8a3 100644 --- a/src/validate/validate_projection.test.ts +++ b/src/validate/validate_projection.test.ts @@ -26,11 +26,11 @@ describe('Validate projection', () => { test('Should return errors according to spec violations', () => { const errors = validateProjection({validateSpec, value: {type: 1 as any}, styleSpec: v8, style: {} as any}); expect(errors).toHaveLength(1); - expect(errors[0].message).toBe('type: expected one of [mercator, globe, globe-to-mercator], 1 found'); + expect(errors[0].message).toBe('type: expected one of [mercator, globe], 1 found'); }); test('Should pass if everything is according to spec', () => { - let errors = validateProjection({validateSpec, value: {type: 'globe-to-mercator'}, styleSpec: v8, style: {} as any}); + let errors = validateProjection({validateSpec, value: {type: 'globe'}, styleSpec: v8, style: {} as any}); expect(errors).toHaveLength(0); errors = validateProjection({validateSpec, value: {type: 'mercator'}, styleSpec: v8, style: {} as any}); expect(errors).toHaveLength(0);