Skip to content

ImageSource

Defined in: source/image_source.ts:122

A data source containing an image. (See the Style Specification for detailed documentation of options.)

Example

// add to map
map.addSource('some id', {
   type: 'image',
   url: 'https://www.maplibre.org/images/foo.png',
   coordinates: [
       [-76.54, 39.18],
       [-76.52, 39.18],
       [-76.52, 39.17],
       [-76.54, 39.17]
   ]
});

// update coordinates
let mySource = map.getSource('some id');
mySource.setCoordinates([
    [-76.54335737228394, 39.18579907229748],
    [-76.52803659439087, 39.1838364847587],
    [-76.5295386314392, 39.17683392507606],
    [-76.54520273208618, 39.17876344106642]
]);

// update url and coordinates simultaneously
mySource.updateImage({
   url: 'https://www.maplibre.org/images/bar.png',
   coordinates: [
       [-76.54335737228394, 39.18579907229748],
       [-76.52803659439087, 39.1838364847587],
       [-76.5295386314392, 39.17683392507606],
       [-76.54520273208618, 39.17876344106642]
   ]
})

// update with an already-decoded image (no network request)
const bitmap = await createImageBitmap(myCanvas);
mySource.updateImage({image: bitmap});

map.removeSource('some id');  // remove

Extends

Extended by

Implements

Methods

hasTransition()

hasTransition(): boolean

Defined in: source/image_source.ts:347

True if the source has transition, false otherwise.

Returns

boolean

Implementation of

Source.hasTransition


listens()

listens(type: string): boolean

Defined in: util/evented.ts:180

Returns a true if this instance of Evented or any forwardeed instances of Evented have a listener for the specified type.

Parameters

Parameter Type Description
type string The event type

Returns

boolean

true if there is at least one registered listener for specified event type, false otherwise

Inherited from

Evented.listens


loaded()

loaded(): boolean

Defined in: source/image_source.ts:196

True if the source is loaded, false otherwise.

Returns

boolean

Implementation of

Source.loaded


loadTile()

loadTile(tile: Tile): Promise<void>

Defined in: source/image_source.ts:324

This method does the heavy lifting of loading a tile. In most cases it will defer the work to the relevant worker source.

Parameters

Parameter Type Description
tile Tile The tile to load

Returns

Promise<void>

Implementation of

Source.loadTile


off()

off<T>(type: T, listener: (event: SourceEventType[T]) => void): this

Defined in: util/evented.ts:95

Removes a previously registered event listener.

Type Parameters

Type Parameter
T extends keyof SourceEventType

Parameters

Parameter Type Description
type T The event type to remove listeners for.
listener (event: SourceEventType[T]) => void The listener function to remove.

Returns

this

Inherited from

Evented.off


on()

on<T>(type: T, listener: (event: SourceEventType[T]) => void): Subscription

Defined in: util/evented.ts:78

Adds a listener to a specified event type.

Type Parameters

Type Parameter
T extends keyof SourceEventType

Parameters

Parameter Type Description
type T The event type to add a listen for.
listener (event: SourceEventType[T]) => void The function to be called when the event is fired. The listener function is called with the data object passed to fire, extended with target and type properties.

Returns

Subscription

Inherited from

Evented.on


onAdd()

onAdd(map: Map): void

Defined in: source/image_source.ts:244

This method is called when the source is added to the map.

Parameters

Parameter Type Description
map Map The map instance

Returns

void

Implementation of

Source.onAdd


once()

Call Signature

once<T>(type: T): Promise<SourceEventType[T]>

Defined in: util/evented.ts:110

Adds a listener that will be called only once to a specified event type.

The listener will be called first time the event fires after the listener is registered.

Type Parameters
Type Parameter
T extends keyof SourceEventType
Parameters
Parameter Type Description
type T The event type to listen for.
Returns

Promise<SourceEventType[T]>

a promise that resolves with the event

Inherited from

Evented.once

Call Signature

once<T>(type: T, listener: (event: SourceEventType[T]) => void): this

Defined in: util/evented.ts:120

Adds a listener that will be called only once to a specified event type.

The listener will be called first time the event fires after the listener is registered.

Type Parameters
Type Parameter
T extends keyof SourceEventType
Parameters
Parameter Type Description
type T The event type to listen for.
listener (event: SourceEventType[T]) => void The function to be called when the event is fired the first time.
Returns

this

this when a listener is provided

Inherited from

Evented.once


onRemove()

onRemove(): void

Defined in: source/image_source.ts:249

This method is called when the source is removed from the map.

Returns

void

Implementation of

Source.onRemove


prepare()

prepare(): void

Defined in: source/image_source.ts:296

Allows to execute a prepare step before the source is used.

Returns

void

Implementation of

Source.prepare


serialize()

serialize(): VideoSourceSpecification | ImageSourceSpecification | CanvasSourceSpecification

Defined in: source/image_source.ts:339

Returns

VideoSourceSpecification | ImageSourceSpecification | CanvasSourceSpecification

A plain (stringifiable) JS object representing the current state of the source. Creating a source using the returned object as the options should result in a Source that is equivalent to this one.

Implementation of

Source.serialize


setCoordinates()

setCoordinates(coordinates: Coordinates): this

Defined in: source/image_source.ts:264

Sets the image's coordinates and re-renders the map.

Parameters

Parameter Type Description
coordinates Coordinates Four geographical coordinates, represented as arrays of longitude and latitude numbers, which define the corners of the image. The coordinates start at the top left corner of the image and proceed in clockwise order. They do not have to represent a rectangle.

Returns

this


setEventedParent()

setEventedParent(parent?: Evented<Record<string, any>>, data?: any): this

Defined in: util/evented.ts:191

Bubble all events fired by this instance of Evented to this parent instance of Evented.

Parameters

Parameter Type
parent? Evented<Record<string, any>>
data? any

Returns

this

Inherited from

Evented.setEventedParent


updateImage()

updateImage(options: UpdateImageOptions): this

Defined in: source/image_source.ts:210

Updates the image and, optionally, the coordinates. To avoid having the image flash after changing, set the raster-fade-duration paint property on the raster layer to 0.

Provide exactly one of url (to fetch a new image over the network) or image (an already-decoded HTMLImageElement, HTMLCanvasElement, ImageBitmap or ImageData to display directly, without a network request).

Parameters

Parameter Type Description
options UpdateImageOptions The options object.

Returns

this

Properties

id

id: string

Defined in: source/image_source.ts:124

The id for the source. Must not be used by any existing source.

Implementation of

Source.id


maxzoom

maxzoom: number

Defined in: source/image_source.ts:126

The maximum zoom level for the source.

Implementation of

Source.maxzoom


minzoom

minzoom: number

Defined in: source/image_source.ts:125

The minimum zoom level for the source.

Implementation of

Source.minzoom


terrainTileRanges

terrainTileRanges: object

Defined in: source/image_source.ts:133

This object is used to store the range of terrain tiles that overlap with this tile. It is relevant for image tiles, as the image exceeds single tile boundaries.

Index Signature

[zoom: string]: CanonicalTileRange


tileSize

tileSize: number

Defined in: source/image_source.ts:127

The tile size for the source.

Implementation of

Source.tileSize