<dependency> <groupId>com.gwidgets</groupId> <artifactId>gwty-leaflet</artifactId> <version>0.4-SNAPSHOT</version> </dependency>
The sonatype snapshot repository needs to be added as well:
<repositories> <repository> <id>snapshots</id> <url>https://oss.sonatype.org/content/repositories/snapshots/</url> <releases> <enabled>false</enabled> </releases> <snapshots> <enabled>true</enabled> </snapshots> </repository> </repositories>
Also, do not forget to include gwty-leaflet in your .gwt.xml module definition file:
<inherits name='com.gwidgets.api.GwtyLeaflet' />
gwty-leaflet is compatible with the latest stable version of Leaflet: 0.7.
<link rel="stylesheet" href="https://email@example.com/dist/leaflet.css" /> <script src="https://firstname.lastname@example.org/dist/leaflet.js"></script>
All objects initializations are done through the L class. gwty-leaflet provides all factory methods of Leaflet. For example:
//equivalent to new Map(...) Map map = L.map("map", new MapOptions.Builder().build()); //equivalent to new Circle(...) Circle circle = L.circle(L.latLng(51.508, 11), 200, options);
Trying to create a Leaflet object directly using the new operator will result in an error. For more information about Leaflet objects creational patterns, you can refer to Leaflet's official documentation.
As specified by Leaflet documentation, the creation of some objects requires a set of options. gwty-leaflet provides all the options with their respective default values as Objects annotated with @JsType. As of version 0.4, options builders were introduced to help in the creation of option Objects and enforce fields validations. Several options have required fields, and using builders help the developer distinguish between required and optional fields.
Before version 0.4:
PathOptions options = new PathOptions(); options.fillColor = "#fff"; options.opacity = 1; //... L.circle(L.latLng(51.508, 11), 200, options).addTo(map);
After version 0.4:
PathOptions options = new PathOptions.Builder() .fillColor("#fff") .opacity(1) .build(); //... L.circle(L.latLng(51.508, 11), 200, options).addTo(map);
For more informations about the available options for each objects, and their utility. You can refer to the original leaflet documentation.
To create a map in a div with an id="map", we can do something like:
L.map("map", new MapOptions.Builder().build()).setView(L.latLng(51.505, -0.09), 12, new ZoomPanOptions.Builder().build());
Events are available only in some objects. Events can be handled throught the following methods: clearAllEventListeners(), on(String type, Function fn), once(String type, Function fn), off(String type, Function fn), fire(String type).
For defining actions, events needs to be supplied with an abstract callback function that needs to be implemented by the developer. The below example will dipslay a pop up on each map click:
Event Objects that the event object can be cast to are (depending on the usage):
Events are executed following the order of registration.
Events are explained in details in Leaflet's documentation.
As of the current version, gwty-leaflet is compiled using GWT 2.8.0-rc2.