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

386
Views
OpenLayers 6, Iterate through all features of a layer?

In OpenLayers 6...

I'm not familiar with the thing, but... How can I iterate through all features on my layer with the title "firmenGeoJSON" and hide or show some of them with specific property "name"?

Thank you...

let myLayers = map.getAllLayers();

myLayers.forEach(function(layer) {
    if (layer.getProperties()['title'] == 'firmenGeoJSON') {
        console.log('found and hide');
        //??????????
    };
});
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

To iterate through all features of a layer you need to get its source first:

layer.getSource().forEachFeature(function (feature) {
    console.log(feature);
});

Though if you want to show or hide features it may be better to do this in a layer style function:

import {Circle, Fill, Stroke, Style} from './style.js';

const style = new Style({
    image: new Circle({
        radius: 8,
        fill: new Fill({
            color: 'blue',
        }),
    }),
    stroke: new Stroke({
        width: 4,
        color: 'green',
    }),
});
layer.setStyle(function (feature, resolution) {
    if (feature.get('hidden')) {
        return undefined;
    }
    return style;
});

But note that a layer style function is only called if the Feature itself has no Style set. In that case consider switching to a layer style function, as seen above.

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!