---
title: "ImageSource | JavaScript maps SDK"
description: "Documentation for MapTiler SDK"
---

> For AI agents: a documentation index is available at [/llms.txt](https://docs.maptiler.com/llms.txt). Markdown versions of all pages are available by appending .md to any URL.

# Class ImageSource

A data source containing an image. (See the [Style Specification](https://maplibre.org/maplibre-style-spec/#sources-image) for detailed documentation of options.)

#### Example[](#example)

```typescript
// 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]
   ]
})

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

#### Hierarchy ([View Summary](https://docs.maptiler.com/sdk-js/api-reference/hierarchy/#Externals.ImageSource))

-   [Evented](https://docs.maptiler.com/sdk-js/api-reference/classes/Externals.Evented/)
    -   ImageSource
        -   [ImageSource](https://docs.maptiler.com/sdk-js/api-reference/classes/ImageSource/)
        -   [CanvasSource](https://docs.maptiler.com/sdk-js/api-reference/classes/Externals.CanvasSource/)
        -   [VideoSource](https://docs.maptiler.com/sdk-js/api-reference/classes/Externals.VideoSource/)

#### Implements

-   [Source](https://docs.maptiler.com/sdk-js/api-reference/interfaces/Source/)

##### Index

### Constructors[](#constructors)

[constructor](#constructor)

### Properties[](#properties)

[coordinates](#coordinates) [dispatcher](#dispatcher) [flippedWindingOrder](#flippedwindingorder) [id](#id) [image](#image) [map](#map) [maxzoom](#maxzoom) [minzoom](#minzoom) [options](#options) [terrainTileRanges](#terraintileranges) [texture](#texture) [tileCoords](#tilecoords) [tileID](#tileid) [tiles](#tiles) [tileSize](#tilesize) [type](#type) [url](#url)

### Methods[](#methods)

[fire](#fire) [hasTransition](#hastransition) [listens](#listens) [load](#load) [loaded](#loaded) [loadTile](#loadtile) [off](#off) [on](#on) [onAdd](#onadd) [once](#once) [onRemove](#onremove) [prepare](#prepare) [serialize](#serialize) [setCoordinates](#setcoordinates) [setEventedParent](#seteventedparent) [updateImage](#updateimage)

## Constructors[](#constructors-1)

### constructor[](#constructor)

-   new ImageSource(  
        id: string,  
        options:  
            | [CanvasSourceSpecification](https://docs.maptiler.com/sdk-js/api-reference/types/CanvasSourceSpecification/)  
            | [VideoSourceSpecification](https://docs.maptiler.com/sdk-js/api-reference/types/VideoSourceSpecification/)  
            | [ImageSourceSpecification](https://docs.maptiler.com/sdk-js/api-reference/types/ImageSourceSpecification/),  
        dispatcher: [Dispatcher](https://docs.maptiler.com/sdk-js/api-reference/classes/Dispatcher/),  
        eventedParent: [Evented](https://docs.maptiler.com/sdk-js/api-reference/classes/Externals.Evented/),  
    ): ImageSource[](#constructorimagesource)
    
    #### Parameters
    
    -   id: string
    -   options: [CanvasSourceSpecification](https://docs.maptiler.com/sdk-js/api-reference/types/CanvasSourceSpecification/) | [VideoSourceSpecification](https://docs.maptiler.com/sdk-js/api-reference/types/VideoSourceSpecification/) | [ImageSourceSpecification](https://docs.maptiler.com/sdk-js/api-reference/types/ImageSourceSpecification/)
    -   dispatcher: [Dispatcher](https://docs.maptiler.com/sdk-js/api-reference/classes/Dispatcher/)
    -   eventedParent: [Evented](https://docs.maptiler.com/sdk-js/api-reference/classes/Externals.Evented/)
    
    #### Returns ImageSource
    
    #### Internal[](#internal)
    
    Overrides [Evented](https://docs.maptiler.com/sdk-js/api-reference/classes/Externals.Evented/).[constructor](https://docs.maptiler.com/sdk-js/api-reference/classes/Externals.Evented/#constructor)
    

## Properties[](#properties-1)

### coordinates[](#coordinates)

coordinates: [Coordinates](https://docs.maptiler.com/sdk-js/api-reference/types/Externals.Coordinates/)

### dispatcher[](#dispatcher)

dispatcher: [Dispatcher](https://docs.maptiler.com/sdk-js/api-reference/classes/Dispatcher/)

### flippedWindingOrder[](#flippedwindingorder)

flippedWindingOrder: boolean

### id[](#id)

id: string

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

Implementation of [Source](https://docs.maptiler.com/sdk-js/api-reference/interfaces/Source/).[id](https://docs.maptiler.com/sdk-js/api-reference/interfaces/Source/#id)

### image[](#image)

image: [ImageBitmap](https://docs.maptiler.com/sdk-js/api-reference/interfaces/Externals.ImageBitmap/) | [HTMLImageElement](https://docs.maptiler.com/sdk-js/api-reference/interfaces/Externals.HTMLImageElement/)

### map[](#map)

map: [MapLibreMap](https://docs.maptiler.com/sdk-js/api-reference/classes/MapLibreMap/)

### maxzoom[](#maxzoom)

maxzoom: number

The maximum zoom level for the source.

Implementation of [Source](https://docs.maptiler.com/sdk-js/api-reference/interfaces/Source/).[maxzoom](https://docs.maptiler.com/sdk-js/api-reference/interfaces/Source/#maxzoom)

### minzoom[](#minzoom)

minzoom: number

The minimum zoom level for the source.

Implementation of [Source](https://docs.maptiler.com/sdk-js/api-reference/interfaces/Source/).[minzoom](https://docs.maptiler.com/sdk-js/api-reference/interfaces/Source/#minzoom)

### options[](#options)

options: any

### terrainTileRanges[](#terraintileranges)

terrainTileRanges: { \[zoom: string\]: [CanonicalTileRange](https://docs.maptiler.com/sdk-js/api-reference/types/CanonicalTileRange/) }

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.

### texture[](#texture)

texture: [Texture](https://docs.maptiler.com/sdk-js/api-reference/classes/Externals.Texture/) | null

### tileCoords[](#tilecoords)

tileCoords: [Point](https://docs.maptiler.com/sdk-js/api-reference/classes/Externals.Point/)\[\]

### tileID[](#tileid)

tileID: [CanonicalTileID](https://docs.maptiler.com/sdk-js/api-reference/classes/Externals.CanonicalTileID/)

Implementation of [Source](https://docs.maptiler.com/sdk-js/api-reference/interfaces/Source/).[tileID](https://docs.maptiler.com/sdk-js/api-reference/interfaces/Source/#tileid)

### tiles[](#tiles)

tiles: { \[\_: string\]: [Tile](https://docs.maptiler.com/sdk-js/api-reference/classes/Tile/) }

### tileSize[](#tilesize)

tileSize: number

The tile size for the source.

Implementation of [Source](https://docs.maptiler.com/sdk-js/api-reference/interfaces/Source/).[tileSize](https://docs.maptiler.com/sdk-js/api-reference/interfaces/Source/#tilesize)

### type[](#type)

type: string

Implementation of [Source](https://docs.maptiler.com/sdk-js/api-reference/interfaces/Source/).[type](https://docs.maptiler.com/sdk-js/api-reference/interfaces/Source/#type)

### url[](#url)

url: string

## Methods[](#methods-1)

### fire[](#fire)

-   fire(event: string | [Event](https://docs.maptiler.com/sdk-js/api-reference/classes/Event/), properties?: any): this[](#fire-1)
    
    An ability to fire an event to all the listeners, see [Evented](https://docs.maptiler.com/sdk-js/api-reference/classes/Externals.Evented/)
    
    #### Parameters
    
    -   event: string | [Event](https://docs.maptiler.com/sdk-js/api-reference/classes/Event/)
        
        The event to fire
        
    -   `Optional`properties: any
    
    #### Returns this
    
    Implementation of [Source](https://docs.maptiler.com/sdk-js/api-reference/interfaces/Source/).[fire](https://docs.maptiler.com/sdk-js/api-reference/interfaces/Source/#fire)
    
    Inherited from [Evented](https://docs.maptiler.com/sdk-js/api-reference/classes/Externals.Evented/).[fire](https://docs.maptiler.com/sdk-js/api-reference/classes/Externals.Evented/#fire)
    

### hasTransition[](#hastransition)

-   hasTransition(): boolean[](#hastransition-1)
    
    True if the source has transition, false otherwise.
    
    #### Returns boolean
    
    Implementation of [Source](https://docs.maptiler.com/sdk-js/api-reference/interfaces/Source/).[hasTransition](https://docs.maptiler.com/sdk-js/api-reference/interfaces/Source/#hastransition)
    

### listens[](#listens)

-   listens(type: string): boolean[](#listens-1)
    
    Returns a true if this instance of Evented or any forwardeed instances of Evented have a listener for the specified type.
    
    #### Parameters
    
    -   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](https://docs.maptiler.com/sdk-js/api-reference/classes/Externals.Evented/).[listens](https://docs.maptiler.com/sdk-js/api-reference/classes/Externals.Evented/#listens)
    

### load[](#load)

-   load(newCoordinates?: [Coordinates](https://docs.maptiler.com/sdk-js/api-reference/types/Externals.Coordinates/)): Promise<void\>[](#load-1)
    
    #### Parameters
    
    -   `Optional`newCoordinates: [Coordinates](https://docs.maptiler.com/sdk-js/api-reference/types/Externals.Coordinates/)
    
    #### Returns Promise<void\>
    

### loaded[](#loaded)

-   loaded(): boolean[](#loaded-1)
    
    True if the source is loaded, false otherwise.
    
    #### Returns boolean
    
    Implementation of [Source](https://docs.maptiler.com/sdk-js/api-reference/interfaces/Source/).[loaded](https://docs.maptiler.com/sdk-js/api-reference/interfaces/Source/#loaded)
    

### loadTile[](#loadtile)

-   loadTile(tile: [Tile](https://docs.maptiler.com/sdk-js/api-reference/classes/Tile/)): Promise<void\>[](#loadtile-1)
    
    This method does the heavy lifting of loading a tile. In most cases it will defer the work to the relevant worker source.
    
    #### Parameters
    
    -   tile: [Tile](https://docs.maptiler.com/sdk-js/api-reference/classes/Tile/)
        
        The tile to load
        
    
    #### Returns Promise<void\>
    
    Implementation of [Source](https://docs.maptiler.com/sdk-js/api-reference/interfaces/Source/).[loadTile](https://docs.maptiler.com/sdk-js/api-reference/interfaces/Source/#loadtile)
    

### off[](#off)

-   off(type: string, listener: [Listener](https://docs.maptiler.com/sdk-js/api-reference/types/Listener/)): this[](#off-1)
    
    Removes a previously registered event listener.
    
    #### Parameters
    
    -   type: string
        
        The event type to remove listeners for.
        
    -   listener: [Listener](https://docs.maptiler.com/sdk-js/api-reference/types/Listener/)
        
        The listener function to remove.
        
    
    #### Returns this
    
    Inherited from [Evented](https://docs.maptiler.com/sdk-js/api-reference/classes/Externals.Evented/).[off](https://docs.maptiler.com/sdk-js/api-reference/classes/Externals.Evented/#off)
    

### on[](#on)

-   on(type: string, listener: [Listener](https://docs.maptiler.com/sdk-js/api-reference/types/Listener/)): [Subscription](https://docs.maptiler.com/sdk-js/api-reference/interfaces/Subscription/)[](#on-1)
    
    Adds a listener to a specified event type.
    
    #### Parameters
    
    -   type: string
        
        The event type to add a listen for.
        
    -   listener: [Listener](https://docs.maptiler.com/sdk-js/api-reference/types/Listener/)
        
        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](https://docs.maptiler.com/sdk-js/api-reference/interfaces/Subscription/)
    
    Inherited from [Evented](https://docs.maptiler.com/sdk-js/api-reference/classes/Externals.Evented/).[on](https://docs.maptiler.com/sdk-js/api-reference/classes/Externals.Evented/#on)
    

### onAdd[](#onadd)

-   onAdd(map: [MapLibreMap](https://docs.maptiler.com/sdk-js/api-reference/classes/MapLibreMap/)): void[](#onadd-1)
    
    This method is called when the source is added to the map.
    
    #### Parameters
    
    -   map: [MapLibreMap](https://docs.maptiler.com/sdk-js/api-reference/classes/MapLibreMap/)
        
        The map instance
        
    
    #### Returns void
    
    Implementation of [Source](https://docs.maptiler.com/sdk-js/api-reference/interfaces/Source/).[onAdd](https://docs.maptiler.com/sdk-js/api-reference/interfaces/Source/#onadd)
    

### once[](#once)

-   once(type: string, listener?: [Listener](https://docs.maptiler.com/sdk-js/api-reference/types/Listener/)): ImageSource | Promise<any\>[](#once-1)
    
    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.
    
    #### Parameters
    
    -   type: string
        
        The event type to listen for.
        
    -   `Optional`listener: [Listener](https://docs.maptiler.com/sdk-js/api-reference/types/Listener/)
        
        The function to be called when the event is fired the first time.
        
    
    #### Returns ImageSource | Promise<any\>
    
    `this` or a promise if a listener is not provided
    
    Inherited from [Evented](https://docs.maptiler.com/sdk-js/api-reference/classes/Externals.Evented/).[once](https://docs.maptiler.com/sdk-js/api-reference/classes/Externals.Evented/#once)
    

### onRemove[](#onremove)

-   onRemove(): void[](#onremove-1)
    
    This method is called when the source is removed from the map.
    
    #### Returns void
    
    Implementation of [Source](https://docs.maptiler.com/sdk-js/api-reference/interfaces/Source/).[onRemove](https://docs.maptiler.com/sdk-js/api-reference/interfaces/Source/#onremove)
    

### prepare[](#prepare)

-   prepare(): void[](#prepare-1)
    
    Allows to execute a prepare step before the source is used.
    
    #### Returns void
    
    Implementation of [Source](https://docs.maptiler.com/sdk-js/api-reference/interfaces/Source/).[prepare](https://docs.maptiler.com/sdk-js/api-reference/interfaces/Source/#prepare)
    

### serialize[](#serialize)

-   serialize(): | [CanvasSourceSpecification](https://docs.maptiler.com/sdk-js/api-reference/types/CanvasSourceSpecification/)  
    | [VideoSourceSpecification](https://docs.maptiler.com/sdk-js/api-reference/types/VideoSourceSpecification/)  
    | [ImageSourceSpecification](https://docs.maptiler.com/sdk-js/api-reference/types/ImageSourceSpecification/)[](#serialize-1)
    
    #### Returns [CanvasSourceSpecification](https://docs.maptiler.com/sdk-js/api-reference/types/CanvasSourceSpecification/) | [VideoSourceSpecification](https://docs.maptiler.com/sdk-js/api-reference/types/VideoSourceSpecification/) | [ImageSourceSpecification](https://docs.maptiler.com/sdk-js/api-reference/types/ImageSourceSpecification/)
    
    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](https://docs.maptiler.com/sdk-js/api-reference/interfaces/Source/).[serialize](https://docs.maptiler.com/sdk-js/api-reference/interfaces/Source/#serialize)
    

### setCoordinates[](#setcoordinates)

-   setCoordinates(coordinates: [Coordinates](https://docs.maptiler.com/sdk-js/api-reference/types/Externals.Coordinates/)): this[](#setcoordinates-1)
    
    Sets the image's coordinates and re-renders the map.
    
    #### Parameters
    
    -   coordinates: [Coordinates](https://docs.maptiler.com/sdk-js/api-reference/types/Externals.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)

-   setEventedParent(parent?: [Evented](https://docs.maptiler.com/sdk-js/api-reference/classes/Externals.Evented/) | null, data?: any): this[](#seteventedparent-1)
    
    Bubble all events fired by this instance of Evented to this parent instance of Evented.
    
    #### Parameters
    
    -   `Optional`parent: [Evented](https://docs.maptiler.com/sdk-js/api-reference/classes/Externals.Evented/) | null
    -   `Optional`data: any
    
    #### Returns this
    
    Inherited from [Evented](https://docs.maptiler.com/sdk-js/api-reference/classes/Externals.Evented/).[setEventedParent](https://docs.maptiler.com/sdk-js/api-reference/classes/Externals.Evented/#seteventedparent)
    

### updateImage[](#updateimage)

-   updateImage(options: [UpdateImageOptions](https://docs.maptiler.com/sdk-js/api-reference/types/UpdateImageOptions/)): this[](#updateimage-1)
    
    Updates the image URL 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.
    
    #### Parameters
    
    -   options: [UpdateImageOptions](https://docs.maptiler.com/sdk-js/api-reference/types/UpdateImageOptions/)
        
        The options object.
        
    
    #### Returns this
