Dominik
Dominik

Reputation: 121

OpenLayers can't get feature by key, undefined error

I am trying to get some key values from features in extent but I am unable to.

I tried to look up ID [feature.getId()] which works totally fine, see here:

enter image description here

If I try feature.get('id') it's undefined for some reason. (And it's undefined for every key I am trying to get by name)

I tried feature.getKeys() and it's returning geometry,info,index,popup.

I stored every info I need under info key.

I tried to get data in console and I can see that a point has 'id' key, and I am unable to get it with feature.get('id')

enter image description here

Does anyone know what am I doing wrong?

Upvotes: 1

Views: 743

Answers (1)

Dominik
Dominik

Reputation: 121

I had to access values with Object.values method.

Object.values(Object.values(feature.get("info"))[0][2])[1]

Upvotes: 1

Related Questions