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 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:
publicstaticvoidonPageLoad(String... args) throwsException {
// Create custom layerExampleCustomLayerduckLayer = newExampleCustomLayer(newLatLng(48.337074, 14.319868), "https://cdnjs.cloudflare.com/ajax/libs/fatcow-icons/20130425/FatCow_Icons32x32/rubber_duck.png");
// Create a map zoomed to Linz.MapOptionsmapOptions = newMapOptions()
.setCenter(newLatLng(48.336614, 14.319305))
.setZoom(15)
.setLayers(newILayer[] { duckLayer });
finalMapmap = newMap("map", mapOptions);
// add a tile layer to the mapTileLayerOptionstlo = newTileLayerOptions();
tlo.setAttribution("Map data © <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);
TileLayerlayer = newTileLayer("http://{s}.tile.thunderforest.com/cycle/{z}/{x}/{y}.png", tlo);
map.addLayer(layer);
// Set a marker with a user defined iconIconicon = newIcon(newIconOptions("leaflet-0.7.2/images/marker-icon.png"));
Markerm = newMarker(newLatLng(48.336614, 14.33), newMarkerOptions().setIcon(icon));
m.addTo(map);
// Add a polygon. When you click on the polygon a popup shows upPolygonpolygonLayer = newPolygon(newLatLng[] {
newLatLng(48.335067, 14.320660),
newLatLng(48.337335, 14.323642),
newLatLng(48.335238, 14.328942),
newLatLng(48.333883, 14.327612)
});
polygonLayer.addMouseListener(MouseEvent.Type.CLICK, newMouseListener() {
@OverridepublicvoidonEvent(MouseEventev) {
PopupOptionspopupOptions = newPopupOptions().setMaxWidth(400);
Popuppopup = newPopup(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.
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.