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

181
Vistas
information about diferents layers map.on method from features

How can I display all the properties of a feature using the map.forEachFeatureAtPixel method? I get a single value, I try to put a for loop to get all the properties, but it doesn't support it. I have this code that works to get a single value. Using forEachFeatureAtPixel allows me to choose the layer on which I want to display information. This is the code

map.on('click', function (evt) {
    document.getElementById("divInformation").innerHTML = '<h1>Click for Info</h1>';
    var layer;
    var feature = map.forEachFeatureAtPixel(evt.pixel,
      function(feature, featureLayer) {
        layer = featureLayer;
        return feature;
    });
    var el = document.getElementById('divInformation');
    el.innerHTML = '';
        if(layer === vectorLayer1){
            el.innerHTML +=  feature.get('cod');
            el.innerHTML += feature.get('date);
        }else if(layer === vectorLayer2){
            el.innerHTML += feature.get('name');
            el.innerHTML += feature.get('Percent');
         }else{
             el.innerHTML = '<h1>click for Info</h1>';
         }
});
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

To display all properties of a feature use JSON.stringify(feature.getProperties()) as in https://openlayers.org/en/latest/examples/vector-tile-info.html

For more control over formatting use a for ... in loop. You could then exclude internal property keys such as geometry which would not be meaningful when displayed.

var key;
var properties = feature.getProperties();
for (key in properties) {
  el.innerHTML +=  key + ': ' + properties[key];
}
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