---
title: "Source | 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.

# Interface Source

The `Source` interface must be implemented by each source type, including "core" types (`vector`, `raster`, `video`, etc.) and all custom, third-party types.

**Event** `data` - Fired with `{dataType: 'source', sourceDataType: 'metadata'}` to indicate that any necessary metadata has been loaded so that it's okay to call `loadTile`; and with `{dataType: 'source', sourceDataType: 'content'}` to indicate that the source data has changed, so that any current caches should be flushed.

interface Source {  
    [attribution](#attribution)?: string;  
    [calculateTileZoom](#calculatetilezoom)?: [CalculateTileZoomFunction](https://docs.maptiler.com/sdk-js/api-reference/types/CalculateTileZoomFunction/);  
    [id](#id): string;  
    [isTileClipped](#istileclipped)?: boolean;  
    [maxzoom](#maxzoom): number;  
    [minzoom](#minzoom): number;  
    [reparseOverscaled](#reparseoverscaled)?: boolean;  
    [roundZoom](#roundzoom)?: boolean;  
    [tileID](#tileid)?: [CanonicalTileID](https://docs.maptiler.com/sdk-js/api-reference/classes/Externals.CanonicalTileID/);  
    [tileSize](#tilesize): number;  
    [type](#type): string;  
    [vectorLayerIds](#vectorlayerids)?: string\[\];  
    [abortTile](#aborttile-1)?(tile: [Tile](https://docs.maptiler.com/sdk-js/api-reference/classes/Tile/)): Promise<void\>;  
    [fire](#fire-1)(event: [Event](https://docs.maptiler.com/sdk-js/api-reference/classes/Event/)): unknown;  
    [hasTile](#hastile-1)?(tileID: [OverscaledTileID](https://docs.maptiler.com/sdk-js/api-reference/classes/OverscaledTileID/)): boolean;  
    [hasTransition](#hastransition-1)(): boolean;  
    [loaded](#loaded-1)(): boolean;  
    [loadTile](#loadtile-1)(tile: [Tile](https://docs.maptiler.com/sdk-js/api-reference/classes/Tile/)): Promise<void | [LoadTileResult](https://docs.maptiler.com/sdk-js/api-reference/types/LoadTileResult/)\>;  
    [onAdd](#onadd-1)?(map: [MapLibreMap](https://docs.maptiler.com/sdk-js/api-reference/classes/MapLibreMap/)): void;  
    [onRemove](#onremove-1)?(map: [MapLibreMap](https://docs.maptiler.com/sdk-js/api-reference/classes/MapLibreMap/)): void;  
    [prepare](#prepare-1)?(): void;  
    [serialize](#serialize-1)(): any;  
    [shouldReloadTile](#shouldreloadtile-1)?(  
        tile: [Tile](https://docs.maptiler.com/sdk-js/api-reference/classes/Tile/),  
        options: [GeoJSONSourceShouldReloadTileOptions](https://docs.maptiler.com/sdk-js/api-reference/types/Externals.GeoJSONSourceShouldReloadTileOptions/),  
    ): boolean;  
    [unloadTile](#unloadtile-1)?(tile: [Tile](https://docs.maptiler.com/sdk-js/api-reference/classes/Tile/)): Promise<void\>;  
}

#### Implemented by

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

##### Index

### Properties[](#properties)

[attribution?](#attribution) [calculateTileZoom?](#calculatetilezoom) [id](#id) [isTileClipped?](#istileclipped) [maxzoom](#maxzoom) [minzoom](#minzoom) [reparseOverscaled?](#reparseoverscaled) [roundZoom?](#roundzoom) [tileID?](#tileid) [tileSize](#tilesize) [type](#type) [vectorLayerIds?](#vectorlayerids)

### Methods[](#methods)

[abortTile?](#aborttile) [fire](#fire) [hasTile?](#hastile) [hasTransition](#hastransition) [loaded](#loaded) [loadTile](#loadtile) [onAdd?](#onadd) [onRemove?](#onremove) [prepare?](#prepare) [serialize](#serialize) [shouldReloadTile?](#shouldreloadtile) [unloadTile?](#unloadtile)

## Properties[](#properties-1)

### `Optional`attribution[](#attribution)

attribution?: string

The attribution for the source.

### `Optional`calculateTileZoom[](#calculatetilezoom)

calculateTileZoom?: [CalculateTileZoomFunction](https://docs.maptiler.com/sdk-js/api-reference/types/CalculateTileZoomFunction/)

Optional function to redefine how tiles are loaded at high pitch angles.

### id[](#id)

id: string

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

### `Optional`isTileClipped[](#istileclipped)

isTileClipped?: boolean

`false` if tiles can be drawn outside their boundaries, `true` if they cannot.

### maxzoom[](#maxzoom)

maxzoom: number

The maximum zoom level for the source.

### minzoom[](#minzoom)

minzoom: number

The minimum zoom level for the source.

### `Optional`reparseOverscaled[](#reparseoverscaled)

reparseOverscaled?: boolean

`true` if tiles should be sent back to the worker for each overzoomed zoom level, `false` if not.

### `Optional`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.

### `Optional`tileID[](#tileid)

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

### tileSize[](#tilesize)

tileSize: number

The tile size for the source.

### `Readonly`type[](#type)

type: string

### `Optional`vectorLayerIds[](#vectorlayerids)

vectorLayerIds?: string\[\]

## Methods[](#methods-1)

### `Optional`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\>
    

### fire[](#fire)

-   fire(event: [Event](https://docs.maptiler.com/sdk-js/api-reference/classes/Event/)): unknown[](#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: [Event](https://docs.maptiler.com/sdk-js/api-reference/classes/Event/)
        
        The event to fire
        
    
    #### Returns unknown
    

### `Optional`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
    

### hasTransition[](#hastransition)

-   hasTransition(): boolean[](#hastransition-1)
    
    True if the source has transition, false otherwise.
    
    #### Returns boolean
    

### loaded[](#loaded)

-   loaded(): boolean[](#loaded-1)
    
    True if the source is loaded, false otherwise.
    
    #### Returns boolean
    

### loadTile[](#loadtile)

-   loadTile(tile: [Tile](https://docs.maptiler.com/sdk-js/api-reference/classes/Tile/)): Promise<void | [LoadTileResult](https://docs.maptiler.com/sdk-js/api-reference/types/LoadTileResult/)\>[](#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 | [LoadTileResult](https://docs.maptiler.com/sdk-js/api-reference/types/LoadTileResult/)\>
    

### `Optional`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
    

### `Optional`onRemove[](#onremove)

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

### `Optional`prepare[](#prepare)

-   prepare?(): void[](#prepare-1)
    
    Allows to execute a prepare step before the source is used.
    
    #### Returns void
    

### serialize[](#serialize)

-   serialize(): any[](#serialize-1)
    
    #### Returns any
    
    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.
    

### `Optional`shouldReloadTile[](#shouldreloadtile)

-   shouldReloadTile?(  
        tile: [Tile](https://docs.maptiler.com/sdk-js/api-reference/classes/Tile/),  
        options: [GeoJSONSourceShouldReloadTileOptions](https://docs.maptiler.com/sdk-js/api-reference/types/Externals.GeoJSONSourceShouldReloadTileOptions/),  
    ): boolean[](#shouldreloadtile-1)
    
    Optional function to determine whether a tile should be reloaded, given a set of options associated with a `MapSourceDataChangedEvent`.
    
    #### Parameters
    
    -   tile: [Tile](https://docs.maptiler.com/sdk-js/api-reference/classes/Tile/)
    -   options: [GeoJSONSourceShouldReloadTileOptions](https://docs.maptiler.com/sdk-js/api-reference/types/Externals.GeoJSONSourceShouldReloadTileOptions/)
    
    #### Returns boolean
    
    #### Internal[](#internal)
    

### `Optional`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\>
