效果图如下:
上代码:
<UserControl x:Class="SYIT.MainPage" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" xmlns:ic="http://schemas.supermap.com/iclient/2010" xmlns:is="http://schemas.supermap.com/isdotnet/2010" xmlns:local="clr-namespace:SYIT.CommonClass" d:DesignHeight="300" d:DesignWidth="400"> <Grid x:Name="LayoutRoot" Background="White"> <ic:Map x:Name="myMap" ViewBoundsChanged="myMap_ViewBoundsChanged"> <local:TiledTDTMapsLayer ID="layer1" IsMarks="False" Mode="Vector"></local:TiledTDTMapsLayer> <local:TiledTDTMapsLayer ID="layer2" IsMarks="True" Mode="Vector" ></local:TiledTDTMapsLayer> </ic:Map> <Border Height="30" Width="150" VerticalAlignment="Top" HorizontalAlignment="Right"> <StackPanel Orientation="Horizontal"> <RadioButton Content="矢量地图" Height="20" IsChecked="True" HorizontalAlignment="Left" Name="Vectorradio" GroupName="layertype" VerticalAlignment="Top" Width="68" Checked="Vectorradio_Checked" /> <RadioButton Content="影像地图" Height="20" HorizontalAlignment="Left" Name="aerialradio" GroupName="layertype" VerticalAlignment="Top" Width="68" Checked="aerialradio_Checked" /> </StackPanel> </Border> <TextBlock x:Name="tblCoordinator" HorizontalAlignment="Left" Margin="10,0,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Bottom" Height="19"/> </Grid> </UserControl> using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; using System.Net; using System.Threading; using System.Windows; using System.Windows.Controls; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Animation; using System.Windows.Shapes; using SuperMap.Web.Actions; using SuperMap.Web.Core; using SuperMap.Web.ISDotNET6; using SuperMap.Web.Mapping; using SuperMap.Web.Service; using SYIT.CommonClass; using SYIT.YLZ_ServiceReference; namespace SYIT { public partial class MainPage : UserControl { private double oldScale = new double(); TiledTDTMapsLayer layer_1 = new TiledTDTMapsLayer(); TiledTDTMapsLayer layer_2 = new TiledTDTMapsLayer(); public MainPage() { InitializeComponent(); this.myMap.ViewBounds = new Rectangle2D(new Point2D(117.112306799734, 29.3397854999518), new Point2D(118.981519200236, 30.5753385000023)); layer_1 = myMap.Layers["layer1"] as TiledTDTMapsLayer; layer_2 = myMap.Layers["layer2"] as TiledTDTMapsLayer; myMap.MouseMove += new System.Windows.Input.MouseEventHandler(myMap_MouseMove); } private void Vectorradio_Checked(object sender, RoutedEventArgs e) { layer_1.Mode = TiledTDTMapsLayer.LayerType.Vector; layer_2.Mode = TiledTDTMapsLayer.LayerType.Vector; } private void aerialradio_Checked(object sender, RoutedEventArgs e) { layer_1.Mode = TiledTDTMapsLayer.LayerType.Aerial; layer_2.Mode = TiledTDTMapsLayer.LayerType.Aerial; } private void myMap_ViewBoundsChanged(object sender, ViewBoundsEventArgs e) { if (oldScale == 0) { oldScale = Math.Round(myMap.Resolution, 10); } else if (oldScale != Math.Round(myMap.Resolution, 10)) { layer_2.Refresh(); oldScale = Math.Round(myMap.Resolution, 10); } } void myMap_MouseMove(object sender, System.Windows.Input.MouseEventArgs e) { this.tblCoordinator.Text = myMap.ScreenToMap(e.GetPosition(myMap)).ToString(); } } }
using System; using System.Net; using System.Windows; using System.Windows.Controls; using System.Windows.Documents; using System.Windows.Ink; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Animation; using System.Windows.Shapes; using SuperMap.Web.Core; using SuperMap.Web.Mapping; namespace SYIT.CommonClass { public class TiledTDTMapsLayer : TiledCachedLayer { //定义基本URL private string[] subDomains = { "0", "1", "2", "3", "4", "5" }; //道路图层缩放级别2-10的URL private const string VectorGroup1 = "http://tile{0}.tianditu.com/DataServer?T=A0512_EMap&X={1}&Y={2}&L={3}"; //道路图层缩放级别11-13的URL private const string VectorGroup2 = "http://tile{0}.tianditu.com/DataServer?T=B0627_EMap1112&X={1}&Y={2}&L={3}"; //道路图层缩放级别13以上的URL private const string VectorGroup3 = "http://tile{0}.tianditu.com/DataServer?T=siwei0608&X={1}&Y={2}&L={3}"; //影像图层缩放级别2-10的URL private const string AerialGroup1 = "http://tile{0}.tianditu.com/DataServer?T=sbsm0210&X={1}&Y={2}&L={3}"; //影像图层缩放级别11的URL private const string AerialGroupLeve11 = "http://tile{0}.tianditu.com/DataServer?T=e11&X={1}&Y={2}&L={3}"; //影像图层缩放级别12的URL private const string AerialGroupLeve12 = "http://tile{0}.tianditu.com/DataServer?T=e12&X={1}&Y={2}&L={3}"; //影像图层缩放级别13的URL private const string AerialGroupLeve13 = "http://tile{0}.tianditu.com/DataServer?T=e13&X={1}&Y={2}&L={3}"; //影像图层缩放级别14的URL private const string AerialGroupLeve14 = "http://tile{0}.tianditu.com/DataServer?T=eastdawnall&X={1}&Y={2}&L={3}"; //影像图层缩放级别15以上的URL private const string AerialGroupLeve15 = "http://tile{0}.tianditu.com/DataServer?T=sbsm1518&X={1}&Y={2}&L={3}"; //影像图层缩放级别2-10地图标记文字的URL private const string AerialMarksGroup1 = "http://tile{0}.tianditu.com/DataServer?T=A0610_ImgAnno&X={1}&Y={2}&L={3}"; //影像图层缩放级别11-13地图标记文字的URL private const string AerialMarksGroup2 = "http://tile{0}.tianditu.com/DataServer?T=B0530_eImgAnno&X={1}&Y={2}&L={3}"; //影像图层缩放级别13以上地图标记文字的URL private const string AerialMarksGroup3 = "http://tile{0}.tianditu.com/DataServer?T=siweiAnno68&X={1}&Y={2}&L={3}"; //道路图层缩放级别2-10地图标记文字的URL private const string VectorMarks = "http://tile{0}.tianditu.com/DataServer?T=AB0512_Anno&X={1}&Y={2}&L={3}"; //定义是否显示地图标记文字,ture时为文字图层,false为地图图层 public bool IsMarks { get; set; } private double[] scales = null; //定义地图类型的依赖属性 public LayerType Mode { get { return (LayerType)GetValue(MapTypeProperty); } set { SetValue(MapTypeProperty, value); } } public static readonly DependencyProperty MapTypeProperty = DependencyProperty.Register("Mode", typeof(LayerType), typeof(TiledTDTMapsLayer), new PropertyMetadata(new PropertyChangedCallback(new PropertyChangedCallback(OnMapTypePropertyChanged)))); private static void OnMapTypePropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { TiledTDTMapsLayer layer = d as TiledTDTMapsLayer; if (layer.IsInitialized) { layer.ChangeTileSource(); } } //改变地图类型出发刷新 private void ChangeTileSource() { if (!base.IsInitialized) { base.Initialize(); } else { base.Refresh(); } } public TiledTDTMapsLayer() { } public override void Initialize() { this.Url = VectorGroup1; this.Bounds = new Rectangle2D(-179.99999999999997, -90.0, 180.00000000000023, 89.99999999999994); this.Resolutions = new double[] { 0.35156249999999994,0.17578124999999997,0.08789062500000014,0.04394531250000007, 0.021972656250000007,0.01098632812500002,0.00549316406250001,0.0027465820312500017, 0.0013732910156250009,0.000686645507812499,0.0003433227539062495,0.00017166137695312503, 0.00008583068847656251,0.000042915344238281406,0.000021457672119140645,0.000010728836059570307, 0.000005364418029785169 }; base.Initialize(); } //重写返回Url函数 public override string GetTileUrl(int indexX, int indexY, int level) { level += 2; switch (this.Mode) { case LayerType.Vector: if (level >= 13 && level <= 18) { this.Url = VectorGroup3; } if (level >= 11 && level <= 12) { this.Url = VectorGroup2; } if (level >= 2 && level <= 10) { if (this.IsMarks) { this.Url = VectorMarks; } else { this.Url = VectorGroup1; } break; } break; case LayerType.Aerial: if (level >= 2 && level <= 10) { if (IsMarks) { this.Url = AerialMarksGroup1; } else { this.Url = AerialGroup1; } } if (level == 11) { if (IsMarks) { this.Url = AerialMarksGroup2; } else { this.Url = AerialGroupLeve11; } } if (level == 12) { if (IsMarks) { this.Url = AerialMarksGroup2; } else { this.Url = AerialGroupLeve12; } } if (level == 13) { if (IsMarks) { this.Url = AerialMarksGroup2; } else { this.Url = AerialGroupLeve13; } } if (level == 14) { if (IsMarks) { this.Url = AerialMarksGroup2; } else { this.Url = AerialGroupLeve14; } } if (level >= 15) { if (IsMarks) { this.Url = AerialMarksGroup3; } else { this.Url = AerialGroupLeve15; } } break; } return String.Format(this.Url, 1, indexX, indexY, level); } public enum LayerType { Vector, Aerial } } }