feat(platform): open amap route from trajectory
This commit is contained in:
@@ -163,6 +163,29 @@ function trajectorySummaryText({
|
||||
].join('\n');
|
||||
}
|
||||
|
||||
function amapLocationName(row: HistoryLocationRow, fallback: string) {
|
||||
return encodeURIComponent(row.plate || row.vin || fallback);
|
||||
}
|
||||
|
||||
function amapTrajectoryURL(points: HistoryLocationRow[]) {
|
||||
const validPoints = points.filter(hasValidCoordinate);
|
||||
if (validPoints.length === 0) return '';
|
||||
if (validPoints.length === 1) {
|
||||
const point = validPoints[0];
|
||||
return `https://uri.amap.com/marker?position=${point.longitude},${point.latitude}&name=${amapLocationName(point, '车辆位置')}&src=lingniu-vehicle-platform`;
|
||||
}
|
||||
const start = validPoints[0];
|
||||
const end = validPoints[validPoints.length - 1];
|
||||
return [
|
||||
'https://uri.amap.com/navigation?',
|
||||
`from=${start.longitude},${start.latitude},${amapLocationName(start, '轨迹起点')}`,
|
||||
`&to=${end.longitude},${end.latitude},${amapLocationName(end, '轨迹终点')}`,
|
||||
'&mode=car',
|
||||
'&policy=1',
|
||||
'&src=lingniu-vehicle-platform'
|
||||
].join('');
|
||||
}
|
||||
|
||||
async function copyText(value: string, label: string) {
|
||||
const text = value.trim();
|
||||
if (!text) {
|
||||
@@ -365,6 +388,14 @@ export function History({
|
||||
'轨迹摘要'
|
||||
);
|
||||
};
|
||||
const openAmapTrajectory = () => {
|
||||
const url = amapTrajectoryURL(validLocations);
|
||||
if (!url) {
|
||||
Toast.warning('当前轨迹没有有效坐标');
|
||||
return;
|
||||
}
|
||||
window.open(url, '_blank', 'noopener,noreferrer');
|
||||
};
|
||||
const movePlayback = (delta: number) => {
|
||||
if (playbackRows.length === 0) return;
|
||||
setPlaybackIndex((current) => Math.min(Math.max(current + delta, 0), playbackRows.length - 1));
|
||||
@@ -460,6 +491,7 @@ export function History({
|
||||
<Space>
|
||||
<span>轨迹回放作业台</span>
|
||||
<Button size="small" theme="light" icon={<IconCopy />} onClick={copyTrajectorySummary}>复制轨迹摘要</Button>
|
||||
<Button size="small" theme="light" disabled={validLocations.length === 0} onClick={openAmapTrajectory}>高德线路</Button>
|
||||
</Space>
|
||||
)}
|
||||
style={{ marginTop: 16 }}
|
||||
|
||||
Reference in New Issue
Block a user