Class WLeafletMap


  • public class WLeafletMap
    extends WCompositeWidget
    A widget that displays a leaflet map.

    This is a simple wrapper around the Leaflet JavaScript library.

    Leaflet itself does not provide maps. It is a JavaScript library that enables you to use any "tile server", like OpenStreetMap. If you just create a WLeafletMap (and give it a size), then you will be presented with an empty map. You can then add tile layers to the map using addTileLayer().

    WLeafletMap is not exhaustive in its support for Leaflet features. It supports a subset out of the box. One of these features is markers, which come in two flavors: standard leaflet markers (WLeafletMap.LeafletMarker) and widget markers (WLeafletMap.WidgetMarker). Using a widget marker, you can place arbitrary widgets on the map.

    If you need direct access to the leaflet map in your own custom JavaScript, you can use getMapJsRef().

    Leaflet itself is not bundled with JWt. Use the leafletJSURL and leafletCSSURL properties to configure where the JavaScript and CSS of Leaflet should be loaded from.

    • Method Detail

      • setOptions

        public void setOptions​(com.google.gson.JsonObject options)
        Change the options of the WLeafletMap.

        Note: This fully rerenders the map, because it creates a new Leaflet map, so any custom JavaScript modifying the map with e.g. WCompositeWidget#doJavaScript() is undone, much like reloading the page when reload-is-new-session is set to false.

        See https://leafletjs.com /reference.html#map for a list of options.
      • removeMarker

        public void removeMarker​(WLeafletMap.Marker marker)
        Remove the given marker.
      • addCircle

        public void addCircle​(WLeafletMap.Coordinate center,
                              double radius,
                              WPen stroke,
                              WBrush fill)
        Add a circle.

        This will draw a circle on the map centered at center, with the given radius (in meters), drawn with the given stroke and fill.

      • setZoomLevel

        public void setZoomLevel​(int level)
        Set the current zoom level.
      • getZoomLevel

        public int getZoomLevel()
        Get the current zoom level.
      • zoomLevelChanged

        public JSignal1<java.lang.Integer> zoomLevelChanged()
        Signal emitted when the user has changed the zoom level of the map.
      • panChanged

        public JSignal2<java.lang.Double,​java.lang.Double> panChanged()
        Signal emitted when the user has panned the map.
      • getMapJsRef

        public java.lang.String getMapJsRef()
        Returns a JavaScript expression to the Leaflet map object.

        You may want to use this in conjunction with JSlot or WCompositeWidget#doJavaScript() in custom JavaScript code, e.g. to access features not built-in to WLeafletMap.

      • render

        protected void render​(java.util.EnumSet<RenderFlag> flags)
        Description copied from class: WWidget
        Renders the widget.

        This function renders the widget (or an update for the widget), after this has been scheduled using scheduleRender().

        The default implementation will render the widget by serializing changes to JavaScript and HTML. You may want to reimplement this widget if you have been postponing some of the layout / rendering implementation until the latest moment possible. In that case you should make sure you call the base implementation however.

        Overrides:
        render in class WCompositeWidget