Access "styleurl" of a Placemark from code

2 posts, 0 answers
  1. Vidyadhar
    Vidyadhar avatar
    23 posts
    Member since:
    Oct 2011

    Posted 12 Nov 2012 Link to this post


    I was wondering if there is a way to access the "styleurl" tag of a placemark in a kml file from code. My requirement is that, I have multiple map backgrounds and I want to change the color of the elements being displayed on the map with a change in the map background. I have different types of elements like, MapPinPoints,MapPolyLines,MapPolygons on the map. Default Icons for PinPoints and default line color for PolyLines are configured as style elements in the kml file. And these styles are referenced in the placemarks as styleurls. Recently, we've added multiple map providers and I have to change the icons and line colors based on the background selected by the user and to achieve that, I guess, I've to access the styleurl of the placemark and edit it accordingly, but I didn't find a way. Here is a trimmed down version of one of my kml files. 

    <?xml version="1.0" encoding="utf-8"?>
    <Style id="PinPoint_IconStyle">
    <Style id="PolyLine_LineStyle">
            <coordinates>-123.13414,49.050929,0 -117.210126,49.01362,0</coordinates>

    I read this kml file using KMLReader and get the List of FrameworkElements. When I iterate through the list, I need to be able to access the "styleurl" tag of each item. Is there a way to retrieve that?

  2. Andrey
    Andrey avatar
    1681 posts

    Posted 15 Nov 2012 Link to this post

    Hello Vidyadhar,

    The KMLReader does not allow to access the "styleurl" of elements which have already been read. They are used during the reading process only.
    So, you can change styles before loading of KML. Or you can change appearance of elements after you get the List of FrameworkElements using the appropriate properties of them. In this case you should check a type of each element, cast it to appropriate type, and then you can change its properties such as Fill, Stroke and StrokeThickness for MapSape object like MapPolyLine and MapPolygon. Also you can change appropriate properties of the MapPinPoints.
    For more information about the appearance of these elements you can take a look at the following topics of our online documentation:

    Andrey Murzov
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  3. DevCraft banner
Back to Top