import Tools from "../../../Tools"; class Section extends Tools { /** * @constructor 剖切 * @param sdk * @param tiles3d {object} 3dtiles对象 * @param {Array.} options.positions 经纬度[{lon,lat,alt},...] * @param options.regionsType=false 裁剪类型 false:裁剪内部,true:裁剪外部 * **/ constructor(sdk, tiles3d, options = {}) { super(sdk, options) this.viewer = sdk.viewer this.tiles3d = tiles3d this.options = { ...options } this.options.regionsType = this.options.regionsType || false YJ.Analysis.SectionResults.push(this) this.Planes = [] Section.start(this) } get regionsType() { return this.options.regionsType } set regionsType(v) { this.options.regionsType = v if (this.Planes.length > 0) { this.Planes = [] Section.planeCollection(this) } } static start(that) { let positions = that.options.positions || [] if(!that.isConvex(positions)) { window.ELEMENT && window.ELEMENT.Message({ message: '不支持凹多边形', type: 'warning', duration: 1500 }); console.log('不支持凹多边形') return } that.inverseTransform = getInverseTransform(that.tiles3d) that.Planes = [] let array = [] if (positions.length > 0) { for (let i = 0; i < positions.length; i++) { array.push([positions[i].lng, positions[i].lat]) } array.push([positions[0].lng, positions[0].lat]) that.isClockwise = turf.booleanClockwise(turf.lineString(array)); } Section.planeCollection(that) function getInverseTransform(tileSet) { let transform const tmp = tileSet.root.transform if ((tmp && tmp.equals(Cesium.Matrix4.IDENTITY)) || !tmp) { transform = Cesium.Transforms.eastNorthUpToFixedFrame(tileSet.boundingSphere.center) } else { transform = Cesium.Matrix4.fromArray(tileSet.root.transform) } return Cesium.Matrix4.inverseTransformation(transform, new Cesium.Matrix4()) } } static planeCollection(that) { let positions = that.options.positions || [] if (that.regionsType == that.isClockwise) { for (let i = 0; i < positions.length; i++) { if (i === (positions.length - 1)) { that.Planes.push(createPlane(positions[i], positions[0], that.inverseTransform)) } else { that.Planes.push(createPlane(positions[i], positions[i + 1], that.inverseTransform)) } } } else { for (let i = positions.length - 1; i >= 0; i--) { if (i === 0) { that.Planes.push(createPlane(positions[i], positions[positions.length - 1], that.inverseTransform)) } else { that.Planes.push(createPlane(positions[i], positions[i - 1], that.inverseTransform)) } } } if(that.tiles3d.clippingPlanes) { that.tiles3d.clippingPlanes.removeAll() for(let i=0;i