1

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.

0

2 Answers 2

2

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.

1
  • That's exactly what I needed. Many thanks @Tom modify_control.activate(); modify_control.selectFeature(vectors.features[0]); Dec 9, 2014 at 11:24
0

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})
iconFeature.set('automodify',true);

$(map.Map.getViewport()).on('mouseup',function(e){
    var feature = map.forEachFeatureAtPixel([e.pageX,e.pageY],function(feature,layer){return feature;});
    if(feature){
        if(feature.get('automodify')){
            handleTheFeatureClick(feature);
        }
    }
});
function handleTheFeatureClick(feature){
    var modify = new ol.interaction.Modify({
        features: new ol.Collection([feature])
    });
    map.addInteraction(modify);
}
1
  • 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] Oct 28, 2014 at 17:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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