Now that a map windows can be created within a Layout page frame, people have asked about what MapBasic to use to get the map's window ID. You need the window ID to use map related MapBasic statements and functions to work with the map.
First we'll start with some setup code to create the Layout window. To create a blank Layout with a single page:
Layout Designer
By default the window is created tabbed unless you specify other window style options such as Floating or Docked. Create a variable named layoutID to hold the newly created Layout window ID.
Dim layoutID as Integer
layoutID = WindowID(0)
To add pages use the Add Designer Page statement:
Add Designer Page
Now our Layout has two pages and the 2nd page is the current page. MapBasic to create content for a Layout window gets executed against the Layout’s current page. Thus if the current page is page 2, any frames you create are created on page 2. To create content on a different page, make sure to make that page the current page.
For example, to move back to page 1:
Set Layout Window layoutID Page 1
Remember to set the coordinate system of the Layout to the units you will be using when creating content. For these examples we'll be using inches:
Set Coordsys Layout Units “in”
Adding a Map
There are several ways to add map content. The first example shown is to create an empty frame with the desired position and size first. Give it a unique name that can be referred to later.
Create Frame (1, 1) (5, 5) Pen(1, 2, 0) Brush(1, 16777215, 16777215) Name "Main Map"
Get the numeric frame ID of the empty frame using the frame name as an argument to LayoutItemInfo. The numeric ID is needed to fill the frame with map data.
Dim frameID as Integer
frameID = LayoutItemID(layoutID, "Main Map", LAYOUT_ITEM_TYPE_EMPTY)
Create the map by filling the empty frame with mappable tables. In this example we use World.TAB.
Open Table World.TAB
Map From World Into Window layoutID ID frameID
Getting the Map window ID
To get the newly created map window ID, use the LayoutItemInfo function. You can pass either the map frame ID or the name assigned to the map frame (e.g., “Main Map”) for the 2nd argument to LayoutItemInfo.
Dim mapWinID as Integer
mapWinID = LayoutItemInfo(layoutID, frameID, LAYOUT_ITEM_INFO_WIN)
Another function to get the map frame’s window ID is LayoutItemWinID. This example shows it will return the first map frame with the name “Main Map”.
mapWinID = LayoutItemWinID(layoutID, “Main Map”, LAYOUT_ITEM_TYPE_MAPPER)
Creating the Map in One Statement
Instead of creating an empty frame first, and filling it with map data, you can create the map frame in one statement:
Map From World Into Window layoutID Position (1, 1) Width 4 Height 4 Pen(1,2,0) Brush(1,16777215,16777215) Name "Main Map"
mapWinID = LayoutItemInfo(layoutID, “Main Map”, LAYOUT_ITEM_INFO_WIN)
Now you have the Map frame's window ID that can be used in subsequent Set Map Layer statements, or any other map related statements and functions.