Module: ol/Image

ol/Image


Functions

decode(image, src){Promise.<(ImageBitmap|HTMLImageElement)>}

import {decode} from 'ol/Image';

Loads an image and decodes it to an ImageBitmap if createImageBitmap() is supported. Returns the loaded image otherwise.

Name Type Description
image HTMLImageElement

Image, not yet loaded.

src string | undefined

src attribute of the image. Optional, not required if already present.

Returns:
Promise resolving to an ImageBitmap or an HTMLImageElement if createImageBitmap() is not supported.

load(image, src){Promise.<HTMLImageElement>}

import {load} from 'ol/Image';

Loads an image.

Name Type Description
image HTMLImageElement

Image, not yet loaded.

src string | undefined

src attribute of the image. Optional, not required if already present.

Returns:
Promise resolving to an HTMLImageElement.

Type Definitions

ImageObject{Object}

Properties:
Name Type Description
extent Extent | undefined

Extent, if different from the requested one.

resolution ResolutionLike | undefined

Resolution, if different from the requested one. When x and y resolution are different, use the array type ([xResolution, yResolution]).

pixelRatio number | undefined

Pixel ratio, if different from the requested one.

image ImageLike

Image.

ImageObjectPromiseLoader()

Loader function used for image sources. Receives extent, resolution and pixel ratio as arguments. The function returns a promise for an image object.

LoadFunction()

A function that takes an ImageWrapper for the image and a {string} for the src as arguments. It is supposed to make it so the underlying image getImage is assigned the content specified by the src. If not specified, the default is

function(image, src) {
  image.getImage().src = src;
}

Providing a custom imageLoadFunction can be useful to load images with post requests or - in general - through XHR requests, where the src of the image element would be set to a data URI when the content is loaded.

Loader()

Loader function used for image sources. Receives extent, resolution and pixel ratio as arguments. For images that cover any extent and resolution (static images), the loader function should not accept any arguments. The function returns an image, an image object, or a promise for the same. For loaders that generate images, the promise should not resolve until the image is loaded. If the returned image does not match the extent, resolution or pixel ratio passed to the loader, it has to return an image object with the image and the correct extent, resolution and pixelRatio.