How to bind WKB sql data to radmap

8 posts, 0 answers
  1. adi
    adi avatar
    79 posts
    Member since:
    Feb 2007

    Posted 27 Jan 2013 Link to this post

    Hi,

    I'm playing around with silverlight map control. I have a WCF based service that returns an ObservableCollection as a result of a sql query. This collection contains a column of geo data (WKB) that I want to show in RadMap control. But don't know, how. Is there any sample that explains? 

    Regards, Adi

  2. Andrey
    Admin
    Andrey avatar
    1681 posts

    Posted 29 Jan 2013 Link to this post

    Hello Andreas,

    Please, take a look into the following sample in our demo application:

    http://demos.telerik.com/silverlight/#Map/WktReader

    You also can find some details here:
     
    http://www.telerik.com/help/silverlight/radmap-features-sql-geospatial-data.html

    All the best,
    Andrey Murzov
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  3. DevCraft banner
  4. adi
    adi avatar
    79 posts
    Member since:
    Feb 2007

    Posted 29 Jan 2013 Link to this post

    Hello Andrey,

    thanks for your response. I'm not able to show the spatial data in my map. Please take a look at my sample code. I followed the instructions http://www.telerik.com/help/silverlight/radmap-features-sql-geospatial-data.html.

    using System.Windows.Controls;
    using System.Windows.Media;
    using Telerik.Windows.Controls.Map;
    using DataService;
     
    namespace myNamespace
    {
        public partial class MainPage : UserControl
        {
            public MainPage()
            {
                InitializeComponent();
            }
     
            private void btnRunQuery_Click(object sender, RoutedEventArgs e)
            {
                QaDataServiceClient queryClient = new QaDataServiceClient();
                queryClient.GetQueryResultCompleted += resultQuery_Completed;
                queryClient.GetQueryResultAsync("");
            }
     
            private void resultQuery_Completed(object sender, GetQueryResultCompletedEventArgs e)
            {
                if (e.Error == null && e.Result != null)
                {
                    var rslt = new ObservableCollection<QaDataRow>(from i in e.Result select new QaDataRow(i));
                    rgrQueryResult.ItemsSource = rslt;
                    rgrQueryResult.IsBusy = false;
                    sqlGeospatialDataReader.Source = rslt; //rslt contains a property 'Geo'
                }
            }
     
        }
    }

    <UserControl x:Class="myNamespace.MainPage"
            mc:Ignorable="d" d:DesignWidth="1000" d:DesignHeight="650">
        <Grid x:Name="layoutRoot">
            <telerik:RadTabControl x:Name="rtcNavigation">
                <telerik:RadTabItem Header="Result">
                    <Grid Background="Transparent">
                        <Button x:Name="btnRunQuery" Click="btnRunQuery_Click">
                        </Button>
                        <telerik:RadGridView x:Name="rgrQueryResult" ActionOnLostFocus="None" IsReadOnly="True" CanUserDeleteRows="False" CanUserInsertRows="False" GroupRenderMode="Flat" Margin="0,0,0,24" IsBusy="True" CanUserFreezeColumns="False" />
                        <telerik:RadDataPager x:Name="rdpQueryResult" Margin="0,595,0,0" VerticalAlignment="Bottom" PageSize="100" Source="{Binding Items, ElementName=rgrQueryResult}" IsTotalItemCountFixed="True" DisplayMode="FirstLastPreviousNextNumeric, Text" Height="Auto"/>
                    </Grid>
                </telerik:RadTabItem>
                <telerik:RadTabItem Header="Map">
                    <Grid Background="Transparent">
                        <telerik:RadMap x:Name="rmMapResult" MinZoomLevel="4" ZoomLevel="8">
                            <telerik:InformationLayer x:Name="informationLayer">
                                <telerik:InformationLayer.Reader>
                                    <telerik:SqlGeospatialDataReader x:Name="sqlGeospatialDataReader"
                                                         GeospatialPropertyName="Geo" />
                                </telerik:InformationLayer.Reader>
                            </telerik:InformationLayer>                       
                        </telerik:RadMap>
                    </Grid>
                </telerik:RadTabItem>
            </telerik:RadTabControl>
        </Grid>
    </UserControl>
  5. Andrey
    Admin
    Andrey avatar
    1681 posts

    Posted 31 Jan 2013 Link to this post

    Hi Andreas,

    It is hard to say about particular causes of this problem using just a code snippet you sent.
    Most often this problem occurs in the following cases:

    1. You didn't specify a map provider for the RadMap. At least I don't see it in the code snippet you sent.
    You can specify it using the following instructions from our online help:
    http://www.telerik.com/help/silverlight/radmap-features-providers.html

    2. You didn't specify the RadMap.Center and RadMap.ZoomLevel properties which correspond with your geospatial data.
    I would recommend to use the Best View feature when the data is read. You can handle the SqlGeospatialDataReader.ReadCompleted event for this purpose. Also I would recommend to handle the SqlGeospatialDataReader.PreviewReadCompleted event to check errors which can occur during reading. Also you can check elements which were created by the SqlGeospatialDataReader. The sample code is below.

    <telerik:RadMap x:Name="rmMapResult" MinZoomLevel="4" ZoomLevel="8">
        <telerik:RadMap.Provider>
            <telerik:OpenStreetMapProvider />
        </telerik:RadMap.Provider>
        <telerik:InformationLayer x:Name="informationLayer">
            <telerik:InformationLayer.Reader>
                <telerik:SqlGeospatialDataReader x:Name="sqlGeospatialDataReader" GeospatialPropertyName="Geo" PreviewReadCompleted="sqlGeospatialDataReader_PreviewReadCompleted" ReadCompleted="sqlGeospatialDataReader_ReadCompleted"/>
            </telerik:InformationLayer.Reader>
        </telerik:InformationLayer>                       
    </telerik:RadMap>

     

    private void sqlGeospatialDataReader_ReadCompleted(object sender, ReadShapesCompletedEventArgs eventArgs)
    {
        LocationRect bestView = this.informationLayer.GetBestView(this.informationLayer.Items);
        this.rmMapResult.SetView(bestView);
    }
     
    private void sqlGeospatialDataReader_PreviewReadCompleted(object sender, PreviewReadShapesCompletedEventArgs eventArgs)
    {
        if (eventArgs.Error != null)
        {
            MessageBox.Show(eventArgs.Error.Message);
        }
        else
        {
            // eventArgs.Items contains the list of objects which are created by SqlGeospatialDataReader
        }
    }

    3. Your 'Geo' property contains point type data.
    In this case you should specify a point template for the SqlGeospatialDataReader. The sample of using the SqlGeospatialDataReader.PointTemplate property is below.

    <telerik:RadMap x:Name="rmMapResult" MinZoomLevel="4" ZoomLevel="8">
        <telerik:RadMap.Provider>
            <telerik:OpenStreetMapProvider />
        </telerik:RadMap.Provider>
        <telerik:InformationLayer x:Name="informationLayer">
            <telerik:InformationLayer.Reader>
                <telerik:SqlGeospatialDataReader x:Name="sqlGeospatialDataReader" GeospatialPropertyName="Geo" PreviewReadCompleted="sqlGeospatialDataReader_PreviewReadCompleted" ReadCompleted="sqlGeospatialDataReader_ReadCompleted">
                    <telerik:SqlGeospatialDataReader.PointTemplate>
                        <DataTemplate>
                            <Border>
                                <telerik:MapLayer.HotSpot>
                                    <telerik:HotSpot X="0.5" Y="0.5" ElementName="PART_Path" />
                                </telerik:MapLayer.HotSpot>
                                <Grid>
                                    <Path Fill="Brown" Name="PART_Path">
                                        <Path.Data>
                                            <GeometryGroup>
                                                <EllipseGeometry Center="7,7" RadiusX="3" RadiusY="3" />
                                                <EllipseGeometry Center="7,7" RadiusX="7" RadiusY="7" />
                                            </GeometryGroup>
                                        </Path.Data>
                                    </Path>
                                </Grid>
                            </Border>
                        </DataTemplate>
                    </telerik:SqlGeospatialDataReader.PointTemplate>
                </telerik:SqlGeospatialDataReader>
            </telerik:InformationLayer.Reader>
        </telerik:InformationLayer>                       
    </telerik:RadMap>

    Kind regards,
    Andrey Murzov
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  6. adi
    adi avatar
    79 posts
    Member since:
    Feb 2007

    Posted 01 Feb 2013 Link to this post

    Hello Andrey,

    thanks for this sample code. I had try it, but it doesn't works for me. As you suggest, I handle PreviewCompleted event. There I get an error 'GeospatialPropertyName'. I have checked the result. The property is there.

    Regards, Adi
  7. Andrey
    Admin
    Andrey avatar
    1681 posts

    Posted 01 Feb 2013 Link to this post

    Hello Andreas,

    This kind of error can occur for example when the property is not accessible within the SqlGeospatialDataReader, because it is not a public property in the QaDataRow class. But it is very complicated and it is hard to reproduce the problem without your solution.
    Could you, please, provide us with your solution or with a small sample solution which reproduces it?

    All the best,
    Andrey Murzov
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  8. adi
    adi avatar
    79 posts
    Member since:
    Feb 2007

    Posted 05 Feb 2013 Link to this post

    Hello Andrey,

    I will open a support ticket to provide the sample solution.

    Regards, Adi
  9. Andrey
    Admin
    Andrey avatar
    1681 posts

    Posted 06 Feb 2013 Link to this post

    Hello Andreas,

    The QaDataRow class inherits the DynamicObject. And it does not contain explicit implementation of the Geo property. It is implemented as a runtime property via overriding the TryGetMember method.

    Unfortunately the SqlGeospatialDataReader does not support properties which are implemented this way. This feature is not in our plans for Q1 2013 and it does not seem to be a trivial one. I will make sure it is reconsidered when discussing our future plans, but I am afraid no certain time frame can be given at the moment.

    The property which you use in the GeospatialPropertyName must be available via the Type.GetProperties method. So, you should implement this property explicitly when you will use it in SqlGeospatialDataReader.

    All the best,
    Andrey Murzov
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Back to Top
DevCraft banner