
本人是silverlight和Arcgis开发的新手,最近因为项目的需要涉及到silverlight和Arcgis的相关开发。写这篇博客的目的一方面是为了总结经验,加深记忆,另一方也是为了能够和网上的高手们多交流。希望看这篇文章的朋友能够不吝赐教。谢谢!
因为项目的成本问题,加上项目本身对功能要求并不是很高,所以我们只能用开源免费的Geoserver作为后台地图服务器。在此要感谢以下几篇博文给我的帮助。
http://www.cnblogs.com/beniao/archive/2011/01/10/1930995.html
http://www.cnblogs.com/wenjl520/archive/2009/06/02/1494149.html
写的非常好。感谢博主!
首先,贴上我的代码:
/// <summary> /// 用arcgis silverlight API 连接Geoserver服务器 /// </summary> public class ArcGisGeoWMSLayer : DynamicMapServiceLayer { public static DependencyProperty URLProperty = DependencyProperty.Register("URL",typeof(string),typeof(ArcGisGeoWMSLayer),new PropertyMetadata("http://localhost:8080/wms",null)); /// <summary> /// GeoServer URI /// </summary> public string URL { get { return (string)GetValue(URLProperty); } set { SetValue(URLProperty,value); } } public static DependencyProperty LayernameProperty = DependencyProperty.Register("Layer",new PropertyMetadata(string.Empty,null)); /// <summary> /// Layer name /// </summary> public string Layer { get { return (string)GetValue(LayernameProperty); } set { SetValue(LayernameProperty,value); } } public static DependencyProperty ExtentProperty = DependencyProperty.Register("Extent",typeof(Envelope),new PropertyMetadata(((object)new Envelope(0,0)),OnExtentPropertyChanged)); private static voID OnExtentPropertyChanged(DependencyObject dp,DependencyPropertyChangedEventArgs e) { } /// <summary> /// 地图边界范围(从geoserver发布地图时可以获取) /// </summary> public Envelope Extent { get { return (Envelope)GetValue(ExtentProperty); } set { SetValue(ExtentProperty,value); this.FullExtent = Extent; } } public overrIDe voID GetUrl(Envelope extent,int wIDth,int height,OnUrlComplete onComplete) { int extentWKID = extent.SpatialReference.WKID; StringBuilder mapURL = new StringBuilder(); mapURL.Append(URL); mapURL.Append("?service=WMS"); mapURL.AppendFormat("&version={0}","1.1.0"); mapURL.Append("&request=GetMap"); mapURL.AppendFormat("&layers={0}",Layer); mapURL.Append("&styles="); mapURL.AppendFormat("&bBox={0},{1},{2},{3}",extent.XMin.ToString(),extent.YMin.ToString(),extent.XMax.ToString(),extent.YMax.ToString()); mapURL.AppendFormat("&wIDth={0}",wIDth); mapURL.AppendFormat("&height={0}",height); mapURL.AppendFormat("&format={0}","image/png"); onComplete(mapURL.ToString(),wIDth,height,new ESRI.ArcGIS.ClIEnt.Geometry.Envelope() { XMin = extent.XMin,YMin = extent.YMin,XMax = extent.XMax,YMax = extent.YMax }); } }
其实原理很简单,geoserver 发布的是未经缓存的地图服务,因此需要从DynamicMapServiceLayer继承,重写GetUrl即可。需要注意的是,在初始化类的时候,需要将地图的extent赋给FullExtent属性,否则地图无法正常显示:
前台XAML代码:
<UserControl x:Class="ArcGisSlGeoDemo.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" xmlns:esri="http://schemas.esri.com/arcgis/clIEnt/2009" xmlns:customLayer="clr-namespace:ArcGisSlGeoDemo" mc:Ignorable="d" d:DesignHeight="300" d:DesignWIDth="400"> <GrID x:name="LayoutRoot" Background="White"> <esri:Map x:name="baseMap" IslogoVisible="False"> <customLayer:ArcGisGeoWMSLayer URL="http://localhost:8080/geoserver/wms" Layer="JianxiYP:JiangxiYP" ID="geolayer"></customLayer:ArcGisGeoWMSLayer> </esri:Map> </GrID></UserControl>
注意要给Extent赋值,这个是地图边界范围,在geoserver发布地图的时候我从geoserver里面直接读取出来的边界范围。
MainPage.cs
public MainPage() { InitializeComponent(); Envelope extent = new Envelope(73580,20411.591,75418.814,21975.971); extent.SpatialReference = new SpatialReference(4326); ArcGisGeoWMSLayer layer = this.baseMap.Layers[0] as ArcGisGeoWMSLayer; layer.Extent = extent; } 总结 以上是内存溢出为你收集整理的用arcgis的silverlight API连接Geoserver全部内容,希望文章能够帮你解决用arcgis的silverlight API连接Geoserver所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)