|  Home  |  Map Suite  |  Cygnus Track
    LivePerson Chat

ThinkGeo Blog

Providing GIS and GPS tracking insight.

 Tuesday, March 04, 2008

Recently I have received several questions about how to retrieve the current zoom level that is applied on the map control.  This information comes in handy when you want to implement a zoom bar or debug rendering code at a specific zoom level.  

To accomplish this, I have provided a function below that checks the current scale of the map against each zoom level's UpperExtent value.  With this code example, I assume that you are using the pre-built zoom levels off of the layer object that were introduced in version 2.39.0 or later of Map Suite and you have at least one layer loaded.   If you don't have any layers loaded, you could switch out the map1.Layers(0) with map1.DynamicLayers(0) and the function should still work properly.  To try this function out for yourself, just call it in the Map1_AfterMapDraw Event.

  'GET ZOOM LEVEL FUNCTION

  Private Function GetZoomLevel(ByRef Map As Map) As String
        Dim ZoomLevel As String = 0
        Dim CurrentScale As Double = map1.CurrentScale
        If CurrentScale < map1.Layers(0).ZoomLevel18.UpperExtent Then ZoomLevel = 18
        If CurrentScale < map1.Layers(0).ZoomLevel17.UpperExtent Then ZoomLevel = 17
        If CurrentScale < map1.Layers(0).ZoomLevel16.UpperExtent Then ZoomLevel = 16
        If CurrentScale < map1.Layers(0).ZoomLevel15.UpperExtent Then ZoomLevel = 15
        If CurrentScale < map1.Layers(0).ZoomLevel14.UpperExtent Then ZoomLevel = 14
        If CurrentScale < map1.Layers(0).ZoomLevel13.UpperExtent Then ZoomLevel = 13
        If CurrentScale < map1.Layers(0).ZoomLevel12.UpperExtent Then ZoomLevel = 12
        If CurrentScale < map1.Layers(0).ZoomLevel11.UpperExtent Then ZoomLevel = 11
        If CurrentScale < map1.Layers(0).ZoomLevel10.UpperExtent Then ZoomLevel = 10
        If CurrentScale < map1.Layers(0).ZoomLevel09.UpperExtent Then ZoomLevel = 9
        If CurrentScale < map1.Layers(0).ZoomLevel08.UpperExtent Then ZoomLevel = 8
        If CurrentScale < map1.Layers(0).ZoomLevel07.UpperExtent Then ZoomLevel = 7
        If CurrentScale < map1.Layers(0).ZoomLevel06.UpperExtent Then ZoomLevel = 6
        If CurrentScale < map1.Layers(0).ZoomLevel05.UpperExtent Then ZoomLevel = 5
        If CurrentScale < map1.Layers(0).ZoomLevel04.UpperExtent Then ZoomLevel = 4
        If CurrentScale < map1.Layers(0).ZoomLevel03.UpperExtent Then ZoomLevel = 3
        If CurrentScale < map1.Layers(0).ZoomLevel02.UpperExtent Then ZoomLevel = 2
        If CurrentScale < map1.Layers(0).ZoomLevel01.UpperExtent Then ZoomLevel = 1
        Return ZoomLevel
    End Function

If you are using an older version of Map Suite, or use Thresholds instead of the built in Zoom Levels, the same theory still applies.  However, instead of using current scale you would most likely use the map1.CurrenExtent.Width property and compare that against each Threshold's UpperLimit value. One additional thing to consider in this scenario is to make sure your ThresholdUnit and MapUnit are the same, otherwise you will need to convert them to make an accurate comparison.

Comments [0] - Trackback Posted March 4, 2008 at 5:35 PM by Clint Batman   #   
Topics: Map Suite Desktop | Map Suite Engine | Map Suite Web
Comments are closed.
Archive
<July 2008>
SunMonTueWedThuFriSat
293012345
6789101112
13141516171819
20212223242526
272829303112
3456789
Statistics
Total Posts: 11
This Year: 11
This Month: 0
This Week: 0
Comments: 4
Administration
Sign In