MapInfo Pro Developers User Group

 View Only
  • 1.  How RBNMapMTBAddControl works MAPBASIC

    Posted 02-20-2024 03:30

    Hi.

     I want to customize the mini map toolbar with Mapbasic.

    Can you show me an example?

     I have seen there that there is a RBNMapMTBAddControl function but I don't know how to use it.

    Thanks



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


  • 2.  RE: How RBNMapMTBAddControl works MAPBASIC

    Employee
    Posted 02-22-2024 04:03

    Hi

    I have used this to add two buttons to the Map Mini Toolbar that didn't exist back in pre-version 17.0:

    'First add a stackpanel to the Map Mini Toolbar
    nCtrlIdx = RBNMapMTBInsertStackPanelAfter("stpWindowHelper", "Info", "MapTools2")
    If nCtrlIdx > 0 Then
    	Call RBNControlSetLeftMarginIdx(nCtrlIdx, 0)
    
    	'Then add the controls that stackpanel - first control
    	nCtrlIdx	= RBNMapMTBStackPanelAddControl("stptbtInfoTool", "", "", ControlType_ToolButton, "stpWindowHelper")
    	If nCtrlIdx > 0 Then
    		Call RBNControlSetToolTipIdx(nCtrlIdx, PRGIGetApplicationName(), GetResItemStr("STR_TTIP_INFO_TOOL"), "")
    		Call RBNControlSetIconsIdx(nCtrlIdx, CONTROL_SIZE_SMALL, MI_IMG_MAP_INFOTOOL_16, "")
    		Call RBNControlSetCmdIDIdx(nCtrlIdx, 1707)
    	End If
    
    	'Then add the controls to that stackpanel - second control
    	nCtrlIdx	= RBNMapMTBStackPanelAddControl("stptbtRuler", "", "", ControlType_ToolButton, "stpWindowHelper")
    	If nCtrlIdx > 0 Then
    		Call RBNControlSetToolTipIdx(nCtrlIdx, PRGIGetApplicationName(), GetResItemStr("STR_TTIP_RULER_TOOL"), "")
    		Call RBNControlSetIconsIdx(nCtrlIdx, CONTROL_SIZE_SMALL, MI_IMG_WIN_RULER_16, "")
    		Call RBNControlSetCmdIDIdx(nCtrlIdx, 1710)
    	End If
    End If

    I hope this helps



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



  • 3.  RE: How RBNMapMTBAddControl works MAPBASIC

    Posted 02-26-2024 08:52
    Edited by Peter Møller 02-27-2024 02:21

    Ok I'll do tests

    Another question.

    I have this button that I want to insert a point into the map and launch the POINT function after drawing the point. How do I do it? The thing is that with this code the function is launched before the point is drawn

    btnPunto = MICtrlCollAddStrStrInt(EielControlCol2, "Visualizar", "Ver", 1)
    Call SetRbnBtnCtrlCmdID(btnPunto, M_TOOLS_POINT)
    Call SetRbnBtnCtrlCallingHandler(btnPunto, "Punto")
    Call SetRbnBtnCtrlSmallIcon(btnPunto, New_Uri("pack://application:,,,/MapInfo.StyleResources;component/Images/Layout/symbol_32x32.png", 0))
    
    Sub Punto
    OnError GoTo etiquetaError
            If WindowInfo(FrontWindow(),WIN_INFO_TYPE)<>WIN_MAPPER Then
                    Note "Esta herramienta solo puede ser utilizada en una ventana de mapa."
                    Exit Sub
            End if
            Dim intLayer as Integer
            intLayer=MapperInfo(FrontWindow(),MAPPER_INFO_EDIT_LAYER)
            If intLayer=-1 then
                    Note "Esta herramienta solo puede ser utilizada sobre una capa editable."
                    Exit sub
            End If
            Dim strLayer as String
            strLayer=LayerInfo(FrontWindow(),intLayer,LAYER_INFO_NAME)
            print "dddd"+CommandInfo(CMD_INFO_X)
            If gblDUPLICAR=True Then
                    Dim objCustom As Object
                    Create Point Into Variable objCustom (CommandInfo(CMD_INFO_X),CommandInfo(CMD_INFO_Y))
                   
                    Call Duplicate(strLayer)
                    Call Replicate(strLayer,objCustom)
                    Close Table OBJAUX
                    Run Menu Command ID 10
            Else
                    Call Mostrar
                    Run Menu Command M_TOOLS_SELECTOR
            End If
    Exit Sub
    etiquetaError:
        Note "ERROR : " +  Chr$(13) & Chr$(10) + Error$()
    End Sub


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



  • 4.  RE: How RBNMapMTBAddControl works MAPBASIC

    Employee
    Posted 02-27-2024 02:46

    Hi

    Yeah, you'll need to create a custom tool to achieve this.

    This requires 2 changes to your code above.

    1. You'll have to specify the button to be a ToolButton and set a DrawMode for it too. Note that I have switched to other methods (SetRbnToolBtn...) now that I'm creating a ToolButton and not a PushButton.

    btnPunto = MICtrlCollAddStrStrInt(EielControlCol2, "Visualizar", "Ver", ControlType_ToolButton) 'ControlTypes are defined in Enums.def
    Call SetRbnToolBtnCtrlDrawMode(btnPunto, DM_CUSTOM_POINT) 'DrawModes are define din Icons.def
    Call SetRbnToolBtnCtrlCallingHandler(btnPunto, "Punto")
    Call SetRbnToolBtnCtrlSmallIcon(btnPunto, New_Uri("pack://application:,,,/MapInfo.StyleResources;component/Images/Layout/symbol_32x32.png", 0))

    2. You'll have to get the coordinate and create the point yourself in the procedure called by the tool.

    Sub Punto
    Dim fX, fY As Float
    OnError GoTo etiquetaError
       If WindowInfo(FrontWindow(),WIN_INFO_TYPE)<>WIN_MAPPER Then
          Note "Esta herramienta solo puede ser utilizada en una ventana de mapa."
          Exit Sub
       End if
    
       '**Let's set the coordsys to match the map 
       '**and then grab the coordinates where the user clicked
       Set CoordSys Window FrontWindow()
       fX = CommandInfo(CMD_INFO_X)
       fY = CommandInfo(CMD_INFO_Y)
    
       Dim intLayer as Integer
       intLayer=MapperInfo(FrontWindow(),MAPPER_INFO_EDIT_LAYER)
       If intLayer=-1 then
          Note "Esta herramienta solo puede ser utilizada sobre una capa editable."
          Exit sub
       End If
       Dim strLayer as String
       strLayer=LayerInfo(FrontWindow(),intLayer,LAYER_INFO_NAME)
       print "dddd"+fX
       If gblDUPLICAR=True Then
          Dim objCustom As Object
          Create Point Into Variable objCustom (fX,fY)
                   
          Call Duplicate(strLayer)
          Call Replicate(strLayer,objCustom)
          Close Table OBJAUX
          Run Menu Command ID 10
       Else
          Call Mostrar
          Run Menu Command M_TOOLS_SELECTOR
       End If
       Exit Sub
    etiquetaError:
       Note "ERROR : " +  Chr$(13) & Chr$(10) + Error$()
    End Sub

    I didn't change much here. I set the coordsys and store the coordinates where the user clicked into two variables.



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



  • 5.  RE: How RBNMapMTBAddControl works MAPBASIC

    Posted 02-27-2024 03:18
    Edited by Mayca González Pérez 02-27-2024 03:19

    Perfect, now it works.

    Is there a manual that indicates all the functions that can be defined in mapinfo?

    For example DM_CUSTOM_POINT draws a point, now I want to know the function to draw a rectangle or move function....?

    And for the icons ?

    Thanks



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



  • 6.  RE: How RBNMapMTBAddControl works MAPBASIC

    Employee
    Posted 02-28-2024 02:50

    Hi

    Icons.def holds the various DrawModes:

    define DM_CUSTOM_CIRCLE     30
    define DM_CUSTOM_ELLIPSE    31
    define DM_CUSTOM_RECT       32
    define DM_CUSTOM_LINE       33
    define DM_CUSTOM_POINT      34
    define DM_CUSTOM_POLYGON    35
    define DM_CUSTOM_POLYLINE   36

    Most of them return coordinates that you access via CommandInfo. DM_CUSTOM_POLYGON and DM_CUSTOM_POLYLINE return spatial objects which you also access through CommandInfo

    You can also assign different cursors to your tools if you want. They are also defined in Icons.def. These are just some of them:

    define MI_CURSOR_ARROW           0
    define MI_CURSOR_IBEAM           1
    define MI_CURSOR_CROSS           2
    define MI_CURSOR_PLUS            3
    define MI_CURSOR_WAIT            4
    define MI_CURSOR_FINGER_LEFT     128
    define MI_CURSOR_ZOOM_IN         129
    define MI_CURSOR_ZOOM_OUT        130
    define MI_CURSOR_DRAG_OBJ        131
    define MI_CURSOR_GRABBER         132
    define MI_CURSOR_CHANGE_WIDTH    133
    define MI_CURSOR_FINGER_UP       134
    define MI_CURSOR_IBEAM_CROSS     135
    define MI_CURSOR_HELP            137
    define MI_CURSOR_CROSSHAIR       138
    define MI_CURSOR_NODROP          139
    define MI_CURSOR_DRAG_LAYER      140
    define MI_CURSOR_DRAG_LAYERS     141
    define MI_CURSOR_BEGIN_DRAGNDROP 142
    define MI_CURSOR_DOING_DRAGNDROP 143
    define MI_CURSOR_DRAGNDROP_COPY  144
    define MI_CURSOR_DRAGNDROP_LINK  145
    define MI_CURSOR_DRAGNDROP_MOVE  146
    define MI_CURSOR_DRAGNDROP_NONE  147
    define MI_CURSOR_MOUSESCROLL_N   148
    define MI_CURSOR_MOUSESCROLL_NE  149
    define MI_CURSOR_MOUSESCROLL_E   150
    define MI_CURSOR_MOUSESCROLL_SE  151
    define MI_CURSOR_MOUSESCROLL_S   152
    define MI_CURSOR_MOUSESCROLL_SW  153
    define MI_CURSOR_MOUSESCROLL_W   154
    define MI_CURSOR_MOUSESCROLL_NW  155
    define MI_CURSOR_MOUSESCROLL_CTR 156
    define MI_CURSOR_SIZE_NESW       157
    define MI_CURSOR_SIZE_NS         158
    define MI_CURSOR_SIZE_NWSE       159 
    define MI_CURSOR_SIZE_WE         160
    define MI_CURSOR_MOVE            161
    define MI_CURSOR_ACT_HAND        162
    define MI_CURSOR_ACT_HAND2       163
    define MI_CURSOR_LRG_CROSSHAIR   164
    define MI_CURSOR_TINY_CROSSHAIR  165
    define MI_CURSOR_ADORNMENT       166
    define MI_CURSOR_ADORNMENT_MOVE  167

    Similarly, all the icons that you see in MapInfo Pro can be used in your tool. They are defined in RibbonControls.def. Again, this is just a small portion:

    Define MI_IMG_APP_CLOSEALL_16                         "pack://application:,,,/MapInfo.StyleResources;component/Images/Application/closeAll_16x16.png"
    Define MI_IMG_APP_CLOSEALL_32                         "pack://application:,,,/MapInfo.StyleResources;component/Images/Application/closeAll_32x32.png"
    Define MI_IMG_APP_CLOSEDBMS_16                        "pack://application:,,,/MapInfo.StyleResources;component/Images/Application/closeDbms_16x16.png"
    Define MI_IMG_APP_CLOSEDBMS_32                        "pack://application:,,,/MapInfo.StyleResources;component/Images/Application/closeDbms_32x32.png"
    Define MI_IMG_APP_IMPORT_16                           "pack://application:,,,/MapInfo.StyleResources;component/Images/Application/import_16x16.png"
    Define MI_IMG_APP_IMPORT_32                           "pack://application:,,,/MapInfo.StyleResources;component/Images/Application/import_32x32.png"
    Define MI_IMG_APP_OPENDBMS_16                         "pack://application:,,,/MapInfo.StyleResources;component/Images/Application/openDbms_16x16.png"
    Define MI_IMG_APP_OPENDBMS_32                         "pack://application:,,,/MapInfo.StyleResources;component/Images/Application/openDbms_32x32.png"
    Define MI_IMG_APP_OPENUNIVERSAL_16                    "pack://application:,,,/MapInfo.StyleResources;component/Images/Application/openUniversal_16x16.png"
    Define MI_IMG_APP_OPENUNIVERSAL_32                    "pack://application:,,,/MapInfo.StyleResources;component/Images/Application/openUniversal_32x32.png"
    Define MI_IMG_APP_OPENWFS_16                          "pack://application:,,,/MapInfo.StyleResources;component/Images/Application/openWfs_16x16.png"
    Define MI_IMG_APP_OPENWFS_32                          "pack://application:,,,/MapInfo.StyleResources;component/Images/Application/openWfs_32x32.png"
    Define MI_IMG_APP_OPENWMS_16                          "pack://application:,,,/MapInfo.StyleResources;component/Images/Application/openWms_16x16.png"
    Define MI_IMG_APP_OPENWMS_32                          "pack://application:,,,/MapInfo.StyleResources;component/Images/Application/openWms_32x32.png"



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



  • 7.  RE: How RBNMapMTBAddControl works MAPBASIC

    Posted 02-28-2024 07:42

    Ok. Thanks



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