Optional
opt_options: ViewOptionsView options.
An ol.View object represents a simple 2D view of the map.
This is the object to act upon to change the center, resolution, and rotation of the map.
An ol.View
is determined by three states: center
, resolution
,
and rotation
. Each state has a corresponding getter and setter, e.g.
getCenter
and setCenter
for the center
state.
An ol.View
has a projection
. The projection determines the
coordinate system of the center, and its units determine the units of the
resolution (projection units per pixel). The default projection is
Spherical Mercator (EPSG:3857).
setCenter
, setResolution
and setRotation
can be used to change the
states of the view. Any value can be passed to the setters. And the value
that is passed to a setter will effectively be the value set in the view,
and returned by the corresponding getter.
But an ol.View
object also has a resolution constraint, a
rotation constraint and a center constraint.
As said above, no constraints are applied when the setters are used to set
new states for the view. Applying constraints is done explicitly through
the use of the constrain*
functions (constrainResolution
and
constrainRotation
and constrainCenter
).
The main users of the constraints are the interactions and the controls. For example, double-clicking on the map changes the view to the "next" resolution. And releasing the fingers after pinch-zooming snaps to the closest resolution (with an animation).
The resolution constraint snaps to specific resolutions. It is
determined by the following options: resolutions
, maxResolution
,
maxZoom
, and zoomFactor
. If resolutions
is set, the other three
options are ignored. See documentation for each option for more
information.
The rotation constraint snaps to specific angles. It is determined
by the following options: enableRotation
and constrainRotation
.
By default the rotation value is snapped to zero when approaching the
horizontal.
The center constraint is determined by the extent
option. By
default the center is not constrained at all.
stable
Animate the view. The view's center, zoom (or resolution), and rotation can be animated for smooth transitions between view states.
Rest
...var_args: (AnimateOptions | AnimateCallback)[]Animation options.
experimental
Calculate the extent for the current view state and the passed size.
The size is the pixel dimensions of the box into which the calculated extent
should fit. In most cases you want to get the extent of the entire map,
that is map.getSize()
.
Box pixel size.
Extent.
stable
Center on coordinate and view position.
Coordinate.
Box pixel size.
Position on the view to center on.
Get the constrained center of this view.
Center.
Constrained center.
Fit the given geometry or extent based on the given map size and border.
The size is pixel dimensions of the box to fit the extent into.
In most cases you will want to use the map size, that is map.getSize()
.
Takes care of the map angle.
Geometry.
Box pixel size.
Optional
opt_options: FitOptionsOptions.
Get the view center.
The center of the view.
stable
Get the view projection.
The projection of the view.
stable
Listen for a certain type of event.
The event type or array of event types.
The listener function.
Optional
opt_this: ObjectThe object to use as this
in listener
.
Unique key for the listener. If called with an array of event types as the first argument, the return will be an array of keys.
stable
Listen once for a certain type of event.
The event type or array of event types.
The listener function.
Optional
opt_this: ObjectThe object to use as this
in listener
.
Unique key for the listener. If called with an array of event types as the first argument, the return will be an array of keys.
stable
Rotate the view around a given coordinate.
New rotation value for the view.
Optional
opt_anchor: CoordinateThe rotation center.
stable
Set the center of the current view.
The center of the view.
stable
Sets a collection of key-value pairs. Note that this changes any existing properties and adds new ones (it does not remove any existing properties).
Values.
Optional
opt_silent: booleanUpdate without triggering an event.
stable
Static
unRemoves an event listener using the key returned by on()
or once()
.
Note that using the ol.Observable.unByKey static function is to
be preferred.
stable
Generated using TypeDoc
Classdesc
An ol.View object represents a simple 2D view of the map.
This is the object to act upon to change the center, resolution, and rotation of the map.
The view states
An
ol.View
is determined by three states:center
,resolution
, androtation
. Each state has a corresponding getter and setter, e.g.getCenter
andsetCenter
for thecenter
state.An
ol.View
has aprojection
. The projection determines the coordinate system of the center, and its units determine the units of the resolution (projection units per pixel). The default projection is Spherical Mercator (EPSG:3857).The constraints
setCenter
,setResolution
andsetRotation
can be used to change the states of the view. Any value can be passed to the setters. And the value that is passed to a setter will effectively be the value set in the view, and returned by the corresponding getter.But an
ol.View
object also has a resolution constraint, a rotation constraint and a center constraint.As said above, no constraints are applied when the setters are used to set new states for the view. Applying constraints is done explicitly through the use of the
constrain*
functions (constrainResolution
andconstrainRotation
andconstrainCenter
).The main users of the constraints are the interactions and the controls. For example, double-clicking on the map changes the view to the "next" resolution. And releasing the fingers after pinch-zooming snaps to the closest resolution (with an animation).
The resolution constraint snaps to specific resolutions. It is determined by the following options:
resolutions
,maxResolution
,maxZoom
, andzoomFactor
. Ifresolutions
is set, the other three options are ignored. See documentation for each option for more information.The rotation constraint snaps to specific angles. It is determined by the following options:
enableRotation
andconstrainRotation
. By default the rotation value is snapped to zero when approaching the horizontal.The center constraint is determined by the
extent
option. By default the center is not constrained at all.Param: opt_options
View options.
Api
stable