${REST_QueryBySQLParameters_Tile}
private async void DouUiqueRenderSearch() { List<FilterParameter> list = new List<FilterParameter>(); list.Add(new FilterParameter { Name = "Countries@World", AttributeFilter = "SmID=39 OR SmID=45 OR SmID=54" }); QueryBySQLParameters parameters = new QueryBySQLParameters { FilterParameters = list }; //与服务端交互 try { QueryBySQLService service = new QueryBySQLService(url); var result = await service.ProcessAsync(parameters); if (result == null) { await MessageBox.Show("没有查询到结果!"); return; } int i = 0; foreach (Recordset item in result.Recordsets) { foreach (Feature feature in item.Features) { feature.ToolTip = new TextBlock { Text = i++.ToString() }; uniqueRenderLayer.Features.Add(feature); } } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
//点击查询按钮触发 private async void QueryBySQL_Click(object sender, RoutedEventArgs e) { //设置 SQL 查询参数,FilterParameters为必设属性 QueryBySQLParameters param = new QueryBySQLParameters() { FilterParameters = new List<FilterParameter>() { new FilterParameter() { //Name 为必设属性 Name = "Countries@World", //SQL 查询条件,从文本框中获取用户输入的查询条件 AttributeFilter = MyTextBox.Text } }, //设置是返回查询结果资源(false)还是返回查询结果记录集(true) ReturnContent = notHighlight }; //与服务器交互 try { QueryBySQLService service = new QueryBySQLService(url); var result = await service.ProcessAsync(param); //无查询结果的情况 if (result == null) { await MessageBox.Show("查询结果为空!"); return; } //如果当前矢量图层中存在上一次的查询地物,则清除 flayer.Features.Clear(); //刷新高亮图层 highlayer.IsVisible = false; highlayer.Refresh(); //当 ReturnContent = false 且有查询结果时,返回结果中的 ResourceInfo 不为空 //当 ReturnContent = true 且有查询结果时,返回结果中的 Recordsets 不为空,ResourceInfo 为空 if (result.ResourceInfo != null) { highlayer.IsVisible = true; //获取高亮图片在服务器上存储的资源 ID 号 highlayer.QueryResultID = result.ResourceInfo.NewResourceID; //设置服务端高亮图层的样式 highlayer.Style = new ServerStyle() { FillForeColor = new Color { R = 0, G = 160, B = 0 }, LineWidth = 0, FillOpaqueRate = 90 }; //该判断控制只加载一个高亮图层 if (!isAdded) { this.MyMap.Layers.Add(highlayer); isAdded = true; } } else { //将查询结果记录集中的数据转换为矢量要素集合并在矢量图层中显示 foreach (Recordset recordset in result.Recordsets) { flayer.AddFeatureSet(recordset.Features); } //将查询到的地物赋予 XMAL 中自定义样式 foreach (Feature item in flayer.Features) { if (item.Geometry is GeoLine) { item.Style = LineSelectStyle; } else if (item.Geometry is GeoRegion) { item.Style = SelectStyle; } else { item.Style = new PredefinedMarkerStyle() { Color = new SolidColorBrush(Colors.Blue), Size = 20, Symbol = PredefinedMarkerStyle.MarkerSymbol.Diamond }; } } } } //服务器查询失败 catch (Exception ex) { MessageBox.Show(ex.Message); } }
private async void DoUniformRendererSearch() { List<FilterParameter> list = new List<FilterParameter>(); list.Add(new FilterParameter { Name = "Countries@World", AttributeFilter = "SmID=43 OR SmID=78 OR SmID=71" }); QueryBySQLParameters parameters = new QueryBySQLParameters { FilterParameters = list }; //与服务端交互 try { QueryBySQLService service1 = new QueryBySQLService(this.url); var result = await service1.ProcessAsync(parameters); if (result == null) { await MessageBox.Show("没有查询到结果!"); return; } foreach (Recordset item in result.Recordsets) { foreach (Feature feature in item.Features) { uniformRendererLayer.Features.Add(feature); } } uniformRendererLayer.Renderer = new UniformRenderer { FillStyle = new FillStyle { Fill = new SolidColorBrush(Color.FromArgb(0xff, 0xe5, 0xe5, 0x45)), Stroke = new SolidColorBrush(Color.FromArgb(0xff, 0x7f, 0x80, 0x13)) } }; } //与服务端交互失败 catch (Exception ex) { MessageBox.Show(ex.Message); } }