You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

478 lines
13 KiB

<template>
<div class="map-container">
<div class="input-search" ref="targetElement">
<div class="search-box">
8 months ago
<input
type="text"
v-model="searchQuery.carPlate"
placeholder="请输入正确的车牌号"
/>
<i
class="el-icon-error icon-close"
v-show="searchQuery.carPlate"
@click="inputClear()"
></i>
<div class="search-btn" @click="handleSearch()"></div>
</div>
<el-collapse-transition>
<div v-show="show" class="search-list">
8 months ago
<div
class="list-item"
v-for="item in searchList"
:key="item.carId"
@click="handelLookCar(item)"
>
{{ item.carName }}
</div>
</div>
</el-collapse-transition>
</div>
8 months ago
<div class="albuginea" @click="initTilesetLayer()">
{{ show3D ? "关闭" : "开启" }}三维
</div>
<mars-map @mapLoad="mapLoad" :options="options"></mars-map>
<div class="multiple">
<div
@click="toggleSelection(item)"
:class="{ checkbox: true, checked: isSelected(item) }"
v-for="(item, index) in multipleList"
:key="index"
>
<img
8 months ago
:src="require(`../assets/images/${item}.png`)"
alt=""
class="btn-icon"
/>
{{ item }}
</div>
</div>
8 months ago
<!-- <div id="carMarker" style="display: none"></div> -->
</div>
</template>
<script>
import MarsMap from "@/components/mars-map";
8 months ago
import { getCarPoint, getCarByCarplate } from "@/api/yunkun/yunkun.js";
8 months ago
import { adjustCanvasSize, changeBorderColor } from "@/utils/carCanvas.js";
export default {
data() {
const basePathUrl = window.basePathUrl || "";
return {
8 months ago
searchList: [],
searchQuery: {
carPlate: undefined, //车牌
plateColor: undefined, //车辆颜色
},
carQuery: {
teamId: "", //该参数表示获取指定车队下所有层级子车队的车辆定位该参数优先级别高于carIds参数,
carIds: "", //车辆id 多个用逗号分开优先级低于teamId
},
8 months ago
list: [],
multipleList: ["营运线路", "维护线路", "临时任务"],
selectedItems: [],
graphicLayer: null,
baseUrl: basePathUrl + "lib/geoJson/tileset.json",
8 months ago
carUrl: basePathUrl + "lib/qiche.gltf",
map: null,
8 months ago
mapLayer: {},
options: {
scene: {
center: {
8 months ago
lat: 31.019462,
lng: 120.635502,
alt: 13761.4,
heading: 357.9,
pitch: -31.5,
},
8 months ago
fog: false,
fxaa: false,
removeDblClick: true,
requestRenderMode: false,
scene3DOnly: false,
sceneMode: 3,
shadows: false,
showMoon: false,
showSkyAtmosphere: false,
showSkyBox: false,
showSun: false,
},
control: {
8 months ago
// contextmenu: { preventDefault: false, hasDefault: false },
},
},
show: false,
showVideo: true,
8 months ago
show3D: false,
};
},
components: { MarsMap },
beforeDestroy() {
9 months ago
clearInterval(this.timer);
// 在组件销毁之前移除事件监听,防止内存泄漏
document.removeEventListener("click", this.handleClickOutside);
},
8 months ago
mounted() {
// 在mounted钩子中添加全局点击事件监听
document.addEventListener("click", this.handleClickOutside);
},
methods: {
8 months ago
/**
8 months ago
* 加载姑苏区三维图层
8 months ago
*/
8 months ago
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 {
}
},
8 months ago
/**地图渲染完毕 */
mapLoad(map) {
this.map = map;
map.fixedLight = true; // 固定光照避免gltf模型随时间存在亮度不一致。
// 创建矢量图层
this.mapLayer.car = new mars3d.layer.GraphicLayer();
this.map.addLayer(this.mapLayer.car);
this.createCar();
9 months ago
},
8 months ago
/**创建车辆 */
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,
9 months ago
style: {
8 months ago
url: this.carUrl,
8 months ago
scale: 0.5,
minimumPixelSize: 30,
8 months ago
silhouette: true,
8 months ago
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,
9 months ago
},
},
8 months ago
attr: {
index: index + 1,
},
9 months ago
});
8 months ago
this.mapLayer.car.addGraphic(graphic);
this.mapLayer.car.enabledEvent = true; // 恢复事件
8 months ago
8 months ago
graphic.bindPopup(
() => {
let html = `<div id="car${index + 1}" class="carPlate">
<img src="${require(`../assets/images/carType${
index + 1
}.png`)}" class="carType"/>
${item.name}
</div>`;
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,
8 months ago
},
});
8 months ago
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({
8 months ago
path: "/carInfo",
8 months ago
// query: { carId: e.target.id },
8 months ago
});
});
8 months ago
// // 设置动态位置
// this.changePosition(0);
// // 定时更新动态位置setInterval为演示
// const interval = 30;
// this.changePosition(interval);
// this.time = setInterval(() => {
// this.changePosition(interval);
// }, interval * 1000);
8 months ago
}
9 months ago
},
8 months ago
changePosition(time) {
this.mapLayer.car.eachGraphic((graphic) => {
graphic.addDynamicPosition(this.randomPoint(), time); // 按time秒运动至指定位置
8 months ago
});
},
8 months ago
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;
},
8 months ago
/**搜索 */
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)) {
this.selectedItems = this.selectedItems.filter(
(selectedItem) => selectedItem !== item
);
} else {
this.selectedItems.push(item);
}
},
isSelected(item) {
// 检查某个项是否被选中
return this.selectedItems.includes(item);
},
},
};
</script>
<style lang="scss" scoped>
8 months ago
.albuginea {
cursor: pointer;
position: absolute;
top: 103px;
left: 554px;
z-index: 100;
width: 80px;
height: 32px;
text-align: center;
line-height: 32px;
background: #032b57;
border-radius: 2px;
border: 1px solid #0084ff;
font-weight: 400;
font-size: 14px;
color: #ffffff;
}
.albuginea:hover {
background: #0084ff;
}
.input-search {
position: absolute;
8 months ago
top: 103px;
left: 50%;
transform: translateX(-50%);
9 months ago
z-index: 100;
.search-box {
8 months ago
position: relative;
display: flex;
align-items: center;
height: 32px;
8 months ago
.icon-close {
cursor: pointer;
position: absolute;
left: 260px;
font-size: 14px;
color: #0084ff;
}
}
.search-btn {
cursor: pointer;
line-height: 32px;
background: #0084ff;
color: #ffffff;
font-size: 14px;
padding: 0 10px;
height: 100%;
border-radius: 0 3px 3px 0;
}
input {
font-size: 14px;
width: 280px;
height: 100%;
border: 1px solid #0084ff;
border-right: 0;
background: #032b57;
padding-left: 6px;
color: #ffffff;
}
input::placeholder {
color: #7c91a8;
}
input:focus-visible {
outline: none;
}
.search-list {
width: 280px;
background: #032b57;
color: #fff;
border: 1px solid #0084ff;
border-top: 0;
& > div {
8 months ago
cursor: pointer;
font-size: 14px;
padding: 10px;
}
& > div:hover {
background: #0084ff;
}
}
}
.video-list {
position: absolute;
bottom: 25px;
left: 50%;
transform: translateX(-50%);
z-index: 50;
padding: 10px;
display: flex;
align-items: center;
border: 1px solid #415367;
border-radius: 10px;
background: rgba(28, 31, 34, 0.6);
}
.multiple {
position: absolute;
8 months ago
bottom: 20px;
left: 50%;
transform: translateX(-50%);
8 months ago
z-index: 100;
width: 880px;
height: 80px;
display: flex;
align-items: center;
justify-content: space-between;
background: url("../assets/images/multipleList.png");
background-size: 100% 100%;
8 months ago
padding: 0 220px;
.checkbox {
cursor: pointer;
width: 112px;
height: 32px;
line-height: 32px;
text-align: center;
font-size: 14px;
color: #ffffff;
background: linear-gradient(180deg, #072853 0%, #0079ff 100%);
border: 1px solid #0084ff;
border-radius: 16px;
display: flex;
align-items: center;
justify-content: center;
8 months ago
opacity: 1;
}
.checked {
8 months ago
opacity: 0.5;
}
.btn-icon {
width: 15px;
height: 16px;
margin-right: 10px;
}
}
</style>