I have a modify interaction enabled on a vector layer with multiple features. It work fine to move a feature to a new position. However if there are more features on the same coordinate, then all of then moved at the same time. See example on codepen.
var raster = new ol.layer.Tile({
source: new ol.source.OSM()
});
var data = new ol.Collection();
data.push(new ol.Feature({
geometry: new ol.geom.Point([0, 0])
}));
var f = new ol.Feature({
geometry: new ol.geom.Point([0, 0])
});
f.setStyle(new ol.style.Style({
image: new ol.style.Circle({
radius: 10,
fill: new ol.style.Fill({
color: [255, 255, 255, 0.5]
}),
zIndex: Infinity
}),
}));
data.push(f);
var vector = new ol.layer.Vector({
source: new ol.source.Vector({
features: data
})
});
var modify = new ol.interaction.Modify({
features: data
});
var map = new ol.Map({
interactions: ol.interaction.defaults().extend([modify]),
layers: [raster, vector],
target: 'map',
view: new ol.View({
center: [0, 0],
zoom: 12
})
});
Are there any way to avoid that? The only solutions I have found are:
- I have a select interation to select the feature
- Use translate interaction to move one of the features
or
- At pointer move event and detect if one or more features are at the coordinate and then select one of then
- Add the selected feature to modify feature layer and move it
Any other way?
Regrads RM