Class GeoMap

java.lang.Object
com.vaadin.flow.component.Component
io.jmix.mapsflowui.kit.component.JmixMap
io.jmix.mapsflowui.component.GeoMap
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, org.springframework.beans.factory.Aware, org.springframework.beans.factory.InitializingBean, org.springframework.context.ApplicationContextAware

public class GeoMap extends JmixMap implements org.springframework.context.ApplicationContextAware, org.springframework.beans.factory.InitializingBean
UI component that displays a geographical data provided by Layers.

The map is built by superposing layers. Initially, map does not have layers.

See Also:
  • Field Details

    • applicationContext

      protected org.springframework.context.ApplicationContext applicationContext
    • projections

      protected Collection<ProjectionRegistration> projections
    • userProjection

      protected CRS userProjection
    • zoomToJson

      protected elemental.json.JsonValue zoomToJson
    • fitJson

      protected elemental.json.JsonValue fitJson
  • Constructor Details

    • GeoMap

      public GeoMap()
  • Method Details

    • setApplicationContext

      public void setApplicationContext(org.springframework.context.ApplicationContext applicationContext) throws org.springframework.beans.BeansException
      Specified by:
      setApplicationContext in interface org.springframework.context.ApplicationContextAware
      Throws:
      org.springframework.beans.BeansException
    • afterPropertiesSet

      public void afterPropertiesSet()
      Specified by:
      afterPropertiesSet in interface org.springframework.beans.factory.InitializingBean
    • autowireDependencies

      protected void autowireDependencies()
    • addLayer

      public void addLayer(Layer<?> layer)
      Adds layer to the map.
      Overrides:
      addLayer in class JmixMap
      Parameters:
      layer - layer to add
    • getLayerOrNull

      @Nullable public <L extends Layer<?>> L getLayerOrNull(String layerId)
      Returns a layer by its ID or null if the map does not contain a layer with the provided ID.
      Overrides:
      getLayerOrNull in class JmixMap
      Type Parameters:
      L - layer type
      Parameters:
      layerId - ID of a layer
      Returns:
      layer
    • getMapView

      public GeoMapView getMapView()
      Overrides:
      getMapView in class JmixMap
      Returns:
      map view
    • setMapView

      public void setMapView(MapView view)
      Sets map view. It replaces previous default map view. To change zoom or center coordinate, use JmixMap.getMapView(), for instance:
       map.getMapView().setZoom(10);
       
      Overrides:
      setMapView in class JmixMap
      Parameters:
      view - map view to set
      See Also:
    • setProjection

      public void setProjection(CRS projection)
      Sets the projection for coordinates supplied from and returned by API methods.

      Note, the projection will be used for all maps on the page.

      Parameters:
      projection - projection to set
    • getCenter

      public org.locationtech.jts.geom.Coordinate getCenter()
      Gets coordinates of the geographic center of the map's visible area.

      Delegates to the map's view. See getMapView().

      Returns:
      current center of the map's visible area
    • setCenter

      public void setCenter(org.locationtech.jts.geom.Coordinate center)
      Sets the geographic center of the map's visible area. Coordinates must be specified in the map projection, which is EPSG:4326.

      If the map projection has been changed using setProjection(CRS), then coordinates must be specified in that projection.

      Note that the map projection is a different concept than the view projection set in the map's GeoMapView. The view projection affects how map data is interpreted and rendered, while the map projection defines the coordinate system that all coordinates passed to, or returned from the public API must be in.

      Delegates to the map's view. See getMapView().

      Parameters:
      center - new center of the visible area
    • zoomToExtent

      public void zoomToExtent(org.locationtech.jts.geom.Coordinate bottomLeft, org.locationtech.jts.geom.Coordinate topRight)
      Sets a map's visible area that contains the given geographical bounds with the maximum zoom level possible.

      To zoom to an extent more advanced way, use fit(FitOptions).

      Parameters:
      bottomLeft - bottom left point coordinates of visible area (SouthWest)
      topRight - top right point coordinates of visible area (NorthEast)
    • zoomToFeature

      public void zoomToFeature(Feature feature)
      Sets a map's visible area that contains envelope of the geometry from given feature.

      This is the convenience method that delegates to zoomToGeometry(Geometry).

      Parameters:
      feature - feature from which geometry will be zoomed to
    • zoomToGeometry

      public void zoomToGeometry(org.locationtech.jts.geom.Geometry geometry)
      Sets a map's visible area that contains envelope of the given geometry with the maximum zoom level possible.

      To zoom to a geometry more advanced way, use fit(FitOptions).

      Note: if the given geometry is a point, map will be centered to this point with the current zoom level.

      Parameters:
      geometry - geometry to zoom
    • fit

      public void fit(FitOptions options)
      Fits the given geometry or extent based on the given map size and border and provided options. For instance, if it is needed to specify maximum zoom level and animation we can do the following:
       map.fit(new FitOptions(feature)
           .withMaxZoom(9.0)
           .withDuration(1500)
           .withEasing(Easing.LINEAR));
       

      For more details see: View#fit() docs

      Parameters:
      options - options that configure zooming to an extent or geometry
    • addClickListener

      public com.vaadin.flow.shared.Registration addClickListener(com.vaadin.flow.component.ComponentEventListener<MapClickEvent> listener)
      Adds map click listener. Note, if the user makes double click on a map, the MapClickEvent will be fired twice.
      Parameters:
      listener - the listener to be added
      Returns:
      a registration object for removing an event listener
    • addSingleClickListener

      public com.vaadin.flow.shared.Registration addSingleClickListener(com.vaadin.flow.component.ComponentEventListener<MapSingleClickEvent> listener)
      Adds map single click listener. Single click means that an event won't be fired if the user makes double click.
      Parameters:
      listener - the listener to be added
      Returns:
      a registration object for removing an event listener
    • addDoubleClickListener

      public com.vaadin.flow.shared.Registration addDoubleClickListener(com.vaadin.flow.component.ComponentEventListener<MapDoubleClickEvent> listener)
      Adds map double click listener.
      Parameters:
      listener - the listener to be added
      Returns:
      a registration object for removing an event listener
    • addZoomChangedListener

      public com.vaadin.flow.shared.Registration addZoomChangedListener(com.vaadin.flow.component.ComponentEventListener<MapZoomChangedEvent> listener)
      Adds map zoom changed listener.
      Parameters:
      listener - the listener to be added
      Returns:
      a registration object for removing an event listener
    • addMoveEndListener

      public com.vaadin.flow.shared.Registration addMoveEndListener(com.vaadin.flow.component.ComponentEventListener<MapMoveEndEvent> listener)
      Adds map move end listener.
      Parameters:
      listener - the listener to be added
      Returns:
      a registration object for removing an event listener
    • getAdditionalPropertiesToUpdate

      protected Map<String,elemental.json.JsonValue> getAdditionalPropertiesToUpdate()
      Overrides:
      getAdditionalPropertiesToUpdate in class JmixMap
    • createSerializer

      protected JmixMapSerializer createSerializer()
      Overrides:
      createSerializer in class JmixMap
    • createMapOptions

      protected MapOptions createMapOptions()
      Overrides:
      createMapOptions in class JmixMap
    • fireFeatureClickEvent

      protected void fireFeatureClickEvent(EventBus eventBus, AbstractFeatureClickDomEvent event, Feature feature)
      Overrides:
      fireFeatureClickEvent in class JmixMap
    • fireSourceFeatureClickEvent

      protected void fireSourceFeatureClickEvent(EventBus eventBus, AbstractFeatureClickDomEvent event, Feature feature, AbstractFeatureSource source)
      Overrides:
      fireSourceFeatureClickEvent in class JmixMap
    • onMapClickDomEvent

      protected void onMapClickDomEvent(MapClickDomEvent event)
      Overrides:
      onMapClickDomEvent in class JmixMap
    • fireMapClickEvent

      protected void fireMapClickEvent(MapClickDomEvent domEvent)
    • onMapSingleClickDomEvent

      protected void onMapSingleClickDomEvent(MapSingleClickDomEvent event)
      Overrides:
      onMapSingleClickDomEvent in class JmixMap
    • fireMapSingleClickDomEvent

      protected void fireMapSingleClickDomEvent(MapSingleClickDomEvent domEvent)
    • onMapDoubleClickDomEvent

      protected void onMapDoubleClickDomEvent(MapDoubleClickDomEvent event)
      Overrides:
      onMapDoubleClickDomEvent in class JmixMap
    • fireMapDoubleClickDomEvent

      protected void fireMapDoubleClickDomEvent(MapDoubleClickDomEvent domEvent)
    • onMapMoveEndEvent

      protected void onMapMoveEndEvent(MapMoveEndDomEvent event)
      Overrides:
      onMapMoveEndEvent in class JmixMap
    • fireMapMoveEndEvent

      protected void fireMapMoveEndEvent(MapMoveEndDomEvent domEvent)
    • onMapZoomChangedEvent

      protected void onMapZoomChangedEvent(MapZoomChangedDomEvent domEvent)
      Overrides:
      onMapZoomChangedEvent in class JmixMap
    • fireMapZoomChangeEvent

      protected void fireMapZoomChangeEvent(MapZoomChangedDomEvent domEvent)
    • onDetach

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