2024-11-15 15:43:39 +08:00
|
|
|
<!--
|
|
|
|
|
* @Author: SunTao 328867980@qq.com
|
|
|
|
|
* @Date: 2024-11-15 13:14:03
|
|
|
|
|
* @LastEditors: SunTao 328867980@qq.com
|
2024-12-03 15:24:58 +08:00
|
|
|
* @LastEditTime: 2024-12-03 14:32:34
|
2024-11-15 15:43:39 +08:00
|
|
|
* @FilePath: \znxjxt-ui\src\views\big-screen\overview-components\components\inspection-follow.vue
|
|
|
|
|
* @Description: 总览大屏-巡检车辆-跟车弹窗
|
|
|
|
|
-->
|
|
|
|
|
|
|
|
|
|
<template>
|
|
|
|
|
<div class="inspection-content">
|
|
|
|
|
<fssm-map ref="carMap" :baseMap="'img_c'"></fssm-map>
|
|
|
|
|
</div>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script>
|
|
|
|
|
// websocket
|
|
|
|
|
import logo from "@/assets/xc.png";
|
|
|
|
|
import FssmMap from "@/components/map/fssm-map.vue";
|
|
|
|
|
import { Point } from "ol/geom";
|
|
|
|
|
import { Feature } from "ol";
|
|
|
|
|
import { Style, Icon } from "ol/style";
|
|
|
|
|
import VectorSource from "ol/source/Vector";
|
|
|
|
|
import VectorLayer from "ol/layer/Vector";
|
|
|
|
|
|
|
|
|
|
export default {
|
|
|
|
|
name: "InspectionFollow",
|
|
|
|
|
components: {
|
|
|
|
|
FssmMap,
|
|
|
|
|
},
|
|
|
|
|
data() {
|
2024-12-02 10:52:22 +08:00
|
|
|
return {
|
|
|
|
|
// 小车图层数据源
|
|
|
|
|
carLayerSource: null,
|
2024-12-03 15:24:58 +08:00
|
|
|
// 病害图层数据源
|
|
|
|
|
defectLayerSource: null,
|
2024-12-02 10:52:22 +08:00
|
|
|
};
|
2024-11-15 15:43:39 +08:00
|
|
|
},
|
|
|
|
|
created() {
|
2024-12-02 10:52:22 +08:00
|
|
|
this.handleMessage();
|
2024-11-15 15:43:39 +08:00
|
|
|
},
|
|
|
|
|
methods: {
|
2024-12-02 10:52:22 +08:00
|
|
|
/**
|
|
|
|
|
* @description: 处理websocket消息
|
|
|
|
|
* @return {*}
|
|
|
|
|
*/
|
|
|
|
|
handleMessage() {
|
|
|
|
|
this.$ws.on("message", (item) => {
|
|
|
|
|
if (item.type === "carPosition") {
|
|
|
|
|
if (!this.carMapPointSource) {
|
|
|
|
|
this.drawCarMapPoint(item.data);
|
2024-12-03 15:24:58 +08:00
|
|
|
} else {
|
2024-12-02 10:52:22 +08:00
|
|
|
// 获取当前位置和目标位置
|
|
|
|
|
const currentLocation = this.carMapPointSource
|
|
|
|
|
.getFeatures()[0]
|
|
|
|
|
.getGeometry()
|
|
|
|
|
.getCoordinates();
|
|
|
|
|
const targetLocation = item.data.location;
|
|
|
|
|
// 计算两点之间的差值
|
|
|
|
|
const dx = (targetLocation[0] * 1 - currentLocation[0] * 1) / 100;
|
|
|
|
|
const dy = (targetLocation[1] * 1 - currentLocation[1] * 1) / 100;
|
2024-12-03 15:24:58 +08:00
|
|
|
|
2024-12-02 10:52:22 +08:00
|
|
|
// 设置计数器
|
|
|
|
|
let count = 0;
|
|
|
|
|
// 创建定时器,每10ms移动一次,总共移动100次,约1秒完成
|
|
|
|
|
const timer = setInterval(() => {
|
|
|
|
|
count++;
|
|
|
|
|
if (count >= 100) {
|
|
|
|
|
clearInterval(timer);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2024-11-15 15:43:39 +08:00
|
|
|
|
2024-12-02 10:52:22 +08:00
|
|
|
// 计算当前帧的位置
|
|
|
|
|
const x = currentLocation[0] * 1 + dx * count;
|
|
|
|
|
const y = currentLocation[1] * 1 + dy * count;
|
|
|
|
|
// 更新小车位置
|
|
|
|
|
const [features] = this.carMapPointSource.getFeatures();
|
|
|
|
|
features.setGeometry(new Point([x, y]));
|
|
|
|
|
features.setStyle([
|
|
|
|
|
new Style({
|
|
|
|
|
image: new Icon({
|
|
|
|
|
crossOrigin: "anonymous",
|
|
|
|
|
src: logo,
|
|
|
|
|
// 图标缩放比例
|
|
|
|
|
scale: 0.03,
|
|
|
|
|
// 将角度转换为弧度,并除以180*π
|
|
|
|
|
rotation: (item.data.direction - 90) * (Math.PI / 180),
|
|
|
|
|
}),
|
|
|
|
|
}),
|
|
|
|
|
]);
|
|
|
|
|
}, 10);
|
|
|
|
|
}
|
2024-12-03 13:42:21 +08:00
|
|
|
} else if (item.type === "defect") {
|
2024-12-03 15:24:58 +08:00
|
|
|
if (!this.defectLayerSource) {
|
|
|
|
|
this.drawDefectMapPoint(item.data);
|
|
|
|
|
} else {
|
|
|
|
|
const feature = new Feature({
|
|
|
|
|
geometry: new Point(item.geometry.coordinates),
|
|
|
|
|
data: item,
|
|
|
|
|
type: "defectPoint",
|
|
|
|
|
});
|
|
|
|
|
this.defectLayerSource.addFeature(feature);
|
|
|
|
|
}
|
2024-12-02 10:52:22 +08:00
|
|
|
}
|
|
|
|
|
});
|
2024-11-15 15:43:39 +08:00
|
|
|
},
|
|
|
|
|
|
2024-12-02 10:52:22 +08:00
|
|
|
/**
|
|
|
|
|
* @description: 绘制小车地图点位
|
|
|
|
|
* @param {object} item
|
|
|
|
|
* @return {void}
|
|
|
|
|
*/
|
|
|
|
|
drawCarMapPoint(item) {
|
2024-11-15 15:43:39 +08:00
|
|
|
const features = [];
|
|
|
|
|
const feature = new Feature({
|
2024-12-02 10:52:22 +08:00
|
|
|
geometry: new Point(item.location),
|
|
|
|
|
data: item,
|
|
|
|
|
type: "carPoint",
|
2024-11-15 15:43:39 +08:00
|
|
|
});
|
|
|
|
|
// 可以给点位设置样式
|
|
|
|
|
feature.setStyle([
|
|
|
|
|
new Style({
|
|
|
|
|
image: new Icon({
|
|
|
|
|
crossOrigin: "anonymous",
|
|
|
|
|
src: logo,
|
|
|
|
|
// 图标缩放比例
|
2024-12-02 10:52:22 +08:00
|
|
|
scale: 0.03,
|
|
|
|
|
// 将角度转换为弧度,并除以180*π
|
|
|
|
|
rotation: item.direction * (Math.PI / 180),
|
2024-11-15 15:43:39 +08:00
|
|
|
}),
|
|
|
|
|
}),
|
|
|
|
|
]);
|
|
|
|
|
features.push(feature);
|
2024-12-02 10:52:22 +08:00
|
|
|
this.carMapPointSource = new VectorSource({
|
2024-11-15 15:43:39 +08:00
|
|
|
features,
|
|
|
|
|
});
|
2024-12-02 10:52:22 +08:00
|
|
|
const carMapPointLayer = new VectorLayer({
|
|
|
|
|
source: this.carMapPointSource,
|
2024-11-15 15:43:39 +08:00
|
|
|
properties: {
|
2024-12-02 10:52:22 +08:00
|
|
|
type: "carPoint",
|
2024-11-15 15:43:39 +08:00
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
this.$nextTick(() => {
|
|
|
|
|
const map = this.$refs.carMap.instance.get("map");
|
2024-12-02 10:52:22 +08:00
|
|
|
map.addLayer(carMapPointLayer);
|
2024-11-15 15:43:39 +08:00
|
|
|
});
|
|
|
|
|
},
|
2024-12-03 15:24:58 +08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @description: 绘制病害地图点位
|
|
|
|
|
* @param {object} item
|
|
|
|
|
* @return {void}
|
|
|
|
|
*/
|
|
|
|
|
drawDefectMapPoint(item) {
|
|
|
|
|
const features = [];
|
|
|
|
|
const feature = new Feature({
|
|
|
|
|
geometry: new Point(item.geometry.coordinates),
|
|
|
|
|
data: item,
|
|
|
|
|
type: "defectPoint",
|
|
|
|
|
});
|
|
|
|
|
// 可以给点位设置样式
|
|
|
|
|
feature.setStyle([
|
|
|
|
|
new Style({
|
|
|
|
|
image: new Icon({
|
|
|
|
|
crossOrigin: "anonymous",
|
|
|
|
|
src: require(`@/assets/screen/index/${item.defecttype}.png`),
|
|
|
|
|
// 图标缩放比例
|
|
|
|
|
scale: 0.5,
|
|
|
|
|
}),
|
|
|
|
|
}),
|
|
|
|
|
]);
|
|
|
|
|
features.push(feature);
|
|
|
|
|
this.defectLayerSource = new VectorSource({
|
|
|
|
|
features,
|
|
|
|
|
});
|
|
|
|
|
const carMapPointLayer = new VectorLayer({
|
|
|
|
|
source: this.defectLayerSource,
|
|
|
|
|
properties: {
|
|
|
|
|
type: "defectPoint",
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
this.$nextTick(() => {
|
|
|
|
|
const map = this.$refs.carMap.instance.get("map");
|
|
|
|
|
map.addLayer(carMapPointLayer);
|
|
|
|
|
});
|
|
|
|
|
},
|
2024-11-15 15:43:39 +08:00
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
|
.inspection-content {
|
|
|
|
|
width: 100%;
|
|
|
|
|
height: 45rem;
|
|
|
|
|
|
|
|
|
|
::v-deep .baseLayerClass {
|
|
|
|
|
filter: grayscale(200%) invert(200%) sepia(50%) hue-rotate(175deg)
|
|
|
|
|
brightness(80%) saturate(550%);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</style>
|