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:
- Download the attached LeafletView.b4xlib and place it in your Additional Libraries folder.
- In the B4X IDE, refresh the Libraries tab and check LeafletView.
- Add a CustomView in the Abstract Designer and set its Custom Class to LeafletView.
- 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.
Support
If this library is useful to you and you'd like to support my work, feel free to buy me a coffee!PayPal: [email protected]