Reputation: 123
Let's say I have two groups of features with different properties on a single map: features A and features B. I'm setting up a single interaction for both feature types because there can be only one.
If I select one A feature, then one B feature, the A feature is removed from the featureCollection. How can I have them both selected at the same time ? I also want to have at most one feature of each type selected.
Example use case:
Click on A1 --> add A1
Click on A2 --> remove A1 and add A2
Click on B1 --> add B1
Click elsewhere on map -->remove A2 and B1
Upvotes: 0
Views: 136
Reputation: 512
I would suggest instead of the select interaction, just creating your own featureOverlay
and adding the features as needed.
var overlay = new ol.featureOverlay({
style: selectedStyle
});
map.on('click', function (event) {
var feature = map.forEachFeatureAtPixel(event.pixel, function (f) { return f;});
// handle the add/remove logic here
if (feature.get('group') === 'A') {
overlay.addFeature(feature);
}
// etc...
});
Upvotes: 0