I have some problems for get and set properties in my features.

When I try get some property with


It not working. I have to look inside to the object and take the property like this:


But it is not a good way, because when I changed CDN to archives in my app, the object is different. And, obviously, feature.get('') must work.

Also, when I try to set new properties to some feature.

var feature = map.getLayers().item(1).getSource().getFeatureById(id);
feature.setGeometry(new ol.geom.Point( ol.proj.transform([lon, lat], 'EPSG:4326', 'EPSG:3857') ));

It not working either.

Maybe the two mistakes are connected. And I suspect that it is for Cluster. It is the function when I create the Layer.

  var vectorSource = new ol.source.Vector({
      features: iconFeatures //add an array of features

  var clusterSource = new ol.source.Cluster({
      source: vectorSource,
      distance: 40

  var vectorLayer = new ol.layer.Vector({
       // source : vectorSource,
      source: clusterSource,
      style: clusterStyle

    if (vector) {
     vector = vectorLayer;


Have you tried getting feature directly from the source:

var feature = vectorSource.getFeatureById(id);


var feature = clusterSource.getFeatureById(id);
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.