HOW TO

Set and return the map's scale

Last Published: April 25, 2020

Summary

How do I zoom the map to a particular scale or report to the user the current scale of the map?

Procedure

The Map control does not have a MapScale property.

Given map data drawn to the Map control's display area, let's say you want a label control on your form to update with the current map scale, expressed in either a ratio form (e.g., 1:24,000) or in some other map unit mix (e.g., 1" = 5,280'). You will need to calculate the map scale in your code so that it is seamless to the user.

Dividing the width of the map data in the Map control by the width of the Map control itself on the form will produce a ratio scale value.

The first step would be to have your code convert the width of the Map control on the form and the width of the map data into the same units. For example, if the MapLayers are shapefiles projected in the UTM projection and coordinate system, chances are the map units are meters. And if you are using MapObjects with Visual Basic, then chances are that the ScaleMode of your Form provides a control coordinate system using twips as the unit of measurement. Pick a common unit of measurement and convert the width of the Map control and the width of the map data into the same units.

'Convert twips into inches
ctrlWidthInches = Map1.Width / 1440

'Convert meters into inches
dataWidthInches = Map1.Extent.Width * 39.37

'Calculate ratio scale
scale = dataWidthInches / ctrlWidthInches

'Populate label control
Label1.Caption = "1 : " & scale

If you instead want an "Inches to Feet" type of scale, then divide the scale calculated above by 12.

Label1.Caption = "1 inch equals " & CStr(scale / 12) & " feet."
SET THE MAP SCALE

The only way to zoom in or out with MapObjects is to create a Rectangle object and write that Rectangle into the Map control's Extent property.
Setting the map scale implies that you are going to receive a ratio scale value from the user. The user wants the map to zoom in or zoom out so that the map draws at that scale, regardless of the current scale of the map. Your code will need to provide a way to receive this scale value from the user, perhaps with a TextBox or InputBox; then your code will calculate a new map extent rectangle and force the Map to draw that rectangular display space.

Multiplying the width of the Map control by the ratio scale will produce a map data width that matches that scale.

'Convert twips into inches
ctrlWidthInches = Map1.Width / 1440

'Convert ratio into inches
dataWidthInches = scale * ctrlWidthInches

'Convert inches into meters (or feet or whatever map units are)
dataWidth = dataWidthInches / 39.37

'Create a new rectangle and set its properties to match the scale.

`Code:Dim rect As New MapObjects2.RectangleWith rect  .Bottom = 0.0000001  .Top = 0.0000001  .Left = Map1.Extent.Center.X - (dataWidth / 2)  .Right = Map1.Extent.Center.X + (dataWidth / 2)End With `
`Code:`

Article ID:000002312

Software:
• Legacy Products

Get summarized answers and video solutions from our new AI chatbot.