override raycast()

in packages/layers/geojson/src/Polygon/PolygonLayer.ts [415:465]


	override raycast(
		polaris: AbstractPolaris,
		canvasCoord: CoordV2,
		ndc: CoordV2
	): PickInfo | undefined {
		const p = polaris as PolarisGSI

		if (!this.getProp('pickable')) return
		if (!this.surfaceLayer || !this.surfaceLayer.geom) return

		const matrix = p.matrixProcessor.getCachedWorldMatrix(this.surfaceLayer.mesh)
		if (!matrix) return

		const pickResult = p.raycastRenderableNode(this.surfaceLayer.mesh, ndc, {})

		let event: PickInfo | undefined
		if (pickResult.hit && pickResult.intersections && pickResult.intersections.length > 0) {
			const inter0 = pickResult.intersections[0]
			const point = inter0.point as Vec3
			const pointLocal = inter0.pointLocal as Vec3
			event = {
				distance: inter0.distance as number,
				point: { x: point.x, y: point.y, z: point.z },
				pointLocal: { x: pointLocal.x, y: pointLocal.y, z: pointLocal.z },
				index: -1,
				object: undefined,
				data: undefined,
			}
			// Find corresponding feature data
			this.surfaceLayer.featIndexRangeMap.forEach((range, feature) => {
				if (
					inter0.index !== undefined &&
					inter0.index >= range[0] / 3 &&
					inter0.index <= range[1] / 3
				) {
					const data: SelectionDataType = {
						curr: feature,
						feature,
					}

					if (event) {
						event.object = this.surfaceLayer.mesh
						event.index = feature.index
						event.data = data
					}
				}
			})
		}

		return event
	}