MapInfo Pro Developers User Group

Expand all | Collapse all

Display Line attribute after the click event

  • 1.  Display Line attribute after the click event

    Posted 10-02-2018 11:44

    dear Expert

    Please need help about  a procedure  i made it called via pushbutton (button_prompt ) which will display some column attribute after the user clic on line object.

    My procedure act only if the selection was done before , But actually I want the invers , thus the user will clic the pushbutton and after he can  go to any map and select any line he want.

    My  procedure output is simple as NOTE message containing the wanted information, is it any other solution to display it in better way as dialog or table like the function INFO of mapinfo .

    please find attached my whole code including this  procedure.

    Best regard.

     

     



  • 2.  RE: Display Line attribute after the click event

    Posted 10-02-2018 08:06

    Hi Mohamed

    Have a look at the InfoSelhandler tool on CommunityDownload: http://communitydownloads.pbinsight.com/code-exchange/download/infoselhandlerEnglish

    It comes with source code.

    The idea behind this tool is to show the information for a selected object as soon as the user select it. It is using an event in MapBasic that is called when a change happens to the selection.

    The downside of this compared to your requirements is that it will show all the information of the selected record in the Info window.



  • 3.  RE: Display Line attribute after the click event

    Posted 10-02-2018 12:38

    Dear Peter ;

    I run your it independently , now i can sen the togglebutton activating and desactivating on the menu but nothing is happening when I click on the map , I dont know maybe I missed some thing .

    Concerning my procedure do you have any idea how to make it reacting until i click on the line object instead of bugging if there no selection made it before.

    The idea is to make it as toolbuttion whith Cursor (Cross for exemple ) and display the information once the user cilck on line .

    Here bellow the whole code of procedure;

    sub button_prompt

    dim Q_table , ColValues()as string

    dim nNumCols, nCol As Integer

    Dim aCol As Alias

    if Str$(selection.Obj)<>"line" then

         note "please select line from Map to get link configuration"

        close table TableInfo(NumTables(),TAB_INFO_NAME)

         exit sub

    End If

    Q_table=SelectionInfo(SEL_INFO_SELNAME)

    nNumCols = TableInfo( Q_table, TAB_INFO_NCOLS)

     ReDim ColValues(nNumCols)

     Fetch First From Q_table

    Do Until EOT(Q_table)

    For nCol = 1 To nNumCols

    aCol = Q_table & ".COL" & nCol

    ColValues(nCol) =aCol

    next

    Fetch Next From Q_table

     Note ColValues(2)+" dir "+ColValues(3)+" < > CORE "+ColValues(5)+Chr$(10)+Chr$(10)+"Freq :" +ColValues(28)+"< >"+ ColValues(29)+Chr$(10)+Chr$(10)+"Radio :"+ColValues(32)+Chr$(10)+Chr$(10)+"Config :"+ColValues(14)+Chr$(10)+Chr$(10)+"Antennas :"+ColValues(24)+"m<>"+ColValues(25)+"m"+Chr$(10)+Chr$(10)+"RSL: "+ColValues(40)+" dBm < >TX: "+ColValues(35)+"dBm"+Chr$(10)+Chr$(10)+ "Availability: "+ColValues(42)+"% < > Margin: "+ColValues(41)+"dBm"

     

    Loop

    close table TableInfo(NumTables(),TAB_INFO_NAME)

     End Sub



  • 4.  RE: Display Line attribute after the click event

    Posted 10-03-2018 02:02

    As for the tool, the idea is that when you have enabled the InfoSelHandler tool, it will show the values of the selected record int he Info window. The Info window might only reflect the selected object after you have enabled it and then selected a record.



  • 5.  RE: Display Line attribute after the click event

    Posted 10-03-2018 02:13

    In regards to your tool, there is a few things you need to do:

    1. Make you button a toolbutton for it to react to you clicking in the map

    A toolbutton can also be given a drawmode, in your case DM_CUSTOM_POINT which makes the tool react to a single click, and a cursor, use MI_CURSOR_CROSS for a crosshair. Both these two defines can be found in the Menu.def file that you need to include in your code.

    2. Select records nearby your click

    Secondly, you need to find the records nearby the point where you clicked in the map.

    These requires that you initially get the coordinate of the point where you clicked:

    Dim fX, fY As Float

    '**Let's use the coordinate system of the active Map window

    Set CoordSys Window FrontWindow()

    fX = CommandInfo(CMD_INFO_X)

    fY = CommandInfo(CMD_INFO_Y)

    Now your variables fX and fY hold the coordinate where you clicked. Let's find the records nearby.

    Dim oBuffer As Object

    '**We are adding a search area around the point using a buffer

    '**If you data is projected, you can also use CartesianBuffer

    '**20 is the resolution of the buffer and 5 is the search distance

    oBuffer = Buffer((CreatePoint(fX, fY), 20, 5, "m")

    '**Let's select the records nearby - here I'm selecting from the table LINK

    Select * From LINK

    Where OBJ Intersects oBuffer

    Now you have you objects selected and you can continue with your code from the question above.



  • 6.  RE: Display Line attribute after the click event

    Posted 10-03-2018 05:24
      |   view attached

    Dear Peter and thanks again for your solution which I'll use it later on;

    In fact till now I'm focusing in line selection to display MW link config thus I've already made exit sub if obj is different than "line".

    The problem is when I click on toolbutton it gives error if there is no selection , I dont know it seem simple but i didn't get the solution yet.

     if there is line selected it works perfectly , I've attached snapshot for both cases maybe it can explain the idea.

    the solution that i'm looking is:

     when I click on the toolbutton I want to clear all the previous selection  and waiting next line selection to reacting after click on .

    Thanks sir and sorry for the poor english as I'm not native speaker

    Attached the error message in case no selection was done.



  • 7.  RE: Display Line attribute after the click event

    Posted 10-03-2018 09:57

    No worries, Mohamed, your English is very good.

    Okay, you need to check if there is a Selection before proceeding.

    Change the beginning of your code to this:

    If SelectionInfo(SEL_INFO_NROWS) = 0 Then

    Note "Please select a single line from the map before using this tool!"

    Exit Sub

    End If

    Fetch First From Selection

    if Str$(selection.Obj)<>"line" then

         note "please select line from Map to get link configuration"

        close table TableInfo(NumTables(),TAB_INFO_NAME)

         exit sub

    End If

    I have just added 5 lines of code.



  • 8.  RE: Display Line attribute after the click event

    Posted 10-03-2018 10:44

    Ok Sir it is better solution to avoid error message.

    ?I'm asking if we can inverse the ordre,  with your code if there are no line selected it will exit sub after Note warning.

    My idea is how to make things in the bellow order:

    1-select Toolbutton or any other suitable type of ButtonBad to be able of selecting

    2--Clearing all the previous selection

    3-Be able to select line on the map

    4-Displaying MW Link parameters as Note.

    My best regard.

     



  • 9.  RE: Display Line attribute after the click event

    Posted 10-04-2018 02:34

    That's the solution I proposed above with the toolbutton