ThinkGeo.com    |     Documentation    |     Premium Support

Restrict & Limit Zooming

Hi,


I want to be able to easily limit zooming and panning for certian users in my applciation, what would be the best approach to do the following restrictions:


1.  Limit the application where a user can't pan or zoom outside of a certian extent.


2.  Limit how far a user can zoom in and if they try write a message on the screen saying maximum zoom level reached.


Thanks!



Clint, 
  
 We have 2 properties, Map.MinimumScale and Map.MaximumScale, to set how far a user can zoom in/out. By default Map.MinumumScale is 500 and Map.MaximumScale is Double.Max. In this version(3.0.131), we have a little bug that when you keep zooming in in some area, it throws an exception “current scale should between MinumumScale and MaximumScale” while in some other area, it just simply forbid you from zooming in further without any exception. We will work on this issue and unify the appearance. 
  
 We cannot add restriction for Panning. I will write this requirement down and maybe we will add a RestrictedExtent in the next version. 
 Thanks for pointing it out and please let us know for more queries. 
  
 Ben. 


Hi I found the Create a Restriction Layer sample under the "Moving Around the Map" section that does what I need. 
  
 Thanks!

That’s good! Let us know if we could make your coding easier.

This also seems to work - recognizing that this is a limited example - implement the CurrentExtentChanging event and set e.Cancel if the pan or zoom tries to expose a region outside your desired area. (yes, my example assumes degrees, -180 - 180, -90 to 90). Got this working about the time I saw this thread, so maybe that’s what the restriction layer does, don’t know… 
  
 -jeff 
  
         ‘’ 
         ‘’ Prevent ZoomOut or Pan that would go past world edges 
         ‘’ 
         Private Sub MapMain_CurrentExtentChanging(ByVal sender As Object, ByVal e As ThinkGeo.MapSuite.DesktopEdition.CurrentExtentChangingWinformsMapEventArgs) Handles MapMain.CurrentExtentChanging 
             Dim minLon As Double = e.NewExtent.GetBoundingBox.LowerLeftPoint.X 
             Dim minLat As Double = e.NewExtent.GetBoundingBox.LowerLeftPoint.Y 
             Dim maxLon As Double = e.NewExtent.GetBoundingBox.UpperRightPoint.X 
             Dim maxLat As Double = e.NewExtent.GetBoundingBox.UpperRightPoint.Y 
             e.Cancel = minLon < -180 Or maxLon > 180 Or minLat < -90 Or maxLat > 90 
         End Sub 
  


Jeff, 
  
 Thanks for your sharing.  
  
 Honestly speaking, it seems this code can have the same effects with RestrictLayer, while RestricLayer do it in another way by overriding the DrawCore API. 
  
 Any more questions just feel free to let me know. 
  
 Thanks. 
  
 Yale