I am using API 3.10 and I am trying to Activate Editor on Button Click and deactivate the Edit when the button is clicked again. on page Page Load I set the EditContent Pane css to display none and display it on button click.
Also calling InitEditor on button click does not seem to work, the editor is not loading neither the TemplatePicker not event the Editor InfoTemplate.
here is my code:
appEdit = {
showEditPanel: function () {
var node = registry.byId("btnEditLayer");
var panel = dojo.byId("EditContent");
var value = node.get("label");
if (value == "Start Edit") {
domStyle.set(registry.byId("EditContent").domNode, { 'display': 'block' });
registry.byId("mainWindow").resize();
node.set("label", "Stop Edit");
initEditor();
}
else if (value == "Stop Edit") {
domStyle.set(registry.byId("EditContent").domNode, { 'display': 'none' });
registry.byId("mainWindow").resize();
node.set("label", "Start Edit");
destroyEditor();
}
}
}
here are the functions InitEditor and DestroyEditor
function initEditor(evt) {
var templatePicker = new TemplatePicker({
featureLayers: [permit, sitePlan],
grouping: true,
rows: "auto",
columns: 3
}, "templateDiv");
templatePicker.startup();
var layers = arrayUtils.map(evt.layers, function (result) {
return { featureLayer: result.layer };
});
var settings = {
map: map,
templatePicker: templatePicker,
layerInfos: layers,
toolbarVisible: true,
createOptions: {
polylineDrawTools: [esri.dijit.editing.Editor.CREATE_TOOL_FREEHAND_POLYLINE],
polygonDrawTools: [esri.dijit.editing.Editor.CREATE_TOOL_FREEHAND_POLYGON]
},
toolbarOptions: {
reshapeVisible: 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
});
myEditor.startup();
}
function destroyEditor() {
if (editorWidget) {
editorWidget.destroy();
editorWidget = null;
}
}
I rewrote the function initEditor and this time when I select the template, I get this error:
"Uncaught TypeError: Cannot read property 'activate' of undefined"
here is the function that Call on button click:
function initEditor(evt) {
var templatePicker = new TemplatePicker({
featureLayers: [permit, sitePlan],
grouping: true,
rows: "auto",
columns: 3
}, "templateDiv");
templatePicker.startup();
var layers = map.on("layers-add-result", function (result) {
return {
featureLayer: result.layer
};
});
//var layers = dojo.connect(map, "onLoad", function (result) {
// return { featureLayer: result.layer };
//});
console.log("Hi Test");
var settings = {
map: map,
templatePicker: templatePicker,
layerInfos: layers,
toolbarVisible: true,
showAttributesOnClick: true,
createOptions: {
polylineDrawTools: [esri.dijit.editing.Editor.CREATE_TOOL_FREEHAND_POLYLINE],
polygonDrawTools: [esri.dijit.editing.Editor.CREATE_TOOL_FREEHAND_POLYGON]
},
toolbarOptions: {
reshapeVisible: true
}
};
var params = { settings: settings };
var myEditor = new esri.dijit.editing.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
});
myEditor.startup();
}