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

Update example styles to use Mapbox Expressions rather than older Mapbox Filters #1041

Open
ANHPearce opened this issue Mar 5, 2021 · 3 comments
Labels

Comments

@ANHPearce
Copy link

mapbox-gl-js version: v2.0.0
mapbox-gl-draw version: v1.2.0

Steps to Trigger Behavior

  1. Using any of your examples styles from Examples.md that include references to properties by name rather than using the "get" expression, or those that use "$type", "!has", etc (full list of old Filters here, scroll to Filters section) with a mixture of the new Expression Syntax.

Expected Behavior

I would expect examples found in Examples.md to work with up to date Mapbox best practices which is to use the Expression syntax rather than the older Filter syntax.

In the very least it would be helpful to user of the library to call out the fact that the older Style Filter syntax is being show/used in the library material and not the updated Expression language.

Actual Behavior

The becomes very confusing when you are trying to make sense of special operators like $type which have little documentation. Error given by the Mapbox and Draw do little to clue you into the fact that the Mapbox style interpreter are failing to use Expression syntax alongside the older Filter syntax.

Old Filter Syntax
['all',
['==', 'user_prop', 'myVal'],
['==', '$type', 'Point'],
]

Example Bad Filter using mix of Expression/Filter syntax, non obvious issue
['all',
['==', ['get', 'user_prop'], 'myVal'],
['==', '$type', 'Point'],
]

Corrected Expression Syntax
['all',
['==', ['get, , 'user_prop'], 'myVal'],
['==', ['geometry-type'], 'Point'],
]

Errors Given on failure
"layers.polygon-fill-inactive.hot.filter[3][1]: string expected, array found" -- this gets buried quickly do to the next error throwing repeatedly.

"The layer 'polygon-fill-inactive-noncommissioned.cold' does not exist in the map's style and cannot be queried for features."

@rctngle
Copy link

rctngle commented Apr 9, 2021

I'm also a bit confused by the use of filters in styles. If you wish to style a feature based on a Feature property, should you create 2 styles, and use the filter to distinguish – or an expression in the style itself (see below – which doesn't actually work)

	"fill-color": [
		"case",
		["==", ["get", "currentUserCreated"], true],
		"#ff0000",
		"#3758e8"
	],	
	"fill-opacity": 0.4	

@oodavid
Copy link
Contributor

oodavid commented Oct 28, 2021

@SnailBones SnailBones added the docs label Nov 8, 2021
@jaybo
Copy link

jaybo commented Feb 12, 2024

Can someone please explain whether Expression syntax is even supposed to work in filters: with Draw v1.4.3?
For example, this filter works fine:

filter: [
    "all",
    ["==", "meta", "vertex"],
    ["==", "$type", "Point"],  # this line
    ["!=", "mode", "static"],
    ["==", "active", "true"],
],

But this one doesn't even compile:

filter: [
    "all",
    ["==", "meta", "vertex"],
    ["==", ["geometry-type"], "Point"], # this line
    ["!=", "mode", "static"],
    ["==", "active", "true"],
],

producing the error:

message: 'layers.gl-draw-polygon-and-line-vertex-snip-…t.filter[2][1]: string expected, array found'}

I am just so confused! I guessing Expressions are not fully functional and this is why I'm experiencing a whole raft of issues like: #1126

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants