MapInfo Pro

 View Only
  • 1.  Set Shade not working

    Posted 08-12-2024 12:21

    Struggling to understand what I'm doing wrong here. I have a program which you can launch to make company standard adjustments to a thematic layer in a layout. The layout, created with another program, contains one map frame with the name "Main Map". The map contains a layer of lines with a theme based on the SCORE field. Here is a simplistic view of the code without extraneous sub routines:

    Dim LayoutID as Integer

    Dim MapLayoutID as Integer

    LayoutID = FrontWindow()

    MapLayoutID = LayoutItemWinID(LayoutID, "Main Map", LAYOUT_ITEM_TYPE_MAPPER)

    Dim LinesID as integer

    fnd = false

    For LinesID = 1 to mapperinfo(MapLayoutID, MAPPER_INFO_LAYERS)

    if layerinfo(MapLayoutID, LinesID, LAYER_INFO_NAME) = HeatLayer then

    LinesID = LinesID - 1

    Print "Lines theme is map layer "+ LinesID

    fnd = true

    exit for

    end if

    next

    if not fnd then

    Note "cannot find lines theme layer" End Program

    end if

    set shade window MapLayoutID LinesID with SCORE ranges

    …etc

    MapInfo finds the layout (so MapLayoutID is correct), map frame and lines theme layer just fine. The print command returns layer 3, and the lines theme layer is indeed layer 3. But the set shade command errors out with an "invalid view layer".

    What exactly is going wrong here? Thanks for your help.

    (Note, that LinesID = LinesID-1 because the theme layer will always be the one prior to the layer being themed).



    ------------------------------
    Ryan Cook
    ORH LTD
    ------------------------------


  • 2.  RE: Set Shade not working

    Employee
    Posted 08-13-2024 02:01

    Hi Ryan

    I can't put my finger on why your code fails. The error you get is meant to tell you that you can't use a theme on that layer. I got the same error when my layer referred to 0.

    I create a small sample code to reproduce your case but it doesn't fail for me.

    The code is only for testing the Set Shade but it can also create a new theme to prepare the map for testing. In the first run, you pick Shade when asked and now you can pick Set Shade when you run it again. The code just changes the theme to use the column LATITUDE instead of LONGITUDE.

    Include "MapBasic.def"
    Include "Defines.def"
    
    Declare Sub Main
    
    Sub Main
    
    Dim	nMID, nLayoutID, nLayerID As Integer,
    	sTab, sCol As String,
    	bFnd, bShade As Logical,
    	arrRanges() As Float,
    	arrSymbols() As Symbol
    
    	sTab			= "Bank_Branches"
    	nLayoutID		= FrontWindow()
    	nMapLayoutID	= LayoutItemWinID(nLayoutID, "Main Map", LAYOUT_ITEM_TYPE_MAPPER)
    
    	bShade = Ask("Shade or Set Shade?", "Shade", "Set Shade")
    
    	If bShade Then
    		Create Ranges
    			From sTab
    			With LONGITUDE
    			Use "Natural Break"
    			Number 5
    			Into Variable arrRanges
    	Else
    		Create Ranges
    			From sTab
    			With LATITUDE
    			Use "Natural Break"
    			Number 5
    			Into Variable arrRanges
    	End If
    
    	Create Styles
    		From Symbol MakeFontSymbol(57,RED,10,"MapInfo Symbols",0,0) 'style for LOW range,
    		To Symbol MakeFontSymbol(57,BLUE,10,"MapInfo Symbols",0,0) 'style for HIGH range
    		Vary Color By "RGB"
    		Number 5
    		Into Variable arrSymbols
    
    	bFnd	= FALSE
    	For nLayerID = 1 To MapperInfo(nMapLayoutID, MAPPER_INFO_LAYERS)
    		If LayerInfo(nMapLayoutID, nLayerID, LAYER_INFO_NAME) = sTab Then
    			bFnd = TRUE
    			Exit For
    		End If
    	Next
    
    	If Not bFnd Then
    		Note "Layer '" & sTab & "' not found!"
    		Exit Sub
    	End If
    
    	If bShade Then
    		Shade Window nMapLayoutID
    			nLayerID
    			with LONGITUDE
    			Ranges From Variable arrRanges
    			Style Variable arrSymbols
    	Else
    		nLayerID = nLayerID - 1
    		Set Shade Window nMapLayoutID
    			nLayerID
    			with LATITUDE
    			Ranges From Variable arrRanges
    			Style Variable arrSymbols
    	End If
    
    End Sub

    Here is my sample map in my layout after I created the initial theme with the Shade statement.

    And here is the map after I modified the theme with the Set Shade statement.
    Can you try to see if you can make my code work with your layout, map, and layer too?


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



  • 3.  RE: Set Shade not working
    Best Answer

    Posted 08-13-2024 06:23

    Thanks Peter. You code made me scrutinize mine more closely and I noticed that nLayerID was actually being dim'ed in a different sub. Sadly rather than return a "variable not defined" error, the shade command was returning the invalid view layer error (because I was asking MapInfo to change the shade of a layer I was referencing wrongly). 

    Got there in the end! Thanks for your help though (as always)



    ------------------------------
    Ryan Cook
    ORH LTD
    ------------------------------