![安全巡检]()
-
{{ item.createTime.slice(5) }}
+
{{ item.label }}
diff --git a/src/views/projectLarge/ProjectScreen/components/newmap.vue b/src/views/projectLarge/ProjectScreen/components/newmap.vue
index d456627..f2b541d 100644
--- a/src/views/projectLarge/ProjectScreen/components/newmap.vue
+++ b/src/views/projectLarge/ProjectScreen/components/newmap.vue
@@ -1,11 +1,22 @@
+
+
diff --git a/src/views/projectLarge/ProjectScreen/js/CesiumImageLabelEntity.js b/src/views/projectLarge/ProjectScreen/js/CesiumImageLabelEntity.js
index fea29ec..bef9597 100644
--- a/src/views/projectLarge/ProjectScreen/js/CesiumImageLabelEntity.js
+++ b/src/views/projectLarge/ProjectScreen/js/CesiumImageLabelEntity.js
@@ -53,8 +53,12 @@ export default class CesiumImageLabelEntity {
// 创建实体
this.entity = this.createEntity();
- // 初始化点击事件监听
- this.initClickHandler();
+ // 为实体添加标识,方便后续判断
+ this.entity._isImageLabelEntity = true;
+ this.entity._imageLabelInstance = this;
+
+ // 初始化全局点击事件(确保只注册一次)
+ this.initGlobalClickHandler();
}
/**
@@ -67,7 +71,7 @@ export default class CesiumImageLabelEntity {
position: Cesium.Cartesian3.fromDegrees(
this.options.position.lng,
this.options.position.lat,
- this.options.position.alt
+ this.options.position.height || 0 // 修复:使用height而非alt
),
show: this.options.show,
@@ -79,8 +83,7 @@ export default class CesiumImageLabelEntity {
color: this.options.imageColor,
horizontalOrigin: this.options.horizontalOrigin,
verticalOrigin: this.options.verticalOrigin,
- // 允许实体被选中
- pickable: true
+ pickable: true // 确保可拾取
},
// 名称标签属性
@@ -91,12 +94,10 @@ export default class CesiumImageLabelEntity {
horizontalOrigin: this.options.horizontalOrigin,
verticalOrigin: Cesium.VerticalOrigin.TOP,
pixelOffset: new Cesium.Cartesian2(0, this.options.labelOffsetY),
- // 添加背景
- backgroundColor: new Cesium.Color(0, 0, 0, 0),
+ backgroundColor: new Cesium.Color(0, 0, 0, 0.5), // 修复:半透明背景更易点击
backgroundPadding: new Cesium.Cartesian2(5, 5),
showBackground: true,
- // 允许标签被选中
- pickable: true
+ pickable: true // 确保可拾取
}
});
@@ -107,29 +108,33 @@ export default class CesiumImageLabelEntity {
}
/**
- * 初始化点击事件处理器
+ * 初始化全局点击事件处理器(只注册一次)
*/
- initClickHandler() {
- // 存储当前实例的引用,方便在回调中使用
- const self = this;
-
- // 注册左击事件
- this.viewer.screenSpaceEventHandler.setInputAction(function onLeftClick(movement) {
- // 检测是否点击了当前实体
- const pickedObject = self.viewer.scene.pick(movement.position);
+ initGlobalClickHandler() {
+ // 检查是否已注册全局事件,避免重复注册
+ if (!this.viewer._imageLabelGlobalClickHandler) {
+ const handler = new Cesium.ScreenSpaceEventHandler(this.viewer.scene.canvas);
- // 检查是否点击了当前实体或其实体的子组件(billboard、label等)
- if (Cesium.defined(pickedObject) &&
- (pickedObject.id === self.entity ||
- pickedObject.id === self.entity.billboard ||
- pickedObject.id === self.entity.label)) {
-
- // 如果设置了点击回调,则执行
- if (self.onClickCallback && typeof self.onClickCallback === 'function') {
- self.onClickCallback(self.entity, movement.position);
+ handler.setInputAction((movement) => {
+ const pickedObject = this.viewer.scene.pick(movement.position);
+
+ // 判断是否点击了我们创建的图片标签实体
+ if (Cesium.defined(pickedObject) &&
+ Cesium.defined(pickedObject.id) &&
+ pickedObject.id._isImageLabelEntity) {
+ // 调用对应实例的回调函数
+ if (pickedObject.id._imageLabelInstance.onClickCallback) {
+ pickedObject.id._imageLabelInstance.onClickCallback(
+ pickedObject.id,
+ movement.position
+ );
+ }
}
- }
- }, Cesium.ScreenSpaceEventType.LEFT_CLICK);
+ }, Cesium.ScreenSpaceEventType.LEFT_CLICK);
+
+ // 存储全局事件处理器引用,避免重复创建
+ this.viewer._imageLabelGlobalClickHandler = handler;
+ }
}
/**