Using Zoom Levels

Objective: In this lesson, you will learn how to zoom the map by zoom levels using the ZoomBar control.


Zoom levels are used to simplify map navigation and feature rendering. Each zoom level represents a map scale. Zoom level indices start with 0 at the smallest scale. The following table demonstrates the relationship between zoom levels and scales:

Map scale            Zoom level index         Zoom level name        Zoom-scale properties relationship 
1:75,000,000         0                        Country                Layer.MaxScale
1:30,000,000         1                        Sub-Region
1:15,000,000         2                        Region
1:7,500,000          3                        State
1:2,500,000          4                        County
1:1,000,000          5                        City                   Layer.MinScale

The Map control has the ZoomLevels collection which lets you add zoom levels. Add multiple zoom levels to the collection if you want to enable map navigation by zoom levels only.


The Map control will adjust the scale of the map changed by the ZoomIn, ZoomOut, ZoomFull, ZoomScale methods and Extent, MapScale properties to the most nearest scale defined in the ZoomLevels collection. The ZoomLevel property also will be set to the zoom level index that corresponds to that scale.


1. Adding Zoom Levels

Add the following code inside the Page_Load event handler (new code is in RED):


Private Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Map1.ZoomLevels.Add(75000000, "COUNTRY");
        Map1.ZoomLevels.Add(30000000, "REGION");
        Map1.ZoomLevels.Add(15000000, "SUBREGION");
        Map1.ZoomLevels.Add(7500000, "STATE");
        Map1.ZoomLevels.Add(2500000, "COUNTY");
        Map1.ZoomLevels.Add(1000000, "CITY");    
End Sub

2. Adding a ZoomBar control.

Add a ZoomBar control on the form. Change the Map property of the ZoomBar control to Map1, set the Position property to TopLeft to display the ZoomBar control inside the map. The ZoomBar control will display the zoom levels from the ZoomLevels collection.


3. Displaying features depending on the current zoom level.

The database layer added in the previous lesson is displayed on every zoom level. We will change its MaxScale property to display the database layer only when the current zoom level(map scale) is equal or less than the zoom level named REGION. Add the following code at the end of the AddDatabase method (new code is in RED):


Private Sub AddDatabase()
        dbLayer.LabelFont.Size = 12
        dbLayer.MaxScale = Map1.ZoomToScale("REGION")
End Sub


4. Compile and run the application, your map should look similar to the image below:




© 2018 VDS Technologies
Converted from CHM to HTML with chm2web Standard 2.85 (unicode)