引入路径规划 数据组件添加完成点
This commit is contained in:
@@ -215,12 +215,9 @@ export default function CesiumMap({ realtimePosition, pathPoints = [], devices =
|
||||
const trackLine = viewer.entities.add({
|
||||
polyline: {
|
||||
positions: positions,
|
||||
width: 3,
|
||||
material: new Cesium.PolylineDashMaterialProperty({
|
||||
color: Cesium?.Color.BLUE,
|
||||
dashLength: 16,
|
||||
gapColor: Cesium?.Color.TRANSPARENT,
|
||||
}),
|
||||
width: 2,
|
||||
// 实线 + 纯蓝色(核心修改)
|
||||
material: Cesium.Color.BLUE.withAlpha(0.9), // 半透明蓝色实线,更美观
|
||||
clampToGround: true,
|
||||
disableDepthTestDistance: Number.POSITIVE_INFINITY,
|
||||
},
|
||||
|
||||
@@ -1,53 +0,0 @@
|
||||
import { useEffect, useRef } from 'react';
|
||||
import mqtt, { MqttClient } from 'mqtt';
|
||||
|
||||
interface Options {
|
||||
url: string;
|
||||
topic: string | string[];
|
||||
onMessage: (topic: string, message: string) => void;
|
||||
}
|
||||
|
||||
export function useMqtt({ url, topic, onMessage }: Options) {
|
||||
const clientRef = useRef<MqttClient | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
const client = mqtt.connect(url, {
|
||||
reconnectPeriod: 3000,
|
||||
username: 'maibu',
|
||||
password: 'maibu',
|
||||
clean: true,
|
||||
});
|
||||
|
||||
clientRef.current = client;
|
||||
|
||||
client.on('connect', () => {
|
||||
console.log('MQTT connected');
|
||||
client.subscribe(topic);
|
||||
});
|
||||
|
||||
client.on('message', (t, payload) => {
|
||||
onMessage(t, payload.toString());
|
||||
});
|
||||
|
||||
client.on('error', err => {
|
||||
console.error('MQTT error', err);
|
||||
});
|
||||
|
||||
return () => {
|
||||
client.end(true);
|
||||
};
|
||||
}, [url, JSON.stringify(topic)]);
|
||||
|
||||
return clientRef;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* 使用 */
|
||||
// useMqtt({
|
||||
// url: 'wss://broker.emqx.io:8084/mqtt',
|
||||
// topic: 'robot/status',
|
||||
// onMessage: (_, message) => {
|
||||
// setMsg(message);
|
||||
// },
|
||||
// });
|
||||
Reference in New Issue
Block a user