How do you bind information layers at runtime

2 posts, 0 answers
  1. FieldTRAKS
    FieldTRAKS avatar
    25 posts
    Member since:
    Apr 2009

    Posted 31 Mar 2011 Link to this post

    Our application has user defined objects so we do not know the information layers or the geometry type until run time. We are using MVVM and I am struggling to find a way to bind several information layers and then to use the itemtemplateselector to decide wether the data should be displayed as mappolygon, mappolyline or mappoint.

    I eventually gave up and tried to just get my polygons to show in a pre-existing information layer

    However, nothing displays on the map. What am I am doing wrong???? I want to be able to bind any collection of mny viewmodels that implement the interfaces described below.

    public interface IPolygon
     {
        Telerik.Windows.Controls.Map.Location[] Points {get;set; }
     }
     
     
     public interface IPolyline
     {
         Telerik.Windows.Controls.Map.Location[] Points { get; set; }
     }
     
     public interface IPoint
     {
         Telerik.Windows.Controls.Map.Location Point { get; set; }
     }

    Here is a sample class that I implement it on

      
       
    public class PolygonObjectDataViewModel : ObjectDataViewModel, IPolygon
        {
            long _geopid;
     
            public PolygonObjectDataViewModel(ObjectActivity oa, bool multi, long geoid)
                : base(oa, multi)
            {
                _geopid = geoid;
            }
     
     
     
            public Telerik.Windows.Controls.Map.Location[] Points
            {
                get
                {
                    try
                    {
                        string geometry = Activity.Data.First(x => x.Pid == _geopid).Value;
                        return ConvertWKTPolygonToLocationArray(geometry);
                    }
                    catch
                    {
                        return null;
                    }
                }
                set
                {
                    throw new NotImplementedException();
                }
            }
     
            private Telerik.Windows.Controls.Map.Location[] ConvertWKTPolygonToLocationArray(string geometry)
            {
                List<Telerik.Windows.Controls.Map.Location> temp = new List<Telerik.Windows.Controls.Map.Location>();
                List<string> groups = new List<string>();
                if (geometry.ToLower().StartsWith("multi"))
                {
     
                    geometry = geometry.Replace("MULTIPOLYGON(((", "");
                    geometry = geometry.Replace("MULTIPOLYGON (((", "");
                    geometry = geometry.Replace(")))", "");
                    groups.AddRange(System.Text.RegularExpressions.Regex.Split(geometry, "\\)\\)\\,\\(\\("));
                }
     
                else
                {
                    geometry = geometry.Replace("POLYGON((", "");
                    geometry = geometry.Replace("POLYGON ((", "");
                    geometry = geometry.Replace("))", "");
                    groups.Add(geometry);
                }
     
                foreach (string group in groups)
                {
                    string[] pairs = group.Split(',');
                    foreach (string pair in pairs)
                    {
                        string[] coords = pair.Trim().Split(' ');
                        Telerik.Windows.Controls.Map.Location l = new Telerik.Windows.Controls.Map.Location(double.Parse(coords[1]), double.Parse(coords[0]));
     
                        temp.Add(l);
                    }
                }
     
                return temp.ToArray();
            }
        }





    Here is the datatemplate that the itemtemplateselector finds (I checked it using a debug converter to check the value the binding passes and it is indeed passing a valid Location[] object)

     
    <DataTemplate x:Key="PolygonObjectDataViewModel">
    <telerik:MapPolygon    Points="{Binding Points,Converter={StaticResource debug}}" Stroke="Yellow"  StrokeThickness="2"/>
    </DataTemplate>


    this is what is in my view (the itemssource binding points to a List<PolygonObjectDataViewModel>)

     
      <telerik:RadMap  UseSpringAnimations="False" Grid.Row="2" Provider="{Binding Provider}"   MouseLeftButtonDown="map_MouseLeftButtonDown"  ZoomLevel="14"   VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Center="{Binding Center}" Name="map" >
          <telerik:InformationLayer Visibility="Visible" ItemTemplateSelector="{Binding Source={StaticResource selector}}"     ItemsSource="{Binding Path=Polygons}" >
     </telerik:InformationLayer>
    </telerik:RadMap>
  2. FieldTRAKS
    FieldTRAKS avatar
    25 posts
    Member since:
    Apr 2009

    Posted 01 Apr 2011 Link to this post

    I figured out the display issue...my interface is specifies Location[] and should be specifying a LocationCollection....my polygons are now displaying....
  3. DevCraft banner
Back to Top