Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

179
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!