arcgis for silverlight 控制图层显示级别
在GIS项目中,如果加载两个图层,一个为切片图层(做为底图),另一个为动态图层,动态图层一般没有设置能够缩放到的比例,就会出现底图空白的情况,那么,是什么原因出现底图为空白的呢?
切片图层早已规定好能够达到的最大比例尺以及最小比例尺,级别已经是固定的了。所以在动态底图里面放大或缩小时就会出现空白。
解决方式:
根据切片图层来控制整个地图能够进行放大或缩小的范围:重载ArcGISTiledMapServiceLayer类
后台代码:
public class ControlArcGiSTitleLayerLevel : ArcGISTiledMapServiceLayer { //最小Level private int MinLevel = 0; //最大Level private int MaxLevel = 1; //目前使用的rest服务共有11个级别 MaxLevel 最大可到10 public override void Initialize() { base.Initialize(); //实际使用中可以不注册此事件 ,只是看Level数值 this.TileLoading -= new EventHandler<TileLoadEventArgs>(ControlArcGiSTitleLayerLevel_TileLoading); this.TileLoading += new EventHandler<TileLoadEventArgs>(ControlArcGiSTitleLayerLevel_TileLoading); this.Map.Loaded -= new RoutedEventHandler(Map_Loaded); this.Map.Loaded += new RoutedEventHandler(Map_Loaded); } void Map_Loaded(object sender, RoutedEventArgs e) { //this.TileInfo.Lods 代表有多少个Level级别 //控制 Lod[] lod = this.TileInfo.Lods.Clone() as Lod[]; Lod[] newlod = new Lod[MaxLevel + 1]; //Resolution 随着比例尺的逐渐变大而更小 for (int i = 0; i < newlod.Length; i++) { newlod[i] = lod[i]; if (i == MinLevel) //Resolution 随着Level的逐渐变大而更小 所以Level越小 Resolution 越大 this.Map.MaximumResolution = lod[i].Resolution; if (i == MaxLevel) //Resolution 随着Level的逐渐变大而更小 所以Level越大 Resolution 越小 this.Map.MinimumResolution = lod[i].Resolution; } this.TileInfo.Lods = newlod; } void ControlArcGiSTitleLayerLevel_TileLoading(object sender, TiledLayer.TileLoadEventArgs e) { string message = string.Concat("Level:", e.Level, ",Scale:", this.Map.Scale, ",Resolution:", this.Map.Resolution); System.Diagnostics.Debug.WriteLine(message); } }
Xaml:
<UserControl x:Class="ControlMapLevel.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:esri="clr-namespace:ESRI.ArcGIS.Client;assembly=ESRI.ArcGIS.Client" xmlns:local="clr-namespace:ControlMapLevel" d:DesignHeight="300" d:DesignWidth="400"> <Grid x:Name="LayoutRoot" Background="White"> <esri:Map x:Name="mapctl"> <esri:Map.Layers> <local:ControlArcGiSTitleLayerLevel Url="http://localhost/arcgis/rest/services/ScSummaryService/MapServer"></local:ControlArcGiSTitleLayerLevel> <esri:ArcGISDynamicMapServiceLayer Url="http://localhost/arcgis/rest/services/testdymic/MapServer"></esri:ArcGISDynamicMapServiceLayer> </esri:Map.Layers> </esri:Map> </Grid> </UserControl>