【问题标题】:Cannot set individual icon heading using SharpKML无法使用 SharpKML 设置单个图标标题
【发布时间】:2013-01-29 09:30:19
【问题描述】:

使用 VB (VS2010) 中的 SharpKML 库,我可以为每个地标创建带有自定义图标的 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 为单个地标设置图标标题?

【问题讨论】:

    标签: vb.net kml sharpkml


    【解决方案1】:

    Heading 实际上是 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;
    

    如果这不起作用,您可能必须为每个地标创建和设置样式,但我很确定情况并非如此。再次,请回帖,让我们知道你是怎么做到的。

    【讨论】:

    • 谢谢马修!我几乎完全按照您的示例进行操作,并且效果很好!我开始认为使用 SharpKML 无法做到这一点
    • 欢迎您 - 大部分都是在我的脑海中完成的,所以我总是第二次猜测语法。虽然我喜欢 SharpKML,但我还没有找到一个地方,它不允许我做一些我知道可以在 KML 中完成的事情。
    猜你喜欢
    • 2018-02-26
    • 2020-12-24
    • 1970-01-01
    • 2021-07-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-07-03
    相关资源
    最近更新 更多