Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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", "http://vmap0.tiles.osgeo.org/wms/vmap0", {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);
    vectorLayer.addFeatures([polygonFeature]);
    map.addLayers([layer, vectorLayer]);
    map.zoomToExtent(vectorLayer.getDataExtent());
    modifyControl = new OpenLayers.Control.ModifyFeature(vectorLayer);
    map.addControls([modifyControl]);
    modifyControl.activate();    

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);
    selectFeature.select(vectorLayer.features[0]);
    selectFeature.activate();

Any ideas? Thanks!

share|improve this question
add comment

1 Answer 1

up vote 1 down vote accepted

You have two ways for that:

First: ModifyControls have their own SelectFeature control, you can use it:

modifyControl.selectControl.select(vectorLayer.features[0]);

Second way: You can use standalone mode and selectFeature() method: http://dev.openlayers.org/docs/files/OpenLayers/Control/ModifyFeature-js.html#OpenLayers.Control.ModifyFeature.selectFeature

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});
/ ... /

modifyControl.selectFeature(vectorLayer.features[0]);
share|improve this answer
    
Thank you! modifyControl.selectControl.select(vectorLayer.features[0]); does exactly what I want! –  Mark Dec 27 '12 at 15:54
add comment

Your Answer

 
discard

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.