diff --git a/GisDevelop_Exp/MainWindow.xaml b/GisDevelop_Exp/MainWindow.xaml
index 21547a6..7e1eb87 100644
--- a/GisDevelop_Exp/MainWindow.xaml
+++ b/GisDevelop_Exp/MainWindow.xaml
@@ -24,6 +24,11 @@
+
diff --git a/GisDevelop_Exp/MainWindow.xaml.cs b/GisDevelop_Exp/MainWindow.xaml.cs
index 10fb498..fc1c338 100644
--- a/GisDevelop_Exp/MainWindow.xaml.cs
+++ b/GisDevelop_Exp/MainWindow.xaml.cs
@@ -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
{
///
@@ -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 _basemapOptions = new Dictionary()
@@ -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);
}
@@ -67,10 +80,11 @@ namespace GisDevelop_Exp
"AAPTxy8BH1VEsoebNVZXo8HurGPYSDOnAeIwA4pOmn4FxRfMsbp3zN7aIhAzuRolPS6JUAtf98pdWdQp1jjclJhIB-7QXbTXrBITqXti07DnOLsRnS9lGLYGImGh5vW_jSlnEBqxbbZQCs4S0y5-tHC0_kSFW9RD3Kv8hiDGt1IGSrs-96vwz6rycPenwu_cAwZHZyTahSAEHOR5A7j2y9sUsZ8HoYLcn2O9SI8OYw2tzr4xAAwqN1fcw6FMiVVpBSYWAT1_A4CN5Ivr";
InitializeAuthenticationManagerWithToken(token);
}
-
+
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)
@@ -104,10 +118,11 @@ namespace GisDevelop_Exp
Geodatabase _localGeodatabase;
System.Windows.Forms.OpenFileDialog fileDialog = new System.Windows.Forms.OpenFileDialog();
fileDialog.Filter = "Geodatabase文件(*.geodatabase)|*.geodatabase";
- if(fileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
+ if (fileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
_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)
@@ -200,7 +216,7 @@ namespace GisDevelop_Exp
private async void OpenOnlineData()
{
Map pMap = new Map();
- pMap.Basemap=new Basemap(BasemapStyle.ArcGISTopographicBase);
+ pMap.Basemap = new Basemap(BasemapStyle.ArcGISTopographicBase);
_featureTable = new ServiceFeatureTable(new Uri(_statesUrl));
_featureLayer = new FeatureLayer(_featureTable);
_featureLayer.MaxScale = 1.0;
@@ -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;
@@ -277,7 +296,7 @@ namespace GisDevelop_Exp
ArcGISPortal portal = await ArcGISPortal.CreateAsync();
// Create a portal item from the ArcGIS Portal object using a portal item string.
PortalItem portalItem = await PortalItem.CreateAsync(portal, "29d7c59212ef479995f5b42bacc9de4c");
- FeatureLayer featureLayer = new FeatureLayer(portalItem,0);
+ FeatureLayer featureLayer = new FeatureLayer(portalItem, 0);
map.OperationalLayers.Add(featureLayer);
MainMapView.Map = map;
}
@@ -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 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 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 pFields = pQueryResult.Fields;
+ for (int i = 0; i < pListFeatures.Count; i++)
+ {
+ pFeature = pListFeatures[i];
+ IDictionary 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 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;
}
}
-}
+}
\ No newline at end of file
diff --git a/GisDevelop_Exp/online.png b/GisDevelop_Exp/online.png
new file mode 100644
index 0000000..83fba13
Binary files /dev/null and b/GisDevelop_Exp/online.png differ