in packages/layers/geojson/src/Polygon/PolygonSurfaceLayer.ts [127:248]
constructor(props: OptionalDefault<PolygonSurfaceLayerProps, typeof defaultProps> = {}) {
const _props = {
...defaultProps,
...props,
}
super(_props)
this.props = _props
// Local caches
this._storeName = 'Polaris_PolygonSurfaceLayer'
this._geomCache = new Map()
this.matr = new PolygonMatr()
this.onRenderOrderChange = (renderOrder) => {
if (this.mesh) {
this.mesh.renderOrder = renderOrder
}
if (this.selectIndicator) {
this.selectIndicator.gline.renderOrder = renderOrder
}
if (this.hoverIndicator) {
this.hoverIndicator.gline.renderOrder = renderOrder
}
}
this.onViewChange = (cam, polaris) => {
if (this.selectIndicator) {
const p = polaris as Polaris
this.selectIndicator.updateResolution(p.canvasWidth, p.canvasHeight)
}
if (this.hoverIndicator) {
const p = polaris as Polaris
this.hoverIndicator.updateResolution(p.canvasWidth, p.canvasHeight)
}
}
this.addEventListener('init', (e) => {
const polaris = e.polaris
const projection = e.projection
this.listenProps(['tessellation'], (e) => {
this._tessellation = this.getProps('tessellation') ?? 0
})
this.listenProps(['transparent', 'doubleSide'], (e) => {
this.matr.alphaMode = this.getProps('transparent') ? 'BLEND' : 'OPAQUE'
this.matr.side = this.getProps('doubleSide') ? 'double' : 'front'
this.matr.version++
})
this.listenProps(['metallic', 'roughness'], (e) => {
this.matr.metallicFactor = this.getProps('metallic')
this.matr.roughnessFactor = this.getProps('roughness')
})
// Init WorkerManager
// @TODO: what is 'workers' ? @qianxun
// this.listenProps(['workers'], (e, done) => {
this.listenProps(['workersCount'], (e) => {
if (this._workerManager) {
throw new Error('can not change props.workersCount')
} else {
const count = this.getProps('workersCount')
if (count > 0) {
const workers: Worker[] = createWorkers(count)
this._workerManager = new WorkerManager(workers)
}
}
})
// this.listenProps(['workersCount'], (e, done) => {
// const count = this.getProps('workersCount')
// if (count > 0) {
// const workers: Worker[] = []
// for (let i = 0; i < count; i++) {
// workers.push(new GeomWorker())
// }
// this._workerManager = new WorkerManager(workers)
// }
// done()
// })
// 数据与配置的应用(包括reaction)
this.listenProps(
[
'data',
'getThickness',
'baseAlt',
'useTessellation',
'genSelectLines',
'selectLinesHeight',
'selectLineWidth',
'selectLineLevel',
'selectLineColor',
],
(e) => {
const data = this.getProps('data')
if (!(data && Array.isArray(data.features))) {
return
}
this.createGeom(data, projection, polaris)
// const cached = undefined
// if (cached) {
// this.mesh.geometry = cached.geom
// if (this.getProps('genSelectLines')) {
// this.selectIndicator = cached.selectIndicator
// this.hoverIndicator = cached.hoverIndicator
// this.selectIndicator.addToLayer(this)
// this.hoverIndicator.addToLayer(this)
// }
// } else {
// this.createGeom(data, projection, polaris)
// }
}
)
// Only update color attributes
this.listenProps(['getColor', 'getOpacity'], (e) => {
this._updateColorsAttr()
})
})
}