in packages/layers/xyz-poi-tile/src/POILayer.ts [294:454]
_init(projection, timeline, polaris) {
const p = polaris as PolarisGSI
if (!projection.isPlaneProjection) {
throw new Error('POILayer - TileLayer can only be used under plane projections')
}
// cache polaris render ratio for pointSizes computation
this._ratio = polaris.ratio ?? 1.0
this.listenProps(
[
'getUrl',
'dataType',
'minZoom',
'maxZoom',
'featureIdKey',
'baseAlt',
'pointImage',
'pointSize',
'pointHoverSize',
'getPointColor',
'pointColorBlend',
'clusterImage',
'clusterColor',
'clusterColorBlend',
'clusterStyle',
'clusterSize',
'featureFilter',
'getClusterContent',
'requestManager',
'pointOffset',
'geojsonFilter',
'framesBeforeRequest',
'customFetcher',
'customTileKeyGen',
'cacheSize',
'viewZoomReduction',
'useParentReplaceUpdate',
],
() => {
this._checkProps(p)
this._featureCount = 0
this._renderableFeatureMap = new Map()
this._indexMeshMap = new Map()
this._idMeshesMap = new Map()
this._idStyleMap = new Map()
this._createPointImgElement()
this.matr = this._createPointMatr(polaris)
const dtConfig = this.getProps('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.getProps('customFetcher')
const customTileKeyGen = this.getProps('customTileKeyGen')
this.requestManager =
this.getProps('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.getProps('getUrl')(requestArgs.x, requestArgs.y, requestArgs.z)
},
})
if (this.tileManager) {
this.tileManager.dispose()
}
this.tileManager = new XYZTileManager({
layer: this,
minZoom: this.getProps('minZoom'),
maxZoom: this.getProps('maxZoom'),
cacheSize: this.getProps('cacheSize'),
framesBeforeUpdate: this.getProps('framesBeforeRequest'),
viewZoomReduction: this.getProps('viewZoomReduction'),
useParentReplaceUpdate: this.getProps('useParentReplaceUpdate'),
getTileRenderables: (tileToken) => {
return this._createTileRenderables(tileToken, projection, polaris)
},
onTileRelease: (tile, token) => {
this._releaseTile(tile, token)
},
})
this.tileManager.start()
}
)
this.onViewChange = (cam, p) => {
const polaris = p as AbstractPolaris
this._ratio = polaris.ratio ?? 1.0
if (this.matr) {
// @note matr.uniform is currently a setter. can not read from it
// this.matr.uniforms.uResolution.value = { x: polaris.canvasWidth, y: polaris.canvasHeight }
}
// if (Math.abs(cam.pitch) > 0.0001) {
// console.warn('POILayer - POILayer under 3D view mode is currently not supported')
// }
}
/** highlight api */
// this.highlightByIndices = undefined
/** highlight api 2 */
this.highlightByIds = (idsArr: (number | string)[], style: { [name: string]: any }) => {
if (!this._idMeshesMap) return
if (!style || !style.type) return
const type = style.type
idsArr.forEach((id) => {
const meshInfos = this._idMeshesMap.get(id)
if (!meshInfos) return
meshInfos.forEach((meshInfo) => {
const obj = meshInfo.obj
const objIdx = meshInfo.objIdx
if (obj instanceof Marker) {
/** @TODO react on marker highlight */
return
} else if (obj instanceof Mesh) {
if (type === 'none') {
this._updatePointSizeByIndex(obj, objIdx, this._getPointStyledSize(style))
this._idStyleMap.delete(id)
} else if (type === 'hover') {
this._updatePointSizeByIndex(obj, objIdx, this._getPointStyledSize(style))
this._idStyleMap.set(id, { ...style })
}
}
})
})
}
}