ionarawilson

Map not refreshing when a new map is created

Discussion created by ionarawilson on Dec 2, 2013
I am creating a web app that is using the editor widget. I want the editor template to show only one layer depending on what the user selects in a combobox. To do that, I have to destroy and recreate the editor template and the map. However when I choose a value for the second time, the feature layer shows up on the map and on the editor template, but the map is not activated. I can see the labels for the hybrid basemap but not the imagery and I cannot edit the feature layer (please see image attached). . Once I click on a zooming level in the zoom slider everything goes back to normal. Does anybody know why this is happening and how to fix it? Is there a map refresh I could use ? Thank you!!!

dojo.connect(dijit.byId("Activity"), 'onChange', function(value){ 
             //alert('ok ' + event);
         displayedvalue = dijit.byId("Activity").get('displayedValue')
        
    if (displayedvalue in oc(officeactivitylist)) {
     
    
    var contentHolder = "<div id='templateDiv'></div><div id='editorDiv'></div>";
    dojo.place(contentHolder, "contentpane", "first");
  
    
      map.on("layers-add-result", initEditor);

  
    map.addLayers([stewardship]);
 
        function initEditor(evt) {
 
          var templateLayers = arrayUtils.map(evt.layers, function(result){
            return result.layer;
 

          });

          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'}
            }
   
   
          });
            return { featureLayer: result.layer, 'fieldInfos':fieldInfos};
          });
 


 
          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
          });
    
        myEditor.startup();
      
        }
    
   }
    
   if (displayedvalue in oc(communityactivitylist)) {
    
    map.removeLayer(stewardship)
                dojo.destroy("templateDiv")
    //dojo.destroy('editorDiv')
    map.destroy()
    var contentHolder2 = "<div id='templateDiv2'></div>";
    dojo.place(contentHolder2, "contentpane", "first");
 
        map = new Map("map", { 
          basemap: "hybrid",
         sliderStyle: "large",

 
          center: [-98.57, 30.98],
          zoom: 6,
          slider: true 


        });


  
    map.addLayers([activityarea]);

   map.on("layers-add-result", initEditor2); 
        function initEditor2(evt) {
 
          var templateLayers = arrayUtils.map(evt.layers, function(result){
            return result.layer;
 

          });

          var templatePicker = new TemplatePicker({
            featureLayers: templateLayers,
            grouping: true,
            rows: "auto",
            columns: 3
          }, "templateDiv2");
          templatePicker.startup();

          var layers = arrayUtils.map(evt.layers, function(result) {
     
   
   var fieldInfos= arrayUtils.map(result.layer.fields,function(field){
           
          });
            return { featureLayer: result.layer, 'fieldInfos':fieldInfos};
          });
 


      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,'editorDiv2');
          //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();
      
        }
    
   }
   
   [ATTACH=CONFIG]29486[/ATTACH]
       });
    

Attachments

Outcomes