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

114
Visualizações
How can I get a VectorGrid layer colored based on property?

I'm trying to style a VectorGrid Layer using a property from the pbf layer. I want to assing the color using a function "getColors" that uses the data on the field "gridcode".

The code runs and draws the layer but uses the default blue color of the server. The layer is served with pg_tileserv and PostgreSQL + PostGIS, the gridcode field is populated with data -1, 0, 1 and 2.

Here is my code:

const vectorLayerTendFull = "public.hum_tendencies_full";
const vectorUrlFull = vectorServer + vectorLayerTendFull + "/{z}/{x}/{y}.pbf";
console.log("Reading tiles from " + vectorUrlFull);
let vectorTileStyling2 = {};
vectorTileStyling[vectorLayerTendFull] = {
    gridcode: function(properties) {
        const val = properties.gridcode;
        return {
            radius: 1,
            weight: 1,
            fillOpacity: 1,
            fill: true,
            fillColor: getColors(val)
        }

        function getColors(val) {
            return val > 1 ? '#89AFD5' :
                val > 0 ? '#267300' :
                val > -1 ? '#FFFF00' :
                val < 0 ? '#A80000' :
                'rgba(0,0,0,0)';
        }
    }
};
let vectorTileOptions2 = {
    "rendererFactory": L.canvas.tile,
    "vectorTileLayerStyles": vectorTileStyling2
};
const vectorLayer2 = L.vectorGrid.protobuf(vectorUrlFull, vectorTileOptions2).addTo(map);

I fixed the function getColors as suggested by nikoshr, but still no styling with gridcode property

VectorGrid Layer drawn but not with the style based on the "gridcode":

Picture

about 4 years ago · Juan Pablo Isaza
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