Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

127
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda