I am drawing a rectangle to create a bounding box to zoom in to using the TrackOverlay. I have noticed that on occasion, the event fires twice, and I am wondering if it is possibly a bug or a mishap on my code that causes this. I use two Subs to zoom into an area but the AreaZoomTrackEnded sub fires twice on occasion.
I have since added a check for the InternalFeatures of the TrackShapeLayer before continuing to prevent an IndexOutOfRangeException. I would think that removing the handler and turning off the TrackMode would stop it from somehow trying to fire TrackEnded again. If there is something differently that should be done, let me know.
Private
Sub
ZoomToArea(
ByVal
sender
As
Object
,
ByVal
e
As
RoutedEventArgs)
Handles
tbAreaZoomTo.Click
DirectCast
(sender, ToggleButton).IsChecked =
False
'add handler for trackoverlay ended
AddHandler
WpfMap_Main.TrackOverlay.TrackEnded,
AddressOf
AreaZoomTrackEnded
'change the track settings // display and style
WpfMap_Main.TrackOverlay.TrackShapeLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = AreaStyles.CreateSimpleAreaStyle(GeoColor.StandardColors.Transparent, GeoColor.StandardColors.Red, 2, LineDashStyle.Dash)
WpfMap_Main.TrackOverlay.TrackMode = TrackMode.Rectangle
End
Sub
Private
Sub
AreaZoomTrackEnded(
ByVal
sender
As
Object
,
ByVal
e
As
TrackEndedTrackInteractiveOverlayEventArgs)
'check for features in the trackshapelayer, if there are no features, exit the sub and allow for continued drawing
If
WpfMap_Main.TrackOverlay.TrackShapeLayer.InternalFeatures.Count = 0
Then
Exit
Sub
End
If
'remove handler
RemoveHandler
WpfMap_Main.TrackOverlay.TrackEnded,
AddressOf
AreaZoomTrackEnded
'turn off trackmode
WpfMap_Main.TrackOverlay.TrackMode = TrackMode.None
'get the shape
Dim
trackPoly
As
PolygonShape =
DirectCast
(WpfMap_Main.TrackOverlay.TrackShapeLayer.InternalFeatures(0).GetShape, PolygonShape)
'clear the track shapes
WpfMap_Main.TrackOverlay.TrackShapeLayer.InternalFeatures.Clear()
'set the new extent
WpfMap_Main.CurrentExtent = trackPoly.GetBoundingBox
'refresh the map
WpfMap_Main.Refresh()
End
Sub