ThinkGeo.com    |     Documentation    |     Premium Support

Error when interacting with map while zooming

I’m having a crash when doing the following:

I add a layer to the map (either a .shp or personalgeodatabasefeaturelayer).
I zoom into where that layer is.
Before that layer finishes refreshing on the map from the zoom, I draw a rectangle shape on the map with my mouse, which gets all the features contained in the rectangle that are also in the personalgeodatabase layer.

This throws an error:
An unhandled exception of type ‘System.InvalidOperationException’ occurred in ThinkGeo.MapSuite.Wpf.dll
The FeatureSource is not open. Please call the Open method before calling this method.
at ThinkGeo.MapSuite.Wpf.Tile.Draw(GeoCanvas geoCanvas)

Here’s some sample code of what I’m doing:

foreach (FeatureLayer layer in (MyMap.Overlays["mdboverlay"] as LayerOverlay).Layers) //loop through the layers in the overlay holding the personalgeodatabasefeaturelayers
{
    if (layer.IsVisible) //only check the ones that are currently visible
    {
        layer.Open();

        var features = layer.QueryTools.GetFeaturesWithin(e.TrackShape, ReturningColumnsType.AllColumns); //ERROR THROWN HERE //get the features within the rectangle shape I drew
        layer.Close();
    }
}

I attached a gif below to show what I mean. I just have a simple countries.shp loaded on the map.

Sorry it’s a little fast, but you get the gist of it.

I don’t get the error if I wait for the map to refresh after zooming in, but that’s not ideal.

Hi Dan,

Here is a simple sample, I hadn’t reproduced your exception in the sample.

9477.zip (101.6 KB)

And it looks your exception is the layer hadn’t get opened when query, in fact it should because this layer get closed in other operation, and currently operation hadn’t get complete.

So I think the solution is remove layer.Open() and layer.Close() in your function here.

You can open the layer when it get initialized, and close when you don’t use this layer.

Regards,

Ethan

Yup that seems to do the trick. I put in a check before calling the open to see if it’s already open, and got rid of the .Close().

One question, is there a list of times when the layer needs to be opened/closed that I can reference? I’ve only found out when I get an error saying it needs to be open and change my code accordingly.

Thanks!

Hi Dan,

“Open” did different things for different layers, but generally you need to open it before spatial query.

And we suggest you open each layer after it’s created and it’s used in map. We also suggest you close the layer when it is make sure not be used again in map.

In your scenario it shouldn’t been closed because one thread stop to use it but the other thread used it again.

Wish that’s helpful.

Regards,

Ethan