VisualizationLayer kml and polylines

2 posts, 0 answers
  1. Jeroen
    Jeroen avatar
    49 posts
    Member since:
    Feb 2012

    Posted 23 Jun 2014 Link to this post

    Hi,

    I'm looking into replacing InformationLayers in my application with VisualizationLayers, but I'm having trouble drawing lines.

    Firstly, I'm looking for an alternative for the MapPolyLine I'm currently using to draw lines. According to what I've found, I should be using PolyLineData, but I can't get that to work at all, and I can't find any examples either.

    Secondly, I'm currently using KML on a few layers as well.

    layer.ItemsSource = KmlReader.Read(routeModel.RouteSegmentXML1.KML);

    This doesn't seem to work either, and I can't find any info or examples on this. The only info I can find always deals with InformationLayer...

    Also, I need to be able to handle everything in code-behind (C#). Xaml is no use to me.
    Any help would be much appreciated.

    Kind regards,
    Jeroen
  2. Andrey
    Admin
    Andrey avatar
    1681 posts

    Posted 23 Jun 2014 Link to this post

    Hello Jeroen,

    You can find an information about PolylineData in the Map Shape Data help article. You can create an instance of the PolylineData like the following:

    PolylineData polyline = new PolylineData()
    {
        ShapeFill = new MapShapeFill()
        {
            Stroke = new SolidColorBrush(Colors.Red),
            StrokeThickness = 2
        }
    };
     
    LocationCollection points = new LocationCollection();
    points.Add(new Location(44.6957539183824, 23.3327663758679));
    points.Add(new Location(44.1429369264591, 24.7498095849434));
    points.Add(new Location(44.5131732087098, 27.4611884843576));
    points.Add(new Location(45.2073941930888, 27.9275176988258));
     
    polyline.Points = points;
     
    this.visualizationLayer.Items.Add(polyline);


    You should use the AsyncKmlReader instead of KmlReader for reading geospatial data which can be used in VisualizationLayer.
    The sample code is below.
    AsyncKmlReader reader = new AsyncKmlReader()
    {
        Source = new Uri("kml-file path")
    };
    reader.PreviewReadShapeDataCompleted += reader_PreviewReadShapeDataCompleted;
    reader.ReadAsync();
     
    void reader_PreviewReadShapeDataCompleted(object sender, PreviewReadShapeDataCompletedEventArgs e)
    {
        layer.ItemsSource = e.Items;
    }

    For more information please take a look at the Reading Map Shapes documentation article.

    Regards,
    Andrey Murzov
    Telerik
     
    Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
     
  3. DevCraft banner
Back to Top