Select to view content in your preferred language

Zoom To Layer Capability in TOC

3683
18
01-20-2011 07:25 AM
PaulHuppé
Deactivated User
Hi,
I am trying to add a zoom-to individual layers inside a map service.  In my Legend template, I added an image to represent the zoom action and I wanted to add an event trigger that would automatically zoom to the extent of that layer.  Something like:

<Image Source="images/zoom.png">
    <i:Interaction.Triggers>
          <i:EventTrigger EventName="Click">
                   <esri:ZoomToAction TargetName="Map">
                           <esri:ZoomToAction.Geometry>

                                  Use some binding here to get the envelope

                           </esri:ZoomToAction.Geometry>
                    </esri:ZoomToAction>
          </i:EventTrigger>
   </i:Interaction.Triggers>
</Image>


But, when I try to add this, I get a message saying "A value of type 'ZoomToAction' cannot be added to a collection or dictionary of type 'TriggerActionCollection'."  Can't I do this?  There is something similar done in the online samples that zoom-to a hardcoded envelope. Here is the code that is used:

                    <Button Style="{StaticResource MenuItem}" 
                            Content="Zoom To" >
                        <i:Interaction.Triggers>
                            <i:EventTrigger EventName="Click">
                                <esri:ZoomToAction
                                    TargetName="MyMap">
                                    <esri:ZoomToAction.Geometry>
                                        <esri:Envelope XMin="-14930991.170" YMin="3611744.037" XMax="-11348896.882" YMax="5340571.181" />
                                    </esri:ZoomToAction.Geometry>
                                </esri:ZoomToAction>
                            </i:EventTrigger>
                        </i:Interaction.Triggers>
                    </Button>


There is another sample that zooms to a service layer.

                    <Button Style="{StaticResource MenuItem}" 
                            Content="Zoom To Layer" >
                        <i:Interaction.Triggers>
                            <i:EventTrigger EventName="Click">
                                <esri:ZoomToLayerAction
                                    LayerID="MyFeatureLayer"
                                    TargetName="MyMap" />
                            </i:EventTrigger>
                        </i:Interaction.Triggers>
                    </Button>



I am using the Legend control in the 2.1 API.
Paul
0 Kudos
18 Replies
DominiqueBroux
Esri Frequent Contributor

A value of type 'ZoomToAction' cannot be added to a collection or dictionary of type 'TriggerActionCollection'

I already ran into this kind of problem when I was not referencing the most up to date  System.Windows.Interactivity.dll.
Which version are you referencing?
0 Kudos
PaulHuppé
Deactivated User
Hi,
The properties say I am using version 4.0.5.0
0 Kudos
DominiqueBroux
Esri Frequent Contributor
And what is the file version? Mine is 2.0.20525
0 Kudos
PaulHuppé
Deactivated User
Mine is 2.0.50727
0 Kudos
PaulHuppé
Deactivated User
Actually, the version I reported was what Visual Studio calls the Runtime Version.  If I go in Explorer, it tells me that the file version is 2.0.20520.0.
0 Kudos
PaulHuppé
Deactivated User
Do you think I should try removing all the Silverlight stuff and the ArcGIS Silverlight API and reinstall them all?
0 Kudos
DominiqueBroux
Esri Frequent Contributor
Do you think I should try removing all the Silverlight stuff and the ArcGIS Silverlight API and reinstall them all?


I don't think it's needed but the problem is that I have no clue:confused:

I know that this already happened to me and it magically ended up working but no idea how.
Perhaps try to clean your project, remove bin and obj directories, reexecute VS2010,  ...... but no guarantee, sorry.
0 Kudos
PaulHuppé
Deactivated User
Hi,

I went ahead and removed/reinstalled all Silverlight components.  Same problem.  I do get an errors when I compile:

Error 6 The tag 'ZoomToLayerAction' does not exist in XML namespace 'http://schemas.esri.com/arcgis/client/2009'.

Error 7 A value of type 'ZoomToLayerAction' cannot be added to a collection or dictionary of type 'TriggerActionCollection'.

The namespace error I find strange because that is the same namespace used in the online samples.

Paul
0 Kudos
PaulHuppé
Deactivated User
Ok, I found the problem.  In my references, the one for ESRI.ArcGIS.Client.Behaviors was still using the 2.0.x version instead of the 2.1.x version.  Now, I do not have errors any more when I try to add the trigger.

But, the trigger does not seem to do anything.  here is the complete code for the Legend control so far with the trigger part in bold:

                <esri:Legend x:Name="legendMap" Map="{Binding ElementName=Map}"
                             LayerItemsMode="Tree"
                             ShowOnlyVisibleLayers="False"
                             Refreshed="Legend_Refreshed"
                             Width="300" Height="300">
                    <esri:Legend.MapLayerTemplate>
                        <DataTemplate>
                            <StackPanel Orientation="Horizontal">
                                <CheckBox Content="{Binding Label}"
                  IsChecked="{Binding IsEnabled, Mode=TwoWay}"
                  IsEnabled="{Binding IsInScaleRange}" >
                                </CheckBox>
                                <Slider Maximum="1" Value="{Binding Layer.Opacity, Mode=TwoWay}" Width="30" />
                            </StackPanel>
                        </DataTemplate>
                    </esri:Legend.MapLayerTemplate>
                    <esri:Legend.LayerTemplate>
                        <DataTemplate>
                            <StackPanel Orientation="Horizontal">
                                <CheckBox
                  IsChecked="{Binding IsEnabled, Mode=TwoWay}"
                  IsEnabled="{Binding IsInScaleRange}" >
                                </CheckBox>
                                <Image Source="images/zoom.png"
                                       ToolTipService.ToolTip="Zoom">
                                    <i:Interaction.Triggers>
                                        <i:EventTrigger EventName="MouseLeftButtonDown">
                                            <esri:ZoomToLayerAction
                                                    LayerID="{Binding Label}"
                                                    TargetName="Map" />
                                        </i:EventTrigger>
                                    </i:Interaction.Triggers>
                                </Image>
                                <RadioButton IsChecked="False"
                                             Checked="RadioButton_Checked"
                                             GroupName="grpLayers"
                                             Tag="{Binding Label}"
                                             Content="{Binding Label}" >
                                </RadioButton>
                            </StackPanel>
                        </DataTemplate>
                    </esri:Legend.LayerTemplate>
                </esri:Legend>


Question: Does the ZoomToLayerAction work only for a Feature layer, or should it also work for any layer in a ArcGISDynamicMapServiceLayer?
0 Kudos