How to create template for kml elements?

2 posts, 0 answers
  1. Eirik
    Eirik avatar
    1 posts
    Member since:
    Jan 2011

    Posted 04 Feb 2011 Link to this post

    How can i create a template that works on every element in a kml file i load from my computer?

    Loading the kml file works fine:   

                    FileStream streamResource = File.Open("c:\\mapsource\\wildlife.kml",FileMode.Open,FileAccess.Read);
                    List<FrameworkElement> elements = Telerik.Windows.Controls.Map.KmlReader.Read(streamResource);

                    foreach (FrameworkElement element in elements)
                catch (Exception e)
                    MessageBox.Show("Error: " + e);

            <Label HorizontalContentAlignment="Center" Content="Map" Width="{Binding Source={StaticResource configSource}, Path=DefaultMapWidth}" Height="30" Background="Gray"></Label>
            <telerik:RadMap x:Name="radMap"  Width="{Binding Source={StaticResource configSource}, Path=DefaultMapWidth}" Height="{Binding Source={StaticResource configSource}, Path=DefaultMapHeight}"
                <telerik:InformationLayer x:Name="informationLayer">
                            <Grid telerik:MapLayer.BaseZoomLevel="5" >
                        <telerik:MapShapeReader Source="c:/mapsource/Oil_Spills.kml" SourceType="Kml"/>

    Here's a part of the kml file that i'm using:

    <?xml version="1.0" encoding="UTF-8"?>
    <kml xmlns="">

            <name>Anshi National Park</name>
                      <p>Wildlife: Bonnet Macaque, Deer, Mouse Deer, Spotted Deer, Indian Bison, Malabar Civet, Malabar Giant Squirrel, Pangolin, Sloth Bear, Black Panther, Elephants, Tigers, Adjutant Stork, Ashy Woodswallow, Black-cre... </p>
                      <p>Plan your wildlife adventure holiday to <a href="">Anshi National Park</a>, India...
                       read reviews by fellow wildlife enthusiasts, and share your own.  For information about other parks in India and the rest of the world visit: <a href="">World Wildlife Adventures</a></p>
            <name>Balphakram National Park</name>
                      <p>Wildlife: Indian Elephant, Bengal Tiger, Leopard, Clouded Leopard, Wild Buffalo, Gaur (Indian Bison), Muntjac (Barking Deer), Hoolock (White-browed) Gibbon, Assamese Macaque, Pig-tailed Macaque, Capped Langur (... </p>
                      <p>Plan your wildlife adventure holiday to <a href="">Balphakram National Park</a>, India...
                       read reviews by fellow wildlife enthusiasts, and share your own.  For information about other parks in India and the rest of the world visit: <a href="">World Wildlife Adventures</a></p>

    It's important that i'm able to format the name and description.
    I did not find any examples on this, so i hope you can help.

    Thanks in advance.
  2. Andrey
    Andrey avatar
    1681 posts

    Posted 09 Feb 2011 Link to this post

    Hi Eirik,

    You can override a standard style for the MapPinPoint to customize its appearance.
    Each MapPinPoint which is returned from the KmlReader contains the ExtendedData property. You can use it to get the Name and Description of Placemark. Also you can add necessary properties to the ExtendedData for binding them later in the custom template.
    The sample code is below.
    <Window x:Class="KmlTemplating.MainWindow"
            Title="MainWindow" Height="600" Width="800">
            <telerik:ExtendedDataConverter x:Key="ExtendedDataConverter" />
            <Style TargetType="telerik:MapPinPoint">
                <Setter Property="Template">
                        <ControlTemplate TargetType="telerik:MapPinPoint">
                            <Border Background="{TemplateBinding Background}"
                                    BorderBrush="{TemplateBinding BorderBrush}" 
                                <Grid Name="PART_Panel">
                                        <ToolTip Content="{TemplateBinding ExtendedData, Converter={StaticResource ExtendedDataConverter}, ConverterParameter=FormattedDescription}" />
                                    <Image Name="PART_Image" 
                                           Source="{TemplateBinding ImageSource}" 
                                           Height="32" />
                                    <TextBlock Name="PART_Text" 
                                               Text="{TemplateBinding Text}" />
            <telerik:RadMap x:Name="radMap"
                    <telerik:OpenStreetMapProvider IsTileCachingEnabled="True" />
                <telerik:InformationLayer x:Name="informationLayer" />
    public MainWindow()

            FileStream streamResource = File.Open("c:\\mapsource\\wildlife.kml", FileMode.Open, FileAccess.Read);
            List<FrameworkElement> elements = Telerik.Windows.Controls.Map.KmlReader.Read(streamResource);

    foreach (FrameworkElement element in elements)
                MapPinPoint point = element as MapPinPoint;
                if (point != null)
                    // get description
                    // Placemark.Name could be used to get the Name of Placemark
                    string description = (string)point.ExtendedData.GetValue("Placemark.Description");

    // format description to a control
                    ContentControl control = this.GetFormattedDescription(description);

    // register the FormattedDescription property
                    point.ExtendedData.PropertySet.RegisterProperty("FormattedDescription", "", typeof(ContentControl), null);

    // add the control to ExtendedData
                    point.ExtendedData.SetValue("FormattedDescription", control);

        catch (Exception e)
            MessageBox.Show("Error: " + e);

    ContentControl GetFormattedDescription(string description)
        // format of description to control should be implemented
        // ...
        ContentControl control = new ContentControl();
        control.Content = description;

    return control;

    Kind regards,
    Andrey Murzov
    the Telerik team
    Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
  3. UI for WPF is Visual Studio 2017 Ready
Back to Top