MapInfo Pro

 View Only

MapInfo Monday: SmartTexts with Map Coordinates in the Layout Window

  • 1.  MapInfo Monday: SmartTexts with Map Coordinates in the Layout Window

    Employee
    Posted 18 days ago

    SmartTexts allows MapInfo Pro users to add dynamic text to map and layout windows that will dynamically change.

    We have previously looked at SmartTexts in the map window which was added in MapInfo Pro v2021. You can also find a Quick Fire Tips & Tricks video about SmartText in the layout.

    In today's article, we will look at using SmartTexts with coordinates from an embedded map in the layout via the WindowHelper tool. This article is based on a question from @John Ievers I received a few weeks back.

    WindowHelper

    WindowHelper is a free tool for MapInfo Pro that can be downloaded and installed directly from the MapInfo Marketplace. Its many features help you work with your windows, maps, layouts, browsers, and layers.

    Besides a wide range of UI tools, the WindowHelper tool also publishes a wide range of custom functions that can be used inside MapInfo Pro. These custom functions can be used via the SQL Select dialog, the SQL Window, the Expression dialog for label expressions, and more.
    From the context menu on the WindowHelper tool, you can open the Custom Functions and Subprocedures dialog which lists the functions published by WindowHelper.
    From the dialog above, you can copy an example of the selected function to use.
    You can also use these custom functions for SmartTexts. We will look closer at the functions that can return coordinates for a map window.
    You can learn more about the recent releases of the tool here: WindowHelper.

    Getting Map Coordinates

    There are a few ways you can get to the coordinates of your map embedded in a layout. You can use the standard MapperInfo() function and you can use the custom function published by the WindowHelper tool.
    In both cases, you will have to start by giving the layout frame holding your map a name. In this way, you can refer to this name when you want to query the map in the frame. We will get back to this shortly.
    I have named my layout frame Map-1. This is the name you will see me using moving forward.
    Normally when querying a map, you need the WindowID of the map. In many cases, you can get to this using a function like FrontWindow(). This would give you the WindowID of the active window.
    It is different when dealing with windows embedded into layout frames. Here you would need to get the layout frame and using the layout frame get the WindowID of the embedded window.

    The first step is to find the frame holding the map. This is where the Name of the frame comes into play. You can use this function to get to the WindowID of the map embedded in a layout frame: LayoutItemWinID(CurContext (1), "Map-1", 1) where "Map-1" is the name of the frame with the embedded map and the last 1 refers to a map frame.

    You can use the expression above to query specifics about the map window, such as the minimum, maximum, and center coordinates:

    • Minimum X: MapperInfo(LayoutItemWinID(CurContext (1), "Map-1", 1), MAPPER_INFO_MINX)
    • Minimum Y: MapperInfo(LayoutItemWinID(CurContext (1), "Map-1", 1), MAPPER_INFO_MINX)
    • Maximum X: MapperInfo(LayoutItemWinID(CurContext (1), "Map-1", 1), MAPPER_INFO_MAXX)
    • Maximum Y: MapperInfo(LayoutItemWinID(CurContext (1), "Map-1", 1), MAPPER_INFO_MAXY)
    • Center X: MapperInfo(LayoutItemWinID(CurContext (1), "Map-1", 1), MAPPER_INFO_CENTERX)
    • Center Y: MapperInfo(LayoutItemWinID(CurContext (1), "Map-1", 1), MAPPER_INFO_CENTERY)
    To use these in a SmartText, you will have to create a new Text Frame on the layout and insert one of the functions above like this: $mb${MapperInfo(LayoutItemWinID(CurContext (1), "Map-1", 1), MAPPER_INFO_CENTERX)}. You can also combine this with a fixed string like this: Center X: $mb${MapperInfo(LayoutItemWinID(CurContext (1), "Map-1", 1), MAPPER_INFO_CENTERX)}.
    In the layout window, this can look like this
    And when the text isn't being edited it looks like this:
    When you use the MapperInfo() function to return the coordinates, the values will be returned based on the current session projection. If this matches the projection of the map, you are good. If it doesn't, you should use the custom function from the WindowHelper tool instead.
    Keep in mind that these functions only work if WindowHelper is loaded in MapInfo Pro.
    Let's look at those functions.
    They work similarly. You still need to provide the WindowID of the map to retrieve the coordinates from and you also need to specify which coordinate you want to return.
    The basic function looks like this used for the active window: WHMAPGetCoordinate(FrontWindow(), "MINX").
    To use it with a map in a layout frame, we need to change it slightly to this: WHMAPGetCoordinate(LayoutItemWinID(CurContext (1), "Map-1", 1), "MINX"). Just like before, "Map-1" refers to the name of the layout frame and the last 1 refers to map frames.

    You can use the expression above to query specifics about the map window, such as the minimum, maximum, and center coordinates:

    • Minimum X: WHMAPGetCoordinate(LayoutItemWinID(CurContext (1), "Map-1", 1), "MINX")
    • Minimum Y: WHMAPGetCoordinate(LayoutItemWinID(CurContext (1), "Map-1", 1), "MINX")
    • Maximum X: WHMAPGetCoordinate(LayoutItemWinID(CurContext (1), "Map-1", 1), "MAXX")
    • Maximum Y: WHMAPGetCoordinate(LayoutItemWinID(CurContext (1), "Map-1", 1), "MAXY")
    • Center X: WHMAPGetCoordinate(LayoutItemWinID(CurContext (1), "Map-1", 1), "CENTERX")
    • Center Y: WHMAPGetCoordinate(LayoutItemWinID(CurContext (1), "Map-1", 1), "CENTERY")
    Again, you insert this using a text with the SmartText expression like this: Y: WHMAPGetCoordinate(LayoutItemWinID(CurContext (1), "Map-1", 1), "MINX").
    This will look very similar to the other one with the session projection and the map projection matching.
    Now if the session projection and the map projection get out of sync, you'd see something like this happen.
    In the example above, the SmartText based on the MapperInfo() function has switched to using the session projection, Long/Lat WGS84. The WHMapGetCoordinate() function from the WindowHelper tool is still using the projection from the map window.
    Both can be right for your work. I just wanted to make sure you were aware of the difference.
    Here's an example where I have set the corner coordinates of the map into the corners of the map frame.
    Is there any other SmartText you'd like to see available for the layout or the map?


    ------------------------------
    Peter Horsbøll Møller
    Principal Presales Consultant | Distinguished Engineer
    Precisely | Trust in Data
    ------------------------------