SqlGeospatialDataReader PreviewReadCompleted

2 posts, 0 answers
  1. Tim
    Tim avatar
    41 posts
    Member since:
    Oct 2012

    Posted 27 Feb 2014 Link to this post

    I'm using SqlGeospatialDataReader to bind data to my Map. I'm trying to get it to where I can click on a polygon and get information about it. I am unable to get information from the CenterArea that belongs to the polygon. CenterAreas is an ObservableCollection<CenterArea>. Here is my map information:

    <telerik:RadMap x:Name="radMap" Center="39.36830, -95.27340" ZoomLevel="5" MouseClickMode="None" MapMouseClick="radMap_MouseClick"  >
                <telerik:InformationLayer x:Name="informationLayer">
                        <telerik:SqlGeospatialDataReader Source="{Binding CenterAreas}"
                                                         ToolTipFormat="Name" PreviewReadCompleted="OnPreviewReadCompleted" >

    Here is the OnPreviewReadCompleted code:
    private void OnPreviewReadCompleted(object sender, PreviewReadShapesCompletedEventArgs eventArgs)
                if (eventArgs.Error == null)
                    foreach (FrameworkElement element in eventArgs.Items)
                        MapShape shape = element as MapShape;
                        if (shape != null)
                            shape.MouseLeftButtonDown += new MouseButtonEventHandler(elementMouseLeftButtonDown);

    How can I get access on click of a polygon to the CenterArea behind it? I want to access the name or some other attribute from it.



  2. Andrey
    Andrey avatar
    1681 posts

    Posted 28 Feb 2014 Link to this post

    Hi Tim,

    The SqlGeospatialDataReader reads a value of each public property in your data item class to the ExtendedData object of MapShape. You can get it using the ExtendedData.GetValue method. So, it will be possible to get any values or to find the data item object if it's required.

    The sample code is below.

    private void elementMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        MapShape shape = sender as MapShape;
        if (shape != null && shape.ExtendedData != null)
            string name = (string)shape.ExtendedData.GetValue("Name");
            if (!string.IsNullOrEmpty(name))
                ViewModel model = this.DataContext as ViewModel;
                CenterArea item = model.CenterAreas.FirstOrDefault((CenterArea row) =>
                    return row.Name == name;

    Andrey Murzov
  3. DevCraft R3 2016 release webinar banner
Back to Top