export function CDTGeojsonWithSubdivision()

in packages/layers/geojson/src/utils.ts [58:139]


export function CDTGeojsonWithSubdivision(data, subdivision): any {
	// console.log('CDTGeojsonWithSubdivision start')
	let points: number[] = []
	let triangles: number[] = []
	let steiners: number[][] = []
	// let lnglats = []

	// 这个会拆掉所有的multiGeom,拆成不同的feature
	// const _t = performance.now()
	// console.time('细分')
	flattenEach(data, (feature) => {
		const geom = getGeom(feature)

		if (!geom) return
		// feature = turf.cleanCoords(feature)

		if (!feature.properties) return

		const coords = getCoords(feature)

		// 与地球的细分对齐,进行差点
		const dLng = 360 / subdivision
		const dLat = 360 / subdivision
		// https://tools.ietf.org/html/rfc7946#section-5
		const _bbox = bbox(feature)
		// 左边界(最小经度)
		const left = Math.floor(_bbox[0] / dLng)
		// 下边界
		const btm = Math.floor(_bbox[1] / dLat)
		// 右边界(最大经度)
		const right = Math.ceil(_bbox[2] / dLng)
		// 上边界
		const top = Math.ceil(_bbox[3] / dLat)

		// https://en.wikipedia.org/wiki/Steiner_point
		const steinerPoints: number[][] = []
		for (let i = left; i <= right; i++) {
			for (let j = btm; j <= top; j++) {
				const lnglat = [i * dLng, j * dLat]
				if (pointInsidePolygon(lnglat, coords)) {
					steinerPoints.push(lnglat)
				}
			}
		}

		// debugger

		// console.log('细分固定点', steinerPoints.length);

		// console.log(steinerPoints);

		// console.time('CDTtriangulate');
		const { triangles: _triangles, points: _points } = CDTtriangulate(coords, steinerPoints)
		// console.timeEnd('CDTtriangulate');

		const offset = points.length / 2

		if (offset === 0) {
			triangles = _triangles
			points = _points
			steiners = steinerPoints
		} else {
			for (let i = 0; i < _triangles.length; i++) {
				triangles.push(_triangles[i] + offset)
			}

			for (let i = 0; i < _points.length; i++) {
				points.push(_points[i])
			}

			for (let i = 0; i < steinerPoints.length; i++) {
				steiners.push(steinerPoints[i])
			}
		}
	})
	// console.log('CDTGeojsonWithSubdivision end')
	return {
		points,
		triangles,
		steiners,
	}
}