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

Getting error on interpolation function #5737

Closed
yoursweater opened this issue Nov 21, 2017 · 4 comments
Closed

Getting error on interpolation function #5737

yoursweater opened this issue Nov 21, 2017 · 4 comments

Comments

@yoursweater
Copy link

I'm trying to change the fill-color of my layer based on two properties, and I'm getting an odd error:

Error: layers.fullcitylayer.paint.fill-color: color expected, array found

The Documentation is very clear that interpolation expressions can validly be used in place of a color.

Here's the code I'm attempting to enter in:

map.setPaintProperty('fullcitylayer', 'fill-color', ['interpolate',['linear'],['/', ['get', 'B19001_017'], ['/', ['get', 'ALAND'], 1000000]],10,'#00adef',100,'#212529',1000,'#ea950b',5000,'#e94e34'] )

Is this just a bug?

@jfirebaugh
Copy link
Contributor

Hi @yoursweater. I'm not able to reproduce that error running that code. Could you provide a self-contained JSFiddle that demonstrates the issue?

@yoursweater
Copy link
Author

This is embarrassing, but for some reason I'm having difficulty getting that set up as well. I can add a layer or load in a map without any difficulty locally, but my jsfiddle is refusing to work. Even using someone else's map, just doing this causes the map to fail to load:

    map.addLayer({
        "id": "pop-data",
        "type": "fill",
        "source": {
            type: 'vector',
            url: 'mapbox://yoursweater.6h1mo1cs'
        },
        "source-layer": "fullCityLayer",
        "paint": {
            "fill-color": "#ff69b4"
        }
    });

@anandthakker
Copy link
Contributor

Thanks @yoursweater. I was able to reproduce this issue locally using the expression you provided in the original post. It looks like the issue is that, for one of the features, ALAND is 0, and we're failing to handle the resulting NaN properly. I'll retitle this issue to reflect that bug.

Meanwhile, a temporary workaround would be to replace ["get", "ALAND"] with ["max", ["get", "ALAND"], 1] (or some other suitable placeholder value besides 1)

@anandthakker
Copy link
Contributor

Actually looks like we have an issue for this for functions already -- let's use that to track.

Duplicate of #4172

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

No branches or pull requests

3 participants