1

I have a select interaction that is drawn in the map as a polygon while the map feauters was not loaded because of scale limit on the layer.

When I zoom in so that the features load, I want to apply a selection style on the newly loaded features that is inside the selection polygon.

I have a custom loader on the data layer, so I can get the selection interaction during the load. The problem is that I can't find any api to get the polygon geometry from the selection interaction. I do have the interaction object available.

How can I solve this?

1
  • How do you code to trigger selection?
    – Chase Choi
    Jun 7 '17 at 12:19
0

You can get the features from an OpenLayers select interaction using the getFeatures method. From there you can get the feature geometry. Here's an example:

var features = selectInteraction.getFeatures();
var polyFeature = features.item(0); // we suppose your feature is the first one
// from there, do what you want with your feature, i.e. get its geometry:
var geometry = polyFeature.getGeometry();
// or set a style
var style = new ol.style.Style({
    fill: new ol.style.Fill({
      color: 'rgba(255, 255, 255, 0.6)'
    })
);
polyFeature.setStyle(style);
1
  • The problem is that getFeatures is empty, because the features were not loaded in the map at the time the selection polygon was drawn. What I need to do is "re-run" the selection after the features has been loaded. If I can get hold of the polygon that defines the lasso of the selection, I can do this when the features load.
    – awe
    Jun 8 '17 at 12:37

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.