首页 / C# / c#-在SHARPMAP中创建新图层
c#-在SHARPMAP中创建新图层
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了c#-在SHARPMAP中创建新图层,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2210字,纯文字阅读大概需要4分钟。
内容图文
我正在制作Sharpmap,说我有美国地图,如何在地图上添加新图层?
因为我需要在基本层上写状态的名称,并用不同的颜色为每个状态着色.
是否可以在Sharpmaps中实现这个目标?
解决方法:
您必须使用“自定义它们”为每个状态着色,并使用“标签层”作为状态名称
您必须先定义一个委托方法.委托将FeatureDataRow作为参数,然后您就可以处理自定义样式
例如
private SharpMap.Styles.VectorStyle GetCountryStyle(SharpMap.Data.FeatureDataRow row)
{
SharpMap.Styles.VectorStyle style = new SharpMap.Styles.VectorStyle();
switch (row["NAME"].ToString().ToLower())
{
case "denmark": //If country name is Danmark, fill it with green
style.Fill = Brushes.Green;
return style;
case "united states": //If country name is USA, fill it with Blue and add a red outline
style.Fill = Brushes.Blue;
style.Outline = Pens.Red;
return style;
case "china": //If country name is China, fill it with red
style.Fill = Brushes.Red;
return style;
default:
break;
}
//If country name starts with S make it yellow
if (row["NAME"].ToString().StartsWith("S"))
{
style.Fill = Brushes.Yellow;
return style;
}
// If geometry is a (multi)polygon and the area of the polygon is less than 30, make it cyan
else if (row.Geometry is GeoAPI.Geometries.IPolygonal && row.Geometry.Area < 30)
{
style.Fill = Brushes.Cyan;
return style;
}
else //None of the above -> Use the default style
return null;
}
然后将图层的Theme属性设置为此方法
SharpMap.Rendering.Thematics.CustomTheme myTheme = new SharpMap.Rendering.Thematics.CustomTheme(GetCountryStyle);
myVectorLayer.Theme = myTheme ;
对于标签图层,您必须按LabelLayer定义新图层
例如
//Name of table in database
string tablename = "Roads";
//Name of object ID column - MUST be integer!
string idColumn = "gid";
//Create layer
SharpMap.Layers.VectorLayer layRoads= new SharpMap.Layers.VectorLayer("Roads");
layRoads.DataSource = datasource;
//Set up a road label layer
SharpMap.Layers.LabelLayer layRoadLabel = new SharpMap.Layers.LabelLayer("Road labels");
//Set the datasource to that of layRoads.
layRoadLabel.DataSource = layRoads.DataSource;
layRoadLabel.Enabled = true;
//Specifiy field that contains the label string.
layRoadLabel.LabelColumn = "RoadOfName";
//Add layer to map
myMap.Layers.Add(layRoads);
//Add label layer to map
myMap.Layers.Add(layRoadLabel);
告诉所有here
内容总结
以上是互联网集市为您收集整理的c#-在SHARPMAP中创建新图层全部内容,希望文章能够帮你解决c#-在SHARPMAP中创建新图层所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。