ThinkGeo.com    |     Documentation    |     Premium Support

What is the best way to find the Active Zoom Level?

Hi,


As I'm building my application and rendering code, a lot of times I want to know what the current zoom level is.  The reason I want to know this is so I can tweak my rendering code for each zoom level very easily.  Is there an API that can provide this?


Thanks!



Clint,


 
Here is the sample code how to get the current zoomlevel. Please have a look and let us know for any queries.
 
Ben.

139-4869.zip (4.06 KB)

Is there anyway to find the current zoom level server side?  Is this possible on the services or desktop editions? 
  
 Thanks!

Clint,

ZoomLevelSet.GetZomLevel() gets the ZoomLevel based on the input extent, the width of the image and the map unit. Here is the code showing how to use it as well as how to get the number (from 1 to 20) of the current zoomLevel.


     ZoomLevelSet zoomLevelSet = new ZoomLevelSet();
            // Get the zoomLevel based on the current extent. 
            ZoomLevel myLevel = zoomLevelSet.GetZoomLevel(mapEngine.CurrentExtent, bitmap.Width, GeographyUnit.DecimalDegree);

            // Get the number(1 to 20) of the current zoomLevel.
            Collection<ZoomLevel> zoomLevels = zoomLevelSet.GetZoomLevels();

            int currentZoomLevelNumber = 0;
            for (int i = 0; i < 20; i++)
            {
                if (zoomLevels[i].Scale == myLevel.Scale)
                {
                    // Here we get the number of the current ZoomLevel
                    currentZoomLevelNumber = i + 1;
                    break;
                }
            }
 

Ben

I have tried the code you posted above and I always get back zoom level 2 when I run it regardles of whether I have zoomed in or out. This does not appear to be working. I am using the lastest release beta of the 3.0 Web Edition control. 
  
 Thanks 
 Jeff

Jeff,


The above code is for service edition. Here is a demo how you can do it in web edition on the client part, please have a look.


Ben.



262-Post4869.zip (97.4 KB)

Thanks for the clarification Ben. I had looked at this last week. I will fashion this into my current application. It is interesting that this functionality is not present when the control is posted back to the server. 
  
 Thanks again.

Jeff,


Here is a sample shows how to implement it on server part in Web Edition, please have a look.


If your map width is set to 100% instead of a concrete value like 800 pixels, the result will not be correct, for we didn't get the concrete value for map width from the relative percentage. We will try to figure it out and please let us know if this is your case.


Ben.



267-Post4869.zip (97.6 KB)