B4A Library [B4X] [B4A] [B4J] [b4xlib] LeafletView

Screenshot 2026-03-14 173909.png
demoapk.png

LeafletView is a cross-platform wrapper for Leaflet.js, providing a lightweight alternative to Google Maps. It uses OpenStreetMap by default, meaning no API keys are required for basic mapping.

This version is distributed as a .b4xlib, making it easy to include in any B4A or B4J project.

Key Features:​

  • Zero Configuration: No Google Play Services or API keys required.
  • Road Routing: Calculate and draw routes with distance and ETA data via Leaflet Routing Machine.
  • B4X Unified: Identical API for B4A and B4J.
  • Interactive: Built-in events for map interaction, marker clicks, and routing results.
  • Fully Customizable: Toggle zoom controls, attributions, and persistent distance labels via the Designer.

Events:​

  • MarkerClick (Data As Map) - Returns ID and ExtraData.
  • MarkerPopupClick (Data As Map) - Triggered when the popup action is clicked.
  • MapClick (Data As Map) - Returns Lat/Lon of the clicked point.
  • ZoomChanged (Data As Map) - Returns current zoom and center.
  • RoutingFound (Data As Map) - Returns distance (km) and car_eta.
  • RouteClick (Data As Map) - Triggered when tapping the route line.

How to install:​

  1. Download the attached LeafletView.b4xlib and place it in your Additional Libraries folder.
  2. In the B4X IDE, refresh the Libraries tab and check LeafletView.
  3. Add a CustomView in the Abstract Designer and set its Custom Class to LeafletView.
  4. Ensure your project has the JavaObject and JSON libraries selected.

Included in the Download:​

  • LeafletView.b4xlib: The compiled library.
  • Example Project: A demo showing markers, routing, and event handling.
Credits: - Leaflet.js
 

Attachments

  • Example_AC_LeafletView.zip
    20 KB · Views: 184
  • AC_LeafletViewv1.2.b4xlib
    4.1 KB · Views: 88
Last edited:

Abdull Cadre

Active Member
Licensed User
Longtime User

LeafletView v1.2​

New Event: Map_Ready​

Added a new event that fires when the map has finished loading and is ready for interaction.

B4X:
Private Sub AC_LeafletView1_MAP_READY (Data As Map)
    Log("MAP_READY")
End Sub
 

Attachments

  • AC_LeafletViewv1.2.b4xlib
    4.1 KB · Views: 90

Sergey_New

Well-Known Member
Licensed User
Longtime User
Please tell me how to set the "Click for details" text in a multilingual application to match the current language.
 

Abdull Cadre

Active Member
Licensed User
Longtime User
Please tell me how to set the "Click for details" text in a multilingual application to match the current language.
EDIT: 2026.08.17 Version 1.3
Added multilingual support via Designer Properties:
- MarkerPopupText: Customizable text for marker popup details
- RoutePopupTitle: Customizable title for route popup
1786972313821.png
 

Attachments

  • AC_LeafletView1.3.b4xlib
    4.2 KB · Views: 2

Sergey_New

Well-Known Member
Licensed User
Longtime User
EDIT: 2026.08.17 Version 1.3
Thanks for the new version! Unfortunately, it doesn't work at runtime. Maybe I'm doing it wrong? Please take a look.
B4X:
Sub Globals
    Private AC_LeafletView1 As AC_LeafletView
    Private extra1 As Map
    Private titl As String
    Private Lat,Lon As Double
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("Layout")
End Sub

Private Sub AC_LeafletView1_MAP_READY (Data As Map)
    AC_LeafletView1.MarkerPopupText="Показать детали"
    AC_LeafletView1.AddMarker("M1", 56.142776, 40.400002, titl, extra1)
    AC_LeafletView1.SetPosition(56.142776, 40.400002, True)
'    AC_LeafletView1.AddMarker("M1", Lat, Lon, titl, extra1)
'    AC_LeafletView1.SetPosition(Lat, Lon, True)
    AC_LeafletView1.SetZoom(10)
End Sub

Sub ShowMap(coordinates() As Double, name As String)
    Lat=coordinates(0)    '56.142776
    Lon=coordinates(1)    '40.00002
    titl=name            'Владимир
    extra1 = CreateMap("db_id": 101, "status": "Active", "note": "High police presence", "time": DateTime.Time(DateTime.Now))
End Sub
The map activity is called from the main activity using this code:
B4X:
Private Sub Button1_Click
    Dim coordinates(2) As Double
    coordinates(0)=56.142776
    coordinates(1)=40.00002
    CallSubDelayed3(OSMap,"ShowMap",coordinates,"Владимир")
End Sub
 
Top