Can't refresh the ServiceUri property for extent using .Net SDK.

3840
1
09-26-2014 09:59 PM
RebeccaFyfe
New Contributor

When I change the esri:ArcGISTiledMapServiceLayer.ServiceUri property in c# the extent that is current sticks.  Zooming in and out show the new ServiceUri property but zooming back to the initial extent will cause the ServiceUri to revert to its original setting.  I have looked into "refresh" and the like but no luck.  Please help.

public void SetMapType(object sender, RoutedEventArgs e)
        {
            Button test = (Button)sender;

            if(test.Name=="btnImage")
            {
                this.BaseMapName.ServiceUri = "http://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer";
            }
            if (test.Name == "btnRoad")
            {
                this.BaseMapName.ServiceUri = "http://server.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer";
            }
            if (test.Name == "btnTopo")
            {
                this.BaseMapName.ServiceUri = "http://server.arcgisonline.com/ArcGIS/rest/services/World_Topo_Map/MapServer";
            }

}

**********************************************

            <esri:Map x:Name="MyMap">

                    <esri:ArcGISTiledMapServiceLayer x:Name="BaseMapName" ID="BaseMap"

                        ServiceUri = "http://server.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer">                                         

                </esri:ArcGISTiledMapServiceLayer>

                <esri:Map.InitialExtent>

                    <esri:Envelope       XMin="-9556486"

                                         YMin="4312801"

                                         XMax="-9551302"

                                         YMax="4315166">                

                    </esri:Envelope>

                </esri:Map.InitialExtent>

            </esri:Map>

0 Kudos
1 Reply
JenniferNery
Esri Regular Contributor

Hi John,

Thank you for your post. Based on the property you are using, ServiceUri, you might be referring to another product. In the future, please post to: ArcGIS Runtime SDK for .NET

I believe ServiceUri is not a property you can set once the layer is initialized. I tweaked your sample so it can run against latest release 10.2.4.

Also, if you need your base layer to point to a new service endpoint, you need to remove the layer from map before adding a new instance with new ServiceUri. No refresh necessary, the same InitialViewpoint, you've set will be used for the new layer. Note, however that replacing tiled layers like this assume you have matching SpatialReference. In your case, the services were all WKID=3857, which is okay. Otherwise, you will need to clear MapView.SpatialReference also.

       xmlns:esri="http://schemas.esri.com/arcgis/runtime/2013">

    <Grid>

        <esri:MapView x:Name="MyMapView">

            <esri:Map InitialViewpoint="-9556486,4312801,-9551302,4315166">

                <esri:ArcGISTiledMapServiceLayer

                                             ID="BaseMap"

                                             ServiceUri="http://server.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer">

            </esri:ArcGISTiledMapServiceLayer>          

        </esri:Map>

        </esri:MapView>

        <StackPanel Orientation="Horizontal"

                    VerticalAlignment="Top"

                    HorizontalAlignment="Center">

            <Button Content="Image"

                    Click="Button_Click" />

            <Button Content="Road"

                    Click="Button_Click" />

            <Button Content="Topo"

                    Click="Button_Click" />

        </StackPanel>

    </Grid>

private void Button_Click(object sender, RoutedEventArgs e)

        {

            var content = ((Button)sender).Content.ToString();

            var layer = MyMapView.Map.Layers["BaseMap"] as ArcGISTiledMapServiceLayer;

            if (layer != null)

            {

                MyMapView.Map.Layers.Remove(layer);

                layer = new ArcGISTiledMapServiceLayer() { ID = layer.ID };

            }

            switch (content)

            {

                case "Image":

                    {

                        layer.ServiceUri = "http://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer";

                        break;

                    }

                case "Road":

                    {

                        layer.ServiceUri = "http://server.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer";

                        break;

                    }

                case "Topo":

                    {

                        layer.ServiceUri = "http://server.arcgisonline.com/ArcGIS/rest/services/World_Topo_Map/MapServer";

                        break;

                    }

            }

            if (layer != null)

                MyMapView.Map.Layers.Insert(0, layer);

        }

0 Kudos