fix:大屏巡检车辆跟车调试

This commit is contained in:
SunTao 2024-12-02 10:52:22 +08:00
parent 6503d7f09d
commit 319818bbf3
3 changed files with 86 additions and 67 deletions

View File

@ -2,7 +2,7 @@
* @Author: SunTao 328867980@qq.com
* @Date: 2024-10-17 11:34:00
* @LastEditors: SunTao 328867980@qq.com
* @LastEditTime: 2024-12-02 10:24:07
* @LastEditTime: 2024-12-02 10:47:38
* @FilePath: \znxjxt-ui\src\views\big-screen\index.vue
* @Description: 大屏首页
-->
@ -1239,8 +1239,8 @@ export default {
.getCoordinates();
const targetLocation = item.data.location;
//
const dx = (targetLocation[0] - currentLocation[0]) / 100;
const dy = (targetLocation[1] - currentLocation[1]) / 100;
const dx = (targetLocation[0] * 1 - currentLocation[0] * 1) / 100;
const dy = (targetLocation[1] * 1 - currentLocation[1] * 1) / 100;
//
let count = 0;
// ,10ms,100,1
@ -1252,8 +1252,8 @@ export default {
}
//
const x = currentLocation[0] + dx * count;
const y = currentLocation[1] + dy * count;
const x = currentLocation[0] * 1 + dx * count;
const y = currentLocation[1] * 1 + dy * count;
//
const [features] = this.carMapPointSource.getFeatures();
@ -1380,6 +1380,7 @@ export default {
},
beforeDestroy() {
clearInterval(this.timeFlag);
//
const data = { type: "carLocation", status: false };
this.$ws.send(data);
},

View File

@ -2,7 +2,7 @@
* @Author: SunTao 328867980@qq.com
* @Date: 2024-11-15 13:14:03
* @LastEditors: SunTao 328867980@qq.com
* @LastEditTime: 2024-11-15 14:06:48
* @LastEditTime: 2024-12-02 10:46:24
* @FilePath: \znxjxt-ui\src\views\big-screen\overview-components\components\inspection-follow.vue
* @Description: 总览大屏-巡检车辆-跟车弹窗
-->
@ -15,12 +15,6 @@
<script>
// websocket
import {
connectWebsocket,
closeWebsocket,
sendMsg,
} from "@/plugins/websocket.js";
import { getToken } from "@/utils/auth.js";
import logo from "@/assets/xc.png";
import FssmMap from "@/components/map/fssm-map.vue";
import { Point } from "ol/geom";
@ -35,50 +29,81 @@ export default {
FssmMap,
},
data() {
return {};
return {
//
carLayerSource: null,
};
},
created() {
this.initWebSocket();
this.handleMessage();
},
methods: {
/* 初始化websocket */
initWebSocket() {
const url = `ws://192.168.1.188:8080/websocket?token=${getToken()}`;
const data = { type: "carLocation", status: true };
connectWebsocket(
url,
data,
(res) => {
// console.log("onWsMessage: ", res);
console.log(JSON.parse(res));
},
(err) => {
console.log("断开重连");
this.drawPoint();
/**
* @description: 处理websocket消息
* @return {*}
*/
handleMessage() {
this.$ws.on("message", (item) => {
if (item.type === "carPosition") {
if (!this.carMapPointSource) {
this.drawCarMapPoint(item.data);
}
else {
//
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;
//
let count = 0;
// ,10ms,100,1
const timer = setInterval(() => {
count++;
if (count >= 100) {
clearInterval(timer);
return;
}
//
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);
}
}
);
});
},
/* 发送消息 */
sendMsg() {
sendMsg(5555); //value
// this.value = "";
},
/* 绘制地图车点位 */
drawPoint() {
/**
* @description: 绘制小车地图点位
* @param {object} item
* @return {void}
*/
drawCarMapPoint(item) {
const features = [];
//
const point = new Point([123.30297096718999,41.87942945541742]);
const feature = new Feature({
geometry: point,
data: {
iconType: "1",
// imageUrl: element.imageUrl,
// rect: element.rect,
},
//
type: "icon",
geometry: new Point(item.location),
data: item,
type: "carPoint",
});
//
feature.setStyle([
@ -87,29 +112,27 @@ export default {
crossOrigin: "anonymous",
src: logo,
//
scale: 0.05,
scale: 0.03,
// ,180*π
rotation: item.direction * (Math.PI / 180),
}),
}),
]);
features.push(feature);
//
const pointSource = new VectorSource({
this.carMapPointSource = new VectorSource({
features,
});
let markLayerPoints = new VectorLayer({
source: pointSource,
const carMapPointLayer = new VectorLayer({
source: this.carMapPointSource,
properties: {
type: "point",
type: "carPoint",
},
});
this.$nextTick(() => {
const map = this.$refs.carMap.instance.get("map");
map.addLayer(markLayerPoints);
map.addLayer(carMapPointLayer);
});
},
beforeDestroy() {
closeWebsocket();
},
},
};
</script>

View File

@ -79,7 +79,6 @@
size="mini"
type="text"
style="margin-right: 0.6rem"
@click="detailDefect(scope.row)"
>详情
</el-button>
</el-popover>
@ -151,7 +150,6 @@
import { getCarList, closeVideoUrl } from "@/api/xj/screen/disease-screen";
import InspectionFollow from "./components/inspection-follow.vue";
import InspectionView from "./components/inspection-view.vue";
import { closeWebsocket } from "@/plugins/websocket.js";
export default {
name: "InspectionVehicles",
components: {
@ -229,13 +227,6 @@ export default {
this.getTableData();
},
/**
* @description: 表格详情事件
* @param {*} val
* @return {*}
*/
detailDefect(val) {},
/**
* @description: 表格跟车事件
* @param {*} val
@ -244,6 +235,8 @@ export default {
followCar(val) {
this.followTitle = "跟车详情";
this.showCarVisible = true;
const carData = { type: "carLocation", status: true };
this.$ws.send(carData);
},
/**
@ -266,7 +259,9 @@ export default {
this.followTitle = "";
this.showCarVisible = false;
this.dialogItem = {};
closeWebsocket();
//
const carData = { type: "carLocation", status: false };
this.$ws.send(carData);
},
/**