订阅选项添加createOnNotFound属性

图形状态接口添加remove属性
调整图形app接收设备状态消息的处理逻辑
This commit is contained in:
walker 2023-11-01 14:46:59 +08:00
parent 460a6237e3
commit 6e86cac613
3 changed files with 30 additions and 9 deletions

View File

@ -475,7 +475,8 @@ export interface IGraphicScene extends EventEmitter<GraphicAppEvents> {
*/
handleGraphicStates(
graphicStates: GraphicState[],
queryer?: GraphicQuery
queryer?: GraphicQuery,
createOnNotFound?: boolean
): void;
/**
*
@ -1092,7 +1093,8 @@ abstract class GraphicSceneBase
*/
handleGraphicStates(
graphicStates: GraphicState[],
queryer?: GraphicQuery
queryer?: GraphicQuery,
createOnNotFound?: boolean
): void {
graphicStates.forEach((state) => {
let g: JlGraphic | undefined;
@ -1103,12 +1105,21 @@ abstract class GraphicSceneBase
}
try {
if (!g) {
const template = this.getGraphicTemplatesByType(state.graphicType);
const g = template.new();
g.loadState(state);
this.addGraphics(g);
} else if (g.updateStates(state)) {
g.repaint();
// 未找到图形对象
if (createOnNotFound) {
const template = this.getGraphicTemplatesByType(state.graphicType);
const g = template.new();
g.loadState(state);
this.addGraphics(g);
}
} else {
// 找到
if (state.remove) {
this.deleteGraphics(g);
g.destroy({ children: true });
} else if (g.updateStates(state)) {
g.repaint();
}
}
} catch (err) {
console.error('图形状态处理异常', g, state, err);

View File

@ -502,6 +502,7 @@ export interface GraphicData {
export interface GraphicState {
get code(): string; // 业务标识
get graphicType(): string; // 图形类型
remove?: boolean; // 是否移除图形
/**
*
*/

View File

@ -146,6 +146,7 @@ export type GraphicStateMessageConvert = (
message: Uint8Array
) => GraphicState[];
// 根据状态查询图形对象查询器
export type GraphicQuery = (
state: GraphicState,
store: GraphicQueryStore
@ -168,6 +169,10 @@ export interface AppStateSubscription {
* ,code和type查询图形对象
*/
graphicQueryer?: GraphicQuery;
/**
*
*/
createOnNotFound?: boolean;
/**
*
*/
@ -196,7 +201,11 @@ class AppMessageHandler implements IMessageHandler {
const sub = this.sub;
if (sub.messageConverter) {
const graphicStates = sub.messageConverter(data);
this.app.handleGraphicStates(graphicStates, sub.graphicQueryer);
this.app.handleGraphicStates(
graphicStates,
sub.graphicQueryer,
sub.createOnNotFound
);
} else if (sub.messageHandle) {
sub.messageHandle(data);
}