Editing environment and workflow

The editing environment for a mobile client application is determined by a variety of factors, including the geodatabase, SDE setup, map compilation, options used when the service is published, and how the client application is designed and built. This topic focuses on the factors within the client application development. See the related topics for details on how to set up and publish your mobile service. Be aware that the geodatabase design and setup have a major impact on the editing environment since it controls what is editable. When the mobile map document is created, it defines the included layers, the spatial reference used, the map extent, and visibility of the layers. Publishing the map document as a mobile service allows mobile clients to connect and make edits, but the settings used when publishing can control who can access the service for security purposes.

The editing environment in the client application includes the featurelayers to edit, snapping environment, input method, edit feature type, edit operation type, and quality checks.

If you are creating a new feature, the workflow resembles the following steps. To set the featurelayer to edit, open the mobilecache to ensure the layers to be edited are there and editable. Set the snapping environment (if needed), and create the geometry for the new feature using the sketch graphic and mapaction. After the geometry is created, a new row is created and added to the feature datatable and the attributes are set. Save all of these edits to the feature source. Post the new data back to the server, and perform some quality checks.

As all of these steps can have many options and variations, there is more information found in the related dtopics. These editing environments are the minimum setting required for a basic editing operation, and should be further refined for a production application.

Steps:
  1. Set the mobileCache properties for the application to access the data.

    mobileCache1.StoragePath = "C:\\data" + "\\MapCache";
    mobileCache1.Open();
    map1.MapLayers.Add(mobileCache1);
    

  2. Get the layers that can be edited from the application.

    foreach (FeatureSource fsource in mobileCache1.FeatureSources);
    {
    //make the first editable layer from the local cache our target
    if (fsource.AllowNew)
      {
      FeatureSource editsource = fsource ;
      }
    }
    

  3. Create the snapping agent for the editlayer and set its properties.

    SnappingEnvironment snapEnv;
    snapEnv = map1.SnappingEnvironment;
    SnappingAgent snapAgent = new SnappingAgent(fsource);
    snapAgent.SnappingType = SnappingType.Edge;
    snapAgent.Active = true;
    snapEnv.SnappingAgents.Add(snapAgent);
    snapEnv.Tolerance = map1.Extent.Width / 10; 
    snapEnv.ShowSegmentLength = true;
    snapEnv.ShowToleranceRadius = true;
    snapEnv.Active = true;
    

  4. Perform your editing operation, which can be adding, modifying, deleting a feature, or updating the feature attributes. The code below shows how to create a simple polygon feature.

    sketchGraphicLayer1.Geometry = new Polygon();
    
    // sets map action to add vertex sketch
    map1.MapAction = addVertexSketchTool1;
    
    FeatureDataTable fTable = editsource.GetDataTable();
    
    // creates a new row
    DataRow editedFeature = fTable.NewRow();
    
    //sets the new geometry to the feature layer data table
    fTable.Rows.Add(editedFeature);         
    
    //sets the new geometry to the geometry field
    editedFeature[editsource.GeometryColumnIndex] = sketchGraphicLayer1.Geometry;
    
    // updates the feature layer data table
    fTable.SaveInFeatureSource();
    

  5. Post the changes made back to the server using the mobile connection.

    FeatureSyncAgent fSyncAgent = new FeatureSyncAgent( editsource,mobileServiceConnection1);
    if (fSyncAgent.IsValid)
      {
        fSyncAgent.SynchronizationDirection = SyncDirection.UploadOnly;
        fSyncAgent.Synchronize();
      }
    

1/7/2015