ThinkGeo.com    |     Documentation    |     Premium Support

Exception Occurring while loading large number of polygons on CurrentExtentChanged Event

Hello,
we have requirement to draw polygon shape on CurrentExtentChanged Event. We are facing some problems in loading large number of polygons on map. We have large number of polygons as close to 18,000. On current extent changed event we are filtering polygon based on certain condition and then adding polygon shape on InMemoryFeatureLayer and refreshing Map. Every time around 5000 polygons are adding on map. But we get ***“Collection was modified; enumeration operation may not execute”***, exception continuously and application stops working. The Exception details are in the attached text file.
please let us known what can be done in such scenario ,a sample code for the same would be more helpful to us.
Exception.txt (1.7 KB)
Thanks And Regards,
Suraj Kokate.

Hi Suraj,

Your data is big, so the refresh time is longer than other scenario. When you pan or zoom the map, the feature collection will be used for drawing, and you remove/add features there at the same time, that’s why you met this exception.

I think the possible solution for solve it should be like this, you create a group of cached InMemoryFeatureLayers background, after extent changed, replace the layer in map by the latest valid cached InMemoryFeatureLayer, and all your feature modify operation need be apply to a new cached layer. You also want to set a flag in the cached layer, so before all changes complete it won’t be added into map.

Wish that’s helpful.

Regards,

Ethan

Hello Ethan,
Thank you for reply. But we want more clarification regarding Cached InMemoryFeatureLayers. Is it same as Normal InMemoryFeatureLayers creation process? , if yes do you mean to say create some InMemoryFeatureLayers in background and on CurrentExtentChanged Event remove current one and add new layer into overlay then refresh map. By adding so many InMemoryFeatureLayers that will increase the size of the application. We have already 8 InMemoryFeatureLayers and two ShapeFileFeatureLayer. So,We don’t wish to add any more InMemoryFeatureLayers .
Also clarify last point ***“You also want to set a flag in the cached layer, so before all changes complete it won’t be added into map.”***. Is it means, after rendering is complete or map is refreshed then only then add next cached layer. if yes, how can we know that the all the data is rendered on the map or map is refreshed. Is there any function or flag is available to check map is refreshed.
Thanks And Regards,
Suraj Kokate.

Hi Suraj,

Our InMemoryFeatureLayer is located in memory, it’s very light and simple, so if your add “around 5000 polygons” operation is copy data from ShapeFileFeatureLayer, that should be looks like this for InMemoryFeatureLayer:

  1. Clear all features
  2. Add new features
    That’s the same like you build a new InMemoryFeatureLayer.

So I think you can try to build a new InMemoryFeatureLayer each time, and just drop old layer from map, the source of old layer will be deallocated by system, it’s in fact the same like your original operation.

If you think that’s not suitable your scenario, you can try to lock(inMemoryFeatureLayer.InternalFeatures) and it should solve this exception.

You can try this event OverlaysDrawn, but I don’t think it can works well for your scenario, because you don’t know it’s the end of which pan or zoom.

Wish that’s helpful.

Regards,

Ethan