Select to view content in your preferred language

Image doesn't display when it's position and the Extent of the Map changed.

676
4
05-26-2010 11:51 PM
hunterruan
Emerging Contributor
Please see the following code:

xaml code:
 <esri:ArcGISTiledMapServiceLayer ID="MyLayer" 
                Url="http://server.arcgisonline.com/ArcGIS/rest/services/ESRI_StreetMap_World_2D/MapServer" />

            <esri:ElementLayer ID="MyElements">
                <esri:ElementLayer.Children>
                    <Button x:Name="RedlandsButton" Width="100" Height="20" Content="ShowImage"  
            esri:ElementLayer.Envelope="-10,10,-10,10" Click="RedlandsButton_Click"
            VerticalAlignment="Center" HorizontalAlignment="Center" ToolTipService.ToolTip="help"
            >
                    </Button>
                    <Image x:Name="Pic" Source="../pin_red.png" Stretch="None" 
                           esri:ElementLayer.Envelope="0,0,0,0" VerticalAlignment="Top" HorizontalAlignment="Left"></Image>


                    <Image x:Name="HoldPic" Source="../pin_red.png" Stretch="Fill" Visibility="Collapsed" 
                           esri:ElementLayer.Envelope="0,0,0,0" VerticalAlignment="Top" HorizontalAlignment="Left"></Image>


                </esri:ElementLayer.Children>
            </esri:ElementLayer>
        </esri:Map>


cs code:
public ElementVisibilityWithMapExtent()
        {
            InitializeComponent();
            LocalMap.Extent = new Envelope(-20,-20,20,20); 
        }

        private void RedlandsButton_Click(object sender, RoutedEventArgs e)
        { 
            Image image = (LocalMap.Layers["MyElements"] as ElementLayer).Children[1] as Image;
            image.Visibility = Visibility.Visible;
            ElementLayer.SetEnvelope(image,new Envelope(-30,30,-30,30));

            //This extent is availble for the map to show the image
            //LocalMap.ZoomTo(new Envelope(-103.0947, -41.07186, 58.95613, 68.22523));

            LocalMap.ZoomTo(new Envelope(-103.0947, 21.07186, 58.95613, 68.22523));
        }


After clicking the Button, the extent of the map is changed but the Image doesn't display on the map.

How can I show the Image successfully?
0 Kudos
4 Replies
dotMorten_esri
Esri Notable Contributor
This line : esri:ElementLayer.Envelope="0,0,0,0" means "show the image at equator/greenwich with the size of the image (which you never set width/height on - you should)". When you change it to -30,30,-30,30, this means its still centered on equator/greenwich, but now 60map units wide and high (width/height of image will be overridden. However you are zooming to -103.0947, 21.07186, 58.95613, 68.22523, which doesn't intersect -30,30,-30,30.

Other things to check: Is your image path correct?
0 Kudos
hunterruan
Emerging Contributor
Thanks for your reply.

The image path is correct and I can see the image if I zoom map to the full extent by mouse before clicking button, this is confusing me also.

I have another idea on the Envelop (-30,30,-30,30) for the Image, I regard it as the position (-30,30) for the Image and it looks like this.

It's easy to test it , could you help me to figure out it?
0 Kudos
dotMorten_esri
Esri Notable Contributor
Before you go down this road, I'm wondering why you are not using a GraphicsLayer ? There's nothing in this post (or your other one) that makes use of something the GraphicsLayer couldn't very easily do.
0 Kudos
hunterruan
Emerging Contributor
Thanks for your suggestion. But I really want to use the ElementLayer and have some Images on the map.
I had tired the GraphicLayer but I didn't find the way to set VerticalAlignment and HorizontalAlignment on the Image symbol and it's not easy to add the Maptips on the Image, I know the way to set the maptips but it is not convenient on my page for some reason.

Thanks anyway. Hope some guy have other good idea.
0 Kudos