Query UI
This commit is contained in:
parent
b5a8793281
commit
cb2d49e0d2
10
.idea/.idea.GisDevelop_Exp/.idea/indexLayout.xml
Normal file
10
.idea/.idea.GisDevelop_Exp/.idea/indexLayout.xml
Normal file
@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="UserContentModel">
|
||||
<attachedFolders>
|
||||
<Path>../../GisDevelop</Path>
|
||||
</attachedFolders>
|
||||
<explicitIncludes />
|
||||
<explicitExcludes />
|
||||
</component>
|
||||
</project>
|
||||
28
GisDevelop_Exp/AttributeQuery.xaml
Normal file
28
GisDevelop_Exp/AttributeQuery.xaml
Normal file
@ -0,0 +1,28 @@
|
||||
<Window x:Class="GisDevelop_Exp.AttributeQuery"
|
||||
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:local="clr-namespace:GisDevelop_Exp"
|
||||
mc:Ignorable="d"
|
||||
Title="按属性查询" Height="323" Width="422"
|
||||
Loaded="AttributeQuery_OnLoaded">
|
||||
<Canvas Margin="0,0,370,0">
|
||||
<Label Content="选择图层" Canvas.Left="50" Canvas.Top="36"/>
|
||||
<ComboBox x:Name="comboBoxLayers" Canvas.Left="121" Canvas.Top="40" Width="243" HorizontalAlignment="Left" VerticalAlignment="Center" SelectionChanged="ComboBoxLayers_OnSelectionChanged"/>
|
||||
<ListBox x:Name="listBoxFields" Height="108" Width="123" d:ItemsSource="{d:SampleData ItemCount=5}" HorizontalAlignment="Left" Canvas.Top="84" VerticalAlignment="Center" Canvas.Left="36" SelectionChanged="ListBoxFields_OnSelectionChanged" MouseDoubleClick="ListBoxFields_OnMouseDoubleClick"/>
|
||||
<ListBox x:Name="listBoxFieldValue" Height="108" Width="124" d:ItemsSource="{d:SampleData ItemCount=5}" Canvas.Top="84" Canvas.Left="276" HorizontalAlignment="Left" VerticalAlignment="Center" MouseDoubleClick="ListBoxFieldValue_OnMouseDoubleClick"/>
|
||||
<Button x:Name="buttonEqual" Content="=" Canvas.Left="179" Canvas.Top="105" HorizontalAlignment="Left" VerticalAlignment="Top" Width="21" Height="22" MouseDoubleClick="OperatorButtonClick"/>
|
||||
<Button x:Name="buttonNotEqual" Content="<>" Canvas.Left="200" Canvas.Top="105" Width="21" Height="22" HorizontalAlignment="Left" VerticalAlignment="Top" MouseDoubleClick="OperatorButtonClick"/>
|
||||
<Button x:Name="buttonLike" Content="Like" Canvas.Left="221" Canvas.Top="105" Width="30" Height="22" HorizontalAlignment="Left" VerticalAlignment="Top" MouseDoubleClick="OperatorButtonClick"/>
|
||||
<Button x:Name="buttonLessThan" Content="<" Canvas.Left="179" Canvas.Top="127" Width="21" Height="22" HorizontalAlignment="Left" VerticalAlignment="Top" MouseDoubleClick="OperatorButtonClick"/>
|
||||
<Button x:Name="buttonLessEqual" Content="<=" Canvas.Left="200" Canvas.Top="127" Width="21" Height="22" HorizontalAlignment="Left" VerticalAlignment="Top" MouseDoubleClick="OperatorButtonClick"/>
|
||||
<Button x:Name="buttonAnd" Content="And" Canvas.Left="221" Canvas.Top="127" Width="30" Height="22" HorizontalAlignment="Left" VerticalAlignment="Top" MouseDoubleClick="OperatorButtonClick"/>
|
||||
<Button x:Name="buttonGreaterThan" Content=">" Canvas.Left="179" Canvas.Top="149" Width="21" Height="22" HorizontalAlignment="Left" VerticalAlignment="Top" MouseDoubleClick="OperatorButtonClick"/>
|
||||
<Button x:Name="buttonGreaterEqual" Content=">=" Canvas.Left="200" Canvas.Top="149" Width="21" Height="22" HorizontalAlignment="Left" VerticalAlignment="Top" MouseDoubleClick="OperatorButtonClick"/>
|
||||
<Button x:Name="buttonOr" Content="Or" Canvas.Left="221" Canvas.Top="149" Width="30" Height="22" HorizontalAlignment="Left" VerticalAlignment="Top" MouseDoubleClick="OperatorButtonClick"/>
|
||||
<TextBox x:Name="textBoxWhere" Canvas.Left="36" TextWrapping="Wrap" Text="TextBox" Canvas.Top="212" Width="364" HorizontalAlignment="Left" VerticalAlignment="Center" Height="29"/>
|
||||
<Button Content="确认" Canvas.Left="36" Canvas.Top="262" RenderTransformOrigin="-0.278,-0.098" HorizontalAlignment="Left" VerticalAlignment="Center" Width="72" Click="ButtonBase_OK_OnClick"/>
|
||||
<Button Content="取消" Canvas.Left="328" Canvas.Top="262" RenderTransformOrigin="-0.278,-0.098" Width="72" HorizontalAlignment="Left" VerticalAlignment="Center" Click="ButtonBase_Cancel_OnClick"/>
|
||||
</Canvas>
|
||||
</Window>
|
||||
190
GisDevelop_Exp/AttributeQuery.xaml.cs
Normal file
190
GisDevelop_Exp/AttributeQuery.xaml.cs
Normal file
@ -0,0 +1,190 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Shapes;
|
||||
using Esri.ArcGISRuntime.Data;
|
||||
|
||||
namespace GisDevelop_Exp
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for AttributeQuery.xaml
|
||||
/// </summary>
|
||||
public partial class AttributeQuery : Window
|
||||
{
|
||||
private List<FeatureTable> _tables;// 表集合
|
||||
private String sqlString; //查询语句的where子句
|
||||
private FeatureTable selectedTable;// 当前所选要素表对象
|
||||
|
||||
public AttributeQuery()
|
||||
{
|
||||
InitializeComponent();
|
||||
Tables = new List<FeatureTable>();//初始化表集合
|
||||
sqlString = string.Empty;//初始化字符串
|
||||
selectedTable = null;
|
||||
listBoxFields.Items.Clear();//清空字段组合框的内容
|
||||
listBoxFieldValue.Items.Clear();//清空字段值组合框的内容
|
||||
textBoxWhere.Text = string.Empty;//清空文本框
|
||||
}
|
||||
|
||||
public List<FeatureTable> Tables
|
||||
{
|
||||
get { return _tables; }
|
||||
set { _tables = value; }
|
||||
}
|
||||
public string SqlString
|
||||
{
|
||||
get { return sqlString; }
|
||||
set { sqlString = value; }
|
||||
}
|
||||
|
||||
|
||||
private void AttributeQuery_OnLoaded(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if(Tables .Count > 0)//表集合不为空
|
||||
{
|
||||
foreach (FeatureTable tb in Tables)// 遍历表,将表名加入组合框
|
||||
{
|
||||
comboBoxLayers.Items.Add(tb.TableName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void ComboBoxLayers_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
|
||||
{
|
||||
if (comboBoxLayers.SelectedIndex > -1)//选项有效
|
||||
{
|
||||
selectedTable = Tables.ElementAt(comboBoxLayers.SelectedIndex);//根据索引取得表对象
|
||||
if(selectedTable !=null)
|
||||
{
|
||||
listBoxFields.Items.Clear();//清空字段组合框内容
|
||||
foreach (Field fld in selectedTable.Fields)//遍历表字段集合,将字段名加入组合框
|
||||
{
|
||||
listBoxFields.Items.Add(fld.Name);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private async void ListBoxFields_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
|
||||
{
|
||||
if (selectedTable !=null && listBoxFields.SelectedIndex > -1)//选项有效
|
||||
{
|
||||
Field selectedField =
|
||||
selectedTable.Fields.ElementAt(listBoxFields.SelectedIndex);//取得索引的字段
|
||||
FeatureQueryResult result = await selectedTable.QueryFeaturesAsync(new
|
||||
QueryParameters());//构建查询参数对象在表对象上进行查询
|
||||
if (result == null) return;
|
||||
listBoxFieldValue.Items.Clear();//清空字段值列表框内容
|
||||
foreach (Feature ft in result)//遍历查询结果
|
||||
{
|
||||
string strValue = ft.GetAttributeValue(selectedField).ToString();//取得当前字段值
|
||||
if (!listBoxFieldValue.Items.Contains(strValue))//检查该值是否已存在
|
||||
{
|
||||
listBoxFieldValue.Items.Add(strValue);//加入字段值列表框
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void ListBoxFields_OnMouseDoubleClick(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
if (listBoxFields.SelectedIndex > -1)//选择项有效
|
||||
{
|
||||
string strSelField = listBoxFields.SelectedItem.ToString();
|
||||
textBoxWhere.Text = string.Concat(textBoxWhere.Text ," ", strSelField); //将所选项填入文本框中
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void ListBoxFieldValue_OnMouseDoubleClick(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
if (listBoxFieldValue.SelectedIndex > -1)//所选项有效
|
||||
{
|
||||
string strSelValue = listBoxFieldValue.SelectedItem.ToString();
|
||||
if(textBoxWhere.Text.EndsWith("and") || textBoxWhere.Text.EndsWith("or"))//如果文本框字符串结尾为and和or则返回
|
||||
{
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
int idx = textBoxWhere.Text.LastIndexOf("'"); //查找最后一个'符号
|
||||
int idx2 = textBoxWhere.Text.LastIndexOf("%"); //如果为模糊查询,则插入值在%号前面
|
||||
if (idx2 > 0)
|
||||
idx = idx2;
|
||||
if (idx > 0)
|
||||
{
|
||||
textBoxWhere.Text = textBoxWhere.Text.Insert(idx, strSelValue); //在文本框字符串中插入字段值
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void OperatorButtonClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
Button btn = (Button)sender;//获取button按钮对象
|
||||
switch (btn.Name)//根据button对象的名称来判断当前按下的按钮
|
||||
{
|
||||
case "buttonEqual"://等于
|
||||
textBoxWhere.Text = string.Concat(textBoxWhere.Text, " ", "= ''");
|
||||
break;
|
||||
case "buttonNotEqual"://不等
|
||||
textBoxWhere.Text = string.Concat(textBoxWhere.Text, " ", "<> ''");
|
||||
break;
|
||||
case "buttonLike"://模糊谓词like
|
||||
textBoxWhere.Text = string.Concat(textBoxWhere.Text, " ", "like '%%'");
|
||||
break;
|
||||
case "buttonLessThan"://小于
|
||||
textBoxWhere.Text = string.Concat(textBoxWhere.Text, " ", "< ''");
|
||||
break;
|
||||
case "buttonLessEqual"://小于等于
|
||||
textBoxWhere.Text = string.Concat(textBoxWhere.Text, " ", "<= ''");
|
||||
break;
|
||||
case "buttonAnd"://与谓词and
|
||||
textBoxWhere.Text = string.Concat(textBoxWhere.Text, " ", "and");
|
||||
break;
|
||||
case "buttonGreaterThan"://大于
|
||||
textBoxWhere.Text = string.Concat(textBoxWhere.Text, " ", "> ''");
|
||||
break;
|
||||
case "buttonGreaterEqual"://大于等于
|
||||
textBoxWhere.Text = string.Concat(textBoxWhere.Text, " ", ">= ''");
|
||||
break;
|
||||
case "buttonOr"://或谓词or
|
||||
textBoxWhere.Text = string.Concat(textBoxWhere.Text, " ", "or");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private async void ButtonBase_OK_OnClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
this.DialogResult = true;//设置窗体对话框退出时的结果为true
|
||||
if (selectedTable != null)//当前选择的表对象存在
|
||||
{
|
||||
QueryParameters qParams = new QueryParameters();//创建查询参数对象
|
||||
qParams.WhereClause = textBoxWhere.Text.Trim();//获取文本框中的字符串作为查询参数对象的where子句
|
||||
FeatureQueryResult result =await selectedTable.QueryFeaturesAsync(qParams);//在表上进行查询
|
||||
if(result != null)//查询结果不为空
|
||||
{
|
||||
QueryResultWindow qsw = new QueryResultWindow();//构造查询结果窗体对象
|
||||
qsw.FeatureQuerySet = result;//设置查询结果对象引用
|
||||
qsw.ShowDialog(); //以对话框形式显示窗体
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void ButtonBase_Cancel_OnClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
this.DialogResult = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
16
GisDevelop_Exp/ExtentLocationQueryResultsWindow.xaml
Normal file
16
GisDevelop_Exp/ExtentLocationQueryResultsWindow.xaml
Normal file
@ -0,0 +1,16 @@
|
||||
<Window x:Class="GisDevelop_Exp.ExtentLocationQueryResultsWindow"
|
||||
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:local="clr-namespace:GisDevelop_Exp"
|
||||
mc:Ignorable="d"
|
||||
Title="拉框选择结果窗口" Height="450" Width="316"
|
||||
Activated="LocationQueryResultsWindow_OnActivated">
|
||||
<Canvas>
|
||||
<ComboBox x:Name="comboBoxLayer" Canvas.Left="10" Canvas.Top="10" Width="164" HorizontalAlignment="Left" VerticalAlignment="Center" SelectionChanged="ComboBoxLayer_OnSelectionChanged"/>
|
||||
<ComboBox x:Name="comboBoxRecord" Canvas.Left="174" Canvas.Top="10" Width="132" HorizontalAlignment="Left" VerticalAlignment="Center" SelectionChanged="ComboBoxRecord_OnSelectionChanged"/>
|
||||
<DataGrid x:Name="dataGridContent" Height="377" Width="286" d:ItemsSource="{d:SampleData ItemCount=5}" HorizontalAlignment="Center" Canvas.Top="37" VerticalAlignment="Top" Canvas.Left="20"/>
|
||||
</Canvas>
|
||||
|
||||
</Window>
|
||||
100
GisDevelop_Exp/ExtentLocationQueryResultsWindow.xaml.cs
Normal file
100
GisDevelop_Exp/ExtentLocationQueryResultsWindow.xaml.cs
Normal file
@ -0,0 +1,100 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Shapes;
|
||||
using Esri.ArcGISRuntime.Data;
|
||||
|
||||
namespace GisDevelop_Exp
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for LocationQueryResultsWindow.xaml
|
||||
/// </summary>
|
||||
public partial class ExtentLocationQueryResultsWindow : Window
|
||||
{
|
||||
public List<QueryResult> resultCollection;//地图识别操作结果集合
|
||||
private bool isClosed;//窗体关闭标记
|
||||
private QueryResult curSelLayer;//当前选择的图层
|
||||
|
||||
public List<QueryResult> ResultCollection
|
||||
{
|
||||
get => resultCollection;
|
||||
set => resultCollection = value ?? throw new ArgumentNullException(nameof(value));
|
||||
}
|
||||
|
||||
public bool IsClosed
|
||||
{
|
||||
get { return isClosed; }
|
||||
}
|
||||
|
||||
public ExtentLocationQueryResultsWindow()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void LocationQueryResultsWindow_OnActivated(object? sender, EventArgs e)
|
||||
{
|
||||
if(resultCollection!=null)//查询结果集不为空
|
||||
{
|
||||
comboBoxLayer.Items.Clear();//清空图层组合框的内容
|
||||
foreach (QueryResult result in resultCollection)
|
||||
{
|
||||
comboBoxLayer.Items.Add(result.Name);
|
||||
}
|
||||
|
||||
QueryResult firstQueryResult = resultCollection.First();//获取第一个集合中第一个图层
|
||||
curSelLayer = firstQueryResult;
|
||||
List<IDictionary<string, object>> selFeatures = firstQueryResult.Attributes;//获取图层中所有要素
|
||||
comboBoxRecord.Items.Clear();//清空记录组合框的内容
|
||||
for(int i = 1; i <= selFeatures.Count; i++)
|
||||
{
|
||||
comboBoxRecord.Items.Add(i);//遍历要素集合,为记录组合框添加项
|
||||
}
|
||||
IDictionary<string, object> firstAttribute = selFeatures.First();//取得要素集合中第一个要素
|
||||
dataGridContent.AutoGenerateColumns = true;//数据格网对象自动生成列
|
||||
dataGridContent.ItemsSource = firstAttribute;//设置数据格网中项的数据源
|
||||
comboBoxLayer.SelectedIndex = 0;
|
||||
comboBoxRecord.SelectedIndex = 0;
|
||||
}
|
||||
}
|
||||
|
||||
private void LocationQueryResultsWindow_OnClosed(object? sender, EventArgs e)
|
||||
{
|
||||
isClosed = true;
|
||||
}
|
||||
|
||||
private void ComboBoxLayer_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
|
||||
{
|
||||
if(comboBoxLayer.SelectedIndex>-1)//索引有效
|
||||
{
|
||||
curSelLayer = resultCollection[comboBoxLayer.SelectedIndex];//取得索引对应的要素图层
|
||||
comboBoxRecord.Items.Clear();//清空记录组合框的 内容
|
||||
for(int i = 1; i <= curSelLayer.Attributes.Count; i++)
|
||||
{
|
||||
comboBoxRecord.Items.Add(i);//遍历图层记录数,为记录组合框添加项
|
||||
}
|
||||
IDictionary<string,object> curAttribute = curSelLayer.Attributes.First();//取得记录集中的第一个要素
|
||||
dataGridContent.ItemsSource = curAttribute;//设置数据格网对象中项的数据源
|
||||
comboBoxRecord.SelectedIndex = 0;
|
||||
}
|
||||
}
|
||||
|
||||
private void ComboBoxRecord_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
|
||||
{
|
||||
if(curSelLayer !=null && comboBoxRecord.SelectedIndex > -1)//当前图层不为空,所选记录索引有效
|
||||
{
|
||||
IDictionary<string,object> curAttribute =
|
||||
curSelLayer.Attributes[comboBoxRecord.SelectedIndex];//获取索引所在要素
|
||||
dataGridContent.ItemsSource = curAttribute;//设置数据格网对象中项的数据源
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -16,4 +16,19 @@
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Page Update="ExtentLocationQueryResultsWindow.xaml">
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
<XamlRuntime>Wpf</XamlRuntime>
|
||||
<SubType>Designer</SubType>
|
||||
</Page>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Update="ExtentLocationQueryResultsWindow.xaml.cs">
|
||||
<SubType>Code</SubType>
|
||||
<DependentUpon>ExtentLocationQueryResultsWindow.xaml</DependentUpon>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
17
GisDevelop_Exp/LocationQueryResultsWindow.xaml
Normal file
17
GisDevelop_Exp/LocationQueryResultsWindow.xaml
Normal file
@ -0,0 +1,17 @@
|
||||
<Window x:Class="GisDevelop_Exp.LocationQueryResultsWindow"
|
||||
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:local="clr-namespace:GisDevelop_Exp"
|
||||
mc:Ignorable="d"
|
||||
Title="LocationQueryResultsWindow" Height="450" Width="316"
|
||||
Activated="LocationQueryResultsWindow_OnActivated"
|
||||
Closed="LocationQueryResultsWindow_OnClosed">
|
||||
<Canvas>
|
||||
<ComboBox x:Name="comboBoxLayer" Canvas.Left="10" Canvas.Top="10" Width="164" HorizontalAlignment="Left" VerticalAlignment="Center" SelectionChanged="ComboBoxLayer_OnSelectionChanged"/>
|
||||
<ComboBox x:Name="comboBoxRecord" Canvas.Left="174" Canvas.Top="10" Width="132" HorizontalAlignment="Left" VerticalAlignment="Center" SelectionChanged="ComboBoxRecord_OnSelectionChanged"/>
|
||||
<DataGrid x:Name="dataGridContent" Height="377" Width="286" d:ItemsSource="{d:SampleData ItemCount=5}" HorizontalAlignment="Center" Canvas.Top="37" VerticalAlignment="Top" Canvas.Left="20"/>
|
||||
</Canvas>
|
||||
|
||||
</Window>
|
||||
97
GisDevelop_Exp/LocationQueryResultsWindow.xaml.cs
Normal file
97
GisDevelop_Exp/LocationQueryResultsWindow.xaml.cs
Normal file
@ -0,0 +1,97 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Shapes;
|
||||
using Esri.ArcGISRuntime.Data;
|
||||
|
||||
namespace GisDevelop_Exp
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for LocationQueryResultsWindow.xaml
|
||||
/// </summary>
|
||||
public partial class LocationQueryResultsWindow : Window
|
||||
{
|
||||
private IReadOnlyList<IdentifyLayerResult> resultCollection;//地图识别操作结果集合
|
||||
private bool isClosed;//窗体关闭标记
|
||||
private IdentifyLayerResult curSelLayer;//当前选择的图层
|
||||
public IReadOnlyList<IdentifyLayerResult> ResultCollection
|
||||
{
|
||||
get { return resultCollection; }
|
||||
set { resultCollection = value; }
|
||||
}
|
||||
public bool IsClosed
|
||||
{
|
||||
get { return isClosed; }
|
||||
}
|
||||
|
||||
public LocationQueryResultsWindow()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void LocationQueryResultsWindow_OnActivated(object? sender, EventArgs e)
|
||||
{
|
||||
if(resultCollection!=null)//查询结果集不为空
|
||||
{
|
||||
comboBoxLayer.Items.Clear();//清空图层组合框的内容
|
||||
foreach (IdentifyLayerResult result in resultCollection)//遍历集合
|
||||
{
|
||||
comboBoxLayer.Items.Add(result.LayerContent.Name);//添加图层名到图层组合框
|
||||
}
|
||||
IdentifyLayerResult firstLayerResult = resultCollection.First();//获取第一个集合中第一个图层
|
||||
IReadOnlyList<GeoElement> selFeatures = firstLayerResult.GeoElements;//获取图层中所有要素
|
||||
comboBoxRecord.Items.Clear();//清空记录组合框的内容
|
||||
for(int i = 1; i <= selFeatures.Count; i++)
|
||||
{
|
||||
comboBoxRecord.Items.Add(i);//遍历要素集合,为记录组合框添加项
|
||||
}
|
||||
Feature ft = (Feature)selFeatures.First();//取得要素集合中第一个要素
|
||||
dataGridContent.AutoGenerateColumns = true;//数据格网对象自动生成列
|
||||
dataGridContent.ItemsSource = ft.Attributes;//设置数据格网中项的数据源
|
||||
comboBoxLayer.SelectedIndex = 0;
|
||||
comboBoxRecord.SelectedIndex = 0;
|
||||
}
|
||||
}
|
||||
|
||||
private void LocationQueryResultsWindow_OnClosed(object? sender, EventArgs e)
|
||||
{
|
||||
isClosed = true;
|
||||
}
|
||||
|
||||
|
||||
private void ComboBoxLayer_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
|
||||
{
|
||||
if(comboBoxLayer.SelectedIndex>-1)//索引有效
|
||||
{
|
||||
curSelLayer = resultCollection[comboBoxLayer.SelectedIndex];//取得索引对应的要素图层
|
||||
comboBoxRecord.Items.Clear();//清空记录组合框的 内容
|
||||
for(int i = 1; i <= curSelLayer.GeoElements.Count; i++)
|
||||
{
|
||||
comboBoxRecord.Items.Add(i);//遍历图层记录数,为记录组合框添加项
|
||||
}
|
||||
Feature ft = (Feature ) curSelLayer.GeoElements.First();//取得记录集中的第一个要素
|
||||
dataGridContent.ItemsSource = ft.Attributes;//设置数据格网对象中项的数据源
|
||||
comboBoxRecord.SelectedIndex = 0;
|
||||
}
|
||||
}
|
||||
|
||||
private void ComboBoxRecord_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
|
||||
{
|
||||
if(curSelLayer !=null && comboBoxRecord.SelectedIndex > -1)//当前图层不为空,所选记录索引有效
|
||||
{
|
||||
Feature ft = (Feature )
|
||||
curSelLayer.GeoElements[comboBoxRecord.SelectedIndex];//获取索引所在要素
|
||||
dataGridContent.ItemsSource = ft.Attributes;//设置数据格网对象中项的数据源
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -58,7 +58,7 @@
|
||||
<MenuItem x:Name="Menu_Attribute_Query" Header="按属性查询" Click="Menu_Attribute_Query_OnClick"></MenuItem>
|
||||
<MenuItem Header="按位置查询">
|
||||
<MenuItem x:Name="Menu_Query_Point" Header="点击选择" Click="Menu_Query_Point_OnClick"></MenuItem>
|
||||
<MenuItem x:Name="Menu_Query_Envelope" Header="拉框选择"></MenuItem>
|
||||
<MenuItem x:Name="Menu_Query_Envelope" Header="拉框选择" Click="Menu_Query_Envelope_OnClick"></MenuItem>
|
||||
</MenuItem>
|
||||
<Separator></Separator>
|
||||
<MenuItem x:Name="Menu_Clear_Selection" Header="清除选择"></MenuItem>
|
||||
@ -67,7 +67,7 @@
|
||||
<esri:MapView x:Name="MainMapView" Map="{Binding Map, Source={StaticResource MapViewModel}}" Margin="0,19,0,0"
|
||||
ViewpointChanged="MainMapView_OnViewpointChanged" GeoViewTapped="MainMapView_OnGeoViewTapped"
|
||||
MouseLeftButtonDown="MainMapView_OnMouseLeftButtonDown"
|
||||
MouseRightButtonDown="MainMapView_OnMouseRightButtonDown" />
|
||||
MouseRightButtonDown="MainMapView_OnMouseRightButtonDown"/>
|
||||
<ListBox x:Name="LayerListBox" Width="143" SelectedIndex="0" RenderTransformOrigin="0.451,1.105"
|
||||
Margin="0,56,0,13" HorizontalAlignment="Left" PreviewMouseMove="LayerListBox_OnPreviewMouseMove"
|
||||
Drop="LayerListBox_OnDrop" PreviewMouseRightButtonDown="LayerListBox_OnPreviewMouseRightButtonDown"
|
||||
|
||||
@ -44,7 +44,10 @@ enum CURRENTOPERATION
|
||||
Cal_Intersect,
|
||||
Cal_Intersection,
|
||||
Cal_Gene,
|
||||
Cal_Buff
|
||||
Cal_Buff,
|
||||
AttributeQuery,
|
||||
ClickQuery,
|
||||
ExtentQuery
|
||||
}
|
||||
|
||||
namespace GisDevelop_Exp
|
||||
@ -80,7 +83,9 @@ namespace GisDevelop_Exp
|
||||
|
||||
private int selByGeometryType = 0;
|
||||
|
||||
LocationQueryResultsWindow locationQueryResultsWindow ;
|
||||
LocationQueryResultsWindow locationQueryResultsWindow;
|
||||
|
||||
private MapPoint _startLocation;
|
||||
|
||||
private readonly Dictionary<string, Basemap> _basemapOptions = new Dictionary<string, Basemap>()
|
||||
{
|
||||
@ -161,14 +166,12 @@ namespace GisDevelop_Exp
|
||||
for (int i = 0; i < fileDialog.FileNames.Length; i++)
|
||||
{
|
||||
String filePath = fileDialog.FileNames.GetValue(i).ToString();
|
||||
|
||||
ShapefileFeatureTable openedFeature = await ShapefileFeatureTable.OpenAsync(filePath);
|
||||
FeatureLayer opendFeatureLayer = new FeatureLayer(openedFeature);
|
||||
MainMapView.Map.OperationalLayers.Add(opendFeatureLayer);
|
||||
await MainMapView.SetViewpointGeometryAsync(openedFeature.Extent);
|
||||
}
|
||||
}
|
||||
|
||||
AddLayerNameToList();
|
||||
}
|
||||
|
||||
@ -1008,7 +1011,7 @@ namespace GisDevelop_Exp
|
||||
}
|
||||
}
|
||||
|
||||
if(selByGeometryType == 1)//检查是否为按照位置查询中的点选
|
||||
if(m_CurOper == CURRENTOPERATION.ClickQuery)//检查是否为按照位置查询中的点选
|
||||
{
|
||||
IInputElement ie = (IInputElement)sender;//转换事件宿主对象为IInputElement对象
|
||||
IReadOnlyList< IdentifyLayerResult> results =await
|
||||
@ -1029,6 +1032,81 @@ namespace GisDevelop_Exp
|
||||
locationQueryResultsWindow.Activate();//使子窗体处于激活状态
|
||||
}
|
||||
}
|
||||
else if (m_CurOper == CURRENTOPERATION.ExtentQuery)
|
||||
{
|
||||
if (_startLocation == null)
|
||||
{
|
||||
MainMapView.GraphicsOverlays.Clear();
|
||||
this._startLocation = location;
|
||||
}
|
||||
else
|
||||
{
|
||||
MapPoint _curLocation = location;
|
||||
List<MapPoint> extentPoints = new List<MapPoint>();
|
||||
extentPoints.Add(new MapPoint(_startLocation.X, _startLocation.Y));
|
||||
extentPoints.Add(new MapPoint(_startLocation.X, location.Y));
|
||||
extentPoints.Add(new MapPoint(location.X, location.Y));
|
||||
extentPoints.Add(new MapPoint(location.X, _startLocation.Y));
|
||||
Polygon polygon = new Polygon(extentPoints);
|
||||
Color lineColor = Color.FromArgb(255, 255, 0, 0);
|
||||
SimpleLineSymbol lineSymbol =
|
||||
new Esri.ArcGISRuntime.Symbology.SimpleLineSymbol(SimpleLineSymbolStyle.Dash, lineColor, 2.0);
|
||||
Color fillColor = Color.FromArgb(0, 0, 0, 0);
|
||||
SimpleFillSymbol fillSymbol = new SimpleFillSymbol(SimpleFillSymbolStyle.Solid, fillColor, lineSymbol);
|
||||
Graphic polygonGraphic = new Graphic(polygon, fillSymbol);
|
||||
MainMapView.GraphicsOverlays.Add(new GraphicsOverlay());
|
||||
MainMapView.GraphicsOverlays[0].Graphics.Add(polygonGraphic);
|
||||
|
||||
Envelope selEnv = new Envelope(this._startLocation.X, this._startLocation.Y, location.X,
|
||||
location.Y, MainMapView.SpatialReference);
|
||||
QueryParameters pQueryPara = new QueryParameters();
|
||||
pQueryPara.Geometry = selEnv;
|
||||
pQueryPara.SpatialRelationship = SpatialRelationship.Intersects;
|
||||
// _featureLayer = MainMapView.Map.OperationalLayers[0] as FeatureLayer;
|
||||
List<QueryResult> queryResults = new List<QueryResult>();
|
||||
foreach (FeatureLayer featureLayer in MainMapView.Map.OperationalLayers)
|
||||
{
|
||||
await featureLayer.SelectFeaturesAsync(pQueryPara,
|
||||
Esri.ArcGISRuntime.Mapping.SelectionMode.New);
|
||||
|
||||
FeatureQueryResult pQueryResult = await featureLayer.GetSelectedFeaturesAsync();
|
||||
|
||||
List<Feature> pListFeatures = pQueryResult.ToList();
|
||||
if (pListFeatures.Count <= 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
EnvelopeBuilder pEnvBuilder = new EnvelopeBuilder(featureLayer.SpatialReference);
|
||||
for (int i = 0; i < pListFeatures.Count; i++)
|
||||
{
|
||||
pEnvBuilder.UnionOf(pListFeatures[i].Geometry.Extent);
|
||||
}
|
||||
|
||||
await MainMapView.SetViewpointGeometryAsync(pEnvBuilder.ToGeometry(), 50);
|
||||
Feature pFeature;
|
||||
string sInfo = "";
|
||||
IReadOnlyList<Field> pFields = pQueryResult.Fields;
|
||||
string featureLayerName = featureLayer.Name;
|
||||
List<IDictionary<string, object>> attributes = new List<IDictionary<string, object>>();
|
||||
for (int i = 0; i < pListFeatures.Count; i++)
|
||||
{
|
||||
pFeature = pListFeatures[i];
|
||||
IDictionary<string, object> FeatureAttri = pFeature.Attributes;
|
||||
string featureName = pFeature.FeatureTable.Layer.Name;
|
||||
attributes.Add(FeatureAttri);
|
||||
}
|
||||
queryResults.Add(new QueryResult(featureLayerName, attributes));
|
||||
}
|
||||
|
||||
ExtentLocationQueryResultsWindow resultsWindow = new ExtentLocationQueryResultsWindow();
|
||||
resultsWindow.resultCollection = queryResults;
|
||||
resultsWindow.Show();
|
||||
resultsWindow.Activate();
|
||||
MainMapView.GraphicsOverlays.Clear();
|
||||
_startLocation = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void Menu_Layers_Options_OnClick(object sender, RoutedEventArgs e)
|
||||
@ -1559,8 +1637,14 @@ namespace GisDevelop_Exp
|
||||
private void Menu_Query_Point_OnClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
selByGeometryType = 1;//设置其值为1
|
||||
m_CurOper = CURRENTOPERATION.ClickQuery;
|
||||
}
|
||||
|
||||
|
||||
private void Menu_Query_Envelope_OnClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
selByGeometryType = 2;//设置其值为2
|
||||
m_CurOper = CURRENTOPERATION.ExtentQuery;
|
||||
}
|
||||
}
|
||||
}
|
||||
28
GisDevelop_Exp/QueryResult.cs
Normal file
28
GisDevelop_Exp/QueryResult.cs
Normal file
@ -0,0 +1,28 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace GisDevelop_Exp;
|
||||
|
||||
public class QueryResult
|
||||
{
|
||||
private string name;
|
||||
private List<IDictionary<string, object>> attributes;
|
||||
|
||||
public QueryResult(string name, List<IDictionary<string, object>> Attributes)
|
||||
{
|
||||
this.name = name;
|
||||
this.attributes = Attributes;
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get => name;
|
||||
set => name = value ?? throw new ArgumentNullException(nameof(value));
|
||||
}
|
||||
|
||||
public List<IDictionary<string, object>> Attributes
|
||||
{
|
||||
get => attributes;
|
||||
set => attributes = value ?? throw new ArgumentNullException(nameof(value));
|
||||
}
|
||||
}
|
||||
14
GisDevelop_Exp/QueryResultWindow.xaml
Normal file
14
GisDevelop_Exp/QueryResultWindow.xaml
Normal file
@ -0,0 +1,14 @@
|
||||
<Window x:Class="GisDevelop_Exp.QueryResultWindow"
|
||||
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:local="clr-namespace:GisDevelop_Exp"
|
||||
mc:Ignorable="d"
|
||||
Title="QueryResultWindow" Height="450" Width="319"
|
||||
Loaded="QueryResultWindow_OnLoaded">
|
||||
<Canvas>
|
||||
<ComboBox x:Name="comboBoxSelectionCount" Canvas.Left="23" Canvas.Top="21" Width="273" HorizontalAlignment="Left" VerticalAlignment="Center" SelectionChanged="ComboBoxSelectionCount_OnSelectionChanged"/>
|
||||
<DataGrid x:Name="dataGridResult" Height="356" Width="276" d:ItemsSource="{d:SampleData ItemCount=5}" HorizontalAlignment="Center" Canvas.Top="58" VerticalAlignment="Top" Canvas.Left="20"/>
|
||||
</Canvas>
|
||||
</Window>
|
||||
69
GisDevelop_Exp/QueryResultWindow.xaml.cs
Normal file
69
GisDevelop_Exp/QueryResultWindow.xaml.cs
Normal file
@ -0,0 +1,69 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Shapes;
|
||||
using Esri.ArcGISRuntime.Data;
|
||||
using Esri.ArcGISRuntime.Mapping;
|
||||
|
||||
namespace GisDevelop_Exp
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for QueryResultWindow.xaml
|
||||
/// </summary>
|
||||
public partial class QueryResultWindow : Window
|
||||
{
|
||||
public QueryResultWindow()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private FeatureQueryResult featureQuerySet; //查询结果集合
|
||||
public FeatureQueryResult FeatureQuerySet
|
||||
{
|
||||
get { return featureQuerySet; }
|
||||
set { featureQuerySet = value; }
|
||||
}
|
||||
|
||||
private void QueryResultWindow_OnLoaded(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (featureQuerySet != null)//结果不为空
|
||||
{
|
||||
dataGridResult.AutoGenerateColumns = true;//数据格网控件自动生成列
|
||||
for(int i=1;i<= featureQuerySet.Count();i++)
|
||||
{
|
||||
comboBoxSelectionCount.Items.Add(i);//按照查询结果集中要素的数目为组合框添加项
|
||||
}
|
||||
Feature ft = featureQuerySet.First();//取得查询结果集合中第一个要素
|
||||
dataGridResult.ItemsSource = ft.Attributes;//设置数据格网对象中项的数据源
|
||||
// ft.FeatureTable.FeatureLayer.SelectFeature(ft);
|
||||
comboBoxSelectionCount.SelectedIndex = 0;
|
||||
((FeatureLayer)ft.FeatureTable.Layer).SelectFeature(ft);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void ComboBoxSelectionCount_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
|
||||
{
|
||||
if (featureQuerySet != null)//查询结果集不为空
|
||||
{
|
||||
int idx = comboBoxSelectionCount.SelectedIndex;//获得选择项的索引
|
||||
if (idx > -1)
|
||||
{
|
||||
Feature ft = featureQuerySet.ElementAt(idx);//获取索引所在的要素对象
|
||||
dataGridResult.ItemsSource = ft.Attributes;//设置数据格网对象中项的数据源
|
||||
// ft.FeatureTable.FeatureLayer.ClearSelection();//清空图层中的原有的选择
|
||||
// ft.FeatureTable.FeatureLayer.SelectFeature(ft);//在图层中重新选择当前所选要素
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user