SqlGeospatialDataReader and DynamicLayer

2 posts, 0 answers
  1. Alan
    Alan avatar
    3 posts
    Member since:
    Sep 2011

    Posted 26 Oct 2011 Link to this post

    I'm interested in reading from a local database, as my shapefiles are far far too large to read completely into memory. I need to both do a Read() on a SqlGeospatioalDataReader based on the current view and also respond to the DynamicLayer's ItemRequest event.

    How should I go about doing both these things?
  2. Andrey
    Admin
    Andrey avatar
    1681 posts

    Posted 31 Oct 2011 Link to this post

    Hi Alan,

    I would recommend using the SqlGeospatialDataReader from the codebehind for reading shapes. The API of the SqlGeospatialDataReader allows to do it using the SqlGeospatialDataReader.Read method. You can start it when the data is already retrieved from database. You can use the SqlGeospatialDataReader.PreviewReadCompleted event to get the generated shapes.
    The SqlGeospatialDataReader reads data asynchronously, but you should have the ItemsRequestEventArgs object of ItemsRequest to invoke the CompleteItemsRequest method.

    Unfortunately the SqlGeospatialDataReader does not support an object like the "UserState" for asyncronous operations. We have created a PITS issue to implement this feature in future releases. You can track implementation of it using the following link:
    http://www.telerik.com/support/pits.aspx#/public/silverlight/8350

    Currently to resolve this problem you should create a reference between SqlGeospatialDataReader instance and ItemsRequestEventArgs. I think for this purpose you can use a dictionary like the following:

    public class DynamicSource : IMapDynamicSource
    {
        private Dictionary<object, ItemsRequestEventArgs> pendingRequests = new Dictionary<object, ItemsRequestEventArgs>();
     
        public void ItemsRequest(object sender, ItemsRequestEventArgs e)
        {
            // ...
     
            var reader = new SqlGeospatialDataReader();
            this.pendingRequests.Add(reader, e);
     
            reader.PreviewReadCompleted += new PreviewReadShapesCompletedEventHandler(reader_PreviewReadCompleted);
            reader.Read(entity, "Point");
        }
     
        private void reader_PreviewReadCompleted(object sender, PreviewReadShapesCompletedEventArgs eventArgs)
        {
            if (eventArgs.Error == null)
            {
                ItemsRequestEventArgs e = this.pendingRequests[sender];
                e.CompleteItemsRequest(eventArgs.Items.ToArray<object>());
            }
     
            this.pendingRequests.Remove(sender);
        }
    }

    Kind regards,
    Andrey Murzov
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  3. UI for WPF is Visual Studio 2017 Ready
Back to Top