1

I use the following code to get WFS features on the map.

let WFSlayer = new ol.layer.Vector({
    title: layer,
    source: new ol.source.Vector({
        url: "/proxy/?layer_name=" + layer + "&bbox=" + [bbox[1], bbox[0], bbox[3], bbox[2]],
        format: new ol.format.GeoJSON(),
    }),
    style: new ol.style.Style({
        stroke: new ol.style.Stroke({
            color: 'rgba(243,20,20,0.3)',
            width: 15
        })
    }),
})

I want to access the properties of the loaded features. How should I do it?

This is what my GeoJSON looks like

features: [{type: "Feature", id: "", geometry: {type: "MultiLineString",…},…}]
0: {type: "Feature", id: "", geometry: {type: "MultiLineString",…},…}
geometry: {type: "MultiLineString",…}
geometry_name: "geom"
id: ""
properties: {rc_id: 530530, local_id: 0, dot_id: 6811526, mfips: "51001", geo_et: 0, geo_effdt: null,…}
add_ed: null
add_format: "A"
add_lf: 21321
add_lt: 21451
1

1 Answer 1

0

Figured it out.

WFSlayer.getSource().once('change', function (event) {
    let source = event.target
    if (source.getState() === 'ready') {
        source.getFeatures().forEach(feature=>{
            console.log(feature.getProperties())
        })
    }
});

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.