AnsweredAssumed Answered

ApplyEdits appears not to work

Question asked by csergent08 Champion on May 19, 2015
Latest reply on May 22, 2015 by csergent08

In my application I can click on a point or add a point to a sign or support layer, but my support layer does not appear to apply the edits and my sign layer does not appear to apply edits or add graphics. I also have this project on github at: csergent45/streetSigns · GitHub  and the file that I am working on is in app/main.js Any ideas on this Tom Wayson ? I see the edits in the console.log, but they don't apply right after that.

 

Here is my code for both layers:

 // temporarily show alert when starting edits  
    // and then start listening for a map click  
    var startCaptureRequest = function (severity) {
        var listener;
        
        // NOTE: once user has clicked "x" to dismiss  
        // this alert, it will no longer show up  
        domStyle.set(app.startEditAlert, "display", "");
        setTimeout(function () {
            domStyle.set(app.startEditAlert, "display", "none");
        }, 3000);
        // save map point in app global and  
        listener = app.map.on("click", function (e) {
            listener.remove();
            // save map point in app global and  
            // show form to collect incident report  
            app.currentGeometry = e.mapPoint;
            
            /* Show signs form */
            if (severity === "0") {
                
                document.getElementById("signForm").reset();
                app.attributesSignModal.modal("show");
                


                /* Enter your domain item and then the element to populate */
                populateSelect("BACKING", "backing","sign");
                populateSelect("VISIBILITY", "visibility","sign");
                populateSelect("CONDITION_", "condition","sign");
                populateSelect("COLOR1", "color1","sign");
                populateSelect("DELINEATOR", "delineator","sign");
                populateSelect("ILLUM", "illum","sign");
                populateSelect("ATTACHTYPE", "attachType","sign");
                populateSelect("ATTACHLOC", "attachLoc","sign");
                populateSelect("SITEOBS", "siteObs","sign");
                populateSelect("SIGNSHAPE", "signShape","sign");
                populateSelect("COLOR2", "color2","sign");
                populateSelect("MUTCD", "mutcd","sign");


                /* Show supports form */
            } else if (severity === "1") {


                document.getElementById("supportForm").reset();
                app.attributesModal.modal("show");
                


                /* Enter your domain item and then the element to populate */
                populateSelect("TYPE", "type","support");
                populateSelect("SIZE_", "size","support");
                populateSelect("MATERIAL", "material","support");
                populateSelect("BASE", "base","support");
                populateSelect("RATING", "rating","support");


            }


           
        });
    };


    var stopCaptureRequest = function () {
          app.currentGeometry = null;
    };
    


    // get attributes from form and submit  
    var submitSupports = function () {
        
        alert(domClass.contains("attributesModal", "in"));


        var attributes = {
            // TODO: not sure if this is needed  
            //requestreceived: null
        };
        var currentDate = new Date(); // current date is defined but never used.
        var graphic;
                
        
        graphic = new Graphic(app.currentGeometry);
        
        query("#attributesModal input, #attributesModal select, #attributesModal textarea").forEach(function (formInput) {
            attributes[formInput.name] = formInput.value;
        });
       
        // Form Validation - ensures that the values for the database are here if left blank
        if ((attributes.supportId === undefined) || (attributes.supportId === "")) {
            attributes.supportId = null;
        }
        if ((attributes.dateInv === undefined) || (attributes.dateInv === "")) {
            attributes.dateInv = null;
        }
        if ((attributes.addrCode === undefined) || (attributes.addrCode === "")) {
            attributes.addrCode = null;
        }        


        
        
        graphic.setAttributes(attributes);
        stopCaptureRequest();
        
        //console.log(attributes);  
        app.supportLayer.applyEdits([graphic], null, null).then(function (response) {
            console.log(response);
        });
    };


    // get sign attributes from form and submit
    var submitSigns = function () {


        alert(domClass.contains("attributesSignModal", "in"));


        var attributes = {
            // TODO: not sure if this is needed  
            //requestreceived: null
        };
        var currentDate = new Date(); // current date is defined but never used.
        var graphic;




        graphic = new Graphic(app.currentGeometry);


        query("#attributesSignModal input, #attributesSignModal select, #attributesSignModal textarea").forEach(function(formInput) {
            attributes[formInput.name] = formInput.value;
        });


        // Form validation - ensures that the values for the data are here if left blank
        if ((attributes.installed === undefined)|| (attributes.installed === "")) {
            attributes.installed = null;
        }
        if ((attributes.signId === undefined) || (attributes.signId === "")) {
            attributes.signId = null;
        }
        if ((attributes.supportId === undefined) || (attributes.supportId === "")) {
            attributes.supportId = null;
        }


        graphic.setAttributes(attributes);
        stopCaptureRequest();


        //console.log(attributes);  
        app.signLayer.applyEdits([graphic], null, null).then(function (response) {
            console.log(response);
            
        });


    };

Outcomes