B4J Question [ABMaterial] Need to put some text on ABMGoogleMap Markers

Discussion in 'B4J Questions' started by vfafou, Jun 5, 2018.

  1. vfafou

    vfafou Active Member Licensed User

    Hello!

    I've just started to develop my first ABMaterial web app.
    I'm using ABMGoogleMap to show some markers on it.
    The marker images are customised PNGs.
    Before showing these markers, I need to draw some dynamic text on them, like canvas.Drawtext in B4A.

    Is there any way to do that with ABMaterial?

    Thank you in advance!
     
    Last edited: Jun 5, 2018
  2. vfafou

    vfafou Active Member Licensed User

    It seems that may it's difficult, because I have to provide a URL for the PNGs, so it isn't possible to draw a dynamic pin on the map!
     
  3. alwaysbusy

    alwaysbusy Expert Licensed User

    have you tried creating the image at run time and saving it in the www images folder and then using the url to that file? (best give it a name with a random number so the cache doesn't take over)
     
  4. vfafou

    vfafou Active Member Licensed User

    Hi Alain!
    Thank you for your response!
    I thought that it's may the only way to do that, but I can't figure out how could I draw text on a given image!
     
  5. alwaysbusy

    alwaysbusy Expert Licensed User

  6. vfafou

    vfafou Active Member Licensed User

    Trying to save the PNG to output stream, I take the following error:
    Code:
    java.lang.IllegalStateException: Not on FX application thread; currentThread = main
        at javafx.graphics/com.sun.javafx.tk.Toolkit.checkFxUserThread(Toolkit.java:
    291)
        at javafx.graphics/com.sun.javafx.tk.quantum.QuantumToolkit.checkFxUserThread(QuantumToolkit.java:
    423)
        at javafx.graphics/javafx.scene.Node.snapshot(
    Node.java:2191)
        at anywheresoftware.b4j.objects.NodeWrapper.Snapshot2(NodeWrapper.java:
    353)
        at anywheresoftware.b4j.objects.B4XCanvas.CreateBitmap(B4XCanvas.java:
    86)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:
    62)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:
    43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:
    564)
        at anywheresoftware.b4a.shell.Shell.runMethod(
    Shell.java:625)
        at anywheresoftware.b4a.shell.Shell.raiseEventImpl(
    Shell.java:234)
        at anywheresoftware.b4a.shell.Shell.raiseEvent(
    Shell.java:168)
        at jdk.internal.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:
    43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:
    564)
        at anywheresoftware.b4a.BA.raiseEvent2(BA.java:
    90)
        at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:
    94)
        at anywheresoftware.b4a.debug.Debug.delegate(Debug.java:
    61)
        at com.vf.rmweb.rmgooglemap._makefleetpos(rmgooglemap.java:
    708)
        at com.vf.rmweb.rmgooglemap._fptimer_tick(rmgooglemap.java:
    699)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:
    62)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:
    43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:
    564)
        at anywheresoftware.b4a.shell.Shell.runMethod(
    Shell.java:625)
        at anywheresoftware.b4a.shell.Shell.raiseEventImpl(
    Shell.java:237)
        at anywheresoftware.b4a.shell.Shell.raiseEvent(
    Shell.java:168)
        at jdk.internal.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:
    43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:
    564)
        at anywheresoftware.b4a.BA.raiseEvent2(BA.java:
    90)
        at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:
    94)
        at anywheresoftware.b4a.objects.Timer$TickTack$
    1.run(Timer.java:118)
        at anywheresoftware.b4a.keywords.SimpleMessageLoop.runMessageLoop(SimpleMessageLoop.java:
    30)
        at anywheresoftware.b4a.StandardBA.startMessageLoop(StandardBA.java:
    26)
        at anywheresoftware.b4a.ShellBA.startMessageLoop(ShellBA.java:
    115)
        at anywheresoftware.b4a.keywords.Common.StartMessageLoop(Common.java:
    153)
        at anywheresoftware.b4a.shell.Shell.raiseEventImpl(
    Shell.java:308)
        at anywheresoftware.b4a.shell.Shell.raiseEvent(
    Shell.java:168)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:
    62)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:
    43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:
    564)
        at anywheresoftware.b4a.BA.raiseEvent2(BA.java:
    90)
        at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:
    94)
        at anywheresoftware.b4a.BA.raiseEvent(BA.java:
    77)
        at anywheresoftware.b4j.object.JServlet.createInstance(JServlet.java:
    65)
        at anywheresoftware.b4j.object.BackgroundWorkersManager$
    1.run(BackgroundWorkersManager.java:21)
        at anywheresoftware.b4a.keywords.SimpleMessageLoop.runMessageLoop(SimpleMessageLoop.java:
    30)
        at anywheresoftware.b4a.StandardBA.startMessageLoop(StandardBA.java:
    26)
        at anywheresoftware.b4a.ShellBA.startMessageLoop(ShellBA.java:
    115)
        at anywheresoftware.b4a.keywords.Common.StartMessageLoop(Common.java:
    153)
        at anywheresoftware.b4a.shell.Shell.raiseEventImpl(
    Shell.java:308)
        at anywheresoftware.b4a.shell.Shell.raiseEvent(
    Shell.java:168)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:
    62)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:
    43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:
    564)
        at anywheresoftware.b4a.BA.raiseEvent2(BA.java:
    90)
        at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:
    94)
        at anywheresoftware.b4a.BA.raiseEvent(BA.java:
    77)
        at com.vf.rmweb.main.main(main.java:
    29)
    The code used is:
    Code:
    Sub CreateBitmapWithText (text As String,bcol As Int,ubmp As String)
        
    Dim img As B4XBitmap = xui.LoadBitmap(File.DirApp & "\images", ubmp)
        
    Dim cvs As B4XCanvas = CreateCanvas(img.Width, img.Height)
        cvs.DrawBitmap(img, cvs.TargetRect)
        
    Dim offset As Int = 10
        cvs.DrawText(text, 
    0, cvs.TargetRect.Height / 2 + offset, xui.CreateDefaultBoldFont(40 / scale), bcol, "CENTER")
        cvs.Invalidate
        
    Dim out As OutputStream = File.OpenOutput(File.DirApp & "\images""fff1.png"False)
        cvs.CreateBitmap.WriteToStream(out,
    100,"PNG")
        out.Close
      
        cvs.Release
    End Sub


    Private Sub CreateCanvas(width As Int, height As Int) As B4XCanvas
        
    Dim p As B4XView = xui.CreatePanel("")
        p.SetLayoutAnimated(
    000, width, height)
        
    Dim cvs As B4XCanvas
        cvs.Initialize(p)
        
    Return cvs
    End Sub
    What is wrong?
     
    Last edited: Jun 6, 2018
  7. alwaysbusy

    alwaysbusy Expert Licensed User

    Ah, that's right! B4J non-ui apps cannot manipulate bitmaps :(
     
  8. vfafou

    vfafou Active Member Licensed User

    So, is it impossible??? :eek:
     
  9. alwaysbusy

    alwaysbusy Expert Licensed User

    Unfortunately, I think so. But you better ask this in the forum as a non-ABM question as the question should be 'How do I draw on a bitmap in a non-ui B4J application?'
     
  10. vfafou

    vfafou Active Member Licensed User

    OK, Alain!
    Thank you very much!
    Have a nice day!
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice