[GIS] OpenLayers: Modify features without virtual vertices

featuresopenlayers-2

When using the modify feature functionality of OpenLayers, I get the option to move the individual vertices around.

But I also get a set of virtual vertices – each vertex located on the edge between the original vertices. The virtual vertices allow me to kind of locally subdivide the existing polygon.

enter image description here

I can see that this feature is neat, but in many situations I don't want the user to be able to do local subdivision of the polygon – I want to maintain the original set of vertices while allowing the user to change the position of each of the vertices.

Is that possible with the existing OpenLayers controls?

Best Answer

The vertices are stored in two different properties of the ModifyFeature control - virtual vertices and vertices.

You could check which group the vertex belonged to in the dragVertex event, and if it is in the virtual vertex array then ignore it.

If you also set the virtualStyle of the control then these virtual vertices will be invisible.

Alternatively you could add an event handler for the selectFeature function and destroy the vertices with code similar to:

myControl.layer.removeFeatures(myControl.virtualVertices, {silent: true});
myControl.virtualVertices = [];

Ignoring drags on the virtual vertices, and hiding them from the user may be simpler to implement though.