How can i upload data on an ArcGIS featureServer using featureLayer.applyEdits

4067
1
01-30-2015 03:35 AM
StefanSchärer
New Contributor

I'm building out a hybrid App with ionic and angular-js, in which the user generates some data (geolocation, date, other...) which has to be uploaded into and expressed as a data point in an ArcGIS Webmap. Unfortunately, I'm quite a javascript beginner and I'm stuck.

That's the code I tried:

 

var featureLayerUrl = "LayerURL";

    var outFields = ["*"];

 

    require([

   "esri/layers/FeatureLayer",

   "esri/tasks/query",

   "esri/graphic",

   'dojo/_base/declare',

   "dgrid/OnDemandGrid",

   "dgrid/CellSelection",

   "dojo/store/Memory",

   "dojo/_base/array",

   "esri/tasks/query", "esri/tasks/QueryTask",

   "dojo/dom",

   "dojo/on",

   "dojo/dom-style",

   "dojo/domReady!",

    "esri/geometry/Point",

        "esri/geometry/Geometry",

        "esri/symbols/Symbol",

        "esri/symbols/SimpleMarkerSymbol"

 

  ], function (FeatureLayer, Query, Graphic, Geometry, Point, SpatialReference,

        declare, OnDemandGrid, CellSelection, Memory, arrayUtils, Query, QueryTask, dom, on, domStyle, SimpleMarkerSymbol, Symbol) {

 

        var featureLayer = new FeatureLayer(featureLayerUrl, {

            outFields: outFields

        });

 

$scope.addFeatureNow = function () {

            // TODO: Adapt with all the attributes

 

           //Defines Symbols

           

            var symbol;

 

            if (allgDatenService.BioWaterQuality = "unpolluted - I") {

 

                symbol = new SimpleMarkerSymbol({

                    "color": [0, 92, 230, 255],

                    "size": 6,

                    "angle": 0,

                    "xoffset": 0,

                    "yoffset": 0,

                    "type": "esriSMS",

                    "style": "esriSMSDiamond",

                    "outline": {

                        "color": [255, 255, 255, 255],

                        "width": 1

                    }

                });

 

            }else if (allgDatenService.BioWaterQuality = "slightly polluted - I-II") {

 

                symbol = new SimpleMarkerSymbol({

                    "color": [0, 197, 255, 255],

                    "size": 6,

                    "angle": 0,

                    "xoffset": 0,

                    "yoffset": 0,

                    "type": "esriSMS",

                    "style": "esriSMSDiamond",

                    "outline": {

                        "color": [255, 255, 255, 255],

                        "width": 1

                    }

                });

            } else if (allgDatenService.BioWaterQuality = "moderately polluted - II") {

 

                symbol = new SimpleMarkerSymbol({

                    "color": [85, 255, 0, 255],

                    "size": 6,

                    "angle": 0,

                    "xoffset": 0,

                    "yoffset": 0,

                    "type": "esriSMS",

                    "style": "esriSMSDiamond",

                    "outline": {

                        "color": [255, 255, 255, 255],

                        "width": 1

                    }

                });

            } else if (allgDatenService.BioWaterQuality = "seriously polluted - II-III") {

 

                symbol = new SimpleMarkerSymbol({

                    "color": [255, 170, 0, 255],

                    "size": 6,

                    "angle": 0,

                    "xoffset": 0,

                    "yoffset": 0,

                    "type": "esriSMS",

                    "style": "esriSMSDiamond",

                    "outline": {

                        "color": [255, 255, 255, 255],

                        "width": 1

                    }

                });

            } else if (allgDatenService.BioWaterQuality = "heavily polluted - III") {

 

                symbol = new SimpleMarkerSymbol({

                    "color": [255, 170, 0, 255],

                    "size": 6,

                    "angle": 0,

                    "xoffset": 0,

                    "yoffset": 0,

                    "type": "esriSMS",

                    "style": "esriSMSDiamond",

                    "outline": {

                        "color": [255, 255, 255, 255],

                        "width": 1

                    }

                });

            } else if (allgDatenService.BioWaterQuality = "very heavily polluted - III-IV") {

 

                symbol = new SimpleMarkerSymbol({

                    "color": [255, 85, 0, 255],

                    "size": 6,

                    "angle": 0,

                    "xoffset": 0,

                    "yoffset": 0,

                    "type": "esriSMS",

                    "style": "esriSMSDiamond",

                    "outline": {

                        "color": [255, 255, 255, 255],

                        "width": 1

                    }

                });

            } else if (allgDatenService.BioWaterQuality = "excessively polluted - IV") {

 

                symbol = new SimpleMarkerSymbol({

                    "color": [168, 56, 0, 255],

                    "size": 6,

                    "angle": 0,

                    "xoffset": 0,

                    "yoffset": 0,

                    "type": "esriSMS",

                    "style": "esriSMSDiamond",

                    "outline": {

                        "color": [255, 255, 255, 255],

                        "width": 1

                    }

                });

            };

 

 

            var geometry = new Point(allgDatenService.long, allgDatenService.lat, new SpatialReference({

                wkid: 4326

            }));

 

            var attributes = {

                "rivername": allgDatenService.rivername,

                "organisation": allgDatenService.organisation,

                "comments": allgDatenService.comments,

                "BioWaterQuality": allgDatenService.BioWaterQuality,

                "landscape_eco_number": allgDatenService.landscape_eco_number,

                "LandscapeEcology": allgDatenService.LandscapeEcology,

                "CreationDate": allgDatenService.CreationDate,

                "Creator": "SomeCreator"

 

            };

 

 

            var graphic = new Graphic(geometry, symbol, attributes, null);

            featureLayer.applyEdits(graphic, null, null, function () {

                $log.log("addFeatureSuccess");

 

            }, function () {

                alert("An error occured during add.");

            })

        }

    });

 

       

So, somehow the console gives me a "addFeatureSuccess", the featureLayer.applyEdits() is executed, but...

When I go and check if there's a data-point in my Map, there isn't. What did I do wrong?

Thanks for any help provided...

0 Kudos
1 Reply
KenBuja
MVP Esteemed Contributor

The first thing that jumps out is your function arguments do not match your require modules. They are out of order and missing some modules. This is a must! Read this blog for more information.

require([
   "esri/layers/FeatureLayer",
   "esri/tasks/query",
   "esri/graphic",
   "esri/geometry/Geometry",
   "esri/geometry/Point",
   "esri/SpatialReference",
   "dojo/_base/declare",
   "dgrid/OnDemandGrid",
   "dgrid/CellSelection",
   "dojo/store/Memory",
   "dojo/_base/array",
   "esri/tasks/QueryTask",
   "dojo/dom",
   "dojo/on",
   "dojo/dom-style",
   "esri/symbols/SimpleMarkerSymbol",
   "esri/symbols/Symbol",
   "dojo/domReady!"
  ], function (FeatureLayer, Query, Graphic, Geometry, Point, SpatialReference,
        declare, OnDemandGrid, CellSelection, Memory, arrayUtils, QueryTask, dom, on, domStyle, SimpleMarkerSymbol, Symbol) {
0 Kudos