I would strongly advise against changing the Url at runtime. Depending on what service you change it to, weird things can happen.Instead remove the layer, create a new instance and add that to the map.
<Grid x:Name="LayoutRoot" Background="White"> <esri:Map x:Name="MyMap" ExtentChanged="MyMap_ExtentChanged"> <esri:ArcGISTiledMapServiceLayer Url="http://server.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer" /> </esri:Map> <Button Content="Replace Layer" Click="Button_Click" VerticalAlignment="Top" HorizontalAlignment="Center"/> </Grid>
private void Button_Click(object sender, RoutedEventArgs e) { ArcGISDynamicMapServiceLayer dynamic = new ArcGISDynamicMapServiceLayer() { Url = "http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/BloomfieldHillsMichigan/LandusePlanning/MapServer" }; dynamic.Initialize(); ArcGISTiledMapServiceLayer tiledLayer = this.MyMap.Layers[0] as ArcGISTiledMapServiceLayer; if (tiledLayer != null) { this.MyMap.Layers.Remove(tiledLayer); this.MyMap.Layers.Add(dynamic); } } private void MyMap_ExtentChanged(object sender, ESRI.ArcGIS.Client.ExtentEventArgs e) { // placed a breakpoint here to make sure the map's extent still get updated after replacing layer. }
Signed in members can post, follow updates, and more. New here? Register a free account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.