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

SqlGeospatialDataReader and DynamicLayer

1 Answer 77 Views
Map
This is a migrated thread and some comments may be shown as answers.
Alan
Top achievements
Rank 1
Alan asked on 26 Oct 2011, 09:17 PM
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?

1 Answer, 1 is accepted

Sort by
0
Andrey
Telerik team
answered on 31 Oct 2011, 10:18 AM
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 >>

Tags
Map
Asked by
Alan
Top achievements
Rank 1
Answers by
Andrey
Telerik team
Share this question
or