@loaders.gl/mvt 4.1.0-alpha.1 → 4.1.0-alpha.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/dist.dev.js +54 -18
- package/dist/index.cjs +51 -15
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/lib/geojson-tiler/clip.d.ts.map +1 -1
- package/dist/lib/geojson-tiler/clip.js.map +1 -1
- package/dist/lib/geojson-tiler/convert.d.ts.map +1 -1
- package/dist/lib/geojson-tiler/convert.js.map +1 -1
- package/dist/lib/geojson-tiler/feature.d.ts.map +1 -1
- package/dist/lib/geojson-tiler/feature.js.map +1 -1
- package/dist/lib/geojson-tiler/geojson-tiler.d.ts.map +1 -1
- package/dist/lib/geojson-tiler/geojson-tiler.js.map +1 -1
- package/dist/lib/geojson-tiler/simplify.d.ts.map +1 -1
- package/dist/lib/geojson-tiler/simplify.js.map +1 -1
- package/dist/lib/geojson-tiler/tile.d.ts.map +1 -1
- package/dist/lib/geojson-tiler/tile.js.map +1 -1
- package/dist/lib/geojson-tiler/transform.d.ts.map +1 -1
- package/dist/lib/geojson-tiler/transform.js.map +1 -1
- package/dist/lib/geojson-tiler/wrap.d.ts.map +1 -1
- package/dist/lib/geojson-tiler/wrap.js.map +1 -1
- package/dist/lib/parse-tilejson.d.ts +2 -1
- package/dist/lib/parse-tilejson.d.ts.map +1 -1
- package/dist/lib/parse-tilejson.js +6 -3
- package/dist/lib/parse-tilejson.js.map +1 -1
- package/dist/lib/types.d.ts +1 -3
- package/dist/lib/types.d.ts.map +1 -1
- package/dist/lib/types.js.map +1 -1
- package/dist/mvt-loader.js +1 -1
- package/dist/mvt-loader.js.map +1 -1
- package/dist/mvt-source.d.ts +34 -8
- package/dist/mvt-source.d.ts.map +1 -1
- package/dist/mvt-source.js +47 -13
- package/dist/mvt-source.js.map +1 -1
- package/dist/mvt-worker.js +1 -1
- package/dist/tilejson-loader.d.ts +3 -1
- package/dist/tilejson-loader.d.ts.map +1 -1
- package/dist/tilejson-loader.js +2 -2
- package/dist/tilejson-loader.js.map +1 -1
- package/package.json +8 -8
- package/src/index.ts +2 -1
- package/src/lib/geojson-tiler/clip.ts +2 -1
- package/src/lib/geojson-tiler/convert.ts +2 -1
- package/src/lib/geojson-tiler/feature.ts +2 -1
- package/src/lib/geojson-tiler/geojson-tiler.ts +2 -1
- package/src/lib/geojson-tiler/simplify.ts +2 -1
- package/src/lib/geojson-tiler/tile.ts +2 -1
- package/src/lib/geojson-tiler/transform.ts +2 -1
- package/src/lib/geojson-tiler/wrap.ts +2 -1
- package/src/lib/parse-tilejson.ts +12 -4
- package/src/lib/types.ts +1 -3
- package/src/mvt-source.ts +105 -20
- package/src/tilejson-loader.ts +6 -3
package/dist/mvt-source.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mvt-source.js","names":["DataSource","resolvePath","ImageLoader","getBinaryImageMetadata","MVTLoader","TileJSONLoader","MVTSource","constructor","props","url","data","schema","metadata","extension","mimeType","x","getTileData","bind","getMetadata","_TileJSONLoader$parse","metadataUrl","getMetadataUrl","response","fetch","error","console","message","ok","statusText","tileJSON","text","parseTextSync","call","JSON","stringify","getTileMIMEType","getTile","tileParams","y","zoom","z","tileUrl","getTileURL","arrayBuffer","index","layers","imageMetadata","parseVectorTile","parseImageTile","getImageTile","parse","loadOptions","getVectorTile","_this$loadOptions","shape","mvt","coordinates","tileIndex"],"sources":["../src/mvt-source.ts"],"sourcesContent":["// loaders.gl, MIT license\n// Copyright (c) vis.gl contributors\n\nimport type {GetTileParameters, ImageType, DataSourceProps} from '@loaders.gl/loader-utils';\nimport type {ImageTileSource, VectorTileSource} from '@loaders.gl/loader-utils';\nimport {DataSource, resolvePath} from '@loaders.gl/loader-utils';\nimport {ImageLoader, getBinaryImageMetadata} from '@loaders.gl/images';\nimport {MVTLoader, MVTLoaderOptions, TileJSONLoader, TileJSON} from '@loaders.gl/mvt';\n\nimport {TileLoadParameters} from '@loaders.gl/loader-utils';\n\nexport type MVTSourceProps = DataSourceProps & {\n url: string;\n attributions?: string[];\n};\n\n/**\n * A PMTiles data source\n * @note Can be either a raster or vector tile source depending on the contents of the PMTiles file.\n */\nexport class MVTSource extends DataSource implements ImageTileSource, VectorTileSource {\n props: MVTSourceProps;\n url: string;\n data: string;\n schema: 'tms' | 'xyz' = 'tms';\n metadata: Promise<TileJSON | null>;\n extension = '.png';\n mimeType: string | null = null;\n\n constructor(props: MVTSourceProps) {\n super(props);\n this.props = props;\n this.url = resolvePath(props.url);\n this.data = this.url;\n this.getTileData = this.getTileData.bind(this);\n this.metadata = this.getMetadata();\n }\n\n // @ts-ignore - Metadata type misalignment\n async getMetadata(): Promise<TileJSON | null> {\n const metadataUrl = this.getMetadataUrl();\n let response: Response;\n try {\n // Annoyingly, on CORS errors, fetch doesn't use the response status/ok mechanism but instead throws\n // CORS errors are common when requesting an unavailable sub resource such as a metadata file or an unavailable tile)\n response = await this.fetch(metadataUrl);\n } catch (error: unknown) {\n // eslint-disable-next-line no-console\n console.error((error as TypeError).message);\n return null;\n }\n if (!response.ok) {\n // eslint-disable-next-line no-console\n console.error(response.statusText);\n return null;\n }\n const tileJSON = await response.text();\n const metadata = TileJSONLoader.parseTextSync?.(JSON.stringify(tileJSON)) || null;\n // metadata.attributions = [...this.props.attributions, ...(metadata.attributions || [])];\n // if (metadata?.mimeType) {\n // this.mimeType = metadata?.tileMIMEType;\n // }\n return metadata;\n }\n\n getTileMIMEType(): string | null {\n return this.mimeType;\n }\n\n async getTile(tileParams: GetTileParameters): Promise<ArrayBuffer | null> {\n const {x, y, zoom: z} = tileParams;\n const tileUrl = this.getTileURL(x, y, z);\n const response = await this.fetch(tileUrl);\n if (!response.ok) {\n return null;\n }\n const arrayBuffer = await response.arrayBuffer();\n return arrayBuffer;\n }\n\n // Tile Source interface implementation: deck.gl compatible API\n // TODO - currently only handles image tiles, not vector tiles\n\n async getTileData(tileParams: TileLoadParameters): Promise<unknown | null> {\n const {x, y, z} = tileParams.index;\n // const metadata = await this.metadata;\n // mimeType = metadata?.tileMIMEType || 'application/vnd.mapbox-vector-tile';\n\n const arrayBuffer = await this.getTile({x, y, zoom: z, layers: []});\n if (arrayBuffer === null) {\n return null;\n }\n\n const imageMetadata = getBinaryImageMetadata(arrayBuffer);\n this.mimeType =\n this.mimeType || imageMetadata?.mimeType || 'application/vnd.mapbox-vector-tile';\n switch (this.mimeType) {\n case 'application/vnd.mapbox-vector-tile':\n return await this.parseVectorTile(arrayBuffer, {x, y, zoom: z, layers: []});\n default:\n return await this.parseImageTile(arrayBuffer);\n }\n }\n x;\n\n // ImageTileSource interface implementation\n\n async getImageTile(tileParams: GetTileParameters): Promise<ImageType | null> {\n const arrayBuffer = await this.getTile(tileParams);\n return arrayBuffer ? this.parseImageTile(arrayBuffer) : null;\n }\n\n protected async parseImageTile(arrayBuffer: ArrayBuffer): Promise<ImageType> {\n return await ImageLoader.parse(arrayBuffer, this.loadOptions);\n }\n\n // VectorTileSource interface implementation\n\n async getVectorTile(tileParams: GetTileParameters): Promise<unknown | null> {\n const arrayBuffer = await this.getTile(tileParams);\n return arrayBuffer ? this.parseVectorTile(arrayBuffer, tileParams) : null;\n }\n\n protected async parseVectorTile(\n arrayBuffer: ArrayBuffer,\n tileParams: GetTileParameters\n ): Promise<unknown | null> {\n const loadOptions: MVTLoaderOptions = {\n shape: 'geojson-table',\n mvt: {\n coordinates: 'wgs84',\n tileIndex: {x: tileParams.x, y: tileParams.y, z: tileParams.zoom},\n ...(this.loadOptions as MVTLoaderOptions)?.mvt\n },\n ...this.loadOptions\n };\n\n return await MVTLoader.parse(arrayBuffer, loadOptions);\n }\n\n getMetadataUrl(): string {\n return `${this.url}/tilejson.json`;\n }\n\n getTileURL(x: number, y: number, z: number) {\n switch (this.schema) {\n case 'xyz':\n return `${this.url}/${x}/${y}/${z}${this.extension}`;\n case 'tms':\n default:\n return `${this.url}/${z}/${x}/${y}${this.extension}`;\n }\n }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,WAAW,cAAAE,iBAAA,uBAAjBA,iBAAA,CAAwCE,GAAG;MAChD,CAAC;MACD,GAAG,IAAI,CAACJ;IACV,CAAC;IAED,OAAO,MAAM/C,SAAS,CAAC8C,KAAK,CAACP,WAAW,EAAEQ,WAAW,CAAC;EACxD;EAEA9B,cAAcA,CAAA,EAAW;IACvB,OAAQ,GAAE,IAAI,CAACZ,GAAI,gBAAe;EACpC;EAEAiC,UAAUA,CAAC3B,CAAS,EAAEuB,CAAS,EAAEE,CAAS,EAAE;IAC1C,QAAQ,IAAI,CAAC7B,MAAM;MACjB,KAAK,KAAK;QACR,OAAQ,GAAE,IAAI,CAACF,GAAI,IAAGM,CAAE,IAAGuB,CAAE,IAAGE,CAAE,GAAE,IAAI,CAAC3B,SAAU,EAAC;MACtD,KAAK,KAAK;MACV;QACE,OAAQ,GAAE,IAAI,CAACJ,GAAI,IAAG+B,CAAE,IAAGzB,CAAE,IAAGuB,CAAE,GAAE,IAAI,CAACzB,SAAU,EAAC;IACxD;EACF;AACF"}
|
|
1
|
+
{"version":3,"file":"mvt-source.js","names":["DataSource","resolvePath","ImageLoader","getBinaryImageMetadata","MVTLoader","TileJSONLoader","MVTSource","constructor","props","url","metadataUrl","data","schema","metadata","extension","mimeType","undefined","getTileData","bind","getMetadata","isURLTemplate","_TileJSONLoader$parse","response","fetch","error","console","message","ok","statusText","tileJSON","text","parseTextSync","call","getTileMIMEType","getTile","tileParams","x","y","zoom","z","tileUrl","getTileURL","arrayBuffer","index","layers","imageMetadata","_parseVectorTile","_parseImageTile","getImageTile","parse","loadOptions","getVectorTile","_this$loadOptions","shape","mvt","coordinates","tileIndex","getMetadataUrl","getURLFromTemplate","Error","s","test","xRegex","RegExp","yRegex","zRegex","template","id","arguments","length","Array","isArray","i","stringHash","replace","String","Number","isInteger","Math","pow","abs","split","reduce","a","b","charCodeAt"],"sources":["../src/mvt-source.ts"],"sourcesContent":["// loaders.gl\n// SPDX-License-Identifier: MIT\n// Copyright (c) vis.gl contributors\n\nimport type {GetTileParameters, ImageType, DataSourceProps} from '@loaders.gl/loader-utils';\nimport type {ImageTileSource, VectorTileSource} from '@loaders.gl/loader-utils';\nimport {DataSource, resolvePath} from '@loaders.gl/loader-utils';\nimport {ImageLoader, ImageLoaderOptions, getBinaryImageMetadata} from '@loaders.gl/images';\nimport {\n MVTLoader,\n MVTLoaderOptions,\n TileJSONLoader,\n TileJSON,\n TileJSONLoaderOptions\n} from '@loaders.gl/mvt';\n\nimport {TileLoadParameters} from '@loaders.gl/loader-utils';\n\n/** Properties for a Mapbox Vector Tile Source */\nexport type MVTSourceProps = DataSourceProps & {\n /** Root url of tileset */\n url: string;\n /** if not supplied, loads tilejson.json, If null does not load metadata */\n metadataUrl?: string | null;\n /** Override extension (necessary if no metadata) */\n extension?: string;\n /** Additional attribution, adds to any attribution loaded from tileset metadata */\n attributions?: string[];\n /** Specify load options for all sub loaders */\n loadOptions?: TileJSONLoaderOptions & MVTLoaderOptions & ImageLoaderOptions;\n};\n\n/**\n * MVT data source for Mapbox Vector Tiles v1.\n */\n/**\n * A PMTiles data source\n * @note Can be either a raster or vector tile source depending on the contents of the PMTiles file.\n */\nexport class MVTSource extends DataSource implements ImageTileSource, VectorTileSource {\n readonly props: MVTSourceProps;\n readonly url: string;\n readonly metadataUrl: string | null = null;\n data: string;\n schema: 'tms' | 'xyz' | 'template' = 'tms';\n metadata: Promise<TileJSON | null>;\n extension: string;\n mimeType: string | null = null;\n\n constructor(props: MVTSourceProps) {\n super(props);\n this.props = props;\n this.url = resolvePath(props.url);\n this.metadataUrl =\n props.metadataUrl === undefined ? `${this.url}/tilejson.json` : props.metadataUrl;\n this.extension = props.extension || '.png';\n this.data = this.url;\n\n this.getTileData = this.getTileData.bind(this);\n this.metadata = this.getMetadata();\n\n if (isURLTemplate(this.url)) {\n this.schema = 'template';\n }\n }\n\n // @ts-ignore - Metadata type misalignment\n async getMetadata(): Promise<TileJSON | null> {\n if (!this.metadataUrl) {\n return null;\n }\n\n let response: Response;\n try {\n // Annoyingly, on CORS errors, fetch doesn't use the response status/ok mechanism but instead throws\n // CORS errors are common when requesting an unavailable sub resource such as a metadata file or an unavailable tile)\n response = await this.fetch(this.metadataUrl);\n } catch (error: unknown) {\n // eslint-disable-next-line no-console\n console.error((error as TypeError).message);\n return null;\n }\n if (!response.ok) {\n // eslint-disable-next-line no-console\n console.error(response.statusText);\n return null;\n }\n const tileJSON = await response.text();\n const metadata = TileJSONLoader.parseTextSync?.(tileJSON) || null;\n\n // TODO add metadata attributions\n // metadata.attributions = [...this.props.attributions, ...(metadata.attributions || [])];\n // if (metadata?.mimeType) {\n // this.mimeType = metadata?.tileMIMEType;\n // }\n\n return metadata;\n }\n\n getTileMIMEType(): string | null {\n return this.mimeType;\n }\n\n async getTile(tileParams: GetTileParameters): Promise<ArrayBuffer | null> {\n const {x, y, zoom: z} = tileParams;\n const tileUrl = this.getTileURL(x, y, z);\n const response = await this.fetch(tileUrl);\n if (!response.ok) {\n return null;\n }\n const arrayBuffer = await response.arrayBuffer();\n return arrayBuffer;\n }\n\n // Tile Source interface implementation: deck.gl compatible API\n // TODO - currently only handles image tiles, not vector tiles\n\n async getTileData(tileParams: TileLoadParameters): Promise<unknown | null> {\n const {x, y, z} = tileParams.index;\n // const metadata = await this.metadata;\n // mimeType = metadata?.tileMIMEType || 'application/vnd.mapbox-vector-tile';\n\n const arrayBuffer = await this.getTile({x, y, zoom: z, layers: []});\n if (arrayBuffer === null) {\n return null;\n }\n\n const imageMetadata = getBinaryImageMetadata(arrayBuffer);\n this.mimeType =\n this.mimeType || imageMetadata?.mimeType || 'application/vnd.mapbox-vector-tile';\n switch (this.mimeType) {\n case 'application/vnd.mapbox-vector-tile':\n return await this._parseVectorTile(arrayBuffer, {x, y, zoom: z, layers: []});\n default:\n return await this._parseImageTile(arrayBuffer);\n }\n }\n\n // ImageTileSource interface implementation\n\n async getImageTile(tileParams: GetTileParameters): Promise<ImageType | null> {\n const arrayBuffer = await this.getTile(tileParams);\n return arrayBuffer ? this._parseImageTile(arrayBuffer) : null;\n }\n\n protected async _parseImageTile(arrayBuffer: ArrayBuffer): Promise<ImageType> {\n return await ImageLoader.parse(arrayBuffer, this.loadOptions);\n }\n\n // VectorTileSource interface implementation\n\n async getVectorTile(tileParams: GetTileParameters): Promise<unknown | null> {\n const arrayBuffer = await this.getTile(tileParams);\n return arrayBuffer ? this._parseVectorTile(arrayBuffer, tileParams) : null;\n }\n\n protected async _parseVectorTile(\n arrayBuffer: ArrayBuffer,\n tileParams: GetTileParameters\n ): Promise<unknown | null> {\n const loadOptions: MVTLoaderOptions = {\n shape: 'geojson-table',\n mvt: {\n coordinates: 'wgs84',\n tileIndex: {x: tileParams.x, y: tileParams.y, z: tileParams.zoom},\n ...(this.loadOptions as MVTLoaderOptions)?.mvt\n },\n ...this.loadOptions\n };\n\n return await MVTLoader.parse(arrayBuffer, loadOptions);\n }\n\n getMetadataUrl(): string | null {\n return this.metadataUrl;\n }\n\n getTileURL(x: number, y: number, z: number) {\n switch (this.schema) {\n case 'xyz':\n return `${this.url}/${x}/${y}/${z}${this.extension}`;\n case 'tms':\n return `${this.url}/${z}/${x}/${y}${this.extension}`;\n case 'template':\n return getURLFromTemplate(this.url, x, y, z, '0');\n default:\n throw new Error(this.schema);\n }\n }\n}\n\nexport function isURLTemplate(s: string): boolean {\n return /(?=.*{z})(?=.*{x})(?=.*({y}|{-y}))|(?=.*{x})(?=.*({y}|{-y})(?=.*{z}))/.test(s);\n}\n\nexport type URLTemplate = string | string[];\n\nconst xRegex = new RegExp('{x}', 'g');\nconst yRegex = new RegExp('{y}', 'g');\nconst zRegex = new RegExp('{z}', 'g');\n\n/**\n * Get a URL from a URL template\n * @note copied from deck.gl/modules/geo-layers/src/tileset-2d/utils.ts\n * @param template - URL template\n * @param x - tile x coordinate\n * @param y - tile y coordinate\n * @param z - tile z coordinate\n * @param id - tile id\n * @returns URL\n */\nexport function getURLFromTemplate(\n template: URLTemplate,\n x: number,\n y: number,\n z: number,\n id: string = '0'\n): string {\n if (Array.isArray(template)) {\n const i = stringHash(id) % template.length;\n template = template[i];\n }\n\n let url = template;\n url = url.replace(xRegex, String(x));\n url = url.replace(yRegex, String(y));\n url = url.replace(zRegex, String(z));\n\n // Back-compatible support for {-y}\n if (Number.isInteger(y) && Number.isInteger(z)) {\n url = url.replace(/\\{-y\\}/g, String(Math.pow(2, z) - y - 1));\n }\n\n return url;\n}\n\nfunction stringHash(s: string): number {\n return Math.abs(s.split('').reduce((a, b) => ((a << 5) - a + b.charCodeAt(0)) | 0, 0));\n}\n"],"mappings":"AAMA,SAAQA,UAAU,EAAEC,WAAW,QAAO,0BAA0B;AAChE,SAAQC,WAAW,EAAsBC,sBAAsB,QAAO,oBAAoB;AAC1F,SACEC,SAAS,EAETC,cAAc,QAGT,iBAAiB;AAyBxB,OAAO,MAAMC,SAAS,SAASN,UAAU,CAA8C;EAUrFO,WAAWA,CAACC,KAAqB,EAAE;IACjC,KAAK,CAACA,KAAK,CAAC;IAAC,KAVNA,KAAK;IAAA,KACLC,GAAG;IAAA,KACHC,WAAW,GAAkB,IAAI;IAAA,KAC1CC,IAAI;IAAA,KACJC,MAAM,GAA+B,KAAK;IAAA,KAC1CC,QAAQ;IAAA,KACRC,SAAS;IAAA,KACTC,QAAQ,GAAkB,IAAI;IAI5B,IAAI,CAACP,KAAK,GAAGA,KAAK;IAClB,IAAI,CAACC,GAAG,GAAGR,WAAW,CAACO,KAAK,CAACC,GAAG,CAAC;IACjC,IAAI,CAACC,WAAW,GACdF,KAAK,CAACE,WAAW,KAAKM,SAAS,GAAI,GAAE,IAAI,CAACP,GAAI,gBAAe,GAAGD,KAAK,CAACE,WAAW;IACnF,IAAI,CAACI,SAAS,GAAGN,KAAK,CAACM,SAAS,IAAI,MAAM;IAC1C,IAAI,CAACH,IAAI,GAAG,IAAI,CAACF,GAAG;IAEpB,IAAI,CAACQ,WAAW,GAAG,IAAI,CAACA,WAAW,CAACC,IAAI,CAAC,IAAI,CAAC;IAC9C,IAAI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AM,CAACC,SAAS,CAACtC,CAAC,CAAC,EAAE;IAC9C9B,GAAG,GAAGA,GAAG,CAACiE,OAAO,CAAC,SAAS,EAAEC,MAAM,CAACG,IAAI,CAACC,GAAG,CAAC,CAAC,EAAExC,CAAC,CAAC,GAAGF,CAAC,GAAG,CAAC,CAAC,CAAC;EAC9D;EAEA,OAAO5B,GAAG;AACZ;AAEA,SAASgE,UAAUA,CAACb,CAAS,EAAU;EACrC,OAAOkB,IAAI,CAACE,GAAG,CAACpB,CAAC,CAACqB,KAAK,CAAC,EAAE,CAAC,CAACC,MAAM,CAAC,CAACC,CAAC,EAAEC,CAAC,KAAM,CAACD,CAAC,IAAI,CAAC,IAAIA,CAAC,GAAGC,CAAC,CAACC,UAAU,CAAC,CAAC,CAAC,GAAI,CAAC,EAAE,CAAC,CAAC,CAAC;AACxF"}
|
package/dist/mvt-worker.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import type { LoaderWithParser, LoaderOptions } from '@loaders.gl/loader-utils';
|
|
2
2
|
import type { TileJSON } from './lib/parse-tilejson';
|
|
3
3
|
export type TileJSONLoaderOptions = LoaderOptions & {
|
|
4
|
+
/** Options for the TileJSONLoader */
|
|
4
5
|
tilejson?: {
|
|
5
|
-
|
|
6
|
+
/** Max number of unique values */
|
|
7
|
+
maxValues?: number;
|
|
6
8
|
};
|
|
7
9
|
};
|
|
8
10
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tilejson-loader.d.ts","sourceRoot":"","sources":["../src/tilejson-loader.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"tilejson-loader.d.ts","sourceRoot":"","sources":["../src/tilejson-loader.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAC,gBAAgB,EAAE,aAAa,EAAC,MAAM,0BAA0B,CAAC;AAC9E,OAAO,KAAK,EAAC,QAAQ,EAAC,MAAM,sBAAsB,CAAC;AAOnD,MAAM,MAAM,qBAAqB,GAAG,aAAa,GAAG;IAClD,qCAAqC;IACrC,QAAQ,CAAC,EAAE;QACT,kCAAkC;QAClC,SAAS,CAAC,EAAE,MAAM,CAAC;KACpB,CAAC;CACH,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,cAAc,EAAE,gBAAgB,CAAC,QAAQ,EAAE,KAAK,EAAE,qBAAqB,CAyBnF,CAAC"}
|
package/dist/tilejson-loader.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { parseTileJSON } from "./lib/parse-tilejson.js";
|
|
2
|
-
const VERSION = typeof
|
|
2
|
+
const VERSION = typeof "4.1.0-alpha.11" !== 'undefined' ? "4.1.0-alpha.11" : 'latest';
|
|
3
3
|
export const TileJSONLoader = {
|
|
4
4
|
name: 'TileJSON',
|
|
5
5
|
id: 'tilejson',
|
|
@@ -11,7 +11,7 @@ export const TileJSONLoader = {
|
|
|
11
11
|
text: true,
|
|
12
12
|
options: {
|
|
13
13
|
tilejson: {
|
|
14
|
-
maxValues:
|
|
14
|
+
maxValues: undefined
|
|
15
15
|
}
|
|
16
16
|
},
|
|
17
17
|
parse: async (arrayBuffer, options) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tilejson-loader.js","names":["parseTileJSON","VERSION","
|
|
1
|
+
{"version":3,"file":"tilejson-loader.js","names":["parseTileJSON","VERSION","TileJSONLoader","name","id","module","version","worker","extensions","mimeTypes","text","options","tilejson","maxValues","undefined","parse","arrayBuffer","jsonString","TextDecoder","decode","json","JSON","tilejsonOptions","parseTextSync"],"sources":["../src/tilejson-loader.ts"],"sourcesContent":["// loaders.gl\n// SPDX-License-Identifier: MIT\n// Copyright (c) vis.gl contributors\n\nimport type {LoaderWithParser, LoaderOptions} from '@loaders.gl/loader-utils';\nimport type {TileJSON} from './lib/parse-tilejson';\nimport {parseTileJSON} from './lib/parse-tilejson';\n\n// __VERSION__ is injected by babel-plugin-version-inline\n// @ts-ignore TS2304: Cannot find name '__VERSION__'.\nconst VERSION = typeof __VERSION__ !== 'undefined' ? __VERSION__ : 'latest';\n\nexport type TileJSONLoaderOptions = LoaderOptions & {\n /** Options for the TileJSONLoader */\n tilejson?: {\n /** Max number of unique values */\n maxValues?: number;\n };\n};\n\n/**\n * Loader for TileJSON metadata\n */\nexport const TileJSONLoader: LoaderWithParser<TileJSON, never, TileJSONLoaderOptions> = {\n name: 'TileJSON',\n id: 'tilejson',\n module: 'pmtiles',\n version: VERSION,\n worker: true,\n extensions: ['json'],\n mimeTypes: ['application/json'],\n text: true,\n options: {\n tilejson: {\n maxValues: undefined\n }\n },\n parse: async (arrayBuffer, options?: TileJSONLoaderOptions) => {\n const jsonString = new TextDecoder().decode(arrayBuffer);\n const json = JSON.parse(jsonString);\n const tilejsonOptions = {...TileJSONLoader.options.tilejson, ...options?.tilejson};\n return parseTileJSON(json, tilejsonOptions) as TileJSON;\n },\n parseTextSync: (text, options) => {\n const json = JSON.parse(text);\n const tilejsonOptions = {...TileJSONLoader.options.tilejson, ...options?.tilejson};\n return parseTileJSON(json, tilejsonOptions) as TileJSON;\n }\n};\n"],"mappings":"SAMQA,aAAa;AAIrB,MAAMC,OAAO,GAAG,uBAAkB,KAAK,WAAW,sBAAiB,QAAQ;AAa3E,OAAO,MAAMC,cAAwE,GAAG;EACtFC,IAAI,EAAE,UAAU;EAChBC,EAAE,EAAE,UAAU;EACdC,MAAM,EAAE,SAAS;EACjBC,OAAO,EAAEL,OAAO;EAChBM,MAAM,EAAE,IAAI;EACZC,UAAU,EAAE,CAAC,MAAM,CAAC;EACpBC,SAAS,EAAE,CAAC,kBAAkB,CAAC;EAC/BC,IAAI,EAAE,IAAI;EACVC,OAAO,EAAE;IACPC,QAAQ,EAAE;MACRC,SAAS,EAAEC;IACb;EACF,CAAC;EACDC,KAAK,EAAE,MAAAA,CAAOC,WAAW,EAAEL,OAA+B,KAAK;IAC7D,MAAMM,UAAU,GAAG,IAAIC,WAAW,CAAC,CAAC,CAACC,MAAM,CAACH,WAAW,CAAC;IACxD,MAAMI,IAAI,GAAGC,IAAI,CAACN,KAAK,CAACE,UAAU,CAAC;IACnC,MAAMK,eAAe,GAAG;MAAC,GAAGpB,cAAc,CAACS,OAAO,CAACC,QAAQ;MAAE,IAAGD,OAAO,aAAPA,OAAO,uBAAPA,OAAO,CAAEC,QAAQ;IAAA,CAAC;IAClF,OAAOZ,aAAa,CAACoB,IAAI,EAAEE,eAAe,CAAC;EAC7C,CAAC;EACDC,aAAa,EAAEA,CAACb,IAAI,EAAEC,OAAO,KAAK;IAChC,MAAMS,IAAI,GAAGC,IAAI,CAACN,KAAK,CAACL,IAAI,CAAC;IAC7B,MAAMY,eAAe,GAAG;MAAC,GAAGpB,cAAc,CAACS,OAAO,CAACC,QAAQ;MAAE,IAAGD,OAAO,aAAPA,OAAO,uBAAPA,OAAO,CAAEC,QAAQ;IAAA,CAAC;IAClF,OAAOZ,aAAa,CAACoB,IAAI,EAAEE,eAAe,CAAC;EAC7C;AACF,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@loaders.gl/mvt",
|
|
3
3
|
"description": "Loader for Mapbox Vector Tiles",
|
|
4
|
-
"version": "4.1.0-alpha.
|
|
4
|
+
"version": "4.1.0-alpha.11",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"publishConfig": {
|
|
@@ -23,9 +23,9 @@
|
|
|
23
23
|
"module": "dist/index.js",
|
|
24
24
|
"exports": {
|
|
25
25
|
".": {
|
|
26
|
+
"types": "./dist/index.d.ts",
|
|
26
27
|
"import": "./dist/index.js",
|
|
27
|
-
"require": "./dist/index.cjs"
|
|
28
|
-
"types": "./dist/index.d.ts"
|
|
28
|
+
"require": "./dist/index.cjs"
|
|
29
29
|
}
|
|
30
30
|
},
|
|
31
31
|
"sideEffects": false,
|
|
@@ -40,15 +40,15 @@
|
|
|
40
40
|
"build-worker": "esbuild src/workers/mvt-worker.ts --bundle --outfile=dist/mvt-worker.js --define:__VERSION__=\\\"$npm_package_version\\\""
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@loaders.gl/gis": "4.1.0-alpha.
|
|
44
|
-
"@loaders.gl/images": "4.1.0-alpha.
|
|
45
|
-
"@loaders.gl/loader-utils": "4.1.0-alpha.
|
|
46
|
-
"@loaders.gl/schema": "4.1.0-alpha.
|
|
43
|
+
"@loaders.gl/gis": "4.1.0-alpha.11",
|
|
44
|
+
"@loaders.gl/images": "4.1.0-alpha.11",
|
|
45
|
+
"@loaders.gl/loader-utils": "4.1.0-alpha.11",
|
|
46
|
+
"@loaders.gl/schema": "4.1.0-alpha.11",
|
|
47
47
|
"@math.gl/polygon": "^4.0.0",
|
|
48
48
|
"pbf": "^3.2.1"
|
|
49
49
|
},
|
|
50
50
|
"devDependencies": {
|
|
51
51
|
"@types/pbf": "^3.0.2"
|
|
52
52
|
},
|
|
53
|
-
"gitHead": "
|
|
53
|
+
"gitHead": "5d3e23bf93762b48c8c1d6d926ede7a97fe43ab0"
|
|
54
54
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
// loaders.gl
|
|
1
|
+
// loaders.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
2
3
|
// Copyright (c) vis.gl contributors
|
|
3
4
|
|
|
4
5
|
export type TileJSONOptions = {
|
|
5
|
-
|
|
6
|
+
/** max number of values. If not provided, include all values in the source tilestats */
|
|
7
|
+
maxValues?: number;
|
|
6
8
|
};
|
|
7
9
|
|
|
8
10
|
/** Parsed and typed TileJSON, merges Tilestats information if present */
|
|
@@ -400,10 +402,16 @@ function attributeToField(
|
|
|
400
402
|
if (typeof attribute.count === 'number') {
|
|
401
403
|
field.uniqueValueCount = attribute.count;
|
|
402
404
|
}
|
|
403
|
-
if (
|
|
405
|
+
if (attribute.values) {
|
|
404
406
|
// Too much data? Add option?
|
|
405
|
-
field.values = attribute.values
|
|
407
|
+
field.values = attribute.values;
|
|
406
408
|
}
|
|
409
|
+
|
|
410
|
+
if (field.values && typeof options.maxValues === 'number') {
|
|
411
|
+
// Too much data? Add option?
|
|
412
|
+
field.values = field.values?.slice(0, options.maxValues);
|
|
413
|
+
}
|
|
414
|
+
|
|
407
415
|
return field;
|
|
408
416
|
}
|
|
409
417
|
|
package/src/lib/types.ts
CHANGED
|
@@ -59,9 +59,7 @@ export type MVTMapboxCoordinates = {
|
|
|
59
59
|
export type MVTLoaderOptions = LoaderOptions & {
|
|
60
60
|
mvt?: MVTOptions;
|
|
61
61
|
gis?: {
|
|
62
|
-
/**
|
|
63
|
-
* When set to `true`, the parser will output the data in binary format. This is equivalent to loading the data as GeoJSON and then applying [geojsonToBinary](https://loaders.gl/modules/gis/docs/api-reference/geojson-to-binary).
|
|
64
|
-
*/
|
|
62
|
+
/** `true`: parser will output the data in binary format. Equivalent to loading the data as GeoJSON and then applying geojsonToBinary */
|
|
65
63
|
binary?: boolean;
|
|
66
64
|
/** @deprecated. Use options.mvt.shape */
|
|
67
65
|
format?: 'geojson-table' | 'columnar-table' | 'geojson' | 'binary' | 'binary-geometry';
|
package/src/mvt-source.ts
CHANGED
|
@@ -1,49 +1,80 @@
|
|
|
1
|
-
// loaders.gl
|
|
1
|
+
// loaders.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
2
3
|
// Copyright (c) vis.gl contributors
|
|
3
4
|
|
|
4
5
|
import type {GetTileParameters, ImageType, DataSourceProps} from '@loaders.gl/loader-utils';
|
|
5
6
|
import type {ImageTileSource, VectorTileSource} from '@loaders.gl/loader-utils';
|
|
6
7
|
import {DataSource, resolvePath} from '@loaders.gl/loader-utils';
|
|
7
|
-
import {ImageLoader, getBinaryImageMetadata} from '@loaders.gl/images';
|
|
8
|
-
import {
|
|
8
|
+
import {ImageLoader, ImageLoaderOptions, getBinaryImageMetadata} from '@loaders.gl/images';
|
|
9
|
+
import {
|
|
10
|
+
MVTLoader,
|
|
11
|
+
MVTLoaderOptions,
|
|
12
|
+
TileJSONLoader,
|
|
13
|
+
TileJSON,
|
|
14
|
+
TileJSONLoaderOptions
|
|
15
|
+
} from '@loaders.gl/mvt';
|
|
9
16
|
|
|
10
17
|
import {TileLoadParameters} from '@loaders.gl/loader-utils';
|
|
11
18
|
|
|
19
|
+
/** Properties for a Mapbox Vector Tile Source */
|
|
12
20
|
export type MVTSourceProps = DataSourceProps & {
|
|
21
|
+
/** Root url of tileset */
|
|
13
22
|
url: string;
|
|
23
|
+
/** if not supplied, loads tilejson.json, If null does not load metadata */
|
|
24
|
+
metadataUrl?: string | null;
|
|
25
|
+
/** Override extension (necessary if no metadata) */
|
|
26
|
+
extension?: string;
|
|
27
|
+
/** Additional attribution, adds to any attribution loaded from tileset metadata */
|
|
14
28
|
attributions?: string[];
|
|
29
|
+
/** Specify load options for all sub loaders */
|
|
30
|
+
loadOptions?: TileJSONLoaderOptions & MVTLoaderOptions & ImageLoaderOptions;
|
|
15
31
|
};
|
|
16
32
|
|
|
33
|
+
/**
|
|
34
|
+
* MVT data source for Mapbox Vector Tiles v1.
|
|
35
|
+
*/
|
|
17
36
|
/**
|
|
18
37
|
* A PMTiles data source
|
|
19
38
|
* @note Can be either a raster or vector tile source depending on the contents of the PMTiles file.
|
|
20
39
|
*/
|
|
21
40
|
export class MVTSource extends DataSource implements ImageTileSource, VectorTileSource {
|
|
22
|
-
props: MVTSourceProps;
|
|
23
|
-
url: string;
|
|
41
|
+
readonly props: MVTSourceProps;
|
|
42
|
+
readonly url: string;
|
|
43
|
+
readonly metadataUrl: string | null = null;
|
|
24
44
|
data: string;
|
|
25
|
-
schema: 'tms' | 'xyz' = 'tms';
|
|
45
|
+
schema: 'tms' | 'xyz' | 'template' = 'tms';
|
|
26
46
|
metadata: Promise<TileJSON | null>;
|
|
27
|
-
extension
|
|
47
|
+
extension: string;
|
|
28
48
|
mimeType: string | null = null;
|
|
29
49
|
|
|
30
50
|
constructor(props: MVTSourceProps) {
|
|
31
51
|
super(props);
|
|
32
52
|
this.props = props;
|
|
33
53
|
this.url = resolvePath(props.url);
|
|
54
|
+
this.metadataUrl =
|
|
55
|
+
props.metadataUrl === undefined ? `${this.url}/tilejson.json` : props.metadataUrl;
|
|
56
|
+
this.extension = props.extension || '.png';
|
|
34
57
|
this.data = this.url;
|
|
58
|
+
|
|
35
59
|
this.getTileData = this.getTileData.bind(this);
|
|
36
60
|
this.metadata = this.getMetadata();
|
|
61
|
+
|
|
62
|
+
if (isURLTemplate(this.url)) {
|
|
63
|
+
this.schema = 'template';
|
|
64
|
+
}
|
|
37
65
|
}
|
|
38
66
|
|
|
39
67
|
// @ts-ignore - Metadata type misalignment
|
|
40
68
|
async getMetadata(): Promise<TileJSON | null> {
|
|
41
|
-
|
|
69
|
+
if (!this.metadataUrl) {
|
|
70
|
+
return null;
|
|
71
|
+
}
|
|
72
|
+
|
|
42
73
|
let response: Response;
|
|
43
74
|
try {
|
|
44
75
|
// Annoyingly, on CORS errors, fetch doesn't use the response status/ok mechanism but instead throws
|
|
45
76
|
// CORS errors are common when requesting an unavailable sub resource such as a metadata file or an unavailable tile)
|
|
46
|
-
response = await this.fetch(metadataUrl);
|
|
77
|
+
response = await this.fetch(this.metadataUrl);
|
|
47
78
|
} catch (error: unknown) {
|
|
48
79
|
// eslint-disable-next-line no-console
|
|
49
80
|
console.error((error as TypeError).message);
|
|
@@ -55,11 +86,14 @@ export class MVTSource extends DataSource implements ImageTileSource, VectorTile
|
|
|
55
86
|
return null;
|
|
56
87
|
}
|
|
57
88
|
const tileJSON = await response.text();
|
|
58
|
-
const metadata = TileJSONLoader.parseTextSync?.(
|
|
89
|
+
const metadata = TileJSONLoader.parseTextSync?.(tileJSON) || null;
|
|
90
|
+
|
|
91
|
+
// TODO add metadata attributions
|
|
59
92
|
// metadata.attributions = [...this.props.attributions, ...(metadata.attributions || [])];
|
|
60
93
|
// if (metadata?.mimeType) {
|
|
61
94
|
// this.mimeType = metadata?.tileMIMEType;
|
|
62
95
|
// }
|
|
96
|
+
|
|
63
97
|
return metadata;
|
|
64
98
|
}
|
|
65
99
|
|
|
@@ -96,21 +130,20 @@ export class MVTSource extends DataSource implements ImageTileSource, VectorTile
|
|
|
96
130
|
this.mimeType || imageMetadata?.mimeType || 'application/vnd.mapbox-vector-tile';
|
|
97
131
|
switch (this.mimeType) {
|
|
98
132
|
case 'application/vnd.mapbox-vector-tile':
|
|
99
|
-
return await this.
|
|
133
|
+
return await this._parseVectorTile(arrayBuffer, {x, y, zoom: z, layers: []});
|
|
100
134
|
default:
|
|
101
|
-
return await this.
|
|
135
|
+
return await this._parseImageTile(arrayBuffer);
|
|
102
136
|
}
|
|
103
137
|
}
|
|
104
|
-
x;
|
|
105
138
|
|
|
106
139
|
// ImageTileSource interface implementation
|
|
107
140
|
|
|
108
141
|
async getImageTile(tileParams: GetTileParameters): Promise<ImageType | null> {
|
|
109
142
|
const arrayBuffer = await this.getTile(tileParams);
|
|
110
|
-
return arrayBuffer ? this.
|
|
143
|
+
return arrayBuffer ? this._parseImageTile(arrayBuffer) : null;
|
|
111
144
|
}
|
|
112
145
|
|
|
113
|
-
protected async
|
|
146
|
+
protected async _parseImageTile(arrayBuffer: ArrayBuffer): Promise<ImageType> {
|
|
114
147
|
return await ImageLoader.parse(arrayBuffer, this.loadOptions);
|
|
115
148
|
}
|
|
116
149
|
|
|
@@ -118,10 +151,10 @@ export class MVTSource extends DataSource implements ImageTileSource, VectorTile
|
|
|
118
151
|
|
|
119
152
|
async getVectorTile(tileParams: GetTileParameters): Promise<unknown | null> {
|
|
120
153
|
const arrayBuffer = await this.getTile(tileParams);
|
|
121
|
-
return arrayBuffer ? this.
|
|
154
|
+
return arrayBuffer ? this._parseVectorTile(arrayBuffer, tileParams) : null;
|
|
122
155
|
}
|
|
123
156
|
|
|
124
|
-
protected async
|
|
157
|
+
protected async _parseVectorTile(
|
|
125
158
|
arrayBuffer: ArrayBuffer,
|
|
126
159
|
tileParams: GetTileParameters
|
|
127
160
|
): Promise<unknown | null> {
|
|
@@ -138,8 +171,8 @@ export class MVTSource extends DataSource implements ImageTileSource, VectorTile
|
|
|
138
171
|
return await MVTLoader.parse(arrayBuffer, loadOptions);
|
|
139
172
|
}
|
|
140
173
|
|
|
141
|
-
getMetadataUrl(): string {
|
|
142
|
-
return
|
|
174
|
+
getMetadataUrl(): string | null {
|
|
175
|
+
return this.metadataUrl;
|
|
143
176
|
}
|
|
144
177
|
|
|
145
178
|
getTileURL(x: number, y: number, z: number) {
|
|
@@ -147,8 +180,60 @@ export class MVTSource extends DataSource implements ImageTileSource, VectorTile
|
|
|
147
180
|
case 'xyz':
|
|
148
181
|
return `${this.url}/${x}/${y}/${z}${this.extension}`;
|
|
149
182
|
case 'tms':
|
|
150
|
-
default:
|
|
151
183
|
return `${this.url}/${z}/${x}/${y}${this.extension}`;
|
|
184
|
+
case 'template':
|
|
185
|
+
return getURLFromTemplate(this.url, x, y, z, '0');
|
|
186
|
+
default:
|
|
187
|
+
throw new Error(this.schema);
|
|
152
188
|
}
|
|
153
189
|
}
|
|
154
190
|
}
|
|
191
|
+
|
|
192
|
+
export function isURLTemplate(s: string): boolean {
|
|
193
|
+
return /(?=.*{z})(?=.*{x})(?=.*({y}|{-y}))|(?=.*{x})(?=.*({y}|{-y})(?=.*{z}))/.test(s);
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
export type URLTemplate = string | string[];
|
|
197
|
+
|
|
198
|
+
const xRegex = new RegExp('{x}', 'g');
|
|
199
|
+
const yRegex = new RegExp('{y}', 'g');
|
|
200
|
+
const zRegex = new RegExp('{z}', 'g');
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* Get a URL from a URL template
|
|
204
|
+
* @note copied from deck.gl/modules/geo-layers/src/tileset-2d/utils.ts
|
|
205
|
+
* @param template - URL template
|
|
206
|
+
* @param x - tile x coordinate
|
|
207
|
+
* @param y - tile y coordinate
|
|
208
|
+
* @param z - tile z coordinate
|
|
209
|
+
* @param id - tile id
|
|
210
|
+
* @returns URL
|
|
211
|
+
*/
|
|
212
|
+
export function getURLFromTemplate(
|
|
213
|
+
template: URLTemplate,
|
|
214
|
+
x: number,
|
|
215
|
+
y: number,
|
|
216
|
+
z: number,
|
|
217
|
+
id: string = '0'
|
|
218
|
+
): string {
|
|
219
|
+
if (Array.isArray(template)) {
|
|
220
|
+
const i = stringHash(id) % template.length;
|
|
221
|
+
template = template[i];
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
let url = template;
|
|
225
|
+
url = url.replace(xRegex, String(x));
|
|
226
|
+
url = url.replace(yRegex, String(y));
|
|
227
|
+
url = url.replace(zRegex, String(z));
|
|
228
|
+
|
|
229
|
+
// Back-compatible support for {-y}
|
|
230
|
+
if (Number.isInteger(y) && Number.isInteger(z)) {
|
|
231
|
+
url = url.replace(/\{-y\}/g, String(Math.pow(2, z) - y - 1));
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
return url;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
function stringHash(s: string): number {
|
|
238
|
+
return Math.abs(s.split('').reduce((a, b) => ((a << 5) - a + b.charCodeAt(0)) | 0, 0));
|
|
239
|
+
}
|
package/src/tilejson-loader.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
// loaders.gl
|
|
1
|
+
// loaders.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
2
3
|
// Copyright (c) vis.gl contributors
|
|
3
4
|
|
|
4
5
|
import type {LoaderWithParser, LoaderOptions} from '@loaders.gl/loader-utils';
|
|
@@ -10,8 +11,10 @@ import {parseTileJSON} from './lib/parse-tilejson';
|
|
|
10
11
|
const VERSION = typeof __VERSION__ !== 'undefined' ? __VERSION__ : 'latest';
|
|
11
12
|
|
|
12
13
|
export type TileJSONLoaderOptions = LoaderOptions & {
|
|
14
|
+
/** Options for the TileJSONLoader */
|
|
13
15
|
tilejson?: {
|
|
14
|
-
|
|
16
|
+
/** Max number of unique values */
|
|
17
|
+
maxValues?: number;
|
|
15
18
|
};
|
|
16
19
|
};
|
|
17
20
|
|
|
@@ -29,7 +32,7 @@ export const TileJSONLoader: LoaderWithParser<TileJSON, never, TileJSONLoaderOpt
|
|
|
29
32
|
text: true,
|
|
30
33
|
options: {
|
|
31
34
|
tilejson: {
|
|
32
|
-
maxValues:
|
|
35
|
+
maxValues: undefined
|
|
33
36
|
}
|
|
34
37
|
},
|
|
35
38
|
parse: async (arrayBuffer, options?: TileJSONLoaderOptions) => {
|