Skip to content
Branch: master
Go to file
This branch is 29 commits ahead, 2 commits behind jtulach:master.

Latest commit


Failed to load latest commit information.
Latest commit message
Commit time

Leaflet for Java API

Java version of leaflet library for rendering of mobile friendly interactive maps in Java. Read more in Javadoc. Include in your Maven project as:


Leaflet Demo

Leaflet Demo rewritten to Java via DukeScript. Clone and then:

# prepare
$ mvn clean install 
$ cd l4jdemo

# run or debug on your desktop:
$ mvn exec:java

# run on your **Android** device
$ mvn -Pdlvkbrwsr package android:deploy android:run -Dandroid.sdk.path=...

# if you are on Mac OS X, run on your iPad simulator
$ mvn -Pibrwsr robovm:ipad-sim

to see the application. Check to see the initialization which basically consists of:

    public static void onPageLoad(String... args) throws Exception {
        // Create custom layer
        ExampleCustomLayer duckLayer = new ExampleCustomLayer(new LatLng(48.337074, 14.319868), 

        // Create a map zoomed to Linz.
        MapOptions mapOptions = new MapOptions()
                .setCenter(new LatLng(48.336614, 14.319305))
                .setLayers(new ILayer[] { duckLayer });
        final Map map = new Map("map", mapOptions);
        // add a tile layer to the map
        TileLayerOptions tlo = new TileLayerOptions();
        tlo.setAttribution("Map data &copy; <a href=''>OpenCycleMap</a> contributors, "
                + "<a href=''>CC-BY-SA</a>, "
                + "Imagery © <a href=''>Thunderforest</a>");
        TileLayer layer = new TileLayer("http://{s}{z}/{x}/{y}.png", tlo);
        // Set a marker with a user defined icon
        Icon icon = new Icon(new IconOptions("leaflet-0.7.2/images/marker-icon.png"));
        Marker m = new Marker(new LatLng(48.336614, 14.33), new MarkerOptions().setIcon(icon));
        // Add a polygon. When you click on the polygon a popup shows up
        Polygon polygonLayer = new Polygon(new LatLng[] {
                new LatLng(48.335067, 14.320660),
                new LatLng(48.337335, 14.323642),
                new LatLng(48.335238, 14.328942),
                new LatLng(48.333883, 14.327612)
        polygonLayer.addMouseListener(MouseEvent.Type.CLICK, new MouseListener() {
            public void onEvent(MouseEvent ev) {
                PopupOptions popupOptions = new PopupOptions().setMaxWidth(400);
                Popup popup = new Popup(popupOptions);
                popup.setContent("You clicked on this polygon;");

Fork and improve the Java leaflet bindings. Or fork and design your own Java wrappers around your favorite JavaScript library as described at this great introduction.

Running inside of JavaFX Application

It is possible to include the browser widget inside of your existing JavaFX application. To see example of such approach, just type:

# prepare
$ mvn clean install 
$ cd l4jfxdemo

$ mvn exec:exec

This mode provides incremental migration approach and should be useful for those who already have an existing JavaFX application, but want to benefit from the power of leaflet4j APIs.


Leaflet Demo rewritten to Java via DukeScript



You can’t perform that action at this time.