switch (bingType) { case (BingMapType.Street): thisType = TileLayer.LayerType.Road; break; case (BingMapType.Satellite): thisType = TileLayer.LayerType.Aerial; break; case (BingMapType.Hybrid): thisType = TileLayer.LayerType.AerialWithLabels; break; } _bingLayer = new TileLayer { LayerStyle = thisType, ServerType = ServerType.Production, Token = _config.BingKey, Visible = _baseLayerVisibility, ShowLegend = false };Solved! Go to Solution.
TileLayer _bingLayer;
private void BingRadioButton_Checked(object sender, RoutedEventArgs e)
{
string layerTypeTag = (string)((RadioButton)sender).Tag;
ESRI.ArcGIS.Client.Bing.TileLayer.LayerType layerType = null;
switch (layerTypeTag)
{
case ("Road"):
layerType = TileLayer.LayerType.Road;
break;
case ("Aerial"):
layerType = TileLayer.LayerType.Aerial;
break;
case ("AerialWithLabels"):
layerType = TileLayer.LayerType.AerialWithLabels;
break;
}
if (_map.Layers["_bingLayer"] != null)
{
_acceleratedDisplayLayersGroup.ChildLayers.Remove(_bingLayer);
}
_bingLayer = new TileLayer
{
ID="_bingLayer",
LayerStyle = layerType,
ServerType = ServerType.Production,
Token = "<ENTER TOKEN HERE>",
Visible = true,
ShowLegend = false
};
_acceleratedDisplayLayersGroup.ChildLayers.Add(_bingLayer);
}
<Grid> <esri:Map x:Name="_map" UseAcceleratedDisplay="False"> <esri:AcceleratedDisplayLayers x:Name="_acceleratedDisplayLayersGroup"> </esri:AcceleratedDisplayLayers> </esri:Map> <StackPanel Orientation="Horizontal" HorizontalAlignment="Center"> <RadioButton x:Name="RoadRadioButton" Checked="BingRadioButton_Checked" Tag="Road" IsChecked="true" Margin="5,0,0,0" GroupName="Layers" Content="Road" /> <RadioButton x:Name="AerialRadioButton" Checked="BingRadioButton_Checked" Tag="Aerial" Margin="5,0,0,0" GroupName="Layers" Content="Aerial" /> <RadioButton x:Name="AerialWithLabelsRadioButton" Checked="BingRadioButton_Checked" Tag="AerialWithLabels" Margin="5,0,0,0" GroupName="Layers" Content="Aerial - Labels"/> </StackPanel> </Grid>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using ESRI.ArcGIS.Client.Bing;
using ESRI.ArcGIS.Client;
namespace esritest
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
TileLayer _bingLayer;
AcceleratedDisplayLayers _acceleratedDisplayLayersGroup = new AcceleratedDisplayLayers();
public MainWindow()
{
InitializeComponent();
Loaded += new RoutedEventHandler(MainWindow_Loaded);
}
bool _loaded = false;
void MainWindow_Loaded(object sender, RoutedEventArgs e)
{
map1.Layers.Add(_acceleratedDisplayLayersGroup);
if (map1.Layers["_bingLayer"] != null)
{
_acceleratedDisplayLayersGroup.ChildLayers.Remove(_bingLayer);
}
_bingLayer = new TileLayer
{
ID = "_bingLayer",
LayerStyle = TileLayer.LayerType.Road,
ServerType = ServerType.Production,
Token = "My Key",
Visible = true,
//ShowLegend = false
};
_bingLayer.Initialize();
_acceleratedDisplayLayersGroup.ChildLayers.Add(_bingLayer);
_loaded = true;
}
private void _radioButtonRoad_Checked(object sender, RoutedEventArgs e)
{
if (_loaded)
{
_acceleratedDisplayLayersGroup.ChildLayers.Remove(_bingLayer);
_bingLayer = null;
_bingLayer = new TileLayer
{
ID = "_bingLayer",
LayerStyle = TileLayer.LayerType.Road,
ServerType = ServerType.Production,
Token = "My Key",
Visible = true,
};
_bingLayer.Initialize();
_acceleratedDisplayLayersGroup.ChildLayers.Add(_bingLayer);
}
}
private void _radioButtonAerial_Checked(object sender, RoutedEventArgs e)
{
if (_loaded)
{
_acceleratedDisplayLayersGroup.ChildLayers.Remove(_bingLayer);
_bingLayer = null;
_bingLayer = new TileLayer
{
ID = "_bingLayer",
LayerStyle = TileLayer.LayerType.Aerial,
ServerType = ServerType.Production,
Token = "My Key",
Visible = true,
};
_bingLayer.Initialize();
_acceleratedDisplayLayersGroup.ChildLayers.Add(_bingLayer);
}
}
private void _radioButtonAerialWithLabels_Checked(object sender, RoutedEventArgs e)
{
if (_loaded)
{
_acceleratedDisplayLayersGroup.ChildLayers.Remove(_bingLayer);
_bingLayer = null;
_bingLayer = new TileLayer
{
ID = "_bingLayer",
LayerStyle = TileLayer.LayerType.AerialWithLabels,
ServerType = ServerType.Production,
Token = "My Key",
Visible = true,
};
_bingLayer.Initialize();
_acceleratedDisplayLayersGroup.ChildLayers.Add(_bingLayer);
}
}
}
}