ThinkGeo.com    |     Documentation    |     Premium Support

WPF Edition: Crashes when using Zoom too quickly





I’m having a problem with the sample program included in the World Map Kit (Decimal Coordinates) and the Map Suite WPF Desktop edition.  The name of the project is CSWpfDesktopEditionSample.  The map is displayed, and I can zoom in and out one level at a time.  However, when I try to zoom by two levels quickly, or use the mouse wheel, the program crashes at the following line:
 
layer.Draw(canvas, labelsInAllLayers); 
// InvalidOperationException: The GeoCanvas is currently not drawing.  Please call the BeginDraw method before calling this method.
 
Can I get some help with this issue?
Thanks in advance.


David, 
  
 Thank you for your post, which version do you use? 
  
 Regards, 
  
 Gary

Hi Gary, 
  
 If I understand your question correctly, I believe the answer is version 5.0 of the Map Suite WPF Desktop Edition.  The World Map Kit was created on 7/21, so whichever version that corresponds to. 
  
 -Dave

David, 
  
 I have checked the sample code of WPF 5.0, but I didn’t find a place use layer.Draw(canvas, labelsInAllLayers); did you change the sample? 
  
 Regards, 
  
 Gary

No, I'm running the code out of the box.  This sample was included on the World Map Kit disc 1. 



These are the files: 

CS VS2010 WpfDesktopEditionSample.sln 

CSWpfDesktopEditionSample\App.xaml 

CSWpfDesktopEditionSample\App.xaml.cs 

CSWpfDesktopEditionSample\CSWpfDesktopEditionSample.csproj 

CSWpfDesktopEditionSample\Window1.xaml 

CSWpfDesktopEditionSample\Window1.xaml.cs 

CSWpfDesktopEditionSample\WorldMapKitRenderLayer.cs 

CSWpfDesktopEditionSample\WorldMapKitShapeFileFeatureLayer.cs 

CSWpfDesktopEditionSample\WorldMapKitShapeFileFeatureSource.cs 



The function that crashes is DrawCore(), which lives in WorldMapKitRenderLayer.cs on line 3026.


[code] 


protected override void DrawCore(GeoCanvas canvas, Collection<simplecandidate> labelsInAllLayers)


        {


            RectangleShape extent = canvas.CurrentWorldExtent;


            object image = canvas.NativeImage;


            GeographyUnit unit = canvas.MapUnit;


            bool isInDrawing = canvas.IsDrawing;


            if (isInDrawing)


            {


                canvas.EndDrawing();


            }


 


            Collection<string> candidateLayerNames = new Collection<string>();


 


            if (rtreeSpatialIndex != null)


            {


                candidateLayerNames = rtreeSpatialIndex.GetFeatureIdsIntersectingBoundingBox(extent);


            }


 


            foreach (WorldMapKitShapeFileFeatureLayer layer in staticLayers)


            {


                if (candidateLayerNames.Count == 0 || candidateLayerNames.Contains(Path.GetFileName(layer.ShapePathFileName)))


                {


                    canvas.BeginDrawing(image, extent, unit);


                    layer.Open();


                    layer.Draw(canvas, labelsInAllLayers);


                    canvas.EndDrawing();


                }


            }


 


            foreach (WorldMapKitShapeFileFeatureLayer layer in dynamicLayers)


            {


                if (candidateLayerNames.Count == 0 || candidateLayerNames.Contains(Path.GetFileName(layer.ShapePathFileName)))


                {


                    canvas.BeginDrawing(image, extent, unit);


                    layer.Open();


                    layer.Draw(canvas, labelsInAllLayers);


                    canvas.EndDrawing();


                }


            }


 


            if (isInDrawing)


            {


                canvas.BeginDrawing(image, extent, unit);


            }


        }


<simplecandidate><string><string>

</string></string></simplecandidate>


 



David, 



Thank you for your feedback and sorry for delay. 



Please replace your drawcore method by the code below and have a try: 


        protected override void DrawCore(GeoCanvas canvas, Collection<SimpleCandidate> labelsInAllLayers)
        {
            RectangleShape extent = canvas.CurrentWorldExtent;
            object image = canvas.NativeImage;
            GeographyUnit unit = canvas.MapUnit;

            Collection<string> candidateLayerNames = new Collection<string>();

            if (rtreeSpatialIndex != null)
            {
                candidateLayerNames = rtreeSpatialIndex.GetFeatureIdsIntersectingBoundingBox(extent);
            }

            foreach (WorldMapKitShapeFileFeatureLayer layer in staticLayers)
            {
                if (candidateLayerNames.Count == 0 || candidateLayerNames.Contains(Path.GetFileName(layer.ShapePathFileName)))
                {
                    layer.Open();
                    layer.Draw(canvas, labelsInAllLayers);
                    canvas.Flush();
                }
            }

            foreach (WorldMapKitShapeFileFeatureLayer layer in dynamicLayers)
            {
                if (candidateLayerNames.Count == 0 || candidateLayerNames.Contains(Path.GetFileName(layer.ShapePathFileName)))
                {
                    layer.Open();
                    layer.Draw(canvas, labelsInAllLayers);
                    canvas.Flush();
                }
            }

        }



Regards, 



Gary



That code removes the issue I was seeing. 
 I’ll continue using it for our evaluation.

David, 
  
 I hope you can enjoying our product. 
  
 Any more questions please feel free to let me know. 
  
 Regards, 
  
 Gary