ArcGIS Runtime WPF SDK (3) 小试身手
分享
本节代码
在上一节中,了解了,WPF API的各个命名空间的作用,本节内容包括,创建一个地图,加载一个要素图层,并支持点选查询。
效果如下:
底图
要素图层
支持点选
弹出窗
在xaml中加入
在cs中加入相应代码,控制popup位置,以及显示内容
使用ArcGIS Runtime WPF SDK (1)创建自己的地图应用程序:http://zhihu.esrichina.com.cn/article/3555
ArcGIS Runtime WPF SDK (2)命名空间解析:http://zhihu.esrichina.com.cn/article/3556
ArcGIS Runtime WPF SDK (3)小试身手:http://zhihu.esrichina.com.cn/article/3552
ArcGIS Runtime WPF SDK (4)绘制,编辑Graphic:http://zhihu.esrichina.com.cn/article/3553
文章来源:http://blog.csdn.net/uninterrupted/article/details/78043397
在上一节中,了解了,WPF API的各个命名空间的作用,本节内容包括,创建一个地图,加载一个要素图层,并支持点选查询。
效果如下:
底图
var myMap = new Map(Basemap.CreateTopographic());
要素图层
// Create Uri for the feature service Uri featureServiceUri = new Uri( "http://sampleserver6.arcgisonl ... 6quot;);
// Initialize feature table using a url to feature server url
var featureTable = new ServiceFeatureTable(featureServiceUri);
// Initialize a new feature layer based on the feature table
_featureLayer = new FeatureLayer(featureTable);
await _featureLayer.LoadAsync();
// Check for the load status. If the layer is loaded then add it to map if (_featureLayer.LoadStatus == LoadStatus.Loaded) { // Add the feature layer to the map myMap.OperationalLayers.Add(_featureLayer);
}
支持点选
// Set the selection color for feature layer
_featureLayer.SelectionColor = Colors.Cyan;
// Set the selection width
_featureLayer.SelectionWidth = 3;
// Add tap event handler for mapview
MyMapView.GeoViewTapped += OnMapViewTapped;
pivate async void OnMapViewTapped(object sender, GeoViewInputEventArgs e)
{
try
{
// Define the selection tolerance (half the marker symbol size so that any click on the symbol will select the feature)
double tolerance = 14;
// Convert the tolerance to map units
double mapTolerance = tolerance * MyMapView.UnitsPerPixel;
// Define the envelope around the tap location for selecting features
var selectionEnvelope = new Envelope(e.Location.X - mapTolerance, e.Location.Y - mapTolerance, e.Location.X + mapTolerance,
e.Location.Y + mapTolerance, MyMapView.Map.SpatialReference);
// Define the query parameters for selecting features
var queryParams = new QueryParameters();
// Set the geometry to selection envelope for selection by geometry
queryParams.Geometry = selectionEnvelope;
// Select the features based on query parameters defined above
await _featureLayer.SelectFeaturesAsync(queryParams, Esri.ArcGISRuntime.Mapping.SelectionMode.New);
}
catch (Exception ex)
{
MessageBox.Show("Sample error", ex.ToString());
}
}
弹出窗
在xaml中加入
<Grid>
<esri:MapView x:Name="MyMapView" />
<Border Name="myPopup" Width="200" Height="100" Margin="0,0,100,200">
<!--<Path x:Name="myPopupPath"> <Path.Data> <PathGeometry x:Name="myPopupPathGeometry" Figures="{Binding FiguresPopupPathGeometry}"/> </Path.Data> </Path>-->
<TextBlock Background="White" Foreground="Blue">Test</TextBlock>
</Border>
</Grid>
在cs中加入相应代码,控制popup位置,以及显示内容
bool hasResult = false;
foreach(var r in _queryResult)
{
hasResult = true;
Feature f = r as Feature;
string attribute = "";
foreach(var a in f.Attributes)
{
attribute = attribute + a.ToString() + "\n";
}
MapPoint p = f.Geometry as MapPoint;
Point sp = MyMapView.LocationToScreen(p);
TextBlock popupText = new TextBlock();
popupText.Background = Brushes.LightBlue;
popupText.Foreground = Brushes.Blue;
popupText.Text = attribute;
myPopup.Child = popupText;
myPopup.Width = 200;
myPopup.Height = 100;
var b = MyMapView.Margin;
myPopup.Margin = new Thickness(sp.X, sp.Y, MyMapView.ActualWidth - 200 - sp.X, MyMapView.ActualHeight - 100 - sp.Y);
}
if(!hasResult)
{
myPopup.Width = myPopup.Height = 0;
}
使用ArcGIS Runtime WPF SDK (1)创建自己的地图应用程序:http://zhihu.esrichina.com.cn/article/3555
ArcGIS Runtime WPF SDK (2)命名空间解析:http://zhihu.esrichina.com.cn/article/3556
ArcGIS Runtime WPF SDK (3)小试身手:http://zhihu.esrichina.com.cn/article/3552
ArcGIS Runtime WPF SDK (4)绘制,编辑Graphic:http://zhihu.esrichina.com.cn/article/3553
文章来源:http://blog.csdn.net/uninterrupted/article/details/78043397
0 个评论
相关问题
- 如何优雅的使用ArcGIS知乎?
- 建设ArcGIS知乎平台的目和意义?
- ArcGIS知乎社区改进意见征集
- 【抽奖结果已出】ArcGIS知乎社区活动 之 你不知道的地理空间革命【转发分享有奖】【附奖品寄送照片】
- 苹果系统下可以使用arcgis 吗?
- arcgis版本兼容性
- 请问ArcGIS适合在局域网内用javaweb做二次开发吗?
- ArcGIS 知乎社区活动 之 字幕组加鸡腿暨KBP字幕组招新【获奖名单公布与优秀作品展示】
- ArcGIS 知乎社区活动 之 2018拒绝boring,来,在线答题赢kindle【结果已出,速来领奖】
- 请问大神们,怎么用ArcGIS做城镇间经济联系强度的图?
- 在Visual studio 2015 中使用 Arcgis API for JavaScript v3.16 如何实现代码智能提示?