All Implemented Interfaces:
Serializable

public class View extends AbstractConfigurationObject
Represents a map's viewport, responsible for changing properties like center and zoom level
See Also:
  • Constructor Details

    • View

      public View()
      Constructs a new view using EPSG:3857 / Web Mercator Sphere coordinate projection by default. Unless you are using a custom map service that uses a different projection, this is what you want.
    • View

      public View(String projection)
      Constructs a new view using a custom coordinate projection. A custom view projection is only necessary when using a map service and corresponding Source that uses a projection other than EPSG:3857 / Web Mercator Sphere projection.
      Parameters:
      projection - the custom coordinate projection to use
  • Method Details

    • getType

      public String getType()
      Description copied from class: AbstractConfigurationObject
      The unique type name of this class. Used by the client-side synchronization mechanism to determine which OpenLayers class to synchronize into.
      Specified by:
      getType in class AbstractConfigurationObject
    • getCenter

      public Coordinate getCenter()
      Gets center coordinates of the view
      Returns:
      center of the view
    • setCenter

      public void setCenter(Coordinate center)
      Sets the center of the map's viewport. Coordinates must be specified in the map's user projection, which by default is EPSG:4326, also referred to as GPS coordinates. If the user projection has been changed using Map.setUserProjection(String), then coordinates must be specified in that projection instead.

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

      Parameters:
      center - coordinates of the center of the view
    • getRotation

      public double getRotation()
      Get rotation of the view, defaults to 0
      Returns:
      current rotation in radians
    • setRotation

      public void setRotation(double rotation)
      Sets the rotation of the view in radians
      Parameters:
      rotation - the rotation in radians format
    • getZoom

      public double getZoom()
      Gets zoom level of the view, defaults to 0
      Returns:
      current zoom level
    • setZoom

      public void setZoom(double zoom)
      Sets the zoom level of the view. 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 to 28. In practical terms, the level of detail of the map data that a map service provides determines how useful higher zoom levels are.
      Parameters:
      zoom - new zoom level
    • getProjection

      public String getProjection()
      Gets the projection of the view, which defaults to EPSG:3857 / Web Mercator Sphere projection
      Returns:
      the projection of the view
    • getExtent

      public Extent getExtent()
      Gets the extent (or bounding box) of the view's currently visible area. Can be used to check whether a specific coordinate is within the viewport.

      NOTE: The extent is calculated on the client-side and will only be available after the first view change event.

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

      public void updateInternalViewState(Coordinate center, double rotation, double zoom, Extent extent)
      Updates internal state of view to the latest values received from client.

      For internal use only.

      Parameters:
      center - the updated center coordinates
      rotation - the updated rotation
      zoom - the updated zoom level
      extent - the updated extent