diff --git a/src/assets/images/big_bg.png b/src/assets/images/big_bg.png new file mode 100644 index 0000000..abb42be Binary files /dev/null and b/src/assets/images/big_bg.png differ diff --git a/src/assets/images/carMarker.png b/src/assets/images/carMarker.png new file mode 100644 index 0000000..343f8d5 Binary files /dev/null and b/src/assets/images/carMarker.png differ diff --git a/src/assets/images/营运线路-active.png b/src/assets/images/carType1-s.png similarity index 100% rename from src/assets/images/营运线路-active.png rename to src/assets/images/carType1-s.png diff --git a/src/assets/images/carType1.png b/src/assets/images/carType1.png new file mode 100644 index 0000000..326ff53 Binary files /dev/null and b/src/assets/images/carType1.png differ diff --git a/src/assets/images/carType2-s.png b/src/assets/images/carType2-s.png new file mode 100644 index 0000000..3f93f8a Binary files /dev/null and b/src/assets/images/carType2-s.png differ diff --git a/src/assets/images/carType2.png b/src/assets/images/carType2.png new file mode 100644 index 0000000..c63cd63 Binary files /dev/null and b/src/assets/images/carType2.png differ diff --git a/src/assets/images/carType3-s.png b/src/assets/images/carType3-s.png new file mode 100644 index 0000000..4695fb0 Binary files /dev/null and b/src/assets/images/carType3-s.png differ diff --git a/src/assets/images/carType3.png b/src/assets/images/carType3.png new file mode 100644 index 0000000..d301124 Binary files /dev/null and b/src/assets/images/carType3.png differ diff --git a/src/assets/images/dialog.jpg b/src/assets/images/dialog.jpg deleted file mode 100644 index a48ba8b..0000000 Binary files a/src/assets/images/dialog.jpg and /dev/null differ diff --git a/src/assets/images/dialog.png b/src/assets/images/dialog.png new file mode 100644 index 0000000..db85d92 Binary files /dev/null and b/src/assets/images/dialog.png differ diff --git a/src/assets/images/diy-popup.png b/src/assets/images/diy-popup.png index 3876474..5e5bf2c 100644 Binary files a/src/assets/images/diy-popup.png and b/src/assets/images/diy-popup.png differ diff --git a/src/assets/images/island.png b/src/assets/images/island.png new file mode 100644 index 0000000..40c62ad Binary files /dev/null and b/src/assets/images/island.png differ diff --git a/src/assets/images/linePoint2.png b/src/assets/images/linePoint2.png index d19c16f..67ff233 100644 Binary files a/src/assets/images/linePoint2.png and b/src/assets/images/linePoint2.png differ diff --git a/src/assets/images/origin.png b/src/assets/images/origin.png new file mode 100644 index 0000000..ec83f50 Binary files /dev/null and b/src/assets/images/origin.png differ diff --git a/src/assets/images/pointer.png b/src/assets/images/pointer.png new file mode 100644 index 0000000..122804d Binary files /dev/null and b/src/assets/images/pointer.png differ diff --git a/src/assets/images/临时任务-选中.png b/src/assets/images/临时任务-选中.png new file mode 100644 index 0000000..7d70f50 Binary files /dev/null and b/src/assets/images/临时任务-选中.png differ diff --git a/src/assets/images/临时任务.png b/src/assets/images/临时任务.png index d301124..8c8def1 100644 Binary files a/src/assets/images/临时任务.png and b/src/assets/images/临时任务.png differ diff --git a/src/assets/images/维护线路.png b/src/assets/images/维护线路.png index c63cd63..f0556da 100644 Binary files a/src/assets/images/维护线路.png and b/src/assets/images/维护线路.png differ diff --git a/src/assets/images/营运线路.png b/src/assets/images/营运线路.png index 326ff53..3a6ddae 100644 Binary files a/src/assets/images/营运线路.png and b/src/assets/images/营运线路.png differ diff --git a/src/assets/styles/map.scss b/src/assets/styles/map.scss index ece7643..76b10ff 100644 --- a/src/assets/styles/map.scss +++ b/src/assets/styles/map.scss @@ -14,19 +14,20 @@ text-align: center; } .mars-four-color { - width: 84px; + width: 100px; position: relative; - top: -68px; - left: -40px; + top: -60px; + left: -50px; cursor: pointer; } .four-color_name { width: 100%; - height: 80px; - line-height: 30px; + height: 100px; + line-height: 37px; background: url("../images/areaName.png"); background-size: 100% 100%; - font-size: 14px; + font-size: 16px; + font-weight: bold; color: #fff250; text-align: center; text-shadow: 0px 0px 2px rgba(0, 0, 0, 0.5); @@ -34,7 +35,7 @@ .mars3d-animation { position: relative; - animation: moveUpDown 1s linear infinite alternate; + // animation: moveUpDown 1s linear infinite alternate; } @keyframes moveUpDown { @@ -49,33 +50,35 @@ .screen-list { position: absolute; top: 0; - right: -195px; + right: -240px; // transform: translateY(50%); min-width: 60px; - opacity: 0; + & > div { + display: none; + } .lable-value { - height: 35px; - width: 190px; + height: 41px; + width: 234px; background: url("../images/screen-list.png"); background-size: 100% 100%; margin-bottom: 3px; display: flex; align-items: center; - padding: 0 4px; + padding: 0 6px; .lable-data { width: 50%; - font-size: 14px; + font-size: 16px; color: #612500; font-weight: bold; } .value-data { flex: 1; text-align: center; - font-size: 18px; + font-size: 20px; color: #f7c75d; font-family: "DIN-Regular-2"; span { - font-size: 14px; + font-size: 16px; color: #ffffff; } } @@ -110,7 +113,7 @@ .video-dialog { background-color: transparent; - width: 833px; + width: 750px; height: 482px; .el-dialog__header { padding: 0; @@ -118,7 +121,7 @@ .el-dialog__body { height: 100%; padding: 15px 10px; - background: url("../images/dialog.jpg"); + background: url("../images/dialog.png"); background-size: 100% 100%; } .el-dialog__headerbtn { @@ -149,12 +152,23 @@ } .diy-popup { + position: relative; height: 430px; width: 260px; background: url("../images/diy-popup.png"); background-size: 100% 100%; padding: 20px 25px; - overflow-y: auto; + // overflow-y: auto; + .pointer { + position: absolute; + left: -145px; + top: 50%; + transform: translateY(-50%); + width: 145px; + height: 207px; + background: url("../images/pointer.png"); + background-size: cover; + } .popup-title { font-size: 18px; color: #ffffff; @@ -194,3 +208,38 @@ } } } +.mars3d-popup-content { + overflow-y: visible; +} +//车辆实时定位弹窗 + +.car-page-popup { + .mars3d-popup-tip-container { + opacity: 0; + } + .mars3d-popup-background { + background: transparent; + box-shadow: 0 0px 0px transparent; + padding: 0; + text-align: left; + border-radius: 0; + } + + .carPlate { + position: relative; + background: #00162d; + border-radius: 4px; + border: 1px solid #008cff; + padding: 2px 10px; + font-size: 14px; + padding-left: 30px; + .carType { + position: absolute; + left: 0; + top: 0; + display: inline-block; + height: 25px; + width: 25px; + } + } +} diff --git a/src/components/grids.vue b/src/components/grids.vue index 8ace3f0..11b29ab 100644 --- a/src/components/grids.vue +++ b/src/components/grids.vue @@ -93,14 +93,14 @@ export default { background-color: #fff; font-size: 14px; - opacity: 0.3; + opacity: 0.5; border: none; outline: none; cursor: pointer; padding: 9px 4px; } .scroll-btn:hover { - opacity: 0.5; + opacity: 0.8; } .left { diff --git a/src/utils/carCanvas.js b/src/utils/carCanvas.js new file mode 100644 index 0000000..893eba9 --- /dev/null +++ b/src/utils/carCanvas.js @@ -0,0 +1,65 @@ +const obj = { + borderWidth: 2, + borderColor: "#006FCB", + backgroundColor: "#00162D", + fontSize: 14, + fontColor: "#FFFFFF", + paddingVertical: 6, + paddingHorizontal: 10, + text: "001号线_01_早送_守押001_苏E", // 这里可以更改为需要绘制的文字 +}; +export function adjustCanvasSize(id) { + const canvas = document.createElement("canvas"); + const ctx = canvas.getContext("2d"); + // 设置文字样式以计算文本宽度 + ctx.font = `${obj.fontSize}px sans-serif`; + + // 计算文本宽度 + const textWidth = ctx.measureText(obj.text).width; + + // 计算画布宽度和高度(加上内边距和边框) + const canvasWidth = textWidth + obj.paddingHorizontal * 2; + const canvasHeight = obj.fontSize + obj.paddingVertical * 2; + + // 设置画布宽度和高度 + canvas.width = canvasWidth; + canvas.height = canvasHeight; + + // 重新绘制矩形和文字 + return drawRectangle(canvas, id, canvasWidth, canvasHeight, textWidth); +} +function drawRectangle(canvas, id, canvasWidth, canvasHeight, textWidth) { + let marker = document.getElementById("carMarker"); + canvas.id = id; + const ctx = canvas.getContext("2d"); + // 清空画布 + ctx.clearRect(0, 0, canvasWidth, canvasHeight); + + // 绘制背景矩形 + ctx.fillStyle = obj.backgroundColor; + ctx.fillRect(0, 0, canvasWidth, canvasHeight); + + // 绘制边框 + ctx.lineWidth = obj.borderWidth; + ctx.strokeStyle = obj.borderColor; + ctx.strokeRect(0.5, 0.5, canvasWidth - 1, canvasHeight - 1); + + // 设置文字样式 + ctx.font = `${obj.fontSize}px sans-serif`; + ctx.fillStyle = obj.fontColor; + + // 计算文字的水平和垂直居中位置 + const textX = (canvasWidth - textWidth) / 2; + const textY = (canvasHeight + obj.fontSize) / 2 - obj.paddingVertical / 2; + // 绘制文字 + ctx.fillText(obj.text, textX, textY); + marker.appendChild(canvas); + return canvas; +} + +export function changeBorderColor(id) { + let canvas = document.getElementById(id); + + console.log(id, canvas); + canvas.style.border = `1px solid #C08700`; +} diff --git a/src/views/canvas.vue b/src/views/canvas.vue new file mode 100644 index 0000000..8133a93 --- /dev/null +++ b/src/views/canvas.vue @@ -0,0 +1,79 @@ + + + + + diff --git a/src/views/car copy.vue b/src/views/car copy.vue new file mode 100644 index 0000000..af1e389 --- /dev/null +++ b/src/views/car copy.vue @@ -0,0 +1,452 @@ + + + + + diff --git a/src/views/car.vue b/src/views/car.vue index 882c4ef..9546466 100644 --- a/src/views/car.vue +++ b/src/views/car.vue @@ -27,6 +27,9 @@ +
+ {{ show3D ? "关闭" : "开启" }}三维 +
{{ item }}
+ + @@ -54,6 +55,8 @@ import MarsMap from "@/components/mars-map"; import { getCarPoint, getCarByCarplate } from "@/api/yunkun/yunkun.js"; +import { adjustCanvasSize, changeBorderColor } from "@/utils/carCanvas.js"; + export default { data() { const basePathUrl = window.basePathUrl || ""; @@ -74,19 +77,13 @@ export default { baseUrl: basePathUrl + "lib/geoJson/tileset.json", carUrl: basePathUrl + "lib/qiche.gltf", map: null, + mapLayer: {}, options: { scene: { - // center: { - // lat: 31.754913, - // lng: 117.248572, - // alt: 6220, - // heading: 357, - // pitch: -31, - // }, center: { - lat: 31.212805, - lng: 120.607156, - alt: 5096.4, + lat: 31.019462, + lng: 120.635502, + alt: 13761.4, heading: 357.9, pitch: -31.5, }, @@ -104,25 +101,12 @@ export default { }, control: { - contextmenu: { preventDefault: false, hasDefault: false }, + // contextmenu: { preventDefault: false, hasDefault: false }, }, - basemaps: [ - // { - // name: "mapbox影像图", - // icon: "img/basemaps/mapboxSatellite.png", - // type: "mapbox", - // username: "sharealex", - // styleId: "cly5i21fn00e901prgq643t4r", - // token: - // "pk.eyJ1Ijoic2hhcmVhbGV4IiwiYSI6ImNsaXNhZmRjbTFhbnczZmxib3h1OW05YXYifQ.PhlKv60ar3K359d8x2yBPw", - // tilesize: 256, - // scaleFactor: false, - // show: false, - // }, - ], }, show: false, showVideo: true, + show3D: false, }; }, components: { MarsMap }, @@ -131,149 +115,212 @@ export default { // 在组件销毁之前移除事件监听,防止内存泄漏 document.removeEventListener("click", this.handleClickOutside); }, + mounted() { // 在mounted钩子中添加全局点击事件监听 document.addEventListener("click", this.handleClickOutside); }, methods: { - /**输入框清除 */ - - inputClear() { - this.map.flyHome(); - if (this.timer) clearInterval(this.timer); - this.searchList = []; - this.searchQuery.carPlate = undefined; - this.carQuery.carIds = undefined; - this.show = false; - this.getCarPoint(); - }, - - /**根据车牌号查询车辆实时定位 */ - async handleSearch() { - if (!this.searchQuery.carPlate) return; - // 清除轮询定时器 - if (this.timer) clearInterval(this.timer); - const result = await getCarByCarplate(this.searchQuery); - this.searchList = result.list; - this.show = true; - }, - - handelLookCar(item) { - this.list = [item]; - this.carQuery.carIds = item.carId; - this.map.flyToPoint( - new mars3d.LngLatPoint(parseFloat(item.lng), parseFloat(item.lat)) - ); - this.createCar("active"); - this.show = false; - }, - /** - * 获取车辆实时定位(可查全部) + * 加载姑苏区三维图层 */ - async getCarPoint() { - this.list = await this.carPoint(); - this.createCar(); + initTilesetLayer() { + if (this.map) { + if (!this.mapLayer.tiles3dLayer) { + this.mapLayer.tiles3dLayer = new mars3d.layer.TilesetLayer({ + name: "姑苏区建筑物", + url: "https://www.jichuanglanhai.com:88/3dtiles/yunkun/tileset.json", + maximumScreenSpaceError: 16, + maximumMemoryUsage: 1024 / 2, + dynamicScreenSpaceError: false, + skipLevelOfDetail: true, + preferLeaves: true, + flyTo: false, + style: { + color: { + conditions: [["true", `color("rgba(42, 160, 224, 1)")`]], + }, + }, + }); + this.map.addLayer(this.mapLayer.tiles3dLayer); + this.show3D = true; + } else { + this.mapLayer.tiles3dLayer.show = !this.mapLayer.tiles3dLayer.show; + this.show3D = !this.show3D; + } + } else { + } }, - - async carPoint() { - let res = await getCarPoint(this.carQuery); - res.list = res.list.filter( - (item) => - item.carPlate.includes("苏E") || - (item.carPlate.includes("苏U") && item.stateCn.includes("在线-行驶")) - ); - return res.list.slice(0, 100); + /**地图渲染完毕 */ + mapLoad(map) { + this.map = map; + map.fixedLight = true; // 固定光照,避免gltf模型随时间存在亮度不一致。 + // 创建矢量图层 + this.mapLayer.car = new mars3d.layer.GraphicLayer(); + this.map.addLayer(this.mapLayer.car); + this.createCar(); }, - - /** - * 创建车辆图标 - */ - createCar(type) { - let _this = this; - this.graphicLayer.clear(); - this.graphicLayer.enabledEvent = false; // 关闭事件,大数据addGraphic时影响加载时间 - // 设置动态位置 - for (let i = 0; i < this.list.length; i++) { - const item = this.list[i]; - let graphic = new mars3d.graphic.ModelPrimitive({ - id: item.carId, + /**创建车辆 */ + createCar() { + let list = [ + { + name: "001号线_01_早送_守押001_苏E", + position: [120.608163, 31.184288, 13.5], + }, + { + name: "002号线_01_维护_守押085_苏E", + position: [120.607528, 31.209201, 11.1], + }, + { + name: "临时任务_考试院_守押072_苏E123", + position: [120.657466, 31.220895, 12.7], + }, + ]; + this.mapLayer.car.clear(); + this.mapLayer.car.enabledEvent = false; // 关闭事件,大数据addGraphic时影响加载时间 + for (let index = 0; index < list.length; index++) { + let item = list[index]; + const graphic = new mars3d.graphic.ModelEntity({ + id: `car${index + 1}`, + position: item.position, style: { url: this.carUrl, - scale: 3, - minimumPixelSize: 20, + scale: 0.5, + minimumPixelSize: 30, silhouette: true, - silhouetteColor: "#0084ff", - silhouetteSize: 2, - pitch: 0, - roll: 0, - label: { - text: item.carPlate, - font_size: 14, - color: "#ffffff", - outline: true, - outlineColor: "#000000", - pixelOffsetY: -30, - visibleDepth: false, - distanceDisplayCondition: true, - distanceDisplayCondition_far: 50000, - distanceDisplayCondition_near: 0, + silhouetteColor: "#008cff", + highlight: { + type: "click", + silhouette: true, + silhouetteColor: "#FFB200", + }, + }, + circle: { + radius: 200, + fill: false, + materialType: mars3d.MaterialType.CircleWave, + materialOptions: { + color: "#FFB200", + count: 2, + speed: 6, }, }, - // autoMiddleDynamicPosition: true, //如果中间缺少数据时是否自动添加中间点 - frameRateHeight: 30, // 控制贴模型的效率,多少帧计算一次 + attr: { + index: index + 1, + }, }); - this.graphicLayer.addGraphic(graphic); - this.graphicLayer.enabledEvent = true; // 恢复事件 + this.mapLayer.car.addGraphic(graphic); + this.mapLayer.car.enabledEvent = true; // 恢复事件 - if (type) { - graphic.openHighlight({ - scale: 5, - silhouette: true, - silhouetteColor: "#FAAC51", - silhouetteSize: 2, - label: { - outlineColor: "#FAAC51", + graphic.bindPopup( + () => { + let html = `
+ + ${item.name} +
`; + return html; + }, + { + closeButton: false, //去除关闭按钮 + className: "car-page-popup", + pointerEvents: false, //DIV是否可以鼠标交互,为false时可以穿透操作及缩放地图,但无法进行鼠标交互及触发相关事件。 + closeOnClick: false, //是否在单击Map地图时,自动关闭当前弹窗 + autoClose: false, //在打开弹窗时,是否自动关闭之前的弹窗 + toggle: false, //是否打开状态下再次单击时关闭Popup + } + ); + graphic.openPopup(); + graphic.on(mars3d.EventType.highlightOpen, (e) => { + e.target.setOptions({ + //添加圆效果 + circle: { + fill: true, }, }); - } - graphic.on(mars3d.EventType.click, function (e) { - _this.$router.push({ + this.handleCarActive({ + id: e.target._id, + color: "#FFB200", + image: require(`../assets/images/carType${e.target.attr.index}-s.png`), + }); + }); + graphic.on(mars3d.EventType.highlightClose, (e) => { + e.target.setOptions({ + circle: { + fill: false, + }, + }); + this.handleCarActive({ + id: e.target._id, + color: "#008cff", + image: require(`../assets/images/carType${e.target.attr.index}.png`), + }); + }); + + graphic.on(mars3d.EventType.click, (e) => { + this.$router.push({ path: "/carInfo", - query: { carId: e.target.id }, + // query: { carId: e.target.id }, }); }); + + // // 设置动态位置 + // this.changePosition(0); + + // // 定时更新动态位置(setInterval为演示) + // const interval = 30; + // this.changePosition(interval); + // this.time = setInterval(() => { + // this.changePosition(interval); + // }, interval * 1000); } - this.changePosition(0); - // 定时更新动态位置(setInterval为演示) - const interval = 15; - this.changePosition(interval); - this.time = setInterval(() => { - this.changePosition(interval); - }, interval * 1000); }, - // 改变位置 - async changePosition(interval) { - let list = await this.carPoint(); - this.graphicLayer.eachGraphic((graphic) => { - let carItam = list.filter((car) => car.carId == graphic.id); - if (carItam.length > 0) { - let position = Cesium.Cartesian3.fromDegrees( - parseFloat(carItam[0].lng), - parseFloat(carItam[0].lat), - 30 - ); - graphic.addDynamicPosition(position, interval); // 按time秒运动至指定位置 - } + changePosition(time) { + this.mapLayer.car.eachGraphic((graphic) => { + graphic.addDynamicPosition(this.randomPoint(), time); // 按time秒运动至指定位置 }); }, - handleClickOutside(event) { - // 判断点击的元素是否在目标元素外部 - if (this.show && !this.$refs.targetElement.contains(event.target)) { - this.show = false; - } + randomPoint() { + const jd = this.random(120.2 * 1000, 120.9 * 1000) / 1000; + const wd = this.random(30.9 * 1000, 31.6 * 1000) / 1000; + return Cesium.Cartesian3.fromDegrees(jd, wd, 30); + }, + random(min, max) { + return Math.floor(Math.random() * (max - min + 1) + min); + }, + + /** + * 处理车辆被选中 + */ + handleCarActive(data) { + let carItem = document.getElementById(data.id); + let carIcon = carItem.getElementsByClassName("carType")[0]; + carIcon.src = data.image; + carItem.style.borderColor = data.color; }, + /**搜索 */ + handleSearch() { + this.searchList = [ + { + carName: "002号线_01_维护_守押085_苏E", + position: [120.607528, 31.209201, 11.1], + }, + ]; + + this.show = !this.show; + }, + /**单击搜索结果 */ + handelLookCar(item) { + let carItem = this.mapLayer.car.getGraphicById(`car2`); + carItem.openHighlight(); + this.map.flyToPoint(item.position, { + radius: 3788, + }); + this.show = !this.show; + }, + toggleSelection(item) { // 切换选中状态 if (this.isSelected(item)) { @@ -288,64 +335,37 @@ export default { // 检查某个项是否被选中 return this.selectedItems.includes(item); }, - - mapLoad(map) { - this.map = map; - this.graphicLayer = new mars3d.layer.GraphicLayer(); - map.addLayer(this.graphicLayer); - // this.initTilesetLayer(); - this.getCarPoint(); - }, - - /** - * 加载姑苏区三维图层 - */ - initTilesetLayer() { - let _this = this; - // 添加参考三维模型; - const tiles3dLayer = new mars3d.layer.TilesetLayer({ - name: "姑苏区建筑物", - url: "https://www.jichuanglanhai.com:88/3dtiles/yunkun/tileset.json", - maximumScreenSpaceError: 16, - maximumMemoryUsage: 1024 / 2, - dynamicScreenSpaceError: false, - skipLevelOfDetail: true, - preferLeaves: true, - flyTo: false, - style: { - color: { - conditions: [["true", `color("rgba(42, 160, 224, 1)")`]], - }, - }, - }); - this.map.addLayer(tiles3dLayer); - if (process.env.NODE_ENV === "production") this.chkShadows(true); - tiles3dLayer.on(mars3d.EventType.load, function (event) { - _this.getCarLocation(); - }); - }, - chkShadows(val) { - let _this = this; - this.map.viewer.shadows = val; - if (val) { - setTimeout(function () { - // 光照沿着相机方向 - _this.map.scene.shadowMap._lightCamera = _this.map.scene.camera; - }, 1500); - } - }, }, }; diff --git a/src/views/carInfo.vue b/src/views/carInfo.vue index 296da55..32965ac 100644 --- a/src/views/carInfo.vue +++ b/src/views/carInfo.vue @@ -3,13 +3,19 @@
- 10.8 + 0
- {{ mileData.mile }} + {{ mileData.mile ? ileData.mile : 0 }}
+
+ {{ show3D ? "关闭" : "开启" }}三维 +
+
+ 返回 +
@@ -26,7 +32,6 @@ export default { data() { const basePathUrl = window.basePathUrl || ""; return { - list: [], mileData: { mile: "", //已经行驶多少里程 }, @@ -34,92 +39,101 @@ export default { startTime: undefined, endTime: undefined, }, - graphicLayer: null, - baseUrl: basePathUrl + "lib/geoJson/tileset.json", map: null, + mapLayer: {}, + show3D: false, options: { scene: { center: { - lat: 31.212805, - lng: 120.607156, - alt: 5096.4, + lat: 31.184348, + lng: 120.625126, + alt: 6764.6, heading: 357.9, pitch: -31.5, }, }, control: { - contextmenu: { preventDefault: false, hasDefault: false }, + // contextmenu: { preventDefault: false, hasDefault: false }, }, - basemaps: [ - { - name: "mapbox影像图", - icon: "img/basemaps/mapboxSatellite.png", - type: "mapbox", - username: "sharealex", - styleId: "cly5i21fn00e901prgq643t4r", - token: - "pk.eyJ1Ijoic2hhcmVhbGV4IiwiYSI6ImNsaXNhZmRjbTFhbnczZmxib3h1OW05YXYifQ.PhlKv60ar3K359d8x2yBPw", - tilesize: 256, - scaleFactor: false, - show: false, - }, - ], }, + Line: [], carUrl: basePathUrl + "lib/qiche.gltf", }; }, components: { MarsMap, grids }, beforeDestroy() {}, - mounted() { - const { startOfDay, endOfDay } = this.getStartAndEndOfDayFormatted(true); - this.queryParams = { - carId: this.$route.query.carId, - startTime: startOfDay, - endTime: endOfDay, - }; - this.getCarMidle(); - }, + created() {}, methods: { + /**地图渲染完毕 */ mapLoad(map) { this.map = map; - this.graphicLayer = new mars3d.layer.GraphicLayer(); - map.addLayer(this.graphicLayer); - - // this.initTilesetLayer(); - this.getCarHistoryLine(); - }, + map.fixedLight = true; // 固定光照,避免gltf模型随时间存在亮度不一致。 + // 创建矢量图层 + this.mapLayer.Line = new mars3d.layer.GraphicLayer(); + this.map.addLayer(this.mapLayer.Line); - /**根据车辆的id获取车辆的历史轨迹 */ - async getCarHistoryLine() { - let result = await historyLine(this.queryParams); - result.list.map((item) => { - this.list.push([parseFloat(item.lng), parseFloat(item.lat)]); - }); + this.mapLayer.car = new mars3d.layer.GraphicLayer(); + this.map.addLayer(this.mapLayer.car); - this.historyLine(); - this.createCar(result.countData.avg_speed); + this.createLine(); + this.createCar(); }, - - historyLine() { - const firstPoint = this.list[0]; - - const divGraphic = new mars3d.graphic.DivGraphic({ - position: firstPoint, + /** + * 加载姑苏区三维图层 + */ + initTilesetLayer() { + if (this.map) { + if (!this.mapLayer.tiles3dLayer) { + this.mapLayer.tiles3dLayer = new mars3d.layer.TilesetLayer({ + name: "姑苏区建筑物", + url: "https://www.jichuanglanhai.com:88/3dtiles/yunkun/tileset.json", + maximumScreenSpaceError: 16, + maximumMemoryUsage: 1024 / 2, + dynamicScreenSpaceError: false, + skipLevelOfDetail: true, + preferLeaves: true, + flyTo: false, + style: { + color: { + conditions: [["true", `color("rgba(42, 160, 224, 1)")`]], + }, + }, + }); + this.map.addLayer(this.mapLayer.tiles3dLayer); + this.show3D = true; + } else { + this.mapLayer.tiles3dLayer.show = !this.mapLayer.tiles3dLayer.show; + this.show3D = !this.show3D; + } + } else { + } + }, + // 绘制历史轨迹线 -- 起点坐标 + createLine() { + this.Line = [ + [120.60011, 31.26247], + [120.599811, 31.267667], + [120.599341, 31.27582], + [120.59705, 31.278812], + [120.599466, 31.279271], + [120.61856, 31.28155], + [120.642973, 31.284112], + ]; + const marker = new mars3d.graphic.BillboardEntity({ + position: this.Line[0], style: { - html: `
-
起点
-
`, - horizontalOrigin: Cesium.HorizontalOrigin.CENTER, //居中防止自定义位置偏差 + image: require("../assets/images/origin.png"), + scale: 1, + horizontalOrigin: Cesium.HorizontalOrigin.CENTER, verticalOrigin: Cesium.VerticalOrigin.BOTTOM, - distanceDisplayCondition: true, clampToGround: true, - visibleDepth: true, + pixelOffsetY: 5, }, }); - this.graphicLayer.addGraphic(divGraphic); + this.mapLayer.Line.addGraphic(marker); - const graphic = new mars3d.graphic.PolylineEntity({ - positions: this.list, + const line = new mars3d.graphic.PolylineEntity({ + positions: this.Line, style: { width: 10, color: "#00F7AC", @@ -129,173 +143,66 @@ export default { clampToGround: true, }, }); - this.graphicLayer.addGraphic(graphic); - }, - - /**获取车辆天里程 */ - async getCarMidle() { - const { startOfDay, endOfDay } = this.getStartAndEndOfDayFormatted(); - let result = await carMidle({ - carId: this.queryParams.carId, - startDate: startOfDay, - endDate: endOfDay, - }); - this.mileData.mile = result.mile; - }, - - getStartAndEndOfDayFormatted(boole) { - const now = new Date(); - const startOfDay = new Date( - now.getFullYear(), - now.getMonth(), - now.getDate(), - 0, - 0, - 0 - ); - const endOfDay = new Date( - now.getFullYear(), - now.getMonth(), - now.getDate(), - 23, - 59, - 59, - 999 - ); - - return { - startOfDay: this.formatDate(startOfDay, boole), - endOfDay: this.formatDate(endOfDay, boole), - }; - }, - - formatDate(date, boole) { - const year = date.getFullYear(); - const month = String(date.getMonth() + 1).padStart(2, "0"); // 月份从0开始,所以要加1 - const day = String(date.getDate()).padStart(2, "0"); - const hours = String(date.getHours()).padStart(2, "0"); - const minutes = String(date.getMinutes()).padStart(2, "0"); - const seconds = String(date.getSeconds()).padStart(2, "0"); + this.mapLayer.Line.addGraphic(line); - if (boole) { - return `${year}${month}${day}${hours}${minutes}${seconds}`; - } else { - return `${year}${month}${day}`; - } + // 创建起始点坐标 }, - /** - * 加载姑苏区三维图层 - */ - initTilesetLayer() { - let _this = this; - // 添加参考三维模型; - let tiles3dLayer = new mars3d.layer.TilesetLayer({ - name: "姑苏区建筑物", - url: "https://www.jichuanglanhai.com:88/3dtiles/yunkun/tileset.json", - maximumScreenSpaceError: 16, - maximumMemoryUsage: 1024 / 2, - dynamicScreenSpaceError: false, - skipLevelOfDetail: true, - preferLeaves: true, - flyTo: false, - style: { - color: { - conditions: [["true", `color("rgba(42, 160, 224, 1)")`]], - }, - }, - }); - this.map.addLayer(tiles3dLayer); - tiles3dLayer.on(mars3d.EventType.load, function (event) { - _this.createCar(); - }); - }, - /** - * 生成车辆实时点位 - */ - async createCar(avg_speed) { - let _this = this; - const lastPoint = this.list[this.list.length - 1]; - // let res = await getCarIdInfo("1328CC51-C858-4FFA-8714-4F354BB49CF8"); - const fixedRoute = new mars3d.graphic.FixedRoute({ - name: "贴模型表面漫游", - speed: avg_speed, //平均速度值 - positions: [lastPoint], - camera: { - type: "gs", - heading: 90, - radius: 500, - }, + //创建实时车辆漫游 + async createCar() { + const lastPoint = this.Line[this.Line.length - 1]; + const car = new mars3d.graphic.FixedRoute({ + name: "漫游对象", + speed: 45, + positions: [ + lastPoint, + [120.6554, 31.285252, 13.6], + [120.654003, 31.298916, 10.8], + [120.649845, 31.299078, 14.2], + [120.647362, 31.308061, 17.4], + [120.645631, 31.314448, 16.1], + [120.638285, 31.312808, 10], + ], + // camera: { + // type: "gs", + // heading: 0, + // radius: 3000, + // }, model: { show: true, - url: _this.carUrl, - scale: 0.3, - minimumPixelSize: 55, + url: this.carUrl, + scale: 0.5, + minimumPixelSize: 30, silhouette: true, - silhouetteColor: "#fff", - silhouetteSize: 1, - silhouetteAlpha: 0.19, - clampToGround: true, + silhouetteColor: "#FFB200", }, - // billboard: { - // image: require("../assets/images/car-active.png"), - // width: 210, - // height: 100, - - // horizontalOrigin: Cesium.HorizontalOrigin.CENTER, //居中防止自定义位置偏差 - // verticalOrigin: Cesium.VerticalOrigin.BOTTOM, - // distanceDisplayCondition: true, - // clampToGround: true, - // visibleDepth: true, - // label: { - // text: "001号线_01_早送_守押001_苏E", - // color: "#fff", - // font_size: 13, - // pixelOffsetY: -81, - // pixelOffsetX: 10, - // horizontalOrigin: Cesium.HorizontalOrigin.CENTER, - // distanceDisplayCondition: true, - // visibleDepth: false, - // }, - // }, circle: { - radius: 500, + radius: 200, materialType: mars3d.MaterialType.CircleWave, materialOptions: { - color: "#FAAC51", + color: "#FFB200", count: 2, - speed: 10, + speed: 6, }, - clampToTileset: true, }, - // polyline: { - // // lastMaterialType: "LineTrail", - // width: 10, - // // closure: true, - // color: "#00F7AC", - // outline: true, - // outlineColor: "#008DF8", - // outlineWidth: 5, - // clampToGround: true, - // // materialOptions: { - // // color: "#008BFA", - // // materialType: "LineTrail", - // // speed: 0, - // // }, - // // materialType: "LineTrail", - // // }, - // }, + polyline: { + width: 10, + color: "#00F7AC", + outline: true, + outlineColor: "#008DF8", + outlineWidth: 5, + clampToGround: true, + }, }); - this.graphicLayer.addGraphic(fixedRoute); - //绑定弹窗 - // this.bindPopup(fixedRoute, res.data); - //开始漫游 - // fixedRoute.start(); - //打开弹窗 - // fixedRoute.openPopup(); - // // //绑定弹窗 + this.mapLayer.car.addGraphic(car); + let res = await getCarIdInfo("1328CC51-C858-4FFA-8714-4F354BB49CF8"); + + this.bindPopup(car, res.data); + car.openPopup(); + car.start(); }, + // 车辆弹窗 bindPopup(fixedRoute, data) { const userList = data.userList.map((item) => { return `