Template Picker, Editor and Snapping

1738
10
07-26-2012 12:09 PM
VIKRANTKRISHNA
New Contributor III
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 !!
0 Kudos
10 Replies
JianHuang
Occasional Contributor III
Did you mean snapping stops working completely, or not working with those invisible layers?
Snapping only works with visible layers. It is by design.
0 Kudos
VIKRANTKRISHNA
New Contributor III
Did you mean snapping stops working completely, or not working with those invisible layers?
Snapping only works with visible layers. It is by design.



snapping stops completely for all the layers.
0 Kudos
VIKRANTKRISHNA
New Contributor III
Jian,
      Check out this sample http://107.21.20.43/editing/testpage4.html

I am just hiding pointsOfInterest layer in initEditor function and snapping doesn't work for evacuationPerimeter layer.
0 Kudos
JianHuang
Occasional Contributor III
I'm looking into it and will keep you updated soon.
Thanks.
0 Kudos
JianHuang
Occasional Contributor III
This is a bug. We will fix it in the next release.
Thanks for letting us know.
0 Kudos
JianHuang
Occasional Contributor III
At this moment, the workaround is to call snappingManager.setLayerInfos(setLayerInfos) to exclude the invisible layer when you cann featureLayer.hide().
Hope this helps.
0 Kudos
VIKRANTKRISHNA
New Contributor III
that works perfect.
0 Kudos
ZhanpingShi
New Contributor
Hi Jian,

Here I have a question about the esri.dijit.editing.Editor, the editorWidget can be created and the template picker can show on the
web page, but the icons on the template picker can not be selected, that means the icon images didn't enabled. I am not sure what
problem is, the problem happens within a JSPX page, but it works fine in HTML page.

Here are the code snippet, every step works fine.


function initEditing(results){
       
var featureLayerInfos = dojo.map(results, function(result) {
   return {
                            "featureLayer": result.layer
                          };
        });
       
var settings = {
  map: map,
  geometryService: new esri.tasks.GeometryService("http://servicesbeta.esri.com/arcgis/rest/services/Geometry/GeometryServer"),

   enableUndoRedo:true,
   layerInfos:featureLayerInfos,
   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  };

var editorWidget = new esri.dijit.editing.Editor(params, 'editorDiv');

var options = {snapKey:dojo.keys.copyKey};

map.enableSnapping(options);

editorWidget.startup();


}

Thank you in advance, and any body who can provide any help!

Zhanping
0 Kudos
JianHuang
Occasional Contributor III
Since it works fine in HTML, it's reasonable to assume that something is wrong in the translation from JSPX to HTML. I'm afraid that it's out of scope of Esri JavaScript API team.
Maybe you share reproducible steps so that we may be able to help?
0 Kudos