This question is locked. New answers and comments are not allowed.
Hi,
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.
Sample.kml
<?xml version="1.0" encoding="utf-8"?>
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.
Sample.kml
<?xml version="1.0" encoding="utf-8"?>
<kml>
<Document>
<Style id="PinPoint_IconStyle">
<IconStyle>
<Icon>
<href>rectangle_green.png</href>
</Icon>
</IconStyle>
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?
Thanks,
Viddy.
<Document>
<Style id="PinPoint_IconStyle">
<IconStyle>
<Icon>
<href>rectangle_green.png</href>
</Icon>
</IconStyle>
</Style>
<Style id="PolyLine_LineStyle">
<LineStyle>
<color>FFFC2896</color>
<width>2</width>
</LineStyle>
</Style>
</kml><Style id="PolyLine_LineStyle">
<LineStyle>
<color>FFFC2896</color>
<width>2</width>
</LineStyle>
</Style>
<Placemark>
<name>PinPoint_Placemark</name>
<styleUrl>#PinPoint_IconStyle</styleUrl>
<name>PinPoint_Placemark</name>
<styleUrl>#PinPoint_IconStyle</styleUrl>
<Point>
<coordinates>-112.426652,50.343271,0</coordinates>
</Point>
</Placemark>
<coordinates>-112.426652,50.343271,0</coordinates>
</Point>
</Placemark>
<Placemark>
<name>Line_Placemark</name>
<styleUrl>#PolyLine_LineStyle</styleUrl>
<LineString>
<coordinates>-123.13414,49.050929,0 -117.210126,49.01362,0</coordinates>
</LineString>
</Placemark>
<name>Line_Placemark</name>
<styleUrl>#PolyLine_LineStyle</styleUrl>
<LineString>
<coordinates>-123.13414,49.050929,0 -117.210126,49.01362,0</coordinates>
</LineString>
</Placemark>
</Document>
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?
Thanks,
Viddy.