Select to view content in your preferred language

How do I save graphic to feature service?

4306
3
11-11-2013 06:53 AM
MStayner
Occasional Contributor
I would like to draw a sketch using graphics (see this example) and save to a feature service.  Any thoughts on how to take the entire sketch (all graphics) and save to feature service?
0 Kudos
3 Replies
JohnGravois
Deactivated User
as long as the graphic geometry type matches what is published in your feature service you can call featureLayer.applyEdits() and pass it in within the 'adds' parameter.

check out this sample for an example of the method in action.
0 Kudos
BrandonIves
Emerging Contributor
as long as the graphic geometry type matches what is published in your feature service you can call featureLayer.applyEdits() and pass it in within the 'adds' parameter.

check out this sample for an example of the method in action.


I see what you are referring to in the sample: selectedTemplate.featureLayer.applyEdits([newGraphic], null, null);

I am able to add the graphic to the map but it isn't saving to the feature layer. Am I missing something??

I am trying to combine the  Draw Graphics on the map example   with the example you posted a link to  Above.

        var map, toolbar, symbol, geomTask;

        require([
          "esri/map",
          "esri/layers/ArcGISDynamicMapServiceLayer",
          "esri/layers/FeatureLayer",
          "esri/toolbars/draw",
          "esri/graphic",
          "esri/symbols/SimpleMarkerSymbol",
          "esri/symbols/SimpleLineSymbol",
          "esri/symbols/SimpleFillSymbol",
          "dojo/parser",
          "dijit/registry",
          "dijit/form/Button",
          "dijit/form/ValidationTextBox",
          "esri/dijit/editing/Editor-all",
          "dijit/layout/BorderContainer",
          "dijit/layout/ContentPane",
          "dojo/domReady!"
          
        ], function (
          Map, ArcGISDynamicMapServiceLayer, FeatureLayer, Draw, Graphic,
          SimpleMarkerSymbol, SimpleLineSymbol, SimpleFillSymbol,
          parser, registry, button, validationTextBox, editorAll, borderContainer, contentPane
        ) {
            parser.parse();

            esri.config.defaults.geometryService = new esri.tasks.GeometryService("http://gisadev:6080/arcgis/rest/services/Utilities/Geometry/GeometryServer");

            // Create the map
            map = new Map("map")
            streetsLayer = new esri.layers.ArcGISDynamicMapServiceLayer("http://gisaprd/ArcGIS/rest/services/SRSLandbase/MapServer", { "id": "Streets" });
            map.addLayer(streetsLayer);
            map.on("load", createToolbar);
            dojo.connect(map, "onLayersAddResult", initEditor);
            //Add the editable feature layer to the map
            var ISS_Features = new esri.layers.FeatureLayer("http://gisadev:6080/arcgis/rest/services/ISS_Inspections/FeatureServer/0", {
                mode: esri.layers.FeatureLayer.MODE_ONDEMAND,
                outFields: ['*']
            });

            map.addLayers([ISS_Features]);

            RedlinePointLayer = new esri.layers.FeatureLayer("http://gisadev:6080/arcgis/rest/services/Redline_Test/FeatureServer/0", {
                mode: FeatureLayer.MODE_SNAPSHOT,
                editable: true,
                outFields: ["*"]
            });
            map.addLayers([RedlinePointLayer]);

            // loop through all dijits, connect onClick event
            // listeners for buttons to activate drawing tools
            registry.forEach(function (d) {
                // d is a reference to a dijit
                // could be a layout container or a button
                if (d.declaredClass === "dijit.form.Button") {
                    d.on("click", activateTool);
                }
            });

            function activateTool() {
                var tool = this.label.toUpperCase().replace(/ /g, "_");
                toolbar.activate(Draw[tool]);
                map.hideZoomSlider();
            }

            function createToolbar(themap) {
                toolbar = new Draw(map);
                toolbar.on("draw-end", addToMap);
            }

            function addToMap(evt) {
                var symbol;
                toolbar.deactivate();
                map.showZoomSlider();
                switch (evt.geometry.type) {
                    case "point":
                    case "multipoint":
                        symbol = new SimpleMarkerSymbol();
                        break;
                    case "polyline":
                        symbol = new SimpleLineSymbol();
                        break;
                    default:
                        symbol = new SimpleFillSymbol();
                        break;
                }
                var graphic = new Graphic(evt.geometry, symbol);
                map.graphics.add(graphic);

                //To save the redline I need to add the graphic to the redline feature class......
                if (graphic.symbol = SimpleMarkerSymbol) {
                    RedlinePointLayer.add(new esri.Graphic(graphic.geometry, RedlinePointLayer.symbol), null, null);               
                }
            }
            function initEditor(results) {
                //only one layer 
                var featureLayer = results[0].layer;

                var templatePicker = new esri.dijit.editing.TemplatePicker({
                    featureLayers: [featureLayer],
                    rows: 'auto',
                    groupingEnabled: false,
                    columns: 1
                }, 'editorDiv');
                templatePicker.startup();

                var layerInfos = [{
                    'featureLayer': featureLayer,
                    'showAttachments': false,
                    'showDeleteButton': false,
                    'isEditable': true,
                    'fieldInfos': [
                    { 'fieldName': 'METER_NUMBER', 'isEditable': true, 'tooltip': 'METER_NUMBER', 'label': 'METER_NUMBER:' },
                    ]
                }];
                //define the editor settings
                var settings = {
                    map: map,
                    templatePicker: templatePicker,
                    layerInfos: layerInfos
                };
                var params = { settings: settings };
                //Create the editor widget 
                var editorWidget = new esri.dijit.editing.Editor(params);
                editorWidget.startup();
                //resize the info window (attribute inspector)
                map.infoWindow.resize(430, 245);
            }
        });

0 Kudos
JohnGravois
Deactivated User
Brandon,

i'm not sure i understand what you're asking.  are you attempting to save new features to your redline feature layer published using ArcGIS Server?  if so, at some point in your code you will need to make a call to RedlinePointLayer.applyEdits() instead of calling RedlinePointLayer.add().
0 Kudos