Exception on Draw.IsEnabled = true

2161
18
06-29-2010 02:49 AM
egismazeika
New Contributor
Hi,
I have a Draw object for simple drawing on the map and a Button for enabling it:
ctrlDrawItem.IsEnabled = true;

Sometimes it works as expected but sometimes fails:

{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.LayersInitializedHandler.Invoke(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 ViewPage.EditGeometry()
   at ViewPageXAML.cmdEditGeometry_Click(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)}

Still can't find any workarounds, just restarting the app and hopping that it will work this time.

Using SL 2.0 RC. Any ideas?
0 Kudos
18 Replies
egismazeika
New Contributor
It seems that my issue is related to
http://forums.arcgis.com/threads/7332-navigation-issues

and Draw object often fails when Map.SnapToLevels == true.
0 Kudos
DominiqueBroux
Esri Frequent Contributor
You are right, it is the same issue.

For the moment, the best workaround is to unset SnapToLevels bu it should be fixed for final.
0 Kudos
egismazeika
New Contributor
You are right, it is the same issue.

For the moment, the best workaround is to unset SnapToLevels bu it should be fixed for final.


Thanks, eagerly waiting for the final
0 Kudos
AndyWright
Occasional Contributor
I think I've stumbled on to an issue very closely related to the one in this post.  I have an application that has various tools that have their own draw objects.  I created a draw object manager that handles enabling/disabling these draw objects whenever necessary.  It all works great except for the fact that every time I enable/disable a draw object the map's ExtentChanged event fires and the map gets blurry for a split second.  That blurriness is the only indicator you have that the map extent changed - the map doesn't actually move at all.  So now when I use my zoom next/previous tools they appear to not work, unless you click them multiple times so it can go through all the map extents created when the IsEnabled property on the draw objects gets set. 

I do have SnapToLevels set to true and it does not happen when SnapToLevels is set to false.  We need SnapToLevels to be true though.  Our maps just look a hell of a lot better that way.  The false setting kind of blurs things a little bit.

Is anyone seeing this same behavior?  We are using the 2.1 API by the way.
0 Kudos
AndyWright
Occasional Contributor
I've found a workaround that works about 90% of the time.  Hopefully someone at ESRI can explain why the ExtentChanged event is getting fired when you set the IsEnabled property on a draw object and also why this workaround does not work 100% of the time. 

Inside of my map's ExtentChanged event I am now testing to see if the OldExtent is equal to the NewExtent.  If they are equal I don't add the new extent to the extent collection.  There are still times when I set a draw object IsEnabled where this doesn't work, but most of the time it does.  here's my code ...

if (e.OldExtent.Equals(e.NewExtent))
{
    return;
}


Here are the values for an OldExtent and a NewExtent that didn't work.  Where I come from these are absolutely equal.  What is going on here?

e.OldExtent = {-12460952.8600617,3948499.37002462,-12460530.6649134,3948805.71530195}
e.NewExtent = {-12460952.8600617,3948499.37002462,-12460530.6649134,3948805.71530195}
0 Kudos
JenniferNery
Esri Regular Contributor
When Draw is enabled, map navigation is disabled - you cannot pan or zoom - this is by design since mouse events now are used for drawing not for navigating the map.
You can see that behavior in this sample
http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#DrawGraphics

I cannot replicate the issue by using the sample above and adding a button to disable Draw, ExtentChanged is not fired even when SnapToLevels is True. The difference is this sample works with only one Draw object. I wonder if maybe the issue is with having multiple Draw objects. Can you share some code? Do you mean each button is a different Draw object?
0 Kudos
AndyWright
Occasional Contributor
Jennifer,

Thanks for the reply.  Yeh, we are definitely using multiple draw objects.  Each one of our tools that needs draw object functionality has its own draw object.  I don't know how else we would do it.  When one tool is active it's draw object is enabled and the others are disabled.  Then we can react to the draw object completed event properly for that particular tool.  It is Monday morning so I'm probably not thinking too clearly yet, but I can't see how you could make one draw object work for multiple tools within the same application.  Each of them need to do different things in the draw object completed event, and if that one draw object is always enabled for the different tools then all of their draw object completed events will fire at the same time.  It doesn't seem like that's a valid way to proceed here.  I suppose we could constantly un-subscribe and re-subscribe to the draw object completed events over and over as each tool becomes active and inactive, but that doesn't seem too elegant either.

Are you able to replicate my issue with multiple draw objects in one application?
0 Kudos
AndyWright
Occasional Contributor
Jennifer,

I don't believe this problem is related to having multiple draw objects in the same application.  I've commented out all references to every draw object in my app except for one and I can still get the map extent changed event to fire.  Like you, I haven't been able to replicate this behavior in the sample on ESRI's SL API website.  At this point it feels like one of those needle in a haystack type things.  My app is huge and a lot of things are happening independent of these draw objects that could be contributing to this problem.  Right now I can't say with any certainty that this is an issue with the draw object itself.

Thanks for your help with this Jennifer ...
0 Kudos
AndyWright
Occasional Contributor
Jennifer,

I have stripped out just about everything in my application so that I can zip it all up and send it to you so you can replicate the issue I've described in here.  I also now know exactly what is causing it, but I'm not sure why.  I was hoping you could shed some light on that for me.

Basically when you have SnapToLevels set to true and a min/max resolution set for your map this weird map extent changed behavior happens when you click one of the three buttons at the top left of the app window.  My min/max resolutions are set to exactly match the resolutions of our first and last scale level in our map caches so our users cannot zoom in or out beyond those resolutions when using ESRI services as their basemaps.

If you run the app and click on any of the buttons you will see the map blur slightly.  If you put a break point in the map extent changed event you will see that those button clicks do in fact cause the map extent to change when basically all I am doing is setting a draw object to enabled.  If you take the min/max resolution properties off of the map and run it again, the map extent changed event does not fire.  It also does not fire either way if SnapToLevels is set to false.

So now my only issue is being able to upload my zipped up project file to you.  It is only 1.6MB which is below the allowable threshold for zip files, but then I get this error ...

Request Entity Too Large
The requested resource
/newattachment.php
does not allow request data with POST requests, or the amount of data provided in the request exceeds the capacity limit.

Any ideas on how I can get this file to you?  Can I send you an e-mail?
0 Kudos