ThinkGeo.com    |     Documentation    |     Premium Support

Exception around setting map extents

Hi,


I get the following exception when I try to reset my map extents:


   at System.Drawing.Bitmap..ctor(Int32 width, Int32 height, PixelFormat format)

   at ThinkGeo.MapSuite.DesktopEdition.WpfMap.xfbd15a0e9d15f4e2(Graphics x783a718028818269, RectangleShape xb35a33b423b17f65)

   at ThinkGeo.MapSuite.DesktopEdition.WpfMap.x7d52d0ad1d6779cd(Boolean x991dc8ddc7528b44, RectangleShape x178b193eec228e6e)


  
private void ResetExtents() {           
    layer.Open();      
    wpfMap1.CurrentExtent = layer.FeatureSource.GetBoundingBox();
    wpfMap1.CenterAt(layer.GetBoundingBox().GetCenterPoint());      
    layer.Close();  


here are the values I'm supplying:


layer.GetBoundingBox().GetCenterPoint() = -93.9375495910645,32.2573108673095,0


layer.FeatureSource.GetBoundingBox() = -94.0427372387695,32.3991367749023,-93.8323619433594,32.1154849597168


Any ideas?


Thanks,


Greg



Greg,


Thanks for your post.
 
I tried the HowDoI sample\GettingStarted\HideOrShowAFeatureLayer by replacing the following code, it works fine. Could you try this in your environment?

private void cbkShowLayer_CheckedChanged(object sender, RoutedEventArgs e)
        {
            //if (wpfMap1.Overlays.Count > 0)
            //{
            //    wpfMap1.FindFeatureLayer("WorldLayer").IsVisible = cbkShowLayer.IsChecked.Value;
            //    wpfMap1.Refresh(wpfMap1.Overlays["WorldOverlay"]);
            //}
 
            if (wpfMap1.Overlays.Count > 0)
            {
                FeatureLayer featureLayer = wpfMap1.FindFeatureLayer("WorldLayer");
                featureLayer.Open();
 
                //wpfMap1.CurrentExtent = featureLayer.GetBoundingBox();
                wpfMap1.CurrentExtent = new RectangleShape(-94.0427372387695, 32.3991367749023, -93.8323619433594, 32.1154849597168);
 
                //wpfMap1.CenterAt(featureLayer.GetBoundingBox().GetCenterPoint());
                wpfMap1.CenterAt(new PointShape(-93.9375495910645,32.2573108673095));
                featureLayer.Close();
 
                wpfMap1.Refresh();
            }
        }


 
From the stack trace, it seems that the problem root is the background of the MapControl, I am wondering if there is any special code in it?
 
If you still have problem, could you send us a small sample application to show us your problem? That would be very helpful to find out and fix the problem.
 
Any more questions just feel free to let me know.
 
Thanks.
 
Yale

Hardcoding the values does prevent the exception from happening.


The problem seems related to how I set the CurrentExtent upon the initial load/display of the map.  When I initially display my map, I haven't yet loaded any features into it, but for some reason if I do not set my extents to the feature set bounding box (unknown at this time), then I get the exception.  By hardcoding the value in, the value was set upon initial load.  Then, when the user selects the dataset they wish to view, I reset the extents to match this new, user selected data set.


So... for example. The code below doesn't work.  (initialSetup is true only during the initial setup of wpfMap (i.e., true during construction)


 


 


 


   
layer.open();   
PointShape centerPoint = layer.GetBoundingBox().GetCenterPoint();   
RectangleShape extent = layer.FeatureSource.GetBoundingBox();   
if(initialSetup)   
{               
    wpfMap1.CenterAt(centerPoint);               
    wpfMap1.CurrentExtent = extent;   
}   
else   
{               
    RectangleShape newExtent = new RectangleShape(-94.0427372387695, 32.3991367749023, -93.8323619433594, 32.1154849597168);      
    wpfMap1.CenterAt(centerPoint);               
    wpfMap1.CurrentExtent = newExtent;   
}   
layer.close(); 


But, this code works.  Obviously this won't fly for production.


 


 


 


  
layer.open();  
PointShape centerPoint = layer.GetBoundingBox().GetCenterPoint();      
RectangleShape newExtent = new RectangleShape(-94.0427372387695, 32.3991367749023, -93.8323619433594, 32.1154849597168);      
wpfMap1.CenterAt(centerPoint);      
wpfMap1.CurrentExtent = newExtent;  
layer.close(); 


So, Am I not able to change the initial extent?


Thanks,


Greg



I found a workaround for my problem.  I created a BeginUpdate / EndUpdate concept which prevented other code from successfully refreshing until I decide.  I determined that a refresh was coming in around the time the code to reset the extents was happening.


-Greg



Greg, 
  
 Thanks for your sharing. 
  
 I agree with you about the root problem reason, and I also found some similar problem when building our HowDoI samples. 
  
 Any more questions just feel free to let me know. 
  
 Thanks. 
  
 Yale