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

Unimplemented distance expression #2077

Closed
cyrilchapon opened this issue Jan 20, 2023 · 8 comments · Fixed by #4076
Closed

Unimplemented distance expression #2077

cyrilchapon opened this issue Jan 20, 2023 · 8 comments · Fixed by #4076
Labels
enhancement New feature or request PR is more than welcomed Extra attention is needed

Comments

@cyrilchapon
Copy link

cyrilchapon commented Jan 20, 2023

Context

I'm trying to color my symbols based on their distance from a point on a map (a marker of my own).
I landed on the documented distance expression and naively tried to replace my icon-color with it.

maplibre-gl-js version: 2.4.0

browser: Chrome 108.0.5359.124

Steps to Trigger Behavior

  1. Use the expression as below
[
   'interpolate', ['linear'],
   [
     'distance',
     {
       type: 'Feature',
       geometry: {
         type: 'Point',
         coordinates: [2, 40]
       }
     },
   ],
   100, '#E02F58',
   10000, '#000000',
 ]
  1. Read the console

Link to Demonstration

PoC, working symbol with static color : https://jsfiddle.net/cpn1dkv8/
Not working symbol with distance based-color https://jsfiddle.net/cpn1dkv8/1/

Expected Behavior

Since it's documented, I'd expect it to work like so.

Actual Behavior

It's generating an error :

Error: layers.[my-layer].icon-color[2][0]: Unknown expression "distance". If you wanted a literal array, use ["literal", [...]].

Addendum

For what it's worth, the original mapbox-gl implementation seems to be blocked in a draft PR here (and the feature is also documented in mapbox docs too).

@HarelM
Copy link
Collaborator

HarelM commented Jan 20, 2023

It might be that this is not fully supported as you said about the draft PR, I'm not sure.
I would start with a simpler example for the distance and see if that works. I know icon-color can use the priorities from a feature (using [get, ...]) but I'm not sure about distance and the combination of these two.

@wipfli
Copy link
Contributor

wipfli commented Jan 20, 2023

Distance is the only expression that is only implemented in MapLibre GL Native and not in MapLibre GL JS, see the supported SDKs table in https://maplibre.org/maplibre-gl-js-docs/style-spec/expressions/#distance

@cyrilchapon
Copy link
Author

Thanks @wipfli for pointing this, I'm so stupid !


Ok so I think this features's state is inherited from mapbox-gl before the fork. I dugg into the draft PR a little bit; and apparently the feature is developed, but the bundle size bump involved is considered too high to allow a merge as-is. The feature has been marked as "postponed" in that sense.

"Bundle size bump too big" + "already implemented" sounds like a perfect fit for a plugin, in my mind. Doesn't it ?

@cyrilchapon cyrilchapon changed the title Unknown expression "distance" Unimplemented distance expression Jan 20, 2023
@HarelM
Copy link
Collaborator

HarelM commented Jan 20, 2023

Yes, plugin is the right solution for bundle size issues.
I'm not sure how easy it will be to add an expression as a plugin, but if you manage to do it, or even create a PR that will allow to add expression as plugins it can open a world of opportunities.

@HarelM HarelM added enhancement New feature or request PR is more than welcomed Extra attention is needed labels Jan 20, 2023
@cyrilchapon
Copy link
Author

Hey @HarelM ,

I'm not sure how easy it will be to add an expression as a plugin
That was my thought. I never encountered such a plugin, so I guess it wouldn't be that easy.

or even create a PR that will allow to add expression as plugins it can open a world of opportunities.
Indeed. That would be so much valuable.

I'm afraid I'm not familiar enough with the codebase, the cartography world and don't have enough time to give it a shot. Though I surely can help and start by documenting and researching a little bit.

Probably related :

@DevelWolf
Copy link

DevelWolf commented Mar 21, 2023

I'm not sure how easy it will be to add an expression as a plugin, but if you manage to do it, or even create a PR that will allow to add expression as plugins it can open a world of opportunities.

Answer moved to #1295 (comment)

@HarelM
Copy link
Collaborator

HarelM commented May 2, 2024

I've done an initial implementation of distance, full polygon support is still missing, but it's getting there...
maplibre/maplibre-style-spec#642

@HarelM
Copy link
Collaborator

HarelM commented May 4, 2024

This will probably get released in the next version within a few days.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request PR is more than welcomed Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants