Managing the Behavior of Labels - MapBasic - 2023

MapInfo MapBasic Reference

Product type
Software
Portfolio
Locate
Product family
MapInfo
Product
MapInfo > MapBasic
Version
2023
Language
English
Product name
MapBasic
Title
MapInfo MapBasic Reference
First publish date
1985
Last updated
2023-09-12
Published on
2023-09-12T16:32:32.686312

If the map contains auto-labels for two or more layers, then not all features have labels on the map. This is because the labels from the different layers are competing for limited space within the map, so a city might not be labeled because a road label is in the way for example. Also, users may want to control whether labels in a map can be selected or not. If they can’t be selected, then users will not accidentally select them when they meant to select an object that is near or overlaps with the label. The following clause specifies that a layer have a high priority when displaying its labels, by moving the layer ID to the top of this list and includes the ability to toggle label selection for a map.

Syntax

Set Map 
	[ Window window_id ] 
	[ Label 
		[ Selection { On | Off } ] 
		[ Priority { Default | layer_id [ , layer_id ... ] } ] ]

window_id is the integer window identifier of a Map window.

layer_id is a number identifying a map layer to modify, according to that layer's original position in the map, where 1 (one) is the top-most layer number (the layer which draws last, and therefore always appears on top).

Description

The Cosmetic layer is a special layer, with a layer number of zero. The Cosmetic layer is always drawn last; thus, a zero should not appear in a LabelPriority clause for layer_id.

If an invalid layer ID is specified, then error 600 is generated: “Invalid view layer.”

Label Selection turns on or off label selection for the entire map. By default, labels can be selected in a Map window. When disabled, you cannot:
  • Select labels in the map regardless of which layer the labels are from.
  • Double-click to open the label dialog (this is the same behavior as for map objects).
When label selection is off for a Map window, the
Set Map Label Selection Off
statement saves to the workspace and the workspace version increases to 1200.

Label Priority dictates the priority order for displaying labels on the map; the first layer listed in this statement is the layer that gets maximum label priority. For example, for a Map window with four layers (not including the Cosmetic layer), the default label priority is 4, 3, 2, 1, so layer 4 has top priority.

This statement can list all layer IDs from your map, but you don’t have to list them all. Whatever layer IDs you do list move to the top of the list of label priorities. The rest of the list of layer IDs remains in whatever order they were in previously. (This is consistent for reordering layers, such as
Set Map Order 3
to move the 3rd layer to the top of the list.)

Ordering layers (moving a layer and group layer to a specific location in the layer list) affects label priority; a layer higher in the list has a higher labeling priority. However, customizing label priority overrides the layer order. After customizing layer priority, changing the order of layers has no effect on label priority.

Set Map LabelPriority Default resets the label priority list to match the default (bottom-up) order, which is the same as the layer draw order in the Layer Control window.

Labels display following the order of records in the table. To change the order of priority for displaying labels, save a copy of the table, sorted in order of priority, most important record first, and use that table for labeling instead of the original. In a table sorted alphabetically by street (like the StreetPro Display layer) this often means that streets with names beginning with A, B, or C are almost the only labeled streets on your map. Labeling effectively gives a small side street like "Aberdeen Street" priority over "State Highway 177" or other major roads that might actually be useful in navigating or orienting a map.

The label priority is the reverse of the layer list, so that the bottom most layer has the top label priority. When adding a Gridline, it is initially the topmost layer, and its label priority is also forced to be the top label priority. To help mimic this, if there is a Gridline layer when issuing a label priority default, the Gridline layer label priority is forced toward the top.

Example

The following example turns on label selection for the entire map and sets the label order, so that layer 2 has the highest priority.

Set Map Label Selection On Priority 2, 4, 3, 1