2

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?

Matthew
  • 9,851
  • 4
  • 46
  • 77
Guy
  • 413
  • 6
  • 20

1 Answers1

1

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.

Matthew
  • 9,851
  • 4
  • 46
  • 77
  • Thank you Matthew! I followed your example almost to the letter and it works perfectly! I was beginning to think there was no way to do this using SharpKML – Guy Jan 29 '13 at 16:17
  • You welcome - was done mostly out of my head so I always second guess the syntax. I love SharpKML though and have yet to find a place where it did not let me do something that I knew could be accomplished in KML. – Matthew Jan 29 '13 at 16:31