This is a migrated thread and some comments may be shown as answers.

Access "styleurl" of a Placemark from code

1 Answer 82 Views
This is a migrated thread and some comments may be shown as answers.
Top achievements
Rank 1
Vidyadhar asked on 12 Nov 2012, 11:18 PM

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?


1 Answer, 1 is accepted

Sort by
Telerik team
answered on 15 Nov 2012, 07:12 AM
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.

Asked by
Top achievements
Rank 1
Answers by
Telerik team
Share this question