B4J Question Add rectangles to Map - use them as limits...

Magma

Expert
Licensed User
Longtime User
Hi there again..

i have some questions as a new starter to b4j (by the way) seems more powerful than any language i ve used (.net, vb6, c++) ofcourse with the help of all these libraries created by online community...

I am using a map (mapquest offline tiles)..

I want the feature user draw rectangles at lat lon (X1,Y1) - (X2, Y2) and the program used them as limits for specific reasons...

But because i am starter i am falling to walls...

B4X:
Sub Process_Globals
' here i am using a rectangle created by Designer:
    Private rect1 As Node
    Dim rlat As Double,rlon As Double,clat As Double,clon As Double
    Dim isdrawon As Boolean
end sub

....

Sub MapPane1_Mouseclicked (EventData As MouseEvent)
    If isdrawon=True Then
        rect1.Left=EventData.X 'seems good here..
        rect1.Top=EventData.y
        rect1.width = 1
        rect1.height = 1
        rect1.Visible = True
    End If
End Sub

Sub MapPane1_MousePressed (EventData As MouseEvent)
    If isdrawon=True Then
        'seems no with, height... :-( am i wrong and what to do ?
        rect1.width = EventData.x - rect1.Left
        rect1.height = EventData.Y - rect1.top
    End If
' here must convert x,y of screen to lat/lon...
rlat = convertsomehow(rect1.left)
rlon = = convertsomehow(rect1.top) 
.....clat,clon......
End Sub

The rectangle used as node... how change it's layout settings ???

Is there a Mappane tip will help me or other way to create map rectangles ?
 

Magma

Expert
Licensed User
Longtime User
Upvote 0

Magma

Expert
Licensed User
Longtime User
@Erel

Hi am getting this:


+++
and how i can combine it with mappane ?

convert it's .left, .top, width, height -> to lat / lon on map ? any idea ?
 
Last edited:
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
You are doing something wrong in Process_Globals. It should only be used to declare variables.

to lat / lon on map ? any idea ?
It depends on the information you have. It might be easier to work in UTM instead of Lat/Lon. You can use the Geodesic class to convert the coordinates between UTM and Lat/Lon.
 
Upvote 0

Magma

Expert
Licensed User
Longtime User
You are doing something wrong in Process_Globals. It should only be used to declare variables.

you were right... but now i am understanding that no.. checking the events of mappane... :-(

B4X:
Sub MapPane1_Mouseclicked (EventData As MouseEvent)
    If isdrawon=True Then
        rect1.Left=EventData.X
        rect1.Top=EventData.y
        rect1.Visible = True
        Log("draw")
    End If
End Sub

Sub MapPane1_MousePressed (EventData As MouseEvent)
    Dim jo As JavaObject = rect1
    Dim width As Double, height As Double
    If isdrawon=True Then
        width = EventData.x - rect1.Left
        height = EventData.Y - rect1.top
        jo.RunMethod("setWidth", Array(width))
        jo.RunMethod("setHeight", Array(height))
        'rect1.width = EventData.x - rect1.Left
        'rect1.height = EventData.Y - rect1.top
    End If
End Sub


never get draw at my logs :-(
and yes isdrawon=true


It depends on the information you have. It might be easier to work in UTM instead of Lat/Lon. You can use the Geodesic class to convert the coordinates between UTM and Lat/Lon.

i want to convert are of pixels of rectangle to lat/lon rectangle area can i have an example or something ?
(neeed to know the upper mappane where starts lat/lon)
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…