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
Nested ClassesModifier and TypeClassDescriptionstatic classAn abstract map item.static classAn abstract map item with text.static classA geographical coordinate (latitude/longitude)static classA standard leaflet marker.static classAn abstract marker.static classA popup that can be added to theWLeafletMap.static classAWLeafletMap.Tooltipthat can be added to theWLeafletMap.static classA marker rendered with a widget.Nested classes/interfaces inherited from class eu.webtoolkit.jwt.WObject
WObject.FormData -
Constructor Summary
ConstructorsConstructorDescriptionCreate a newWLeafletMap.WLeafletMap(com.google.gson.JsonObject options) Create a newWLeafletMapwith the given options.WLeafletMap(com.google.gson.JsonObject options, WContainerWidget parentContainer) Create a newWLeafletMapwith the given options.WLeafletMap(WContainerWidget parentContainer) Create a newWLeafletMap. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddCircle(WLeafletMap.Coordinate center, double radius, WPen stroke, WBrush fill) Add a circle.voidaddMarker(WLeafletMap.Marker marker) Add the given marker.voidaddPolyline(List<WLeafletMap.Coordinate> points, WPen pen) Add a polyline.voidaddPopup(WLeafletMap.Popup popup) Add the given popup.voidaddTileLayer(String urlTemplate, com.google.gson.JsonObject options) Add a new tile layer.voidaddTooltip(WLeafletMap.Tooltip tooltip) Add the given tooltip.Returns a JavaScript expression to the Leaflet map object.Get the current position.intGet the current zoom level.Signalemitted when the user has panned the map.voidpanTo(WLeafletMap.Coordinate center) Pan to the given coordinate.voidremove()Destructor.removeMarker(WLeafletMap.Marker marker) Remove the given marker.removePopup(WLeafletMap.Popup popup) Remove the given popup.removeTooltip(WLeafletMap.Tooltip tooltip) Remove the given tooltip.protected voidrender(EnumSet<RenderFlag> flags) Renders the widget.voidsetOptions(com.google.gson.JsonObject options) Change the options of the WLeafletMap.voidsetZoomLevel(int level) Set the current zoom level.Signalemitted 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, setParentWidget, setPopup, setPositionScheme, setScrollVisibilityEnabled, setScrollVisibilityMargin, setSelectable, setStyleClass, setTabIndex, setThemeStyleEnabled, setToolTip, setVerticalAlignmentMethods inherited from class eu.webtoolkit.jwt.WWidget
acceptDrops, acceptDrops, addCssRule, addCssRule, addJSignal, addStyleClass, animateHide, animateShow, applyThemeStyles, createJavaScript, disable, dropEvent, enable, getDropTouch, getJsRef, getParent, hide, htmlText, isExposed, isGlobalWidget, isLayoutSizeAware, isRendered, layoutSizeChanged, needsRerender, positionAt, positionAt, positionAt, positionAt, removeFromParent, removeStyleClass, render, resize, scheduleRender, scheduleRender, scheduleRender, scheduleThemeStyleApply, setClearSides, setDeferredToolTip, setFocus, setHeight, setHidden, setLayoutSizeAware, setMargin, setMargin, setMargin, setMargin, setMargin, setOffsets, setOffsets, setOffsets, setOffsets, setOffsets, setToolTip, setVerticalAlignment, setWidth, show, stopAcceptDrops, toggleStyleClass, toggleStyleClass, trMethods inherited from class eu.webtoolkit.jwt.WObject
setFormData
-
Constructor Details
-
WLeafletMap
Create a newWLeafletMap. -
WLeafletMap
public WLeafletMap()Create a newWLeafletMap. -
WLeafletMap
Create a newWLeafletMapwith the given options. -
WLeafletMap
public WLeafletMap(com.google.gson.JsonObject options) Create a newWLeafletMapwith the given options.
-
-
Method Details
-
remove
public void remove()Description copied from class:WWidgetDestructor.Deletes a widget and all contained contents.
- Overrides:
removein 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-sessionis set to false. See https://leafletjs.com/reference.html#map for a list of options. -
addTileLayer
Add a new tile layer. -
addPopup
Add the given popup. -
removePopup
Remove the given popup. -
addTooltip
Add the given tooltip. -
removeTooltip
Remove the given tooltip. -
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 givenstrokeandfill. -
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
Signalemitted when the user has changed the zoom level of the map. -
panChanged
Signalemitted 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
JSlotorWCompositeWidget#doJavaScript()in custom JavaScript code, e.g. to access features not built-in to WLeafletMap. -
render
Description copied from class:WWidgetRenders 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:
renderin classWCompositeWidget
-