import * as turf from "@turf/turf"; const msgList = { label: null, circle: undefined, line: [], startLine: [], backLine: [], point: null, removeLabel() { if (this.label) { this.label.removeFromMap(); this.label = null; } if (this.circle) { this.circle.removeFromMap(); this.circle = undefined; } if (this.pathLine) { Viewer.entities.remove(this.pathLine); this.pathLine = null; } this.startLine = []; this.line = []; this.backLine = []; }, setInit(item) { const point = item.point.split(','); this.point = point; this.label = earthCtrl.factory.createLabel({ lon: point[0], lat: point[1], alt: 40, text: item.msg, image: config.sdkImg + 'Workers/image/mark.png', // 文本偏移量 pixelOffset: new SmartEarth.Cesium.Cartesian2(0, -50), // 图片偏移量 iPixelOffset: new SmartEarth.Cesium.Cartesian2(0, -20), }); this.showCircle(point, '#ff0000'); if (!item.geom.line) return; this.line = this.chunkArray(item.geom.line, 2); var center_Coord = []; for (var i = 0; i < this.line.length; i++) { center_Coord.push(turf.point([this.line[i][0], this.line[i][1]])); var coord_start =this.getCartesianCoord(this.line[i][0], this.line[i][1], 1); this.startLine.push(coord_start); } var features = turf.featureCollection(center_Coord); var center = turf.center(features).geometry.coordinates; earthCtrl.camera.flyTo(center[0], center[1], 8000, 0, -90, 0, 0); var backGeom = this.line.reverse(); for (var i = 0; i < backGeom.length; i++) { var coord_back =this.getCartesianCoord(backGeom[i][0], backGeom[i][1], 1); this.backLine.push(coord_back); } // this.$nextTick(() => { this.showPathLine(this.startLine, true); // }); }, getCartesianCoord(longitude, latitude, height) { return Cesium.Cartesian3.fromDegrees(longitude, latitude, height); }, showCircle(res, color) { if (this.circle) { this.circle.removeFromMap(); this.circle = undefined; } this.circle = earthCtrl.factory.createCircleScan({ lon: res[0], lat: res[1], color: SmartEarth.Cesium.Color.fromCssColorString(color), height: 1, maxRadius: 100, duration: 5000, }); }, chunkArray(array, size) { return array.reduce((chunks, current, index) => { const chunkIndex = Math.floor(index / size); if (!chunks[chunkIndex]) { chunks[chunkIndex] = []; } chunks[chunkIndex].push(current); return chunks; }, []); }, showPathLine(degreesArr, boolen) { this.pathLine = Viewer.entities.add({ polyline: { clampToGround: true, //轨迹线的分布位置 positions: degreesArr, material: new Cesium.ImageMaterialProperty({ //图片的颜色 //轨迹运行的速率 speed: 10, //随意一张图片 image: config.images + '向右.png', //将轨迹分成一行50个图片 repeat: { x: 40, y: 1 }, }), width: 20, }, }); }, }; export default msgList;