3

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

When I try get some property with

feature.get('property') 

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

feature["O"]["features"]["0"]["O"]["carrier"]

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) {
      map.removeLayer(vector);
     }
     vector = vectorLayer;


      map.addLayer(vectorLayer);
1

Have you tried getting feature directly from the source:

var feature = vectorSource.getFeatureById(id);

or

var feature = clusterSource.getFeatureById(id);

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.