add a feature in feature service

1524
1
09-05-2016 04:56 PM
RaymundoValencia_Martinez
New Contributor II

HI, I have a problem in AppStudio for arcgis. I created an application to add a feature in feature service when a button is pressed, I found a very simple way to do this in the help of arcgis but when run the project don´t save the feature

I leave here the code used whitout mistakes, but not add the feature.

I only need capture the current location for the feature to add.

someone can help me 

thanks 

App {
    id: app
    width: 640
    height: 480
    Rectangle
    {
        id: titleRect
        anchors
        {
            left: parent.left
            right: parent.right
            top: parent.top
        }
        height: titleText.paintedHeight + titleText.anchors.margins * 2
        color: app.info.propertyValue("titleBackgroundColor", "darkblue")
    }
    Map {
        id: map
        Envelope {
            id: envelopeInitalExtent
            xMax: -13630134.691272736
            yMax: 4554320.7069897875
            xMin: -13647294.804122735
            yMin: 4535211.44991852
            spatialReference: mainMap.spatialReference
        }
        positionDisplay {
            id: positionDisplay
            zoomScale: 200000
            mode: Enums.AutoPanModeDefault
            positionSource: PositionSource {
                id: positionSource
            }
        }
        anchors {
            left: parent.left
            right: parent.right
            top: titleRect.bottom
            bottom: parent.bottom
        }
        onStatusChanged: {
            if(map.status === Enums.MapStatusReady) {
                graphicsLayer.renderingMode = Enums.RenderingModeStatic;
                addLayer(graphicsLayer);
            }
        }
        ArcGISTiledMapServiceLayer {
            url: "http://services.arcgisonline.com/ArcGIS/rest/services/Canvas/World_Light_Gray_Base/MapServer"
        }
        ArcGISDynamicMapServiceLayer
        {
             id: demoDynamicMapService
             url: "https://gis1041.sbx.mx:6443/arcgis/rest/services/Boton_Emergencia/BTN_Emerg/MapServer"
        }
        GeodatabaseFeatureServiceTable
        {
            id: featureServiceTable
            url: "https://gis1041.sbx.mx:6443/arcgis/rest/services/Boton_Emergencia/BTN_Emerg/FeatureServer/0"
        }
        FeatureLayer
        {
            id: featureLayer
            featureTable: featureServiceTable
        }
        Button {
            id: showPosition
            text: "Capture Location"
            width: addLocationPoint.width
            enabled: mainMap.status === Enums.MapStatusReady
            onClicked: {
                positionSource.active = true;
                positionDisplay.mode = Enums.AutoPanModeDefault
                var featureJson = {
                    geometry: {
                        x: positionDisplay.mapPoint.x,
                        y: positionDisplay.mapPoint.y,
                        spatialReference: mainMap.spatialReference
                    },
                    attributes: {
                        desc: "ABC456"
                    }
                }
                if (featureServiceTable.featureTableStatus === Enums.FeatureTableStatusInitialized) {
                    featureServiceTable.addFeature(featureJson)
                }
            }
        }
        Button {
            id: hidePosition
            text: "hide Location"
           // anchors.horizontalCenter: parent.horizontalCenter
            anchors.verticalCenter: parent.verticalCenter
            enabled: mainMap.status === Enums.MapStatusReady
            onClicked: {
                positionSource.active = false;
            }
        }
    }
}
Tags (3)
0 Kudos
1 Reply
nakulmanocha
Esri Regular Contributor

Once the feature is added to the featureservice table. You need to call the ApplyFeatureEdits method on the feature service table to persist changes to the feature service layer.

featureServiceTable.applyFeatureEdits();

ArcGIS Runtime SDK for Qt QML API: GeodatabaseFeatureServiceTable Class Reference 

You can see how it is implemented in our "Add and edit features" sample. Once you make changes to the form and press ok it calls the above method to save changes like adding features or updating features to the feature service layer.