com.vaadin.flow.component.map.
Class Map
- java.lang.Object
-
- com.vaadin.flow.component.Component
-
- com.vaadin.flow.component.map.MapBase
-
- com.vaadin.flow.component.map.Map
-
All Implemented Interfaces:
AttachNotifier
,DetachNotifier
,HasElement
,HasSize
,HasTheme
,Serializable
@Tag("vaadin-map") @NpmPackage(value="@vaadin/map", version="23.1.15") @JsModule("@vaadin/map/src/vaadin-map.js") @JsModule("./vaadin-map/mapConnector.js") public class Map extends MapBase
Map is a component for displaying geographic maps from various sources. It supports multiple layers, tiled and full image sources, adding markers, and interaction through events.
Each map consists of one or more
Layer
s that display geographical data. Each layer has aSource
that provides that data. The Map component provides several types of layers (for exampleTileLayer
,VectorLayer
,ImageLayer
), as well as several types of sources that can be used with each type of layer (for exampleOSMSource
,XYZSource
,VectorSource
).The map component comes pre-configured with a background layer, which by default is a
TileLayer
using anOSMSource
, which means that it displays tiled image data from the OpenStreeMap service. The background layer of the map can be replaced usingsetBackgroundLayer(Layer)
. The component is also pre-configured with aFeatureLayer
, accessible withgetFeatureLayer()
, that allows to quickly display geographical features, such as markers (seeMarkerFeature
), on top of a map. Custom layers can be added or removed usingaddLayer(Layer)
andremoveLayer(Layer)
.The viewport of the map is controlled through a
View
, which allows setting the center, zoom level and rotation. The map's view can be accessed throughMapBase.getView()
.See Also:
-
-
Constructor Summary
Constructors Constructor Description Map()
-
Method Summary
All Methods Modifier and Type Method Description void
addLayer(Layer layer)
Adds a layer to the map.
Layer
getBackgroundLayer()
Background layer of the map.
Coordinate
getCenter()
Gets center coordinates of the map's viewport
FeatureLayer
getFeatureLayer()
The feature layer of the map.
Configuration
getRawConfiguration()
float
getZoom()
Gets zoom level of the map's viewport, defaults to
0
void
removeLayer(Layer layer)
Remove a layer from the map
void
setBackgroundLayer(Layer backgroundLayer)
Sets the background layer of the map.
void
setCenter(Coordinate center)
Sets the center of the map's viewport in format specified by projection set on the view, which defaults to
EPSG:3857
void
setZoom(float zoom)
Sets the zoom level of the map's viewport.
-
Methods inherited from class com.vaadin.flow.component.map.MapBase
addClickEventListener, addFeatureClickListener, addFeatureClickListener, addThemeVariants, addViewMoveEndEventListener, getConfiguration, getFeatureFlags, getView, onAttach, removeThemeVariants, setView
-
Methods inherited from class com.vaadin.flow.component.Component
addListener, fireEvent, from, get, getChildren, getElement, getEventBus, getId, getLocale, getParent, getTranslation, getTranslation, getTranslation, getUI, hasListener, isAttached, isTemplateMapped, isVisible, onDetach, onEnabledStateChanged, scrollIntoView, set, setElement, setId, setVisible
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.vaadin.flow.component.AttachNotifier
addAttachListener
-
Methods inherited from interface com.vaadin.flow.component.DetachNotifier
addDetachListener
-
Methods inherited from interface com.vaadin.flow.component.HasElement
getElement
-
Methods inherited from interface com.vaadin.flow.component.HasSize
getHeight, getHeightUnit, getMaxHeight, getMaxWidth, getMinHeight, getMinWidth, getWidth, getWidthUnit, setHeight, setHeight, setHeightFull, setMaxHeight, setMaxHeight, setMaxWidth, setMaxWidth, setMinHeight, setMinHeight, setMinWidth, setMinWidth, setSizeFull, setSizeUndefined, setWidth, setWidth, setWidthFull
-
Methods inherited from interface com.vaadin.flow.component.HasTheme
addThemeName, addThemeNames, getThemeName, getThemeNames, hasThemeName, removeThemeName, removeThemeNames, setThemeName, setThemeName
-
-
-
-
Method Detail
-
getRawConfiguration
public Configuration getRawConfiguration()
-
getBackgroundLayer
public Layer getBackgroundLayer()
Background layer of the map. Every new instance of a
Map
is initialized with a background layer. By default, the background layer will be aTileLayer
using anOSMSource
, which means it will display tiled map data from the official OpenStreetMap server.Returns:
the background layer of the map
-
setBackgroundLayer
public void setBackgroundLayer(Layer backgroundLayer)
Sets the background layer of the map. The layer will be prepended before all other layers, which means it will be rendered in the background by default. The background layer is not intended to be removed, and thus can not be set to null. For use-cases where you want to use a dynamic set of layers, consider setting the first layer as background layer, and then adding the remaining layers using
addLayer(Layer)
.Parameters:
backgroundLayer
- the new background layer, not null
-
getFeatureLayer
public FeatureLayer getFeatureLayer()
The feature layer of the map. Every new instance of a
Map
has a pre-configuredFeatureLayer
for convenience, to allow quickly adding geographical features without requiring to set up a layer. Note that it is possible to add additional feature layers withaddLayer(Layer)
if splitting up features into different layers is beneficial for a use-case.Returns:
the feature layer of the map
-
addLayer
public void addLayer(Layer layer)
Adds a layer to the map. The layer will be appended to the list of layers, meaning that it will be rendered last / on top of previously added layers by default. For more fine-grained control of the layer rendering order, use
Layer.setzIndex(Integer)
.Parameters:
layer
- the layer to be added
-
removeLayer
public void removeLayer(Layer layer)
Remove a layer from the map
Parameters:
layer
- the layer to be removed
-
getCenter
public Coordinate getCenter()
Gets center coordinates of the map's viewport
This is a convenience method that delegates to the map's internal
View
. SeeMapBase.getView()
for accessing other properties of the view.Returns:
current center of the viewport
-
setCenter
public void setCenter(Coordinate center)
Sets the center of the map's viewport in format specified by projection set on the view, which defaults to
EPSG:3857
This is a convenience method that delegates to the map's internal
View
. SeeMapBase.getView()
for accessing other properties of the view.Parameters:
center
- new center of the viewport
-
getZoom
public float getZoom()
Gets zoom level of the map's viewport, defaults to
0
This is a convenience method that delegates to the map's internal
View
. SeeMapBase.getView()
for accessing other properties of the view.Returns:
current zoom level
-
setZoom
public void setZoom(float zoom)
Sets the zoom level of the map's viewport. The zoom level is a decimal value that starts at
0
as the most zoomed-out level, and then continually increases to zoom further in. By default, the maximum zoom level is currently restricted to28
. In practical terms, the level of detail of the map data that a map service provides determines how useful higher zoom levels are.This is a convenience method that delegates to the map's internal
View
. SeeMapBase.getView()
for accessing other properties of the view.Parameters:
zoom
- new zoom level
-
-