Search code examples
openlayers-5

Get the Feature id openlayers5


In OL2 feature id's were generated internally. In OL5 this doesn't seem to be the case since the id's are undefined. Has the internal feature id been removed from OL5? If not what do I need to do to get the id's generated. I am requesting the id via:

feature.getId()


Solution

  • openlayers 5 doesn't generate the feature ID.

    You have to set the feature's ID (if necessary) when creating it. Use the setId method. Now by calling feature.getId() you will get the feature id.

    It must be taken into account that in the same source of the map the id must be unique.