3.4 Open online map
This commit is contained in:
parent
cc948d9ce6
commit
cb87a4a08d
@ -15,8 +15,12 @@
|
|||||||
<MenuItem x:Name="Menu_File" Header="文件">
|
<MenuItem x:Name="Menu_File" Header="文件">
|
||||||
<MenuItem x:Name="Menu_OpenShp" Header="打开Shp" Click="Menu_OpenShp_Click"/>
|
<MenuItem x:Name="Menu_OpenShp" Header="打开Shp" Click="Menu_OpenShp_Click"/>
|
||||||
<MenuItem x:Name="Menu_OpenGeodatabase" Header="打开Geodatabase" Click="Menu_OpenGeodatabase_Click"/>
|
<MenuItem x:Name="Menu_OpenGeodatabase" Header="打开Geodatabase" Click="Menu_OpenGeodatabase_Click"/>
|
||||||
|
<MenuItem x:Name="Menu_OpenOnlineMap" Header="打开在线地图" Click="Menu_OpenOnlineMap_OnClick"></MenuItem>
|
||||||
|
</MenuItem>
|
||||||
|
<MenuItem x:Name="Menu_View" Header="视图">
|
||||||
|
<MenuItem x:Name="Menu_Zoom_in" Header="放大" Click="Menu_Zoom_in_OnClick"></MenuItem>
|
||||||
|
<MenuItem x:Name="Menu_Zoom_out" Header="缩小" Click="Menu_Zoom_out_OnClick"></MenuItem>
|
||||||
</MenuItem>
|
</MenuItem>
|
||||||
<MenuItem x:Name="Menu_View" Header="视图"/>
|
|
||||||
</Menu>
|
</Menu>
|
||||||
<esri:MapView x:Name="MainMapView" Map="{Binding Map, Source={StaticResource MapViewModel}}" Margin="0,19,0,0" ViewpointChanged="MainMapView_OnViewpointChanged"/>
|
<esri:MapView x:Name="MainMapView" Map="{Binding Map, Source={StaticResource MapViewModel}}" Margin="0,19,0,0" ViewpointChanged="MainMapView_OnViewpointChanged"/>
|
||||||
<Border BorderBrush="#FF8B1D76" BorderThickness="2,2,2,2" HorizontalAlignment="Right" Height="180" Width="202" VerticalAlignment="Top" IsEnabled="False">
|
<Border BorderBrush="#FF8B1D76" BorderThickness="2,2,2,2" HorizontalAlignment="Right" Height="180" Width="202" VerticalAlignment="Top" IsEnabled="False">
|
||||||
|
|||||||
@ -16,7 +16,9 @@ using System.Windows.Navigation;
|
|||||||
using System.Windows.Shapes;
|
using System.Windows.Shapes;
|
||||||
using Esri.ArcGISRuntime.Geometry;
|
using Esri.ArcGISRuntime.Geometry;
|
||||||
using Esri.ArcGISRuntime.Symbology;
|
using Esri.ArcGISRuntime.Symbology;
|
||||||
|
using Esri.ArcGISRuntime.UI;
|
||||||
using Color = System.Drawing.Color;
|
using Color = System.Drawing.Color;
|
||||||
|
using Polygon = Esri.ArcGISRuntime.Geometry.Polygon;
|
||||||
|
|
||||||
namespace GisDevelop_Exp
|
namespace GisDevelop_Exp
|
||||||
{
|
{
|
||||||
@ -26,6 +28,10 @@ namespace GisDevelop_Exp
|
|||||||
public partial class MainWindow : Window
|
public partial class MainWindow : Window
|
||||||
{
|
{
|
||||||
private FeatureLayer _featureLayer;
|
private FeatureLayer _featureLayer;
|
||||||
|
|
||||||
|
private string _statesUrl =
|
||||||
|
"https://services.arcgis.com/jIL9msH9OI208GCb/arcgis/rest/services/USA_Daytime_Population_2016/FeatureServer/0";
|
||||||
|
private ServiceFeatureTable _featureTable;
|
||||||
public MainWindow()
|
public MainWindow()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
@ -106,5 +112,87 @@ namespace GisDevelop_Exp
|
|||||||
graphicOverlay.Graphics.Add(envGraphic);
|
graphicOverlay.Graphics.Add(envGraphic);
|
||||||
EagleMapView.GraphicsOverlays.Add(graphicOverlay);
|
EagleMapView.GraphicsOverlays.Add(graphicOverlay);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private double GetDistance(MapPoint p1, MapPoint p2)
|
||||||
|
{
|
||||||
|
double dx = p2.X - p1.X;
|
||||||
|
double dy = p2.Y - p1.Y;
|
||||||
|
return Math.Sqrt(dx * dx + dy * dy);
|
||||||
|
}
|
||||||
|
|
||||||
|
private double GetAngle(MapPoint p1, MapPoint p2)
|
||||||
|
{
|
||||||
|
double dx = p2.X - p1.X;
|
||||||
|
double dy = p2.Y - p1.Y;
|
||||||
|
return Math.Atan2(dy, dx) * 180 / Math.PI;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Menu_Zoom_in_OnClick(object sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Viewpoint initViewpoint = MainMapView.GetCurrentViewpoint(ViewpointType.CenterAndScale);
|
||||||
|
MainMapView.SetViewpointScaleAsync(initViewpoint.TargetScale / 2.0);
|
||||||
|
}
|
||||||
|
catch (Exception exception)
|
||||||
|
{
|
||||||
|
Console.WriteLine(exception);
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Menu_Zoom_out_OnClick(object sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Viewpoint initViewpoint = MainMapView.GetCurrentViewpoint(ViewpointType.CenterAndScale);
|
||||||
|
MainMapView.SetViewpointScaleAsync(initViewpoint.TargetScale * 2.0);
|
||||||
|
}
|
||||||
|
catch (Exception exception)
|
||||||
|
{
|
||||||
|
Console.WriteLine(exception);
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Menu_OpenOnlineMap_OnClick(object sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
OpenOnlineData();
|
||||||
|
}
|
||||||
|
|
||||||
|
private async void OpenOnlineData()
|
||||||
|
{
|
||||||
|
Map pMap = new Map();
|
||||||
|
pMap.Basemap=new Basemap(BasemapStyle.ArcGISTopographicBase);
|
||||||
|
_featureTable = new ServiceFeatureTable(new Uri(_statesUrl));
|
||||||
|
_featureLayer = new FeatureLayer(_featureTable);
|
||||||
|
_featureLayer.MaxScale = 1.0;
|
||||||
|
await _featureLayer.LoadAsync();
|
||||||
|
Viewpoint pVP = new Viewpoint(_featureLayer.FullExtent);
|
||||||
|
pMap.InitialViewpoint = pVP;
|
||||||
|
SimpleMarkerSymbol pMarkerSymbol = new SimpleMarkerSymbol(SimpleMarkerSymbolStyle.Circle, Color.Blue, 5.0);
|
||||||
|
SimpleLineSymbol pLineSymbol = new SimpleLineSymbol(SimpleLineSymbolStyle.Solid, Color.Red, 5.0);
|
||||||
|
SimpleFillSymbol pFillSymbol = new SimpleFillSymbol(SimpleFillSymbolStyle.Solid, Color.Pink, pLineSymbol);
|
||||||
|
SimpleRenderer pRenderer = new SimpleRenderer();
|
||||||
|
if (_featureLayer.FeatureTable.GeometryType == GeometryType.Polygon)
|
||||||
|
{
|
||||||
|
pRenderer.Symbol = pFillSymbol;
|
||||||
|
}else if (_featureLayer.FeatureTable.GeometryType == GeometryType.Point)
|
||||||
|
{
|
||||||
|
pRenderer.Symbol = pMarkerSymbol;
|
||||||
|
}else if (_featureLayer.FeatureTable.GeometryType == GeometryType.Polyline)
|
||||||
|
{
|
||||||
|
pRenderer.Symbol = pLineSymbol;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
pRenderer.Symbol = pFillSymbol;
|
||||||
|
}
|
||||||
|
_featureLayer.Renderer = pRenderer;
|
||||||
|
pMap.OperationalLayers.Add(_featureLayer);
|
||||||
|
MainMapView.Map = pMap;
|
||||||
|
MainMapView.SelectionProperties.Color = Color.Cyan;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -26,7 +26,6 @@ namespace GisDevelop_Exp
|
|||||||
_map = new Map(SpatialReferences.WebMercator)
|
_map = new Map(SpatialReferences.WebMercator)
|
||||||
{
|
{
|
||||||
InitialViewpoint = new Viewpoint(new Envelope(-180, -85, 180, 85, SpatialReferences.Wgs84)),
|
InitialViewpoint = new Viewpoint(new Envelope(-180, -85, 180, 85, SpatialReferences.Wgs84)),
|
||||||
#warning To use ArcGIS location services (including basemaps) specify your API Key access token or require the user to sign in using a valid ArcGIS account.
|
|
||||||
Basemap = new Basemap(BasemapStyle.ArcGISTopographic)
|
Basemap = new Basemap(BasemapStyle.ArcGISTopographic)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user