Does anyone know how to programmatically simulate a vector feature click that puts this feature from normal mode:

enter image description here

to modifyfeature mode:

enter image description here

I only have one feature inside the vectors layers and i have a edit button. I have everything working and i'm just trying to save one unnecessary feature click.


Use the ModifyFeature control. Add your layer to the control, add the control to the map, activate the control and then call selectFeature() on the control and pass it your feature. The API makes it sound like you have to be in standalone mode but it works for me without being in standalone mode. I'm using OL 2.13.1.

| improve this answer | |
  • That's exactly what I needed. Many thanks @Tom modify_control.activate(); modify_control.selectFeature(vectors.features[0]); – Miguel Ângelo Belém Dec 9 '14 at 11:24

I assume you're asking about Open Layers 3?

I use Jquery (or straight js) and setup a mouse event on the viewport. This will let you identify what feature is clicked. I also add a custom attribute to the feature to identify if its polygon,icon,etc.

var iconFeature = new ol.Feature({YOUR FEATURE PROPERTIES})

    var feature = map.forEachFeatureAtPixel([e.pageX,e.pageY],function(feature,layer){return feature;});
function handleTheFeatureClick(feature){
    var modify = new ol.interaction.Modify({
        features: new ol.Collection([feature])
| improve this answer | |
  • I'm still using Openlayers 2 so it's different. Anyone knows how to programmatically click a feature? Please? The feature i can identify easily, it's always vectors.features[0] – Miguel Ângelo Belém Oct 28 '14 at 17:08

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.