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

README example for feature filter is no more working/valid with style-spec 10.0.x #5862

Closed
lamuertepeluda opened this issue Dec 14, 2017 · 2 comments

Comments

@lamuertepeluda
Copy link

The code from the readme of style-spec should now change from

var ff = require('feature-filter');

// will match a feature with class of street_limited,
// AND an admin_level less than or equal to 3,
// that's NOT a polygon.
var filter = [
    "all",
    ["==", "class", "street_limited"],
    ["<=", "admin_level", 3],
    ["!=", "$type", "Polygon"]
]

// will match a feature that has a class of
// wetland OR wetland_noveg.
// ["in", "class", "wetland", "wetland_noveg"]

// testFilter will be a function that returns a boolean
var testFilter = ff(filter);

// Layer feature that you're testing. Must have type
// and properties keys.
var feature = {
    type: 2,
    properties: {
       class: "street_limited"
       admin_level: 1
    }
};

// will return a boolean based on whether the feature matched the filter
return testFilter(feature);

to

var ff = require('feature-filter');

// will match a feature with class of street_limited,
// AND an admin_level less than or equal to 3,
// that's NOT a polygon.
var filter = [
    "all",
    ["==", "class", "street_limited"],
    ["<=", "admin_level", 3],
    ["!=", "$type", "Polygon"]
]

// will match a feature that has a class of
// wetland OR wetland_noveg.
// ["in", "class", "wetland", "wetland_noveg"]

// testFilter will be a function that returns a boolean
var testFilter = ff(filter);

// Layer feature that you're testing. Must have type
// and properties keys.
var feature = {
    type: 2,
    properties: {
-       class: "street_limited"
+       class: "street_limited", //WARNING: MISSING COMMA
       admin_level: 1
    }
};

// will return a boolean based on whether the feature matched the filter
-return testFilter(feature);
+return testFilter(null, feature); // <-- MAIN CHANGE HERE

The reason why last line is now wrong and would always return false is that a second, unused argument ('g') has been added to the generated filter at this line .

I'm sure there has to be a good reason for this 😄 but I'd like some explanation.

@lamuertepeluda
Copy link
Author

See also #5502 for usage within a browser

@jfirebaugh
Copy link
Contributor

Thanks for reporting. We added this parameter in order to support filter expressions that use the zoom expression operator.

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

No branches or pull requests

2 participants