无法使用SharpKML设置单个图标标题

时间:2013-01-29 09:30:20

标签: vb.net kml sharpkml

使用VB的SharpKML库(VS2010),我可以为每个地标创建带有自定义图标的kml文件。地标是在循环中创建的,我想为每个地标设置图标的标题属性。

'Define the style for the icon
Dim kmlStyle As New SharpKml.Dom.Style
kmlStyle.Id = "ShipIcon"
kmlStyle.Icon = New SharpKml.Dom.IconStyle
kmlStyle.Icon.Icon = New SharpKml.Dom.IconStyle.IconLink(New System.Uri("http://www.mysite.com/mapfiles/ship4.png")) 
kmlStyle.Icon.Scale = 1

Poscommand.CommandText = "SELECT * FROM Ships"
PosReader = Poscommand.ExecuteReader()

While PosReader.Read()
   'Add placemark for position
   kmlPosPoint = New SharpKml.Dom.Point
   kmlPosPoint.Coordinate = New SharpKml.Base.Vector(PosReader("Lat"), PosReader("Lon"))
   kmlPosPlaceMark = New SharpKml.Dom.Placemark
   kmlPosPlaceMark.Geometry = kmlPosPoint
   kmlPosPlaceMark.Name = "My Name"
   kmlPosPlaceMark.StyleUrl = New System.Uri("#ShipIcon", UriKind.Relative)
   'SET icon.heading HERE???  How to access icon heading property for this placemark only???
End While

有人可以帮我用SharpKML设置单个地标的图标标题吗?

1 个答案:

答案 0 :(得分:1)

标题实际上是IconStyle的属性而不是Icon(Icon是IconStyle的子属性,只指定图标图像的URL。

在上面的代码中,它(来自内存):

kmlStyle.Icon.Heading = 90;

因为您对所有项目都使用了一种通用样式,我相信您可以在循环内覆盖样式的一部分(如果您测试,请发布结果):

kmlPosPlaceMark.StyleUrl = New System.Uri("#ShipIcon", UriKind.Relative);
Style s = new Style();
s.Icon = new IconStyle();
s.Icon.Heading = 90;
kmlPosPlaceMark.StyleSelector = s;

如果这不起作用,您可能需要为每个地标创建和设置样式,但我很确定不是这样。再次,请回复并让我们知道你是如何做出来的。