VERIFIED SOLUTION i

Working with Maps in the 64-bit Layout

Working with Maps in the 64-bit Layout

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.


CREATING 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.  The remainder of this document uses 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 example, to set the units to inches:

Set Coordsys Layout Units “in”

MODIFYING LAYOUT WINDOW PROPERTIES

Use Set Layout to modify properties of a Layout window. The clauses that apply to the 64 bit Layout window are:

Set Layout [Window window_id]
     [Page page_number]
     [Center ( center_x, center_y )]
     [Zoom zoom_percent]
     [Selection {All | Clear | [Add | Remove] Frame ID
         frame_id, frame_id,…}]
     [Grid
            [Visibility { On | Off }]
            [Snap { On | Off }]
            [Size distance { Units paper_unit}]]
     [Smart Guides { On | Off }]

 
For example, to change grid settings:

Set Layout Window layoutID Grid Snap Off

Or to change zoom and select all the frames on the page 2 of a multi-page Layout:

Set Layout Window layoutID Page 2

Set Layout Window layoutID Zoom 40 Selection All

Adding A Map

USING AN EMPTY FRAME

Create the empty frame 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 mapFrameID as Integer
mapFrameID = 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 mapFrameID

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, mapFrameID, 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 MAP FRAME 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)

EXAMPLE WITH BROWSER

The same approach can be applied to browser frames. For example:

browserWinID = LayoutItemInfo(layoutID, “Browser”, LAYOUT_ITEM_INFO_WIN)

Browse * From World Into Window layoutID Position (1, 1) Width 5 Height 10 Pen(1,2,0) Name "Browser"

LAYOUTITEMINFO VS. LAYOUTPAGEITEMINFO FUNCTIONS

Both of these functions return information about a frame on a page of a Layout window.  LayoutItemInfo assumes you are querying about a frame on the current page. LayoutPageItemInfo takes a page number as an argument to let you query information about a frame on a specific page, which doesn’t have to be the current page.

All of the examples given in this document use
LayoutItemInfo for convenience.

 

 





 
UPDATED:  June 29, 2018