Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'd like to create a map displaying a feature ready to modify. The map should already be selected and show the draggable vertices when you load the page (without needing to click on the feature first).

With this code, you first need to click the feature before you can edit:

    layer = new OpenLayers.Layer.WMS( "OpenLayers WMS", "", {layers: 'basic'} );
    vectorLayer = new OpenLayers.Layer.Vector("Foo");
    map = new OpenLayers.Map('map');
    var wkt = "POLYGON((0 1, -1 0, 1 0))";
    var polygonFeature = new OpenLayers.Format.WKT().read(wkt);
    map.addLayers([layer, vectorLayer]);
    modifyControl = new OpenLayers.Control.ModifyFeature(vectorLayer);

I already tried OpenLayers.Control.SelectFeature. It selects the feature (blue line) but it doesn't show the draggable vertices:

    selectFeature = new OpenLayers.Control.SelectFeature(vectorLayer);[0]);

Any ideas? Thanks!

share|improve this question
up vote 2 down vote accepted

You have two ways for that:

First: ModifyControls have their own SelectFeature control, you can use it:[0]);

Second way: You can use standalone mode and selectFeature() method:

But you can't unselect and select features with mouse in standalone mode (you can do it only with code), so I'm not sure, whether it's suitable for your needs.

modifyControl = new OpenLayers.Control.ModifyFeature(vectorLayer, {standalone: true});
/ ... /

share|improve this answer
Thank you![0]); does exactly what I want! – Mark Dec 27 '12 at 15:54

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.