Class: PmTilesSource
The PmTiles source. It mainly should work as a regular source as other mapbox sources.
Remarks
The Source will automatically set its type [vector|raster] based on the type defined in the pmTiles metadata. The different PmTiles
data type is defined as here: https://github.com/protomaps/PMTiles/blob/main/spec/v3/spec.md#tile-type-tt. We also use the
rest of the headers to set source boundary. This includes minZoom, maxZoom, minLon, minLat, maxLon and maxLat if they are
available.
Param
The unique id of the source
Param
The main pmtiles options
Param
Param
Example
import mapboxgl from "mapbox-gl";
import { PmTilesSource } from "mapbox-pmtiles";
//Define custom source
mapboxgl.Style.setSourceType(PmTilesSource.SOURCE_TYPE, PmTilesSource);
map.on("load", () => {
const PMTILES_URL =
"https://r2-public.protomaps.com/protomaps-sample-datasets/protomaps-basemap-opensource-20230408.pmtiles";
map.addSource("pmTileSourceName", {
type: PmTilesSource.SOURCE_TYPE, //Add this line
url: PMTILES_URL,
maxzoom: 10,
});
map.current.showTileBoundaries = true;
map.current.addLayer({
id: "places",
source: "pmTileSourceName",
"source-layer": "places",
type: "circle",
paint: {
"circle-color": "steelblue",
},
maxzoom: 14,
});
});
Hierarchy
-
VectorTileSourceImpl↳
PmTilesSource
Constructors
constructor
• new PmTilesSource(id, options, _dispatcher, _eventedParent): PmTilesSource
The PmTiles source. It mainly should work as a regular source as other mapbox sources.
Parameters
| Name | Type | Description |
|---|---|---|
id | string | The unique id of the source |
options | PmTilesOptions | The main pmtiles options |
_dispatcher | any | |
_eventedParent | any |
Returns
Remarks
The Source will automatically set its type [vector|raster] based on the type defined in the pmTiles metadata. The different PmTiles
data type is defined as here: https://github.com/protomaps/PMTiles/blob/main/spec/v3/spec.md#tile-type-tt. We also use the
rest of the headers to set source boundary. This includes minZoom, maxZoom, minLon, minLat, maxLon and maxLat if they are
available.
Example
import mapboxgl from "mapbox-gl";
import { PmTilesSource } from "mapbox-pmtiles";
//Define custom source
mapboxgl.Style.setSourceType(PmTilesSource.SOURCE_TYPE, PmTilesSource);
map.on("load", () => {
const PMTILES_URL =
"https://r2-public.protomaps.com/protomaps-sample-datasets/protomaps-basemap-opensource-20230408.pmtiles";
map.addSource("pmTileSourceName", {
type: PmTilesSource.SOURCE_TYPE, //Add this line
url: PMTILES_URL,
maxzoom: 10,
});
map.current.showTileBoundaries = true;
map.current.addLayer({
id: "places",
source: "pmTileSourceName",
"source-layer": "places",
type: "circle",
paint: {
"circle-color": "steelblue",
},
maxzoom: 14,
});
});
Overrides
VectorTileSourceImpl.constructor
Defined in
Properties
_dataType
• _dataType: string
Defined in
_implementation
• _implementation: PmTilesOptions
Defined in
_instance
• _instance: PMTiles
Defined in
_loaded
• _loaded: boolean
Defined in
_protocol
• _protocol: Protocol
Defined in
_tileJSONRequest
• _tileJSONRequest: undefined | Promise<any>
Defined in
_tileWorkers
• _tileWorkers: Object
Index signature
▪ [string: string]: any
Defined in
attribution
• attribution: undefined | string
Defined in
contentType
• contentType: string
Defined in
dispatcher
• dispatcher: any
Defined in
fire
• fire: Function
Defined in
header
• header: any
Defined in
id
• id: string
Defined in
loadTile
• loadTile: (tile: Tile, callback: Callback<void>) => void
Type declaration
▸ (tile, callback): void
Parameters
| Name | Type |
|---|---|
tile | Tile |
callback | Callback<void> |
Returns
void
Defined in
map
• map: MapboxMap
Defined in
maxTileCacheSize
• maxTileCacheSize: undefined | number
Defined in
maxzoom
• maxzoom: number
Defined in
minTileCacheSize
• minTileCacheSize: undefined | number
Defined in
minzoom
• minzoom: number
Defined in
promoteId
• promoteId: undefined | string
Defined in
reparseOverscaled
• reparseOverscaled: boolean
Defined in
roundZoom
• roundZoom: boolean = true
Defined in
scheme
• scheme: string
Defined in
scope
• scope: undefined | string
Defined in
setEventedParent
• setEventedParent: any
Defined in
tileBounds
• tileBounds: undefined | TileBounds
Defined in
tileSize
• tileSize: number
Defined in
tileType
• tileType: TileType
Defined in
tiles
• tiles: string[]
Defined in
type
• type: string = 'vector'
Defined in
SOURCE_TYPE
▪ Static SOURCE_TYPE: string = SOURCE_TYPE
Defined in
Methods
getExtent
▸ getExtent(): LngLatBoundsLike
the extent of the entire source extracted from pmtiles header
Returns
LngLatBoundsLike
Defined in
hasTile
▸ hasTile(tileID): boolean
Parameters
| Name | Type |
|---|---|
tileID | TileID |
Returns
boolean
Defined in
load
▸ load(callback?): void
Parameters
| Name | Type |
|---|---|
callback? | Callback<void> |
Returns
void
Defined in
loadRasterTile
▸ loadRasterTile(tile, callback): void
Parameters
| Name | Type |
|---|---|
tile | Tile |
callback | Callback<void> |
Returns
void
Defined in
loadRasterTileData
▸ loadRasterTileData(tile, data): void
Parameters
| Name | Type |
|---|---|
tile | Tile |
data | any |
Returns
void
Defined in
loadVectorTile
▸ loadVectorTile(tile, callback): void
Parameters
| Name | Type |
|---|---|
tile | Tile |
callback | Callback<void> |
Returns
void
Defined in
loaded
▸ loaded(): boolean
Returns
boolean
Defined in
getHeader
▸ getHeader(url): Promise<any>
An static function to get the header of an pmtiles
Parameters
| Name | Type | Description |
|---|---|---|
url | string | The pmTiles URL |
Returns
Promise<any>
A Json object of the PmTile's header
Defined in
getMetadata
▸ getMetadata(url): Promise<any>
An static function to get the metadata of a pmtiles
Parameters
| Name | Type | Description |
|---|---|---|
url | string | The pmTiles URL |
Returns
Promise<any>
A Json object of the PmTile's metadata