${IS6_QueryParam_Title}
${IS6_QueryParam_Description}
//SQL查询 private void Query_Click(object sender, RoutedEventArgs e) { string str = MyTextBox.Text; if (str == "") { MessageBox.Show("请输入SQL条件!"); } QueryLayer querylayer = new QueryLayer(); querylayer.LayerName = comboBox.SelectionBoxItem.ToString(); querylayer.WhereClause = str; List<QueryLayer> queryLayers = new List<QueryLayer>() { querylayer }; QueryParam queryParam = new QueryParam() { ExpectCount = 0, StartRecord = 0, QueryLayers = queryLayers }; QueryBySqlParameters parameters = new QueryBySqlParameters { MapName = "changchun", QueryParam = queryParam }; QueryBySqlService queryBySqlService = new QueryBySqlService("http://localhost/IS/AjaxDemo"); queryBySqlService.ProcessAsync(parameters); queryBySqlService.Failed += new EventHandler<ServiceFailedEventArgs>(queryBySqlService_Failed); queryBySqlService.ProcessCompleted += new EventHandler<QueryServiceEventArgs>(queryBySqlService_ProcessCompleted); featuresLayer.MouseLeftButtonDown +=new EventHandler<FeatureMouseButtonEventArgs>(featuresLayer_MouseLeftButtonDown); }
internal static string ToJson(QueryParam queryParam) { if (queryParam == null) { return null; } string json = "{"; List<string> list = new List<string>(); list.Add("\"customParams\":\"\""); if (queryParam.ExpectCount > 0) { list.Add(string.Format("\"expectCount\":{0}", queryParam.ExpectCount)); } else { list.Add("\"expectCount\":null"); } list.Add(string.Format("\"hasGeometry\":{0}", queryParam.HasGeometry.ToString().ToLower())); list.Add(string.Format("\"highlight\":null")); list.Add(string.Format("\"queryAllLayer\":{0}", queryParam.QueryAllLayer.ToString().ToLower())); IList<QueryLayer> queryLayers = queryParam.QueryLayers; if (queryLayers != null && queryLayers.Count > 0) { List<string> layerParams = new List<string>(); for (int i = 0; i < queryLayers.Count; i++) { layerParams.Add(QueryLayer.ToJson(queryLayers[i])); } string temp = "[" + string.Join(",", layerParams.ToArray()) + "]"; list.Add(string.Format("\"queryLayers\":{0}", temp)); } list.Add(string.Format("\"networkType\":{0}", (int)queryParam.NetworkType)); if (queryParam.ReturnFields != null && queryParam.ReturnFields.Count > 0) { List<string> temp = new List<string>(); for (int i = 0; i < queryParam.ReturnFields.Count; i++) { temp.Add(string.Format("\"{0}\"", queryParam.ReturnFields[i])); } list.Add(string.Format("\"returnFields\":[{0}]", string.Join(",", temp.ToArray()))); } else { list.Add("\"returnFields\":null"); } list.Add(string.Format("\"startRecord\":{0}", queryParam.StartRecord)); if (!string.IsNullOrEmpty(queryParam.WhereClause)) { list.Add(string.Format("\"whereClause\":\"{0}\"", queryParam.WhereClause)); } else { list.Add("\"whereClause\":\"\""); } list.Add(string.Format("\"returnCenterAndBounds\":{0}", queryParam.ReturnCenterAndBounds.ToString().ToLower())); list.Add(string.Format("\"returnShape\":{0}", queryParam.ReturnShape.ToString().ToLower())); json += string.Join(",", list.ToArray()); json += "}"; return json; }
//服务器返回查询结果 private void DrawCompleted(object sender, DrawEventArgs e) { QueryLayer querylayer = new QueryLayer(); querylayer.LayerName = comboBox.SelectionBoxItem.ToString(); List<QueryLayer> queryLayers = new List<QueryLayer>() { querylayer }; QueryParam queryParam = new QueryParam() { ExpectCount = 0, QueryLayers = queryLayers, StartRecord = 0 }; QueryByGeometryParameters parameters = new QueryByGeometryParameters { Geometry = e.Geometry, MapName = "changchun", QueryParam = queryParam }; QueryByGeometryService queryByGeometryService = new QueryByGeometryService("http://localhost/IS/AjaxDemo"); queryByGeometryService.ProcessAsync(parameters); queryByGeometryService.Failed += new EventHandler<ServiceFailedEventArgs>(queryByGeometryService_Failed); queryByGeometryService.ProcessCompleted += new EventHandler<QueryServiceEventArgs>(queryByGeometryService_ProcessCompleted); featuresLayer.MouseLeftButtonDown +=new EventHandler<FeatureMouseButtonEventArgs>(featuresLayer_MouseLeftButtonDown); }
//设置缓冲区查询参数 private void Button_Click(object sender, RoutedEventArgs e) { BufferQueryParameters parameters = new BufferQueryParameters(); //几何对象缓冲区查询 if (BufferQuery.IsChecked == true) { BufferParam bufferParam = new BufferParam() { Distance = 500, FromCustomGeo = true, Geometries = geometries, Smoothness = 12, QueryMode = SpatialQueryMode.AreaIntersect, ReturnBufferResult = true }; QueryLayer queriedLayer = new QueryLayer(); queriedLayer.LayerName = QueriedComboBox.SelectionBoxItem.ToString(); QueryParam queryParam = new QueryParam() { QueryLayers = new List<QueryLayer> { queriedLayer } }; parameters = new BufferQueryParameters() { MapName = "changchun", QueryParam = queryParam, BufferParam = bufferParam }; } //地物缓冲区查询 else { QueryLayer queryLayer = new QueryLayer(); queryLayer.LayerName = QueryComboBox.SelectionBoxItem.ToString(); queryLayer.WhereClause = queryText.Text; BufferParam bufferParam = new BufferParam() { FromLayer = queryLayer, Distance = 500, FromCustomGeo = false, Smoothness = 12, QueryMode = SpatialQueryMode.AreaIntersect, ReturnBufferResult = true }; QueryLayer queriedLayer = new QueryLayer(); queriedLayer.LayerName = QueriedComboBox.SelectionBoxItem.ToString(); QueryParam queryParam = new QueryParam() { QueryLayers = new List<QueryLayer> { queriedLayer } }; parameters = new BufferQueryParameters() { MapName = "changchun", QueryParam = queryParam, BufferParam = bufferParam }; } BufferQueryService bufferQueryService = new BufferQueryService("http://localhost/IS/AjaxDemo"); bufferQueryService.ProcessAsync(parameters); bufferQueryService.Failed += new EventHandler<ServiceFailedEventArgs>(Service_Failed); bufferQueryService.ProcessCompleted += new EventHandler<BufferQueryEventArgs>(bufferQueryService_ProcessCompleted); resultLayer.MouseLeftButtonDown += new EventHandler<FeatureMouseButtonEventArgs>(resultLayer_MouseLeftButtonDown); }
//中心点查询 private void point_DrawCompleted(object sender, DrawEventArgs e) { QueryParam queryParam = new QueryParam(); QueryLayer queryLayer = new QueryLayer(); queryLayer.LayerName = comboBox.SelectionBoxItem.ToString(); List<QueryLayer> queryLayers = new List<QueryLayer> { queryLayer }; queryParam = new QueryParam() { ExpectCount = 0, QueryLayers = queryLayers, StartRecord = 0 }; //将文本中读取的容限值转换为Double类型,如果值为0则将其设为100 double tolerance; if (!double.TryParse(MyTextBox.Text, out tolerance)) { tolerance = 100; } QueryByCenterParameters parameters = new QueryByCenterParameters { MapName = "changchun", CenterPoint = e.Geometry.Bounds.Center, Tolerance = tolerance, QueryParam = queryParam }; if (FindNearest.IsChecked == true) { parameters.IsNearest = true; } //与服务器交互 QueryByCenterService query = new QueryByCenterService("http://localhost/IS/AjaxDemo"); query.ProcessAsync(parameters); query.Failed += new EventHandler<ServiceFailedEventArgs>(query_Failed); query.ProcessCompleted += new EventHandler<QueryServiceEventArgs>(query_ProcessCompleted); featuresLayer.MouseLeftButtonDown+=new EventHandler<FeatureMouseButtonEventArgs>(featuresLayer_MouseLeftButtonDown); }
private string GetQueryStr(BufferParam bufferParam, QueryParam queryParam) { if (bufferParam != null && queryParam != null) { List<string> temp = new List<string>(); temp.Add("\"bufferDistance\":" + bufferParam.Distance.ToString(CultureInfo.InvariantCulture)); temp.Add("\"bufferSmoothness\":" + bufferParam.Smoothness.ToString(CultureInfo.InvariantCulture)); //temp.Add("\bufferSourceHighlight\":"+queryParam.he) temp.Add("\"queryMode\":" + ((int)bufferParam.QueryMode).ToString(CultureInfo.InvariantCulture)); temp.Add("\"queryParam\":" + QueryParam.ToJson(queryParam)); temp.Add("\"returnBufferResult\":" + bufferParam.ReturnBufferResult.ToString(CultureInfo.InvariantCulture).ToLower(CultureInfo.InvariantCulture)); string str = "{" + string.Format("{0}", string.Join(",", temp.ToArray())) + "}"; return str; } else { return string.Empty; } }