@ -148,6 +148,11 @@ const vehicleCategories = ref({
'SHUTTLE_VEHICLE' : { visible : true , showLabel : true , name : '摆渡车' }
} ) ;
/ / 监 听 v e h i c l e C a t e g o r i e s 变 化 , 用 于 调 试
watch ( vehicleCategories , ( newCategories ) => {
console . log ( 'VehicleMovementControl: vehicleCategories 发生变化:' , newCategories ) ;
} , { deep : true } ) ;
/ / 告 警 / 预 警 状 态
const alertMessage = ref ( '' ) ;
const alertType = ref ( '' ) ;
@ -365,6 +370,9 @@ function updateVehiclePosition(vehicleData) {
if ( labelSystem . value ) {
labelSystem . value . updateVehicleLabel ( object _id , coordinates , speed ) ;
}
/ / 应 用 当 前 分 类 设 置 到 新 创 建 的 车 辆
applyCurrentCategorySettings ( object _id ) ;
} else {
/ / 更 新 动 画 目 标
if ( animationSystem . value ) {
@ -1088,6 +1096,58 @@ function clearSpeedViolationStatus(vehicleId) {
console . log ( ` 已成功清除车辆 ${ vehicleId } 的超速状态 ` ) ;
}
/ / 获 取 车 辆 类 型 键 值
function getVehicleTypeKey ( vehicle ) {
if ( ! vehicle || ! vehicle . type ) return 'UNMANNED_VEHICLE' ;
const vehicleType = vehicle . type . toUpperCase ( ) ;
/ / 根 据 车 辆 类 型 和 特 征 确 定 分 类 键 值
if ( vehicleType === 'AIRCRAFT' ) {
return 'AIRCRAFT' ;
} else if ( vehicle . isAircraft ) {
return 'AIRCRAFT' ;
} else if ( vehicleType === 'UNMANNED_VEHICLE' || vehicle . isUnmannedVehicle ) {
return 'UNMANNED_VEHICLE' ;
} else if ( vehicleType === 'SPECIAL_VEHICLE' || vehicle . isSpecialVehicle ) {
return 'AIRPORT_VEHICLE' ;
} else if ( vehicleType === 'SHUTTLE_VEHICLE' || vehicle . isShuttleVehicle ) {
return 'SHUTTLE_VEHICLE' ;
}
/ / 默 认 返 回 无 人 车 类 型
return 'UNMANNED_VEHICLE' ;
}
/ / 获 取 默 认 车 辆 样 式
function getDefaultVehicleStyle ( vehicle ) {
if ( ! vehicle ) return new Style ( { } ) ;
const isAircraft = vehicle . isAircraft || vehicle . type ? . toUpperCase ( ) === 'AIRCRAFT' ;
const iconSrc = isAircraft ? aircraftIcon : carIcon ;
const heading = vehicle . heading || 0 ;
/ / 计 算 旋 转 角 度
const rotationRad = ( ( heading - 72 ) * Math . PI ) / 180 ;
return new Style ( {
image : new Icon ( {
src : iconSrc ,
scale : 1.5 ,
anchor : [ 0.5 , 0.5 ] ,
rotation : rotationRad ,
} )
} ) ;
}
/ / 默 认 获 取 车 辆 样 式 函 数 ( 用 于 动 画 系 统 )
/ / f u n c t i o n d e f a u l t G e t V e h i c l e S t y l e ( v e h i c l e I d , s p e e d , h e a d i n g ) {
/ / c o n s t v e h i c l e = v e h i c l e s . v a l u e [ v e h i c l e I d ] ;
/ / i f ( ! v e h i c l e ) r e t u r n n e w S t y l e ( { } ) ;
/ / r e t u r n g e t D e f a u l t V e h i c l e S t y l e ( v e h i c l e ) ;
/ / }
/ / 清 除 车 辆 告 警 状 态 ( 如 果 需 要 )
function clearVehicleAlertStatus ( vehicleData ) {
const { object _id , speed } = vehicleData ;
@ -1328,43 +1388,51 @@ defineExpose({
}
} ,
setCategoryVisibility ( type , { visible , showLabel } ) {
console . log ( ` VehicleMovementControl: 设置分类 ${ type } 可见性 ` , { visible , showLabel } ) ;
if ( vehicleCategories . value [ type ] ) {
/ / 更 新 分 类 设 置
vehicleCategories . value [ type ] . visible = visible ;
vehicleCategories . value [ type ] . showLabel = showLabel ;
console . log ( ` 更新分类设置完成: ${ type } ` , vehicleCategories . value [ type ] ) ;
/ / 立 即 应 用 更 改 - 更 新 所 有 属 于 此 类 别 的 车 辆
Object . values ( vehicles . value ) . forEach ( vehicle => {
let vehicleTypeKey = vehicle . type ;
/ / 根 据 车 辆 特 征 确 定 类 别
if ( vehicle . isAircraftIn ) vehicleTypeKey = 'AIRCRAFT_IN' ;
else if ( vehicle . isAircraftOut ) vehicleTypeKey = 'AIRCRAFT_OUT' ;
else if ( vehicle . isUnmannedVehicle ) vehicleTypeKey = 'UNMANNED_VEHICLE' ;
else if ( vehicle . isSpecialVehicle ) vehicleTypeKey = 'AIRPORT_VEHICLE' ;
else if ( vehicle . isShuttleVehicle ) vehicleTypeKey = 'SHUTTLE_VEHICLE' ;
let vehicleTypeKey = getVehicleTypeKey ( vehicle ) ;
/ / 如 果 车 辆 属 于 当 前 修 改 的 类 别
if ( vehicleTypeKey === type ) {
/ / 更 新 图 标 可 见 性 - 如 果 不 可 见 , 则 完 全 移 除 图 标 样 式
console . log ( ` 更新车辆 ${ vehicle . id } ( ${ vehicleTypeKey } ) 的显示状态: ` , { visible , showLabel } ) ;
/ / 更 新 图 标 可 见 性
if ( vehicle . feature ) {
if ( visible ) {
/ / 显 示 图 标 - 确 保 s t y l e M a n a g e r . v a l u e 存 在
/ / 显 示 图 标
if ( styleManager . value ) {
vehicle . feature . setStyle ( styleManager . value . getVehicleStyle ( vehicle . id , vehicle . speed , vehicle . heading ) ) ;
} else {
/ / 提供 一 个 默 认 样 式 , 根 据 车 辆 类 型 选 择 图 标
vehicle . feature . setStyle ( defaultGetVehicleStyle( vehicle . id , vehicle . speed , vehicle . heading ) ) ;
/ / 使用 默 认 样 式
vehicle . feature . setStyle ( getDefaultVehicleStyle( vehicle ) ) ;
}
} else {
/ / 完全 隐藏 图 标 , 使 用 空 样 式 而 非 n u l l
/ / 隐藏 图 标
vehicle . feature . setStyle ( new Style ( { } ) ) ;
}
}
/ / 单独 控制 文 本 标 签 可 见 性 , 与 图 标 显 示 状 态 无 关
/ / 控制 文 本 标 签 可 见 性
if ( labelSystem . value ) {
labelSystem . value . setLabelVisibility ( vehicle . id , showLabel ) ;
if ( labelSystem . value . setLabelVisibility ) {
labelSystem . value . setLabelVisibility ( vehicle . id , showLabel ) ;
} else if ( labelSystem . value . updateVehicleLabel ) {
/ / 如 果 没 有 s e t L a b e l V i s i b i l i t y 方 法 , 使 用 u p d a t e V e h i c l e L a b e l
if ( showLabel && vehicle . position ) {
labelSystem . value . updateVehicleLabel ( vehicle . id , vehicle . position , vehicle . speed ) ;
} else {
labelSystem . value . removeVehicleLabel ( vehicle . id ) ;
}
}
}
}
} ) ;