ProtecteddisposedThe object has already been disposed.
Padding (in css pixels).
If the map viewport is partially covered with other content (overlays) along
its edges, this setting allows to shift the center of the viewport away from that
content. The order of the values in the array is top, right, bottom, left.
The default is no padding, which is equivalent to [0, 0, 0, 0].
Key name.
Listener.
Type.
Listener.
Adds relative coordinates to the center of the view. Any extent constraint will apply.
Relative value to add.
Multiply the view resolution by a ratio, optionally using an anchor. Any resolution constraint will apply.
The ratio to apply on the view resolution.
Optionalanchor: Coordinate
The origin of the transformation.
Relative value to add to the zoom rotation, in radians.
Optionalanchor: Coordinate
The rotation center.
Animate the view. The view's center, zoom (or resolution), and rotation can be animated for smooth transitions between view states. For example, to animate the view to a new zoom level:
view.animate({zoom: view.getZoom() + 1});
By default, the animation lasts one second and uses in-and-out easing. You
can customize this behavior by including duration (in milliseconds) and
easing options (see :ol/easing).
To chain together multiple animations, call the method with multiple animation objects. For example, to first zoom and then pan:
view.animate({zoom: 10}, {center: [0, 0]});
If you provide a function as the last argument to the animate method, it
will get called at the end of an animation series. The callback will be
called with true if the animation series completed on its own or false
if it was cancelled.
Animations are cancelled by user interactions (e.g. dragging the map) or by
calling view.setCenter(), view.setResolution(), or view.setRotation()
(or another method that calls one of these).
Set up the view with the given options.
View options.
ProtectedapplyProtected
Apply any properties from another object without triggering events.
The source object.
Target rotation.
Rotation anchor.
Center for rotation and anchor.
Calculates the shift between map and viewport center.
Center.
Resolution.
Rotation.
Size.
Center shift.
Target resolution.
Zoom anchor.
Center for resolution and anchor.
Calculate the extent for the current view state and the passed box size.
Optionalsize: Size
The pixel dimensions of the box
into which the calculated extent should fit. Defaults to the size of the
map the view is associated with.
If no map or multiple maps are connected to the view, provide the desired
box size (e.g. map.getSize()).
Extent.
Optionalsize: Size
Box pixel size. If not provided, the map's last known viewport size will be used.
Extent.
Coordinate.
Box pixel size.
Position on the view to center on.
Dispatches an event and calls all listeners listening for events
of this type. The event parameter can either be a string or an
Object with a type property.
Event object.
false if anyone called preventDefault on the
event object or if any of the listeners returned false.
Clean up.
ProtecteddisposeProtected
Extension point for disposable objects.
Notify the View that an interaction has ended. The view state will be resolved to a stable one if needed (depending on its constraints).
Optionalduration: number
Animation duration in ms.
OptionalresolutionDirection: number
Which direction to zoom.
Optionalanchor: Coordinate
The origin of the transformation.
Notify the View that an interaction has ended. The view state will be resolved to a stable one if needed (depending on its constraints).
Optionalduration: number
Animation duration in ms.
OptionalresolutionDirection: number
Which direction to zoom.
Optionalanchor: Coordinate
The origin of the transformation.
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.
The geometry or extent to fit the view to.
Optionaloptions: FitOptions
Options.
The geometry.
Optionaloptions: FitOptions
Options.
Get the view center without transforming to user projection.
The center of the view.
Get a valid position for the view center according to the current constraints.
Target center position.
OptionaltargetResolution: number
Target resolution. If not supplied, the current one will be used. This is useful to guess a valid center position at a different zoom level.
Valid center position.
Get a valid resolution according to the current view constraints.
Target resolution.
Optionaldirection: number
Indicate which resolution should be used by a renderer if the view resolution does not match any resolution of the tile source. If 0, the nearest resolution will be used. If 1, the nearest lower resolution will be used. If -1, the nearest higher resolution will be used.
Valid resolution.
Get a valid zoom level according to the current view constraints.
Target zoom.
Optionaldirection: number
Indicate which resolution should be used by a renderer if the view resolution does not match any resolution of the tile source. If 0, the nearest resolution will be used. If 1, the nearest lower resolution will be used. If -1, the nearest higher resolution will be used.
Valid zoom level.
Resolution constraint is set
Constraints.
Optionalhints: number[]
Destination array.
Hint.
Get the listeners for a specified event type. Listeners are returned in the order that they will be called in.
Type.
Listeners.
Get an object of all property names and values.
Object.
Get the resolution for a provided extent (in map units) and size (in pixels).
Extent.
Optionalsize: Size
Box pixel size.
The resolution at which the provided extent will render at the given size.
Return a function that returns a value between 0 and 1 for a resolution. Exponential scaling is assumed.
Optionalpower: number
Power.
Resolution for value function.
View state.
Get an updated version of the view options used to construct the view. The current resolution (or zoom), center, and rotation are applied to any stored options. The provided options can be used to apply new min/max zoom or resolution limits.
New options to be applied.
New options updated with the current view state.
Return a function that returns a resolution for a value between 0 and 1. Exponential scaling is assumed.
Optionalpower: number
Power.
Value for resolution function.
Like FrameState, but just viewState and extent.
Optionaltype: string
Type. If not provided,
true will be returned if this event target has any listeners.
Has listeners.
The object has properties.
Is defined.
Key name.
Old value.
ProtectedonceProtectedonKey name.
Listener.
Type.
Listener.
If any constraints need to be applied, an animation will be triggered. This is typically done on interaction end. Note: calling this with a duration of 0 will apply the constrained values straight away, without animation.
Optionalduration: number
The animation duration in ms.
OptionalresolutionDirection: number
Which direction to zoom.
Optionalanchor: Coordinate
The origin of the transformation.
Calculate rotated extent
The geometry.
The rotated extent for the geometry.
Set the center using the view projection (not the user projection).
The center of the view.
Hint.
Delta.
New value.
Stores the viewport size on the view. The viewport size is not read every time from the DOM to avoid performance hit and layout reflow. This should be done on map size change. Note: the constraints are not resolved during an animation to avoid stopping it
Optionalsize: Size
Viewport size; if undefined, [100, 100] is assumed
ProtectedunProtected
Unlisten for a certain type of event.
Type.
Listener.
Update all animations.
Classdesc
A 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.
A 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 Web Mercator (EPSG:3857).The view states
A View is determined by three states:
center,resolution, androtation. Each state has a corresponding getter and setter, e.g.getCenterandsetCenterfor thecenterstate.The
zoomstate is actually not saved on the view: all computations internally use theresolutionstate. Still, thesetZoomandgetZoommethods are available, as well asgetResolutionForZoomandgetZoomForResolutionto switch from one system to the other.The constraints
setCenter,setResolutionandsetRotationcan be used to change the states of the view, but any constraint defined in the constructor will be applied along the way.A View object can have a resolution constraint, a rotation constraint and a center constraint.
The resolution constraint typically restricts min/max values and snaps to specific resolutions. It is determined by the following options:
resolutions,maxResolution,maxZoomandzoomFactor. Ifresolutionsis set, the other three options are ignored. See documentation for each option for more information. By default, the view only has a min/max restriction and allow intermediary zoom levels when pinch-zooming for example.The rotation constraint snaps to specific angles. It is determined by the following options:
enableRotationandconstrainRotation. By default rotation is allowed and its value is snapped to zero when approaching the horizontal.The center constraint is determined by the
extentoption. By default the view center is not constrained at all.Changing the view state
It is important to note that
setZoom,setResolution,setCenterandsetRotationare subject to the above mentioned constraints. As such, it may sometimes not be possible to know in advance the resulting state of the View. For example, callingsetResolution(10)does not guarantee thatgetResolution()will return10.A consequence of this is that, when applying a delta on the view state, one should use
adjustCenter,adjustRotation,adjustZoomandadjustResolutionrather than the corresponding setters. This will let view do its internal computations. Besides, theadjust*methods also take ananchorargument which allows specifying an origin for the transformation.Interacting with the view
View constraints are usually only applied when the view is at rest, meaning that no interaction or animation is ongoing. As such, if the user puts the view in a state that is not equivalent to a constrained one (e.g. rotating the view when the snap angle is 0), an animation will be triggered at the interaction end to put back the view to a stable state;
Api