Select to view content in your preferred language

Map.MouseMove Event issues

2155
4
09-21-2010 04:46 AM
jonataspovoas
Regular Contributor
Hi,

I'm making a funcion to show the mouse position on the map, but I'm having trouble fixing the following problem.

If the user moves the mouse through the application before it finishes loading, this error occurs:
Runtime Error in Microsoft JScript: Unhandled Error in Silverlight Application Object reference not set to an instance of an object. 
   in MDSalvador.MainPage.Mapa_MouseMove (Object sender, MouseEventArgs e)
   in MS.Internal.CoreInvokeHandler.InvokeEventHandler (Int32 typeIndex, handlerDelegate Delegate, Object sender, Object args)
   in MS.Internal.JoltHelper.FireEvent (unmanagedObj IntPtr, IntPtr unmanagedObjArgs, argsTypeIndex Int32, String eventName)


I'm basicaly using the function shown here : http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#MouseCoords except for that i'm showing only the coordinates of the map.
0 Kudos
4 Replies
JenniferNery
Esri Regular Contributor
I'm not able to replicate the issue using the SDK sample. What might be causing delay loading the map? I tried moving the mouse while the map is still loading and I do not get object reference not set to an instance exception. Have you tried setting breakpoint in the MouseMove event handler?
0 Kudos
AliMirzabeigi
Emerging Contributor
Add the following on your page constructor. MyMap is your map control:
MyMap.Layers.LayersInitialized += new ESRI.ArcGIS.Client.LayerCollection.LayersInitializedHandler(Layers_LayersInitialized);


The LayersInitialized event handler will hook up the mouse move handler of your map control:
private void Layers_LayersInitialized(object sender, EventArgs args)
{
   MyMap.MouseMove += new MouseEventHandler(MyMap_MouseMove);
}
0 Kudos
jonataspovoas
Regular Contributor
Add the following on your page constructor. MyMap is your map control:
MyMap.Layers.LayersInitialized += new ESRI.ArcGIS.Client.LayerCollection.LayersInitializedHandler(Layers_LayersInitialized);


The LayersInitialized event handler will hook up the mouse move handler of your map control:
private void Layers_LayersInitialized(object sender, EventArgs args)
{
   MyMap.MouseMove += new MouseEventHandler(MyMap_MouseMove);
}


Thanks a lot, this solved the problem 🙂
0 Kudos
AliMirzabeigi
Emerging Contributor
Great! Just a quick comment that you should also make sure that you are not hooking up the map's MouseMove event handler more than once. This could be the case where you have a GraphicsLayer that could be initialized later in your application.
0 Kudos