Class LeafletMap
java.lang.Object
com.vaadin.flow.component.Component
org.vaadin.addons.componentfactory.leaflet.LeafletMap
- All Implemented Interfaces:
com.vaadin.flow.component.AttachNotifier,com.vaadin.flow.component.DetachNotifier,com.vaadin.flow.component.HasElement,com.vaadin.flow.component.HasSize,com.vaadin.flow.component.HasStyle,com.vaadin.flow.component.HasTheme,Serializable,Evented,SupportsKeyboardEvents,SupportsLayerEvents,SupportsLocationEvents,SupportsMapEvents,SupportsMouseEvents,Identifiable,ExecutableFunctions,GeolocationFunctions,MapConversionFunctions,MapGetStateFunctions,MapModifyStateFunctions
@Tag("leaflet-map")
@NpmPackage(value="leaflet",
version="1.9.4")
@JsModule("./leaflet-map.js") @JsModule("leaflet/dist/leaflet-src.js")
@CssImport(value="leaflet/dist/leaflet.css",themeFor="leaflet-map") @CssImport(value="./styles/leaflet-lumo-theme.css",themeFor="leaflet-map")
public final class LeafletMap
extends com.vaadin.flow.component.Component
implements MapModifyStateFunctions, MapGetStateFunctions, GeolocationFunctions, MapConversionFunctions, SupportsMouseEvents, SupportsMapEvents, SupportsLocationEvents, SupportsKeyboardEvents, SupportsLayerEvents, com.vaadin.flow.component.HasSize, com.vaadin.flow.component.HasTheme, com.vaadin.flow.component.HasStyle
Server-side component wrapping the Leaflet interactive map. It manages the
map layers, controls, options and events, and executes the corresponding
function calls on the client-side Leaflet instance.
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classMap event which fired when map gets initialized on client side -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new map using the default map options.LeafletMap(MapOptions mapOptions) Creates a new map configured with the given map options. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddControl(LeafletControl leafletControl) Adds the given control to the map<T extends LeafletEvent>
voidaddEventListener(LeafletEventType eventType, LeafletEventListener<T> listener) Registers a listener for the given Leaflet event type on the map.voidAdds the given layer to the mapvoidaddThemeVariants(LeafletMapVariant... variants) Adds theme variants to the map component.<T extends Serializable>
CompletableFuture<T> call(Identifiable target, String functionName, Class<T> resultType, Serializable... arguments) Calls the named Leaflet function on the client for the given target and asynchronously returns its result deserialized to the requested type.voidRemoves all event listeners registered on the map.voidexecuteJs(Identifiable target, String functionName, Serializable... arguments) Executes the named Leaflet function on the client for the given target, without expecting a return value.Recursively searches the map, including nested layer groups, for the layer with the given internal ID.Returns the layer with the given internal ID.getUuid()Returns the unique identifier of the map.booleanhasEventListeners(LeafletEventType eventType) Returns whether any listener is registered for the given Leaflet event type.booleanisReady()Returns whether the map has been initialized on the client side.protected voidonAttach(com.vaadin.flow.component.AttachEvent attachEvent) Sends the registered event types to the client when the component is attached, so that the matching Leaflet listeners get bound.voidremoveControl(LeafletControl leafletControl) Removes the given control from the mapvoidremoveEventListener(LeafletEventType eventType) Removes the listeners registered for the given Leaflet event type.voidremoveLayer(Layer layer) Removes the given layer from the map.voidsetBaseUrl(String baseUrl) Adds a tile layer to the map using the given URL template as the tile source.com.vaadin.flow.shared.RegistrationwhenReady(com.vaadin.flow.component.ComponentEventListener<LeafletMap.MapReadyEvent> listener) Fired when the map gets initialized with a view (center and zoom) and at least one layer, or immediately if it's already initialized.Methods inherited from class com.vaadin.flow.component.Component
addListener, bindVisible, findAncestor, fireEvent, from, get, getChildren, getElement, getEventBus, getId, getListeners, getLocale, getParent, getTestId, getTranslation, getTranslation, getTranslation, getTranslation, getTranslation, getTranslation, getUI, hasListener, isAttached, isTemplateMapped, isVisible, onDetach, onEnabledStateChanged, removeFromParent, scrollIntoView, scrollIntoView, set, setElement, setId, setTestId, setVisibleMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.vaadin.flow.component.AttachNotifier
addAttachListenerMethods inherited from interface com.vaadin.flow.component.DetachNotifier
addDetachListenerMethods inherited from interface org.vaadin.addons.componentfactory.leaflet.layer.events.Evented
listens, off, off, onMethods inherited from interface org.vaadin.addons.componentfactory.leaflet.layer.map.functions.ExecutableFunctions
call, executeJsMethods inherited from interface org.vaadin.addons.componentfactory.leaflet.layer.map.functions.GeolocationFunctions
locate, locate, stopLocateMethods inherited from interface com.vaadin.flow.component.HasElement
getElementMethods inherited from interface com.vaadin.flow.component.HasSize
bindHeight, bindWidth, getHeight, getHeightUnit, getMaxHeight, getMaxWidth, getMinHeight, getMinWidth, getWidth, getWidthUnit, setHeight, setHeight, setHeightFull, setMaxHeight, setMaxHeight, setMaxWidth, setMaxWidth, setMinHeight, setMinHeight, setMinWidth, setMinWidth, setSizeFull, setSizeUndefined, setWidth, setWidth, setWidthFullMethods inherited from interface com.vaadin.flow.component.HasStyle
addClassName, addClassNames, bindClassName, bindClassNames, getClassName, getClassNames, getStyle, hasClassName, removeClassName, removeClassNames, setClassName, setClassNameMethods inherited from interface com.vaadin.flow.component.HasTheme
addThemeName, addThemeNames, bindThemeName, bindThemeNames, getThemeName, getThemeNames, hasThemeName, removeThemeName, removeThemeNames, setThemeName, setThemeNameMethods inherited from interface org.vaadin.addons.componentfactory.leaflet.layer.map.functions.MapConversionFunctions
containerPointToLatLng, containerPointToLayerPoint, distance, latLngToContainerPoint, latLngToLayerPoint, layerPointToContainerPoint, layerPointToLatLng, mouseEventToContainerPoint, mouseEventToLatLng, mouseEventToLayerPoint, project, unproject, wrapLatLng, wrapLatLngBoundsMethods inherited from interface org.vaadin.addons.componentfactory.leaflet.layer.map.functions.MapGetStateFunctions
getBounds, getBoundsZoom, getCenter, getMaxZoom, getMinZoom, getPixelBounds, getPixelOrigin, getPixelWorldBounds, getSize, getZoomMethods inherited from interface org.vaadin.addons.componentfactory.leaflet.layer.map.functions.MapModifyStateFunctions
fitBounds, fitBounds, fitWorld, fitWorld, flyTo, flyTo, flyTo, flyTo, flyToBounds, flyToBounds, invalidateSize, invalidateSize, invalidateSize, invalidateSize, panBy, panBy, panInside, panInside, panInsideBounds, panInsideBounds, panTo, panTo, setMaxBounds, setMaxZoom, setMinZoom, setView, setView, setView, setZoom, setZoom, setZoomAround, setZoomAround, stop, zoomIn, zoomIn, zoomOut, zoomOutMethods inherited from interface org.vaadin.addons.componentfactory.leaflet.layer.events.supports.SupportsKeyboardEvents
onKeyDown, onKeyPress, onKeyUpMethods inherited from interface org.vaadin.addons.componentfactory.leaflet.layer.events.supports.SupportsLayerEvents
onLayerAdd, onLayerRemoveMethods inherited from interface org.vaadin.addons.componentfactory.leaflet.layer.events.supports.SupportsLocationEvents
onLocationError, onLocationFoundMethods inherited from interface org.vaadin.addons.componentfactory.leaflet.layer.events.supports.SupportsMapEvents
onLoad, onMove, onMoveEnd, onMoveStart, onResize, onUnload, onViewReset, onZoom, onZoomAnim, onZoomEnd, onZoomLevelsChange, onZoomStartMethods inherited from interface org.vaadin.addons.componentfactory.leaflet.layer.events.supports.SupportsMouseEvents
onClick, onContextMenuOpened, onDoubleClick, onMouseDown, onMouseMove, onMouseOut, onMouseOver, onMouseUp
-
Constructor Details
-
LeafletMap
public LeafletMap()Creates a new map using the default map options. -
LeafletMap
Creates a new map configured with the given map options.- Parameters:
mapOptions- the options used to initialize the map
-
-
Method Details
-
onAttach
protected void onAttach(com.vaadin.flow.component.AttachEvent attachEvent) Sends the registered event types to the client when the component is attached, so that the matching Leaflet listeners get bound.- Overrides:
onAttachin classcom.vaadin.flow.component.Component- Parameters:
attachEvent- the attach event
-
getLayer
Returns the layer with the given internal ID.- Parameters:
layerId- the id of the layer to be looking for- Returns:
- the layer with the given internal ID
-
findLayer
Recursively searches the map, including nested layer groups, for the layer with the given internal ID.- Parameters:
layerId- the id of the layer to look for- Returns:
- the matching layer, or the root map layer if none is found
-
addLayer
Adds the given layer to the map- Parameters:
layer- the layer to add
-
removeLayer
Removes the given layer from the map.- Parameters:
layer- the layer to remove
-
setBaseUrl
Adds a tile layer to the map using the given URL template as the tile source.- Parameters:
baseUrl- the tile layer URL template
-
addControl
Adds the given control to the map- Parameters:
leafletControl- the control to add
-
removeControl
Removes the given control from the map- Parameters:
leafletControl- the control to remove
-
whenReady
public com.vaadin.flow.shared.Registration whenReady(com.vaadin.flow.component.ComponentEventListener<LeafletMap.MapReadyEvent> listener) Fired when the map gets initialized with a view (center and zoom) and at least one layer, or immediately if it's already initialized.- Parameters:
listener- the listener to call when the event occurs, notnull- Returns:
- a handle that can be used for removing the listener
-
addThemeVariants
Adds theme variants to the map component.- Parameters:
variants- theme variants to add
-
executeJs
Executes the named Leaflet function on the client for the given target, without expecting a return value.- Specified by:
executeJsin interfaceExecutableFunctions- Parameters:
target- the client object (map, layer or control) to invoke the function onfunctionName- the name of the Leaflet function to callarguments- the arguments passed to the function
-
call
public <T extends Serializable> CompletableFuture<T> call(Identifiable target, String functionName, Class<T> resultType, Serializable... arguments) Calls the named Leaflet function on the client for the given target and asynchronously returns its result deserialized to the requested type.- Specified by:
callin interfaceExecutableFunctions- Type Parameters:
T- the type of the returned result- Parameters:
target- the client object (map, layer or control) to invoke the function onfunctionName- the name of the Leaflet function to callresultType- the type the client result should be deserialized toarguments- the arguments passed to the function- Returns:
- a future completed with the function result, or
nullif the map is not ready yet
-
addEventListener
public <T extends LeafletEvent> void addEventListener(LeafletEventType eventType, LeafletEventListener<T> listener) Registers a listener for the given Leaflet event type on the map.- Specified by:
addEventListenerin interfaceEvented- Type Parameters:
T- the type of the fired event- Parameters:
eventType- the event type to listen forlistener- the listener invoked when the event occurs
-
getUuid
Returns the unique identifier of the map.- Specified by:
getUuidin interfaceIdentifiable- Returns:
- the map uuid
-
removeEventListener
Removes the listeners registered for the given Leaflet event type.- Specified by:
removeEventListenerin interfaceEvented- Parameters:
eventType- the event type to stop listening for
-
clearAllEventListeners
public void clearAllEventListeners()Removes all event listeners registered on the map.- Specified by:
clearAllEventListenersin interfaceEvented
-
hasEventListeners
Returns whether any listener is registered for the given Leaflet event type.- Specified by:
hasEventListenersin interfaceEvented- Parameters:
eventType- the event type to check- Returns:
trueif at least one listener is registered for the event type
-
isReady
public boolean isReady()Returns whether the map has been initialized on the client side.- Returns:
- the ready
-