Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

126
Views
MapboxGL polygons are black colored if property missing

I am having issue with colors of the polygons. So i display polygones/areas in the map and i set for each color depending of their properties:

map.setPaintProperty("layerName", "fill-color", [
            "interpolate",
            ["linear"],
            ["get", key],
            range[0], colors[0],
            range[1], colors[1],
            range[2], colors[2],
        ]);

But some of these polygons just do not have the "key" property in them hence the map reads them like undefined/nullish and sets default color to them a pure black. I need to change this black color to something else but cant figure it out.

I tried to add default color after the ranges but it didnt work . Also tried if i could do it via styling/css but its a canvas so seems that this is not an option.

map.setPaintProperty("layerName", "fill-color", [
            "interpolate",
            ["linear"],
            ["get", key],
            range[0], colors[0],
            range[1], colors[1],
            range[2], colors[2],
          defaultColor
        ]);
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

This solution worked for me :

//This will put color of white for the missing property 
map.setPaintProperty(
                    'layerName',
                    'fill-color',
                    ["case", ["==", ["get", key], null], "#ffffff", [
                        "interpolate",
                        ["linear"],
                        ["get", key],
                        range[0], colors[0],
                        range[1], colors[1],
                        range[2], colors[2],
                    ]]
                );

This works also for opacity:

map.setPaintProperty(
            'layerName',
            'fill-opacity',
            ["case", ["==", ["get", key], null], 0.1, 0.7]
        );
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!