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 have a startEditing() function:

function startEditing(){

       colorPoly = document.getElementById('color_picker_'+shapeId).value;

        var shapeStyle = {
            strokeOpacity: 1,
            strokeWidth: 1,
            fillColor: colorPoly,
            fillOpacity: 0.45,
        }

        var shapeStyle2 = {
            strokeOpacity: 1,
            strokeWidth: 1,
            fillColor: colorPoly,
            fillOpacity: 0.45,
            pointRadius: 5,
        }

        var styleMap = new OpenLayers.StyleMap({
            "default": shapeStyle,
            "temporary": shapeStyle,
            "select": shapeStyle,
            "vertex": shapeStyle2
        }, {extendDefault: false});

            var newShape = new OpenLayers.Layer.Vector( "Editable",{
                styleMap: styleMap
            });

            newShape.events.register("sketchcomplete", newShape, function(){
                map.addLayer(newShape);
                newShape.id = shapeId;
                createdShapes.push(newShape);
                alert(createdShapes.length)
            });

            editingToolBar = new OpenLayers.Control.Panel({
                displayClass: 'customEditingToolbar',
                allowDepress: true
            });

            var draw = new OpenLayers.Control.DrawFeature(
            newShape, OpenLayers.Handler.Polygon,
            {
                title: "Draw Feature",
                displayClass: "olControlDrawFeaturePolygon",
                multi: true
            });

            var edit = new OpenLayers.Control.ModifyFeature(newShape,
            {
                title: "Modify Feature",
                displayClass: "olControlModifyFeature",
                vertexRenderIntent: "vertex"
            });

            editingToolBar.addControls([edit, draw]);
            map.addControl(editingToolBar);
}

and I have a stopEditing() function:

function stopEditing(){
    map.removeControl(editingToolBar);
}

When I call stopEditing(), the EditingToolBar disappears from the map. However, the cursor can still draw new features. map.removeControl(editingToolBar); doesn't stop the control, it just makes the icon disappear. How to disable the editingToolBar controls and bring back the default pan cursor?

More, when I call startEditing() a second time after stopEditing(), the editingToolBar does not appear but the cursor can still draw.

share|improve this question

1 Answer 1

up vote 2 down vote accepted

All you need is deactivate method of your panel:

function initControls(){
    // init your controls here
    // deactivated by default
}

function stopEditing(){
    editingToolBar.deactivate();
}

function startEditing(){
    editingToolBar.activate();
}
share|improve this answer

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.