ZoomToLayerAction

1225
12
06-30-2011 01:27 PM
TonyThatcher
New Contributor
For today's challenge....ZoomToLayerAction.

I'm having trouble with using an EventTrigger to fire the esri:ZoomToLayerAction.  I'm trying to implement this in the menu template so that each layer in the menu has a "Zoom To Layer" button associated with it.  I've succeeded in getting the Layer Actions sample to work http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#LayerActions).  But I'm having trouble getting it to work in my application within the menu template.  In order to get the sample to work I had to uninstall all of the Expressions Blend installations and reinstally the Blend 4 SDK.  I also upgraded the API to 2.2 from 2.1.  I don't get any compile errors.

Here's the code from my legend template:
<esri:Legend.MapLayerTemplate>
                                                            <DataTemplate>
                                                                <StackPanel Orientation="Horizontal">
                                                                    <CheckBox Content="{Binding Label}"
                                                  IsChecked="{Binding IsEnabled, Mode=TwoWay}"
                                                  IsEnabled="{Binding IsInScaleRange}" 
                                                                    >
                                                                    </CheckBox>
                                                                    <Image Height="15" Width="15"  Source="/PlacePlay1;component/Assets/Images/InfoTag.png" MouseLeftButtonDown="Image_MouseLeftButtonDown" Tag="{Binding Label}"  />
                                                                    <StackPanel>
                                                                        
                                                                        <Button Content="Zoom" >
                                                                            <i:Interaction.Triggers>
                                                                                <i:EventTrigger EventName="Click">
                                                                                    <esri:ZoomToLayerAction LayerID="MyFeatureLayer" TargetName="MyMap" />
                                                                                </i:EventTrigger>
                                                                            </i:Interaction.Triggers>
                                                                        </Button>
                                                                    </StackPanel>



                                                                    <Slider Maximum="1" Value="{Binding Layer.Opacity, Mode=TwoWay}" Width="50" />
                                                                    <Image Source="{Binding ImageSource}" VerticalAlignment="Center" Height="20" Width="20" Margin="2,0"/>
                                                                </StackPanel>
                                                            </DataTemplate>
                                                        </esri:Legend.MapLayerTemplate>


Right now I'm just using the same MyFeatureLayer as is used in the sample.  The layer is in my map and it is displayed correctly.  When I click on any of the resulting Zoom To Layer buttons in the legend I get the following error in the IE error window:
"Webpage error details

User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; GTB7.1; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; .NET4.0C; .NET4.0E; MS STORE DMC2.6.3411.2)
Timestamp: Thu, 30 Jun 2011 21:22:07 UTC


Message: Unhandled Error in Silverlight Application
Code: 4004   
Category: ManagedRuntimeError      
Message: System.NullReferenceException: Object reference not set to an instance of an object.
   at ESRI.ArcGIS.Client.Actions.ZoomToLayerAction.Invoke(Object parameter)
   at System.Windows.Interactivity.TriggerAction.CallInvoke(Object parameter)
   at System.Windows.Interactivity.TriggerBase.InvokeActions(Object parameter)
   at System.Windows.Interactivity.EventTriggerBase.OnEvent(EventArgs eventArgs)
   at System.Windows.Interactivity.EventTriggerBase.OnEventImpl(Object sender, EventArgs eventArgs)
   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, Int32 actualArgsTypeIndex, String eventName)    

Line: 56
Char: 13
Code: 0
URI: http://localhost:4677/PlacePlay1TestPage.aspx"

An error message also pops up (See attached graphic).

Any thoughts?

-T
0 Kudos
12 Replies
DominiqueBroux
Esri Frequent Contributor
ZoomToLayer should work as soon as the layer returns a full extent in the same coordinates system than the map.

So the problem might be that your map is not in Web Mercator coordinates.

If that's the case, the workarounds are:
    - use a map in web mercator coordinates (generally by setting a basemaplayer in that coordinates system)
or - write your own action that projects the full extent of the layer in the map coordinates
0 Kudos
BarraLoubna
New Contributor
I create a service feature and it works:

http://......./services/Communes_Luxembourg2/FeatureServer/0

I use the projection system of Luxembourg: GCS_Luxembourg_1930.

Which projection you think I should use?
0 Kudos
BarraLoubna
New Contributor
I asked a question in the post: Re:    Zoom To Layer Capability in TOC.

I hope  you have a some time to help me, thank you for your cooperation.
0 Kudos