updateFeatureColor()

in packages/layers/geojson/src/Polygon/PolygonSurfaceLayer.ts [530:572]


	updateFeatureColor(feature: any, color: Color, alpha: number) {
		if (!this.geom) return

		const range = this.getFeatureColorRange(feature)
		if (!range) return

		const attr = this.geom.attributes.color
		if (!attr) return

		const array = attr.array
		if (isDISPOSED(array)) return

		let needsUpdate = false
		const colorUint = getColorUint(color, alpha)
		for (let i = range[0]; i < range[1]; i += 4) {
			if (
				array[i + 0] !== colorUint[0] ||
				array[i + 1] !== colorUint[1] ||
				array[i + 2] !== colorUint[2] ||
				array[i + 3] !== colorUint[3]
			) {
				array[i + 0] = colorUint[0]
				array[i + 1] = colorUint[1]
				array[i + 2] = colorUint[2]
				array[i + 3] = colorUint[3]
				needsUpdate = true
			}
		}

		if (needsUpdate) {
			!attr.extensions && (attr.extensions = {})
			!attr.extensions.EXT_buffer_partial_update &&
				(attr.extensions.EXT_buffer_partial_update = { updateRanges: [] })

			const updateRanges = attr.extensions.EXT_buffer_partial_update.updateRanges

			updateRanges.push({
				start: range[0],
				count: range[1] - range[0],
			})
			attr.version++
		}
	}