Select to view content in your preferred language

Template Picker, Editor and Snapping

2420
10
07-26-2012 12:09 PM
VIKRANTKRISHNA
Regular Contributor
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
ZhanpingShi
Emerging Contributor
Hi Jian,

Thank you very much for your great help! Since the editor widget was not workable, so I switch to use the FeatureLayer.applyEdits() function to add, update and delete the feature service layer, but I got a new problem, please take look at if you have any ideas, the code snippet as below, it should not have problem on the normal html or JSP code to add a drew feature into the feature service, however our application is a JAVA based and the part of Javacript function is resided within a JSPX page, when the page
is running on the web site, the JSPX page (which include the function below) is forwarded to a JSP page to show on the web site.

As test the editing function to draw a new feature on the map, the "FeatureLayer.applyEdits()" just skipped, and not works at all. In addition, if creating a new feature service layer within this function, the created feature layer is unable to show its attributes like name, type, isEditable() is false.....

Can you please have your time to help me to know what problem it is, any suggestions, how the best way to resolve it. Thank you again, my personal email: zhanpings@yahoo.com

Zhanping

function addToMap(geometry) {

var editFeatureLayer = map.getLayer("firePerimeterFL");
var fieldAttributes = layerFieldToAttributes(editFeatureLayer.fields);

symbol = new esri.symbol.SimpleFillSymbol(
esri.symbol.SimpleFillSymbol.STYLE_SOLID,
new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID,
new dojo.Color([255,0,0,1]), 2),
new dojo.Color([255,0,0, 0.4])
);

var graphic = new esri.Graphic(geometry, symbol, fieldAttributes);
var layerInfos = getLayerInfos(editFeatureLayer);

var attInspector = new esri.dijit.AttributeInspector({
layerInfos: layerInfos
}, dojo.create("div"));


editFeatureLayer.applyEdits([graphic], null, null, function() {

var screenPoint = map.toScreen(getInfoWindowPositionPoint(graphic));
map.infoWindow.setContent(attInspector.domNode);

map.infoWindow.resize(350, 450);
map.infoWindow.show(screenPoint, map.getInfoWindowAnchor(screenPoint));

});

map.addLayer(editFeatureLayer);

}
0 Kudos