I need to have just one single feature in the template picker of the editor widget based on the selection of a combobox. However, the template picker is being created after the add layer result event. Because the add layer result fires before the change event in the combobox, I had to create a deferred function but the function works well the first time and the second time it does not work, because the deferred function has already been resolved. Can you please take a look at my code and tell me the best way to do this? Thank you so much for any help!
var stewardship = new esri.layers.FeatureLayer("http://tfsgis-iisd01:6080/arcgis/rest/services/FeatureServiceStewAAreaAPoint/FeatureServer/0",
{
mode: FeatureLayer.MODE_SELECTION, id: 'stewardship',
outFields: ['*']
});
var activityarea = new esri.layers.FeatureLayer("http://tfsgis-iisd01:6080/arcgis/rest/services/FeatureServiceStewAAreaAPoint/FeatureServer/1",
{
mode: FeatureLayer.MODE_SELECTION, id: 'activityarea',
outFields: ['*']
});
deferred = new dojo.Deferred();
deferred.then(function(value){
console.log(value);
activityValue = dijit.byId('Activity').get('displayedValue')
if (activityValue == "Forest Stewardship Plan")
{ map.removeAllLayers;
alert("TEST")
map.addLayers([stewardship]);
}
if (activityValue == "Non Forest Stewardship Plan")
{
map.removeAllLayers;
alert("TEST2")
map.addLayers([activityarea]);
}
});
map.on("layer-remove", layerremove)
function layerremove()
{
TemplatePicker.destroy()
}
// map.addLayers([activityarea]);
function initEditor(evt) {
var templateLayers = arrayUtils.map(evt.layers, function(result){
return result.layer;
});
// TEST: Changed to stewardship instead of templateLayers
var templatePicker = new TemplatePicker({
featureLayers: templateLayers,
grouping: true,
rows: "auto",
columns: 3
}, "templateDiv");
templatePicker.startup();
var layers = arrayUtils.map(evt.layers, function(result)
{
var fieldInfos= arrayUtils.map(result.layer.fields,function(field){
if(field.name === 'RecipientLast'){
return {'fieldName': field.name,'label':'Rec Last Name'}
}
if(field.name === 'RecipientFirst'){
return {'fieldName': field.name,'label':'Rec First Name'}
// return {'fieldName': field.name,'label':'Rec First Name',stringFieldOption:esri.dijit.AttributeInspector.STRING_FIELD_OPTION_TEXTAREA
}
if(field.name === 'Phone'){
return {'fieldName': field.name,'label':'Phone', 'customField':myDijit}
// return {'fieldName': field.name,'label':'Rec First Name',stringFieldOption:esri.dijit.AttributeInspector.STRING_FIELD_OPTION_TEXTAREA
}
if(field.name === 'ZipCode'){
return {'fieldName': field.name,'label':'ZipCode', 'customField':myDijit2}
// return {'fieldName': field.name,'label':'Rec First Name',stringFieldOption:esri.dijit.AttributeInspector.STRING_FIELD_OPTION_TEXTAREA
}
if (field.name == 'DateStart')
{
return {'fieldName': field.name,'label':'Start Date', 'customField': datedijit }
}
else{
return {'fieldName': field.name,'label':field.alias}
}
});
return { featureLayer: result.layer, 'fieldInfos':fieldInfos};
});
//add a default value for newly added features
var settings = {
map: map,
templatePicker: templatePicker,
layerInfos: layers,
toolbarVisible: true,
createOptions: {
polylineDrawTools:[ Editor.CREATE_TOOL_FREEHAND_POLYLINE ],
polygonDrawTools: [ Editor.CREATE_TOOL_FREEHAND_POLYGON,
Editor.CREATE_TOOL_CIRCLE,
Editor.CREATE_TOOL_TRIANGLE,
Editor.CREATE_TOOL_RECTANGLE
]
},
toolbarOptions: {
reshapeVisible: true,
mergeVisible: true,
cutVisible: true
}
};
var params = {settings: settings};
var myEditor = new Editor(params,'editorDiv');
//define snapping options
var symbol = new SimpleMarkerSymbol(
SimpleMarkerSymbol.STYLE_CROSS,
15,
new SimpleLineSymbol(
SimpleLineSymbol.STYLE_SOLID,
new Color([255, 0, 0, 0.5]),
5
),
null
);
map.enableSnapping({
snapPointSymbol: symbol,
tolerance: 20,
snapKey: keys.ALT
});
}//end of init editor function
dojo.connect(dijit.byId("Activity"), 'onChange', function(value){
deferred.resolve("success");
return deferred.promise;
}
});