private _init()

in packages/layers/xyz-aoi-tile/src/AOILayer.ts [284:444]


	private _init(projection, timeline, polaris) {
		const p = polaris as AbstractPolaris

		if (!projection.isPlaneProjection) {
			throw new Error('AOILayer - TileLayer can only be used under plane projections')
		}

		this.listenProps(['workersNum'], () => {
			if (this._workerManager) {
				throw new Error('can not change props.workersNum')
			} else {
				const workersNum = this.getProp('workersNum')
				if (workersNum && workersNum > 0) {
					const workers: Worker[] = createWorkers(workersNum)
					this._workerManager = new WorkerManager(workers)
				}
			}
		})

		this.listenProps(
			[
				'debug',
				'dataType',
				'getUrl',
				'minZoom',
				'maxZoom',
				'featureIdKey',
				'baseAlt',
				'getColor',
				'getOpacity',
				'transparent',
				'indicatorLinesHeight',
				'hoverLineLevel',
				'hoverLineWidth',
				'hoverLineColor',
				'selectLineLevel',
				'selectLineWidth',
				'selectLineColor',
				'geojsonFilter',
				'featureFilter',
				'framesBeforeRequest',
				'customFetcher',
				'customTileKeyGen',
				'cacheSize',
				'viewZoomReduction',
				'useParentReplaceUpdate',
			],
			() => {
				this._featureCount = 0

				this._renderableFeatureMap = new Map()

				this._featureIndexRangeMap = new Map()

				this._idIndicatorRangeMap = new Map()

				this._hoveredIds = new Set()

				this._selectedIds = new Set()

				this._indicators = new Set()

				this.info = {
					times: new Map(),
				}

				this.matr = this._createPolygonMatr()

				const dtConfig = this.getProp('dataType')
				let dataType
				switch (dtConfig) {
					case 'pbf': {
						dataType = 'arraybuffer'
						break
					}
					case 'geojson': {
						dataType = 'json'
						break
					}
					case 'auto': {
						dataType = 'auto'
						break
					}
					default: {
						throw new Error(`Invalid dataType prop value: ${dtConfig}`)
					}
				}

				if (this.requestManager) {
					this.requestManager.dispose()
				}

				const customFetcher = this.getProp('customFetcher')
				const customTileKeyGen = this.getProp('customTileKeyGen')
				this.requestManager =
					this.getProp('requestManager') ??
					new XYZTileRequestManager({
						dataType,
						fetcher: customFetcher ? ({ x, y, z }) => customFetcher(x, y, z) : undefined,
						getCacheKey: customTileKeyGen ? ({ x, y, z }) => customTileKeyGen(x, y, z) : undefined,
						getUrl: (requestArgs) => {
							return this.getProp('getUrl')(requestArgs.x, requestArgs.y, requestArgs.z)
						},
					})

				if (this.tileManager) {
					this.tileManager.dispose()
				}

				this.tileManager = new XYZTileManager({
					layer: this,
					minZoom: this.getProp('minZoom'),
					maxZoom: this.getProp('maxZoom'),
					cacheSize: this.getProp('cacheSize'),
					framesBeforeUpdate: this.getProp('framesBeforeRequest'),
					viewZoomReduction: this.getProp('viewZoomReduction'),
					useParentReplaceUpdate: this.getProp('useParentReplaceUpdate'),
					getTileRenderables: (tileToken) => {
						return this._createTileRenderables(tileToken, projection, polaris)
					},
					onTileRelease: (tile, token) => {
						this._releaseTile(tile, token)
					},
					printErrors: this.getProp('debug'),
				})

				this.tileManager.start()
			}
		)

		// update indicators' resolution uniform
		this.onViewChange = (cam) => {
			this._indicators.forEach((indicator) => {
				indicator.updateResolution(polaris.width, polaris.height)
			})
			// if (Math.abs(cam.pitch) > 0.0001) {
			// 	console.warn('AOILayer - AOILayer under 3D view mode is currently not supported')
			// }
		}

		/** highlight api */
		this.highlightByIds = (idsArr: (number | string)[], style: { [name: string]: any }) => {
			const type = style.type
			if (type !== 'hover' && type !== 'select' && type !== 'none') {
				console.error(`AOILayer - Invalid argument style.type: ${style}`)
				return
			}
			idsArr.forEach((id) => {
				this._setStyleById(id, type)
				// cache or delete style
				if (type === 'none') {
					this._hoveredIds.delete(id)
					this._selectedIds.delete(id)
				} else if (type === 'hover') {
					this._hoveredIds.add(id)
				} else if (type === 'select') {
					this._selectedIds.add(id)
				}
			})
		}
	}