OpenLayers更改控件上的层

OpenLayers更改控件上的层,openlayers,Openlayers,我想更改OpenLayers.Control.ModifyFeature控件的图层 我尝试完全移除控制器,然后基于新层添加另一个控制器。 我通过使用如下循环直接更改了ModifyFeature的图层属性: for(var i = 0; i <= 10; i++) { if(document.getElementById('verksamhet').selectedIndex === i) { controlList.modifyFeature.layer = w

我想更改OpenLayers.Control.ModifyFeature控件的图层 我尝试完全移除控制器,然后基于新层添加另一个控制器。 我通过使用如下循环直接更改了ModifyFeature的图层属性:

for(var i = 0; i <= 10; i++) {
    if(document.getElementById('verksamhet').selectedIndex === i) {
        controlList.modifyFeature.layer =   window[layerName[i+1]];
    }
}
controlList.modifyFeature.deactivate();
map.removeControl(controlList.modifyFeature);

for(var i = 0; i <= 10; i++) {
    if(document.getElementById('verksamhet').selectedIndex === i) {
        controlList.modifyFeature = new OpenLayers.Control.ModifyFeature(window[layerName[i+1]], {displayClass: 'modButton', clickout: true, toggle: true, title: 'Modify feature'});
    }
}
map.addControl(controlList.modifyFeature);
controlList.modifyFeature.activate();

for(var i=0;i我还研究了在多个层上获得modifyControl的方法。这并不容易。
在创建ModifyControl时,将设置该层。它还会为该层创建一个dragControl。如果使用modifyFeature.deactivate(),则该控件仅被禁用,而不会被删除。我认为这会导致您遇到的干扰

您还应该使用modifyFeature.destroy()

controlList.modifyFeature.deactivate();
controlList.modifyFeature.destroy();
map.removeControl(controlList.modifyFeature);