|  |  | @ -2,7 +2,7 @@ | 
			
		
	
		
		
			
				
					
					|  |  |  |  * @Author: cbwu 504-wuchengbo@htsdfp.com |  |  |  |  * @Author: cbwu 504-wuchengbo@htsdfp.com | 
			
		
	
		
		
			
				
					
					|  |  |  |  * @Date: 2024-03-27 08:43:44 |  |  |  |  * @Date: 2024-03-27 08:43:44 | 
			
		
	
		
		
			
				
					
					|  |  |  |  * @LastEditors: cbwu |  |  |  |  * @LastEditors: cbwu | 
			
		
	
		
		
			
				
					
					|  |  |  |  * @LastEditTime: 2024-04-16 19:00:18 |  |  |  |  * @LastEditTime: 2024-04-22 11:23:47 | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |  * @Description: 绘制Polyline类 |  |  |  |  * @Description: 绘制Polyline类 | 
			
		
	
		
		
			
				
					
					|  |  |  |  */ |  |  |  |  */ | 
			
		
	
		
		
			
				
					
					|  |  |  | import { |  |  |  | import { | 
			
		
	
	
		
		
			
				
					|  |  | @ -14,6 +14,7 @@ import { | 
			
		
	
		
		
			
				
					
					|  |  |  |   Entity, |  |  |  |   Entity, | 
			
		
	
		
		
			
				
					
					|  |  |  |   CallbackProperty, |  |  |  |   CallbackProperty, | 
			
		
	
		
		
			
				
					
					|  |  |  |   PolylineDashMaterialProperty, |  |  |  |   PolylineDashMaterialProperty, | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |   Cartesian2, | 
			
		
	
		
		
			
				
					
					|  |  |  |   HeightReference, |  |  |  |   HeightReference, | 
			
		
	
		
		
			
				
					
					|  |  |  | } from 'cesium' |  |  |  | } from 'cesium' | 
			
		
	
		
		
			
				
					
					|  |  |  | import { |  |  |  | import { | 
			
		
	
	
		
		
			
				
					|  |  | @ -27,17 +28,8 @@ import EditGeometry from '@/utils/map/draw/editGeometry' | 
			
		
	
		
		
			
				
					
					|  |  |  | import { getDistance } from '@/utils/map/geocomputation.ts' |  |  |  | import { getDistance } from '@/utils/map/geocomputation.ts' | 
			
		
	
		
		
			
				
					
					|  |  |  | import { Angle } from '@/utils/map/angle.ts' |  |  |  | import { Angle } from '@/utils/map/angle.ts' | 
			
		
	
		
		
			
				
					
					|  |  |  | import { TextLabel } from '@/utils/map/geometry/textLabel.ts' |  |  |  | import { TextLabel } from '@/utils/map/geometry/textLabel.ts' | 
			
		
	
		
		
			
				
					
					|  |  |  | type EntityOptions = { |  |  |  | import { EntityOptions } from '@/types/entityoptions.ts' | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |   id?: string |  |  |  | 
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |   name?: string |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |   show?: boolean |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |   pixelSize?: number |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |   color?: Color |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |   fillColor?: Color |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |   fill?: boolean |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |   width?: number |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |   outlineWidth?: number |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  | } |  |  |  |  | 
			
		
	
		
		
	
		
		
	
		
		
			
				
					
					|  |  |  | export default class CreatePolyline { |  |  |  | export default class CreatePolyline { | 
			
		
	
		
		
			
				
					
					|  |  |  |   viewer: Viewer |  |  |  |   viewer: Viewer | 
			
		
	
		
		
			
				
					
					|  |  |  |   handler: ScreenSpaceEventHandler |  |  |  |   handler: ScreenSpaceEventHandler | 
			
		
	
	
		
		
			
				
					|  |  | @ -57,6 +49,9 @@ export default class CreatePolyline { | 
			
		
	
		
		
			
				
					
					|  |  |  |   clickTimeout: any |  |  |  |   clickTimeout: any | 
			
		
	
		
		
			
				
					
					|  |  |  |   altitudeOffset: number = 20 //相对高度
 |  |  |  |   altitudeOffset: number = 20 //相对高度
 | 
			
		
	
		
		
			
				
					
					|  |  |  |   vDashLinePosition: Cartesian3[][] = [] //垂直辅助线坐标数组
 |  |  |  |   vDashLinePosition: Cartesian3[][] = [] //垂直辅助线坐标数组
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |   // 存储第一次点击的信息
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |   firstClickPosition: Cartesian2 | null = null | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |   firstClickTime: number | null = null | 
			
		
	
		
		
			
				
					
					|  |  |  |   // layer: CustomDataSource
 |  |  |  |   // layer: CustomDataSource
 | 
			
		
	
		
		
			
				
					
					|  |  |  |   defaultStyle: EntityOptions = { |  |  |  |   defaultStyle: EntityOptions = { | 
			
		
	
		
		
			
				
					
					|  |  |  |     // id: 'Polyline' + String(PolylineEntity.id),
 |  |  |  |     // id: 'Polyline' + String(PolylineEntity.id),
 | 
			
		
	
	
		
		
			
				
					|  |  | @ -111,17 +106,9 @@ export default class CreatePolyline { | 
			
		
	
		
		
			
				
					
					|  |  |  |   private leftClickCallBack = ( |  |  |  |   private leftClickCallBack = ( | 
			
		
	
		
		
			
				
					
					|  |  |  |     event: ScreenSpaceEventHandler.PositionedEvent, |  |  |  |     event: ScreenSpaceEventHandler.PositionedEvent, | 
			
		
	
		
		
			
				
					
					|  |  |  |   ) => { |  |  |  |   ) => { | 
			
		
	
		
		
			
				
					
					|  |  |  |     const pickedObject = this.viewer.scene.pick(event.position) |  |  |  |     //根据屏幕坐标判断是否为同一点
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |     if (pickedObject) { |  |  |  |     if (this.isSamplePosition(event.position.clone())) return | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |       //点击同一位置,返回
 |  |  |  | 
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |       if ( |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |         pickedObject.id.id === |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |         this.polyline?.controlPointsID[this.positions.length - 1] |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |       ) { |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |         console.log('********click the same point') |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |         return |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |       } |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |     } |  |  |  |  | 
			
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					|  |  |  |     let cartesian3 = cartesian2ToCartesian3(this.viewer, event.position) |  |  |  |     let cartesian3 = cartesian2ToCartesian3(this.viewer, event.position) | 
			
		
	
		
		
			
				
					
					|  |  |  |     if (cartesian3 != undefined) { |  |  |  |     if (cartesian3 != undefined) { | 
			
		
	
		
		
			
				
					
					|  |  |  |       if (!this.polyline) { |  |  |  |       if (!this.polyline) { | 
			
		
	
	
		
		
			
				
					|  |  | @ -152,24 +139,24 @@ export default class CreatePolyline { | 
			
		
	
		
		
			
				
					
					|  |  |  |       this.viewer.scene.requestRender() //刷新
 |  |  |  |       this.viewer.scene.requestRender() //刷新
 | 
			
		
	
		
		
			
				
					
					|  |  |  |       // 计算2点距离
 |  |  |  |       // 计算2点距离
 | 
			
		
	
		
		
			
				
					
					|  |  |  |       if (this.positions.length >= 2 && this.bMeasure) { |  |  |  |       if (this.positions.length >= 2 && this.bMeasure) { | 
			
		
	
		
		
			
				
					
					|  |  |  |         let distance = getDistance( |  |  |  |         const distance = getDistance( | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |           this.positions[this.positions.length - 1], |  |  |  |           this.positions[this.positions.length - 1], | 
			
		
	
		
		
			
				
					
					|  |  |  |           this.positions[this.positions.length - 2], |  |  |  |           this.positions[this.positions.length - 2], | 
			
		
	
		
		
			
				
					
					|  |  |  |         ) |  |  |  |         ) | 
			
		
	
		
		
			
				
					
					|  |  |  |         this.totalDistance += distance |  |  |  |         this.totalDistance += distance | 
			
		
	
		
		
			
				
					
					|  |  |  |         // 计算2点方位角
 |  |  |  |         // 计算2点方位角
 | 
			
		
	
		
		
			
				
					
					|  |  |  |         let azimuth = Angle.getAzimuth( |  |  |  |         const azimuth = Angle.getAzimuth( | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |           this.positions[this.positions.length - 2], |  |  |  |           this.positions[this.positions.length - 2], | 
			
		
	
		
		
			
				
					
					|  |  |  |           this.positions[this.positions.length - 1], |  |  |  |           this.positions[this.positions.length - 1], | 
			
		
	
		
		
			
				
					
					|  |  |  |         ) |  |  |  |         ) | 
			
		
	
		
		
			
				
					
					|  |  |  |         // 计算2点的中间点
 |  |  |  |         // 计算2点的中间点
 | 
			
		
	
		
		
			
				
					
					|  |  |  |         let midPoint = Cartesian3.midpoint( |  |  |  |         const midPoint = Cartesian3.midpoint( | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |           this.positions[this.positions.length - 1], |  |  |  |           this.positions[this.positions.length - 1], | 
			
		
	
		
		
			
				
					
					|  |  |  |           this.positions[this.positions.length - 2], |  |  |  |           this.positions[this.positions.length - 2], | 
			
		
	
		
		
			
				
					
					|  |  |  |           new Cartesian3(), |  |  |  |           new Cartesian3(), | 
			
		
	
		
		
			
				
					
					|  |  |  |         ) |  |  |  |         ) | 
			
		
	
		
		
			
				
					
					|  |  |  |         // 添加label
 |  |  |  |         // 添加label
 | 
			
		
	
		
		
			
				
					
					|  |  |  |         let labelText = `距离: ${distance.toFixed(2)}km, 方位角: ${azimuth}°` |  |  |  |         const labelText = `距离: ${distance.toFixed(2)}km, 方位角: ${azimuth}°` | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |         new TextLabel(this.viewer, midPoint, labelText) |  |  |  |         new TextLabel(this.viewer, midPoint, labelText) | 
			
		
	
		
		
			
				
					
					|  |  |  |       } |  |  |  |       } | 
			
		
	
		
		
			
				
					
					|  |  |  |     } |  |  |  |     } | 
			
		
	
	
		
		
			
				
					|  |  | @ -272,4 +259,28 @@ export default class CreatePolyline { | 
			
		
	
		
		
			
				
					
					|  |  |  |       }, |  |  |  |       }, | 
			
		
	
		
		
			
				
					
					|  |  |  |     }) |  |  |  |     }) | 
			
		
	
		
		
			
				
					
					|  |  |  |   } |  |  |  |   } | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |   //判断点击是否同一位置
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |   isSamplePosition(clickPosition: Cartesian2) { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     if (this.firstClickPosition) { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |       const dist = Cartesian2.distance(this.firstClickPosition, clickPosition) | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |       if (dist <= 3) { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         console.log('********click the same point0') | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         return true | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |       } | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     } | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     this.firstClickPosition = clickPosition | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     // const pickedObject = this.viewer.scene.pick(clickPosition)
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     // if (pickedObject) {
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     //   //点击同一位置,返回
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     //   if (
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     //     pickedObject.id.id ===
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     //     this.polyline?.controlPointsID[this.positions.length - 1]
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     //   ) {
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     //     console.log('********click the same point')
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     //     return
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     //   }
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     // }
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     return false | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |   } | 
			
		
	
		
		
			
				
					
					|  |  |  | } |  |  |  | } | 
			
		
	
	
		
		
			
				
					|  |  | 
 |