0

我无法从地图中删除editingToolBar。我不明白为什么这段代码不起作用:

var 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"
});

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

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

感谢调试!

4

1 回答 1

0

最后,错误是editingToolBar变量未定义为全局变量,而是在函数内部,因此无法在stopEditing()函数中访问。

在全局中定义 var:

var editingToolBar;
于 2013-01-10T21:02:07.593 回答