簡體   English   中英

無法使用SharpKML設置單個圖標標題

[英]Cannot set individual icon heading using SharpKML

使用VB(VS2010)中的SharpKML庫,我可以為每個地標創建帶有自定義圖標的kml文件。 地標是在循環中創建的,我想為每個地標設置圖標的heading屬性。

'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幫我設置單個地標的圖標標題嗎?

標題實際上是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;

如果這樣不起作用,則可能必須為每個地標創建和設置樣式,但是我敢肯定情況並非如此。 同樣,請發回郵件,讓我們知道您的結果。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM