Class MapLibre

java.lang.Object
com.vaadin.flow.component.Component
org.vaadin.addons.velocitycomponent.AbstractVelocityJsComponent
org.vaadin.addons.maplibre.MapLibre
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, Serializable

@Tag("div") public class MapLibre extends org.vaadin.addons.velocitycomponent.AbstractVelocityJsComponent implements com.vaadin.flow.component.HasSize, com.vaadin.flow.component.HasStyle
A Java/Vaadin API for MapLibre GL JS.
See Also:
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    class 
     
    static interface 
     
    class 
     
    static interface 
     
    static final record 
     
  • Constructor Summary

    Constructors
    Constructor
    Description
     
    MapLibre(InputStream styleJson)
     
    MapLibre(String styleUrl)
     
    MapLibre(URI styleUrl)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected Layer
    addFillLayer(String name, String source, String sourceLayer, FillPaint paintJson, org.locationtech.jts.geom.Geometry geom)
     
    addFillLayer(org.locationtech.jts.geom.Geometry geom, FillPaint style)
     
    addFillLayer(org.locationtech.jts.geom.Polygon polygon, FillPaint style)
     
    addLineLayer(String name, String source, String sourceLayer, LinePaint paint)
    Adds a new layer only on the client sided
    protected LineLayer
    addLineLayer(String name, String source, String sourceLayer, LinePaint paint, org.locationtech.jts.geom.Geometry geom)
     
    addLineLayer(org.locationtech.jts.geom.LineString geometry, LinePaint linePaint)
     
    void
     
    addMarker(double x, double y)
     
    addMarker(org.locationtech.jts.geom.Point point)
     
    void
     
    void
    addSource(String name, String sourceDeclarationJson)
     
    void
    fitBounds(org.locationtech.jts.geom.Geometry geometry)
     
    protected void
    fitTo(org.locationtech.jts.geom.Envelope envelope, double padding)
     
    void
    fitTo(org.locationtech.jts.geom.Geometry geom, double padding)
     
    void
     
    void
    flyTo(double x, double y, Double zoom)
     
    void
    flyTo(org.locationtech.jts.geom.Geometry geometry)
     
    void
    flyTo(org.locationtech.jts.geom.Geometry geometry, double zoomLevel)
     
    org.locationtech.jts.geom.Coordinate
    Deprecated.
    Might contain outdated value, consider using getViewPort()
    protected org.apache.velocity.VelocityContext
     
    Detects current view port details.
     
    protected com.vaadin.flow.component.page.PendingJavaScriptResult
    js(String js)
     
    protected com.vaadin.flow.component.page.PendingJavaScriptResult
    js(String js, Map<String,Object> variables)
    Executes given JS in the context of the map component, either right away, or right after initial loading is done.
    protected void
    Loads the MapLibre JS library to the host page.
    protected void
    onAttach(com.vaadin.flow.component.AttachEvent attachEvent)
     
    protected void
    onDetach(com.vaadin.flow.component.DetachEvent detachEvent)
     
    void
     
    void
     
    void
    setCenter(double x, double y)
     
    void
    setCenter(org.locationtech.jts.geom.Coordinate coordinate)
     
    void
    setCenter(org.locationtech.jts.geom.Geometry geom)
     
    void
    setStyle(String styleUrl)
    Removes all current styles and layers and inits the map with given style URL
    void
    setZoomLevel(double zoomLevel)
     

    Methods inherited from class org.vaadin.addons.velocitycomponent.AbstractVelocityJsComponent

    jsTemplate, velocityJs, velocityJs, velocityJs

    Methods inherited from class com.vaadin.flow.component.Component

    addListener, findAncestor, fireEvent, from, get, getChildren, getElement, getEventBus, getId, getListeners, getLocale, getParent, getTranslation, getTranslation, getTranslation, getTranslation, getTranslation, getTranslation, getUI, hasListener, isAttached, isTemplateMapped, isVisible, onEnabledStateChanged, removeFromParent, scrollIntoView, 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.HasStyle

    addClassName, addClassNames, getClassName, getClassNames, getStyle, hasClassName, removeClassName, removeClassNames, setClassName, setClassName
  • Constructor Details

    • MapLibre

      public MapLibre()
    • MapLibre

      public MapLibre(URI styleUrl)
    • MapLibre

      public MapLibre(String styleUrl)
    • MapLibre

      public MapLibre(InputStream styleJson)
  • Method Details

    • onAttach

      protected void onAttach(com.vaadin.flow.component.AttachEvent attachEvent)
      Overrides:
      onAttach in class com.vaadin.flow.component.Component
    • onDetach

      protected void onDetach(com.vaadin.flow.component.DetachEvent detachEvent)
      Overrides:
      onDetach in class com.vaadin.flow.component.Component
    • loadMapLibreJs

      protected void loadMapLibreJs()
      Loads the MapLibre JS library to the host page. Not using @JavaScript annotation, as not all users necessarily want to use the unpkg.com CDN.

      Override if you want for example to load it from a local file instead of from unpkg.com.

    • getZoomLevel

      public Double getZoomLevel()
    • setZoomLevel

      public void setZoomLevel(double zoomLevel)
    • getCenter

      @Deprecated public org.locationtech.jts.geom.Coordinate getCenter()
      Deprecated.
      Might contain outdated value, consider using getViewPort()
      Returns the defined center of this map. Note that user can most likely pan the map. Use getViewPort() method to detect the current value from the client side.
      Returns:
      the last set center of this map.
    • setCenter

      public void setCenter(org.locationtech.jts.geom.Coordinate coordinate)
    • setCenter

      public void setCenter(org.locationtech.jts.geom.Geometry geom)
    • addLineLayer

      public LineLayer addLineLayer(org.locationtech.jts.geom.LineString geometry, LinePaint linePaint)
    • addFillLayer

      public Layer addFillLayer(org.locationtech.jts.geom.Polygon polygon, FillPaint style)
    • addFillLayer

      public Layer addFillLayer(org.locationtech.jts.geom.Geometry geom, FillPaint style)
    • addFillLayer

      protected Layer addFillLayer(String name, String source, String sourceLayer, FillPaint paintJson, org.locationtech.jts.geom.Geometry geom)
    • addLineLayer

      public LineLayer addLineLayer(String name, String source, String sourceLayer, LinePaint paint)
      Adds a new layer only on the client sided
      Parameters:
      name - the name of the new layer
      source - the source id
      sourceLayer - the source layer
      paint - the paint for the features
      Returns:
      Layer handle (e.g. to remove the layer)
    • addLineLayer

      protected LineLayer addLineLayer(String name, String source, String sourceLayer, LinePaint paint, org.locationtech.jts.geom.Geometry geom)
    • removeLayer

      public void removeLayer(Layer layer)
    • addSource

      public void addSource(String name, String sourceDeclarationJson)
    • addMarker

      public Marker addMarker(org.locationtech.jts.geom.Point point)
    • addMarker

      public Marker addMarker(double x, double y)
    • getVelocityContext

      protected org.apache.velocity.VelocityContext getVelocityContext()
      Overrides:
      getVelocityContext in class org.vaadin.addons.velocitycomponent.AbstractVelocityJsComponent
    • setCenter

      public void setCenter(double x, double y)
    • fitTo

      public void fitTo(org.locationtech.jts.geom.Geometry geom, double padding)
    • fitTo

      protected void fitTo(org.locationtech.jts.geom.Envelope envelope, double padding)
    • flyTo

      public void flyTo(double x, double y, Double zoom)
    • js

      protected com.vaadin.flow.component.page.PendingJavaScriptResult js(String js, Map<String,Object> variables)
      Executes given JS in the context of the map component, either right away, or right after initial loading is done.
      Parameters:
      js - the JS to execute, map and component variables are initialized automatically.
      Returns:
    • js

      protected com.vaadin.flow.component.page.PendingJavaScriptResult js(String js)
    • flyTo

      public void flyTo(org.locationtech.jts.geom.Geometry geometry, double zoomLevel)
    • flyTo

      public void flyTo(org.locationtech.jts.geom.Geometry geometry)
    • addMapClickListener

      public void addMapClickListener(MapLibre.MapClickListener listener)
    • fitBounds

      public void fitBounds(org.locationtech.jts.geom.Geometry geometry)
    • addMoveEndListener

      public void addMoveEndListener(MapLibre.MoveEndListener listener)
    • getViewPort

      public CompletableFuture<MapLibre.ViewPort> getViewPort()
      Detects current view port details.
      Returns:
      viewport details
    • fitToContent

      public void fitToContent()
    • removeAll

      public void removeAll()
    • setStyle

      public void setStyle(String styleUrl)
      Removes all current styles and layers and inits the map with given style URL
      Parameters:
      styleUrl - the styleUrl