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 am trying to modify an already selected vector (feature) in Open Layers. In my map i have implemented "select on click" functionality, so what i would like to achive is to have a "Modify" button which will actually activate ModifyFeature control for the selected feature. Here is my code:

function initialiseMap(){
    ...
    map = new OpenLayers.Map(imageEditorID, options);

    imageLayer = new OpenLayers.Layer.TMS(imgURL, "", {
        url : '',
        serviceVersion : '.',
        layername : '.',
        alpha : true,
        type : 'png',
        getURL : overlay_getTileURL,
        transitionEffect: 'resize'
    });

    map.addLayer(imageLayer);
    var vlayer = new OpenLayers.Layer.Vector("Editable");
    map.addLayer(vlayer);
    ...
    // **** CREATE PANEL AND CONTROLS ***
    var panel = new OpenLayers.Control.Panel({ ....
    //control for DRAW REGULAR POLYGON button
    var drawRegularPolygonControl = new OpenLayers.Control.DrawFeatureOpt(vlayer, OpenLayers.Handler.RegularPolygon,
            {title:'Draw a regular polygon', text: '','displayClass':'olControlDrawFeatureRegularPolygon'});        
    ... 
    //control for MODIFY button
    var modifyFeatureControl = new OpenLayers.Control.ModifyFeature(vlayer, {
        clickout: true,
        toggle: false,
        deleteCodes: [46, 68, 27],
        title: 'Modify', text: '',
        displayClass: "olControlModify"
    });
    ...
    //register events for draw regular polygon
    drawRegularPolygonControl.events.register("featureadded", this, function(e) {
    drawRegularPolygonControl.selectFeature(e.feature);
    drawRegularPolygonControl.selectControl.select(e.feature);
    drawRegularPolygonControl.activate();
    drawRegularPolygonControl.deactivate();
    });
    ...
    //  select on click
    ctrlSelectFeatures = new OpenLayers.Control.SelectFeature(
        vlayer,
         {
             clickout: true, toggle: false,
             multiple: false, hover: false,
             toggleKey: "ctrlKey", // ctrl key removes from selection
             multipleKey: "shiftKey" // shift key adds to selection
         }
    )

    map.addControl(ctrlSelectFeatures);
    ctrlSelectFeatures.activate();

    vlayer.events.register('featureselected',   vlayer, regFeatureSelected);
    vlayer.events.register('featureunselected', vlayer, regFeatureUnselected);
    ...
    panel.addControls([...
    ...
    map.addControls([panel, modifyFeatureControl]);
    map.addControl(panel);
    ...

The two functions regFeatureSelected, regFeatureUnselected simply show/hide a popup if certain conditions are met:

function regFeatureSelected()
 {
     aktPopup = create_Popup();
     var objF = this.selectedFeatures[0];
     var desc   = objF.attributes['description'] ? objF.attributes['description'] : "about:blank";
     document.getElementById("featDesc").innerHTML = objF.attributes.name + ", " + objF.attributes.description;
 }

 function regFeatureUnselected()
 {
     if(aktPopup)
         map.removePopup(aktPopup.popup);

     document.getElementById("featDesc").innerHTML = "selected feature description";
 }

Can somebody guide me on how to have the modifyFeatureControl get working?

If i do not use:

vlayer.events.register('featureselected',   vlayer, regFeatureSelected);
vlayer.events.register('featureunselected', vlayer, regFeatureUnselected);

the modify control seem to work.

I am really new on Jscript/Open layers so any advice could be really useful...

share|improve this question
add comment

Your Answer

 
discard

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

Browse other questions tagged or ask your own question.