Feature ID's in OpenLayers 3 are undefined
Asked Answered
K

1

5

In OL2 feature id's were generated internally. In OL3 this doesn't seem to be the case since the id's are undefined. I have tried with WKT, JSON, and KML sources and none of them have id's assigned to features. Has the internal feature id been removed from OL3? If not what do I need to do to get the id's generated. I am requesting the id via:

feature.getId();

This is real problem for drag and drop since I don't have control over the files.

Cheers

Kurtiskurtosis answered 31/12, 2015 at 13:52 Comment(1)
I'm facing exactly the very same problem, like you, but I have not found a solution yet. So, I'm interested to know, whether you managed to solve it or not.Sinfonia
C
9

No, OL3 does not generate any feature IDs.

When reading features, each Format may set the feature ID if it is defined according to the semantics of the format. For GeoJSON, it's the "id" member of the feature (not a property).

When creating new features, it's the responsibility of the application to set the features ID if necessary. Use the setId method of the feature. If using the Draw interaction, it's drawend event might be useful.

You should also note these facts about feature IDs in OL3:

No features with duplicate IDs may be in the same source. If you add a feature to a source where a feature with an equal ID exists, the new feature is ignored.

Feature IDs are compared as strings, so 1234 and "1234" are considered equal.

IDs are included when serializing features according to each Format's specification for feature identifiers.

Chimkent answered 3/1, 2016 at 12:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.