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

104
Vistas
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 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