Adding custom geometry collection methods

Create a custom geometry collection method

You may want to create a custom geometry collection method sometime, for example, to collect features through a laser range finder via wireless connection. To create a new geometry collection method, you need to first create a new method by inheriting the GeometryCollectionMethod class.

On the Windows platform, once you add GeometryCollectionMethod, it will show up as a button on the left panel of EditFeatureAttributesPage on the Attributes tab. The left panel contains GeometryCollectionControl that you can customize if needed. It's accessible through EditFeatureAttributesPage. Do not confuse GeometryCollectionControl with GeometryEditControl. These are two different controls serving different purposes. As their names imply, GeometryCollectionControl is loaded when collecting a new feature, while the other control is loaded when editing an existing feature. Also, GeometryCollectionMethod is associated with GeometryCollectionControl, while GeometryEditMethod is associated with GeometryEditControl.

When a user clicks your geometry collection method button on the left panel, your custom business logic starts. For most built-in geometry collection methods, there is a menu next to the geometry collection method allowing a user to apply offset or change settings specific to the geometry collection method. You can do so for your custom GeometryCollectionMethod by customizing the GeometryCollectionMethod.GeometryOperations collection.

The following is an example of implementing custom geometry collection methods:

/// <summary>
  /// Custom Geometry collection
  /// </summary>
  public class CustomGeometryCollection : GeometryCollectionMethod
  {
    /// <summary>
    /// Custom Geometry collection
    /// </summary>
    public CustomGeometryCollection()
    {
      this.Name = "New Geometry Collection Demo";      
    }   

    /// <summary>
    /// Begins the geometry collection workflow.
    /// </summary>
    protected override void GeometryCollectionStarted()
    {
      ESRI.ArcGIS.Mobile.Client.Windows.MessageBox.ShowDialog("Custom Geometry Collection Started");
    }   

    /// <summary>
    /// Overrides Geometry Collection Start over 
    /// </summary>
    protected override void GeometryCollectionStartOver()
    {
      throw new NotImplementedException();
    }

    /// <summary>
    /// Stop Geometry Collection
    /// </summary>
    protected override void GeometryCollectionStopped()
    {
      ESRI.ArcGIS.Mobile.Client.Windows.MessageBox.ShowDialog("Custom Geometry Collection Stopped");
    }

Add and remove geometry collection methods

To remove built-in geometry collection methods or add custom geometry collection methods, you can listen to the CollectFeaturesTask.EditFeatureAttributesPage.EditFeatureAttributesViewModel.CreatingGeometryCollectionMethods event. This event is triggered when CollectFeaturesTask creates a list of built-in geometry collection methods. This is the only extensible point where adding and removing geometry collection methods are possible. Later on, although you can still get the collection that holds all geometry collection methods, you won't be able to add or remove geometry collection methods to the collection.

Add a custom geometry collection method

The location group on the EditFeatureAttributesPage on the Windows platform is not removable. You can get a collection of attribute groups for a current feature, but this collection doesn't contain the location group. This is different from the application programming interface (API) on the Windows Mobile platform where the Location group is replaceable. Therefore, on the Windows platform, to customize a geometry collection, do not replace the built-in Location group. Instead, create a custom geometry collection method that inherits GeometryCollectionMethod. To add or remove geometry collection methods to a tablet app, listen to CollectFeaturesTask.EditFeatureAttributesPage.EditFeatureAttributesViewModel.

Create the GeometryCollectionMethods event

This is the extensible point where you can add and remove a geometry collection method, whether it's built-in or custom. Afterwards, although you can still get a collection of GeometryCollectionMethods, you won't be able to change the collection. The Sketch geometry collection method, however, cannot be removed.

_editFeatureAttributesViewModel = new EditFeatureAttributesViewModel(_feature);
_editFeatureAttributesViewModel.CreatingGeometryCollectionMethods += new EventHandler<CreatingGeometryCollectionMethodsEventArgs>(_editFeatureAttributesViewModel_CreatingGeometryCollectionMethods);
_editFeatureAttributesPage = new EditFeatureAttributesPage(_editFeatureAttributesViewModel);

void _editFeatureAttributesViewModel_CreatingGeometryCollectionMethods(object sender, CreatingGeometryCollectionMethodsEventArgs e)
{
 	StringBuilder builder = new StringBuilder();
  builder.AppendLine("Geometry Collection Methods:");
  e.GeometryCollectionMethods.Add(new CustomGeometryCollection());
      // Look through the collection of geometry collection methods and remove
      // the GPS Averaging method.
  for(int i=0;i<e.GeometryCollectionMethods.Count;i++)
  {
     builder.AppendLine(e.GeometryCollectionMethods[i].Name);
     if (e.GeometryCollectionMethods[i] is GpsStreamingGeometryCollectionMethod)
 		    e.GeometryCollectionMethods.Remove(e.GeometryCollectionMethods[i]);
  }
   ESRI.ArcGIS.Mobile.Client.Windows.MessageBox.ShowDialog(builder.ToString());
}

1/7/2015