hn-map 1.1.14 → 1.1.16

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.
@@ -180,9 +180,6 @@ export default (hnMap: any) => {
180
180
  type: "Point",
181
181
  coordinates: [v.lng, v.lat],
182
182
  },
183
- properties: {
184
- value: v.value,
185
- },
186
183
  })),
187
184
  },
188
185
  });
@@ -38,6 +38,17 @@ export default (hnMap: any) => {
38
38
  entity.start();
39
39
  } else if (entity.type == "pointCloud" || entity.type == "heatMap") {
40
40
  hnMap.map.map.addLayer(entity.layerEntity);
41
+ } else if (entity.type == "cluster") {
42
+ // 添加聚合图层到地图
43
+ hnMap.map.map.addLayer(entity.layerEntity);
44
+
45
+ // 如果已有位置数据,立即设置
46
+ if (entity.option.position && entity.option.position.length > 0) {
47
+ setTimeout(() => {
48
+ entity.setPosition(entity.option.position);
49
+ entity.flyTo();
50
+ }, 100);
51
+ }
41
52
  } else {
42
53
  this.layerEntity.addGraphic(entity.graphic); // 添加图形
43
54
  }
@@ -51,9 +62,7 @@ export default (hnMap: any) => {
51
62
  return v.id !== entity.id;
52
63
  });
53
64
  if (entity.type === "pointCloud" || entity.type === "heatMap") {
54
- alert(entity.id);
55
65
  hnMap.map.map.removeLayer(entity.id);
56
- // entity.id.destroy();
57
66
  }
58
67
  this.layerEntity.removeGraphic(entity.graphic);
59
68
  }
@@ -180,7 +189,6 @@ export default (hnMap: any) => {
180
189
  if (this.children.find((v: any) => v.id === entity.id)) {
181
190
  console.error("已存在同名图形" + entity.id);
182
191
  } else {
183
- alert(entity.id);
184
192
  this.children.push(entity);
185
193
  this.layerEntity.addOverlay(entity.graphic); // 添加图形
186
194
 
@@ -399,6 +407,24 @@ export default (hnMap: any) => {
399
407
  duration: 2000,
400
408
  essential: true,
401
409
  });
410
+ } else if (entity.type == "cluster") {
411
+ hnMap.map.map.addLayer(entity.config_layer);
412
+ hnMap.map.map.addLayer(entity.config_label);
413
+ hnMap.map.map.loadImage(
414
+ entity.option.image,
415
+ function (error: any, image: any) {
416
+ entity.config_Image.layout["icon-size"] =
417
+ entity.option.width / image.width;
418
+
419
+ hnMap.map.map.addImage(entity.id + "_poiImage", image);
420
+ hnMap.map.map.addLayer(entity.config_Image);
421
+ }
422
+ );
423
+ hnMap.map.map.flyTo({
424
+ center: entity.option.position[0].position,
425
+ duration: 2000,
426
+ essential: true,
427
+ });
402
428
  } else {
403
429
  hnMap.map.map.addLayer(entity.config);
404
430
  }
@@ -507,10 +533,186 @@ export default (hnMap: any) => {
507
533
  }
508
534
  }
509
535
 
536
+ class cesium_class {
537
+ type: any = "layer";
538
+ id: any = null;
539
+ option: any = JSON.parse(JSON.stringify(defaultOption));
540
+ config: any = null;
541
+ children: any = null;
542
+ layerEntity: any = null;
543
+ show: boolean = true;
544
+ constructor(option: any) {
545
+ this.id = option.id;
546
+ this.children = [];
547
+ deepMerge(this.option, option);
548
+ this.config = this.formatConfig(this.option);
549
+
550
+ // 创建数据源
551
+ this.layerEntity = new Cesium.CustomDataSource(this.id);
552
+ this.layerEntity.show = this.show;
553
+
554
+ // 添加到地图
555
+ hnMap.map.dataSources.add(this.layerEntity);
556
+ }
557
+ formatConfig(option: any) {
558
+ return option;
559
+ }
560
+ // 添加图形
561
+ addEntity(entity: any) {
562
+ if (this.children.find((v: any) => v.id === entity.id)) {
563
+ console.error(`已存在同名图形: ${entity.id}`);
564
+ return;
565
+ }
566
+
567
+ this.children.push(entity);
568
+
569
+ // 根据图形类型处理
570
+ if (entity.graphic) {
571
+ if (entity.type === "cluster") {
572
+ // 集群特殊处理
573
+ this.handleCluster(entity);
574
+ } else if (entity.type === "pointCloud") {
575
+ // 点云特殊处理
576
+ this.handlePointCloud(entity);
577
+ } else if (entity.type === "heatMap") {
578
+ // 热力图特殊处理
579
+ this.handleHeatMap(entity);
580
+ } else {
581
+ // 普通实体
582
+ this.layerEntity.entities.add(entity.graphic);
583
+ }
584
+ }
585
+ }
586
+
587
+ // 处理集群
588
+ handleCluster(entity: any) {
589
+ // 集群有自己的管理逻辑
590
+ entity.layer = this;
591
+ // 集群会自己管理添加到地图
592
+ }
593
+
594
+ // 处理点云
595
+ handlePointCloud(entity: any) {
596
+ // 点云有自己的图层管理
597
+ if (entity.layerEntity) {
598
+ hnMap.map.scene.primitives.add(entity.layerEntity);
599
+ }
600
+ }
601
+
602
+ // 处理热力图
603
+ handleHeatMap(entity: any) {
604
+ // 热力图有自己的图层管理
605
+ if (entity.layerEntity) {
606
+ hnMap.map.scene.primitives.add(entity.layerEntity);
607
+ }
608
+ }
609
+
610
+ // 移除图形
611
+ removeEntity(entityParam: string) {
612
+ const entity = this.getEntity(entityParam);
613
+ if (entity) {
614
+ this.children = this.children.filter((v: any) => v.id !== entity.id);
615
+
616
+ if (entity.graphic) {
617
+ if (entity.type === "cluster") {
618
+ entity.destroy();
619
+ } else if (
620
+ entity.type === "pointCloud" ||
621
+ entity.type === "heatMap"
622
+ ) {
623
+ if (entity.layerEntity) {
624
+ hnMap.map.scene.primitives.remove(entity.layerEntity);
625
+ }
626
+ } else {
627
+ this.layerEntity.entities.remove(entity.graphic);
628
+ }
629
+ }
630
+
631
+ if (entity.destroy) {
632
+ entity.destroy();
633
+ }
634
+ }
635
+ }
636
+
637
+ // 获取图形
638
+ getEntity(entityId: string) {
639
+ return this.children.find((v: any) => v.id === entityId);
640
+ }
641
+
642
+ // 清除所有图形
643
+ clearEntity() {
644
+ this.children.forEach((entity: any) => {
645
+ if (entity.destroy) entity.destroy();
646
+ if (entity.graphic) {
647
+ this.layerEntity.entities.remove(entity.graphic);
648
+ }
649
+ });
650
+ this.children = [];
651
+ }
652
+
653
+ // 销毁图层
654
+ destroy() {
655
+ this.clearEntity();
656
+ hnMap.map.dataSources.remove(this.layerEntity);
657
+
658
+ // 从图层列表中移除
659
+ const index = hnMap.map.layerList.findIndex((v: any) => v.id === this.id);
660
+ if (index > -1) {
661
+ hnMap.map.layerList.splice(index, 1);
662
+ }
663
+ }
664
+
665
+ // 飞向图层
666
+ flyTo() {
667
+ if (this.children.length > 0) {
668
+ // 计算所有实体的边界
669
+ const positions: any[] = [];
670
+ this.children.forEach((entity: any) => {
671
+ if (entity.option.position) {
672
+ positions.push(entity.option.position);
673
+ } else if (entity.option.positions) {
674
+ positions.push(...entity.option.positions);
675
+ }
676
+ });
677
+
678
+ if (positions.length > 0) {
679
+ // 飞向边界
680
+ const cartesians = positions.map((pos) =>
681
+ Cesium.Cartesian3.fromDegrees(pos[0], pos[1], pos[2] || 0)
682
+ );
683
+ const boundingSphere = Cesium.BoundingSphere.fromPoints(cartesians);
684
+
685
+ hnMap.map.flyToBoundingSphere(boundingSphere, {
686
+ duration: 2,
687
+ offset: new Cesium.HeadingPitchRange(0, -Cesium.Math.PI / 4, 0),
688
+ });
689
+ }
690
+ }
691
+ }
692
+
693
+ // 添加属性弹窗
694
+ addPopupByAttr() {
695
+ this.children.forEach((entity: any) => {
696
+ if (entity.addPopupByAttr) {
697
+ entity.addPopupByAttr();
698
+ }
699
+ });
700
+ }
701
+
702
+ // 添加自定义弹窗
703
+ addCustomPopup(getCustomDom: Function) {
704
+ this.children.forEach((entity: any) => {
705
+ if (entity.addCustomPopup) {
706
+ entity.addCustomPopup(getCustomDom);
707
+ }
708
+ });
709
+ }
710
+ }
510
711
  const fn: any = {
511
712
  mars3d: mars3d_class,
512
713
  gaode: gaode_class,
513
714
  siji: siji_class,
715
+ cesium: cesium_class,
514
716
  };
515
717
 
516
718
  return fn[hnMap.mapType];
@@ -104,6 +104,7 @@ export default (hnMap: any) => {
104
104
  ]);
105
105
  var modelAltitude = option.position.alt;
106
106
  var modelRotate = this.calculateRotationFromDegrees(option.rotation);
107
+
107
108
  var modelScale = option.scale * (1e-6);
108
109
 
109
110
  var modelTransform = {
@@ -145,10 +146,10 @@ export default (hnMap: any) => {
145
146
  this.scene.add(directionalLight2);
146
147
 
147
148
  // var loader = new THREE.GLTFLoader();
148
- var loader = new THREE.ObjectLoader();
149
+ var loader = new THREE.ObjectLoader();
149
150
  let that = this;
150
- loader.load(option.url,
151
- // 'https://map.sgcc.com.cn/products/js-sdk/v3/assets/model/ZH-SZC3-42.gltf',
151
+ loader.load(
152
+ 'https://map.sgcc.com.cn/products/js-sdk/v3/assets/model/ZH-SZC3-42.gltf',
152
153
  // function (gltf: any) {
153
154
  function (object:any) {
154
155
  that.scene.add(object);