Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

128
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda