MapInfo Pro

 View Only
  • 1.  Selecting Map Window using Mapbasic

    Posted 06-30-2022 11:07
    Edited by A Oliver 06-30-2022 11:08
    Hallo, all

    I hope someone can help me.

    We have a Mapbasic program that works its way down a MapInfo Table and re-centers the map window based on values in each record in the table.  It then saves a new named workspace after each record.

     

    The program opens a template Workspace with a Map Window as the Front Window

    It then sets the centre easting and northing and zoom width based on values in the table

     

    set map  window frontwindow() center (iCOP_east, iCOP_north)

    set Map  window frontwindow() zoom iWidth Units "m"

     

    We are then trying to centre and size a second Map Window in the same Workspace which is not the Front Window.

    How do we write the Mapbasic to specify that we want to Change View for that second Map Window?

    We are using Mapbasic 15 and MapInfo Pro 15.0.3.

    Thank you,

    Alan.



    ------------------------------
    A Oliver
    West Midland Police
    BIRMINGHAM
    ------------------------------


  • 2.  RE: Selecting Map Window using Mapbasic

    Employee
    Posted 07-01-2022 08:52
    Hi

    You can loop through the open windows, detects the map windows and finally see if it's the FrontWindow() or not.
    Something along these lines:

    Dim nWIn, nFirstMID, nSecondMID As Integer

    For nWin = 1 To NumWindows()

       If WindowInfo(WindowID(nWin), WIN_INFO_TYPE) = WIN_MAPPER Then
          If WindowID(nWID) = FrontWindow() Then
             'Ah, we found the front map window
             nFirstMID = WindowID(nWin)
           Else
             'Ah, we found the other map window
             nSecondMID = WindowID(nWin)

          End If
      End If
    Next

    Now you have the ID of the two windows stored in two Integer variables

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



  • 3.  RE: Selecting Map Window using Mapbasic

    Posted 07-01-2022 09:33
    Peter,
    thank you for that.  We'll give it a go.  I was hoping we could just use the map "name" that appears in the top bar, but this way will still get us where we want to be.
    Thanks.
    Alan.

    ------------------------------
    A Oliver
    West Midland Police
    BIRMINGHAM
    ------------------------------



  • 4.  RE: Selecting Map Window using Mapbasic

    Employee
    Posted 12 days ago
    Ah, you can do that too.
    But you need to do it with a function like the one below from the Mapbasic Library on GitHub. The function can be found in the file WindowLib.mb

    Function WINGetIDFromTitle(ByVal sTitle As String) As Integer

    Dim i As Integer

    OnError GoTo ErrorOccured

    WINGetIDFromTitle = 0

    If sTitle = "" Then
      Exit Function
    End If

    For i = 1 To NumWindows()
      If WindowInfo(WindowID(i), WIN_INFO_NAME) = sTitle Then
        WINGetIDFromTitle = WindowID(i)
        Exit Function
      End If
    Next

    Exit Function
    '-------------------------
    ErrorOccured:
    Call ERRCreate(Err(), Error$(), "WINGetIDFromTitle")
    Call ERRShow()

    End Function

    Hope this helps

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



  • 5.  RE: Selecting Map Window using Mapbasic

    Posted 11 days ago
    Peter. thank you for that, too.

    ------------------------------
    A Oliver
    West Midland Police
    BIRMINGHAM
    ------------------------------