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

KML Files

1 Answer 126 Views
Map
This is a migrated thread and some comments may be shown as answers.
Moises Casusol
Top achievements
Rank 1
Moises Casusol asked on 10 Feb 2010, 06:04 PM
HI,

I was checking the RadMap examples and some of them use an XML or KML file to import the coordinates for the polygon. But how did u generate the XML or KML file, i mean did u wrote coordinate by coordinate? or maybe with a drawing tool? i need to do an KML file with states borders of my country. I hope u can help me :)

Best Regards,
Lois

1 Answer, 1 is accepted

Sort by
0
Andrey
Telerik team
answered on 15 Feb 2010, 06:41 AM
Hello Moises Casusol,

Unfortunately we do not have any Drawing Tool for KML building, but you can use the MapMouseClick event to get coordinates and build KML file.
Please see the following example code:
<UserControl
...
    xmlns:map="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.DataVisualization"
    xmlns:maps="clr-namespace:Telerik.Windows.Controls.Map;assembly=Telerik.Windows.Controls.DataVisualization"
>
  <Grid x:Name="LayoutRoot">
        <Grid.Resources>
            <Style x:Key="CustomPinPoint" TargetType="maps:MapPinPoint">
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="maps:MapPinPoint">
                            <Border Background="{TemplateBinding Background}"
                                    BorderBrush="{TemplateBinding BorderBrush}" 
                                    BorderThickness="1" 
                                    CornerRadius="3"
                                    Padding="2,2,2,2">
                                <Grid Name="PART_Panel">
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="14" />
                                        <ColumnDefinition Width="Auto" />
                                    </Grid.ColumnDefinitions>
                                    <Path Fill="Green" Name="PART_Image">
                                        <Path.Data>
                                            <GeometryGroup>
                                                <EllipseGeometry Center="7,7" RadiusX="3" RadiusY="3" />
                                                <EllipseGeometry Center="7,7" RadiusX="7" RadiusY="7" />
                                            </GeometryGroup>
                                        </Path.Data>
                                    </Path>
                                </Grid>
                            </Border>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>
        </Grid.Resources>
  
        <map:RadMap x:Name="radMap" MapMouseClick="radMap_MapMouseClick" MouseClickMode="None">
            <maps:InformationLayer Name="informationLayer" Visibility="Collapsed" />
        </map:RadMap>
  
        <Button Click="SaveToKlm" Width="150" Height="40" VerticalAlignment="Top" HorizontalAlignment="Right" Content="Save"/>
    </Grid>
</UserControl>
public partial class MainPage : UserControl
{
    private LocationCollection polygonPoints = new LocationCollection();
    private Dictionary<Location, MapPinPoint> pinPoints = new Dictionary<Location, MapPinPoint>();
    public MainPage()
    {
        InitializeComponent();
        this.Loaded += new RoutedEventHandler(MainPage_Loaded);
    }
    void MainPage_Loaded(object sender, RoutedEventArgs e)
    {
        this.radMap.InitializeCompleted += new EventHandler(radMap_InitializeCompleted);
        VEMapProvider provider = new VEMapProvider(MapMode.Aerial, true, "Your_BingMap_Token");
        this.radMap.Provider = provider;
    }
    void radMap_InitializeCompleted(object sender, EventArgs e)
    {
        // set center
        this.radMap.Center = new Telerik.Windows.Controls.Map.Location(37.684297, -99.06924);
        // set zoom
        this.radMap.ZoomLevel = 4;
        this.informationLayer.Visibility = Visibility.Visible;
    }
    private void radMap_MapMouseClick(object sender, MapMouseRoutedEventArgs eventArgs)
    {
        polygonPoints.Add(eventArgs.Location);
        MapPinPoint point = new MapPinPoint()
        {
            Style = this.LayoutRoot.Resources["CustomPinPoint"] as Style
        };
        MapLayer.SetLocation(point, eventArgs.Location);
        this.pinPoints.Add(eventArgs.Location, point);
        this.informationLayer.Items.Add(point);
    }
    private void SaveToKlm(object sender, RoutedEventArgs e)
    {
        try
        {
            SaveFileDialog dialog = new SaveFileDialog();
            dialog.Filter = "Kml (*.kml)|*.kml";
            bool? dialogResult = dialog.ShowDialog();
            if (dialogResult == true)
            {
                XDocument doc = new XDocument(
                    new XElement("Document",
                        new XElement("Style",
                            new XAttribute("id", "defaultStyle"),
                            new XElement("LineStyle",
                                new XElement("color", "ffffffff"),
                                new XElement("width", "2")),
                            new XElement("PolyStyle",
                                new XElement("color", "99ff6600"),
                                new XElement("outline", "1"),
                                new XElement("fill", "1"))),
                        new XElement("Placemark",
                            new XElement("styleUrl", "#defaultStyle"),
                            new XElement("MultiGeometry",
                                new XElement("Polygon",
                                    new XElement("outerBoundaryIs",
                                        new XElement("LinearRing",
                                            new XElement("coordinates", polygonPoints.ToString(new System.Globalization.CultureInfo("En-US"), true)))))))));
                using (Stream stream = dialog.OpenFile())
                {
                    doc.Save(stream);
                }
            }
        }
        catch (Exception ex)
        {
        }
    }
}

Sincerely yours,
Andrey Murzov
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Tags
Map
Asked by
Moises Casusol
Top achievements
Rank 1
Answers by
Andrey
Telerik team
Share this question
or