2-1 Query function
This commit is contained in:
parent
a7b979347c
commit
0ecca052cf
@ -24,6 +24,11 @@
|
||||
<MenuItem x:Name="Menu_Full_Extent" Header="全图" Click="Menu_Full_Extent_OnClick"></MenuItem>
|
||||
<MenuItem x:Name="Menu_Wrap_Around" Header="开启漫游" Click="Menu_Wrap_Around_OnClick"></MenuItem>
|
||||
</MenuItem>
|
||||
<MenuItem x:Name="Menu_Identify" Header="查询">
|
||||
<MenuItem x:Name="Menu_Simple_Identify" Header="简单查询" Click="Menu_Simple_Identify_OnClick"></MenuItem>
|
||||
<MenuItem x:Name="Menu_Click_Indentify" Header="点击查询" Click="Menu_Click_Indentify_OnClick"></MenuItem>
|
||||
<MenuItem x:Name="Menu_Identify_Indentify" Header="Indentify查询" Click="Menu_Identify_Indentify_OnClick"></MenuItem>
|
||||
</MenuItem>
|
||||
</Menu>
|
||||
<esri:MapView x:Name="MainMapView" Map="{Binding Map, Source={StaticResource MapViewModel}}" Margin="0,19,0,0" ViewpointChanged="MainMapView_OnViewpointChanged" GeoViewTapped="MainMapView_OnGeoViewTapped"/>
|
||||
<Border BorderBrush="#FF8B1D76" BorderThickness="2,2,2,2" HorizontalAlignment="Right" Height="180" Width="202" VerticalAlignment="Top" IsEnabled="False">
|
||||
|
||||
@ -24,6 +24,14 @@ using Color = System.Drawing.Color;
|
||||
using Geometry = Esri.ArcGISRuntime.Geometry.Geometry;
|
||||
using Polygon = Esri.ArcGISRuntime.Geometry.Polygon;
|
||||
|
||||
enum CURRENTOPERATION
|
||||
{
|
||||
NullOpe = -1,
|
||||
SelectQuery = 0,
|
||||
IdentifyQuery,
|
||||
PanMap,
|
||||
}
|
||||
|
||||
namespace GisDevelop_Exp
|
||||
{
|
||||
/// <summary>
|
||||
@ -35,6 +43,7 @@ namespace GisDevelop_Exp
|
||||
|
||||
private string _statesUrl =
|
||||
"https://services.arcgis.com/jIL9msH9OI208GCb/arcgis/rest/services/USA_Daytime_Population_2016/FeatureServer/0";
|
||||
|
||||
private ServiceFeatureTable _featureTable;
|
||||
|
||||
private readonly Dictionary<string, Basemap> _basemapOptions = new Dictionary<string, Basemap>()
|
||||
@ -51,9 +60,13 @@ namespace GisDevelop_Exp
|
||||
{ "Navigation (Vector)", new Basemap(BasemapStyle.ArcGISNavigation) },
|
||||
{ "OpenStreetMap (Raster)", new Basemap(BasemapStyle.OSMNavigation) }
|
||||
};
|
||||
|
||||
private CURRENTOPERATION m_CurOper;
|
||||
|
||||
public MainWindow()
|
||||
{
|
||||
InitializeComponent();
|
||||
m_CurOper = CURRENTOPERATION.NullOpe;
|
||||
Initialize();
|
||||
EagleMapView.Map = new Map(BasemapStyle.ArcGISImageryStandard);
|
||||
}
|
||||
@ -70,7 +83,8 @@ namespace GisDevelop_Exp
|
||||
|
||||
private void InitializeAuthenticationManagerWithToken(string token)
|
||||
{
|
||||
AuthenticationManager.Current.AddCredential(new OAuthTokenCredential(new Uri("https://services3.arcgis.com/Po7vxnPH4Do7ht5I/arcgis/rest/services/test/MapServer"),token));
|
||||
AuthenticationManager.Current.AddCredential(new OAuthTokenCredential(
|
||||
new Uri("https://services3.arcgis.com/Po7vxnPH4Do7ht5I/arcgis/rest/services/test/MapServer"), token));
|
||||
}
|
||||
|
||||
private void Menu_OpenShp_Click(object sender, RoutedEventArgs e)
|
||||
@ -108,6 +122,7 @@ namespace GisDevelop_Exp
|
||||
{
|
||||
_slocalGeodatabasePath = fileDialog.FileName;
|
||||
}
|
||||
|
||||
if (System.IO.File.Exists(_slocalGeodatabasePath))
|
||||
{
|
||||
_localGeodatabase = await Geodatabase.OpenAsync(_slocalGeodatabasePath);
|
||||
@ -122,6 +137,7 @@ namespace GisDevelop_Exp
|
||||
geodatabaseMap.OperationalLayers.Add(layer);
|
||||
_featureLayer = layer;
|
||||
}
|
||||
|
||||
Viewpoint geodatabaseViewPoint = new Viewpoint(_featureLayer.FullExtent);
|
||||
geodatabaseMap.InitialViewpoint = geodatabaseViewPoint;
|
||||
MainMapView.Map = geodatabaseMap;
|
||||
@ -139,7 +155,8 @@ namespace GisDevelop_Exp
|
||||
Esri.ArcGISRuntime.Geometry.Polygon vExtent = MainMapView.VisibleArea;
|
||||
Envelope eagleViewEnvelop = vExtent.Extent;
|
||||
Color lineColor = Color.FromArgb(255, 255, 0, 0);
|
||||
SimpleLineSymbol lineSymbol = new Esri.ArcGISRuntime.Symbology.SimpleLineSymbol(SimpleLineSymbolStyle.Dash, lineColor,2.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);
|
||||
var graphicOverlay = new Esri.ArcGISRuntime.UI.GraphicsOverlay();
|
||||
@ -174,7 +191,6 @@ namespace GisDevelop_Exp
|
||||
Console.WriteLine(exception);
|
||||
throw;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void Menu_Zoom_out_OnClick(object sender, RoutedEventArgs e)
|
||||
@ -214,10 +230,12 @@ namespace GisDevelop_Exp
|
||||
if (_featureLayer.FeatureTable.GeometryType == GeometryType.Polygon)
|
||||
{
|
||||
pRenderer.Symbol = pFillSymbol;
|
||||
}else if (_featureLayer.FeatureTable.GeometryType == GeometryType.Point)
|
||||
}
|
||||
else if (_featureLayer.FeatureTable.GeometryType == GeometryType.Point)
|
||||
{
|
||||
pRenderer.Symbol = pMarkerSymbol;
|
||||
}else if (_featureLayer.FeatureTable.GeometryType == GeometryType.Polyline)
|
||||
}
|
||||
else if (_featureLayer.FeatureTable.GeometryType == GeometryType.Polyline)
|
||||
{
|
||||
pRenderer.Symbol = pLineSymbol;
|
||||
}
|
||||
@ -225,6 +243,7 @@ namespace GisDevelop_Exp
|
||||
{
|
||||
pRenderer.Symbol = pFillSymbol;
|
||||
}
|
||||
|
||||
_featureLayer.Renderer = pRenderer;
|
||||
pMap.OperationalLayers.Add(_featureLayer);
|
||||
MainMapView.Map = pMap;
|
||||
@ -287,9 +306,146 @@ namespace GisDevelop_Exp
|
||||
MapPoint mapLocation = e.Location;
|
||||
Geometry myGeometry = mapLocation.Project(SpatialReferences.Wgs84);
|
||||
MapPoint projectedLocation = (MapPoint)myGeometry;
|
||||
string mapLocationDescription = string.Format("纬度: {0:F3} 经度:{1:F3}", projectedLocation.Y, projectedLocation.X);
|
||||
string mapLocationDescription =
|
||||
string.Format("纬度: {0:F3} 经度:{1:F3}", projectedLocation.Y, projectedLocation.X);
|
||||
CalloutDefinition myCalloutDefinition = new CalloutDefinition("当前位置:", mapLocationDescription);
|
||||
MainMapView.ShowCalloutAt(mapLocation, myCalloutDefinition);
|
||||
if (m_CurOper == CURRENTOPERATION.SelectQuery)
|
||||
{
|
||||
if (MainMapView.Map.OperationalLayers.Count > 0)
|
||||
{
|
||||
FeatureLayer _featureLayer = MainMapView.Map.OperationalLayers.First() as FeatureLayer;
|
||||
if (_featureLayer != null)
|
||||
{
|
||||
FunClickQuery(e.Location, _featureLayer);
|
||||
}
|
||||
}
|
||||
}else if (m_CurOper == CURRENTOPERATION.IdentifyQuery)
|
||||
{
|
||||
if (MainMapView.Map.OperationalLayers.Count > 0)
|
||||
{
|
||||
FeatureLayer _featureLayer = MainMapView.Map.OperationalLayers.First() as FeatureLayer;
|
||||
if (_featureLayer != null)
|
||||
{
|
||||
FunIndentifyQuery(e.Position, _featureLayer);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void Menu_Simple_Identify_OnClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
string sQueryFieldName = "Name";
|
||||
string stateName = "New York";
|
||||
FeatureLayer _featureLayer = MainMapView.Map.OperationalLayers[0] as FeatureLayer;
|
||||
if (_featureLayer != null)
|
||||
{
|
||||
QueryStateFeature3(_featureLayer, sQueryFieldName, stateName);
|
||||
}
|
||||
}
|
||||
|
||||
private async Task QueryStateFeature3(FeatureLayer _featureLayer, string sQueryFieldName, string stateName)
|
||||
{
|
||||
try
|
||||
{
|
||||
QueryParameters pQueryP = new QueryParameters();
|
||||
string sformat = stateName.Trim().ToUpper();
|
||||
pQueryP.WhereClause = "upper(" + sQueryFieldName + ") LIKE '%" + sformat + "%'";
|
||||
await _featureLayer.SelectFeaturesAsync(pQueryP, Esri.ArcGISRuntime.Mapping.SelectionMode.New);
|
||||
FeatureQueryResult pQueryResult = await _featureLayer.GetSelectedFeaturesAsync();
|
||||
List<Feature> pListFeatures = pQueryResult.ToList();
|
||||
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);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
System.Windows.MessageBox.Show("【程序出错】" + ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
private async void FunClickQuery(MapPoint pPoint, FeatureLayer _featureLayer)
|
||||
{
|
||||
double tol = 3; //容差设为3像素
|
||||
double mapTol = tol * MainMapView.UnitsPerPixel;
|
||||
MapPoint pNormalPoint = pPoint;
|
||||
if (MainMapView.IsWrapAroundEnabled)
|
||||
{
|
||||
pNormalPoint = (MapPoint)GeometryEngine.NormalizeCentralMeridian(pPoint);
|
||||
}
|
||||
|
||||
Envelope selEnv = new Envelope(pNormalPoint.X - mapTol, pNormalPoint.Y - mapTol, pNormalPoint.X + mapTol,
|
||||
pNormalPoint.Y + mapTol, MainMapView.SpatialReference);
|
||||
QueryParameters pQueryPara = new QueryParameters();
|
||||
pQueryPara.Geometry = selEnv;
|
||||
pQueryPara.SpatialRelationship = SpatialRelationship.Intersects;
|
||||
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;
|
||||
for (int i = 0; i < pListFeatures.Count; i++)
|
||||
{
|
||||
pFeature = pListFeatures[i];
|
||||
IDictionary<string,object> FeatureAttri = pFeature.Attributes;
|
||||
string str;
|
||||
object obj;
|
||||
sInfo += "选中的第" + i.ToString() + "个要素的属性\n\r";
|
||||
for (int j = 0; j < FeatureAttri.Count; j++)
|
||||
{
|
||||
str = FeatureAttri.Keys.ElementAt(j);
|
||||
obj = FeatureAttri.Values.ElementAt(j);
|
||||
sInfo += str + ":" + obj.ToString() + "\r\n";
|
||||
}
|
||||
MessageBox.Show(sInfo);
|
||||
}
|
||||
}
|
||||
|
||||
private async void FunIndentifyQuery(System.Windows.Point pPoint, FeatureLayer pFLayer)
|
||||
{
|
||||
IdentifyLayerResult identifyLayerResult = await MainMapView.IdentifyLayerAsync(pFLayer,pPoint,20,false);
|
||||
if (!identifyLayerResult.GeoElements.Any())
|
||||
{
|
||||
return;
|
||||
}
|
||||
Feature identifyFeature = (Feature)identifyLayerResult.GeoElements.First();
|
||||
IDictionary<string,object> FeatureAttri = identifyFeature.Attributes;
|
||||
string str;
|
||||
string tempStr = "";
|
||||
object obj;
|
||||
for (int i = 0; i < FeatureAttri.Count; i++)
|
||||
{
|
||||
str = FeatureAttri.Keys.ElementAt(i);
|
||||
obj = FeatureAttri.Values.ElementAt(i);
|
||||
tempStr += str + ":" + obj.ToString() + "\r\n";
|
||||
}
|
||||
System.Windows.MessageBox.Show(tempStr);
|
||||
}
|
||||
|
||||
private void Menu_Click_Indentify_OnClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
m_CurOper = CURRENTOPERATION.SelectQuery;
|
||||
}
|
||||
|
||||
private void Menu_Identify_Indentify_OnClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
m_CurOper = CURRENTOPERATION.IdentifyQuery;
|
||||
}
|
||||
}
|
||||
}
|
||||
BIN
GisDevelop_Exp/online.png
Normal file
BIN
GisDevelop_Exp/online.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 13 KiB |
Loading…
Reference in New Issue
Block a user