Select to view content in your preferred language

navigation issues

1412
5
06-30-2010 04:50 AM
LanceCrumbliss
Frequent Contributor
hi all, i've got a user control (code attached) that was working just fine in the pre-RC of the API (it is in fact almost entirely built on the sample here http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#Navigation), but now will throw an error when following these steps after starting the app:

1) pressing the zoom in tool
2) using the zoom in tool to zoom in
3) pressing the pan tool
4) pressing the zoom in tool again.

and will occur at the highlighted line in the sub below

 Private Sub ToolButton_Clicked(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs)
  If _bDrawObjectInitialized = False Then
   _DrawObject = New Draw(Map) With {.DrawMode = DrawMode.Rectangle, .FillSymbol = DefaultFillSymbol}
   AddHandler _DrawObject.DrawComplete, AddressOf _DrawObject_DrawComplete
   _bDrawObjectInitialized = True
  End If

  Dim Btn As Button = sender

  For Each childBtn As Button In ToolsPanel.Children
   If childBtn.Name <> Btn.Name Then
    childBtn.Background = _OriginalButtonBackground
   End If
  Next

  Btn.Background = ToggleGradient 'New SolidColorBrush(Color.FromArgb(128, 0, 255, 0))

  Dim ToolName As String = Btn.Name

        Select Case ToolName
            Case "Pan"
                _DrawObject.IsEnabled = False
                DrawActive = False
                _toolmode = "pan"
            Case "ZoomInTool"
                _DrawObject.IsEnabled = True
                DrawActive = True
                _toolmode = "zoomin"
            Case "ZoomOutTool"
                _DrawObject.IsEnabled = True
                DrawActive = True
                _toolmode = "zoomout"
        End Select

 End Sub


the short version of the error is

Object reference not set to an instance of an object.


and the long one is

{System.NullReferenceException: Object reference not set to an instance of an object.
   at ESRI.ArcGIS.Client.LayerCanvas.PrepareAnimation()
   at ESRI.ArcGIS.Client.Map.beginZoomToExtent(Envelope targetExtent, Boolean skipAnimation)
   at ESRI.ArcGIS.Client.Map.zoomToResolution(Double resolution, MapPoint center, Boolean skipAnimation)
   at ESRI.ArcGIS.Client.Map.ZoomToResolution(Double resolution, MapPoint center)
   at ESRI.ArcGIS.Client.Map.ZoomToResolution(Double resolution)
   at ESRI.ArcGIS.Client.Map.Layers_LayersInitialized(Object sender, EventArgs args)
   at ESRI.ArcGIS.Client.LayerCollection.calculateLevelScheme()
   at ESRI.ArcGIS.Client.LayerCollection.LayerCollection_CollectionChanged(Object sender, NotifyCollectionChangedEventArgs e)
   at System.Collections.Specialized.NotifyCollectionChangedEventHandler.Invoke(Object sender, NotifyCollectionChangedEventArgs e)
   at System.Collections.ObjectModel.ObservableCollection`1.OnCollectionChanged(NotifyCollectionChangedEventArgs e)
   at System.Collections.ObjectModel.ObservableCollection`1.InsertItem(Int32 index, T item)
   at System.Collections.ObjectModel.Collection`1.Add(T item)
   at ESRI.ArcGIS.Client.Draw.Activate()
   at ESRI.ArcGIS.Client.Draw.OnIsEnabledPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
   at System.Windows.DependencyObject.RaisePropertyChangeNotifications(DependencyProperty dp, Object oldValue, Object newValue)
   at System.Windows.DependencyObject.UpdateEffectiveValue(DependencyProperty property, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, ValueOperation operation)
   at System.Windows.DependencyObject.SetValueInternal(DependencyProperty dp, Object value, Boolean allowReadOnlySet)
   at System.Windows.DependencyObject.SetValue(DependencyProperty dp, Object value)
   at ESRI.ArcGIS.Client.Draw.set_IsEnabled(Boolean value)
   at CHFMap09.NavBar.ToolButton_Clicked(Object sender, RoutedEventArgs e)
   at System.Windows.Controls.Primitives.ButtonBase.OnClick()
   at System.Windows.Controls.Button.OnClick()
   at System.Windows.Controls.Primitives.ButtonBase.OnMouseLeftButtonUp(MouseButtonEventArgs e)
   at System.Windows.Controls.Control.OnMouseLeftButtonUp(Control ctrl, EventArgs e)
   at MS.Internal.JoltHelper.FireEvent(IntPtr unmanagedObj, IntPtr unmanagedObjArgs, Int32 argsTypeIndex, String eventName)}
0 Kudos
5 Replies
DominiqueBroux
Esri Frequent Contributor
Looks the same error than http://forums.arcgis.com/threads/7242-Exception-on-Draw.IsEnabled-true

From my tests, it could happen more frequently if SnapToLevels map property is set to true.
Is it your case?
If it is, a workaround might to set SnapToLevels to false.
0 Kudos
LanceCrumbliss
Frequent Contributor
Looks the same error than http://forums.arcgis.com/threads/7242-Exception-on-Draw.IsEnabled-true

From my tests, it could happen more frequently if SnapToLevels map property is set to true.
Is it your case?
If it is, a workaround might to set SnapToLevels to false.


hm, yes...it does seem to only happen when SnapToLevels is true.  is this a bug?  again, this didn't happen with the previous build of the API.  it just started happening with the RC.

i'd rather not have to settle on always having SnapToLevels set to true.  There are some tiled layers in the map, and they can look quite nasty when between LODs.  Is there a real fix?

lance
0 Kudos
LanceCrumbliss
Frequent Contributor
OK, i got around it by turning SnapToLevels to false before enabling the draw object.  for the record, this sill seems like a bug.

 Private Sub ToolButton_Clicked(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs)
  If _bDrawObjectInitialized = False Then
   _DrawObject = New Draw(Map) With {.DrawMode = DrawMode.Rectangle, .FillSymbol = DefaultFillSymbol}
   AddHandler _DrawObject.DrawComplete, AddressOf _DrawObject_DrawComplete
   _bDrawObjectInitialized = True
  End If

        Dim Btn As Button = sender

  For Each childBtn As Button In ToolsPanel.Children
   If childBtn.Name <> Btn.Name Then
    childBtn.Background = _OriginalButtonBackground
   End If
  Next

  Btn.Background = ToggleGradient 'New SolidColorBrush(Color.FromArgb(128, 0, 255, 0))

        Dim ToolName As String = Btn.Name
        Dim bSavedSnapValue As Boolean = Map.SnapToLevels
        Map.SnapToLevels = False

        Select Case ToolName
            Case "Pan"
                _DrawObject.IsEnabled = False
                DrawActive = False
                _toolmode = "pan"
            Case "ZoomInTool"
                _DrawObject.IsEnabled = True
                DrawActive = True
                _toolmode = "zoomin"
            Case "ZoomOutTool"
                _DrawObject.IsEnabled = True
                DrawActive = True
                _toolmode = "zoomout"
        End Select

        Map.SnapToLevels = bSavedSnapValue
 End Sub
0 Kudos
egismazeika
Emerging Contributor
Looks the same error than http://forums.arcgis.com/threads/7242-Exception-on-Draw.IsEnabled-true

From my tests, it could happen more frequently if SnapToLevels map property is set to true.
Is it your case?
If it is, a workaround might to set SnapToLevels to false.


Dominique, it IS the same case and we need a real fix.
0 Kudos
DominiqueBroux
Esri Frequent Contributor
The fix should be in 2.0 final (to confirm by Morten).
0 Kudos