When geometry collection begins/ends

Similar to the CollectionStarted/CollectionCompleted events for the collection of a new feature, CollectFeaturesTask also contains events that are raised when the collection of the feature geometry begins (GeometryCollectionStarted) and the collection of the feature geometry is either finished or canceled (GeometryCollectionCompleted):

public event  EventHandler<GeometryCollectionStartedEventArgs>  GeometryCollectionStarted;
public event EventHandler<GeometryCollectionCompletedEventArgs> GeometryCollectionCompleted;

The event argument classes for both events, GeometryCollectionStartedEventArgs and GeometryCollectionCompletedEventArgs, contain a CollectionMethod property that identifies which geometry collection method is used to collect the geometry:

public  GeometryCollectionMethod CollectionMethod { get; protected set; }

The GeometryCollectionCompletedEventArgs class also contains a Canceled property that indicates whether the collection was canceled (true) or successful (false). GeometryCollectionMethod, an abstract class, provides access to both the feature and geometry being collected. The ESRI.ArcGIS.Mobile.Client assembly currently contains three concrete GeometryCollectionMethod classes: SketchGeometryCollectionMethod, GpsAveragingGeometryCollectionMethod, and GpsStreamingGeometryCollectionMethod. Each class has a GeometryCollectionPage property that provides access to that geometry collection methods page, which may also be customized.

The following is an example of an extension that listens to the GeometryCollectionStarted and GeometryCollectionCompleted events:

public class  GeometryMethodCustomizationExtension : ProjectExtension
{
  private CollectFeaturesTask _collectFeaturesTask;

  protected override void Initialize()
  {
  }

  protected override void OnOwnerInitialized()
  {
    _collectFeaturesTask = MobileApplication.Current.FindTask(typeof(CollectFeaturesTask)) as CollectFeaturesTask;
    if (_collectFeaturesTask != null)
    {
      _collectFeaturesTask.GeometryCollectionStarted += new EventHandler<GeometryCollectionStartedEventArgs>(_collectFeaturesTask_GeometryCollectionStarted);
      _collectFeaturesTask.GeometryCollectionCompleted += new EventHandler<GeometryCollectionCompletedEventArgs>(_collectFeaturesTask_GeometryCollectionCompleted);
    }
  }

  protected override void Uninitialize()
  {
    if (_collectFeaturesTask != null)
    {
      _collectFeaturesTask.GeometryCollectionStarted -= new EventHandler<GeometryCollectionStartedEventArgs>(_collectFeaturesTask_GeometryCollectionStarted);
      _collectFeaturesTask.GeometryCollectionCompleted -= new EventHandler<GeometryCollectionCompletedEventArgs>(_collectFeaturesTask_GeometryCollectionCompleted);
      _collectFeaturesTask = null;
    }
  }

  void _collectFeaturesTask_GeometryCollectionStarted(object sender, GeometryCollectionStartedEventArgs e)
  {
    StringBuilder builder = new StringBuilder();
    builder.AppendLine(String.Format("Collecting a new geometry by {0}", e.CollectionMethod.Name));
    builder.AppendLine(String.Format("Feature type = {0}", e.CollectionMethod.Feature.FeatureType.Name));
    ESRI.ArcGIS.Mobile.Client.Windows.MessageBox.ShowDialog(builder.ToString());
  }

  void _collectFeaturesTask_GeometryCollectionCompleted(object sender, GeometryCollectionCompletedEventArgs e)
  {
    StringBuilder builder = new StringBuilder();
    if (e.Canceled)
    {
      builder.AppendLine("Geometry collection has been canceled");
    }
    else
    {
      builder.AppendLine(String.Format("Finished collecting {0} geometry.", e.CollectionMethod.Geometry.GeometryType.ToString()));
      int partCount = 0;
      int coordinateCount = 0;
      foreach (ESRI.ArcGIS.Mobile.Geometries.CoordinateCollection coordinates in e.CollectionMethod.Geometry.Parts)
      {
        partCount++;
        coordinateCount += coordinates.Count;
      }
      builder.AppendLine(String.Format("Geometry contains {0} parts and {1} coordinates total", partCount, coordinateCount));
    }

    ESRI.ArcGIS.Mobile.Client.Windows.MessageBox.ShowDialog(builder.ToString());
  }
}  


9/20/2011