ThinkGeo.com    |     Documentation    |     Premium Support

Full Extent on a Map

Hello,


My question should be an easy one for someone to answer... 2.0 and 3.0 beta 1 had a way to get the FullExtent of the map (2.0 samples often had it right in the toolbars).  When upgrading to beta 2, the method GetFullExtent was removed, what am i supposed to do to replicate that function?


Thanks, Chad



Chad, 
  
   I knew we would catch from flack from this change.  Let me try and explain my way through this.  We removed it because people mis-using the API.  What we found people doing was using this API on a button click whenever they wanted their users to zoom out to the max extent.   
  
   The problem is this API has a high overhead because it in real time goes to every layer and gets it bounding box.  This operation of opening and closing every layer can be very slow when you have hundreds of shape files loaded.  It is also redundant because many shape files have about the same extent.  This was really bad for people using web services backed layers and also SQL type layers where the overhead of a single call is a bit expensive.  We felt like the better way for for users to specify their maximum extent and remove this crutch.   
  
   Most of the time you know one shape file that is the maximum extent, like a shape file for US states, and you can open it, call the GetBoundingBox and the close it.  You can cache this in you app so you don;t need to query it all the time.  We thought about caching the results but then people might add or remove layers and then would complain it wasn’t accurate.  I guess in the end to make the API very accurate it was expensive and people didn’t realize how expensive it was. 
  
   We suggest you set the max extent yourself in code and keep it around.  You can do this by finding a reference layer that you want to use for the extent.  In this way you can make the calls above and cache the results.  The other way is to set the extent at first to the whole world, see our samples for that extent, and then zoom into the place where you want it to be and record the current extent.  In this way you can hard code it in your app and adjust it as necessary.   
  
   To replicate exactly what we did you can do this.  Write a little code that loops through the overlays and then check if the overlay is a LayerOverlay.  If do then loop through the layers.  The first bounding box you find make this the refrence one.  For every other one you find call the ExtentHelper.ExpandToInclude or maybe it is on the RectangleShape, and pass in the other bounding box.  This will create a bounding box that includes both.  Keep looping and keep including the bounding boxes.  If you need help with the code let me know and I can whip up a sample. 
  
 Sorry for taking that away and if there was a purpose you used it for other than what I mentioned let me know.  Maybe we can design a better API to meet your needs. 
  
 David

Easy enough, i was able to get that working.  Did not even know the GetBoundingBox existed.  Thanks.



Chad, 
  
 My pleasure and let me know if you have any other questions. 
  
 David