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

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

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 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
Assistente virtual