Customizing GPS averaging and streaming
The GPS averaging and GPS streaming geometry collection methods allow a greater level of customization because a developer can add custom commands (as buttons) directly within the GPS averaging/streaming pages. The GpsAveragingPage and GpsStreamingPage both have a CustomActions property, which is a collection of commands that is shown on the page as a button:
public ObservableCollection<IUICommand> CustomActions { get; }
Adding a custom command to either of these pages can be done as follows:
Steps:
- Listen to the CollectFeaturesTask.GeometryCollectionStarted event.
- In the GeometryCollectionStarted event handler, see whether the GeometryCollectionStartedEventArgs.CollectionMethod parameter is either the GpsAveragingGeometryCollectionMethod or GpsStreamingGeometryCollectionMethod.
- From GpsAveragingGeometryCollectionMethod or GpsStreamingGeometryCollectionMethod in step 2, obtain a reference to GpsAveragingPage or GpsStreamingPage, respectively, using the GeometryCollectionPage property.
- From the page in step 3, add your command to the page's CustomActions collection.
Example extension
The following is an example of an extension that adds a custom command to both the GPS averaging and GPS streaming pages:
public class GpsCustomizationExtension : ProjectExtension { private CollectFeaturesTask _collectFeaturesTask; private GpsAveragingGeometryCollectionMethod _averagingCollectionMethod; private GpsStreamingGeometryCollectionMethod _streamingCollectionMethod; protected override void Initialize() {} protected override void OnOwnerInitialized() { _collectFeaturesTask = MobileApplication.Current.FindTask(typeof(CollectFeaturesTask)) as CollectFeaturesTask; if (_collectFeaturesTask != null) { _collectFeaturesTask.GeometryCollectionStarted += new EventHandler<GeometryCollectionStartedEventArgs>(task_GeometryCollectionStarted); _collectFeaturesTask.GeometryCollectionCompleted += new EventHandler<GeometryCollectionCompletedEventArgs>(_collectFeaturesTask_GeometryCollectionCompleted); } } protected override void Uninitialize() { if (_collectFeaturesTask != null) { _collectFeaturesTask.GeometryCollectionStarted -= new EventHandler<GeometryCollectionStartedEventArgs>(task_GeometryCollectionStarted); _collectFeaturesTask.GeometryCollectionCompleted -= new EventHandler<GeometryCollectionCompletedEventArgs>(_collectFeaturesTask_GeometryCollectionCompleted); _collectFeaturesTask = null; } } void task_GeometryCollectionStarted(object sender, GeometryCollectionStartedEventArgs e) { if (e.CollectionMethod is GpsAveragingGeometryCollectionMethod) { UICommand command = new UICommand("Custom Averaging", param => this.CustomAveragingCommandExecute()); _averagingCollectionMethod = e.CollectionMethod as GpsAveragingGeometryCollectionMethod; _averagingCollectionMethod.GeometryCollectionPage.CustomActions.Add(command); } else if (e.CollectionMethod is GpsStreamingGeometryCollectionMethod) { UICommand command = new UICommand("Custom Streaming", param => this.CustomStreamingCommandExecute()); _streamingCollectionMethod = e.CollectionMethod as GpsStreamingGeometryCollectionMethod; _streamingCollectionMethod.GeometryCollectionPage.CustomActions.Add(command); } } void _collectFeaturesTask_GeometryCollectionCompleted(object sender, GeometryCollectionCompletedEventArgs e) { _averagingCollectionMethod = null; _streamingCollectionMethod = null; } private void CustomAveragingCommandExecute() { System.Text.StringBuilder builder = new System.Text.StringBuilder(); builder.AppendLine("You clicked my custom GPS averaging action"); builder.AppendLine(String.Format("Current Coordinate Index = {0}", _averagingCollectionMethod.Geometry.CurrentCoordinateIndex)); ESRI.ArcGIS.Mobile.Client.Windows.MessageBox.ShowDialog(builder.ToString()); } private void CustomStreamingCommandExecute() { System.Text.StringBuilder builder = new System.Text.StringBuilder(); builder.AppendLine("You clicked my custom GPS streaming action"); builder.AppendLine(String.Format("Current Coordinate Index = {0}", _streamingCollectionMethod.Geometry.CurrentCoordinateIndex)); ESRI.ArcGIS.Mobile.Client.Windows.MessageBox.ShowDialog(builder.ToString()); } }
9/20/2011