Cannot set individual icon heading using SharpKML

1.7k views Asked by At

Using SharpKML library from VB (VS2010), I can create kml files with a custom icon for each placemark. The placemarks are created in a loop and I want to set the icon's heading property for each placemark.

'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

Can anybody help me set the icon heading for an individual placemark using SharpKML?

1

There are 1 answers

2
Matthew On BEST ANSWER

The Heading is actually a property of IconStyle and not Icon (Icon is a child property of IconStyle and only specifies the URL to the icon image.

In your code above it would be (from memory):

kmlStyle.Icon.Heading = 90;

Because you are using a common style for all items I believe you can override just parts of a Style like this inside your loop (please post the result if you test):

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

If that doesn't work you might have to create and set a style per Placemark, but i am pretty sure that is not the case. Again, please post back and let us know how you make out.