Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Feature ID's in OpenLayers 3 are undefined

Tags:

openlayers-3

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

like image 305
MoreScratch Avatar asked Dec 31 '15 13:12

MoreScratch


1 Answers

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.

like image 59
Alvin Lindstam Avatar answered Jan 01 '23 01:01

Alvin Lindstam