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

289
Vistas
How to paint the result of a filter in MAPBOX a different color

I am working with the mapbox-gl-js library I have some filters of a dot layer but one of these filters would like to paint in another color. Is this possible? I already checked the documentation for mapbox-gl-js but I can't find anything concrete. Specifically, I would like to paint in another color when I filter the "Urbana" option.

This is how I have created my filter

document
                .getElementById("filters")
                .addEventListener("change", function (e) {
                  var zona = e.target.value;

                  map.setLayoutProperty('pnud', 'visibility', 'none' );
                  map.setLayoutProperty('cluster-count', 'visibility', 'none' );
                  map.setLayoutProperty('unclustered-point', 'visibility', 'none' );
                  map.setLayoutProperty('participacion_75', 'visibility', 'none' );
                  map.setLayoutProperty('filtros', 'visibility', 'visible' );

                  
                  
                  // update the map filter
                  if (zona === "all") {
                    filterZona = ["!=", ["string", ["get", "zona"]], "placeholder"];
                    
                  } else if (zona === "rural") {
                    filterZona = ["match", ["get", "zona"], ["Rural"], true, false];
                    
                  } else if (zona === "urbana") {
                    filterZona = ["match", ["get", "zona"], ["Urbana"], true, false];
                  } else {
                    console.log("error");
                  }
                  
                  map.setFilter(["filtros"], [
                    "all",
                    filterZona,
                    filterRegion,
                    filterComp,
                    filterCat1,
                  ]);
                });

And so I create the layer

map.addLayer({
                id: "filtros",
                type: "circle",
                source: 'sin_cluster',
                filter: ['has', 'point_count'],
                paint: {
                    'circle-color': '#03047D',
                    'circle-radius': 7
                  }
              });
over 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You can achieve that with circle-color which is a paint property.

In the example below, we're mapping colours to the ethnicity property from the geojson. Each ethnicity value gets the colour below it. Notice in the end their are 2 consecutive colours. The one directly under "Asian" belongs to the "Asian" category, while the last one simply specifies a colour for other ethnicities that may be present in the data.

'circle-color': [
'match',
['get', 'ethnicity'],
'White',
'#fbb03b',
'Black',
'#223b53',
'Hispanic',
'#e55e5e',
'Asian',
'#3bb2d0',
/* other */ '#ccc'
]

Find the documentation here.

In your example you'll be able to use ["get", "zona"] to specify a color for your Urbana's.

over 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
Asistente virtual