.NET MAUI地图选择
Map允许用户从每个ShapefileLayer应用的源中选择一个或多个形状。该功能为用户的操作提供了视觉和编程反馈。
以下成员的ShapefileLayer类都有相关的选择:
SelectionMode
:枚举属性,指示选择的内容。它可以接收以下值:没有一个
单
多个
SelectedShape
(类型的IShape
):定义当前选择的形状实例。当启用多重选择时,此值将设置为第一个选择的形状。SelectedShapes
(类型的ObservableCollection< IShape>
):读取当前选定形状的集合。当选择是单个形状时,只能选择一个形状-因此集合将具有count = 1。SelectedShapeStyle
(类型的MapShapeStyle
):通过提供的StrokeWidth, StrokeColor和FillColor属性来定义所选形状的外观。有关MapShapeStyle使用的更多细节,请访问形状样式的话题。
定义RadMapSelectionMode
:
< / telerik: RadMap >
在哪里源
和数据源
应该分别设置为.shp和.dbf文件:
var assembly = this.GetType().Assembly;var source = MapSource.FromResource("SDKBrowserMaui.Examples.MapControl.world. "轴马力”,装配);var dataSource = MapSource.FromResource("SDKBrowserMaui.Examples.MapControl.world. "dbf”、装配);this.reader.Source =来源;this.reader.DataSource =数据源;
添加命名空间:
xmlns: telerik = " http://schemas.telerik.com/2022/xaml/maui "
看看下面的RadMap和一些选定的形状是什么样子的:
以编程方式选择形状的示例
下面的代码片段演示了如何以编程方式选择某个形状。在这个示例中,使用的ESRI文件包含世界地图,因此选择的形状是一个国家。该示例使用形状属性遍历所有可用的形状。
让我们选择/取消选择“France”,例如,点击按钮:
事件处理程序:
private void selectfranceclick(对象发送方,EventArgs e) {var shape = this.GetItemFromCountryName("France");if (shape != null) {this. mapshapelayer . selectedshape . add (shape);}} private void deselectfranceclick(对象发送方,EventArgs e) {var shape = this.GetItemFromCountryName("France");if (shape != null && this. mapshapelayer . selectedshape . contains (shape)) {this. mapshapelayer . selectedshape . remove (shape);}} private IShape GetItemFromCountryName(string countryName) {foreach (var shape in this.reader.Shapes) {var name = shape. getattribute ("CNTRY_NAME").ToString();if (name == countryName){返回形状;}}返回null;}
xmlns: telerik = " http://schemas.telerik.com/2022/xaml/maui "
结果如下:
的Map/Selection文件夹中可以找到一个示例编程选择示例SDK .NET MAUI演示应用程序。