How to destroy esri.dijit.editing.Editor?

2321
7
01-06-2011 01:24 AM
AndrisBerzins
New Contributor
When I call destroy()  and recreate after, got following error:

Unable to draw graphic (geometry:null, symbol:null): Tried to register widget with id==templateDiv but that id is already registered.
0 Kudos
7 Replies
timgogl
New Contributor II
i did something similar and got the same error... heh. now i cannot remember what i did to fix it, but here is a snippet of my code:

  function openEdit(){
   editLayersAdded = dojo.connect(map,'onLayersAddResult',addEditor);
   
   StructurePoints = new esri.layers.FeatureLayer(STRUCTPOINTSERV, {
    mode: esri.layers.FeatureLayer.MODE_ONDEMAND,
    outFields: ["*"]
   });
   
   RecPolygon = new esri.layers.FeatureLayer(RECPOLYSERV, {
    mode: esri.layers.FeatureLayer.MODE_ONDEMAND,
    outFields: ["*"]
   });

         map.addLayers([StructurePoints,RecPolygon]);
  } 
     
  function closeEditor(){
   if(editIsOn){
    dojo.disconnect(editLayersAdded);
    map.removeLayer(StructurePoints);
    map.removeLayer(RecPolygon);
    myEditor.destroy();
   }
  }
  function addEditor(r){
   
   var contentHolder = "<div id='editorDiv'></div><div id='tmpDiv'></div>";
   $j('##editDiv').append(contentHolder);
   
   var templateLayers = dojo.map(r,function(result){
    return result.layer;
   });
   
   var widget = new esri.dijit.editing.TemplatePicker({
    featureLayers: templateLayers,
    grouping: true,
    rows: 'auto',
    columns: 3
   },'tmpDiv');
   widget.startup();
   
   var layers = dojo.map(r, function(result) {
    return {featureLayer:result.layer};
   });
   
   var settings = {
    map: map,
    templatePicker: widget,
    geometryService: new esri.tasks.GeometryService(GEOSERVICE),
    layerInfos:layers,
    toolbarVisible: true,
    createOptions: {
     polylineDrawTools:[ esri.dijit.editing.Editor.CREATE_TOOL_FREEHAND_POLYLINE],
     polygonDrawTools: [ esri.dijit.editing.Editor.CREATE_TOOL_FREEHAND_POLYGON,
                         esri.dijit.editing.Editor.CREATE_TOOL_CIRCLE,
                         esri.dijit.editing.Editor.CREATE_TOOL_TRIANGLE,
                         esri.dijit.editing.Editor.CREATE_TOOL_RECTANGLE ]
    },
    toolbarOptions: {
     reshapeVisible: true
    }
   };
   var params = {settings: settings};   
   
   myEditor = new esri.dijit.editing.Editor(params,'editorDiv');
   myEditor.startup();  
   
  }


basically my editor is now in an accordion container... when the users switch accordion panels, it turns on/off the editor.


you can ignore the double # signs... i use coldfusion as a backend... and am 'escaping' the # character used by cf.
0 Kudos
DavidHollema
New Contributor III
I had experienced the same problem.  From what I can tell in testing, the solution is to called <yourEditorWidget>.destroy() successfully.  In addition, create the template and editor divs dynamically in the DOM using the tools of your choice.  In dojo...

var contentHolder = "<div id='templateDiv'></div><div id='editorDiv'></div>";
dojo.place(contentHolder, "LogOccurrence", "first");


Include this code prior to or during your creation of the editor-related objects.  To deactivate editing or recreate the editing stuff upon opening a container, for example, just call <yourEditorWidget>.destroy();

Using static divs in the page prevented the editor from reappearing after a destroy.  I could see the editor initially but not after destroy.  I believe the destroy operation blows away the domNodes associated with the static divs.
0 Kudos
JeffPace
MVP Alum
I had experienced the same problem.  From what I can tell in testing, the solution is to called <yourEditorWidget>.destroy() successfully.  In addition, create the template and editor divs dynamically in the DOM using the tools of your choice.  In dojo...

var contentHolder = "<div id='templateDiv'></div><div id='editorDiv'></div>";
dojo.place(contentHolder, "LogOccurrence", "first");


Include this code prior to or during your creation of the editor-related objects.  To deactivate editing or recreate the editing stuff upon opening a container, for example, just call <yourEditorWidget>.destroy();

Using static divs in the page prevented the editor from reappearing after a destroy.  I could see the editor initially but not after destroy.  I believe the destroy operation blows away the domNodes associated with the static divs.


You have two options really.

1. Destroy the containing div as well.  We use a container div and then the edit div.  When destroying edit, we destroy the edit div as well.  Actually we have to do this for almost all widgets.
2. Loop through the dijit.registry and destroy the proper widget (Code below destroys all).

dijit.registry.forEach(function(w){
                  w.destroy();             
          });
0 Kudos
KellyHutchins
Esri Frequent Contributor
For an example of destroying/recreating the editor take a look at the Basic Viewer template. The source code is available as a download here:

http://www.arcgis.com/home/item.html?id=89db99ee00834c85b3f9284d9e81c964
0 Kudos
dancheng
New Contributor II
hey, did you get this problem solved? my problem is similar but a little bit different. If i dont click on the map, its working pretty well. but as long as i click an point on the map and turn off editor which is using destroy(), the console shows error "object layer layer1 has no method 'disconnect'",thanks.
When I call destroy()  and recreate after, got following error:

Unable to draw graphic (geometry:null, symbol:null): Tried to register widget with id==templateDiv but that id is already registered.
0 Kudos
UmutZaim
New Contributor II
Hey. After selecting Map from Editor I get the following error when I want to editorwidget.destroy()
error message: _E.DISCONNECT IS NOT A FUNCTION
0 Kudos
JonathanUihlein
Esri Regular Contributor
Hey. After selecting Map from Editor I get the following error when I want to editorwidget.destroy()
error message: _E.DISCONNECT IS NOT A FUNCTION


Hi orhun,

Can you create a sample of your issue using jsfiddle.net so I can take a look?

Thanks!
0 Kudos