Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add projection expression syntax (#888) #899

Merged
merged 14 commits into from
Nov 17, 2024

Conversation

birkskyum
Copy link
Member

@birkskyum birkskyum commented Nov 13, 2024

This is a merging branch for

Docs here
https://maplibre.org/maplibre-style-spec/projection/
https://maplibre.org/maplibre-style-spec/types/#projectiondefinition

Launch Checklist

  • Confirm your changes do not include backports from Mapbox projects (unless with compliant license) - if you are not sure about this, please ask!
  • Briefly describe the changes in this PR.
  • Link to related issues.
  • Include before/after visuals or gifs if this PR includes visual changes.
  • Write tests for all new functionality.
  • Document any changes to public APIs.
  • Post benchmark scores.
  • Add an entry to CHANGELOG.md under the ## main section.

@codecov-commenter
Copy link

codecov-commenter commented Nov 13, 2024

Codecov Report

Attention: Patch coverage is 94.28571% with 4 lines in your changes missing coverage. Please review.

Project coverage is 92.78%. Comparing base (f91416f) to head (2eeba43).
Report is 23 commits behind head on main.

Files with missing lines Patch % Lines
src/expression/index.ts 66.66% 2 Missing ⚠️
src/expression/types/projection_definition.ts 94.11% 1 Missing ⚠️
src/expression/values.ts 83.33% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main     #899   +/-   ##
=======================================
  Coverage   92.77%   92.78%           
=======================================
  Files         105      107    +2     
  Lines        4678     4739   +61     
  Branches     1323     1346   +23     
=======================================
+ Hits         4340     4397   +57     
- Misses        338      342    +4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@HarelM
Copy link
Collaborator

HarelM commented Nov 13, 2024

See my additions here:

@birkskyum
Copy link
Member Author

birkskyum commented Nov 13, 2024

It's probably OK for the projection to have it's own type, but I am wondering a bit if it's too close to the StringType - the projection interpolation... it has, after removing the from: ProjectionPrimitive evolved into a generic string interpolation, or even an any transition catch-all, for whenever it's not possible to make an intermediate value, and the only option is to pass through the from, to and transition as an array like we do:

function number(from: number, to: number, t: number): number {
    return from + t * (to - from);
}

function projection(from: string, to: string, interpolation: number): Projection {
    return new Projection(from, to, interpolation);
}

function color(from: Color, to: Color, t: number, spaceKey: InterpolationColorSpace = 'rgb'): Color {
    switch (spaceKey) {

We could in principle have a fallback

function anyInterpolation<T,U>(from: T, to: U, t: number): [T, U, number]: AnyInterpolation {}

And for Projection, where we know the type

function string(from: string, to: string, t: number): StringInterpolate {}

@birkskyum
Copy link
Member Author

birkskyum commented Nov 13, 2024

The only problem I really have before merging this is that the interpolate-projection ran in GL JS, but the same expression now with interpolate is breaking... so i'm debugging

@HarelM
Copy link
Collaborator

HarelM commented Nov 13, 2024

Ok, if you need anything let me know.
The only thing I have left to consider in this PR is the following comment:
#888 (comment)

in proj4js they use the term ProjectionDefinition for the values related to the projection:
https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/proj4/index.d.ts

So the question is if to rename Projection to ProjectionDefinition and rename ProjectionConfigSpecifications to ProjectionSpecifications.
I'm not sure what I think about this... Let me know what you think...

@birkskyum
Copy link
Member Author

Wrt. Projection -> ProjectionDefinition

I think that's a great idea - will get to it. "Projection" is overloaded by the class in geo/projection.

src/reference/v8.json Outdated Show resolved Hide resolved
src/util/interpolate.ts Outdated Show resolved Hide resolved
src/util/projection.ts Outdated Show resolved Hide resolved
src/util/projection.ts Outdated Show resolved Hide resolved
src/util/interpolate.ts Outdated Show resolved Hide resolved
@birkskyum
Copy link
Member Author

birkskyum commented Nov 13, 2024

Screenshot 2024-11-14 at 00 15 23

it's working again

@birkskyum
Copy link
Member Author

birkskyum commented Nov 14, 2024

I'm not sure if theres anything left

We could technically replace projectionDefinition type, with an expression compatible string-type. This can be done under the hood later anyway, affecting users just through a change to the url of the relevant documentation page section. Also, i'd prefer to introduce such big change separately, because a new string expression support, could affect all the existing string values. If we land it at some point we can just move projectionDefinition -> "string" / "expressionString". Haven't really thought it to completion, just have intuition there's a win-win kind of thing to get here, by both simplifying the code and bringing generic interpolation support for strings with same api as we have now for projections.

@birkskyum
Copy link
Member Author

birkskyum commented Nov 14, 2024

Maybe the array values in step could make sense to add

src/index.ts Outdated Show resolved Hide resolved
src/util/projection.ts Outdated Show resolved Hide resolved
src/util/projection.ts Outdated Show resolved Hide resolved
src/util/interpolate.ts Outdated Show resolved Hide resolved
@HarelM
Copy link
Collaborator

HarelM commented Nov 15, 2024

I'm working to move the types to the right place in the folder structure, to make things a bit more organized. Just FYI...

@birkskyum
Copy link
Member Author

I'm working to move the types to the right place in the folder structure, to make things a bit more organized. Just FYI...

Thanks, that does sounds great. Are you working on it in a separate cleanup PR, or on this branch?

@birkskyum
Copy link
Member Author

Update:
I'm half-ways through refactoring to named exports, in separate PR. I find it'll be faster to work when that's in order, because we rename a lot (Projection -> ProjectDefinition etc.), and a named export will auto-propagate these change to the import statements and keep things consistent, where a default export does no such thing, so typecheck can't help.

Will wrap that up and get back to this

@HarelM
Copy link
Collaborator

HarelM commented Nov 16, 2024

I had the same observation lately when working with the code, this is needed indeed. Thanks!

@birkskyum birkskyum force-pushed the projection-expression-collecting-branch branch from 64f5c8c to 76bfcf0 Compare November 16, 2024 19:49
src/expression/values.ts Outdated Show resolved Hide resolved
src/index.ts Outdated Show resolved Hide resolved
@HarelM
Copy link
Collaborator

HarelM commented Nov 16, 2024

I've fixed the tests and addressed the comments I found when reviewing.
Feel free to review this.
I think this is ready to be merged.
Let me know if you are able to use it in maplibre-gl-js.
Note that I have removed the serialization to array of projectionDefinition as I'm not sure where this is needed.
I do see that color does get serialized to array somehow (saw it in test/integration/expression/tests/interpolate-hcl/linear/test.json test), but I couldn't figure out where it happens.

@birkskyum birkskyum force-pushed the projection-expression-collecting-branch branch from 537eb32 to 2eeba43 Compare November 17, 2024 11:22
@birkskyum
Copy link
Member Author

birkskyum commented Nov 17, 2024

It's running fine in GL JS, with this syntax now

const exprestInt = createExpression(['interpolate', ['linear'], ['zoom'], 10, 'vertical-perspective', 12, 'mercator'], v8.projection.type)
Screen.Recording.2024-11-17.at.12.26.22.mov

I believe it's ready to go - I can't approve it, since I opened the PR.

Copy link
Collaborator

@HarelM HarelM left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great!

@birkskyum birkskyum merged commit c5f8f8d into main Nov 17, 2024
6 checks passed
@birkskyum birkskyum deleted the projection-expression-collecting-branch branch November 17, 2024 11:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants