ThinkGeo.com    |     Documentation    |     Premium Support

ThinkGeo.MapSuite.Wpf exception

Hi,
from certain time I get this error right after I start my application. Strange thing is that this is not all the time. I’m not able to determine what can cause this exception since my application is quite long and there is no clear point where this happens.

Do you have any hints what can cause this?

System.InvalidOperationException
HResult=0x80131509
Message=Collection was modified; enumeration operation may not execute.
Source=ThinkGeo.MapSuite.Wpf
StackTrace:
at ThinkGeo.MapSuite.Wpf.Tile.DrawException(GeoCanvas geoCanvas, Exception exception)
at ThinkGeo.MapSuite.Wpf.Tile.Draw(GeoCanvas geoCanvas)
at ThinkGeo.MapSuite.Wpf.Tile.hFY=(Object status)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()
at System.Threading.ThreadPoolWorkQueue.Dispatch()

Yhank you

Martin

Hi Martin,

Thanks for let us know your problem, the Tile.Draw contains many other functions, so we also cannot make sure which part throw the exception.

We want to know whether you modified the dll version before you met the exception? Or if anything changed please let us know, so we can try to find which part is effected.

And if you open cache please try to close it or clear saved cache tile images to see whether it can be reproduced.

Regards,

Ethan

Hi Ethan,
thank you for your reply.
I narrowed down my investigation and this is what I found.
I need to generate custom grid evenly spaced 1 km. This is done by creating lines in InMemoryFeatureLayer.
My goal is to show different grid lines spacing for different zoomlevels so my featureLayer contains FeatureSourceColumn(“gline”) and then I have one ValueStyle

    public static ValueStyle ValueStyleKilometerGrid(int level, LineStyle lineStyle)
    {
        ValueStyle valueStyle = new ValueStyle();
        valueStyle.ColumnName = "gline";

        valueStyle.ValueItems.Add(new ValueItem("0", lineStyle));
        valueStyle.ValueItems.Add(new ValueItem("100", lineStyle));

        if (level == 0)
        {
            valueStyle.ValueItems.Add(new ValueItem("50", lineStyle));
        }
        else if (level == 1)
        {
            for (int i = 25; i < 100; i += 25)
            {
                valueStyle.ValueItems.Add(new ValueItem(i.ToString(), lineStyle));
            }
        }
        else if (level == 2)
        {
            for (int i = 20; i < 100; i += 20)
            {
                valueStyle.ValueItems.Add(new ValueItem(i.ToString(), lineStyle));
            }
        }
        else if (level == 3)
        {
            for (int i = 10; i < 100; i += 10)
            {
                valueStyle.ValueItems.Add(new ValueItem(i.ToString(), lineStyle));
            }
        }
        else if (level == 4)
        {
            for (int i = 5; i < 100; i += 5)
            {
                valueStyle.ValueItems.Add(new ValueItem(i.ToString(), lineStyle));
            }
        }
        else if (level == 5)
        {
            for (int i = 2; i < 100; i += 2)
            {
                valueStyle.ValueItems.Add(new ValueItem(i.ToString(), lineStyle));
            }
        }

        return valueStyle;
    }

and custom ZoomLevelSet

        public static ZoomLevelSet KilometerGridZoomLevelSet()
    {
        ZoomLevelSet zoomLevelSet = new ZoomLevelSet();

        zoomLevelSet = MainWindow.SetZoomLeves();
        zoomLevelSet.ZoomLevel02.CustomStyles.Add(ValueStyleKilometerGrid(0, kmGridLineStyle16));
        zoomLevelSet.ZoomLevel03.CustomStyles.Add(ValueStyleKilometerGrid(0, kmGridLineStyle32));
        zoomLevelSet.ZoomLevel04.CustomStyles.Add(ValueStyleKilometerGrid(0, kmGridLineStyle64));
        zoomLevelSet.ZoomLevel05.CustomStyles.Add(ValueStyleKilometerGrid(1, kmGridLineStyle64));
        zoomLevelSet.ZoomLevel06.CustomStyles.Add(ValueStyleKilometerGrid(2, kmGridLineStyle64));
        zoomLevelSet.ZoomLevel07.CustomStyles.Add(ValueStyleKilometerGrid(3, kmGridLineStyle64));
        zoomLevelSet.ZoomLevel07.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level08;
        zoomLevelSet.ZoomLevel09.CustomStyles.Add(ValueStyleKilometerGrid(4, kmGridLineStyle64));
        zoomLevelSet.ZoomLevel09.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level10;
        zoomLevelSet.ZoomLevel11.CustomStyles.Add(ValueStyleKilometerGrid(5, kmGridLineStyle64));
        zoomLevelSet.ZoomLevel12.DefaultLineStyle = kmGridLineStyle64;
        zoomLevelSet.ZoomLevel12.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;

        return zoomLevelSet;
    }

I think that somewhere here is problem that can cause above exception.
For now I have workaround that will generate grid lines for each grid step to different InMemoryFeatureLayer but this is not very elegant solution I think.

Thanks
Martin

Hi Martin,

In fact I hadn’t found your code have problem.

I have a question, does your lines shows different color or different width in same level?

If it’s the same style for the same level, in fact I think you can create the rectangle shape, and save them as a shape file.

Then you can just modify the style for different level, which should be simpler than use lines, and you can build index for it.

Regards,

Ethan

Hi Ethan
my grid lines are not simple straight lines. They are curved a little because of different projection so I need to recreate them again for different point on map. So I think that shapefile solution wont work.
All lines have the same thickness and color, what is different is opacity for certain zoom levels. Exception are grid lines that crates border of area for which the grid is displayed. Basically it is 100x100 km square with 1 km spacing at lowest scale. The higher map scale, the higher gridline spacing (2, 5, 10, 20, 25, 50, 100 km).

For now I think that I can live with the solution I have, but definitely in future I will return to it and try to find what could be wrong with ValueStyle solution.

I’ll try to separate gridline generation to new one-purpose project and send it to you to investigate what’s wrong. Of course if you will have time.

Thanks a lot Ethan

Martin

Hi Martin,

Thanks for your update, if you have the sample project which should be helpful for us to improvement related classes.

Regards,

Ethan