B4J Question [BANano] How to use Leaflet Plugin in B4j Project (Sovled)

NGUYEN TUAN ANH

Active Member
Licensed User
I see a lot of useful Plugins added to Leaflet, But B4J users seem to only be able to use the basic Leaflet functions that are wrapped, but cannot use the extended functions like the others. . I don't know how to include Plugins (*.js) in B4J, resulting in very limited application compared to other applications, Could you please help me. !
Thank you very much
 

alwaysbusy

Expert
Licensed User
Longtime User
I have no idea why it takes so long to add it to the BDAV3 library. In pure BANano it literally takes about 2 seconds to add the rotation plugin to the BANanoLeaflet library (note: this will not work with BDAV3, it is just to demonstrate it is not a BANano nor a B4J problem):

B4X:
BANano.Header.AddJavascriptFile("https://unpkg.com/[email protected]/leaflet.rotatedMarker.js")

B4X:
' Sets the rotation origin
public Sub SetRotationOrigin(rotationOrigin As Float)
    MarkerObject.GetField("options").SetField("rotationOrigin", rotationOrigin) 
End Sub

' Sets the roation angle
public Sub SetRotationAngle(rotationAngle As Float)
    MarkerObject.GetField("options").SetField("rotationAngle", rotationAngle)
End Sub

Usage:
B4X:
Sub Process_Globals 
    Private BANano As BANano 'ignore 
    Dim LeafletMap As BANanoLeafletMap 
End Sub

Sub Init() 
    BANano.GetElement("#DemoContainer").Empty 
    BANano.GetElement("#DemoContainer").Append("<h1>RotatedMarker - Demo</h1>")
    LeafletMap.Initialize("#DemoContainer") 
    LeafletMap.SetStyle($"{ "width": "800px", "height": "600px" }"$)
 
    ' add a TileLayer...
    Dim TileLayer As BANanoLeafletTileLayer
    TileLayer.Initialize
    LeafletMap.AddTileLayer(TileLayer)
    LeafletMap.PanTo(48.856613, 2.352222)
    LeafletMap.SetZoom(5)

    ' Add a marker
    Dim myMarker As BANanoLeafletMarker
    myMarker.Initialize2( 48.856613, 2.352222 )
    myMarker.SetDraggable(True)
    myMarker.SetAutoPan(True)
    myMarker.SetTooltip("I'm a Tooltip")
    myMarker.SetPopup("I'm a Popup")
    myMarker.SetRotationAngle(45) '<-------------
    LeafletMap.AddMarker(myMarker)
End Sub

leafletdemo.jpg
 

Attachments

  • BANanoLeafletLibrary.zip
    7.8 KB · Views: 67
  • BANanoLeafletDemo.zip
    8.6 KB · Views: 64
Last edited:
Upvote 0
Top