OpenLayers Feature – How to Get Feature by ID in OpenLayers

javascriptopenlayers

I have a VectorLayer layer with a feature collection in GeoJSON. The GeoJSON format is as following:

{
    "type": "FeatureCollection",
    "totalFeatures": "unknown",
    "features": [
        {
            "type": "Feature",
            "id": "ES.RRTN.CP.1010001",
            "geometry": {
                "type": "MultiPolygon",
                "coordinates": [
                    [
                        [
                            [
                                570389.865,
                                4722149.567
                            ],
                            [
                                570391.945,
                                4722149.769
                            ],
                            [
                                570394.939,
                                4722150.04
                            ],
                            [
                                570395.084,
                                4722144.205
                            ]
                        ]
                    ]
                ]
            },
            "properties": {
                "validTo": {
                    "simpleContent": null
                },
                "validFrom": {
                    "simpleContent": null
                },
                "inspireId": {
                    "Identifier": {
                        "localId": "1010001",
                        "namespace": "ES.RRTN.CP"
                    }
                },
                "label": "1",
                "nationalCadastralReference": "1010001",
                "areaValue": 101.2779,
                "beginLifespanVersion": {
                    "simpleContent": null
                }
            }
        }
    ]
 }

I know the feature id=1010001, so I can identify a feature by its id, localid and nationalCadastralReference.

Is there a way to get the Feature object from the
VectorLayer/VectorSource/Map with one of this parameters?

Best Answer

The solution given in the comments finally was:

source.getFeatureById('ES.RRTN.CP.1010001')

Related Question