hn-map 1.1.18 → 1.1.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -178,11 +178,18 @@ export default (hnMap: any) => {
178
178
 
179
179
  // 隐藏弹窗
180
180
  public hide(): void {
181
- if (this.popupContainer) {
182
- this.popupContainer.style.display = "none";
181
+ if (this.popupContainer && this.popupContainer.parentNode) {
182
+ // 移除点击外部关闭的监听器
183
+ document.removeEventListener("click", this.handleOutsideClick);
184
+
185
+ // 从 DOM 中彻底移除容器
186
+ this.popupContainer.parentNode.removeChild(this.popupContainer);
187
+
188
+ // 重置引用
189
+ this.popupContainer = null;
190
+ this.popupElement = null;
183
191
  this.isPopupVisible = false;
184
192
  this.currentEntity = null;
185
- document.removeEventListener("click", this.handleOutsideClick);
186
193
  }
187
194
  }
188
195
 
@@ -192,6 +199,7 @@ export default (hnMap: any) => {
192
199
  this.popupElement &&
193
200
  !this.popupElement.contains(event.target as Node)
194
201
  ) {
202
+ console.log(1111111111111)
195
203
  this.hide();
196
204
  }
197
205
  };
package/src/map.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { deepMerge, getHeightToLevel, getLevelMiddleHeight } from "./util";
2
+ import CesiumEntity from "./base/cesium_entity";
2
3
 
3
4
  export default (hnMap: any) => {
4
5
  const defaultOption = {
@@ -475,6 +476,9 @@ export default (hnMap: any) => {
475
476
  layerList: any = [];
476
477
  event: any = {};
477
478
  level: any = null;
479
+ private globalClickHandler: any = null;
480
+ // 新增:点击回调注册表 存储 { entityGraphic => clickHandler }
481
+ private entityClickHandlers = new Map<any, Array<(movement: any) => void>>();
478
482
  // 数据源集合
479
483
  // dataSources: any = new Cesium.CustomDataSource("hnMap_dataSources");
480
484
  // // 数据源集合 - 改为初始化为数组
@@ -537,7 +541,11 @@ export default (hnMap: any) => {
537
541
  setTimeout(() => {
538
542
  this.addMars3dStyleRoadNetwork();
539
543
  }, 100);
544
+
545
+ // 初始化后设置全局点击监听
546
+ this.setupGlobalClickHandler();
540
547
  }
548
+
541
549
  static async create(id: string, option: any) {
542
550
  const instance = new cesium_map(id, option);
543
551
 
@@ -598,9 +606,26 @@ export default (hnMap: any) => {
598
606
  return config;
599
607
  }
600
608
 
609
+ private setupGlobalClickHandler() {
610
+ // 销毁旧的(防止重复)
611
+ if (this.globalClickHandler) {
612
+ this.globalClickHandler.destroy();
613
+ }
614
+
615
+ this.globalClickHandler = new Cesium.ScreenSpaceEventHandler(this.map.canvas);
616
+ this.globalClickHandler.setInputAction((movement: any) => {
617
+ const pickedObject = this.map.scene.pick(movement.position);
618
+ if (pickedObject && pickedObject.id) {
619
+ const handlers = this.entityClickHandlers.get(pickedObject.id);
620
+ if (handlers && handlers.length > 0) {
621
+ handlers.forEach(handler => handler(movement));
622
+ }
623
+ }
624
+ }, Cesium.ScreenSpaceEventType.LEFT_CLICK);
625
+ }
626
+
601
627
  // 模仿Mars3D的方式添加路网
602
628
  private addMars3dStyleRoadNetwork() {
603
- // console.log("添加Mars3D风格的路网...");
604
629
 
605
630
  // 方案0:使用GeoJSON数据(如果可用)
606
631
  if (this.option.roadNetworkGeoJSON) {