I have about 10-12 layers in my application which needs to be edited. I don't want to show all the layers turned initially. I tried to hide some layers after the templatePicker and editor widget have loaded (layerName.hide()). What I am seeing is that snapping stops working in this case. I modified sample server demo to show this. In this code only thing different that I have done is to put a line at the end of initEditor() to hide one layer . Below is the code initEditor function.
function initEditor(results) {
//build the layer and field information for the layer, display the description field
//using a text area.
var layers = dojo.map(results, function(result) {
var fieldInfos= dojo.map(result.layer.fields,function(field){
if(field.name === 'description'){
return {'fieldName': field.name,'label':'Details',stringFieldOption:esri.dijit.AttributeInspector.STRING_FIELD_OPTION_TEXTAREA}
}
else{
return {'fieldName': field.name,'lable':field.alias}
}
});
return {featureLayer:result.layer,'fieldInfos':fieldInfos}
});
var settings = {
map: map,
enableUndoRedo:true,
layerInfos:layers,
toolbarVisible: true,
createOptions: {
polygonDrawTools: [ esri.dijit.editing.Editor.CREATE_TOOL_FREEHAND_POLYGON,
esri.dijit.editing.Editor.CREATE_TOOL_AUTOCOMPLETE]
},
toolbarOptions: {
reshapeVisible: true,
cutVisible: true,
mergeVisible: true
}
};
var params = {settings: settings};
editorWidget = new esri.dijit.editing.Editor(params,'editorDiv');
//Dojo.keys.copyKey maps to CTRL in Windows and CMD in Mac
map.enableSnapping({snapKey:dojo.keys.copyKey});
//create a new checkbox to enable/disable snapping
var checkBox = new dijit.form.CheckBox({
name: "chkSnapping",
checked:true,
id: "chkSnapping",
label:"Snapping",
showLabel:"false",
title:"Snapping",
onChange: function(evt) {
console.log(this.checked);
if(this.checked){
map.enableSnapping({snapKey:dojo.keys.copyKey});
}else{
//map.disableSnapping();
}
}
});
//add the snapping checkbox to the editor's toolbar
var myToolbarElement = dojo.query(".esriDrawingToolbar",editorWidget.domNode)[0];
var myToolbar = dijit.byId(myToolbarElement.id);
myToolbar.addChild(new dijit.ToolbarSeparator());
myToolbar.addChild(checkBox);
editorWidget.startup();
//listen for the template pickers onSelectionChange and disable
//the snapping checkbox when a template is selected
var templatePickerElement = dojo.query(".esriTemplatePicker",editorWidget.domNode)[0];
var templatePicker = dijit.byId(templatePickerElement.id);
dojo.connect(templatePicker,"onSelectionChange",function(){
if(templatePicker.getSelected()){
//disable the snapping checkbox
dijit.byId('chkSnapping').set("disabled",true);
}else{
dijit.byId('chkSnapping').set("disabled",false);
}
});
map.infoWindow.resize(325,200);
pointsOfInterest.hide(); // This is the line I added to test
}
Help needed !!