Silverlight使用GeoServer(转载自jxzz016590)
<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>
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; }
///<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", typeof(string), typeof(ArcGisGeoWMSLayer), 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), typeof(ArcGisGeoWMSLayer), new PropertyMetadata(((object)new Envelope(0, 0, 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 }); } }