private _createTileRenderables()

in packages/layers/xyz-aoi-tile/src/AOILayer.ts [467:559]


	private _createTileRenderables(token, projection, polaris) {
		const dataType = this.getProp('dataType')
		const geojsonFilter = this.getProp('geojsonFilter')
		const x = token[0],
			y = token[1],
			z = token[2]

		const requestPending = this.requestManager.request({ x, y, z })
		const cacheKey = this._getCacheKey(x, y, z)

		// perf indicator
		this.info.times.set(cacheKey, { reqTime: performance.now(), genTime: 0 })

		const promise = new Promise<TileRenderables>((resolve, reject) => {
			requestPending.promise
				.then((data) => {
					// Perf log
					const time = this.info.times.get(cacheKey)
					if (time) {
						time.reqTime = performance.now() - time.reqTime
						time.genTime = performance.now()
					}

					let geojson: any

					const emptyTile = {
						meshes: [],
						layers: [],
					}

					// parse response to geojson
					if (dataType === 'pbf') {
						geojson = decode(new Pbf(data))
					} else if (dataType === 'geojson') {
						geojson = data
					} else if (dataType === 'auto') {
						if (data.constructor === ArrayBuffer) {
							geojson = decode(new Pbf(data))
						} else if (typeof data === 'string') {
							geojson = JSON.parse(data)
						} else if (typeof data === 'object') {
							geojson = data
						}
					} else {
						console.error(`Invalid dataType prop value: ${dataType}`)
						resolve(emptyTile)
						return
					}

					const filteredGeojson = geojsonFilter ? geojsonFilter(geojson) : undefined
					geojson = filteredGeojson ?? geojson

					if (
						!geojson.type ||
						geojson.type !== 'FeatureCollection' ||
						!geojson.features ||
						!Array.isArray(geojson.features)
					) {
						// console.warn(
						// 	`AOILayer - Tile source is not a valid GeoJSON, skip. Use 'geojsonFilter' to modify the response data if necessary. `
						// )
						resolve(emptyTile)
						return
					}

					if (geojson.features.length > 0) {
						this._createTileMesh(geojson, projection, polaris, cacheKey)
							.then((tile) => {
								if (time) {
									time.genTime = performance.now() - time.genTime
								}
								if (tile) {
									resolve(tile)
								}
							})
							.catch((e) => {
								reject(e)
							})
						return
					}

					resolve(emptyTile)
				})
				.catch((e) => {
					reject(e)
				})
		})

		return {
			promise,
			abort: requestPending.abort,
		}
	}