Class WLeafletMap
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.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
A geographical coordinate (latitude/longitude)static class
A standard leaflet marker.static class
An abstract marker.static class
A marker rendered with a widget.Nested classes/interfaces inherited from class eu.webtoolkit.jwt.WObject
WObject.FormData
-
Constructor Summary
ConstructorDescriptionCreate a newWLeafletMap
.WLeafletMap
(com.google.gson.JsonObject options) Create a newWLeafletMap
with the given options.WLeafletMap
(com.google.gson.JsonObject options, WContainerWidget parentContainer) Create a newWLeafletMap
with the given options.WLeafletMap
(WContainerWidget parentContainer) Create a newWLeafletMap
. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addCircle
(WLeafletMap.Coordinate center, double radius, WPen stroke, WBrush fill) Add a circle.void
addMarker
(WLeafletMap.Marker marker) Add the given marker.void
addPolyline
(List<WLeafletMap.Coordinate> points, WPen pen) Add a polyline.void
addTileLayer
(String urlTemplate, com.google.gson.JsonObject options) Add a new tile layer.Returns a JavaScript expression to the Leaflet map object.Get the current position.int
Get the current zoom level.Signal
emitted when the user has panned the map.void
panTo
(WLeafletMap.Coordinate center) Pan to the given coordinate.void
remove()
Destructor.removeMarker
(WLeafletMap.Marker marker) Remove the given marker.protected void
render
(EnumSet<RenderFlag> flags) Renders the widget.void
setOptions
(com.google.gson.JsonObject options) Change the options of the WLeafletMap.void
setZoomLevel
(int level) Set the current zoom level.Signal
emitted when the user has changed the zoom level of the map.Methods inherited from class eu.webtoolkit.jwt.WCompositeWidget
addStyleClass, boxBorder, boxPadding, callJavaScriptMember, doJavaScript, enableAjax, find, findById, getAttributeValue, getBaseZIndex, getChildren, getClearSides, getDecorationStyle, getFloatSide, getHeight, getId, getImplementation, getJavaScriptMember, getLineHeight, getMargin, getMaximumHeight, getMaximumWidth, getMinimumHeight, getMinimumWidth, getObjectName, getOffset, getPositionScheme, getScrollVisibilityMargin, getStyleClass, getTabIndex, getTakeImplementation, getToolTip, getVerticalAlignment, getVerticalAlignmentLength, getWidth, hasFocus, hasStyleClass, isCanReceiveFocus, isDisabled, isEnabled, isHidden, isHiddenKeepsGeometry, isInline, isLoaded, isPopup, isScrollVisibilityEnabled, isScrollVisible, isSetFirstFocus, isThemeStyleEnabled, isVisible, load, propagateSetEnabled, propagateSetVisible, refresh, removeStyleClass, removeWidget, resize, scrollVisibilityChanged, setAttributeValue, setCanReceiveFocus, setClearSides, setDecorationStyle, setDeferredToolTip, setDisabled, setFloatSide, setFocus, setHidden, setHiddenKeepsGeometry, setId, setImplementation, setInline, setJavaScriptMember, setLineHeight, setMargin, setMaximumSize, setMinimumSize, setObjectName, setOffsets, setPopup, setPositionScheme, setScrollVisibilityEnabled, setScrollVisibilityMargin, setSelectable, setStyleClass, setTabIndex, setThemeStyleEnabled, setToolTip, setVerticalAlignment
Methods inherited from class eu.webtoolkit.jwt.WWidget
acceptDrops, acceptDrops, addCssRule, addCssRule, addJSignal, addStyleClass, animateHide, animateShow, createJavaScript, disable, dropEvent, enable, getDropTouch, getJsRef, getParent, hide, htmlText, isExposed, isGlobalWidget, isLayoutSizeAware, isRendered, layoutSizeChanged, needsRerender, positionAt, positionAt, removeFromParent, removeStyleClass, render, resize, scheduleRender, scheduleRender, scheduleRender, setClearSides, setDeferredToolTip, setFocus, setHeight, setHidden, setLayoutSizeAware, setMargin, setMargin, setMargin, setMargin, setMargin, setOffsets, setOffsets, setOffsets, setOffsets, setOffsets, setToolTip, setVerticalAlignment, setWidth, show, stopAcceptDrops, toggleStyleClass, toggleStyleClass, tr
Methods inherited from class eu.webtoolkit.jwt.WObject
setFormData
-
Constructor Details
-
WLeafletMap
Create a newWLeafletMap
. -
WLeafletMap
public WLeafletMap()Create a newWLeafletMap
. -
WLeafletMap
Create a newWLeafletMap
with the given options. -
WLeafletMap
public WLeafletMap(com.google.gson.JsonObject options) Create a newWLeafletMap
with the given options.
-
-
Method Details
-
remove
public void remove()Description copied from class:WWidget
Destructor.Deletes a widget and all contained contents.
- Overrides:
remove
in classWCompositeWidget
- See Also:
-
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 whenreload-is-new-session
is set to false. See https://leafletjs.com/reference.html#map for a list of options. -
addTileLayer
Add a new tile layer. -
addMarker
Add the given marker. -
removeMarker
Remove the given marker. -
addPolyline
Add a polyline.This will draw a polyline on the map going through the given list of coordinates, with the given pen.
-
addCircle
Add a circle.This will draw a circle on the map centered at
center
, with the givenradius
(in meters), drawn with the givenstroke
andfill
. -
setZoomLevel
public void setZoomLevel(int level) Set the current zoom level. -
getZoomLevel
public int getZoomLevel()Get the current zoom level. -
panTo
Pan to the given coordinate. -
getPosition
Get the current position. -
zoomLevelChanged
Signal
emitted when the user has changed the zoom level of the map. -
panChanged
Signal
emitted when the user has panned the map. -
getMapJsRef
Returns a JavaScript expression to the Leaflet map object.You may want to use this in conjunction with
JSlot
orWCompositeWidget#doJavaScript()
in custom JavaScript code, e.g. to access features not built-in to WLeafletMap. -
render
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 classWCompositeWidget
-