Select to view content in your preferred language

Programmatically Change Magnify Glass Tiled Map Service

3134
6
06-23-2010 12:50 AM
CameronIrvine
Emerging Contributor
Can anyone tell me if its possible to change the Tiled Map Service for the Magnifying Glass at runtime?  I have been trying to change the Tiled Map Service in code but it returns an error 'the value is out of range.'

I have found a work around by creating a separate magnifying glass per tiled map service and call it depending on the select tiled map service.  It works but having one magnifying glass that can be changed would be more desirable.

Thanks,
Cameron
0 Kudos
6 Replies
DominiqueBroux
Esri Frequent Contributor
It should work.

I didn't reproduce the issue.
I tested either by changing the Url of the magnifying glass layer or by changing the layer itself (by instantiating a new one). Both works.

How exactly ar you changing the Tiles Map Service? Which version are you using?
0 Kudos
CameronIrvine
Emerging Contributor
Hi Dominque,

I am using version 1.2.0.177

below is the xaml and code behind:


<esriToolkit:MagnifyingGlass x:Name="MyMagnifyingGlass" Visibility="Collapsed"
                                         HorizontalAlignment="Center" VerticalAlignment="Center"
                                         Map="{Binding ElementName=Map}" >
                    <esriToolkit:MagnifyingGlass.Layer>
                        <esri:ArcGISTiledMapServiceLayer ID="ColourMap" Url="http://esridev2ksrv/ArcGIS/rest/services/Maps/ColourMap/MapServer"/>
                    </esriToolkit:MagnifyingGlass.Layer>
                </esriToolkit:MagnifyingGlass>

We added the code in the code behind as:
MyMagnifyingGlass.Layer property was set as

ArcGISTiledMapServiceLayer arcgisLayer = Map.Layers["imagery"] as ArcGISTiledMapServiceLayer;
MyMagnifyingGlass.Layer = arcgisLayer;

This resulted in an application error with a message:  "Value does not fall within the expected range."

I hope that is clear

Thanks!
Cameron
0 Kudos
DominiqueBroux
Esri Frequent Contributor
The magnifying control can't reuse a layer coming from the map (a layer can only be displayed in ONE control).

Instead, create a new layer. Something like:
 
ArcGISTiledMapServiceLayer arcgisLayer = Map.Layers["imagery"] as ArcGISTiledMapServiceLayer;
ArcGISTiledMapServiceLayer arcgisMagnifyingLayer = new ArcGISTiledMapServiceLayer();
arcgisMagnifyingLayer.Url = arcgisLayer.Url;
MyMagnifyingGlass.Layer = arcgisMagnifyingLayer;
 


Or even simpler (depending on your need), you could just change the magnifying layer url:
MyMagnifyingGlass.Layer.Url = arcgisLayer.Url;
0 Kudos
CameronIrvine
Emerging Contributor
Hi Dominque,

For some reason I can't see the url property for layers (see attached image).  I am using version 1.2.0.177.

Any ideas?

Thanks,
Cameron
0 Kudos
DominiqueBroux
Esri Frequent Contributor
My bad. MagnifyingGlass Layer property is of type Layer and not TiledMapServiceLayer --> Need a cast:
 
((ArcGISTiledMapServiceLayer)MyMagnifyingGlass.Layer).Url = .....

Sorry about the mistake.
0 Kudos
CameronIrvine
Emerging Contributor
Thanks Dominique, managed to get it working with your help.
0 Kudos