All Implemented Interfaces:
Serializable
Direct Known Subclasses:
GeoMapView, NoOpMapView

public abstract class MapView extends MapObservableObject
See Also:
  • Field Details

    • extent

      protected Extent extent
    • showFullExtent

      protected Boolean showFullExtent
    • constrainOnlyCenter

      protected Boolean constrainOnlyCenter
    • smoothExtentConstraint

      protected Boolean smoothExtentConstraint
    • projection

      protected CRS projection
    • rotation

      protected Double rotation
    • maxZoom

      protected Double maxZoom
    • minZoom

      protected Double minZoom
    • zoom

      protected double zoom
    • currentExtent

      protected Extent currentExtent
  • Constructor Details

    • MapView

      public MapView()
  • Method Details

    • getExtent

      public Extent getExtent()
      Returns:
      view extent or null if not set
    • setExtent

      public void setExtent(Extent extent)
      Sets the view extent. This extent is a constraint that does not enable to move map visible area outside specified extent.

      Note, extent attribute is set only at creation time and cannot be changed at runtime.

      For more details see: View docs

      Parameters:
      extent - extent to set
    • getShowFullExtent

      public Boolean getShowFullExtent()
      Gets whether the view can be zoomed out far enough to show the whole configured extent, even when the viewport aspect ratio differs from it.
      Returns:
      true if the full extent may be shown, false if not, or null if not set (OpenLayers default is false)
    • setShowFullExtent

      public void setShowFullExtent(Boolean showFullExtent)
      Sets whether the view can be zoomed out far enough to show the whole configured extent. Useful together with setExtent(Extent) in responsive layouts, where the container aspect ratio may differ from the extent. The OpenLayers default is false.

      Note, this attribute is set only at creation time and cannot be changed at runtime.

      For more details see: View docs

      Parameters:
      showFullExtent - whether to allow showing the full extent
    • getConstrainOnlyCenter

      public Boolean getConstrainOnlyCenter()
      Gets whether the extent constraint applies to the view center only rather than to the whole viewport.
      Returns:
      true if only the center is constrained, false if the whole viewport is, or null if not set (OpenLayers default is false)
    • setConstrainOnlyCenter

      public void setConstrainOnlyCenter(Boolean constrainOnlyCenter)
      Sets whether the extent constraint applies to the view center only. When true, the center cannot leave the extent, but the viewport may. The OpenLayers default is false.

      Note, this attribute is set only at creation time and cannot be changed at runtime.

      For more details see: View docs

      Parameters:
      constrainOnlyCenter - whether to constrain only the center
    • getSmoothExtentConstraint

      public Boolean getSmoothExtentConstraint()
      Gets whether the extent constraint is applied smoothly, allowing the view to move slightly outside the extent before being constrained back.
      Returns:
      true if the constraint is applied smoothly, false if strictly, or null if not set (OpenLayers default is true)
    • setSmoothExtentConstraint

      public void setSmoothExtentConstraint(Boolean smoothExtentConstraint)
      Sets whether the extent constraint is applied smoothly. When true, the view may move slightly outside the extent and is eased back; when false, the constraint is hard. The OpenLayers default is true.

      Note, this attribute is set only at creation time and cannot be changed at runtime.

      For more details see: View docs

      Parameters:
      smoothExtentConstraint - whether to apply the extent constraint smoothly
    • getProjection

      public CRS getProjection()
      Returns:
      projection or null if not set
    • setProjection

      public void setProjection(CRS projection)
      Sets the projection to view. The default projection is "EPSG:3857" (Pseudo-Mercator). If a source (based on TileImageSource or ImageSource) has a projection different from the current map view’s projection then the reprojection happens automatically.

      There are available two options:

      • CRS value - sets value as CRS constant, e.g. CRS.EPSG_4326 or as anonymous implementation, e.g. setProjection(() -> "EPSG:4326");.
      • Projection value - sets custom projection.
      Note, projection attribute is set only at creation time and cannot be changed at runtime.
      Parameters:
      projection - projection to set
    • getRotation

      public Double getRotation()
      Note, the rotation can be updated from the client-side and can be available after the first view change.
      Returns:
      the rotation in radians or null if not set or is not updated from the client-side
    • setRotation

      public void setRotation(Double rotation)
      Sets the rotation for the view in radians (positive rotation clockwise, 0 means North).

      For more details see: setRotation docs

      Parameters:
      rotation - rotation to set
    • getMaxZoom

      public Double getMaxZoom()
      Returns:
      maximum zoom level or null if not set
    • setMaxZoom

      public void setMaxZoom(Double maxZoom)
      Sets the maximum zoom level for the view. The default value is 28.

      For more details see: setMaxZoom docs

      Parameters:
      maxZoom - maximum zoom to set
    • getMinZoom

      public Double getMinZoom()
      Returns:
      minimum zoom level or null if not set
    • setMinZoom

      public void setMinZoom(Double minZoom)
      Sets a minimum zoom level for the view. The default value is 0.

      For more details see: setMinZoom docs

      Parameters:
      minZoom - minimum zoom level to set
    • getZoom

      public double getZoom()
      Returns:
      zoom level
    • setZoom

      public void setZoom(double zoom)
      Zooms to a specific zoom level. The zoom level starts at 0 as the most zoomed-out level, and then continually increases to zoom further in.
      Parameters:
      zoom - zoom level
    • getCurrentExtent

      public Extent getCurrentExtent()
      Gets the extent (or bounding box) of the currently visible area.

      Note, the extent is calculated on the client-side and will only be available after the first view change.

      Returns:
      the coordinates of the view's extent
    • getType

      protected String getType()
      Specified by:
      getType in class MapObservableObject
    • onStateChangeEvent

      protected void onStateChangeEvent(MapView.StateChangeEvent event)