---
title: "RasterTileSource | 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 RasterTileSource`Maptiler`

A source containing raster tiles (See the [raster source documentation](https://maplibre.org/maplibre-style-spec/sources/#raster) for detailed documentation of options.)

#### Example[](#example)

```typescript
map.addSource('raster-source', {
    'type': 'raster',
    'tiles': ['https://tiles.stadiamaps.com/tiles/stamen_watercolor/{z}/{x}/{y}.jpg'],
    'tileSize': 256, // Set this to match tile server output to avoid blurry rendering
});
```

#### Example[](#example-1)

```typescript
map.addSource('wms-test-source', {
     'type': 'raster',
// use the tiles option to specify a WMS tile source URL
     'tiles': [
         'https://img.nj.gov/imagerywms/Natural2015?bbox={bbox-epsg-3857}&format=image/png&service=WMS&version=1.1.1&request=GetMap&srs=EPSG:3857&transparent=true&width=256&height=256&layers=Natural2015'
     ],
     'tileSize': 256 // Important for WMS if tiles are 256px
});
```

#### See[](#see)

-   [Add a raster tile source](https://maplibre.org/maplibre-gl-js/docs/examples/map-tiles/)
-   [Add a WMS source](https://maplibre.org/maplibre-gl-js/docs/examples/add-a-wms-source/)
-   [Display a satellite map](https://maplibre.org/maplibre-gl-js/docs/examples/display-a-satellite-map/)

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

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

##### Index

### Constructors[](#constructors)

[constructor](#constructor)

### Properties[](#properties)

[bounds](#bounds) [dispatcher](#dispatcher) [id](#id) [map](#map) [maxzoom](#maxzoom) [minzoom](#minzoom) [roundZoom](#roundzoom) [scheme](#scheme) [tileBounds](#tilebounds) [tiles](#tiles) [tileSize](#tilesize) [type](#type) [url](#url)

### Methods[](#methods)

[abortTile](#aborttile) [fire](#fire) [hasTile](#hastile) [hasTransition](#hastransition) [listens](#listens) [load](#load) [loaded](#loaded) [loadTile](#loadtile) [off](#off) [on](#on) [onAdd](#onadd) [once](#once) [onRemove](#onremove) [serialize](#serialize) [setEventedParent](#seteventedparent) [setSourceProperty](#setsourceproperty) [setTiles](#settiles) [setUrl](#seturl) [unloadTile](#unloadtile)

## Constructors[](#constructors-1)

### constructor[](#constructor)

-   new RasterTileSource(  
        id: string,  
        options: [RasterSourceSpecification](https://docs.maptiler.com/sdk-js/api-reference/types/RasterSourceSpecification/) | [RasterDEMSourceSpecification](https://docs.maptiler.com/sdk-js/api-reference/types/RasterDEMSourceSpecification/),  
        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/),  
    ): RasterTileSource[](#constructorrastertilesource)
    
    #### Parameters
    
    -   id: string
    -   options: [RasterSourceSpecification](https://docs.maptiler.com/sdk-js/api-reference/types/RasterSourceSpecification/) | [RasterDEMSourceSpecification](https://docs.maptiler.com/sdk-js/api-reference/types/RasterDEMSourceSpecification/)
    -   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 RasterTileSource
    
    Inherited from [RasterTileSource](https://docs.maptiler.com/sdk-js/api-reference/classes/Externals.RasterTileSource/).[constructor](https://docs.maptiler.com/sdk-js/api-reference/classes/Externals.RasterTileSource/#constructor)
    

## Properties[](#properties-1)

### bounds[](#bounds)

bounds: \[number, number, number, number\]

Inherited from [RasterTileSource](https://docs.maptiler.com/sdk-js/api-reference/classes/Externals.RasterTileSource/).[bounds](https://docs.maptiler.com/sdk-js/api-reference/classes/Externals.RasterTileSource/#bounds)

### dispatcher[](#dispatcher)

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

Inherited from [RasterTileSource](https://docs.maptiler.com/sdk-js/api-reference/classes/Externals.RasterTileSource/).[dispatcher](https://docs.maptiler.com/sdk-js/api-reference/classes/Externals.RasterTileSource/#dispatcher)

### id[](#id)

id: string

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

Inherited from [RasterTileSource](https://docs.maptiler.com/sdk-js/api-reference/classes/Externals.RasterTileSource/).[id](https://docs.maptiler.com/sdk-js/api-reference/classes/Externals.RasterTileSource/#id)

### map[](#map)

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

Inherited from [RasterTileSource](https://docs.maptiler.com/sdk-js/api-reference/classes/Externals.RasterTileSource/).[map](https://docs.maptiler.com/sdk-js/api-reference/classes/Externals.RasterTileSource/#map)

### maxzoom[](#maxzoom)

maxzoom: number

The maximum zoom level for the source.

Inherited from [RasterTileSource](https://docs.maptiler.com/sdk-js/api-reference/classes/Externals.RasterTileSource/).[maxzoom](https://docs.maptiler.com/sdk-js/api-reference/classes/Externals.RasterTileSource/#maxzoom)

### minzoom[](#minzoom)

minzoom: number

The minimum zoom level for the source.

Inherited from [RasterTileSource](https://docs.maptiler.com/sdk-js/api-reference/classes/Externals.RasterTileSource/).[minzoom](https://docs.maptiler.com/sdk-js/api-reference/classes/Externals.RasterTileSource/#minzoom)

### roundZoom[](#roundzoom)

roundZoom: boolean

`true` if zoom levels are rounded to the nearest integer in the source data, `false` if they are floor-ed to the nearest integer.

Inherited from [RasterTileSource](https://docs.maptiler.com/sdk-js/api-reference/classes/Externals.RasterTileSource/).[roundZoom](https://docs.maptiler.com/sdk-js/api-reference/classes/Externals.RasterTileSource/#roundzoom)

### scheme[](#scheme)

scheme: string

Inherited from [RasterTileSource](https://docs.maptiler.com/sdk-js/api-reference/classes/Externals.RasterTileSource/).[scheme](https://docs.maptiler.com/sdk-js/api-reference/classes/Externals.RasterTileSource/#scheme)

### tileBounds[](#tilebounds)

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

Inherited from [RasterTileSource](https://docs.maptiler.com/sdk-js/api-reference/classes/Externals.RasterTileSource/).[tileBounds](https://docs.maptiler.com/sdk-js/api-reference/classes/Externals.RasterTileSource/#tilebounds)

### tiles[](#tiles)

tiles: string\[\]

Inherited from [RasterTileSource](https://docs.maptiler.com/sdk-js/api-reference/classes/Externals.RasterTileSource/).[tiles](https://docs.maptiler.com/sdk-js/api-reference/classes/Externals.RasterTileSource/#tiles)

### tileSize[](#tilesize)

tileSize: number

The tile size for the source.

Inherited from [RasterTileSource](https://docs.maptiler.com/sdk-js/api-reference/classes/Externals.RasterTileSource/).[tileSize](https://docs.maptiler.com/sdk-js/api-reference/classes/Externals.RasterTileSource/#tilesize)

### type[](#type)

type: "raster" | "raster-dem"

Inherited from [RasterTileSource](https://docs.maptiler.com/sdk-js/api-reference/classes/Externals.RasterTileSource/).[type](https://docs.maptiler.com/sdk-js/api-reference/classes/Externals.RasterTileSource/#type)

### url[](#url)

url: string

Inherited from [RasterTileSource](https://docs.maptiler.com/sdk-js/api-reference/classes/Externals.RasterTileSource/).[url](https://docs.maptiler.com/sdk-js/api-reference/classes/Externals.RasterTileSource/#url)

## Methods[](#methods-1)

### abortTile[](#aborttile)

-   abortTile(tile: [Tile](https://docs.maptiler.com/sdk-js/api-reference/classes/Tile/)): Promise<void\>[](#aborttile-1)
    
    Allows to abort a tile loading.
    
    #### Parameters
    
    -   tile: [Tile](https://docs.maptiler.com/sdk-js/api-reference/classes/Tile/)
        
        The tile to abort
        
    
    #### Returns Promise<void\>
    
    Inherited from [RasterTileSource](https://docs.maptiler.com/sdk-js/api-reference/classes/Externals.RasterTileSource/).[abortTile](https://docs.maptiler.com/sdk-js/api-reference/classes/Externals.RasterTileSource/#aborttile)
    

### 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
    
    Inherited from [RasterTileSource](https://docs.maptiler.com/sdk-js/api-reference/classes/Externals.RasterTileSource/).[fire](https://docs.maptiler.com/sdk-js/api-reference/classes/Externals.RasterTileSource/#fire)
    

### hasTile[](#hastile)

-   hasTile(tileID: [OverscaledTileID](https://docs.maptiler.com/sdk-js/api-reference/classes/OverscaledTileID/)): boolean[](#hastile-1)
    
    True is the tile is part of the source, false otherwise.
    
    #### Parameters
    
    -   tileID: [OverscaledTileID](https://docs.maptiler.com/sdk-js/api-reference/classes/OverscaledTileID/)
        
        The tile ID
        
    
    #### Returns boolean
    
    Inherited from [RasterTileSource](https://docs.maptiler.com/sdk-js/api-reference/classes/Externals.RasterTileSource/).[hasTile](https://docs.maptiler.com/sdk-js/api-reference/classes/Externals.RasterTileSource/#hastile)
    

### hasTransition[](#hastransition)

-   hasTransition(): boolean[](#hastransition-1)
    
    True if the source has transition, false otherwise.
    
    #### Returns boolean
    
    Inherited from [RasterTileSource](https://docs.maptiler.com/sdk-js/api-reference/classes/Externals.RasterTileSource/).[hasTransition](https://docs.maptiler.com/sdk-js/api-reference/classes/Externals.RasterTileSource/#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 [RasterTileSource](https://docs.maptiler.com/sdk-js/api-reference/classes/Externals.RasterTileSource/).[listens](https://docs.maptiler.com/sdk-js/api-reference/classes/Externals.RasterTileSource/#listens)
    

### load[](#load)

-   load(sourceDataChanged?: boolean): Promise<void\>[](#load-1)
    
    #### Parameters
    
    -   `Optional`sourceDataChanged: boolean
    
    #### Returns Promise<void\>
    
    Inherited from [RasterTileSource](https://docs.maptiler.com/sdk-js/api-reference/classes/Externals.RasterTileSource/).[load](https://docs.maptiler.com/sdk-js/api-reference/classes/Externals.RasterTileSource/#load)
    

### loaded[](#loaded)

-   loaded(): boolean[](#loaded-1)
    
    True if the source is loaded, false otherwise.
    
    #### Returns boolean
    
    Inherited from [RasterTileSource](https://docs.maptiler.com/sdk-js/api-reference/classes/Externals.RasterTileSource/).[loaded](https://docs.maptiler.com/sdk-js/api-reference/classes/Externals.RasterTileSource/#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\>
    
    Inherited from [RasterTileSource](https://docs.maptiler.com/sdk-js/api-reference/classes/Externals.RasterTileSource/).[loadTile](https://docs.maptiler.com/sdk-js/api-reference/classes/Externals.RasterTileSource/#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 [RasterTileSource](https://docs.maptiler.com/sdk-js/api-reference/classes/Externals.RasterTileSource/).[off](https://docs.maptiler.com/sdk-js/api-reference/classes/Externals.RasterTileSource/#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 [RasterTileSource](https://docs.maptiler.com/sdk-js/api-reference/classes/Externals.RasterTileSource/).[on](https://docs.maptiler.com/sdk-js/api-reference/classes/Externals.RasterTileSource/#on)
    

### `Maptiler`onAdd[](#onadd)

-   onAdd(map: [MapLibreMap](https://docs.maptiler.com/sdk-js/api-reference/classes/MapLibreMap/) | [Map](https://docs.maptiler.com/sdk-js/api-reference/classes/Map/)): 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/) | [Map](https://docs.maptiler.com/sdk-js/api-reference/classes/Map/)
        
        The map instance
        
    
    #### Returns void
    
    Overrides [RasterTileSource](https://docs.maptiler.com/sdk-js/api-reference/classes/Externals.RasterTileSource/).[onAdd](https://docs.maptiler.com/sdk-js/api-reference/classes/Externals.RasterTileSource/#onadd)
    

### once[](#once)

-   once(type: string, listener?: [Listener](https://docs.maptiler.com/sdk-js/api-reference/types/Listener/)): Promise<any\> | RasterTileSource[](#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 Promise<any\> | RasterTileSource
    
    `this` or a promise if a listener is not provided
    
    Inherited from [RasterTileSource](https://docs.maptiler.com/sdk-js/api-reference/classes/Externals.RasterTileSource/).[once](https://docs.maptiler.com/sdk-js/api-reference/classes/Externals.RasterTileSource/#once)
    

### onRemove[](#onremove)

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

### serialize[](#serialize)

-   serialize(): [RasterSourceSpecification](https://docs.maptiler.com/sdk-js/api-reference/types/RasterSourceSpecification/) | [RasterDEMSourceSpecification](https://docs.maptiler.com/sdk-js/api-reference/types/RasterDEMSourceSpecification/)[](#serialize-1)
    
    #### Returns [RasterSourceSpecification](https://docs.maptiler.com/sdk-js/api-reference/types/RasterSourceSpecification/) | [RasterDEMSourceSpecification](https://docs.maptiler.com/sdk-js/api-reference/types/RasterDEMSourceSpecification/)
    
    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.
    
    Inherited from [RasterTileSource](https://docs.maptiler.com/sdk-js/api-reference/classes/Externals.RasterTileSource/).[serialize](https://docs.maptiler.com/sdk-js/api-reference/classes/Externals.RasterTileSource/#serialize)
    

### 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 [RasterTileSource](https://docs.maptiler.com/sdk-js/api-reference/classes/Externals.RasterTileSource/).[setEventedParent](https://docs.maptiler.com/sdk-js/api-reference/classes/Externals.RasterTileSource/#seteventedparent)
    

### setSourceProperty[](#setsourceproperty)

-   setSourceProperty(callback: Function): void[](#setsourceproperty-1)
    
    #### Parameters
    
    -   callback: Function
    
    #### Returns void
    
    Inherited from [RasterTileSource](https://docs.maptiler.com/sdk-js/api-reference/classes/Externals.RasterTileSource/).[setSourceProperty](https://docs.maptiler.com/sdk-js/api-reference/classes/Externals.RasterTileSource/#setsourceproperty)
    

### setTiles[](#settiles)

-   setTiles(tiles: string\[\]): this[](#settiles-1)
    
    Sets the source `tiles` property and re-renders the map.
    
    #### Parameters
    
    -   tiles: string\[\]
        
        An array of one or more tile source URLs, as in the raster tiles spec (See the [Style Specification](https://maplibre.org/maplibre-style-spec/)
        
    
    #### Returns this
    
    Inherited from [RasterTileSource](https://docs.maptiler.com/sdk-js/api-reference/classes/Externals.RasterTileSource/).[setTiles](https://docs.maptiler.com/sdk-js/api-reference/classes/Externals.RasterTileSource/#settiles)
    

### setUrl[](#seturl)

-   setUrl(url: string): this[](#seturl-1)
    
    Sets the source `url` property and re-renders the map.
    
    #### Parameters
    
    -   url: string
        
        A URL to a TileJSON resource. Supported protocols are `http:` and `https:`.
        
    
    #### Returns this
    
    Inherited from [RasterTileSource](https://docs.maptiler.com/sdk-js/api-reference/classes/Externals.RasterTileSource/).[setUrl](https://docs.maptiler.com/sdk-js/api-reference/classes/Externals.RasterTileSource/#seturl)
    

### unloadTile[](#unloadtile)

-   unloadTile(tile: [Tile](https://docs.maptiler.com/sdk-js/api-reference/classes/Tile/)): Promise<void\>[](#unloadtile-1)
    
    Allows to unload a tile.
    
    #### Parameters
    
    -   tile: [Tile](https://docs.maptiler.com/sdk-js/api-reference/classes/Tile/)
        
        The tile to unload
        
    
    #### Returns Promise<void\>
    
    Inherited from [RasterTileSource](https://docs.maptiler.com/sdk-js/api-reference/classes/Externals.RasterTileSource/).[unloadTile](https://docs.maptiler.com/sdk-js/api-reference/classes/Externals.RasterTileSource/#unloadtile)
