代码迁移
This commit is contained in:
		
							
								
								
									
										209
									
								
								src/Measure/MeasureAngle/index.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										209
									
								
								src/Measure/MeasureAngle/index.js
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,209 @@ | ||||
| /** | ||||
|  * @name: index | ||||
|  * @author: Administrator | ||||
|  * @date: 2023-12-29 10:11 | ||||
|  * @description:index | ||||
|  * @update: 2023-12-29 10:11 | ||||
|  */ | ||||
| import Measure from "../index"; | ||||
|  | ||||
| class MeasureAngle extends Measure { | ||||
|   constructor(sdk) { | ||||
|     super(sdk, { text: "左键开始,右键取消" }); | ||||
|     this.cachePositions = [] | ||||
|     this.positions = [] | ||||
|     this.arcPositions = [] | ||||
|     this.line_id = "" | ||||
|     this.label_id = "" | ||||
|     this.arc_id = "" | ||||
|     this.bearing = 0 | ||||
|   } | ||||
|  | ||||
|   createPolyline() { | ||||
|     let that = this | ||||
|     let id = that.randomString() | ||||
|     that.viewer.entities.add(new Cesium.Entity({ | ||||
|       id, | ||||
|       polyline: { | ||||
|         positions: new Cesium.CallbackProperty(() => { | ||||
|           return that.positions | ||||
|         }, false), | ||||
|         clampToGround: true, | ||||
|         width: 5, | ||||
|         material: new Cesium.Color.fromCssColorString(that.options.color || that.defaultColor), | ||||
|         zIndex: 99999999 | ||||
|       } | ||||
|     })) | ||||
|     return id | ||||
|   } | ||||
|  | ||||
|   end() { | ||||
|     super.end(); | ||||
|   } | ||||
|  | ||||
|   destroy() { | ||||
|     super.destroy(); | ||||
|     let arr = [this.line_id, this.label_id, this.arc_id] | ||||
|     arr.forEach(id => { | ||||
|       if (id) | ||||
|         this.remove_entity(id) | ||||
|     }) | ||||
|   } | ||||
|  | ||||
|   cancel() { | ||||
|     this.end() | ||||
|     this.destroy() | ||||
|   } | ||||
|  | ||||
|   caculateAngle(points = []) { | ||||
|     let p1 = this.cartesian3Towgs84(points[0], this.viewer) | ||||
|     let p2 = this.cartesian3Towgs84(points[1], this.viewer) | ||||
|     let p3 = this.cartesian3Towgs84(points[2], this.viewer) | ||||
|     let point1 = turf.point([p1.lng, p1.lat]); | ||||
|     let point2 = turf.point([p2.lng, p2.lat]); | ||||
|     let point3 = turf.point([p3.lng, p3.lat]); | ||||
|     let options = { units: 'kilometers' }; | ||||
|     let distance1 = turf.rhumbDistance(point1, point2, options); | ||||
|     let distance2 = turf.rhumbDistance(point3, point2, options); | ||||
|     let distance = distance1 | ||||
|     if (distance1 > distance2) { | ||||
|       distance = distance2 | ||||
|     } | ||||
|  | ||||
|     let bearing1 = turf.rhumbBearing(point1, point2) | ||||
|     let bearing2 = turf.rhumbBearing(point3, point2) | ||||
|  | ||||
|     let bearing = Math.abs(((bearing1 - bearing2) + 360) % 360) | ||||
|     if (bearing > 180) { | ||||
|       this.bearing = 360 - bearing | ||||
|     } else { | ||||
|       this.bearing = bearing | ||||
|     } | ||||
|     this.bearing = this.bearing.toFixed(2) | ||||
|  | ||||
|     let b1 = (bearing1 - 180) | ||||
|     let b2 = (bearing2 - 180) | ||||
|     let arc = turf.lineArc(point2, (distance / 3), b2, b1); | ||||
|     if (bearing > 180) { | ||||
|       arc = turf.lineArc(point2, (distance / 3), b1, b2); | ||||
|     } | ||||
|     let arcPos = [] | ||||
|     for (let i = 0; i < arc.geometry.coordinates.length; i++) { | ||||
|       arcPos.push(Cesium.Cartesian3.fromDegrees(arc.geometry.coordinates[i][0], arc.geometry.coordinates[i][1])) | ||||
|     } | ||||
|     this.arcPositions = arcPos | ||||
|  | ||||
|     // if (bearing1 > 0 && bearing2 > 0) { | ||||
|     //   this.bearing = Math.abs(bearing1 - bearing2).toFixed(1) | ||||
|     // } else if (bearing1 < 0 && bearing2 < 0) { | ||||
|     //   this.bearing = Math.abs(bearing1 - bearing2).toFixed(1) | ||||
|     // } else if (bearing1 > 0 && bearing2 < 0) { | ||||
|     //   this.bearing = Math.abs(360 - Math.abs(bearing2) - bearing1).toFixed(1) | ||||
|     // } else { | ||||
|     //   this.bearing = Math.abs(360 - Math.abs(bearing1) - bearing2).toFixed(1) | ||||
|     // } | ||||
|   } | ||||
|  | ||||
|  | ||||
|   start() { | ||||
|     if (!YJ.Measure.GetMeasureStatus()) { | ||||
|       super.start(); | ||||
|  | ||||
|       let leftEvent = (movement, car) => { | ||||
|         if (this.ids.length === 0) { | ||||
|           //需要创建一个线 | ||||
|           this.line_id = this.createPolyline() | ||||
|         } | ||||
|  | ||||
|         this.ids.push(this.create_point(car)) | ||||
|         this.tip.setPosition(car, movement.position.x, movement.position.y) | ||||
|         this.cachePositions.push(car) | ||||
|         if (this.cachePositions.length) { | ||||
|           this.positions = this.cachePositions.concat(car) | ||||
|         } | ||||
|         if (this.ids.length === 2) { | ||||
|           this.label_id = Cesium.createGuid() | ||||
|           this.arc_id = Cesium.createGuid() | ||||
|           let p = this.cartesian3Towgs84(car, this.viewer) | ||||
|           this.sampleHeightMostDetailed([p]).then((res) => { | ||||
|             let arc = this.viewer.entities.add({ | ||||
|               id: this.arc_id, | ||||
|               polyline: { | ||||
|                 positions: new Cesium.CallbackProperty(() => { | ||||
|                   return this.arcPositions | ||||
|                 }, false), | ||||
|                 clampToGround: true, | ||||
|                 width: 5, | ||||
|                 material: new Cesium.Color.fromCssColorString(this.options.color || this.defaultColor), | ||||
|                 zIndex: 99999999 | ||||
|               } | ||||
|             }) | ||||
|             let label = this.viewer.entities.add({ | ||||
|               id: this.label_id, | ||||
|               position: Cesium.Cartesian3.fromDegrees(p.lng, p.lat, (res[0].height || 0) + 0.1), | ||||
|               label: { | ||||
|                 text: new Cesium.CallbackProperty(() => { | ||||
|                   return "夹角:" + this.bearing + "°" | ||||
|                 }, false), | ||||
|                 font: '20px Microsoft YaHei', | ||||
|                 fillColor: Cesium.Color.fromCssColorString('#f1e605'), | ||||
|                 style: Cesium.LabelStyle.FILL_AND_OUTLINE, | ||||
|                 //标注的遮挡距离设置为100则视角与标注的距离大于100米时会有遮挡 | ||||
|                 // distanceDisplayCondition: this.distanceDisplayCondition, | ||||
|                 scale: 1, | ||||
|                 horizontalOrigin: Cesium.HorizontalOrigin.CENTER, | ||||
|                 verticalOrigin: Cesium.VerticalOrigin.BOTTOM, | ||||
|                 disableDepthTestDistance: Number.POSITIVE_INFINITY, | ||||
|               } | ||||
|             }) | ||||
|           }) | ||||
|         } | ||||
|          | ||||
|  | ||||
|         if (this.ids.length === 3) { | ||||
|           this.caculateAngle([this.positions[0], this.positions[1], this.positions[2]]) | ||||
|           //需要停止绘制 | ||||
|           this.end() | ||||
|         } | ||||
|  | ||||
|       } | ||||
|       this.event.mouse_left(leftEvent) | ||||
|       this.event.mouse_move((movement, car) => { | ||||
|         this.tip.setPosition(car, movement.endPosition.x, movement.endPosition.y) | ||||
|         if (this.cachePositions.length) { | ||||
|           this.positions = this.cachePositions.concat(car) | ||||
|         } | ||||
|         if (this.positions.length > 2) { | ||||
|           //需要开始计算夹角 | ||||
|           this.caculateAngle([this.positions[0], this.positions[1], this.positions[2]]) | ||||
|         } | ||||
|       }) | ||||
|       this.event.mouse_right((movement, car) => { | ||||
|         this.cancel() | ||||
|       }) | ||||
|  | ||||
|       this.event.gesture_pinck_start((movement, cartesian) => { | ||||
|         let startTime = new Date() | ||||
|         let pos = { | ||||
|           position: { | ||||
|             x: (movement.position1.x + movement.position2.x) / 2, | ||||
|             y: (movement.position1.y + movement.position2.y) / 2 | ||||
|           } | ||||
|         } | ||||
|         this.event.gesture_pinck_end(() => { | ||||
|           let endTime = new Date() | ||||
|           if (endTime - startTime >= 500) { | ||||
|             // 长按取消 | ||||
|             this.cancel() | ||||
|           } | ||||
|           else { | ||||
|             leftEvent(pos, cartesian) | ||||
|           } | ||||
|         }) | ||||
|       }) | ||||
|     } | ||||
|  | ||||
|   } | ||||
| } | ||||
|  | ||||
| export default MeasureAngle | ||||
							
								
								
									
										206
									
								
								src/Measure/MeasureAzimuth/index.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										206
									
								
								src/Measure/MeasureAzimuth/index.js
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,206 @@ | ||||
| import Measure from "../index"; | ||||
|  | ||||
| class MeasureAzimuth extends Measure { | ||||
|   /** | ||||
|    * @constructor | ||||
|    * @param sdk  | ||||
|    * @description 方位角测量 | ||||
|    * */ | ||||
|   constructor(sdk) { | ||||
|     super(sdk, { text: "左键开始,右键取消" }); | ||||
|     this.cachePositions = [] | ||||
|     this.positions = [] | ||||
|     this.arcPositions = [] | ||||
|     this.line_id = "" | ||||
|     this.label_id = "" | ||||
|     this.arc_id = "" | ||||
|     this.bearing = 0 | ||||
|   } | ||||
|  | ||||
|   createPolyline() { | ||||
|     let that = this | ||||
|     let id = that.randomString() | ||||
|     that.viewer.entities.add(new Cesium.Entity({ | ||||
|       id, | ||||
|       polyline: { | ||||
|         positions: new Cesium.CallbackProperty(() => { | ||||
|           return that.positions | ||||
|         }, false), | ||||
|         clampToGround: true, | ||||
|         width: 5, | ||||
|         material: new Cesium.Color.fromCssColorString(that.options.color || that.defaultColor), | ||||
|         zIndex: 99999999 | ||||
|       } | ||||
|     })) | ||||
|     return id | ||||
|   } | ||||
|  | ||||
|   end() { | ||||
|     super.end(); | ||||
|   } | ||||
|  | ||||
|   destroy() { | ||||
|     super.destroy(); | ||||
|     let arr = [this.line_id, this.label_id, this.arc_id] | ||||
|     arr.forEach(id => { | ||||
|       if (id) | ||||
|         this.remove_entity(id) | ||||
|     }) | ||||
|   } | ||||
|  | ||||
|   cancel() { | ||||
|     this.end() | ||||
|     this.destroy() | ||||
|   } | ||||
|  | ||||
|   caculateAngle(line1 = [], line2 = []) { | ||||
|     let c = this.cartesian3Towgs84(line2[1], this.viewer) | ||||
|     let p2 = this.cartesian3Towgs84(line2[0], this.viewer) | ||||
|     let center = turf.point([c.lng, c.lat]) | ||||
|     let point2 = turf.point([p2.lng, p2.lat]) | ||||
|     let bearing = this.rhumbBearing(p2, c) | ||||
|     this.bearing = (180 + bearing).toFixed(2) | ||||
|      | ||||
|     let distance = turf.rhumbDistance(center, point2, { units: 'kilometers' }); | ||||
|     let arc = turf.lineArc(center, (distance/3), 0, this.bearing); | ||||
|     let arcPos = [] | ||||
|     for (let i = 0; i < arc.geometry.coordinates.length; i++) { | ||||
|       arcPos.push(Cesium.Cartesian3.fromDegrees(arc.geometry.coordinates[i][0], arc.geometry.coordinates[i][1])) | ||||
|     } | ||||
|     this.arcPositions = arcPos | ||||
|   } | ||||
|  | ||||
|  | ||||
|   start() { | ||||
|     if (!YJ.Measure.GetMeasureStatus()) { | ||||
|       super.start(); | ||||
|  | ||||
|       let leftEvent = async (movement, car) => { | ||||
|         if (this.ids.length === 0) { | ||||
|           //需要创建一个线 | ||||
|           this.line_id = this.createPolyline() | ||||
|         } | ||||
|         this.tip.setPosition(car, movement.position.x, movement.position.y) | ||||
|         if (this.cachePositions.length) { | ||||
|           this.positions = this.cachePositions.concat(car) | ||||
|           let p = this.cartesian3Towgs84(car, this.viewer) | ||||
|           let pc = this.cartesian3Towgs84(this.positions[1], this.viewer) | ||||
|           let from = turf.point([pc.lng, pc.lat]); | ||||
|           let to = turf.point([p.lng, p.lat]); | ||||
|           let options = { units: 'kilometers' }; | ||||
|           let distance = turf.rhumbDistance(from, to, options); | ||||
|  | ||||
|           let bearing = 0; | ||||
|           let destination = turf.destination(from, distance, bearing, options); | ||||
|           this.positions[0] = Cesium.Cartesian3.fromDegrees(...destination.geometry.coordinates) | ||||
|         } | ||||
|         this.cachePositions.push(car) | ||||
|         this.cachePositions.push(car) | ||||
|         if (this.positions.length > 2) { | ||||
|           //需要开始计算夹角 | ||||
|           this.caculateAngle( | ||||
|             [this.positions[0], this.positions[1]], | ||||
|             [this.positions[2], this.positions[1]]) | ||||
|         } | ||||
|         if (this.ids.length >= 2) { | ||||
|           //需要停止绘制 | ||||
|           this.end() | ||||
|           return | ||||
|         } | ||||
|  | ||||
|         this.ids.push(this.create_point(car)) | ||||
|         this.ids.push(this.create_point(car)) | ||||
|         if (this.ids.length === 2) { | ||||
|           this.label_id = Cesium.createGuid() | ||||
|           this.arc_id = Cesium.createGuid() | ||||
|           let p = this.cartesian3Towgs84(car, this.viewer) | ||||
|           let res = await this.sampleHeightMostDetailed([p]) | ||||
|  | ||||
|           let arc = this.viewer.entities.add({ | ||||
|             id: this.arc_id, | ||||
|             polyline: { | ||||
|               positions: new Cesium.CallbackProperty(() => { | ||||
|                 return this.arcPositions | ||||
|               }, false), | ||||
|               clampToGround: true, | ||||
|               width: 5, | ||||
|               material: new Cesium.Color.fromCssColorString(this.options.color || this.defaultColor), | ||||
|               zIndex: 99999999 | ||||
|             } | ||||
|           }) | ||||
|  | ||||
|           let label = this.viewer.entities.add({ | ||||
|             id: this.label_id, | ||||
|             position: Cesium.Cartesian3.fromDegrees(p.lng, p.lat, (res[0].height || 0) + 0.1), | ||||
|             label: { | ||||
|               text: new Cesium.CallbackProperty(() => { | ||||
|                 return "方位夹角:" + this.bearing + "°" | ||||
|               }, false), | ||||
|               font: '20px Microsoft YaHei', | ||||
|               fillColor: Cesium.Color.fromCssColorString('#f1e605'), | ||||
|               style: Cesium.LabelStyle.FILL_AND_OUTLINE, | ||||
|               //标注的遮挡距离设置为100则视角与标注的距离大于100米时会有遮挡 | ||||
|               // distanceDisplayCondition: this.distanceDisplayCondition, | ||||
|               scale: 1, | ||||
|               horizontalOrigin: Cesium.HorizontalOrigin.CENTER, | ||||
|               verticalOrigin: Cesium.VerticalOrigin.BOTTOM, | ||||
|               disableDepthTestDistance: Number.POSITIVE_INFINITY, | ||||
|             } | ||||
|           }) | ||||
|           //需要创建夹角的显示效果 | ||||
|  | ||||
|         } | ||||
|          | ||||
|       } | ||||
|       this.event.mouse_left(leftEvent) | ||||
|       this.event.mouse_move((movement, car) => { | ||||
|         this.tip.setPosition(car, movement.endPosition.x, movement.endPosition.y) | ||||
|         if (this.cachePositions.length) { | ||||
|           this.positions = this.cachePositions.concat(car) | ||||
|           let p = this.cartesian3Towgs84(car, this.viewer) | ||||
|           let pc = this.cartesian3Towgs84(this.positions[1], this.viewer) | ||||
|           let from = turf.point([pc.lng, pc.lat]); | ||||
|           let to = turf.point([p.lng, p.lat]); | ||||
|           let options = { units: 'kilometers' }; | ||||
|           let distance = turf.rhumbDistance(from, to, options); | ||||
|  | ||||
|           let bearing = 0; | ||||
|           let destination = turf.destination(from, distance, bearing, options); | ||||
|           this.positions[0] = Cesium.Cartesian3.fromDegrees(...destination.geometry.coordinates) | ||||
|         } | ||||
|         if (this.positions.length > 2) { | ||||
|           //需要开始计算夹角 | ||||
|           this.caculateAngle( | ||||
|             [this.positions[0], this.positions[1]], | ||||
|             [this.positions[2], this.positions[1]]) | ||||
|         } | ||||
|       }) | ||||
|       this.event.mouse_right((movement, car) => { | ||||
|         this.cancel() | ||||
|       }) | ||||
|  | ||||
|       this.event.gesture_pinck_start((movement, cartesian) => { | ||||
|         let startTime = new Date() | ||||
|         let pos = { | ||||
|           position: { | ||||
|             x: (movement.position1.x + movement.position2.x) / 2, | ||||
|             y: (movement.position1.y + movement.position2.y) / 2 | ||||
|           } | ||||
|         } | ||||
|         this.event.gesture_pinck_end(() => { | ||||
|           let endTime = new Date() | ||||
|           if (endTime - startTime >= 500) { | ||||
|             // 长按取消 | ||||
|             this.cancel() | ||||
|           } | ||||
|           else { | ||||
|             leftEvent(pos, cartesian) | ||||
|           } | ||||
|         }) | ||||
|       }) | ||||
|     } | ||||
|  | ||||
|   } | ||||
| } | ||||
|  | ||||
| export default MeasureAzimuth | ||||
							
								
								
									
										18
									
								
								src/Measure/MeasureCircle/index.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										18
									
								
								src/Measure/MeasureCircle/index.js
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,18 @@ | ||||
| import Measure from '../index' | ||||
|  | ||||
| /**@extends Measure*/ | ||||
| class MeasureCircle extends Measure { | ||||
|   constructor(sdk, options = {}) { | ||||
|     super(sdk, options) | ||||
|   } | ||||
|  | ||||
|   start() { | ||||
|     super.start(); | ||||
|   } | ||||
|  | ||||
|   end() { | ||||
|     super.end(); | ||||
|   } | ||||
| } | ||||
|  | ||||
| export default MeasureCircle | ||||
							
								
								
									
										326
									
								
								src/Measure/MeasureDistance/index.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										326
									
								
								src/Measure/MeasureDistance/index.js
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,326 @@ | ||||
| /** | ||||
|  * @name: index | ||||
|  * @author: Administrator | ||||
|  * @date: 2022-07-11 10:31 | ||||
|  * @description:index | ||||
|  * @update: 2022-07-11 10:31 | ||||
|  */ | ||||
|  | ||||
| import Measure from "../index" | ||||
|  | ||||
| class MeasureDistance extends Measure { | ||||
|   /** | ||||
|    * @constructor | ||||
|    * @param sdk  | ||||
|    * @description 距离测量 | ||||
|    * */ | ||||
|   constructor(sdk, options = {}) { | ||||
|     super(sdk, options) | ||||
|     this.options.color = this.options.color || "#00ffff" | ||||
|     this.start_id = "" | ||||
|     this.end_id = "" | ||||
|     this.polyline_id = "" | ||||
|     this.clampPositions = [] | ||||
|   } | ||||
|  | ||||
|   async clampToGroundMeasure(meters, cb) { | ||||
|     let positions = [] | ||||
|     this.ids.forEach((id, index) => { | ||||
|       let p = this.viewer.entities.getById(id).position.getValue() | ||||
|       positions.push(this.cartesian3Towgs84(p, this.viewer)) | ||||
|     }) | ||||
|     let res = this.chunkLine(positions, meters) | ||||
|     let coordinates = [] | ||||
|     res.forEach((Feature, index) => { | ||||
|       if (index === 0) { | ||||
|         coordinates = [...Feature.geometry.coordinates] | ||||
|       } else { | ||||
|         coordinates.push(Feature.geometry.coordinates[1]) | ||||
|       } | ||||
|     }) | ||||
|     let total = coordinates.length | ||||
|  | ||||
|     for (const item of coordinates) { | ||||
|       const index = coordinates.indexOf(item); | ||||
|       let r = await this.getHeight({lng: item[0], lat: item[1], alt: 0}, index, total,) | ||||
|       cb(null, r) | ||||
|     } | ||||
|   } | ||||
|  | ||||
|   async computeDisByTowPoint(p1, p2) { | ||||
|     let d = this.computeDistance([p1, p2]) | ||||
|     let meters = 10 | ||||
|     let createLabel = (distance) => { | ||||
|       if(this._isDestroy) { | ||||
|         return | ||||
|       } | ||||
|       let label = this.getLabel("贴地距离:" + Number(distance).toFixed(2) + "米") | ||||
|       label.pixelOffset = new Cesium.Cartesian2( | ||||
|         0, -(32) | ||||
|       ) | ||||
|       this.ids.push(MeasureDistance.create_point(Cesium.Cartesian3.fromDegrees(p2.lng, p2.lat, p2.alt), {label: label}, this)) | ||||
|     } | ||||
|     let start = async (meters) => { | ||||
|       let res = this.chunkLine([p1, p2], meters) | ||||
|       let coordinates = [] | ||||
|       res.forEach((Feature, index) => { | ||||
|         if (index === 0) { | ||||
|           coordinates = [...Feature.geometry.coordinates] | ||||
|         } else { | ||||
|           coordinates.push(Feature.geometry.coordinates[1]) | ||||
|         } | ||||
|       }) | ||||
|       let arr = [] | ||||
|       for (const item of coordinates) { | ||||
|         const index = coordinates.indexOf(item); | ||||
|         let r = await this.sampleHeight({lng: item[0], lat: item[1], alt: 0}, index) | ||||
|         arr.push(r) | ||||
|       } | ||||
|       let total_length = 0 | ||||
|       let l = arr.length - 1 | ||||
|       arr.forEach((item, index) => { | ||||
|         if (index !== l) { | ||||
|           let d1 = this.computeDistance([item.position, arr[index + 1].position]) | ||||
|           let d2 = Math.abs(item.position.alt - arr[index + 1].position.alt) | ||||
|           let d3 = Math.sqrt(d1 * d1 + d2 * d2) | ||||
|           total_length += d3 | ||||
|         } | ||||
|       }) | ||||
|       createLabel(total_length) | ||||
|     } | ||||
|  | ||||
|  | ||||
|     //暂时固定取20个点 | ||||
|     if (d > 20) {//大于20m时,固定取20个点 | ||||
|       meters = d / 20 | ||||
|       await start(meters) | ||||
|     } else if (d < 1) { | ||||
|       //不计算 | ||||
|       createLabel(d) | ||||
|     } else {//小于20m的时候 | ||||
|       meters = 1 | ||||
|       await start(meters) | ||||
|     } | ||||
|  | ||||
|   } | ||||
|  | ||||
|  | ||||
|   async sampleHeight(p1, index) { | ||||
|     let p2 = await this.sampleHeightMostDetailed([p1]) | ||||
|     p1.alt = p2[0].height | ||||
|     return {position: p1, index} | ||||
|   } | ||||
|  | ||||
|  | ||||
|   async getHeight(p1, index, total) { | ||||
|     let p2 = await this.sampleHeightMostDetailed([p1]) | ||||
|     p1.alt = p2[0].height | ||||
|     this.clampPositions.push({position: p1, index}) | ||||
|     if (total === this.clampPositions.length) { | ||||
|       let total_length = this.startCompute() | ||||
|       return {total, current: this.clampPositions.length, total_length} | ||||
|     } | ||||
|     return {total, current: this.clampPositions.length,} | ||||
|   } | ||||
|  | ||||
|   startCompute() { | ||||
|     this.clampPositions.sort(function (a, b) { | ||||
|       return a.index < b.index | ||||
|     }) | ||||
|     let total_length = 0 | ||||
|     let l = this.clampPositions.length - 1 | ||||
|     this.clampPositions.forEach((item, index) => { | ||||
|       if (index !== l) { | ||||
|         let d1 = this.computeDistance([item.position, this.clampPositions[index + 1].position]) | ||||
|         let d2 = Math.abs(item.position.alt - this.clampPositions[index + 1].position.alt) | ||||
|         let d3 = Math.sqrt(d1 * d1 + d2 * d2) | ||||
|         total_length += d3 | ||||
|       } | ||||
|     }) | ||||
|     return Number(total_length.toFixed(2)) | ||||
|   } | ||||
|  | ||||
|  | ||||
|   static createPolyline(that) { | ||||
|     let id = that.randomString() | ||||
|     that.viewer.entities.add(new Cesium.Entity({ | ||||
|       id, | ||||
|       polyline: { | ||||
|         positions: new Cesium.CallbackProperty(() => { | ||||
|           return that.positions | ||||
|         }, false), | ||||
|         clampToGround: true, | ||||
|         width: 3, | ||||
|         material: new Cesium.PolylineDashMaterialProperty({ | ||||
|           color: new Cesium.Color.fromCssColorString(that.options.color || that.defaultColor), | ||||
|           dashLength: 20, //短划线长度 | ||||
|         }), | ||||
|         zIndex: 99999999 | ||||
|       } | ||||
|     })) | ||||
|     return id | ||||
|   } | ||||
|  | ||||
|   static create_point(cartesian, { | ||||
|     label, image = "point.png", | ||||
|     width, | ||||
|     height | ||||
|   }, that) { | ||||
|     let id = that.randomString() | ||||
|     let p = that.cartesian3Towgs84(cartesian, that.viewer) | ||||
|     if (label) { | ||||
|       label.pixelOffset = new Cesium.Cartesian2( | ||||
|         0, -(height || 32) | ||||
|       ) | ||||
|     } | ||||
|     that.viewer.entities.add( | ||||
|       new Cesium.Entity({ | ||||
|         id: id, | ||||
|         label, | ||||
|         position: Cesium.Cartesian3.fromDegrees(p.lng, p.lat, p.alt), | ||||
|         billboard: { | ||||
|           image: that.getSourceRootPath() + '/img/' + image, | ||||
|           verticalOrigin: Cesium.VerticalOrigin.BOTTOM, | ||||
|           disableDepthTestDistance: Number.POSITIVE_INFINITY, | ||||
|           width, | ||||
|           height | ||||
|         } | ||||
|       }) | ||||
|     ) | ||||
|     return id | ||||
|   } | ||||
|  | ||||
|   getLabel(text) { | ||||
|     return { | ||||
|       text: text || '', | ||||
|       //标注文字描述 | ||||
|       font: '20px Microsoft YaHei', | ||||
|       fillColor: Cesium.Color.fromCssColorString('#f1e605'), | ||||
|       style: Cesium.LabelStyle.FILL_AND_OUTLINE, | ||||
|       //标注的遮挡距离设置为100则视角与标注的距离大于100米时会有遮挡 | ||||
|       // distanceDisplayCondition: this.distanceDisplayCondition, | ||||
|       scale: 1, | ||||
|       horizontalOrigin: Cesium.HorizontalOrigin.CENTER, | ||||
|       verticalOrigin: Cesium.VerticalOrigin.BOTTOM, | ||||
|       disableDepthTestDistance: Number.POSITIVE_INFINITY, | ||||
|  | ||||
|       // disableDepthTestDistance: this.disableDepthTestDistance, | ||||
|     } | ||||
|   } | ||||
|  | ||||
|   /** | ||||
|    * 开始测量 | ||||
|    */ | ||||
|   start() { | ||||
|     if (!YJ.Measure.GetMeasureStatus()) { | ||||
|       super.start() | ||||
|       this.positions = [] | ||||
|       this.cachePositions = [] | ||||
|  | ||||
|  | ||||
|       let leftEvent = async (movement, car) => { | ||||
|         if (this.ids.length === 0) { | ||||
|           this.polyline_id = (MeasureDistance.createPolyline(this)) | ||||
|           this.start_id = MeasureDistance.create_point(car, { | ||||
|             image: "start1.png", width: 30, height: 38, label: this.getLabel("") | ||||
|           }, this) | ||||
|           //创建起点 | ||||
|         } | ||||
|  | ||||
|         this.tip.setPosition(car, movement.position.x, movement.position.y) | ||||
|         this.positions = this.cachePositions.concat(car) | ||||
|  | ||||
|         if (this.ids.length !== 0) { | ||||
|           let cur_point = this.cartesian3Towgs84(car, this.viewer) | ||||
|           let pre_p = this.cartesian3Towgs84(this.cachePositions[this.cachePositions.length - 1], this.viewer) | ||||
|           this.cachePositions.push(car) | ||||
|           await this.computeDisByTowPoint(pre_p, cur_point) | ||||
|         } else { | ||||
|           this.cachePositions.push(car) | ||||
|           this.ids.push(MeasureDistance.create_point(car, {}, this)) | ||||
|           let startPoint = this.viewer.entities.getById(this.ids[0]) | ||||
|           if(startPoint) { | ||||
|             startPoint.billboard.show = false | ||||
|           } | ||||
|         } | ||||
|       } | ||||
|       let rightEvent = (movement, car) => { | ||||
|         if (this.cachePositions.length) { | ||||
|           this.positions = this.cachePositions | ||||
|           this.end_id = MeasureDistance.create_point(this.cachePositions[this.cachePositions.length - 1], { | ||||
|             image: "end1.png", | ||||
|             width: 30, | ||||
|             height: 38, | ||||
|           }, this) | ||||
|           let endPoint = this.viewer.entities.getById(this.ids[this.ids.length-1]) | ||||
|           if(endPoint) { | ||||
|             endPoint.billboard.show = false | ||||
|           } | ||||
|         } | ||||
|         if (this.cachePositions.length < 2) { | ||||
|           this.destroy() | ||||
|           YJ.Measure.Measures.pop()//弹出测量实体 | ||||
|         } | ||||
|         this.end() | ||||
|       } | ||||
|       this.event.mouse_left(leftEvent) | ||||
|       this.event.mouse_move((movement, car) => { | ||||
|         this.tip.setPosition(car, movement.endPosition.x, movement.endPosition.y) | ||||
|         this.positions = this.cachePositions.concat(car) | ||||
|         // if (this.cachePositions.length) { | ||||
|         //   let cur_point = this.cartesian3Towgs84(car, this.viewer) | ||||
|         //   let pre_p = this.cartesian3Towgs84(this.cachePositions[this.cachePositions.length - 1], this.viewer) | ||||
|         //   let cur_len = this.computeDistance([cur_point, pre_p]) | ||||
|         //   let text = "当前投影距离:" + cur_len + " 米" | ||||
|         //   // this.tip.set_text(text) | ||||
|         // } | ||||
|       }) | ||||
|       this.event.mouse_right(rightEvent) | ||||
|  | ||||
|       this.event.gesture_pinck_start((movement, cartesian) => { | ||||
|         let startTime = new Date() | ||||
|         let pos = { | ||||
|           position: { | ||||
|             x: (movement.position1.x + movement.position2.x) / 2, | ||||
|             y: (movement.position1.y + movement.position2.y) / 2 | ||||
|           } | ||||
|         } | ||||
|         this.event.gesture_pinck_end(() => { | ||||
|           let endTime = new Date() | ||||
|           if (endTime - startTime >= 500) { | ||||
|             // 长按取消 | ||||
|             rightEvent(pos, cartesian) | ||||
|           } | ||||
|           else { | ||||
|             leftEvent(pos, cartesian) | ||||
|           } | ||||
|         }) | ||||
|       }) | ||||
|     } | ||||
|   } | ||||
|  | ||||
|   /** | ||||
|    * 清除测量 | ||||
|    */ | ||||
|   destroy() { | ||||
|     [this.polyline_id, this.end_id, this.start_id, ...this.ids].forEach(id => { | ||||
|       this.remove_entity(id) | ||||
|     }) | ||||
|     super.destroy() | ||||
|   } | ||||
|  | ||||
|  | ||||
|   /** | ||||
|    * 结束测量 | ||||
|    */ | ||||
|   end() { | ||||
|     // YJ.Measure.SetMeasureStatus(false) | ||||
|     // this.tip.destroy() | ||||
|     // this.event.destroy() | ||||
|     super.end() | ||||
|     // this.setPickStatus(this.pickStatus.pick) | ||||
|  | ||||
|   } | ||||
| } | ||||
|  | ||||
| export default MeasureDistance | ||||
							
								
								
									
										327
									
								
								src/Measure/MeasureDistance/index2.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										327
									
								
								src/Measure/MeasureDistance/index2.js
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,327 @@ | ||||
| /** | ||||
|  * @name: index | ||||
|  * @author: Administrator | ||||
|  * @date: 2022-07-11 10:31 | ||||
|  * @description:index | ||||
|  * @update: 2022-07-11 10:31 | ||||
|  */ | ||||
|  | ||||
| import Measure from "../index" | ||||
|  | ||||
| class MeasureDistance extends Measure { | ||||
|   /** | ||||
|    * @constructor | ||||
|    * @param sdk  | ||||
|    * @description 距离测量 | ||||
|    * */ | ||||
|   constructor(sdk, options = {}) { | ||||
|     super(sdk, options) | ||||
|     this.start_id = "" | ||||
|     this.end_id = "" | ||||
|     this.polyline_id = "" | ||||
|     this.clampPositions = [] | ||||
|   } | ||||
|  | ||||
|   async clampToGroundMeasure(meters, cb) { | ||||
|     let positions = [] | ||||
|     this.ids.forEach((id, index) => { | ||||
|       let p = this.viewer.entities.getById(id).position.getValue() | ||||
|       positions.push(this.cartesian3Towgs84(p, this.viewer)) | ||||
|     }) | ||||
|     let res = this.chunkLine(positions, meters) | ||||
|     let coordinates = [] | ||||
|     res.forEach((Feature, index) => { | ||||
|       if (index === 0) { | ||||
|         coordinates = [...Feature.geometry.coordinates] | ||||
|       } else { | ||||
|         coordinates.push(Feature.geometry.coordinates[1]) | ||||
|       } | ||||
|     }) | ||||
|     let total = coordinates.length | ||||
|  | ||||
|     for (const item of coordinates) { | ||||
|       const index = coordinates.indexOf(item); | ||||
|       let r = await this.getHeight({lng: item[0], lat: item[1], alt: 0}, index, total,) | ||||
|       cb(null, r) | ||||
|     } | ||||
|   } | ||||
|  | ||||
|   async computeDisByTowPoint(p1, p2) { | ||||
|     let d = this.computeDistance([p1, p2]) | ||||
|     let meters = 10 | ||||
|     let createLabel = (distance) => { | ||||
|       let label = this.getLabel("贴地距离:" + distance.toFixed(2) + "米") | ||||
|       label.pixelOffset = new Cesium.Cartesian2( | ||||
|         0, -(84) | ||||
|       ) | ||||
|       let id = this.randomString() | ||||
|       this.viewer.entities.add( | ||||
|         new Cesium.Entity({ | ||||
|           id: id, | ||||
|           label, | ||||
|           position: Cesium.Cartesian3.fromDegrees(p2.lng, p2.lat, p2.alt), | ||||
|         }) | ||||
|       ) | ||||
|       this.ids.push(id) | ||||
|     } | ||||
|     let start = async (meters) => { | ||||
|       let res = this.chunkLine([p1, p2], meters) | ||||
|       let coordinates = [] | ||||
|       res.forEach((Feature, index) => { | ||||
|         if (index === 0) { | ||||
|           coordinates = [...Feature.geometry.coordinates] | ||||
|         } else { | ||||
|           coordinates.push(Feature.geometry.coordinates[1]) | ||||
|         } | ||||
|       }) | ||||
|       let arr = [] | ||||
|       for (const item of coordinates) { | ||||
|         const index = coordinates.indexOf(item); | ||||
|         let r = await this.sampleHeight({lng: item[0], lat: item[1], alt: 0}, index) | ||||
|         arr.push(r) | ||||
|       } | ||||
|       let total_length = 0 | ||||
|       let l = arr.length - 1 | ||||
|       arr.forEach((item, index) => { | ||||
|         if (index !== l) { | ||||
|           let d1 = this.computeDistance([item.position, arr[index + 1].position]) | ||||
|           let d2 = Math.abs(item.position.alt - arr[index + 1].position.alt) | ||||
|           let d3 = Math.sqrt(d1 * d1 + d2 * d2) | ||||
|           total_length += d3 | ||||
|         } | ||||
|       }) | ||||
|       createLabel(total_length) | ||||
|     } | ||||
|  | ||||
|  | ||||
|     //暂时固定取20个点 | ||||
|     if (d > 20) {//大于20m时,固定取20个点 | ||||
|       meters = d / 20 | ||||
|       await start(meters) | ||||
|     } else if (d < 1) { | ||||
|       //不计算 | ||||
|       createLabel(d) | ||||
|     } else {//小于20m的时候 | ||||
|       meters = 1 | ||||
|       await start(meters) | ||||
|     } | ||||
|  | ||||
|   } | ||||
|  | ||||
|  | ||||
|   async sampleHeight(p1, index) { | ||||
|     let p2 = await this.sampleHeightMostDetailed([p1]) | ||||
|     p1.alt = p2[0].height | ||||
|     return {position: p1, index} | ||||
|   } | ||||
|  | ||||
|  | ||||
|   async getHeight(p1, index, total) { | ||||
|     let p2 = await this.sampleHeightMostDetailed([p1]) | ||||
|     p1.alt = p2[0].height | ||||
|     this.clampPositions.push({position: p1, index}) | ||||
|     if (total === this.clampPositions.length) { | ||||
|       let total_length = this.startCompute() | ||||
|       return {total, current: this.clampPositions.length, total_length} | ||||
|     } | ||||
|     return {total, current: this.clampPositions.length,} | ||||
|   } | ||||
|  | ||||
|   startCompute() { | ||||
|     this.clampPositions.sort(function (a, b) { | ||||
|       return a.index < b.index | ||||
|     }) | ||||
|     let total_length = 0 | ||||
|     let l = this.clampPositions.length - 1 | ||||
|     this.clampPositions.forEach((item, index) => { | ||||
|       if (index !== l) { | ||||
|         let d1 = this.computeDistance([item.position, this.clampPositions[index + 1].position]) | ||||
|         let d2 = Math.abs(item.position.alt - this.clampPositions[index + 1].position.alt) | ||||
|         let d3 = Math.sqrt(d1 * d1 + d2 * d2) | ||||
|         total_length += d3 | ||||
|       } | ||||
|     }) | ||||
|     return Number(total_length.toFixed(2)) | ||||
|   } | ||||
|  | ||||
|  | ||||
|   static createPolyline(that) { | ||||
|     let id = that.randomString() | ||||
|     that.viewer.entities.add(new Cesium.Entity({ | ||||
|       id, | ||||
|       polyline: { | ||||
|         positions: new Cesium.CallbackProperty(() => { | ||||
|           return that.positions | ||||
|         }, false), | ||||
|         clampToGround: true, | ||||
|         width: 5, | ||||
|         material: new Cesium.Color.fromCssColorString(that.options.color || that.defaultColor), | ||||
|         zIndex: 99999999 | ||||
|       } | ||||
|     })) | ||||
|     return id | ||||
|   } | ||||
|  | ||||
|   static create_point(cartesian, { | ||||
|     label, image = "point.png", | ||||
|     width, | ||||
|     height | ||||
|   }, that) { | ||||
|     let id = that.randomString() | ||||
|     let p = that.cartesian3Towgs84(cartesian, that.viewer) | ||||
|     if (label) { | ||||
|       label.pixelOffset = new Cesium.Cartesian2( | ||||
|         0, -(height || 32) | ||||
|       ) | ||||
|     } | ||||
|     that.viewer.entities.add( | ||||
|       new Cesium.Entity({ | ||||
|         id: id, | ||||
|         label, | ||||
|         position: Cesium.Cartesian3.fromDegrees(p.lng, p.lat, p.alt), | ||||
|         billboard: { | ||||
|           image: that.getSourceRootPath() + '/img/' + image, | ||||
|           verticalOrigin: Cesium.VerticalOrigin.BOTTOM, | ||||
|           disableDepthTestDistance: Number.POSITIVE_INFINITY, | ||||
|           width, | ||||
|           height | ||||
|         } | ||||
|       }) | ||||
|     ) | ||||
|     return id | ||||
|   } | ||||
|  | ||||
|   getLabel(text) { | ||||
|     return { | ||||
|       text: text || '', | ||||
|       //标注文字描述 | ||||
|       font: '20px Microsoft YaHei', | ||||
|       fillColor: Cesium.Color.fromCssColorString('#f1e605'), | ||||
|       style: Cesium.LabelStyle.FILL_AND_OUTLINE, | ||||
|       //标注的遮挡距离设置为100则视角与标注的距离大于100米时会有遮挡 | ||||
|       // distanceDisplayCondition: this.distanceDisplayCondition, | ||||
|       scale: 1, | ||||
|       horizontalOrigin: Cesium.HorizontalOrigin.CENTER, | ||||
|       verticalOrigin: Cesium.VerticalOrigin.BOTTOM, | ||||
|       disableDepthTestDistance: Number.POSITIVE_INFINITY, | ||||
|  | ||||
|       // disableDepthTestDistance: this.disableDepthTestDistance, | ||||
|     } | ||||
|   } | ||||
|  | ||||
|   /** | ||||
|    * 开始测量 | ||||
|    */ | ||||
|   start() { | ||||
|     if (!YJ.Measure.GetMeasureStatus()) { | ||||
|       super.start() | ||||
|       this.positions = [] | ||||
|       this.cachePositions = [] | ||||
|  | ||||
|  | ||||
|       this.event.mouse_left(async (movement, car) => { | ||||
|         if (this.ids.length === 0) { | ||||
|           this.polyline_id = (MeasureDistance.createPolyline(this)) | ||||
|           this.start_id = MeasureDistance.create_point(car, { | ||||
|             image: "start.png", width: 32, height: 32, label: this.getLabel("") | ||||
|           }, this) | ||||
|           //创建起点 | ||||
|         } | ||||
|  | ||||
|         if (this.ids.length !== 0) { | ||||
|           let cur_point = this.cartesian3Towgs84(car, this.viewer) | ||||
|           let pre_p = this.cartesian3Towgs84(this.cachePositions[this.cachePositions.length - 1], this.viewer) | ||||
|           let cur_len = this.computeDistance([cur_point, pre_p]) | ||||
|           let text = "投影距离:" + cur_len + " 米" | ||||
|           this.ids.push(MeasureDistance.create_point(car, {label: this.getLabel(text)}, this)) | ||||
|           this.cachePositions.push(car) | ||||
|           //计算坡度 | ||||
|           this.computeAngle(pre_p, cur_point) | ||||
|           await this.computeDisByTowPoint(pre_p, cur_point) | ||||
|         } else { | ||||
|           this.cachePositions.push(car) | ||||
|           this.ids.push(MeasureDistance.create_point(car, {}, this)) | ||||
|         } | ||||
|  | ||||
|       }) | ||||
|       this.event.mouse_move((movement, car) => { | ||||
|         this.tip.setPosition(car, movement.endPosition.x, movement.endPosition.y) | ||||
|         this.positions = this.cachePositions.concat(car) | ||||
|         if (this.cachePositions.length) { | ||||
|           let cur_point = this.cartesian3Towgs84(car, this.viewer) | ||||
|           let pre_p = this.cartesian3Towgs84(this.cachePositions[this.cachePositions.length - 1], this.viewer) | ||||
|           let cur_len = this.computeDistance([cur_point, pre_p]) | ||||
|           let text = "当前投影距离:" + cur_len + " 米" | ||||
|           this.tip.set_text(text) | ||||
|         } | ||||
|       }) | ||||
|       this.event.mouse_right((movement, car) => { | ||||
|         if (this.cachePositions.length) { | ||||
|           this.positions = this.cachePositions | ||||
|           this.end_id = MeasureDistance.create_point(this.cachePositions[this.cachePositions.length - 1], { | ||||
|             image: "end.png", | ||||
|             width: 32, | ||||
|             height: 32, | ||||
|           }, this) | ||||
|         } | ||||
|         if (this.cachePositions.length === 0) { | ||||
|           this.destroy() | ||||
|           YJ.Measure.Measures.pop()//弹出测量实体 | ||||
|         } | ||||
|         this.end() | ||||
|       }) | ||||
|       this.event.mouse_right_keyboard_ctrl((movement, car) => { | ||||
|         if (this.cachePositions.length) { | ||||
|           this.cachePositions.pop() | ||||
|           this.remove_entity(this.ids.pop()) | ||||
|         } | ||||
|       }) | ||||
|     } | ||||
|   } | ||||
|  | ||||
|   computeAngle(start, end) { | ||||
|     let d1 = this.computeDistance([start, end]) | ||||
|     let d2 = Math.abs(start.alt - end.alt) | ||||
|     let d3 = Math.sqrt(d1 * d1 + d2 * d2) | ||||
|     let cosAlpha = d1 / d3 | ||||
|     let acos = Math.acos(cosAlpha) | ||||
|     let angle = this.radiansToDegrees(acos) | ||||
|     let label = this.getLabel("坡度:" + angle.toFixed(1) + "°") | ||||
|     label.pixelOffset = new Cesium.Cartesian2( | ||||
|       0, -(58) | ||||
|     ) | ||||
|     let id = this.randomString() | ||||
|     this.viewer.entities.add( | ||||
|       new Cesium.Entity({ | ||||
|         id: id, | ||||
|         label, | ||||
|         position: Cesium.Cartesian3.fromDegrees(end.lng, end.lat, end.alt), | ||||
|       }) | ||||
|     ) | ||||
|     this.ids.push(id) | ||||
|   } | ||||
|  | ||||
|   /** | ||||
|    * 清除测量 | ||||
|    */ | ||||
|   destroy() { | ||||
|     [this.polyline_id, this.end_id, this.start_id, ...this.ids].forEach(id => { | ||||
|       this.remove_entity(id) | ||||
|     }) | ||||
|   } | ||||
|  | ||||
|  | ||||
|   /** | ||||
|    * 结束测量 | ||||
|    */ | ||||
|   end() { | ||||
|     // YJ.Measure.SetMeasureStatus(false) | ||||
|     // this.tip.destroy() | ||||
|     // this.event.destroy() | ||||
|     super.end() | ||||
|     // this.setPickStatus(this.pickStatus.pick) | ||||
|  | ||||
|   } | ||||
| } | ||||
|  | ||||
| export default MeasureDistance | ||||
							
								
								
									
										197
									
								
								src/Measure/MeasureHeight/index.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										197
									
								
								src/Measure/MeasureHeight/index.js
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,197 @@ | ||||
| /** | ||||
|  * @name: index | ||||
|  * @author: Administrator | ||||
|  * @date: 2022-07-22 17:15 | ||||
|  * @description:index | ||||
|  * @update: 2022-07-22 17:15 | ||||
|  */ | ||||
| import Measure from "../index"; | ||||
|  | ||||
| class MeasureHeight extends Measure { | ||||
|   /** | ||||
|    * @constructor | ||||
|    * @param sdk  | ||||
|    * @description 高度测量 | ||||
|    * */ | ||||
|   constructor(sdk) { | ||||
|     super(sdk, {text: "左键开始,右键取消"}); | ||||
|   } | ||||
|  | ||||
|   static create_polygon(that) { | ||||
|     let id = that.randomString() | ||||
|     let a = that.viewer.entities.add(new Cesium.Entity({ | ||||
|       id, | ||||
|       billboard: { | ||||
|         image: that.getSourceRootPath() + '/img/point.png', | ||||
|         verticalOrigin: Cesium.VerticalOrigin.BOTTOM, | ||||
|         disableDepthTestDistance: Number.POSITIVE_INFINITY, | ||||
|         color: Cesium.Color.WHITE.withAlpha(0.99) | ||||
|  | ||||
|       }, | ||||
|       position: new Cesium.CallbackProperty(() => { | ||||
|         return that.position | ||||
|       }, false), | ||||
|       label: { | ||||
|         text: new Cesium.CallbackProperty(() => { | ||||
|           return that.text | ||||
|         }, false), | ||||
|         scale: 1, | ||||
|         // fillColor: Cesium.Color.RED, | ||||
|         font: 'normal 20px MicroSoft YaHei', | ||||
|         verticalOrigin: Cesium.VerticalOrigin.BOTTOM, | ||||
|         style: Cesium.LabelStyle.FILL_AND_OUTLINE, | ||||
|         pixelOffset: new Cesium.Cartesian2(0, -15), | ||||
|         disableDepthTestDistance: Number.POSITIVE_INFINITY, | ||||
|  | ||||
|       }, | ||||
|       polyline: { | ||||
|         positions: new Cesium.CallbackProperty(e => { | ||||
|           return that.positions; | ||||
|         }, false), | ||||
|         width: 2, | ||||
|         material: Cesium.Color.YELLOW, | ||||
|         zIndex: 99999999 | ||||
|       }, | ||||
|       ellipse: { | ||||
|         height: new Cesium.CallbackProperty(() => { | ||||
|           return that.height + that.firstpoint.alt; | ||||
|         }, false), | ||||
|         semiMinorAxis: new Cesium.CallbackProperty(e => { | ||||
|           return that.circleRadius; | ||||
|         }, false), | ||||
|         semiMajorAxis: new Cesium.CallbackProperty(e => { | ||||
|           return that.circleRadius; | ||||
|         }, false), | ||||
|         material: new Cesium.Color.fromCssColorString(that.defaultColor) | ||||
|  | ||||
|       }, | ||||
|     })) | ||||
|     return id | ||||
|   } | ||||
|  | ||||
|   static create_point(that, cartesian, option = {}) { | ||||
|     let id = that.randomString() | ||||
|     let p = that.cartesian3Towgs84(cartesian, that.viewer) | ||||
|     let params = { | ||||
|       id: id, | ||||
|       position: Cesium.Cartesian3.fromDegrees(p.lng, p.lat, p.alt), | ||||
|       billboard: { | ||||
|         image: that.getSourceRootPath() + '/img/point.png', | ||||
|         verticalOrigin: Cesium.VerticalOrigin.BOTTOM, | ||||
|         disableDepthTestDistance: Number.POSITIVE_INFINITY, | ||||
|         color: Cesium.Color.WHITE.withAlpha(0.99) | ||||
|       } | ||||
|     } | ||||
|     if (option.label) { | ||||
|       params.label = { | ||||
|         text: option.label.text, | ||||
|         scale: 1, | ||||
|         // fillColor: Cesium.Color.fromCssColorString("#06eee5"), | ||||
|         font: 'normal 20px MicroSoft YaHei', | ||||
|         verticalOrigin: Cesium.VerticalOrigin.BOTTOM, | ||||
|         style: Cesium.LabelStyle.FILL_AND_OUTLINE, | ||||
|         pixelOffset: new Cesium.Cartesian2(0, -15), | ||||
|       } | ||||
|     } | ||||
|     that.viewer.entities.add( | ||||
|       new Cesium.Entity(params) | ||||
|     ) | ||||
|     return id | ||||
|   } | ||||
|  | ||||
|   /** | ||||
|    * 开始测量 | ||||
|    */ | ||||
|   start() { | ||||
|     if (!YJ.Measure.GetMeasureStatus()) { | ||||
|       super.start() | ||||
|       this.positions = [] | ||||
|       this.position = new Cesium.Cartesian3() | ||||
|       this.height = 0 | ||||
|       this.text = "" | ||||
|       this.circleRadius = 0 | ||||
|       let count = 0; | ||||
|       this.firstpoint = null | ||||
|  | ||||
|       let leftEvent = (movement, cartesian) => { | ||||
|         if (this.firstpoint === null) { | ||||
|           this.positions.push(cartesian) | ||||
|           this.firstpoint = this.cartesian3Towgs84(cartesian, this.viewer) | ||||
|           this.ids.push(MeasureHeight.create_polygon(this)) | ||||
|           this.ids.push(MeasureHeight.create_point(this, cartesian)) | ||||
|         } | ||||
|         count++ | ||||
|         this.tip.setPosition(cartesian, movement.position.x, movement.position.y) | ||||
|         if (count === 2) { | ||||
|           if (this.firstpoint) { | ||||
|             let cur_point = this.cartesian3Towgs84(cartesian, this.viewer) | ||||
|             this.positions[1] = Cesium.Cartesian3.fromDegrees(this.firstpoint.lng, this.firstpoint.lat, cur_point.alt) | ||||
|             this.positions[2] = cartesian | ||||
|             this.position = this.positions[1] | ||||
|             this.circleRadius = this.computeDistance([this.firstpoint, cur_point]) | ||||
|             this.height = Number((cur_point.alt - this.firstpoint.alt).toFixed(2)) | ||||
|             this.text = "相对高度:" + this.height + " 米" | ||||
|             this.tip.set_text("左键完成,右键取消;半径:" + this.circleRadius + " 米") | ||||
|           } | ||||
|           this.ids.push(MeasureHeight.create_point(this, cartesian, {label: {text: "半径:" + this.circleRadius + " 米"}})) | ||||
|           this.end() | ||||
|         } | ||||
|       } | ||||
|       this.event.mouse_left(leftEvent) | ||||
|       this.event.mouse_move((movement, cartesian) => { | ||||
|         this.tip.setPosition(cartesian, movement.endPosition.x, movement.endPosition.y) | ||||
|         if (this.firstpoint) { | ||||
|           let cur_point = this.cartesian3Towgs84(cartesian, this.viewer) | ||||
|           this.positions[1] = Cesium.Cartesian3.fromDegrees(this.firstpoint.lng, this.firstpoint.lat, cur_point.alt) | ||||
|           this.positions[2] = cartesian | ||||
|           this.position = this.positions[1] | ||||
|           this.circleRadius = this.computeDistance([this.firstpoint, cur_point]) | ||||
|           this.height = Number((cur_point.alt - this.firstpoint.alt).toFixed(2)) | ||||
|           this.text = "相对高度:" + this.height + " 米" | ||||
|           this.tip.set_text("左键完成,右键取消;半径:" + this.circleRadius + " 米") | ||||
|         } | ||||
|       }) | ||||
|       this.event.mouse_right((movement, cartesian) => { | ||||
|         this.end() | ||||
|         this.destroy() | ||||
|       }) | ||||
|       this.event.gesture_pinck_start((movement, cartesian) => { | ||||
|         let startTime = new Date() | ||||
|         let pos = { | ||||
|           position: { | ||||
|             x: (movement.position1.x + movement.position2.x) / 2, | ||||
|             y: (movement.position1.y + movement.position2.y) / 2 | ||||
|           } | ||||
|         } | ||||
|         this.event.gesture_pinck_end(() => { | ||||
|           let endTime = new Date() | ||||
|           if (endTime - startTime >= 500) { | ||||
|             // 长按取消 | ||||
|             this.end() | ||||
|             this.destroy() | ||||
|           } | ||||
|           else { | ||||
|             leftEvent(pos, cartesian) | ||||
|           } | ||||
|         }) | ||||
|       }) | ||||
|     } | ||||
|  | ||||
|   } | ||||
|  | ||||
|   /** | ||||
|    * 结束测量 | ||||
|    */ | ||||
|   end() { | ||||
|     super.end() | ||||
|   } | ||||
|  | ||||
|   /** | ||||
|    * 清除测量 | ||||
|    */ | ||||
|   destroy() { | ||||
|     super.destroy() | ||||
|   } | ||||
| } | ||||
|  | ||||
| export default MeasureHeight | ||||
							
								
								
									
										182
									
								
								src/Measure/MeasureLocation/index.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										182
									
								
								src/Measure/MeasureLocation/index.js
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,182 @@ | ||||
| /** | ||||
|  * @name: index | ||||
|  * @author: Administrator | ||||
|  * @date: 2022-07-22 16:13 | ||||
|  * @description:index | ||||
|  * @update: 2022-07-22 16:13 | ||||
|  */ | ||||
| import Measure from "../index"; | ||||
| import { Proj } from "../../Tools/proj"; | ||||
| import { getCoordinateSystem } from "../../Global/global"; | ||||
|  | ||||
| class MeasureLocation extends Measure { | ||||
|   /** | ||||
|    * @constructor | ||||
|    * @param sdk  | ||||
|    * @description 坐标测量 | ||||
|    * */ | ||||
|   constructor(sdk) { | ||||
|     super(sdk, {text: ""}); | ||||
|     this.defaultColor = "#f11515" | ||||
|     this.locationID = this.randomString() | ||||
|     this.position = new Cesium.Cartesian3() | ||||
|     this.text = "" | ||||
|   } | ||||
|  | ||||
|   static createLocation(that) { | ||||
|     that.viewer.entities.add(new Cesium.Entity({ | ||||
|       id: that.locationID, | ||||
|       show: false, | ||||
|       position: new Cesium.CallbackProperty(() => { | ||||
|         return that.position | ||||
|       }, false), | ||||
|       label: { | ||||
|         text: new Cesium.CallbackProperty(() => { | ||||
|           return that.text | ||||
|         }, false), | ||||
|         //标注文字描述 | ||||
|         font: '22px Microsoft YaHei', | ||||
|  | ||||
|         fillColor: new Cesium.Color.fromCssColorString(that.defaultColor), | ||||
|         style: Cesium.LabelStyle.FILL_AND_OUTLINE, | ||||
|         //标注的遮挡距离设置为100则视角与标注的距离大于100米时会有遮挡 | ||||
|         // distanceDisplayCondition: this.distanceDisplayCondition, | ||||
|         // scale: this.options.label.scale, | ||||
|         horizontalOrigin: Cesium.HorizontalOrigin.LEFT, | ||||
|         verticalOrigin: Cesium.VerticalOrigin.BOTTOM, | ||||
|         disableDepthTestDistance: Number.POSITIVE_INFINITY, | ||||
|  | ||||
|         pixelOffset: new Cesium.Cartesian2( | ||||
|           -100, | ||||
|           -50 | ||||
|         ), | ||||
|         // disableDepthTestDistance: this.disableDepthTestDistance, | ||||
|       }, | ||||
|       billboard: { | ||||
|         image: that.getSourceRootPath() + "/img/location.png", | ||||
|         color: Cesium.Color.fromCssColorString(`rgba(255,255,255,0.99)`), | ||||
|         disableDepthTestDistance: Number.POSITIVE_INFINITY, | ||||
|         // scaleByDistance: new Cesium.NearFarScalar( | ||||
|         //   2000, | ||||
|         //   1, | ||||
|         //   1000000, | ||||
|         //   0 | ||||
|         // ), | ||||
|         scale: 1, | ||||
|         horizontalOrigin: Cesium.HorizontalOrigin.CENTER, | ||||
|         verticalOrigin: Cesium.VerticalOrigin.BOTTOM, | ||||
|         width: 48, | ||||
|         height: 48 | ||||
|       } | ||||
|     })) | ||||
|   } | ||||
|  | ||||
|   static create_point(that) { | ||||
|     let id = that.randomString() | ||||
|     that.viewer.entities.add( | ||||
|       new Cesium.Entity({ | ||||
|         id: id, | ||||
|         position: new Cesium.CallbackProperty(() => { | ||||
|           return that.position | ||||
|         }, false), | ||||
|         billboard: { | ||||
|           image: that.getSourceRootPath() + '/img/point.png', | ||||
|           color: Cesium.Color.fromCssColorString(`rgba(255,255,255,0.99)`), | ||||
|           verticalOrigin: Cesium.VerticalOrigin.BOTTOM, | ||||
|           disableDepthTestDistance: Number.POSITIVE_INFINITY, | ||||
|           color: Cesium.Color.WHITE.withAlpha(0.99) | ||||
|         } | ||||
|       }) | ||||
|     ) | ||||
|     return id | ||||
|   } | ||||
|  | ||||
|   /** | ||||
|    * 开始测量 | ||||
|    */ | ||||
|   start() { | ||||
|     if (!YJ.Measure.GetMeasureStatus()) { | ||||
|       super.start() | ||||
|       this.cache_id = MeasureLocation.create_point(this) | ||||
|       MeasureLocation.createLocation(this) | ||||
|  | ||||
|       let leftEvent = (movement, cartesian) => { | ||||
|         this.position = cartesian | ||||
|         let entity = this.viewer.entities.getById(this.locationID) | ||||
|         if(entity) { | ||||
|           entity.show = true | ||||
|         } | ||||
|         let p = this.cartesian3Towgs84(cartesian, this.viewer) | ||||
|         let coordinateSystem = getCoordinateSystem() | ||||
|         if(coordinateSystem==='EPSG:4326') { | ||||
|           this.text = `经度:${Number(p.lng.toFixed(8))}\n纬度:${Number(p.lat.toFixed(8))}\n海拔:${Number(p.alt.toFixed(2))}` | ||||
|         } | ||||
|         else { | ||||
|           let result = this.convert([{x: p.lng, y: p.lat, z: p.alt}], 'EPSG:4326', coordinateSystem) | ||||
|           this.text = `x:${Number(result.points[0].x.toFixed(8))}\ny:${Number(result.points[0].y.toFixed(8))}\nz:${Number(result.points[0].z.toFixed(2))}` | ||||
|         } | ||||
|         this.end() | ||||
|       } | ||||
|       this.event.mouse_left(leftEvent) | ||||
|       this.event.mouse_right((movement, cartesian) => { | ||||
|         this.destroy() | ||||
|         this.end() | ||||
|       }) | ||||
|       this.event.mouse_move((movement, cartesian) => { | ||||
|         this.tip.setPosition(cartesian, movement.endPosition.x, movement.endPosition.y) | ||||
|         let entity = this.viewer.entities.getById(this.locationID) | ||||
|         if(entity) { | ||||
|           entity.show = true | ||||
|         } | ||||
|         this.position = cartesian | ||||
|         let p = this.cartesian3Towgs84(cartesian, this.viewer) | ||||
|         let coordinateSystem = getCoordinateSystem() | ||||
|         if(coordinateSystem==='EPSG:4326') { | ||||
|           this.text = `经度:${Number(p.lng.toFixed(8))}\n纬度:${Number(p.lat.toFixed(8))}\n海拔:${Number(p.alt.toFixed(2))}` | ||||
|         } | ||||
|         else { | ||||
|           let result = this.convert([{x: p.lng, y: p.lat, z: p.alt}], 'EPSG:4326', coordinateSystem) | ||||
|           this.text = `x:${Number(result.points[0].x.toFixed(8))}\ny:${Number(result.points[0].y.toFixed(8))}\nz:${Number(result.points[0].z.toFixed(2))}` | ||||
|         } | ||||
|       }) | ||||
|       this.event.gesture_pinck_start((movement, cartesian) => { | ||||
|         let startTime = new Date() | ||||
|         let pos = { | ||||
|           position: { | ||||
|             x: (movement.position1.x + movement.position2.x) / 2, | ||||
|             y: (movement.position1.y + movement.position2.y) / 2 | ||||
|           } | ||||
|         } | ||||
|         this.event.gesture_pinck_end(() => { | ||||
|           let endTime = new Date() | ||||
|           if (endTime - startTime >= 500) { | ||||
|             // 长按取消 | ||||
|             this.destroy() | ||||
|             this.end() | ||||
|           } | ||||
|           else { | ||||
|             leftEvent(pos, cartesian) | ||||
|           } | ||||
|         }) | ||||
|       }) | ||||
|     } | ||||
|   } | ||||
|  | ||||
|   /** | ||||
|    * 清除测量 | ||||
|    */ | ||||
|   destroy() { | ||||
|     this.remove_entity(this.locationID) | ||||
|     this.remove_entity(this.cache_id) | ||||
|     super.destroy() | ||||
|   } | ||||
|  | ||||
|   /** | ||||
|    * 结束测量 | ||||
|    */ | ||||
|   end() { | ||||
|     super.end() | ||||
|   } | ||||
| } | ||||
|  | ||||
| export default MeasureLocation | ||||
							
								
								
									
										276
									
								
								src/Measure/MeasureProjectionDistance/index.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										276
									
								
								src/Measure/MeasureProjectionDistance/index.js
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,276 @@ | ||||
| /** | ||||
|  * @name: index | ||||
|  * @author: Administrator | ||||
|  * @date: 2022-07-11 10:31 | ||||
|  * @description:index | ||||
|  * @update: 2022-07-11 10:31 | ||||
|  */ | ||||
|  | ||||
| import Measure from "../index" | ||||
|  | ||||
| class MeasureProjectionDistance extends Measure { | ||||
|   /** | ||||
|    * @constructor | ||||
|    * @param sdk  | ||||
|    * @description 投影距离测量 | ||||
|    * */ | ||||
|   constructor(sdk, options = {}) { | ||||
|     super(sdk, options) | ||||
|     this.options.color = this.options.color || "#00ffff" | ||||
|     this.start_id = "" | ||||
|     this.end_id = "" | ||||
|     this.polyline_id = "" | ||||
|     this.clampPositions = [] | ||||
|   } | ||||
|  | ||||
|   async clampToGroundMeasure(meters, cb) { | ||||
|     let positions = [] | ||||
|     this.ids.forEach((id, index) => { | ||||
|       let p = this.viewer.entities.getById(id).position.getValue() | ||||
|       positions.push(this.cartesian3Towgs84(p, this.viewer)) | ||||
|     }) | ||||
|     let res = this.chunkLine(positions, meters) | ||||
|     let coordinates = [] | ||||
|     res.forEach((Feature, index) => { | ||||
|       if (index === 0) { | ||||
|         coordinates = [...Feature.geometry.coordinates] | ||||
|       } else { | ||||
|         coordinates.push(Feature.geometry.coordinates[1]) | ||||
|       } | ||||
|     }) | ||||
|     let total = coordinates.length | ||||
|  | ||||
|     for (const item of coordinates) { | ||||
|       const index = coordinates.indexOf(item); | ||||
|       let r = await this.getHeight({lng: item[0], lat: item[1], alt: 0}, index, total,) | ||||
|       cb(null, r) | ||||
|     } | ||||
|   } | ||||
|  | ||||
|   async sampleHeight(p1, index) { | ||||
|     let p2 = await this.sampleHeightMostDetailed([p1]) | ||||
|     p1.alt = p2[0].height | ||||
|     return {position: p1, index} | ||||
|   } | ||||
|  | ||||
|  | ||||
|   async getHeight(p1, index, total) { | ||||
|     let p2 = await this.sampleHeightMostDetailed([p1]) | ||||
|     p1.alt = p2[0].height | ||||
|     this.clampPositions.push({position: p1, index}) | ||||
|     if (total === this.clampPositions.length) { | ||||
|       let total_length = this.startCompute() | ||||
|       return {total, current: this.clampPositions.length, total_length} | ||||
|     } | ||||
|     return {total, current: this.clampPositions.length,} | ||||
|   } | ||||
|  | ||||
|   startCompute() { | ||||
|     this.clampPositions.sort(function (a, b) { | ||||
|       return a.index < b.index | ||||
|     }) | ||||
|     let total_length = 0 | ||||
|     let l = this.clampPositions.length - 1 | ||||
|     this.clampPositions.forEach((item, index) => { | ||||
|       if (index !== l) { | ||||
|         let d1 = this.computeDistance([item.position, this.clampPositions[index + 1].position]) | ||||
|         let d2 = Math.abs(item.position.alt - this.clampPositions[index + 1].position.alt) | ||||
|         let d3 = Math.sqrt(d1 * d1 + d2 * d2) | ||||
|         total_length += d3 | ||||
|       } | ||||
|     }) | ||||
|     return Number(total_length.toFixed(2)) | ||||
|   } | ||||
|  | ||||
|  | ||||
|   static createPolyline(that) { | ||||
|     let id = that.randomString() | ||||
|     that.viewer.entities.add(new Cesium.Entity({ | ||||
|       id, | ||||
|       polyline: { | ||||
|         positions: new Cesium.CallbackProperty(() => { | ||||
|           return that.positions | ||||
|         }, false), | ||||
|         clampToGround: true, | ||||
|         width: 3, | ||||
|         material: new Cesium.PolylineDashMaterialProperty({ | ||||
|           color: new Cesium.Color.fromCssColorString(that.options.color || that.defaultColor), | ||||
|           dashLength: 20, //短划线长度 | ||||
|         }), | ||||
|       }, | ||||
|       zIndex: 99999999 | ||||
|     })) | ||||
|     return id | ||||
|   } | ||||
|  | ||||
|   static create_point(cartesian, { | ||||
|     label, image = "point.png", | ||||
|     width, | ||||
|     height | ||||
|   }, that) { | ||||
|     let id = that.randomString() | ||||
|     let p = that.cartesian3Towgs84(cartesian, that.viewer) | ||||
|     if (label) { | ||||
|       label.pixelOffset = new Cesium.Cartesian2( | ||||
|         0, -(height || 32) | ||||
|       ) | ||||
|     } | ||||
|     that.viewer.entities.add( | ||||
|       new Cesium.Entity({ | ||||
|         id: id, | ||||
|         label, | ||||
|         position: Cesium.Cartesian3.fromDegrees(p.lng, p.lat, p.alt), | ||||
|         billboard: { | ||||
|           image: that.getSourceRootPath() + '/img/' + image, | ||||
|           verticalOrigin: Cesium.VerticalOrigin.BOTTOM, | ||||
|           disableDepthTestDistance: Number.POSITIVE_INFINITY, | ||||
|           width, | ||||
|           height | ||||
|         } | ||||
|       }) | ||||
|     ) | ||||
|     return id | ||||
|   } | ||||
|  | ||||
|   getLabel(text) { | ||||
|     return { | ||||
|       text: text || '', | ||||
|       //标注文字描述 | ||||
|       font: '20px Microsoft YaHei', | ||||
|       fillColor: Cesium.Color.fromCssColorString('#f1e605'), | ||||
|       style: Cesium.LabelStyle.FILL_AND_OUTLINE, | ||||
|       //标注的遮挡距离设置为100则视角与标注的距离大于100米时会有遮挡 | ||||
|       // distanceDisplayCondition: this.distanceDisplayCondition, | ||||
|       scale: 1, | ||||
|       horizontalOrigin: Cesium.HorizontalOrigin.CENTER, | ||||
|       verticalOrigin: Cesium.VerticalOrigin.BOTTOM, | ||||
|       disableDepthTestDistance: Number.POSITIVE_INFINITY, | ||||
|  | ||||
|       // disableDepthTestDistance: this.disableDepthTestDistance, | ||||
|     } | ||||
|   } | ||||
|  | ||||
|   /** | ||||
|    * 开始测量 | ||||
|    */ | ||||
|   start() { | ||||
|     if (!YJ.Measure.GetMeasureStatus()) { | ||||
|       super.start() | ||||
|       this.positions = [] | ||||
|       this.cachePositions = [] | ||||
|  | ||||
|       let leftEvent = async (movement, car) => { | ||||
|         if (this.ids.length === 0) { | ||||
|           this.polyline_id = (MeasureProjectionDistance.createPolyline(this)) | ||||
|           this.start_id = MeasureProjectionDistance.create_point(car, { | ||||
|             image: "start1.png", width: 30, height: 38, label: this.getLabel("") | ||||
|           }, this) | ||||
|           //创建起点 | ||||
|         } | ||||
|  | ||||
|         this.positions = this.cachePositions.concat(car) | ||||
|         this.tip.setPosition(car, movement.position.x, movement.position.y) | ||||
|  | ||||
|         if (this.ids.length !== 0) { | ||||
|           let cur_point = this.cartesian3Towgs84(car, this.viewer) | ||||
|           let pre_p = this.cartesian3Towgs84(this.cachePositions[this.cachePositions.length - 1], this.viewer) | ||||
|           let cur_len = this.computeDistance([cur_point, pre_p]) | ||||
|           let text = "投影距离:" + cur_len + " 米" | ||||
|           this.ids.push(MeasureProjectionDistance.create_point(car, {label: this.getLabel(text)}, this)) | ||||
|           this.cachePositions.push(car) | ||||
|         } else { | ||||
|           this.cachePositions.push(car) | ||||
|           this.ids.push(MeasureProjectionDistance.create_point(car, {show: false}, this)) | ||||
|           let startPoint = this.viewer.entities.getById(this.ids[0]) | ||||
|           if(startPoint) { | ||||
|             startPoint.billboard.show = false | ||||
|           } | ||||
|         } | ||||
|  | ||||
|       } | ||||
|       let rightEvent = (movement, car) => { | ||||
|         if (this.cachePositions.length) { | ||||
|           this.positions = this.cachePositions | ||||
|           this.end_id = MeasureProjectionDistance.create_point(this.cachePositions[this.cachePositions.length - 1], { | ||||
|             image: "end1.png", | ||||
|             width: 30, | ||||
|             height: 38, | ||||
|           }, this) | ||||
|           let endPoint = this.viewer.entities.getById(this.ids[this.ids.length-1]) | ||||
|           if(endPoint) { | ||||
|             endPoint.billboard.show = false | ||||
|           } | ||||
|         } | ||||
|         if (this.cachePositions.length < 2) { | ||||
|           this.destroy() | ||||
|           YJ.Measure.Measures.pop()//弹出测量实体 | ||||
|         } | ||||
|         this.end() | ||||
|       } | ||||
|  | ||||
|       this.event.mouse_left(leftEvent) | ||||
|       this.event.mouse_move((movement, car) => { | ||||
|         this.tip.setPosition(car, movement.endPosition.x, movement.endPosition.y) | ||||
|         this.positions = this.cachePositions.concat(car) | ||||
|         if (this.cachePositions.length) { | ||||
|           let cur_point = this.cartesian3Towgs84(car, this.viewer) | ||||
|           let pre_p = this.cartesian3Towgs84(this.cachePositions[this.cachePositions.length - 1], this.viewer) | ||||
|           let cur_len = this.computeDistance([cur_point, pre_p]) | ||||
|           let text = "当前投影距离:" + cur_len + " 米" | ||||
|           this.tip.set_text(text) | ||||
|         } | ||||
|       }) | ||||
|       this.event.mouse_right(rightEvent) | ||||
|       this.event.mouse_right_keyboard_ctrl((movement, car) => { | ||||
|         if (this.cachePositions.length) { | ||||
|           this.cachePositions.pop() | ||||
|           this.remove_entity(this.ids.pop()) | ||||
|         } | ||||
|       }) | ||||
|       this.event.gesture_pinck_start((movement, cartesian) => { | ||||
|         let startTime = new Date() | ||||
|         let pos = { | ||||
|           position: { | ||||
|             x: (movement.position1.x + movement.position2.x) / 2, | ||||
|             y: (movement.position1.y + movement.position2.y) / 2 | ||||
|           } | ||||
|         } | ||||
|         this.event.gesture_pinck_end(() => { | ||||
|           let endTime = new Date() | ||||
|           if (endTime - startTime >= 500) { | ||||
|             // 长按取消 | ||||
|             rightEvent(pos, cartesian) | ||||
|           } | ||||
|           else { | ||||
|             leftEvent(pos, cartesian) | ||||
|           } | ||||
|         }) | ||||
|       }) | ||||
|     } | ||||
|   } | ||||
|  | ||||
|   /** | ||||
|    * 清除测量 | ||||
|    */ | ||||
|   destroy() { | ||||
|     [this.polyline_id, this.end_id, this.start_id, ...this.ids].forEach(id => { | ||||
|       this.remove_entity(id) | ||||
|     }) | ||||
|     super.destroy() | ||||
|   } | ||||
|  | ||||
|  | ||||
|   /** | ||||
|    * 结束测量 | ||||
|    */ | ||||
|   end() { | ||||
|     // YJ.Measure.SetMeasureStatus(false) | ||||
|     // this.tip.destroy() | ||||
|     // this.event.destroy() | ||||
|     super.end() | ||||
|     // this.setPickStatus(this.pickStatus.pick) | ||||
|  | ||||
|   } | ||||
| } | ||||
|  | ||||
| export default MeasureProjectionDistance | ||||
							
								
								
									
										316
									
								
								src/Measure/MeasureSlopeDistance/index.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										316
									
								
								src/Measure/MeasureSlopeDistance/index.js
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,316 @@ | ||||
| /** | ||||
|  * @name: index | ||||
|  * @author: Administrator | ||||
|  * @date: 2022-07-11 10:31 | ||||
|  * @description:index | ||||
|  * @update: 2022-07-11 10:31 | ||||
|  */ | ||||
|  | ||||
| import Measure from "../index" | ||||
| import MouseEvent from "../../Event"; | ||||
|  | ||||
| class MeasureSlopeDistance extends Measure { | ||||
|   /** | ||||
|    * @constructor | ||||
|    * @param sdk  | ||||
|    * @description 坡度测量 | ||||
|    * */ | ||||
|   constructor(sdk, options = {}) { | ||||
|     super(sdk, options) | ||||
|     this.options.color = this.options.color || "#00ffff" | ||||
|     this.start_id = "" | ||||
|     this.end_id = "" | ||||
|     this.polyline_id = "" | ||||
|     this.clampPositions = [] | ||||
|     this.event = new MouseEvent(sdk) | ||||
|   } | ||||
|  | ||||
|   async clampToGroundMeasure(meters, cb) { | ||||
|     let positions = [] | ||||
|     this.ids.forEach((id, index) => { | ||||
|       let p = this.viewer.entities.getById(id).position.getValue() | ||||
|       positions.push(this.cartesian3Towgs84(p, this.viewer)) | ||||
|     }) | ||||
|     let res = this.chunkLine(positions, meters) | ||||
|     let coordinates = [] | ||||
|     res.forEach((Feature, index) => { | ||||
|       if (index === 0) { | ||||
|         coordinates = [...Feature.geometry.coordinates] | ||||
|       } else { | ||||
|         coordinates.push(Feature.geometry.coordinates[1]) | ||||
|       } | ||||
|     }) | ||||
|     let total = coordinates.length | ||||
|  | ||||
|     for (const item of coordinates) { | ||||
|       const index = coordinates.indexOf(item); | ||||
|       let r = await this.getHeight({ lng: item[0], lat: item[1], alt: 0 }, index, total,) | ||||
|       cb(null, r) | ||||
|     } | ||||
|   } | ||||
|  | ||||
|   async sampleHeight(p1, index) { | ||||
|     let p2 = await this.sampleHeightMostDetailed([p1]) | ||||
|     p1.alt = p2[0].height | ||||
|     return { position: p1, index } | ||||
|   } | ||||
|  | ||||
|  | ||||
|   async getHeight(p1, index, total) { | ||||
|     let p2 = await this.sampleHeightMostDetailed([p1]) | ||||
|     p1.alt = p2[0].height | ||||
|     this.clampPositions.push({ position: p1, index }) | ||||
|     if (total === this.clampPositions.length) { | ||||
|       let total_length = this.startCompute() | ||||
|       return { total, current: this.clampPositions.length, total_length } | ||||
|     } | ||||
|     return { total, current: this.clampPositions.length, } | ||||
|   } | ||||
|  | ||||
|   startCompute() { | ||||
|     this.clampPositions.sort(function (a, b) { | ||||
|       return a.index < b.index | ||||
|     }) | ||||
|     let total_length = 0 | ||||
|     let l = this.clampPositions.length - 1 | ||||
|     this.clampPositions.forEach((item, index) => { | ||||
|       if (index !== l) { | ||||
|         let d1 = this.computeDistance([item.position, this.clampPositions[index + 1].position]) | ||||
|         let d2 = Math.abs(item.position.alt - this.clampPositions[index + 1].position.alt) | ||||
|         let d3 = Math.sqrt(d1 * d1 + d2 * d2) | ||||
|         total_length += d3 | ||||
|       } | ||||
|     }) | ||||
|     return Number(total_length.toFixed(2)) | ||||
|   } | ||||
|  | ||||
|  | ||||
|   static createPolyline(that) { | ||||
|     let id = that.randomString() | ||||
|     that.viewer.entities.add(new Cesium.Entity({ | ||||
|       id, | ||||
|       polyline: { | ||||
|         positions: new Cesium.CallbackProperty(() => { | ||||
|           return that.positions | ||||
|         }, false), | ||||
|         clampToGround: true, | ||||
|         width: 3, | ||||
|         material: new Cesium.PolylineDashMaterialProperty({ | ||||
|           color: new Cesium.Color.fromCssColorString(that.options.color || that.defaultColor), | ||||
|           dashLength: 20, //短划线长度 | ||||
|         }), | ||||
|         zIndex: 99999999 | ||||
|       } | ||||
|     })) | ||||
|     return id | ||||
|   } | ||||
|  | ||||
|   static create_point(cartesian, { | ||||
|     label, image = "point.png", | ||||
|     width, | ||||
|     height | ||||
|   }, that) { | ||||
|     let id = that.randomString() | ||||
|     let p = that.cartesian3Towgs84(cartesian, that.viewer) | ||||
|     if (label) { | ||||
|       label.pixelOffset = new Cesium.Cartesian2( | ||||
|         0, -(height || 32) | ||||
|       ) | ||||
|     } | ||||
|     that.viewer.entities.add( | ||||
|       new Cesium.Entity({ | ||||
|         id: id, | ||||
|         label, | ||||
|         position: Cesium.Cartesian3.fromDegrees(p.lng, p.lat, p.alt), | ||||
|         billboard: { | ||||
|           image: that.getSourceRootPath() + '/img/' + image, | ||||
|           verticalOrigin: Cesium.VerticalOrigin.BOTTOM, | ||||
|           disableDepthTestDistance: Number.POSITIVE_INFINITY, | ||||
|           width, | ||||
|           height | ||||
|         } | ||||
|       }) | ||||
|     ) | ||||
|     return id | ||||
|   } | ||||
|  | ||||
|   getLabel(text) { | ||||
|     return { | ||||
|       text: text || '', | ||||
|       //标注文字描述 | ||||
|       font: '20px Microsoft YaHei', | ||||
|       fillColor: Cesium.Color.fromCssColorString('#f1e605'), | ||||
|       style: Cesium.LabelStyle.FILL_AND_OUTLINE, | ||||
|       //标注的遮挡距离设置为100则视角与标注的距离大于100米时会有遮挡 | ||||
|       // distanceDisplayCondition: this.distanceDisplayCondition, | ||||
|       scale: 1, | ||||
|       horizontalOrigin: Cesium.HorizontalOrigin.CENTER, | ||||
|       verticalOrigin: Cesium.VerticalOrigin.BOTTOM, | ||||
|       disableDepthTestDistance: Number.POSITIVE_INFINITY, | ||||
|  | ||||
|       // disableDepthTestDistance: this.disableDepthTestDistance, | ||||
|     } | ||||
|   } | ||||
|  | ||||
|   /** | ||||
|    * 开始测量 | ||||
|    */ | ||||
|   start() { | ||||
|     if (!YJ.Measure.GetMeasureStatus()) { | ||||
|       super.start() | ||||
|       this.positions = [] | ||||
|       this.cachePositions = [] | ||||
|  | ||||
|       let leftEvent = (movement, car) => { | ||||
|         if (this.ids.length === 0) { | ||||
|           this.polyline_id = (MeasureSlopeDistance.createPolyline(this)) | ||||
|           this.start_id = MeasureSlopeDistance.create_point(car, { | ||||
|             image: "start1.png", width: 30, height: 38, label: this.getLabel("") | ||||
|           }, this) | ||||
|           //创建起点 | ||||
|         } | ||||
|         this.tip.setPosition(car, movement.position.x, movement.position.y) | ||||
|         this.positions = this.cachePositions.concat(car) | ||||
|         if (this.ids.length !== 0) { | ||||
|           let cur_point = this.cartesian3Towgs84(car, this.viewer) | ||||
|           let pre_p = this.cartesian3Towgs84(this.cachePositions[this.cachePositions.length - 1], this.viewer) | ||||
|           if (cur_point.lng !== pre_p.lng || cur_point.lat !== pre_p.lat || cur_point.alt !== pre_p.alt) { | ||||
|             this.cachePositions.push(car) | ||||
|             //计算坡度 | ||||
|             this.computeAngle(pre_p, cur_point) | ||||
|           } | ||||
|         } else { | ||||
|           this.cachePositions.push(car) | ||||
|           this.ids.push(MeasureSlopeDistance.create_point(car, {}, this)) | ||||
|           let startPoint = this.viewer.entities.getById(this.ids[0]) | ||||
|           if(startPoint) { | ||||
|             startPoint.billboard.show = false | ||||
|           } | ||||
|         } | ||||
|  | ||||
|       } | ||||
|       let rightEvent = (movement, car) => { | ||||
|         if (this.ids.length !== 0) { | ||||
|           // let cur_point = this.cartesian3Towgs84(car, this.viewer) | ||||
|           // let pre_p = this.cartesian3Towgs84(this.cachePositions[this.cachePositions.length - 1], this.viewer) | ||||
|           // if (cur_point.lng !== pre_p.lng || cur_point.lat !== pre_p.lat || cur_point.alt !== pre_p.alt) { | ||||
|           //   this.cachePositions.push(car) | ||||
|           //   //计算坡度 | ||||
|           //   this.computeAngle(pre_p, cur_point) | ||||
|           // } | ||||
|         } else { | ||||
|           // this.cachePositions.push(car) | ||||
|           this.ids.push(MeasureSlopeDistance.create_point(car, {}, this)) | ||||
|         } | ||||
|         if (this.cachePositions.length) { | ||||
|           this.positions = this.cachePositions | ||||
|           this.end_id = MeasureSlopeDistance.create_point(this.cachePositions[this.cachePositions.length - 1], { | ||||
|             image: "end1.png", | ||||
|             width: 30, | ||||
|             height: 38, | ||||
|           }, this) | ||||
|           let endPoint = this.viewer.entities.getById(this.ids[this.ids.length-1]) | ||||
|           if(endPoint) { | ||||
|             endPoint.billboard.show = false | ||||
|           } | ||||
|         } | ||||
|         if (this.cachePositions.length < 2) { | ||||
|           this.destroy() | ||||
|           YJ.Measure.Measures.pop()//弹出测量实体 | ||||
|         } | ||||
|         this.end() | ||||
|       } | ||||
|  | ||||
|       this.event.mouse_left(leftEvent) | ||||
|       this.event.mouse_move((movement, car) => { | ||||
|         movement.endPosition.y += 2 | ||||
|         let position = movement.endPosition | ||||
|         let cartesian = this.viewer.scene.pickPosition(position) | ||||
|         if (!cartesian) { | ||||
|           const ray = this.viewer.camera.getPickRay(position); //相交的射线 | ||||
|           cartesian = this.viewer.scene.globe.pick(ray, this.viewer.scene); | ||||
|         } | ||||
|         this.tip.setPosition(car, movement.endPosition.x, movement.endPosition.y) | ||||
|         this.positions = this.cachePositions.concat(cartesian) | ||||
|         if (this.cachePositions.length) { | ||||
|           let cur_point = this.cartesian3Towgs84(cartesian, this.viewer) | ||||
|           let pre_p = this.cartesian3Towgs84(this.cachePositions[this.cachePositions.length - 1], this.viewer) | ||||
|           let d1 = this.computeDistance([pre_p, cur_point]) | ||||
|           let d2 = Math.abs(pre_p.alt - cur_point.alt) | ||||
|           let d3 = Math.sqrt(d1 * d1 + d2 * d2) | ||||
|           let cosAlpha = d1 / d3 | ||||
|           let acos = Math.acos(cosAlpha) | ||||
|           let angle = this.radiansToDegrees(acos) | ||||
|           let label = "坡度:" + angle.toFixed(2) + "°" | ||||
|           this.tip.set_text(label) | ||||
|         } | ||||
|       }) | ||||
|       this.event.mouse_right(rightEvent) | ||||
|       this.event.mouse_right_keyboard_ctrl((movement, car) => { | ||||
|         if (this.cachePositions.length) { | ||||
|           this.cachePositions.pop() | ||||
|           this.remove_entity(this.ids.pop()) | ||||
|         } | ||||
|       }) | ||||
|  | ||||
|       this.event.gesture_pinck_start((movement, cartesian) => { | ||||
|         let startTime = new Date() | ||||
|         let pos = { | ||||
|           position: { | ||||
|             x: (movement.position1.x + movement.position2.x) / 2, | ||||
|             y: (movement.position1.y + movement.position2.y) / 2 | ||||
|           } | ||||
|         } | ||||
|         this.event.gesture_pinck_end(() => { | ||||
|           let endTime = new Date() | ||||
|           if (endTime - startTime >= 500) { | ||||
|             // 长按取消 | ||||
|             rightEvent(pos, cartesian) | ||||
|           } | ||||
|           else { | ||||
|             leftEvent(pos, cartesian) | ||||
|           } | ||||
|         }) | ||||
|       }) | ||||
|     } | ||||
|   } | ||||
|  | ||||
|   computeAngle(start, end) { | ||||
|     let d1 = this.computeDistance([start, end]) | ||||
|     let d2 = Math.abs(start.alt - end.alt) | ||||
|     let d3 = Math.sqrt(d1 * d1 + d2 * d2) | ||||
|     let cosAlpha = d1 / d3 | ||||
|     let acos = Math.acos(cosAlpha) | ||||
|     let angle = this.radiansToDegrees(acos) | ||||
|     let label = this.getLabel("坡度:" + angle.toFixed(2) + "°") | ||||
|     label.pixelOffset = new Cesium.Cartesian2( | ||||
|       0, -(32) | ||||
|     ) | ||||
|     this.ids.push(MeasureSlopeDistance.create_point(Cesium.Cartesian3.fromDegrees(end.lng, end.lat, end.alt), {label: label}, this)) | ||||
|   } | ||||
|  | ||||
|   /** | ||||
|    * 清除测量 | ||||
|    */ | ||||
|   destroy() { | ||||
|     [this.polyline_id, this.end_id, this.start_id, ...this.ids].forEach(id => { | ||||
|       this.remove_entity(id) | ||||
|     }) | ||||
|     super.destroy() | ||||
|   } | ||||
|  | ||||
|  | ||||
|   /** | ||||
|    * 结束测量 | ||||
|    */ | ||||
|   end() { | ||||
|     // YJ.Measure.SetMeasureStatus(false) | ||||
|     // this.tip.destroy() | ||||
|     // this.event.destroy() | ||||
|     super.end() | ||||
|     // this.setPickStatus(this.pickStatus.pick) | ||||
|  | ||||
|   } | ||||
| } | ||||
|  | ||||
| export default MeasureSlopeDistance | ||||
							
								
								
									
										173
									
								
								src/Measure/MeasureTdArea/index.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										173
									
								
								src/Measure/MeasureTdArea/index.js
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,173 @@ | ||||
| import Measure from "../index" | ||||
|  | ||||
| /**@extends Measure*/ | ||||
| class MeasureTdArea extends Measure { | ||||
|   /** | ||||
|    * @constructor | ||||
|    * @param sdk  | ||||
|    * @description 贴地面积测量 | ||||
|    * */ | ||||
|   constructor(sdk, options = {}) { | ||||
|     super(sdk, options); | ||||
|     this.options.lineColor = '#ffdf53' | ||||
|     this.polygon_id = "" | ||||
|   } | ||||
|  | ||||
|   static create_polygon(that) { | ||||
|     let id = that.randomString() | ||||
|  | ||||
|     let scaleByDistance = new Cesium.NearFarScalar(2000, 1, 100000, 0) | ||||
|  | ||||
|     let e = that.viewer.entities.add( | ||||
|       new Cesium.Entity({ | ||||
|         id: id, | ||||
|         label: { | ||||
|           text: new Cesium.CallbackProperty(() => { | ||||
|             return that.text | ||||
|           }, false), | ||||
|           //标注文字描述 | ||||
|           font: '20px Microsoft YaHei', | ||||
|           fillColor: Cesium.Color.fromCssColorString('#ffffff'), | ||||
|           style: Cesium.LabelStyle.FILL_AND_OUTLINE, | ||||
|           //标注的遮挡距离设置为100则视角与标注的距离大于100米时会有遮挡 | ||||
|           // distanceDisplayCondition: this.distanceDisplayCondition, | ||||
|  | ||||
|           disableDepthTestDistance: Number.POSITIVE_INFINITY, | ||||
|  | ||||
|           // scaleByDistance, | ||||
|           scale: 1, | ||||
|           horizontalOrigin: Cesium.HorizontalOrigin.CENTER, | ||||
|           verticalOrigin: Cesium.VerticalOrigin.BOTTOM, | ||||
|         }, | ||||
|         position: new Cesium.CallbackProperty(() => { | ||||
|           return that.center | ||||
|         }, false), | ||||
|         polygon: { | ||||
|           classificationType: Cesium.ClassificationType.BOTH, | ||||
|           hierarchy: new Cesium.CallbackProperty((e) => { | ||||
|             return new Cesium.PolygonHierarchy(that.positions) | ||||
|           }, false), | ||||
|           material: new Cesium.Color.fromCssColorString(that.options.color || that.defaultColor), | ||||
|           zIndex: 99999999 | ||||
|         }, | ||||
|         polyline: { | ||||
|           positions: new Cesium.CallbackProperty(() => { | ||||
|             if (that.positions.length) | ||||
|               return that.positions.concat(that.positions[0]) | ||||
|             return that.positions | ||||
|           }, false), | ||||
|           width: 2, | ||||
|           material: new Cesium.PolylineDashMaterialProperty({ | ||||
|             color: new Cesium.Color.fromCssColorString(that.options.lineColor || that.defaultColor), | ||||
|             dashLength: 20, //短划线长度 | ||||
|           }), | ||||
|           clampToGround: true, | ||||
|           zIndex: 99999999 | ||||
|         } | ||||
|       }) | ||||
|     ) | ||||
|     return id | ||||
|   } | ||||
|  | ||||
|   /** | ||||
|    * 开始测量 | ||||
|    */ | ||||
|   start() { | ||||
|     if (!YJ.Measure.GetMeasureStatus()) { | ||||
|       super.start() | ||||
|       this.ids = [] | ||||
|       this.positions = [] | ||||
|       this.text = "" | ||||
|       this.center = new Cesium.Cartesian3() | ||||
|       this.cachePositions = [] | ||||
|       let height = 0 | ||||
|       let text | ||||
|  | ||||
|       let leftEvent = (movement, car) => { | ||||
|         if (this.ids.length === 0) { | ||||
|           this.polygon_id = MeasureTdArea.create_polygon(this) | ||||
|         } | ||||
|         this.cachePositions.push({ ...car }) | ||||
|         this.ids.push(this.create_point({ ...car }, false)) | ||||
|         let po = this.cartesian3Towgs84({ ...car }, this.viewer) | ||||
|         if (po.alt > height) { | ||||
|           height = po.alt | ||||
|         } | ||||
|  | ||||
|         this.positions = this.cachePositions.concat({ ...car }) | ||||
|         this.tip.setPosition({ ...car }, movement.position.x, movement.position.y) | ||||
|       } | ||||
|       let rightEvent = (movement, car) => { | ||||
|         this.positions = this.cachePositions | ||||
|         if (this.positions.length > 2) { | ||||
|           let arr = [] | ||||
|           this.positions.forEach(item => { | ||||
|             let p = this.cartesian3Towgs84(item, this.viewer) | ||||
|             arr.push({ lng: p.lng, lat: p.lat }) | ||||
|           }) | ||||
|           setTimeout(() => { | ||||
|             let center = this.computeCenter(arr) | ||||
|             let area = this.computeSignedArea(this.viewer, arr) | ||||
|             this.center = new Cesium.Cartesian3.fromDegrees(center.lng, center.lat, height) | ||||
|             this.text = "贴地面积:" + area + " ㎡" | ||||
|           }, 0); | ||||
|         } | ||||
|         else { | ||||
|           let error = '面积计算至少需要三个坐标!' | ||||
|           console.warn(error) | ||||
|           window.ELEMENT && window.ELEMENT.Message({ | ||||
|             message: error, | ||||
|             type: 'warning', | ||||
|             duration: 1500 | ||||
|           }); | ||||
|           this.destroy() | ||||
|         } | ||||
|         this.end() | ||||
|       } | ||||
|       this.event.mouse_left(leftEvent) | ||||
|       this.event.mouse_move((movement, car) => { | ||||
|         this.tip.setPosition({ ...car }, movement.endPosition.x, movement.endPosition.y) | ||||
|         this.positions = this.cachePositions.concat({ ...car }) | ||||
|       }) | ||||
|       this.event.mouse_right(rightEvent) | ||||
|       this.event.gesture_pinck_start((movement, cartesian) => { | ||||
|         let startTime = new Date() | ||||
|         let pos = { | ||||
|           position: { | ||||
|             x: (movement.position1.x + movement.position2.x) / 2, | ||||
|             y: (movement.position1.y + movement.position2.y) / 2 | ||||
|           } | ||||
|         } | ||||
|         this.event.gesture_pinck_end(() => { | ||||
|           let endTime = new Date() | ||||
|           if (endTime - startTime >= 500) { | ||||
|             // 长按取消 | ||||
|             rightEvent(pos, cartesian) | ||||
|           } | ||||
|           else { | ||||
|             leftEvent(pos, cartesian) | ||||
|           } | ||||
|         }) | ||||
|       }) | ||||
|     } | ||||
|   } | ||||
|  | ||||
|   /** | ||||
|    * 清除测量 | ||||
|    */ | ||||
|   destroy() { | ||||
|     [this.polygon_id, ...this.ids].forEach(id => { | ||||
|       this.remove_entity(id) | ||||
|     }) | ||||
|     super.destroy() | ||||
|   } | ||||
|  | ||||
|   /** | ||||
|    * 结束测量 | ||||
|    */ | ||||
|   end() { | ||||
|     super.end() | ||||
|   } | ||||
| } | ||||
|  | ||||
| export default MeasureTdArea | ||||
							
								
								
									
										290
									
								
								src/Measure/MeasureTriangle/index.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										290
									
								
								src/Measure/MeasureTriangle/index.js
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,290 @@ | ||||
| /** | ||||
|  * @name: index | ||||
|  * @author: Administrator | ||||
|  * @date: 2022-07-21 15:22 | ||||
|  * @description:index | ||||
|  * @update: 2022-07-21 15:22 | ||||
|  */ | ||||
| import Measure from "../index"; | ||||
|  | ||||
| class MeasureTriangle extends Measure { | ||||
|   /** | ||||
|    * @constructor | ||||
|    * @param sdk  | ||||
|    * @description 三角测量 | ||||
|    * */ | ||||
|   constructor(sdk) { | ||||
|     super(sdk); | ||||
|   } | ||||
|  | ||||
|   cal_center(positions) { | ||||
|     let p1 = this.cartesian3Towgs84(positions[0], this.viewer) | ||||
|     let p2 = this.cartesian3Towgs84(positions[1], this.viewer) | ||||
|     let center = this.computeCenter([p1, p2]); | ||||
|     return Cesium.Cartesian3.fromDegrees(center.lng, center.lat, (p1.alt + p2.alt) / 2) | ||||
|   } | ||||
|  | ||||
|   cal_distance(positions) { | ||||
|     let p1 = this.cartesian3Towgs84(positions[0], this.viewer) | ||||
|     let p2 = this.cartesian3Towgs84(positions[1], this.viewer) | ||||
|     let dis = this.computeDistance([p1, p2]) | ||||
|     p1.alt = p1.alt.toFixed(2) | ||||
|     p2.alt = p2.alt.toFixed(2) | ||||
|     if (p1.alt === p2.alt) {//水平边 | ||||
|       return dis | ||||
|     } else if (Number(dis) === 0.00) {//竖直边 | ||||
|       return Math.abs(p1.alt - p2.alt).toFixed(2) | ||||
|     } else {//斜边 | ||||
|       return Math.sqrt(dis * dis + Math.pow(Math.abs(p1.alt - p2.alt).toFixed(2), 2)).toFixed(2) | ||||
|     } | ||||
|   } | ||||
|  | ||||
|   createPolyline(id) { | ||||
|     let obj = this.id_map.get(id) | ||||
|  | ||||
|     this.viewer.entities.add(new Cesium.Entity({ | ||||
|       id, | ||||
|       position: new Cesium.CallbackProperty(() => { | ||||
|         if (obj.positions.length === 2) | ||||
|           return this.cal_center(obj.positions) | ||||
|         else | ||||
|           return Cesium.Cartesian3() | ||||
|       }, false), | ||||
|       label: { | ||||
|         text: new Cesium.CallbackProperty(() => { | ||||
|           if (obj.positions.length === 2) | ||||
|             return this.cal_distance(obj.positions) + "米" | ||||
|           else | ||||
|             return "0米" | ||||
|         }, false), | ||||
|         scale: 1, | ||||
|         fillColor: Cesium.Color.RED, | ||||
|         font: 'normal 20px MicroSoft YaHei', | ||||
|         verticalOrigin: Cesium.VerticalOrigin.BOTTOM, | ||||
|         style: Cesium.LabelStyle.FILL_AND_OUTLINE, | ||||
|         pixelOffset: new Cesium.Cartesian2(0, -10), | ||||
|         disableDepthTestDistance: Number.POSITIVE_INFINITY, | ||||
|  | ||||
|       }, | ||||
|       polyline: { | ||||
|         positions: new Cesium.CallbackProperty(() => { | ||||
|           return obj.positions | ||||
|         }, false), | ||||
|         width: 2, | ||||
|         material: Cesium.Color.YELLOW, | ||||
|         zIndex: 99999999 | ||||
|       } | ||||
|     })) | ||||
|  | ||||
|     this.ids.push(id) | ||||
|   } | ||||
|  | ||||
|   create_angle_label(positions1, positions2, id, type) { | ||||
|     let entity = new Cesium.Entity({ | ||||
|       id, | ||||
|       position: new Cesium.CallbackProperty(() => { | ||||
|         if (positions1.length === 2) | ||||
|           return this.cal_point(positions1, positions2) | ||||
|         else | ||||
|           return Cesium.Cartesian3() | ||||
|       }), | ||||
|       label: { | ||||
|         text: new Cesium.CallbackProperty(() => { | ||||
|           if (positions1.length === 2) | ||||
|             return this.cal_angle(positions1, positions2, type) + "°" | ||||
|           else | ||||
|             return "0°" | ||||
|         }, false), | ||||
|         scale: 1, | ||||
|         fillColor: Cesium.Color.RED, | ||||
|         font: 'normal 20px MicroSoft YaHei', | ||||
|         verticalOrigin: Cesium.VerticalOrigin.BOTTOM, | ||||
|         style: Cesium.LabelStyle.FILL_AND_OUTLINE, | ||||
|         pixelOffset: new Cesium.Cartesian2(15, -10), | ||||
|       } | ||||
|     }) | ||||
|     this.viewer.entities.add(entity) | ||||
|  | ||||
|   } | ||||
|  | ||||
|   cal_point(positions1, positions2) { | ||||
|     for (let i = 0; i < positions1.length; i++) { | ||||
|       for (let j = 0; j < positions2.length; j++) { | ||||
|         if (positions1[i].x === positions2[j].x && | ||||
|           positions1[i].y === positions2[j].y && | ||||
|           positions1[i].z === positions2[j].z | ||||
|         ) { | ||||
|           return positions1[i] | ||||
|         } | ||||
|       } | ||||
|     } | ||||
|   } | ||||
|  | ||||
|   cal_angle(id1, id2, type) { | ||||
|     if (type === 1) {//水平&竖直 | ||||
|       return 90 | ||||
|     } else if (type === 2 || type === 3) {//水平&斜边  竖直&斜边 | ||||
|       let positions1 = this.id_map.get(id1).positions | ||||
|       let positions2 = this.id_map.get(id2).positions | ||||
|       let p1 = this.cartesian3Towgs84(positions1[0], this.viewer) | ||||
|       let p2 = this.cartesian3Towgs84(positions1[1], this.viewer) | ||||
|       let shuiping = this.computeDistance([p2, p1]) | ||||
|       let p3 = this.cartesian3Towgs84(positions2[0], this.viewer) | ||||
|       let p4 = this.cartesian3Towgs84(positions2[1], this.viewer) | ||||
|       let d = this.computeDistance([p3, p4]) | ||||
|       let h = Math.abs(p3.alt - p4.alt) | ||||
|       let x = Math.sqrt(Math.pow(h, 2) + Math.pow(d, 2)) | ||||
|       if (shuiping == 0.00) { | ||||
|         shuiping = Math.abs(p2.alt - p1.alt) | ||||
|       } | ||||
|       return (Math.acos(shuiping / x) * 180 / Math.PI).toFixed(2) | ||||
|     } | ||||
|   } | ||||
|  | ||||
|   /** | ||||
|    * 开始测量 | ||||
|    */ | ||||
|   start() { | ||||
|  | ||||
|     if (!YJ.Measure.GetMeasureStatus()) { | ||||
|       super.start() | ||||
|       this.positions = [] | ||||
|       this.cachePositions = [] | ||||
|       let shuiping_line_id = this.randomString();//水平线 | ||||
|       let shuizhi_line_id = this.randomString();//竖直边 | ||||
|       let xiebian_line_id = this.randomString();//斜边 | ||||
|  | ||||
|       let angle1 = this.randomString();//角度1 | ||||
|       let angle2 = this.randomString();//角度2 | ||||
|       let angle3 = this.randomString();//角度3 | ||||
|  | ||||
|  | ||||
|       let xiebian_line_positions = [];//斜边 | ||||
|  | ||||
|       this.id_map = new Map() | ||||
|       let first_point = {} | ||||
|       this.id_map.set(xiebian_line_id, {positions: []}) | ||||
|       this.id_map.set(shuiping_line_id, {positions: []}) | ||||
|       this.id_map.set(shuizhi_line_id, {positions: []}) | ||||
|  | ||||
|       let leftEvent = (movement, car) => { | ||||
|         xiebian_line_positions.push(car) | ||||
|  | ||||
|         if (this.ids.length === 0) {//创建三角形 | ||||
|           first_point = this.cartesian3Towgs84(car, this.viewer) | ||||
|           this.createPolyline(shuiping_line_id,) | ||||
|           this.createPolyline(shuizhi_line_id,) | ||||
|           this.createPolyline(xiebian_line_id,) | ||||
|  | ||||
|           // this.cal_angle(shuiping_line_id, shuizhi_line_id, 1) | ||||
|           // this.cal_angle(shuiping_line_id, xiebian_line_id, 2) | ||||
|           // this.cal_angle(shuizhi_line_id, xiebian_line_id, 3) | ||||
|  | ||||
|           // this.ids.push(shuiping_line_id) | ||||
|           // this.ids.push(shuizhi_line_id) | ||||
|           // this.ids.push(xiebian_line_id) | ||||
|         } | ||||
|  | ||||
|         this.ids.push(this.create_point(car)) | ||||
|         this.tip.setPosition(car, movement.position.x, movement.position.y) | ||||
|         // // 隐藏斜边文字 | ||||
|         // let xiebian = this.id_map.get(xiebian_line_id) | ||||
|         // let xbEntity = this.viewer.entities.getById(xiebian_line_id) | ||||
|         // if(xbEntity) { | ||||
|         //   xbEntity.label.show = false | ||||
|         // } | ||||
|         if (xiebian_line_positions.length) { | ||||
|           // xiebian.positions = xiebian_line_positions.concat(car) | ||||
|           let p = this.cartesian3Towgs84(car, this.viewer) | ||||
|           let shuzhi = this.id_map.get(shuizhi_line_id) | ||||
|           let shuiping = this.id_map.get(shuiping_line_id) | ||||
|           if (p.alt < first_point.alt) { | ||||
|             shuzhi.positions[0] = car | ||||
|             shuzhi.positions[1] = Cesium.Cartesian3.fromDegrees(p.lng, p.lat, first_point.alt) | ||||
|             shuiping.positions[0] = Cesium.Cartesian3.fromDegrees(p.lng, p.lat, first_point.alt) | ||||
|             shuiping.positions[1] = Cesium.Cartesian3.fromDegrees(first_point.lng, first_point.lat, first_point.alt) | ||||
|  | ||||
|           } else { | ||||
|             shuzhi.positions[0] = Cesium.Cartesian3.fromDegrees(first_point.lng, first_point.lat, p.alt) | ||||
|             shuzhi.positions[1] = car | ||||
|  | ||||
|             shuiping.positions[0] = Cesium.Cartesian3.fromDegrees(first_point.lng, first_point.lat, p.alt) | ||||
|             shuiping.positions[1] = Cesium.Cartesian3.fromDegrees(first_point.lng, first_point.lat, first_point.alt) | ||||
|  | ||||
|           } | ||||
|           // shuizhi.positions = shuizhi_positions | ||||
|         } | ||||
|         if (xiebian_line_positions.length === 2) { | ||||
|           this.end() | ||||
|         } | ||||
|       } | ||||
|       this.event.mouse_left(leftEvent) | ||||
|       this.event.mouse_move((movement, car) => { | ||||
|         this.tip.setPosition(car, movement.endPosition.x, movement.endPosition.y) | ||||
|         let xiebian = this.id_map.get(xiebian_line_id) | ||||
|  | ||||
|         if (xiebian_line_positions.length) { | ||||
|           xiebian.positions = xiebian_line_positions.concat(car) | ||||
|           let p = this.cartesian3Towgs84(car, this.viewer) | ||||
|           let shuzhi = this.id_map.get(shuizhi_line_id) | ||||
|           let shuiping = this.id_map.get(shuiping_line_id) | ||||
|           if (p.alt < first_point.alt) { | ||||
|             shuzhi.positions[0] = car | ||||
|             shuzhi.positions[1] = Cesium.Cartesian3.fromDegrees(p.lng, p.lat, first_point.alt) | ||||
|             shuiping.positions[0] = Cesium.Cartesian3.fromDegrees(p.lng, p.lat, first_point.alt) | ||||
|             shuiping.positions[1] = Cesium.Cartesian3.fromDegrees(first_point.lng, first_point.lat, first_point.alt) | ||||
|  | ||||
|           } else { | ||||
|             shuzhi.positions[0] = Cesium.Cartesian3.fromDegrees(first_point.lng, first_point.lat, p.alt) | ||||
|             shuzhi.positions[1] = car | ||||
|  | ||||
|             shuiping.positions[0] = Cesium.Cartesian3.fromDegrees(first_point.lng, first_point.lat, p.alt) | ||||
|             shuiping.positions[1] = Cesium.Cartesian3.fromDegrees(first_point.lng, first_point.lat, first_point.alt) | ||||
|  | ||||
|           } | ||||
|           // shuizhi.positions = shuizhi_positions | ||||
|         } | ||||
|       }) | ||||
|       this.event.mouse_right((movement, car) => { | ||||
|         this.end() | ||||
|       }) | ||||
|       this.event.gesture_pinck_start((movement, cartesian) => { | ||||
|         let startTime = new Date() | ||||
|         let pos = { | ||||
|           position: { | ||||
|             x: (movement.position1.x + movement.position2.x) / 2, | ||||
|             y: (movement.position1.y + movement.position2.y) / 2 | ||||
|           } | ||||
|         } | ||||
|         this.event.gesture_pinck_end(() => { | ||||
|           let endTime = new Date() | ||||
|           if (endTime - startTime >= 500) { | ||||
|             // 长按取消 | ||||
|             this.end() | ||||
|           } | ||||
|           else { | ||||
|             leftEvent(pos, cartesian) | ||||
|           } | ||||
|         }) | ||||
|       }) | ||||
|     } | ||||
|  | ||||
|   } | ||||
|  | ||||
|   /** | ||||
|    * 结束测量 | ||||
|    */ | ||||
|   end() { | ||||
|     super.end(); | ||||
|   } | ||||
|  | ||||
|   /** | ||||
|    * 清除测量 | ||||
|    */ | ||||
|   destroy() { | ||||
|     super.destroy() | ||||
|   } | ||||
|  | ||||
| } | ||||
|  | ||||
| export default MeasureTriangle | ||||
							
								
								
									
										197
									
								
								src/Measure/MeasureTyArea/index.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										197
									
								
								src/Measure/MeasureTyArea/index.js
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,197 @@ | ||||
| /** | ||||
|  * @name: index | ||||
|  * @author: Administrator | ||||
|  * @date: 2022-07-11 17:28 | ||||
|  * @description:index | ||||
|  * @update: 2022-07-11 17:28 | ||||
|  */ | ||||
| import Measure from "../index" | ||||
|  | ||||
| /**@extends Measure*/ | ||||
| class MeasureTyArea extends Measure { | ||||
|   /** | ||||
|    * @constructor | ||||
|    * @param sdk  | ||||
|    * @description 投影面积测量 | ||||
|    * */ | ||||
|   constructor(sdk, options = {}) { | ||||
|     super(sdk, options); | ||||
|     this.options.lineColor = '#ffdf53' | ||||
|     this.polygon_id = "" | ||||
|   } | ||||
|  | ||||
|   static create_polygon(that) { | ||||
|     let id = that.randomString() | ||||
|  | ||||
|     let scaleByDistance = new Cesium.NearFarScalar(2000, 1, 100000, 0) | ||||
|  | ||||
|     let e = that.viewer.entities.add( | ||||
|       new Cesium.Entity({ | ||||
|         id: id, | ||||
|         label: { | ||||
|           text: new Cesium.CallbackProperty(() => { | ||||
|             return that.text | ||||
|           }, false), | ||||
|           //标注文字描述 | ||||
|           font: '20px Microsoft YaHei', | ||||
|           fillColor: Cesium.Color.fromCssColorString('#ffffff'), | ||||
|           style: Cesium.LabelStyle.FILL_AND_OUTLINE, | ||||
|           //标注的遮挡距离设置为100则视角与标注的距离大于100米时会有遮挡 | ||||
|           // distanceDisplayCondition: this.distanceDisplayCondition, | ||||
|  | ||||
|           disableDepthTestDistance: Number.POSITIVE_INFINITY, | ||||
|  | ||||
|           // scaleByDistance, | ||||
|           scale: 1, | ||||
|           horizontalOrigin: Cesium.HorizontalOrigin.CENTER, | ||||
|           verticalOrigin: Cesium.VerticalOrigin.BOTTOM, | ||||
|         }, | ||||
|         position: new Cesium.CallbackProperty(() => { | ||||
|           return that.center | ||||
|         }, false), | ||||
|         polygon: { | ||||
|           classificationType: Cesium.ClassificationType.BOTH, | ||||
|           hierarchy: new Cesium.CallbackProperty((e) => { | ||||
|             return new Cesium.PolygonHierarchy(that.positions) | ||||
|           }, false), | ||||
|           material: new Cesium.Color.fromCssColorString(that.options.color || that.defaultColor), | ||||
|           zIndex: 99999999 | ||||
|         }, | ||||
|         polyline: { | ||||
|           positions: new Cesium.CallbackProperty(() => { | ||||
|             if (that.positions.length) | ||||
|               return that.positions.concat(that.positions[0]) | ||||
|             return that.positions | ||||
|           }, false), | ||||
|           width: 2, | ||||
|           material: new Cesium.PolylineDashMaterialProperty({ | ||||
|             color: new Cesium.Color.fromCssColorString(that.options.lineColor || that.defaultColor), | ||||
|             dashLength: 20, //短划线长度 | ||||
|           }), | ||||
|           clampToGround: true, | ||||
|           zIndex: 99999999 | ||||
|         } | ||||
|       }) | ||||
|     ) | ||||
|     return id | ||||
|   } | ||||
|  | ||||
|   /** | ||||
|    * 开始测量 | ||||
|    */ | ||||
|   start() { | ||||
|     if (!YJ.Measure.GetMeasureStatus()) { | ||||
|       super.start() | ||||
|       this.ids = [] | ||||
|       this.positions = [] | ||||
|       this.text = "" | ||||
|       this.center = new Cesium.Cartesian3() | ||||
|       this.cachePositions = [] | ||||
|       let height = 0 | ||||
|       let lastArea = 0 | ||||
|       let lastcneter | ||||
|  | ||||
|       let leftEvent = (movement, car) => { | ||||
|         if (this.ids.length === 0) { | ||||
|           this.polygon_id = MeasureTyArea.create_polygon(this) | ||||
|         } | ||||
|         this.cachePositions.push({ ...car }) | ||||
|         this.ids.push(this.create_point({ ...car }, false)) | ||||
|         let po = this.cartesian3Towgs84({ ...car }, this.viewer) | ||||
|         if (po.alt > height) { | ||||
|           height = po.alt | ||||
|         } | ||||
|  | ||||
|         this.positions = this.cachePositions.concat({ ...car }) | ||||
|         this.tip.setPosition({ ...car }, movement.position.x, movement.position.y) | ||||
|         if (this.positions.length > 2) { | ||||
|           let arr = [] | ||||
|           this.positions.forEach(item => { | ||||
|             let p = this.cartesian3Towgs84(item, this.viewer) | ||||
|             arr.push({ lng: p.lng, lat: p.lat }) | ||||
|           }) | ||||
|           let center = this.computeCenter(arr) | ||||
|           let area = this.computeArea(arr) | ||||
|           lastArea = area | ||||
|           this.center = new Cesium.Cartesian3.fromDegrees(center.lng, center.lat, height) | ||||
|           lastcneter = this.center | ||||
|           this.text = "投影面积:" + area + " ㎡" | ||||
|         } | ||||
|       } | ||||
|       this.event.mouse_left(leftEvent) | ||||
|       this.event.mouse_move((movement, car) => { | ||||
|         this.tip.setPosition({ ...car }, movement.endPosition.x, movement.endPosition.y) | ||||
|         this.positions = this.cachePositions.concat({ ...car }) | ||||
|         if (this.positions.length > 2) { | ||||
|           let arr = [] | ||||
|           this.positions.forEach(item => { | ||||
|             let p = this.cartesian3Towgs84(item, this.viewer) | ||||
|             arr.push({ lng: p.lng, lat: p.lat }) | ||||
|           }) | ||||
|           let center = this.computeCenter(arr) | ||||
|           let area = this.computeArea(arr) | ||||
|           this.center = new Cesium.Cartesian3.fromDegrees(center.lng, center.lat, height) | ||||
|           this.text = "投影面积:" + area + " ㎡" | ||||
|         } | ||||
|       }) | ||||
|       this.event.mouse_right((movement, car) => { | ||||
|         this.positions = this.cachePositions | ||||
|         this.center = lastcneter | ||||
|         if (this.positions.length < 3) { | ||||
|           this.text = "" | ||||
|           let error = '面积计算至少需要三个坐标!' | ||||
|           console.warn(error) | ||||
|           window.ELEMENT && window.ELEMENT.Message({ | ||||
|             message: error, | ||||
|             type: 'warning', | ||||
|             duration: 1500 | ||||
|           }); | ||||
|           this.destroy() | ||||
|         } | ||||
|         else { | ||||
|           this.text = "投影面积:" + lastArea + " ㎡" | ||||
|         } | ||||
|         this.end() | ||||
|       }) | ||||
|       this.event.gesture_pinck_start((movement, cartesian) => { | ||||
|         let startTime = new Date() | ||||
|         let pos = { | ||||
|           position: { | ||||
|             x: (movement.position1.x + movement.position2.x) / 2, | ||||
|             y: (movement.position1.y + movement.position2.y) / 2 | ||||
|           } | ||||
|         } | ||||
|         this.event.gesture_pinck_end(() => { | ||||
|           let endTime = new Date() | ||||
|           if (endTime - startTime >= 500) { | ||||
|             // 长按取消 | ||||
|             this.positions = this.cachePositions | ||||
|             this.end() | ||||
|           } | ||||
|           else { | ||||
|             leftEvent(pos, cartesian) | ||||
|           } | ||||
|         }) | ||||
|       }) | ||||
|     } | ||||
|   } | ||||
|  | ||||
|   /** | ||||
|    * 清除测量 | ||||
|    */ | ||||
|   destroy() { | ||||
|     [this.polygon_id, ...this.ids].forEach(id => { | ||||
|       this.remove_entity(id) | ||||
|     }) | ||||
|     super.destroy() | ||||
|   } | ||||
|  | ||||
|   /** | ||||
|    * 结束测量 | ||||
|    */ | ||||
|   end() { | ||||
|     super.end() | ||||
|   } | ||||
| } | ||||
|  | ||||
| export default MeasureTyArea | ||||
							
								
								
									
										16
									
								
								src/Measure/clear.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										16
									
								
								src/Measure/clear.js
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,16 @@ | ||||
| /** | ||||
|  * @name: clear | ||||
|  * @author: Administrator | ||||
|  * @date: 2022-07-11 15:28 | ||||
|  * @description:clear | ||||
|  * @update: 2022-07-11 15:28 | ||||
|  */ | ||||
|  | ||||
| function Clear() { | ||||
|   YJ.Measure.Measures.forEach(m => { | ||||
|     m.destroy() | ||||
|   }) | ||||
|   YJ.Measure.Measures = [] | ||||
| } | ||||
|  | ||||
| export {Clear} | ||||
							
								
								
									
										80
									
								
								src/Measure/index.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										80
									
								
								src/Measure/index.js
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,80 @@ | ||||
| import MouseEvent from "../Event"; | ||||
| import MouseTip from "../MouseTip"; | ||||
| import Tools from "../Tools"; | ||||
|  | ||||
| /** | ||||
|  * @name: measure | ||||
|  * @author: Administrator | ||||
|  * @date: 2022-07-11 10:52 | ||||
|  * @description:measure | ||||
|  * @update: 2022-07-11 10:52 | ||||
|  */ | ||||
|  | ||||
| class Measure extends Tools { | ||||
|   constructor(sdk, options = {text: "左键开始,右键结束;"}) { | ||||
|     super(sdk, options) | ||||
|     this.options = {...options} | ||||
|     this.event = new MouseEvent(sdk) | ||||
|     this.tip = new MouseTip(options.text, sdk) | ||||
|     this.viewer = sdk.viewer | ||||
|     this.defaultColor = 'rgba(246,49,49,0.55)' | ||||
|     this.ids = [] | ||||
|     YJ.Measure.Measures.push(this) | ||||
|     this._isDestroy = false | ||||
|     // this.pickStatus = {pick: YJ.getEarth().interaction.picking.enabled} | ||||
|   } | ||||
|  | ||||
|   start() { | ||||
|     this.setPickStatus(false) | ||||
|     YJ.Measure.SetMeasureStatus(true) | ||||
|   } | ||||
|  | ||||
|   destroy() { | ||||
|     // YJ.Measure.Measures.pop() | ||||
|     this._isDestroy = true | ||||
|     this.end() | ||||
|     this.ids.forEach(id => { | ||||
|       this.remove_entity(id) | ||||
|     }) | ||||
|   } | ||||
|  | ||||
|  | ||||
|   end() { | ||||
|     // this.ids.forEach(id => { | ||||
|     //   this.remove_entity(id) | ||||
|     // }) | ||||
|     //还原上一次的状态 | ||||
|     // this.setPickStatus(this.pickStatus.pick) | ||||
|     YJ.Measure.SetMeasureStatus(false) | ||||
|     this.tip && this.tip.destroy() | ||||
|     this.event && this.event.destroy() | ||||
|     this.tip = null | ||||
|     this.event = null | ||||
|   } | ||||
|  | ||||
|   create_point(cartesian,show = true) { | ||||
|     let id = this.randomString() | ||||
|     let p = this.cartesian3Towgs84(cartesian, this.viewer) | ||||
|     this.viewer.entities.add( | ||||
|       new Cesium.Entity({ | ||||
|         id: id, | ||||
|         position: Cesium.Cartesian3.fromDegrees(p.lng, p.lat, p.alt), | ||||
|         billboard: { | ||||
|           show: show, | ||||
|           image: this.getSourceRootPath() + '/img/point.png', | ||||
|           verticalOrigin: Cesium.VerticalOrigin.BOTTOM, | ||||
|           disableDepthTestDistance: Number.POSITIVE_INFINITY, | ||||
|           color: Cesium.Color.WHITE.withAlpha(0.99) | ||||
|         } | ||||
|       }) | ||||
|     ) | ||||
|     return id | ||||
|   } | ||||
|  | ||||
|   remove_entity(id) { | ||||
|     this.viewer.entities.removeById(id) | ||||
|   } | ||||
| } | ||||
|  | ||||
|  | ||||
| export default Measure | ||||
		Reference in New Issue
	
	Block a user