形状样式
的ShapefileLayer公开ShapeStyle/SelectedShapeStyle同时ShapeStyleSelector属性,这将有助于实现所需的外观和形状在地图上的感觉。
形状样式
ShapeStyle而且SelectedShapeStyle属性为类型MapShapeStyle它为形状提供了以下样式选项:
- StrokeWidth;
- StrokeColor;
- FillColor。
下面的代码片段显示了如何应用ShapeStyle属性:
< telerikMap: ShapefileLayer。ShapeStyle>
结果如下:
在哪里源和数据源mapshaperreader的.shp和.dbf文件分别设置为:
var assembly = this.GetType().Assembly;var source = MapSource.FromResource("SDKBrowser.Examples.MapControl.world. "轴马力”,装配);var dataSource = MapSource.FromResource("SDKBrowser.Examples.MapControl.world. "dbf”、装配);this.reader.Source =源;this.reader.DataSource = dataSource;
形状StyleSelector
通过ShapeStyleSelector属性,你可以实现条件样式。
下面的例子展示了如何根据每个形状的特定属性值对形状应用不同的样式。
首先,创建应该继承的选择器类MapShapeStyleSelector:
public类PopulationShapeStyleSelector: MapShapeStyleSelector {public MapShapeStyle HighPopulationShapeStyle {get;设置;} public MapShapeStyle MediumPopulationShapeStyle {get;设置;} public MapShapeStyle LowPopulationShapeStyle {get;设置;} public override MapShapeStyle SelectStyle(对象形状,BindableObject容器){var attributesShape =形状为IShape;if (attributesShape != null) {var populationText = attributesShape. getattribute ("POP_CNTRY").ToString();int人口;如果(int)。TryParse(populationText, out population)) { if (population > 20000000) { return this.HighPopulationShapeStyle; } else if (population < 1000000) { return this.LowPopulationShapeStyle; } return this.MediumPopulationShapeStyle; } } return null; } }
然后,将Styles定义为ResourceDictionary中的资源:
<: PopulationShapeStyleSelector。MediumPopulationShapeStyle> <: PopulationShapeStyleSelector。LowPopulationShapeStyle>
最后,添加应用PopulationShapeStyleSelector的RadMap控件定义;
< / telerikMap: RadMap >
请看下面的截图:
的“地图/功能”文件夹中可以找到形状样式示例浏览器应用程序.