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:

Program started.
main.initializeProcessGlobals (java line: 512)
java.lang.RuntimeException: java.lang.RuntimeException: Object should first be initialized (Node).
at b4j.example.main.initializeProcessGlobals(main.java:512)
at b4j.example.main.start(main.java:32)
at com.sun.javafx.application.LauncherImpl$5.run(LauncherImpl.java:319)
at com.sun.javafx.application.PlatformImpl$5.run(PlatformImpl.java:219)
at com.sun.javafx.application.PlatformImpl$4$1.run(PlatformImpl.java:182)
at com.sun.javafx.application.PlatformImpl$4$1.run(PlatformImpl.java:179)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl$4.run(PlatformImpl.java:179)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:76)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.access$100(WinApplication.java:17)
at com.sun.glass.ui.win.WinApplication$3$1.run(WinApplication.java:67)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.RuntimeException: Object should first be initialized (Node).
at anywheresoftware.b4a.AbsObjectWrapper.getObject(AbsObjectWrapper.java:28)
at b4j.example.main._process_globals(main.java:592)
at b4j.example.main.initializeProcessGlobals(main.java:509)
... 12 more

+++
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
Top