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

SqlGeospatialDataReader PreviewReadCompleted

1 Answer 15 Views
Map
This is a migrated thread and some comments may be shown as answers.
Tim
Top achievements
Rank 1
Tim asked on 27 Feb 2014, 06:55 PM
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:InformationLayer.Reader>
                    <telerik:SqlGeospatialDataReader Source="{Binding CenterAreas}"
                                                     GeospatialPropertyName="Geometry"
                                                     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.

Thanks,

Tim














1 Answer, 1 is accepted

Sort by
0
Andrey
Telerik team
answered on 28 Feb 2014, 08:35 AM

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;
            });
        }
    }
}


Regards,
Andrey Murzov
Telerik
Tags
Map
Asked by
Tim
Top achievements
Rank 1
Answers by
Andrey
Telerik team
Share this question
or