StoryMapJS API
    Preparing search index...

    Interface OlView

    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).

    A 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.

    The zoom state is actually not saved on the view: all computations internally use the resolution state. Still, the setZoom and getZoom methods are available, as well as getResolutionForZoom and getZoomForResolution to switch from one system to the other.

    setCenter, setResolution and setRotation can 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, maxZoom and zoomFactor. If resolutions is 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: enableRotation and constrainRotation. By default rotation is allowed and its value is snapped to zero when approaching the horizontal.

    The center constraint is determined by the extent option. By default the view center is not constrained at all.

    It is important to note that setZoom, setResolution, setCenter and setRotation are 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, calling setResolution(10) does not guarantee that getResolution() will return 10.

    A consequence of this is that, when applying a delta on the view state, one should use adjustCenter, adjustRotation, adjustZoom and adjustResolution rather than the corresponding setters. This will let view do its internal computations. Besides, the adjust* methods also take an anchor argument which allows specifying an origin for the transformation.

    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;

    interface OlView {
        disposed: boolean;
        on: ViewOnSignature<EventsKey>;
        once: ViewOnSignature<EventsKey>;
        un: ViewOnSignature<void>;
        get padding(): number[] | undefined;
        set padding(padding: number[] | undefined): void;
        addChangeListener(key: string, listener: Listener): void;
        addEventListener(type: string, listener: Listener): void;
        adjustCenter(deltaCoordinates: Coordinate): void;
        adjustCenterInternal(deltaCoordinates: Coordinate): void;
        adjustResolution(ratio: number, anchor?: Coordinate): void;
        adjustResolutionInternal(ratio: number, anchor?: Coordinate): void;
        adjustRotation(delta: number, anchor?: Coordinate): void;
        adjustRotationInternal(delta: number, anchor?: Coordinate): void;
        adjustZoom(delta: number, anchor?: Coordinate): void;
        animate(...args: (AnimationOptions | ((arg0: boolean) => void))[]): void;
        animateInternal(
            ...args: (AnimationOptions | ((arg0: boolean) => void))[],
        ): void;
        applyOptions_(options: ViewOptions): void;
        applyProperties(source: BaseObject): void;
        beginInteraction(): void;
        calculateCenterRotate(
            rotation: number,
            anchor: Coordinate,
        ): Coordinate | undefined;
        calculateCenterShift(
            center: Coordinate,
            resolution: number,
            rotation: number,
            size: Size,
        ): number[] | undefined;
        calculateCenterZoom(
            resolution: number,
            anchor: Coordinate,
        ): Coordinate | undefined;
        calculateExtent(size?: Size): Extent;
        calculateExtentInternal(size?: Size): Extent;
        cancelAnimations(): void;
        centerOn(coordinate: Coordinate, size: Size, position: Pixel): void;
        centerOnInternal(coordinate: Coordinate, size: Size, position: Pixel): void;
        changed(): void;
        dispatchEvent(event: string | BaseEvent): boolean | undefined;
        dispose(): void;
        disposeInternal(): void;
        endInteraction(
            duration?: number,
            resolutionDirection?: number,
            anchor?: Coordinate,
        ): void;
        endInteractionInternal(
            duration?: number,
            resolutionDirection?: number,
            anchor?: Coordinate,
        ): void;
        fit(geometryOrExtent: Extent | SimpleGeometry, options?: FitOptions): void;
        fitInternal(geometry: SimpleGeometry, options?: FitOptions): void;
        get(key: string): any;
        getAnimating(): boolean;
        getCenter(): Coordinate | undefined;
        getCenterInternal(): Coordinate | undefined;
        getConstrainedCenter(
            targetCenter: Coordinate | undefined,
            targetResolution?: number,
        ): Coordinate | undefined;
        getConstrainedResolution(
            targetResolution: number | undefined,
            direction?: number,
        ): number | undefined;
        getConstrainedZoom(
            targetZoom: number | undefined,
            direction?: number,
        ): number | undefined;
        getConstrainResolution(): boolean;
        getConstraints(): Constraints;
        getHints(hints?: number[]): number[];
        getInteracting(): boolean;
        getKeys(): string[];
        getListeners(type: string): Listener[] | undefined;
        getMaxResolution(): number;
        getMaxZoom(): number;
        getMinResolution(): number;
        getMinZoom(): number;
        getProjection(): OlProjection;
        getProperties(): NoInfer<ViewOptions>;
        getPropertiesInternal(): Partial<NoInfer<ViewOptions>> | null;
        getResolution(): number | undefined;
        getResolutionForExtent(extent: Extent, size?: Size): number;
        getResolutionForExtentInternal(extent: Extent, size?: Size): number;
        getResolutionForValueFunction(power?: number): (arg0: number) => number;
        getResolutionForZoom(zoom: number): number;
        getResolutions(): number[] | undefined;
        getRevision(): number;
        getRotation(): number;
        getState(): State;
        getUpdatedOptions_(newOptions: ViewOptions): ViewOptions;
        getValueForResolutionFunction(power?: number): (arg0: number) => number;
        getViewStateAndExtent(): ViewStateLayerStateExtent;
        getZoom(): number | undefined;
        getZoomForResolution(resolution: number): number | undefined;
        hasListener(type?: string): boolean;
        hasProperties(): boolean;
        isDef(): boolean;
        notify(key: string, oldValue: any): void;
        onceInternal(
            type: string | string[],
            listener: (arg0: Event | BaseEvent) => unknown,
        ): EventsKey | EventsKey[];
        onInternal(
            type: string | string[],
            listener: (arg0: Event | BaseEvent) => unknown,
        ): EventsKey | EventsKey[];
        removeChangeListener(key: string, listener: Listener): void;
        removeEventListener(type: string, listener: Listener): void;
        resolveConstraints(
            duration?: number,
            resolutionDirection?: number,
            anchor?: Coordinate,
        ): void;
        rotatedExtentForGeometry(geometry: SimpleGeometry): Extent;
        set(key: string, value: any, silent?: boolean): void;
        setCenter(center: Coordinate | undefined): void;
        setCenterInternal(center: Coordinate | undefined): void;
        setConstrainResolution(enabled: boolean): void;
        setHint(hint: any, delta: number): number;
        setMaxZoom(zoom: number): void;
        setMinZoom(zoom: number): void;
        setProperties(values: Partial<NoInfer<Properties>>, silent?: boolean): void;
        setResolution(resolution: number | undefined): void;
        setRotation(rotation: number): void;
        setViewportSize(size?: Size): void;
        setZoom(zoom: number): void;
        unInternal(
            type: string | string[],
            listener: (arg0: Event | BaseEvent) => unknown,
        ): void;
        unset(key: string, silent?: boolean): void;
        updateAnimations_(): void;
    }

    Hierarchy

    • BaseObject<ViewOptions>
      • OlView
    Index
    disposed: boolean

    The object has already been disposed.

    on: ViewOnSignature<EventsKey>
    once: ViewOnSignature<EventsKey>
    un: ViewOnSignature<void>
    • get padding(): number[] | undefined

      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].

      Returns number[] | undefined

    • set padding(padding: number[] | undefined): void

      Parameters

      • padding: number[] | undefined

      Returns void

    • Parameters

      • key: string

        Key name.

      • listener: Listener

        Listener.

      Returns void

    • Parameters

      • type: string

        Type.

      • listener: Listener

        Listener.

      Returns void

    • Adds relative coordinates to the center of the view. Any extent constraint will apply.

      Parameters

      • deltaCoordinates: Coordinate

        Relative value to add.

      Returns void

    • Adds relative coordinates to the center of the view. Any extent constraint will apply.

      Parameters

      • deltaCoordinates: Coordinate

        Relative value to add.

      Returns void

    • Multiply the view resolution by a ratio, optionally using an anchor. Any resolution constraint will apply.

      Parameters

      • ratio: number

        The ratio to apply on the view resolution.

      • Optionalanchor: Coordinate

        The origin of the transformation.

      Returns void

    • Multiply the view resolution by a ratio, optionally using an anchor. Any resolution constraint will apply.

      Parameters

      • ratio: number

        The ratio to apply on the view resolution.

      • Optionalanchor: Coordinate

        The origin of the transformation.

      Returns void

    • Adds a value to the view rotation, optionally using an anchor. Any rotation constraint will apply.

      Parameters

      • delta: number

        Relative value to add to the zoom rotation, in radians.

      • Optionalanchor: Coordinate

        The rotation center.

      Returns void

    • Parameters

      • delta: number

        Relative value to add to the zoom rotation, in radians.

      • Optionalanchor: Coordinate

        The rotation center.

      Returns void

    • Adds a value to the view zoom level, optionally using an anchor. Any resolution constraint will apply.

      Parameters

      • delta: number

        Relative value to add to the zoom level.

      • Optionalanchor: Coordinate

        The origin of the transformation.

      Returns void

    • 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).

      Parameters

      • ...args: (AnimationOptions | ((arg0: boolean) => void))[]

      Returns void

    • Parameters

      • ...args: (AnimationOptions | ((arg0: boolean) => void))[]

      Returns void

    • Set up the view with the given options.

      Parameters

      • options: ViewOptions

        View options.

      Returns void

    • Protected

      Apply any properties from another object without triggering events.

      Parameters

      • source: BaseObject

        The source object.

      Returns void

    • Notify the View that an interaction has started. The view state will be resolved to a stable one if needed (depending on its constraints).

      Returns void

    • Parameters

      • rotation: number

        Target rotation.

      • anchor: Coordinate

        Rotation anchor.

      Returns Coordinate | undefined

      Center for rotation and anchor.

    • Calculates the shift between map and viewport center.

      Parameters

      • center: Coordinate

        Center.

      • resolution: number

        Resolution.

      • rotation: number

        Rotation.

      • size: Size

        Size.

      Returns number[] | undefined

      Center shift.

    • Parameters

      • resolution: number

        Target resolution.

      • anchor: Coordinate

        Zoom anchor.

      Returns Coordinate | undefined

      Center for resolution and anchor.

    • Calculate the extent for the current view state and the passed box size.

      Parameters

      • 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()).

      Returns Extent

      Extent.

    • Parameters

      • Optionalsize: Size

        Box pixel size. If not provided, the map's last known viewport size will be used.

      Returns Extent

      Extent.

    • Cancel any ongoing animations.

      Returns void

    • Center on coordinate and view position.

      Parameters

      • coordinate: Coordinate

        Coordinate.

      • size: Size

        Box pixel size.

      • position: Pixel

        Position on the view to center on.

      Returns void

    • Parameters

      • coordinate: Coordinate

        Coordinate.

      • size: Size

        Box pixel size.

      • position: Pixel

        Position on the view to center on.

      Returns void

    • Increases the revision counter and dispatches a 'change' event.

      Returns void

    • 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.

      Parameters

      • event: string | BaseEvent

        Event object.

      Returns boolean | undefined

      false if anyone called preventDefault on the event object or if any of the listeners returned false.

    • Clean up.

      Returns void

    • Protected

      Extension point for disposable objects.

      Returns void

    • Notify the View that an interaction has ended. The view state will be resolved to a stable one if needed (depending on its constraints).

      Parameters

      • Optionalduration: number

        Animation duration in ms.

      • OptionalresolutionDirection: number

        Which direction to zoom.

      • Optionalanchor: Coordinate

        The origin of the transformation.

      Returns void

    • Notify the View that an interaction has ended. The view state will be resolved to a stable one if needed (depending on its constraints).

      Parameters

      • Optionalduration: number

        Animation duration in ms.

      • OptionalresolutionDirection: number

        Which direction to zoom.

      • Optionalanchor: Coordinate

        The origin of the transformation.

      Returns void

    • 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.

      Parameters

      • geometryOrExtent: Extent | SimpleGeometry

        The geometry or extent to fit the view to.

      • Optionaloptions: FitOptions

        Options.

      Returns void

    • Parameters

      • geometry: SimpleGeometry

        The geometry.

      • Optionaloptions: FitOptions

        Options.

      Returns void

    • Gets a value.

      Parameters

      • key: string

        Key name.

      Returns any

      Value.

    • Determine if the view is being animated.

      Returns boolean

      The view is being animated.

    • Get the view center.

      Returns Coordinate | undefined

      The center of the view.

    • Get the view center without transforming to user projection.

      Returns Coordinate | undefined

      The center of the view.

    • Get a valid position for the view center according to the current constraints.

      Parameters

      • targetCenter: Coordinate | undefined

        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.

      Returns Coordinate | undefined

      Valid center position.

    • Get a valid resolution according to the current view constraints.

      Parameters

      • targetResolution: number | undefined

        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.

      Returns number | undefined

      Valid resolution.

    • Get a valid zoom level according to the current view constraints.

      Parameters

      • targetZoom: number | undefined

        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.

      Returns number | undefined

      Valid zoom level.

    • Returns boolean

      Resolution constraint is set

    • Returns Constraints

      Constraints.

    • Parameters

      • Optionalhints: number[]

        Destination array.

      Returns number[]

      Hint.

    • Determine if the user is interacting with the view, such as panning or zooming.

      Returns boolean

      The view is being interacted with.

    • Get a list of object property names.

      Returns string[]

      List of property names.

    • Get the listeners for a specified event type. Listeners are returned in the order that they will be called in.

      Parameters

      • type: string

        Type.

      Returns Listener[] | undefined

      Listeners.

    • Get the maximum resolution of the view.

      Returns number

      The maximum resolution of the view.

    • Get the maximum zoom level for the view.

      Returns number

      The maximum zoom level.

    • Get the minimum resolution of the view.

      Returns number

      The minimum resolution of the view.

    • Get the minimum zoom level for the view.

      Returns number

      The minimum zoom level.

    • Get the view projection.

      Returns OlProjection

      The projection of the view.

    • Get an object of all property names and values.

      Returns NoInfer<ViewOptions>

      Object.

    • Get an object of all property names and values.

      Returns Partial<NoInfer<ViewOptions>> | null

      Object.

    • Get the view resolution.

      Returns number | undefined

      The resolution of the view.

    • Get the resolution for a provided extent (in map units) and size (in pixels).

      Parameters

      • extent: Extent

        Extent.

      • Optionalsize: Size

        Box pixel size.

      Returns number

      The resolution at which the provided extent will render at the given size.

    • Get the resolution for a provided extent (in map units) and size (in pixels).

      Parameters

      • extent: Extent

        Extent.

      • Optionalsize: Size

        Box pixel size.

      Returns number

      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.

      Parameters

      • Optionalpower: number

        Power.

      Returns (arg0: number) => number

      Resolution for value function.

    • Get the resolution for a zoom level.

      Parameters

      • zoom: number

        Zoom level.

      Returns number

      The view resolution for the provided zoom level.

    • Get the resolutions for the view. This returns the array of resolutions passed to the constructor of the View, or undefined if none were given.

      Returns number[] | undefined

      The resolutions of the view.

    • Get the version number for this object. Each time the object is modified, its version number will be incremented.

      Returns number

      Revision.

    • Get the view rotation.

      Returns number

      The rotation of the view in radians.

    • Returns State

      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.

      Parameters

      • newOptions: ViewOptions

        New options to be applied.

      Returns ViewOptions

      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.

      Parameters

      • Optionalpower: number

        Power.

      Returns (arg0: number) => number

      Value for resolution function.

    • Returns ViewStateLayerStateExtent

      Like FrameState, but just viewState and extent.

    • Get the current zoom level. This method may return non-integer zoom levels if the view does not constrain the resolution, or if an interaction or animation is underway.

      Returns number | undefined

      Zoom.

    • Get the zoom level for a resolution.

      Parameters

      • resolution: number

        The resolution.

      Returns number | undefined

      The zoom level for the provided resolution.

    • Parameters

      • Optionaltype: string

        Type. If not provided, true will be returned if this event target has any listeners.

      Returns boolean

      Has listeners.

    • Returns boolean

      The object has properties.

    • Returns boolean

      Is defined.

    • Parameters

      • key: string

        Key name.

      • oldValue: any

        Old value.

      Returns void

    • Protected

      Parameters

      • type: string | string[]

        Type.

      • listener: (arg0: Event | BaseEvent) => unknown

        Listener.

      Returns EventsKey | EventsKey[]

      Event key.

    • Protected

      Parameters

      • type: string | string[]

        Type.

      • listener: (arg0: Event | BaseEvent) => unknown

        Listener.

      Returns EventsKey | EventsKey[]

      Event key.

    • Parameters

      • key: string

        Key name.

      • listener: Listener

        Listener.

      Returns void

    • Parameters

      • type: string

        Type.

      • listener: Listener

        Listener.

      Returns void

    • 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.

      Parameters

      • Optionalduration: number

        The animation duration in ms.

      • OptionalresolutionDirection: number

        Which direction to zoom.

      • Optionalanchor: Coordinate

        The origin of the transformation.

      Returns void

    • Calculate rotated extent

      Parameters

      • geometry: SimpleGeometry

        The geometry.

      Returns Extent

      The rotated extent for the geometry.

    • Sets a value.

      Parameters

      • key: string

        Key name.

      • value: any

        Value.

      • Optionalsilent: boolean

        Update without triggering an event.

      Returns void

    • Set the center of the current view. Any extent constraint will apply.

      Parameters

      • center: Coordinate | undefined

        The center of the view.

      Returns void

    • Set the center using the view projection (not the user projection).

      Parameters

      • center: Coordinate | undefined

        The center of the view.

      Returns void

    • Set whether the view should allow intermediary zoom levels.

      Parameters

      • enabled: boolean

        Whether the resolution is constrained.

      Returns void

    • Parameters

      • hint: any

        Hint.

      • delta: number

        Delta.

      Returns number

      New value.

    • Set a new maximum zoom level for the view.

      Parameters

      • zoom: number

        The maximum zoom level.

      Returns void

    • Set a new minimum zoom level for the view.

      Parameters

      • zoom: number

        The minimum zoom level.

      Returns void

    • 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).

      Parameters

      • values: Partial<NoInfer<Properties>>

        Values.

      • Optionalsilent: boolean

        Update without triggering an event.

      Returns void

    • Set the resolution for this view. Any resolution constraint will apply.

      Parameters

      • resolution: number | undefined

        The resolution of the view.

      Returns void

    • Set the rotation for this view. Any rotation constraint will apply.

      Parameters

      • rotation: number

        The rotation of the view in radians.

      Returns void

    • 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

      Parameters

      • Optionalsize: Size

        Viewport size; if undefined, [100, 100] is assumed

      Returns void

    • Zoom to a specific zoom level. Any resolution constrain will apply.

      Parameters

      • zoom: number

        Zoom level.

      Returns void

    • Protected

      Unlisten for a certain type of event.

      Parameters

      • type: string | string[]

        Type.

      • listener: (arg0: Event | BaseEvent) => unknown

        Listener.

      Returns void

    • Unsets a property.

      Parameters

      • key: string

        Key name.

      • Optionalsilent: boolean

        Unset without triggering an event.

      Returns void

    • Update all animations.

      Returns void