Working with Legends in the 64-bit Layout
This is a continuation of the article posted about working with map frames in the 64-bit Layout.
Each map layer creates its own legend and these are created in the Layout as separate frames. This makes it easy to move them about and place them in different layouts.
You create legends using Create Designer Legend. Once you have the map frame’s window ID you can create a legend for any layer or layers from the map. The legends are created on the same page as their associated map frame.
This example creates a legend for the World map layer using the name of the layer for its legend row text.
Create Designer Legend From Window mapWinID Default Frame Style “#” Font ("Arial",0,8,0) Frame From Layer 1
Since we know the map is embedded in a Layout window, this creates the legend for the map’s first layer in a new frame on the same page as the map.
WORKING WITH LEGENDS
The set of legend frames created for each map is considered a unique collection and has its own Legend Designer window ID although there is no actual Legend Designer window created. You need this window ID, and you need to know the index of each legend frame in itscollection, if you want to use MapBasic statements and functions to add or modify legend frames. In fact, the MapBasic to work with legends in the Layout is the same as if the legends existed in a real Legend Designer Window.
Consider this example of a page with two maps, each with their own set of legends.
Using layoutID as the MapBasic variable with the window identifier for the Layout window, the total number of frames on the page is given by:
DimcountFrames as Integer
countFrames = LayoutInfo(layoutID, LAYOUT_INFO_NUM_ITEMS)
There are a total of 8 frames on this page; 2 maps, 4 legends, and 2 text frames. Assume the top map is named “Map-1” and the bottom map is named “Map-2”. The frames were created/added to the page in this order giving them the following frame IDs:
2. Map-1 legend #1
3. Map-1 legend #2
4. Text “IDSS Map Legend”
6. Map-2 legend #1
7. Map-2 legend #2
8. Text “Connecticut Wire and Rate Map Legend”
GETTING THE LEGEND DESIGNER WINDOW ID
To get the Legend Designer window ID for the legends belonging to Map-2 use either of their frame IDs as the 2nd argument in LayoutItemInfo with the attribute that returns their Legend Designer window.
Dim map2LegendWinID as Integer
map2LegendWinID = LayoutItemInfo(layoutID, 6, LAYOUT_ITEM_INFO_LEGEND_DESIGNER_WINDOW)
If you want to modify Map-2’s first legend you also need its index into its unique collection.
Dimlegend Id as Integer
legendId = LayoutItemInfo(layoutID, 6, LAYOUT_ITEM_INFO_LEGEND_FRAME_ID)
Now you can use Alter Designer Frame to modify that legend. For example, if you wanted to modify its text from “Wire Center Boundary Lines” to “Wire Centers”
Alter Designer Frame Window map2LegendWinID Id legend Id Style id 1 Text "Wire Centers"
Once you’ve created at least one legend for a map and you want to add more using MapBasic, use Add Designer Frame to add more legends from the same map.
UPDATED: June 29, 2018