MapInfo Pro Developers User Group

 View Only
  • 1.  Find Selection in Map Frame

    Posted 05-18-2022 10:24
    Is there a way to activate a map frame and find selection in MapBasic 2021?

    ------------------------------
    Jim
    ------------------------------


  • 2.  RE: Find Selection in Map Frame

    Employee
    Posted 05-19-2022 03:30
    Hi Jim

    You can try this solution:

    Set Map Window 3129 Zoom Entire Selection

    It does require that you know the Window ID of the map in the frame.

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



  • 3.  RE: Find Selection in Map Frame

    Employee
    Posted 05-20-2022 05:27
    Hi Jim

    Here's a more complete example that loops over all windows and over all frames in a layout designer.
    It will zoom to the extent for all the embedded maps

    Include "MapBasic.def"

    Dim nWin, nFrame, nWID, nMID As Integer

    If SelectionInfo(SEL_INFO_NROWS) = 0 Then
       Note "Please select a record to zoom to!"
       Exit Sub
    End If

    Print "Number of Windows: '" & NumWindows() & "'"
    For nWin = 1 To NumWindows()
       nWID = WindowID(nWin)

       Print "Testing " & WindowInfo(nWID, WIN_INFO_NAME)
       If WindowInfo(nWID, WIN_INFO_TYPE) = WIN_LAYOUT_DESIGNER Then
          Print " Found a Layout (Designer) window!"

          Print " Number of Frames: " & LayoutInfo(nWID, LAYOUT_INFO_NUM_ITEMS)
          For nFrame = 1 To LayoutInfo(nWID, LAYOUT_INFO_NUM_ITEMS)
             nMID = LayoutItemInfo(nWID, nFrame, LAYOUT_ITEM_INFO_WIN)
             If nMID <> 0 Then
                Print " Frame " & nFrame & " contains a window"
                If WindowInfo(nMID, WIN_INFO_TYPE) = WIN_MAPPER Then
                   Print " Window is a map '" & WindowInfo(nWID, WIN_INFO_NAME) & "'"

                   Set Map Window nMID Zoom Entire Selection
                End If
             End If
          Next 'nFrame
       End If

    Next 'nWin

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



  • 4.  RE: Find Selection in Map Frame

    Posted 05-20-2022 08:12

    Thank you very much.  I definitely already see some things I had wrong or missing.

     

    Jim

     






  • 5.  RE: Find Selection in Map Frame

    Employee
    Posted 05-19-2022 11:00
    Open a table like States, create a layout and add a map frame to it.
    Run this in MapBasic Window
    ** assumes Layout is FrontWindow, and only 1 frame in Layout (the map frame), else pass the frame number if different frame.
    Would need to loop through Layout frames and see which one is map frame type otherwise to get its number.

    Select * from States where State = "MT" into Selection
    Set Window LayoutItemInfo(FrontWindow(), 1, LAYOUT_ITEM_INFO_WIN) Front
    Set map Zoom Entire Selection

    Regards,
    -Bill

    ------------------------------
    Bill Wemple
    Principal Software Engineer, Quality Management
    Precisely, Inc
    precisely.com
    ------------------------------