${iServer2_QueryLayerParam_Title}

${iServer2_QueryLayerParam_Description}

${iServer2_QueryLayerParam_Remarks}
        internal static string ToJson(QueryLayerParam queryLayerParam)
        {
            if (queryLayerParam == null)
            {
                return null;
            }

            StringBuilder builder = new StringBuilder();
            builder.Append("{");
            if (!string.IsNullOrEmpty(queryLayerParam.Name))
            {
                builder.AppendFormat("\"name\":\"{0}\"", queryLayerParam.Name);
            }
            if (queryLayerParam.SqlParam != null)
            {
                //string json = SqlParam.ToJson(queryLayerParam.SqlParam, queryLayerParam.Name);
                string json = SqlParam.ToJson(queryLayerParam.SqlParam);
                if (!string.IsNullOrEmpty(json) && json.Length > 2)
                {
                    builder.Append(",");
                    builder.AppendFormat("\"sqlParam\":{0}", json);
                }
            }
            builder.Append("}");

            return builder.ToString();
        }
        //SQL查询
        private void QueryBySQL_Click(object sender, RoutedEventArgs e)
        {
            List<QueryLayerParam> queryLayerParams = new List<QueryLayerParam>();
            string str = MyTextBox.Text;
            if (str == "")
            {
                MessageBox.Show("请输入SQL条件!");
            }

            //在一个图层中查询,设置要查询的图层名和SQL语句
            if (comboBox.SelectedIndex != 3)
            {
                QueryLayerParam queryLayerParam = new QueryLayerParam();
                queryLayerParam.Name = comboBox.SelectionBoxItem.ToString();
                queryLayerParam.SqlParam = new SqlParam() { WhereClause = str };
                queryLayerParams = new List<QueryLayerParam>() { queryLayerParam };
            }

            // 在三个图层中查询,设置要查询的图层名和SQL语句
            else
            {

                QueryLayerParam queryLayerParamPoint = new QueryLayerParam();
                queryLayerParamPoint.Name = PointLayerName;
                queryLayerParamPoint.SqlParam = new SqlParam() { WhereClause = str };

                QueryLayerParam queryLayerParamLine = new QueryLayerParam();
                queryLayerParamLine.Name = LineLayerName;
                queryLayerParamLine.SqlParam = new SqlParam() { WhereClause = str };

                QueryLayerParam queryLayerParamArea = new QueryLayerParam();
                queryLayerParamArea.Name = AreaLayerName;
                queryLayerParamArea.SqlParam = new SqlParam() { WhereClause = str };

                queryLayerParams = new List<QueryLayerParam>() { queryLayerParamPoint, queryLayerParamLine, queryLayerParamArea };
            }

            // 设置SQL查询参数类,以下属性为必设属性
            QueryBySqlParameters parameters = new QueryBySqlParameters
            {
                MapName = "World",

                //ExpectCount小于等于0时返回全部查询结果
                QueryParam = new QueryParam { QueryLayerParams = queryLayerParams, ExpectCount = 0 }
            };

            //与指定服务器交互
            QueryBySqlService query = new QueryBySqlService("http://localhost:7080/demo/");
            query.ProcessAsync(parameters);
            query.Failed += (s, args) => { MessageBox.Show(args.Error.ToString()); };
            query.ProcessCompleted += (s, args) => { ShowResult(args.ResultSet); };
        }
        //设置几何查询参数类
        private void LoadParam(Geometry geo)
        {
            List<QueryLayerParam> queryLayerParams = new List<QueryLayerParam>();
            if (comboBox.SelectedIndex != 3)
            {
                //在一个图层中查询,获取要查询的图层名
                QueryLayerParam queryLayerParam = new QueryLayerParam();
                queryLayerParam.Name = comboBox.SelectionBoxItem.ToString();

                //查询图层参数列表
                queryLayerParams = new List<QueryLayerParam>() { queryLayerParam };
            }
            else
            {
                //在三个图层中查询,获取要查询的图层名
                QueryLayerParam queryLayerParamLine = new QueryLayerParam();
                queryLayerParamLine.Name = LineLayerName;
                QueryLayerParam queryLayerParamPolygon = new QueryLayerParam();
                queryLayerParamPolygon.Name = AreaLayerName;
                QueryLayerParam queryLayerParamPoint = new QueryLayerParam();
                queryLayerParamPoint.Name = PointLayerName;

                //查询图层参数列表
                queryLayerParams = new List<QueryLayerParam>()
                {   queryLayerParamPoint,
                    queryLayerParamLine,
                    queryLayerParamPolygon
                };
            }

            //设置几何查询参数类,以下属性为必设属性
            QueryByGeometryParameters parameters = new QueryByGeometryParameters
            {
                MapName = "Changchun",
                QueryParam = new QueryParam() { QueryLayerParams = queryLayerParams, ExpectCount = 0 },
                Geometry = geo
            };

            //与指定服务器交互
            QueryByGeometryService query = new QueryByGeometryService("http://localhost:7080/demo/");
            query.ProcessAsync(parameters);
            query.ProcessCompleted += new EventHandler<QueryEventArgs>(ProcessCompleted);
            query.Failed += new EventHandler<ServiceFailedEventArgs>(queryFailedMessages);
        }
        //设置缓冲区查询参数类
        private void LoadParam(SuperMap.Web.Core.Geometry geo)
        {
            List<QueryLayerParam> queryLayerParams = new List<QueryLayerParam>();
            if (QueriedComboBox.SelectedIndex != 3)
            {
                //在一个图层中查询,获取要查询的图层名
                QueryLayerParam queryLayerParam = new QueryLayerParam();
                queryLayerParam.Name = QueriedComboBox.SelectionBoxItem.ToString();

                //查询图层参数列表
                queryLayerParams = new List<QueryLayerParam>() { queryLayerParam };
            }
            else
            {
                //在三个图层中查询,获取要查询的图层名
                QueryLayerParam queryLayerParamLine = new QueryLayerParam();
                queryLayerParamLine.Name = SchoolLayerName;
                QueryLayerParam queryLayerParamPolygon = new QueryLayerParam();
                queryLayerParamPolygon.Name = RailLayerName;
                QueryLayerParam queryLayerParamPoint = new QueryLayerParam();
                queryLayerParamPoint.Name = ResidentialLayerName;

                //查询图层参数列表
                queryLayerParams = new List<QueryLayerParam>()
                    {   queryLayerParamPoint,
                        queryLayerParamLine,
                        queryLayerParamPolygon
                    };
            }

            //缓冲区参数类
            BufferAnalystParam param = new BufferAnalystParam
            {
                LeftDistance = 100,
                SemicircleLineSegment = 10,
            };

            //如果为缓冲区查询,则设置缓冲区查询参数
            if (BufferQuery.IsChecked == true)
            {
                BufferQueryParameters parameters = new BufferQueryParameters
                {
                    BufferParam = param,
                    Geometry = geo,
                    QueryMode = SpatialQueryMode.Intersect,
                    MapName = "Changchun",
                    QueryParam = new QueryParam { QueryLayerParams = queryLayerParams, ExpectCount = 0 }
                };
                BufferQueryService query = new BufferQueryService("http://localhost:7080/demo/");
                query.ProcessAsync(parameters);
                query.ProcessCompleted += new EventHandler<BufferQueryEventArgs>(query_ProcessCompleted);
                query.Failed += new EventHandler<ServiceFailedEventArgs>(query_Failed);
            }

            //如果为地物缓冲区查询,则设置地物缓冲区查询参数
            else
            {
                EntityBufferQueryParameters parameters = new EntityBufferQueryParameters
                {
                    BufferParam = param,
                    Geometry = geo,
                    QueryMode = SpatialQueryMode.Intersect,
                    MapName = "Changchun",
                    QueryParam = new QueryParam { QueryLayerParams = queryLayerParams, ExpectCount = 0 },
                    FromLayer = QueryComboBox.SelectionBoxItem.ToString()
                };
                EntityBufferQueryService query = new EntityBufferQueryService("http://localhost:7080/demo/");
                query.ProcessAsync(parameters);
                query.ProcessCompleted += new EventHandler<BufferQueryEventArgs>(query_ProcessCompleted);
                query.Failed += new EventHandler<ServiceFailedEventArgs>(query_Failed);
            }
        }
        //中心点查询
        private void point_DrawCompleted(object sender, DrawEventArgs e)
        {
            List<QueryLayerParam> queryLayerParams = new List<QueryLayerParam>();
            if (comboBox.SelectedIndex != 3)
            {   //在一个图层中查询,获取要查询的图层名
                QueryLayerParam queryLayerParam = new QueryLayerParam();
                queryLayerParam.Name = comboBox.SelectionBoxItem.ToString();

                //查询图层参数列表
                queryLayerParams = new List<QueryLayerParam>() { queryLayerParam };
            }
            else
            {
                //在三个图层中查询,获取要查询的图层名
                QueryLayerParam queryLayerParamPoint = new QueryLayerParam();
                queryLayerParamPoint.Name = PointLayerName;
                QueryLayerParam queryLayerParamLine = new QueryLayerParam();
                queryLayerParamLine.Name = LineLayerName;
                QueryLayerParam queryLayerParamPolygon = new QueryLayerParam();
                queryLayerParamPolygon.Name = AreaLayerName;

                //查询图层参数列表
                queryLayerParams = new List<QueryLayerParam>()
                {   queryLayerParamPoint,
                    queryLayerParamLine,
                    queryLayerParamPolygon
                };
            }

            //将文本中读取的容限值转换为Double类型,如果值为0则将其设为100
            double tolerance;
            if (!double.TryParse(MyTextBox.Text, out tolerance))
            {
                tolerance = 100;
            }

            //设置中心点查询参数,其中四个属性都为必设属性
            QueryByCenterParameters parameters = new QueryByCenterParameters
            {
                CenterPoint = e.Geometry.Bounds.Center,
                Tolerance = tolerance,
                MapName = "Changchun",

                // ExceptCount属性小于等于0时表示返回全部查询结果
                QueryParam = new QueryParam { QueryLayerParams = queryLayerParams, ExpectCount =1000 }
            };

            //是否查找最近地物
            if (FindNearest.IsChecked == true)
            {
                parameters.IsNearest = true;
            }

            //与指定服务器交互
            QueryByCenterService queryByCenterService = new QueryByCenterService("http://localhost:7080/demo");
            queryByCenterService.ProcessAsync(parameters);
            queryByCenterService.Failed += new System.EventHandler<ServiceFailedEventArgs>(queryByCenterService_Failed);
            queryByCenterService.ProcessCompleted += new System.EventHandler<QueryEventArgs>(queryByCenterService_ProcessCompleted);
        }