Giter VIP home page Giter VIP logo

leaflet4j's Introduction

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:

<dependency>
  <groupId>com.dukescript.api</groupId>
  <artifactId>leaflet4j</artifactId>
  <version>0.7</version>
</dependency>

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 Main.java 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), 
			"https://cdnjs.cloudflare.com/ajax/libs/fatcow-icons/20130425/FatCow_Icons32x32/rubber_duck.png");

        // Create a map zoomed to Linz.
        MapOptions mapOptions = new MapOptions()
                .setCenter(new LatLng(48.336614, 14.319305))
                .setZoom(15)
                .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='http://www.thunderforest.com/opencyclemap/'>OpenCycleMap</a> contributors, "
                + "<a href='http://creativecommons.org/licenses/by-sa/2.0/'>CC-BY-SA</a>, "
                + "Imagery © <a href='http://www.thunderforest.com/'>Thunderforest</a>");
        tlo.setMaxZoom(18);
        TileLayer layer = new TileLayer("http://{s}.tile.thunderforest.com/cycle/{z}/{x}/{y}.png", tlo);
        map.addLayer(layer);
        
        // 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));
        m.addTo(map);
        
        // 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() {
            @Override
            public void onEvent(MouseEvent ev) {
                PopupOptions popupOptions = new PopupOptions().setMaxWidth(400);
                Popup popup = new Popup(popupOptions);
                popup.setLatLng(ev.getLatLng());
                popup.setContent("You clicked on this polygon;");
                popup.openOn(map);
            }
        });
        map.addLayer(polygonLayer);
    }

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.

leaflet4j's People

Contributors

swurzinger avatar dukescript avatar keptn-nightly-user avatar sperlchris avatar jtulach avatar monezz avatar

Watchers

José avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.