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

Access "styleurl" of a Placemark from code

1 Answer 78 Views
Map
This is a migrated thread and some comments may be shown as answers.
Vidyadhar
Top achievements
Rank 1
Vidyadhar asked on 12 Nov 2012, 11:18 PM
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"?>
<kml>
<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>
<Placemark>
      <name>PinPoint_Placemark</name>
      <styleUrl>#PinPoint_IconStyle</styleUrl>
<Point>
        <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>
</Document>
</kml>


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.

1 Answer, 1 is accepted

Sort by
0
Andrey
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:
http://www.telerik.com/help/silverlight/radmap-features-shape-appearance.html
http://www.telerik.com/help/silverlight/radmap-features-information-layer-pin-points.html

Regards,
Andrey Murzov
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Tags
Map
Asked by
Vidyadhar
Top achievements
Rank 1
Answers by
Andrey
Telerik team
Share this question
or