WebGIS课程设计作业姓名:甄真班级:2011010班专业:地理信息系统指导老师:张俊峰许德合实验步骤:1.代码实现:using System;using System.Collections.Generic;using System.Linq;using ;using System.Windows;using System.Windows.Browser;using System.Windows.Controls;using System.Windows.Documents;using System.Windows.Input;using System.Windows.Media;using System.Windows.Media.Animation;using System.Windows.Markup;using System.Windows.Shapes;using ponentModel;using ESRI.ArcGIS.Client;using System.Windows.Controls.Primitives;using ESRI.ArcGIS.Client.Tasks;using ESRI.ArcGIS.Client.Symbols;using ESRI.ArcGIS.Client.Behaviors;using ESRI.ArcGIS.Client.Geometry;namespace ESRIStandardMapApplication1{public partial class MainPage : UserControl{public MainPage(){InitializeComponent();}属性查询:#region//属º?性?查¨¥询¡¤private void QueryButton_Click(object sender, RoutedEventArgs e) {QueryTask queryTask = newQueryTask("http://zhen-pc/ArcGIS/rest/services/test/MapServer/0");queryTask.ExecuteCompleted += QueryTask_ExecuteCompleted;queryTask.Failed += QueryTask_Failed;ESRI.ArcGIS.Client.Tasks.Query query = new ESRI.ArcGIS.Client.Tasks.Query(); query.Text = StateNameTextBox.Text;query.OutFields.Add("*");queryTask.ExecuteAsync(query);}void QueryTask_ExecuteCompleted(object sender,ESRI.ArcGIS.Client.Tasks.QueryEventArgs args)//在¨²查¨¥询¡¤完ª¨º成¨¥后¨®触䣤发¤¡é的Ì?事º?件t{FeatureSet featureSet = args.FeatureSet;if (featureSet != null && featureSet.Features.Count > 0){List<QueryResultData> resultList = new List<QueryResultData>();foreach (Graphic feature in featureSet.Features){resultList.Add(new QueryResultData(){Id = feature.Attributes["Id"].ToString(),FID = feature.Attributes["FID"].ToString(),Area = feature.Attributes["Area"].ToString(),Name = feature.Attributes["Name"].ToString(),});}QueryDetailsDataGrid.ItemsSource = resultList;}else{MessageBox.Show("No features returned from query");}}private void QueryTask_Failed(object sender, TaskFailedEventArgs args)//在¨²查¨¥询¡¤失º¡ì败㨹{MessageBox.Show("Query execute error: " + args.Error);}public class QueryResultData{public string Id { get; set; }public string FID { get; set; }public string Area { get; set; }public string Name { get; set; }}#endregion书签管理:private void FeatureLayer_MouseLeftButtonUp(object sender, GraphicMouseButtonEventArgs e) {e.Graphic.Selected = !e.Graphic.Selected;e.Graphic.Selected = true;//获?取¨?选?择?要©a素?if (e.Graphic.Selected == true){//控?件t数ºy据Y源¡ä绑㨮定¡§//IdentifyDetailsDataGrid.ItemsSource = e.Graphic.Attributes;}//将?该?要©a素?平?移©?至¨¢屏¨¢幕?中D心?Map.PanTo(e.Graphic.Geometry);}打开属性表:#region //属º?性?表À¨ªprivate void btnAttributeMenu_Click(object sender, RoutedEventArgs e){string url = "http://zhen-pc/ArcGIS/rest/services/test/MapServer/0";QueryTask queryTask = new QueryTask(url);queryTask.ExecuteCompleted += TableQueryTask_ExecuteCompleted;queryTask.Failed += TableQueryTask_Failed;ESRI.ArcGIS.Client.Tasks.Query query = new ESRI.ArcGIS.Client.Tasks.Query(); query.Where = "1=1";query.OutFields.Add("*");queryTask.ExecuteAsync(query);}void TableQueryTask_ExecuteCompleted(object sender,ESRI.ArcGIS.Client.Tasks.QueryEventArgs args){FeatureSet featureSet = args.FeatureSet;if (featureSet != null && featureSet.Features.Count > 0){List<TableResultData> resultList = new List<TableResultData>();foreach (Graphic feature in featureSet.Features){resultList.Add(new TableResultData(){FID = feature.Attributes["FID"].ToString(),ID = feature.Attributes["Id"].ToString(),Area = feature.Attributes["Area"].ToString(),Name =feature.Attributes["Name"].ToString(),});}TableDataGrid.ItemsSource = resultList;}else{MessageBox.Show("No features returned from query");}}private void TableQueryTask_Failed(object sender, TaskFailedEventArgs args) {MessageBox.Show("Query execute error: " + args.Error);}public class TableResultData{public string FID { get; set; }public string Name { get; set; }public string ID { get; set; }public string Area { get; set; }public string Length { get; set; }}#endregion长度量算:#region //长¡è度¨¨量¢?算?private void btnMeasureMenu_Click(object sender, RoutedEventArgs e){Measure();}private Draw MeaMyDrawObject;public void Measure(){MeaMyDrawObject = new Draw(Map){DrawMode = DrawMode.Polyline,IsEnabled = true,LineSymbol = LayoutRoot.Resources["DrawLineSymbol"] asESRI.ArcGIS.Client.Symbols.LineSymbol};MeaMyDrawObject.DrawComplete += LineMyDrawObject_DrawComplete;MeaMyDrawObject.DrawBegin += MeaMyDrawObject_DrawBegin;}private void LineMyDrawObject_DrawComplete(object sender, DrawEventArgs args) {ESRI.ArcGIS.Client.Geometry.Polyline polyline = args.Geometry asESRI.ArcGIS.Client.Geometry.Polyline;polyline.SpatialReference = Map.SpatialReference;Graphic graphic = new Graphic(){Symbol = LayoutRoot.Resources["DrawLineSymbol"] asESRI.ArcGIS.Client.Symbols.Symbol,Geometry = polyline};GeometryService geometryService =newGeometryService("http://zhen-pc/ArcGIS/rest/services/Geometry/GeometryServer");geometryService.LengthsCompleted += GeometryService_LengthsCompleted;geometryService.Failed += GeometryService_Failed;GraphicsLayer graphicsLayer = yers["Attribute"] as GraphicsLayer; graphicsLayer.Graphics.Add(graphic);geometryService.LengthsAsync(graphicsLayer.Graphics.ToList(), LinearUnit.SurveyMile, CalculationType.Geodesic, null);}private void MeaMyDrawObject_DrawBegin(object sender, EventArgs args){GraphicsLayer graphicsLayer = yers["Attribute"] as GraphicsLayer; graphicsLayer.Graphics.Clear();}private void GeometryService_LengthsCompleted(object sender,ESRI.ArcGIS.Client.Tasks.LengthsEventArgs args){//ResponseTextBlock.Text =//String.Format("所¨´测a得Ì?的Ì?折?线?长¡è度¨¨为a {0} 米¡Á",Math.Round(args.Results[0], 3));MessageBox.Show(String.Format("所¨´测a得Ì?的Ì?折?线?长¡è度¨¨为a {0} 米¡Á", Math.Round(args.Results[0], 3)));}private void GeometryService_Failed(object sender, TaskFailedEventArgs e){MessageBox.Show("Geometry Service error: " + e.Error);}#endregion#region#endregion}}2.发布地图服务:打开Arccatalog10,先在GIS服务器下添加ArcGIS Server,添加当地localhost(系统管理员),如图:预览成功3.登陆ArcGIS Server Manager界面,成功后在service栏下的manage services中查看发布是否成功。