LegendInfo() function - 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

Purpose

Returns information about a legend, such as the orientation, number of legend frames, and the sample size style of small or large. You can call this function from the MapBasic window in MapInfo Pro.

Syntax

LegendInfo( window_id, attribute )

window_id is a number that specifies which legend window you want to query.

attribute is an integer code indicating which type of information to return. For values, see the table later in this description.

Return Value

Depends on the attribute parameter, see the table later in this description.

Description

The window_id parameter specifies which window to query. To obtain a window identifier, call the FrontWindow() function immediately after opening a window, or call the WindowID() function at any time after the window's creation.

There are several attributes that LegendInfo() returns about any given Legend window. The attribute parameter tells the LegendInfo() function what Legend window statistic to return. The attribute parameter should be one of the codes from the following table; codes are defined in MAPBASIC.DEF.

Attribute Code ID LegendInfo() Return Value
LEGEND_INFO_MAP_ID 1 Integer: Returns the ID of the parent map window (can also get this value by calling the WindowInfo() function with the WIN_INFO_TABLE code).
LEGEND_INFO_ORIENTATION 2 Integer: Returns predefined value to indicate the layout of the legend:
  • ORIENTATION_PORTRAIT (1)
  • ORIENTATION_LANDSCAPE (2)
  • ORIENTATION_CUSTOM (3)
LEGEND_INFO_NUM_FRAMES 3 Integer: Returns the number of frames in the legend.
LEGEND_INFO_STYLE_SAMPLE_SIZE 4 Integer: Returns 0 for small legend sample size style or 1 for large legend sample size style. Returns -1 for a Legend window.
LEGEND_INFO_LINE_SAMPLE_WIDTH 5 Integer: Returns line sample width in MapBasic paper units. Returns -1 for Cartographic Legend window. For details about paper units, see Set Paper Units statement.
LEGEND_INFO_REGION_SAMPLE_WIDTH 6 Integer: Returns region sample width in MapBasic paper units. Returns -1 for Cartographic Legend window.
LEGEND_INFO_REGION_SAMPLE_HEIGHT 7 Integer: Returns region sample height in MapBasic paper units. Returns -1 for Cartographic Legend window.
LEGEND_INFO_NUM_TEXTFRAMES 8 Integer: Returns the number of Text Frames in the current Legend window.
LEGEND_INFO_DEFAULT_TITLE 9 String: Returns the default title pattern for the legend.
LEGEND_INFO_DEFAULT_TITLE_FONT 10 String: Returns the default title pattern font for the legend.
LEGEND_INFO_DEFAULT_SUBTITLE 11 String: Returns the default subtitle pattern for the legend.
LEGEND_INFO_DEFAULT_SUBTITLE_FONT 12 String: Returns the default subtitle pattern font for the legend.
LEGEND_INFO_DEFAULT_STYLE 13 String: Returns the default style name pattern for the legend.
LEGEND_INFO_DEFAULT_STYLE_FONT 14 String: Returns the default style name pattern font for the legend.
LEGEND_INFO_DEFAULT_AUTO_FNT_SZ 15 Logical: Returns the default value of "Auto increase sample size to match font".

Example

dim wndLegend, wndMap as integer
for i = 1 to NumWindows() 
	If WindowInfo(WindowID(i), WIN_INFO_TYPE) = WIN_MAPPER then
		wndMap = WindowInfo(WindowID(i), WIN_INFO_WINDOWID)
	end if
	if WindowInfo(WindowID(i), WIN_INFO_TYPE) = WIN_LEGEND_DESIGNER then
		wndLegend = WindowInfo(WindowID(i), WIN_INFO_WINDOWID)
	end if
next

This example illustrates how to see which map window ID was used for creating the Legend Window.

If LegendInfo(wndLegend, LEGEND_INFO_MAP_ID) = wndMap then
	Print "Map ID: " + str$(MapID) + " was correct"
End if

See Also:

FrontWindow() function, LegendFrameInfo() function, LegendTextFrameInfo() function, LegendStyleInfo() function, WindowID() function