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?


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.

  • Even though I set a transparent virtualStyle I'll still get the move cursor when hovering a virtual vertex - right? I don't get though, why they haven't included a boolean useVirtualVertices. I could add it my self, but I would have to maintain it when upgrading OpenLayers. – Chau Mar 8 '11 at 10:05
  • You could always extend the control to add this functionality so you would not have to worry (or worry less) about upgrades. Did you try the cursor property of the virtualStyle? – geographika Mar 8 '11 at 10:40
  • I haven't tried the cursor property. I am still at the planning phase and just wanted to hear if the answer to my question is yes or if I need to take another route. – Chau Mar 8 '11 at 11:54
  • Obviously, the answer is yes. Geographika gave you already many informations to prove/do it. – simo Mar 9 '11 at 8:25

Just set createVertices on your ModifyFeature control to false.


    var modifyControl = new OpenLayers.Control.ModifyFeature(vectorLayer);
    modifyControl.createVertices = false;

Here is a live demo.

  • I seems like it is supported now, it wasn't more than two years ago when I posted the question :) Thanks for informing us! – Chau Dec 2 '13 at 10:36

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.