init()

in packages/layers/geojson/src/Polygon/PolygonSideLayer.ts [80:155]


	init(projection, timeline, polaris) {
		// 数据与配置的应用(包括 reaction)
		this.listenProps(['data', 'getColor', 'getThickness', 'baseAlt'], () => {
			this.geom = new Geom()

			const data = this.getProp('data')
			const getThickness = functionlize(this.getProp('getThickness'))
			const getColor = functionlize(this.getProp('getColor'))
			const baseAlt = this.getProp('baseAlt')

			const positions = [] as Array<number>
			const colors = [] as Array<number>
			const indices = [] as Array<number>

			if (!(data && Array.isArray(data.features))) {
				return
			}

			let offset = 0
			data.features.forEach((feature) => {
				const startOffset = offset
				// const indexRange = [indices.length, 0]
				// const vertRange = [positions.length, 0]
				let count = 0
				flattenEach(feature, (f) => {
					if (!f.geometry) return
					const rings: any[] = getCoords(f as any) // @note looks fine
					for (let k = 0; k < rings.length; k++) {
						const coordinates: number[][] = rings[k]
						let canConnect = false
						for (let i = 0; i < coordinates.length; i++) {
							const lnglat = coordinates[i]
							const bottomXYZ = projection.project(lnglat[0], lnglat[1], baseAlt)
							const topXYZ = projection.project(
								lnglat[0],
								lnglat[1],
								baseAlt + getThickness(feature)
							)
							positions.push(...bottomXYZ)
							positions.push(...topXYZ)
							count += 2
							offset += 2
							if (canConnect) {
								indices.push(offset - 4, offset - 3, offset - 2)
								indices.push(offset - 2, offset - 3, offset - 1)
							}
							canConnect = true
						}
					}
				})

				const color = new Color(getColor(feature))
				const colorUint = getColorUint(color, 1.0)
				const index = startOffset * 4
				for (let i = 0; i < count; i++) {
					colors[i * 4 + 0 + index] = colorUint[0]
					colors[i * 4 + 1 + index] = colorUint[1]
					colors[i * 4 + 2 + index] = colorUint[2]
					colors[i * 4 + 3 + index] = colorUint[3]
				}
			})

			this._generateMesh()

			this.geom.attributes.position = new Attr(new Float32Array(positions), 3)
			this.geom.attributes.color = new Attr(new Uint16Array(colors), 4, false, 'DYNAMIC_DRAW')
			const indicesArray = offset > 65535 ? new Uint32Array(indices) : new Uint16Array(indices)
			this.geom.indices = new Attr(indicesArray, 1)

			this.mesh.geometry = this.geom
			this.mesh.material = this.matr

			this.geom.boundingSphere = computeBSphere(this.geom)
			this.geom.boundingBox = computeBBox(this.geom)
		})
	}