[OpenLayers-Users] activate/deactivate DrawFeature and ModifyFeature controls on multiple vector layers
Robert Sanson
Robert.Sanson at asurequality.com
Wed Aug 28 14:04:11 PDT 2013
I have a map with 7 editable vector layers. As each layer is loaded and added to the map, I create DrawFeature, ModifyFeature and SelectFeature controls and add them to the map, but don't activate them.
Here is code showing one of the layers:
map.addLayer(crops);
cropControls = {
dpoly: new OpenLayers.Control.DrawFeature(crops,OpenLayers.Handler.Polygon,{id: 'ctrldraw'}),
modify: new OpenLayers.Control.ModifyFeature(crops,OpenLayers.Handler.Polygon,{id: 'ctrlmod'}),
delf: new OpenLayers.Control.SelectFeature(crops, {id: 'ctrldel',
multiple: true,
onSelect: function(feature) {feature.attributes.pstate = "del";
crops.drawFeature(feature, "delf");
}
}
)
};
for(var key in cropControls) {
map.addControl(cropControls[key]);
}
When a user wishes to edit one of the layers, they select the activelayer and the action (control) and then I try to deactivate all other controls that might be active and activate the correct one via functions such as modcrop() below:
function modcrop() {
var val = "modify";
for(key in measureControls) {
var mcontrol = measureControls[key];
if(mcontrol.active){
mcontrol.deactivate();
}
}
for(key in eptsControls) {
var eptscontrol = eptsControls[key];
if(eptscontrol.active){
eptscontrol.deactivate();
}
}
for(key in elinesControls) {
var eptscontrol = elinesControls[key];
if(eptscontrol.active){
elinescontrol.deactivate();
}
}
for(key in epolysControls) {
var epolycontrol = epolysControls[key];
if (epolycontrol.active){
epolycontrol.deactivate();
}
}
for(key in paddControls) {
var paddcontrol = paddControls[key];
if(paddcontrol.active){
paddcontrol.deactivate();
}
}
for(key in orchControls) {
var orchcontrol = orchControls[key];
if(orchcontrol.active){
orchcontrol.deactivate();
}
}
for(key in foreControls) {
var forecontrol = foreControls[key];
if(forecontrol.active){
forecontrol.deactivate();
}
}
for(key in cropControls) {
var crcontrol = cropControls[key];
if(val == key) {
if(!crcontrol.active){
crcontrol.activate();
alert("activated crop modify control");
}
} else {
if(crcontrol.active){
crcontrol.deactivate();
}
}
}
}
The problem I have is that the first time I select an active layer and activate say a ModifyFeature control and then select a feature, the feature gets selected but not in modify mode (ie. no vertices showing). If I switch to dpoly mode (DrawFeature) and then back to modify, then it works. For some reason the activate code is not working properly the first time during an edit session.
Any clues?
Many thanks,
Robert
This email and any attachments are confidential and intended solely for the addressee(s). If you are not the intended recipient, please notify us immediately and then delete this email from your system.
This message has been scanned for Malware and Viruses by Websense Hosted Security.
www.websense.com
More information about the Users
mailing list