MapInfo Pro Developers User Group

 View Only
  • 1.  Layout zoom behavior vs Map window zoom

    Posted 23 days ago

    Hello,

    I am generating a Layout from a Map window using MapBasic.

    In MapInfo Pro 15, the Layout frame correctly inherits the current Map window zoom (for example after Set Map Window Zoom Entire Layer).

    In newer versions, the Layout always shows the full extent instead.

    Has the behavior of Layout frames regarding map extents changed?

    Is there a supported way to force the Layout to use the current Map window zoom?

    Thanks.



    ------------------------------
    Mayca González Pérez
    COMUNIDAD. AUT. REG MURCIA
    ------------------------------


  • 2.  RE: Layout zoom behavior vs Map window zoom

    Employee
    Posted 22 days ago

    Hey Mayca

    Yes, back in v15.2 (or was it 12.5.2?), we implemented a new Layout Designer window that changes how you work with maps and browsers in the layout.

    Instead of basically showing a still image of the map and the browser, we made these behave as active windows within the layout. This allows you to double-click the frame with the map, then zoom, pan, and edit spatial features directly in the embedded map window.

    This means that you need to get to the window ID of your map, and then you can change anything for that map, just like any map.

     Include "MapBasic.def"
    
    Dim	nMapID, nMapIDInLayout, nLayoutID, nLegendID, i As Integer
    
    	'**Let's find a map window to insert
    	For i = 1 To NumWindows()
    		If WindowInfo(WindowID(i), WIN_INFO_TYPE) = WIN_MAPPER Then
    			nMapID = WindowID(i)
    			Exit For
    		End If
    	Next
    	Print "Map: " & WindowInfo(nMapID, WIN_INFO_NAME)
    
    	'Create Layout window
    	Layout Designer
    		Position (0.0,0.0) Units "in"
    		Width 8 Height 8 Units "in"
    	nLayoutID = WindowID(0)
    
    	Set Layout
    		Window nLayoutID
    		Extents To Fit Zoom 100
    
    	Set CoordSys Layout Units "in"
    	Set Paper Units "In"
    
    	'Insert Map into Layout
    	Create Frame Into Window nLayoutID (0.5,1.0) (6.5,7.0)
    		Pen (1,2,0) Brush (2, 16777215, 16777215)
    		From Window nMapID
    		FillFrame On
    
    	nMapIDInLayout = WindowID(0)
    
    	Set Map Window nMapIDInLayout Zoom Entire Layer Selection


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



  • 3.  RE: Layout zoom behavior vs Map window zoom

    Posted 22 days ago

    When running a MapBasic script that inserts a Map into a Layout using Layout Designer, I receive the following error:

    ERROR: (tematicos.mb:80) Error: expecting a Map window.

    The error occurs when executing a Set Map Window command after creating a map frame inside the Layout.
    It seems that the active window at that moment is not recognized as a Map window, even though the frame was created using From Window <mapID>.



    ------------------------------
    Mayca González Pérez
    COMUNIDAD. AUT. REG MURCIA
    ------------------------------



  • 4.  RE: Layout zoom behavior vs Map window zoom

    Employee
    Posted 22 days ago

    Hey

    Can you share your code or just that part of your code where you create your layout and insert the map window?

    Did you get the ID of the new Map in the frame?

    Above, I used this statement to get to the ID of the most recently created map window:

    nMapIDInLayout = WindowID(0)

    Peter



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



  • 5.  RE: Layout zoom behavior vs Map window zoom

    Posted 22 days ago
    Edited by Peter Møller 21 days ago
    Dim nMapID, nMapIDInLayout, nLayoutID, nLegendID, i As Integer
    
    '**Let's find a map window to insert
    For i = 1 To NumWindows()
      If WindowInfo(WindowID(i), WIN_INFO_TYPE) = WIN_MAPPER Then
        nMapID = WindowID(i)
        Exit For
      End If
    Next
    Print "Map: " & WindowInfo(nMapID, WIN_INFO_NAME)
    
    'Create Layout window
    Layout Designer
      Position (0.0,0.0) Units "in"
      Width 8 Height 8 Units "in"
    nLayoutID = WindowID(0)
    nLayoutID = FrontWindow()
    Set Layout
      Window nLayoutID
      Extents To Fit Zoom 100
    
    Set CoordSys Layout Units "in"
    Set Paper Units "In"
    
    'Insert Map into Layout
    Create Frame Into Window nLayoutID (0.5,1.0) (6.5,7.0)
      Pen (1,2,0) Brush (2, 16777215, 16777215)
      From Window nMapID
      FillFrame On
    
    nMapIDInLayout = WindowID(0)
    nMapIDInLayout = FrontWindow()
    
    Set Map Window nMapIDInLayout Zoom Entire Layer Selection
    
    If WindowInfo(nMapIDInLayout, WIN_INFO_TYPE) <> WIN_MAPPER Then
        Note "La ventana activa no es un mapa"
        Exit Sub
    End If



    ------------------------------
    Mayca González Pérez
    COMUNIDAD. AUT. REG MURCIA
    ------------------------------



  • 6.  RE: Layout zoom behavior vs Map window zoom

    Employee
    Posted 21 days ago

    Ah, the problem lies in this lne:

    nMapIDInLayout = FrontWindow()

    The map window is not the current active window, so don't use this to get to the ID of the map, but the ID of the layout window. The ID of the map has already been read with the previous line:

    nMapIDInLayout = WindowID(0)

    This line is also obsolete, as it's just another way to do what was done in the line before:

    nLayoutID = FrontWindow()



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



  • 7.  RE: Layout zoom behavior vs Map window zoom

    Posted 21 days ago

    I get the following error when running the script:
    ERROR: (tematicos.mb:80) Invalid view layer.  



    ------------------------------
    Mayca González Pérez
    COMUNIDAD. AUT. REG MURCIA
    ------------------------------



  • 8.  RE: Layout zoom behavior vs Map window zoom

    Employee
    Posted 21 days ago

    Make sure you have referenced a layer in your map in the Set Map statement.

    As an example, I just used the layer Selection, which won't work unless it's an actual layer.

    Sorry for not being clear on this



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



  • 9.  RE: Layout zoom behavior vs Map window zoom

    Posted 21 days ago

    There is no active selection. I'm not trying to zoom to a layer.
    I only need the layout (map frame) to refresh/redraw when the map window zoom changes.



    ------------------------------
    Mayca González Pérez
    COMUNIDAD. AUT. REG MURCIA
    ------------------------------



  • 10.  RE: Layout zoom behavior vs Map window zoom

    Employee
    Posted 19 days ago

    I'm not sure if you are trying to zoom the map in the layout via the original map?

    If you are, that won't work anymore. You need to use the Set Map statement on the map that is embedded in the frame in the layout.

    In the code above, it is the map referred to with this variable: 

    nMapIDInLayout


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