| | |
| | | this.waypoints = await this.parseKMZ(arrayBuffer); |
| | | //å ç¹é»è¾ æ¯å¦å第2-n-1䏿å
¥å
ç´ ç»çº¬åº¦ä¸ºå½åç heading pitch roll ä¸ä¸ä¸ªç |
| | | const dealArr = []; |
| | | // console.log(">> this.waypoints:", this.waypoints); |
| | | console.log(">> this.waypoints:", this.waypoints); |
| | | for (let i = 0; i < this.waypoints.length - 1; i++) { |
| | | dealArr.push(this.waypoints[i]); // Push the current element |
| | | const current = this.waypoints[i]; |
| | | const next = this.waypoints[i + 1]; |
| | | dealArr.push({ |
| | | "lng": current.lng, |
| | | "lat": current.lat, |
| | | "alt": current.alt, |
| | | 'flyHeading':current.flyHeading, |
| | | "heading": current.heading, |
| | | "pitch": current.pitch, |
| | | "roll": current.roll, |
| | | "zoom":current.zoom || 1, |
| | | 'wait' : 5 |
| | | }); |
| | | dealArr.push({ |
| | | "lng": next.lng, |
| | | "lat": next.lat, |
| | |
| | | "heading": current.heading, |
| | | "pitch": current.pitch, |
| | | "roll": current.roll, |
| | | "zoom":next.zoom || 1 |
| | | "zoom":current.zoom || 1, |
| | | 'wait':1 |
| | | }); |
| | | |
| | | } |
| | | |
| | | // Push the last element without any change |
| | | dealArr.push(this.waypoints[this.waypoints.length - 1]); |
| | | this.waypoints = dealArr |
| | | console.log(dealArr) |
| | | this.fileInfo = ` |
| | | èªç¹:${this.waypoints.length}个 <br/> |
| | | è·ç¦»:${this.calculateTotalDistance(this.waypoints).toFixed(2)}å
Ž |
| | |
| | | } |
| | | // const startDate = new Date("2025-04-01T13:00:00Z"); |
| | | const startDate = new Date(date.toISOString()); |
| | | console.log(dealArr) |
| | | let nowTime |
| | | const result = dealArr.map((item, index) => { |
| | | console.log(index) |
| | | // const result = this.waypoints.map((item, index) => { |
| | | // æ¯æ¬¡å ä¸å¤© |
| | | const time = new Date(startDate.getTime() + index * 60 * 1000).toISOString(); |
| | | // const time = new Date(startDate.getTime() + index * 60 *1000 + (item.wait ? item.wait :1 ) * 60 * 1000).toISOString(); |
| | | if(index == 0) { |
| | | nowTime = startDate.getTime() + 1 *1000 |
| | | }else{ |
| | | nowTime = nowTime + (item.wait ? item.wait :1 ) *1000 |
| | | } |
| | | const time = new Date(nowTime).toISOString() |
| | | // const time = Cesium.JulianDate.addSeconds(startDate, 3600, new Cesium.JulianDate()); |
| | | return { |
| | | time, |
| | |
| | | }; |
| | | }); |
| | | this.trajectoryData = result |
| | | // console.log(this.trajectoryData) |
| | | console.log(this.trajectoryData) |
| | | this.loadTimeLine() |
| | | } catch (error) { |
| | | console.error(error); |
| | |
| | | reader.readAsArrayBuffer(file); |
| | | }); |
| | | }, |
| | | azimuthtwopoi(x1, y1, x2, y2) { |
| | | let result; |
| | | let a = Math.abs(Math.atan((y2 - y1) / (x2 - x1))) * 180 / Math.PI; |
| | | if ((x2 - x1) < 0) { |
| | | if ((y2 - y1) > 0) { |
| | | result = a + 270; |
| | | } else { |
| | | result = 90 - a + 180; |
| | | } |
| | | } else { |
| | | if ((y2 - y1) > 0) { |
| | | result = 90 - a; |
| | | } else { |
| | | result = a + 90; |
| | | } |
| | | } |
| | | return result; |
| | | }, |
| | | dealdDirection(x1, y1, x2, y2){ |
| | | // å®ä¹ç¹1åç¹2çç»çº¬åº¦ï¼åä½ï¼åº¦ï¼ |
| | | const point1 = Cesium.Cartesian3.fromDegrees(x1,y1); // ä¾å¦ï¼ç¹1çç»çº¬åº¦ |
| | | const point2 = Cesium.Cartesian3.fromDegrees(x2, y2); // ä¾å¦ï¼ç¹2çç»çº¬åº¦ |
| | | |
| | | // è®¡ç®æ¹ååé |
| | | const direction = Cesium.Cartesian3.subtract(point2, point1, new Cesium.Cartesian3()); |
| | | |
| | | // å½ä¸åæ¹ååé |
| | | Cesium.Cartesian3.normalize(direction, direction); |
| | | |
| | | // 计ç®èªåãä¿¯ä»°åæ»è½¬è§ |
| | | const headingPitchRoll = Cesium.HeadingPitchRoll.fromCartesian3(direction); |
| | | |
| | | // æ¾ç¤ºç»æ |
| | | console.log('Heading:', Cesium.Math.toDegrees(headingPitchRoll.heading)); |
| | | console.log('Pitch:', Cesium.Math.toDegrees(headingPitchRoll.pitch)); |
| | | console.log('Roll:', Cesium.Math.toDegrees(headingPitchRoll.roll)); |
| | | }, |
| | | Bearing(from, to){ |
| | | from = Cesium.Cartographic.fromCartesian(from) |
| | | to = Cesium.Cartographic.fromCartesian(to) |
| | | |
| | | let lat1 = from.latitude |
| | | let lon1 = from.longitude |
| | | let lat2 = to.latitude |
| | | let lon2 = to.longitude |
| | | let angle = -Math.atan2(Math.sin(lon1 - lon2) * Math.cos(lat2), Math.cos(lat1) * Math.sin(lat2) - Math.sin(lat1) * Math.cos(lat2) * Math.cos(lon1 - lon2)) |
| | | if (angle < 0) { |
| | | angle += Math.PI * 2.0 |
| | | } |
| | | let degreesPerRadian = 180.0 / Math.PI // 弧度转å为è§åº¦ |
| | | |
| | | angle = angle * degreesPerRadian // è§åº¦ |
| | | return angle |
| | | }, |
| | | // è§£æKMZæä»¶ |
| | | async parseKMZ(kmzData) { |
| | | |
| | | // â ï¸ è¿éç´æ¥ä½¿ç¨å
¨å± JSZip å xml2jsï¼éè¿CDNå¼å
¥ï¼ |
| | | const zip = await JSZip.loadAsync(kmzData); |
| | | const kmlFile = Object.keys(zip.files).find(name => |
| | |
| | | result.kml.Document[0].Folder[0].Placemark || []; |
| | | const points = []; |
| | | var lastZoom =1 |
| | | placemarks.forEach(placemark => { |
| | | const coords = placemark.Point?.[0]?.coordinates?.[0]; |
| | | const height = placemark["wpml:height"]?.[0]; |
| | | let lastHeading = 0 |
| | | for(let i=0;i<placemarks.length;i++){ |
| | | const coords = placemarks[i].Point?.[0]?.coordinates?.[0]; |
| | | const height = placemarks[i]["wpml:height"]?.[0]; |
| | | if(i<placemarks.length-1){ |
| | | // console.log(placemarks[i]) |
| | | // console.log( placemarks[i].Point?.[0]?.coordinates?.[0].split(',')[0]) |
| | | // console.log( placemarks[i].Point?.[0]?.coordinates?.[0].split(',')[1]) |
| | | // console.log( placemarks[i+1].Point?.[0]?.coordinates?.[0].split(',')[0]) |
| | | // console.log( placemarks[i+1].Point?.[0]?.coordinates?.[0].split(',')[1]) |
| | | let lon1 = placemarks[i].Point?.[0]?.coordinates?.[0].split(',')[0] |
| | | let lat1 = placemarks[i].Point?.[0]?.coordinates?.[0].split(',')[1] |
| | | let lon2 = placemarks[i+1].Point?.[0]?.coordinates?.[0].split(',')[0] |
| | | let lat2 = placemarks[i+1].Point?.[0]?.coordinates?.[0].split(',')[1] |
| | | // console.log(this.azimuthtwopoi(lon1,lat1,lon2,lat2)) |
| | | // lastHeading = this.azimuthtwopoi(lon1,lat1,lon2,lat2) |
| | | var nowHeading = this.azimuthtwopoi(lon1,lat1,lon2,lat2) |
| | | if(!nowHeading){ |
| | | nowHeading = lastHeading |
| | | }else { |
| | | let p1 = {"lng": lon1, "lat": lat1, "alt": height}; |
| | | |
| | | let p2 = {"lng": lon2, "lat": lat2, "alt": height}; |
| | | |
| | | let c1 = Cesium.Cartesian3.fromDegrees(p1.lng,p1.lat,p1.height); |
| | | let c2 = Cesium.Cartesian3.fromDegrees(p2.lng,p2.lat,p2.height); |
| | | lastHeading = this.Bearing(c1, c2); |
| | | // lastHeading = this.azimuthtwopoi(lon1,lat1,lon2,lat2) |
| | | } |
| | | |
| | | // console.log(lastHeading) |
| | | // console.log('+++++++++++++++++++++++++') |
| | | } |
| | | // æå aircraftHeading |
| | | // æå action éçåæ° |
| | | // åå§å Pitch, Roll å Heading |
| | |
| | | let totalRoll = 0; |
| | | let totalHeading = 0; |
| | | let flyHeadingData = 0; |
| | | if (placemark["wpml:actionGroup"]?.[0]?.["wpml:action"]) { |
| | | placemark["wpml:actionGroup"][0]["wpml:action"].forEach(action => { |
| | | if (placemarks[i]["wpml:actionGroup"]?.[0]?.["wpml:action"]) { |
| | | placemarks[i]["wpml:actionGroup"][0]["wpml:action"].forEach(action => { |
| | | // å¤ç gimbalRotate å rotateYaw 彿° |
| | | if (action['wpml:actionActuatorFunc'].includes("gimbalRotate")) { |
| | | // è·åæ¯ä¸ªè§åº¦å¼ |
| | | const gimbalPitch = parseFloat(action['wpml:actionActuatorFuncParam'][0]["wpml:gimbalPitchRotateAngle"][0]); |
| | | const gimbalRoll = parseFloat(action['wpml:actionActuatorFuncParam'][0]["wpml:gimbalRollRotateAngle"][0]); |
| | | const gimbalYaw = parseFloat(action['wpml:actionActuatorFuncParam'][0]["wpml:gimbalYawRotateAngle"][0]); |
| | | |
| | | if(gimbalYaw < 0 ){ |
| | | gimbalYaw += 360 |
| | | } |
| | | // ç´¯å Pitch, Roll å Heading |
| | | totalPitch += gimbalPitch; |
| | | totalRoll += gimbalRoll; |
| | | totalHeading += gimbalYaw; |
| | | // totalHeading += gimbalYaw; |
| | | |
| | | } |
| | | // å¤ç rotateYaw 彿° |
| | | if (action['wpml:actionActuatorFunc'].includes("rotateYaw")) { |
| | | // è·å aircraftHeading |
| | | const aircraftHeading = parseFloat(action['wpml:actionActuatorFuncParam'][0]["wpml:aircraftHeading"][0]); |
| | | var aircraftHeading = parseFloat(action['wpml:actionActuatorFuncParam'][0]["wpml:aircraftHeading"][0]); |
| | | |
| | | if(aircraftHeading <0) { |
| | | aircraftHeading+=360 |
| | | } |
| | | flyHeadingData = aircraftHeading |
| | | // å° aircraftHeading ç´¯å å° totalHeading |
| | | totalHeading += aircraftHeading; |
| | |
| | | if (coords) { |
| | | coords.trim().split(" ").forEach(coord => { |
| | | const [lng, lat] = coord.split(",").map(Number); |
| | | points.push({ lng, lat, alt: height,heading:totalHeading || 0,pitch:totalPitch || 0,roll:totalRoll|| 0 ,flyHeading:flyHeadingData,zoom :lastZoom}); |
| | | points.push({ lng, lat, alt: height,heading:totalHeading ?totalHeading:lastHeading ,pitch:totalPitch || 0,roll:totalRoll|| 0 ,flyHeading:flyHeadingData,zoom :lastZoom}); |
| | | }); |
| | | } |
| | | }); |
| | | |
| | | } |
| | | console.log(points) |
| | | if (points.length === 0) throw new Error("æªæ¾å°ææèªç¹"); |
| | | return points; |
| | | }, |
| | |
| | | const holderYtHeading = this.holderHeadingProperty.getValue(currentTime) |
| | | const holderYtPitch = this.holderPitchProperty.getValue(currentTime) |
| | | const holderYtRoll = this.holderRollProperty.getValue(currentTime) |
| | | console.log(holderYtHeading) |
| | | if(holderYtHeading) { |
| | | this.heading = holderYtHeading |
| | | this.pitch = holderYtPitch |