This question is locked. New answers and comments are not allowed.
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.
Here is a sample class that I implement it on
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)
this is what is in my view (the itemssource binding points to a List<PolygonObjectDataViewModel>)
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
publicclassPolygonObjectDataViewModel : ObjectDataViewModel, IPolygon{long_geopid;publicPolygonObjectDataViewModel(ObjectActivity oa,boolmulti,longgeoid):base(oa, multi){_geopid = geoid;}publicTelerik.Windows.Controls.Map.Location[] Points{get{try{stringgeometry = Activity.Data.First(x => x.Pid == _geopid).Value;returnConvertWKTPolygonToLocationArray(geometry);}catch{returnnull;}}set{thrownewNotImplementedException();}}privateTelerik.Windows.Controls.Map.Location[] ConvertWKTPolygonToLocationArray(stringgeometry){List<Telerik.Windows.Controls.Map.Location> temp =newList<Telerik.Windows.Controls.Map.Location>();List<string> groups =newList<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(stringgroupingroups){string[] pairs = group.Split(',');foreach(stringpairinpairs){string[] coords = pair.Trim().Split(' ');Telerik.Windows.Controls.Map.Location l =newTelerik.Windows.Controls.Map.Location(double.Parse(coords[1]),double.Parse(coords[0]));temp.Add(l);}}returntemp.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>