hn-map 1.1.15 → 1.1.17

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.
@@ -4,9 +4,10 @@ import {
4
4
  wgs84ToGcj02Format,
5
5
  convertPosition,
6
6
  } from "../util";
7
- import mars3d_entity from "../base/mars3d_entity";
8
- import gaode_entity from "../base/gaode_entity";
9
- import siji_entity from "../base/siji_entity";
7
+ import Mars3dEntity from "../base/mars3d_entity";
8
+ import GaodeEntity from "../base/gaode_entity";
9
+ import SijiEntity from "../base/siji_entity";
10
+ import CesiumEntity from "../base/cesium_entity";
10
11
 
11
12
  export default (hnMap: any) => {
12
13
  const defaultOption = {
@@ -22,8 +23,8 @@ export default (hnMap: any) => {
22
23
  dashColor: "#00ff00",
23
24
  dashLength: 16,
24
25
  image: "",
25
- repeat: [1, 1],
26
- speed: 5,
26
+ repeat: [1, 1], // 闪烁线重复次数
27
+ speed: 5, // 闪烁线速度
27
28
  scaleByDistance: true,
28
29
  distanceDisplayCondition: false,
29
30
  distanceDisplayCondition_far: 1,
@@ -33,7 +34,7 @@ export default (hnMap: any) => {
33
34
  instances: [],
34
35
  };
35
36
 
36
- class mars3d_class extends mars3d_entity {
37
+ class mars3d_class extends Mars3dEntity {
37
38
  type: any = "line";
38
39
  id: any = null;
39
40
  option: any = JSON.parse(JSON.stringify(defaultOption));
@@ -84,7 +85,7 @@ export default (hnMap: any) => {
84
85
  outlineColor: option.outlineColor,
85
86
  outlineWidth: option.outlineWidth,
86
87
  clampToGround: !option.position[0][2],
87
- scaleByDistance: option.scaleByDistance,
88
+ scaleByDistance: option.scaleByDistance, // 缩放
88
89
  distanceDisplayCondition: option.distanceDisplayCondition,
89
90
  distanceDisplayCondition_far: distanceDisplayCondition_far,
90
91
  distanceDisplayCondition_near: distanceDisplayCondition_near,
@@ -162,7 +163,7 @@ export default (hnMap: any) => {
162
163
  }
163
164
  }
164
165
 
165
- class gaode_class extends gaode_entity {
166
+ class gaode_class extends GaodeEntity {
166
167
  id: any = null;
167
168
  option: any = JSON.parse(JSON.stringify(defaultOption));
168
169
  config: any = null;
@@ -199,7 +200,7 @@ export default (hnMap: any) => {
199
200
  this.graphic.setPath(this.config.path);
200
201
  }
201
202
  }
202
- class siji_class extends siji_entity {
203
+ class siji_class extends SijiEntity {
203
204
  type: any = "line";
204
205
  id: any = null;
205
206
  option: any = JSON.parse(JSON.stringify(defaultOption));
@@ -363,10 +364,341 @@ export default (hnMap: any) => {
363
364
  }
364
365
  }
365
366
 
367
+ class cesium_class extends CesiumEntity {
368
+ type: any = "line";
369
+ id: any = null;
370
+ option: any = JSON.parse(JSON.stringify(defaultOption));
371
+ config: any = null;
372
+ graphic: any = null;
373
+ entity: any = null;
374
+ flickerInterval: any = null;
375
+
376
+ constructor(option: any) {
377
+ super(hnMap);
378
+ this.id = option.id;
379
+ deepMerge(this.option, option);
380
+ this.config = this.formatConfig(this.option);
381
+ this.createGraphic();
382
+
383
+ // 确保graphic正确指向entity
384
+ this.graphic = this.entity;
385
+ }
386
+
387
+ formatConfig(option: any) {
388
+ // 转换位置坐标为 Cesium 格式
389
+ const positions = option.position.map((pos: any) => {
390
+ if (Array.isArray(pos) && pos.length >= 2) {
391
+ const height = pos.length >= 3 ? pos[2] : 0;
392
+ return Cesium.Cartesian3.fromDegrees(pos[0], pos[1], height);
393
+ }
394
+ return pos;
395
+ });
396
+
397
+ return {
398
+ id: option.id,
399
+ positions: positions,
400
+ width: option.width || 2,
401
+ color: option.color || "#ffffff",
402
+ opacity: option.opacity || 1,
403
+ type: option.type || "line",
404
+ dashColor: option.dashColor || "#00ff00",
405
+ dashLength: option.dashLength || 16,
406
+ // dashPattern: option.dashPattern,
407
+ speed: option.speed || 5,
408
+ image: option.image,
409
+ repeat: option.repeat || [1, 1],
410
+ data: option.data,
411
+ clampToGround: option.clampToGround !== false,
412
+ distanceDisplayCondition: option.distanceDisplayCondition,
413
+ distanceDisplayCondition_far: option.distanceDisplayCondition_far,
414
+ distanceDisplayCondition_near: option.distanceDisplayCondition_near,
415
+ scaleByDistance: option.scaleByDistance,
416
+ };
417
+ }
418
+
419
+ createGraphic() {
420
+ const option = this.option;
421
+ const config = this.config;
422
+
423
+ // 根据线条类型创建不同的材质
424
+ let material: any;
425
+ switch (option.type) {
426
+ case "dash":
427
+ material = new Cesium.PolylineDashMaterialProperty({
428
+ color: Cesium.Color.fromCssColorString(option.color).withAlpha(
429
+ option.opacity
430
+ ),
431
+ gapColor: Cesium.Color.TRANSPARENT,
432
+ dashPattern: parseInt("1111111100000000", 2),
433
+ });
434
+ break;
435
+
436
+ case "flicker":
437
+ material = new Cesium.ColorMaterialProperty(
438
+ Cesium.Color.fromCssColorString(option.color).withAlpha(
439
+ option.opacity
440
+ )
441
+ );
442
+ this.setupFlickerEffect();
443
+ break;
444
+
445
+ case "flow":
446
+ material = new Cesium.PolylineArrowMaterialProperty(
447
+ Cesium.Color.fromCssColorString(option.color).withAlpha(
448
+ option.opacity
449
+ )
450
+ );
451
+ break;
452
+
453
+ case "arrow":
454
+ material = new Cesium.PolylineArrowMaterialProperty(
455
+ Cesium.Color.fromCssColorString(option.color).withAlpha(
456
+ option.opacity
457
+ )
458
+ );
459
+ break;
460
+
461
+ case "line":
462
+ default:
463
+ material = new Cesium.ColorMaterialProperty(
464
+ Cesium.Color.fromCssColorString(option.color).withAlpha(
465
+ option.opacity
466
+ )
467
+ );
468
+ break;
469
+ }
470
+
471
+ // 创建实体配置
472
+ const entityConfig: any = {
473
+ id: config.id,
474
+ name: config.id,
475
+ polyline: {
476
+ positions: new Cesium.ConstantProperty(config.positions),
477
+ width: new Cesium.ConstantProperty(config.width),
478
+ material: material,
479
+ clampToGround: config.clampToGround,
480
+ arcType: Cesium.ArcType.RHUMB,
481
+ show: true,
482
+ },
483
+ };
484
+
485
+ // // 添加距离显示条件
486
+ // if (option.distanceDisplayCondition) {
487
+ // const far = getLevelMiddleHeight(option.distanceDisplayCondition_far);
488
+ // const near = getLevelMiddleHeight(option.distanceDisplayCondition_near);
489
+ // entityConfig.polyline.distanceDisplayCondition =
490
+ // new Cesium.ConstantProperty(
491
+ // new Cesium.DistanceDisplayCondition(near, far)
492
+ // );
493
+ // }
494
+
495
+ // 创建 Cesium 实体
496
+ this.entity = new Cesium.Entity(entityConfig);
497
+ this.graphic = this.entity; // 确保graphic指向entity
498
+ }
499
+
500
+ // 设置闪烁效果
501
+ setupFlickerEffect() {
502
+ if (
503
+ this.option.type === "flicker" &&
504
+ this.entity &&
505
+ this.entity.polyline
506
+ ) {
507
+ let visible = true;
508
+ const toggleVisibility = () => {
509
+ if (this.entity && this.entity.polyline) {
510
+ visible = !visible;
511
+ this.entity.polyline.show = visible;
512
+ }
513
+ };
514
+
515
+ // 设置定时器
516
+ this.flickerInterval = setInterval(
517
+ toggleVisibility,
518
+ 1000 / this.option.speed
519
+ );
520
+ }
521
+ }
522
+
523
+ // 清理闪烁效果
524
+ cleanupFlickerEffect() {
525
+ if (this.flickerInterval) {
526
+ clearInterval(this.flickerInterval);
527
+ this.flickerInterval = null;
528
+ }
529
+ }
530
+ set(option: any) {
531
+ // 清理之前的特效
532
+ this.cleanupFlickerEffect();
533
+
534
+ deepMerge(this.option, option);
535
+ this.config = this.formatConfig(this.option);
536
+
537
+ // 重新创建图形
538
+ this.createGraphic();
539
+
540
+ // 注意:这里不需要手动添加到地图
541
+ // 图层会通过layer.set()或重新addEntity来更新
542
+ }
543
+
544
+ // 飞行到线条位置
545
+ flyTo(options: any = {}) {
546
+ if (this.entity && this.entity.polyline) {
547
+ const positions = this.entity.polyline.positions.getValue(
548
+ Cesium.JulianDate.now()
549
+ );
550
+ if (positions && positions.length > 0) {
551
+ // 计算包围盒
552
+ const boundingSphere = Cesium.BoundingSphere.fromPoints(positions);
553
+
554
+ // 飞行到目标
555
+ hnMap.map.map.camera.flyToBoundingSphere(boundingSphere, {
556
+ duration: options.duration || 2.0,
557
+ offset: new Cesium.HeadingPitchRange(
558
+ Cesium.Math.toRadians(0),
559
+ Cesium.Math.toRadians(-45),
560
+ boundingSphere.radius * 2.0
561
+ ),
562
+ });
563
+ }
564
+ }
565
+ }
566
+
567
+ // 打开弹窗(如果需要)
568
+ openPopup(htmlContent: string) {
569
+ if (this.entity && hnMap.map.map) {
570
+ // 设置实体的描述属性
571
+ this.entity.description = htmlContent;
572
+
573
+ // 选中实体以显示弹窗
574
+ hnMap.map.map.selectedEntity = this.entity;
575
+ }
576
+ }
577
+
578
+ // 判断点是否在线条附近
579
+ isInPoly(lng: number, lat: number) {
580
+ if (this.entity && this.entity.polyline) {
581
+ const positions = this.entity.polyline.positions.getValue(
582
+ Cesium.JulianDate.now()
583
+ );
584
+ if (positions && positions.length > 0) {
585
+ const point = Cesium.Cartesian3.fromDegrees(lng, lat);
586
+ // 检查点到线段的距离
587
+ for (let i = 0; i < positions.length - 1; i++) {
588
+ const start = positions[i];
589
+ const end = positions[i + 1];
590
+ const distance = Cesium.Cartesian3.distance(point, start);
591
+ if (distance < 1000) {
592
+ // 1公里范围内认为在线上
593
+ return true;
594
+ }
595
+ }
596
+ }
597
+ }
598
+ return false;
599
+ }
600
+
601
+ // 更新位置
602
+ setPosition(position: any[][]) {
603
+ if (this.entity && this.entity.polyline) {
604
+ const positions = position.map((pos: any) => {
605
+ if (Array.isArray(pos) && pos.length >= 2) {
606
+ const height = pos.length >= 3 ? pos[2] : 0;
607
+ return Cesium.Cartesian3.fromDegrees(pos[0], pos[1], height);
608
+ }
609
+ return pos;
610
+ });
611
+ this.entity.polyline.positions = new Cesium.CallbackProperty(
612
+ () => positions,
613
+ false
614
+ );
615
+ }
616
+ }
617
+
618
+ // 获取位置
619
+ getPosition() {
620
+ if (this.entity && this.entity.polyline) {
621
+ const positions = this.entity.polyline.positions.getValue(
622
+ Cesium.JulianDate.now()
623
+ );
624
+ return positions.map((cartesian: any) => {
625
+ const cartographic = Cesium.Cartographic.fromCartesian(cartesian);
626
+ return [
627
+ Cesium.Math.toDegrees(cartographic.longitude),
628
+ Cesium.Math.toDegrees(cartographic.latitude),
629
+ cartographic.height,
630
+ ];
631
+ });
632
+ }
633
+ return [];
634
+ }
635
+
636
+ // 设置颜色
637
+ setColor(color: string) {
638
+ if (
639
+ this.entity &&
640
+ this.entity.polyline &&
641
+ this.entity.polyline.material
642
+ ) {
643
+ const cesiumColor = Cesium.Color.fromCssColorString(color).withAlpha(
644
+ this.option.opacity
645
+ );
646
+ if (this.entity.polyline.material.color) {
647
+ this.entity.polyline.material.color = cesiumColor;
648
+ } else if (this.entity.polyline.material.evenColor) {
649
+ this.entity.polyline.material.evenColor = cesiumColor;
650
+ }
651
+ }
652
+ }
653
+
654
+ // 设置透明度
655
+ setOpacity(opacity: number) {
656
+ if (
657
+ this.entity &&
658
+ this.entity.polyline &&
659
+ this.entity.polyline.material
660
+ ) {
661
+ this.option.opacity = opacity;
662
+ const currentColor = Cesium.Color.fromCssColorString(this.option.color);
663
+ const newColor = currentColor.withAlpha(opacity);
664
+
665
+ if (this.entity.polyline.material.color) {
666
+ this.entity.polyline.material.color = newColor;
667
+ } else if (this.entity.polyline.material.evenColor) {
668
+ this.entity.polyline.material.evenColor = newColor;
669
+ }
670
+ }
671
+ }
672
+
673
+ // 设置线宽
674
+ setWidth(width: number) {
675
+ if (this.entity && this.entity.polyline) {
676
+ this.option.width = width;
677
+ this.entity.polyline.width = width;
678
+ }
679
+ }
680
+
681
+ // 销毁实体
682
+ destroy() {
683
+ // 清理特效
684
+ this.cleanupFlickerEffect();
685
+
686
+ if (this.entity) {
687
+ // 从图层移除实体
688
+ if (hnMap.map.map && hnMap.map.map.entities) {
689
+ hnMap.map.entities.remove(this.entity);
690
+ }
691
+ this.entity = null;
692
+ this.graphic = null;
693
+ }
694
+ }
695
+ }
696
+
366
697
  const fn: any = {
367
698
  mars3d: mars3d_class,
368
699
  gaode: gaode_class,
369
700
  siji: siji_class,
701
+ cesium: cesium_class,
370
702
  };
371
703
 
372
704
  return fn[hnMap.mapType];
@@ -4,9 +4,9 @@ import {
4
4
  wgs84ToGcj02Format,
5
5
  convertPosition,
6
6
  } from "../util";
7
- import mars3d_entity from "../base/mars3d_entity";
8
- import gaode_entity from "../base/gaode_entity";
9
- import siji_entity from "../base/siji_entity";
7
+ import Mars3dEntity from "../base/mars3d_entity";
8
+ import GaodeEntity from "../base/gaode_entity";
9
+ import SijiEntity from "../base/siji_entity";
10
10
  export default (hnMap: any) => {
11
11
  const defaultOption = {
12
12
  id: "",
@@ -24,7 +24,7 @@ export default (hnMap: any) => {
24
24
  data: null,
25
25
  };
26
26
 
27
- class mars3d_class extends mars3d_entity {
27
+ class mars3d_class extends Mars3dEntity {
28
28
  type: any = "numPoint";
29
29
  id: any = null;
30
30
  option: any = JSON.parse(JSON.stringify(defaultOption));
@@ -74,7 +74,7 @@ export default (hnMap: any) => {
74
74
  }
75
75
  }
76
76
 
77
- class gaode_class extends gaode_entity {
77
+ class gaode_class extends GaodeEntity {
78
78
  id: any = null;
79
79
  option: any = JSON.parse(JSON.stringify(defaultOption));
80
80
  config: any = null;
@@ -120,7 +120,7 @@ export default (hnMap: any) => {
120
120
  }
121
121
  }
122
122
 
123
- class siji_class extends siji_entity {
123
+ class siji_class extends SijiEntity {
124
124
  type: any = "numPoint";
125
125
  id: any = null;
126
126
  option: any = JSON.parse(JSON.stringify(defaultOption));
@@ -4,9 +4,9 @@ import {
4
4
  wgs84ToGcj02Format,
5
5
  convertPosition,
6
6
  } from "../util";
7
- import mars3d_entity from "../base/mars3d_entity";
8
- import gaode_entity from "../base/gaode_entity";
9
- import siji_entity from "../base/siji_entity";
7
+ import Mars3dEntity from "../base/mars3d_entity";
8
+ import GaodeEntity from "../base/gaode_entity";
9
+ import SijiEntity from "../base/siji_entity";
10
10
 
11
11
  export default (hnMap: any) => {
12
12
  const defaultOption = {
@@ -37,7 +37,7 @@ export default (hnMap: any) => {
37
37
  data: null,
38
38
  };
39
39
 
40
- class mars3d_class extends mars3d_entity {
40
+ class mars3d_class extends Mars3dEntity {
41
41
  type: any = "point";
42
42
  id: any = null;
43
43
  option: any = JSON.parse(JSON.stringify(defaultOption));
@@ -105,7 +105,7 @@ export default (hnMap: any) => {
105
105
  }
106
106
  }
107
107
 
108
- class gaode_class extends gaode_entity {
108
+ class gaode_class extends GaodeEntity {
109
109
  id: any = null;
110
110
  option: any = JSON.parse(JSON.stringify(defaultOption));
111
111
  config: any = null;
@@ -144,7 +144,7 @@ export default (hnMap: any) => {
144
144
  }
145
145
  }
146
146
 
147
- class siji_class extends siji_entity {
147
+ class siji_class extends SijiEntity {
148
148
  type: any = "point";
149
149
  id: any = null;
150
150
  option: any = JSON.parse(JSON.stringify(defaultOption));
@@ -4,9 +4,9 @@ import {
4
4
  wgs84ToGcj02Format,
5
5
  convertPosition,
6
6
  } from "../util";
7
- import mars3d_entity from "../base/mars3d_entity";
8
- import gaode_entity from "../base/gaode_entity";
9
- import siji_entity from "../base/siji_entity";
7
+ import Mars3dEntity from "../base/mars3d_entity";
8
+ import GaodeEntity from "../base/gaode_entity";
9
+ import SijiEntity from "../base/siji_entity";
10
10
  export default (hnMap: any) => {
11
11
  const defaultOption = {
12
12
  id: "",
@@ -24,7 +24,7 @@ export default (hnMap: any) => {
24
24
  data: null,
25
25
  };
26
26
 
27
- class mars3d_class extends mars3d_entity {
27
+ class mars3d_class extends Mars3dEntity {
28
28
  type: any = "polygon";
29
29
  id: any = null;
30
30
  option: any = JSON.parse(JSON.stringify(defaultOption));
@@ -73,7 +73,7 @@ export default (hnMap: any) => {
73
73
  }
74
74
  }
75
75
 
76
- class gaode_class extends gaode_entity {
76
+ class gaode_class extends GaodeEntity {
77
77
  id: any = null;
78
78
  option: any = JSON.parse(JSON.stringify(defaultOption));
79
79
  config: any = null;
@@ -111,7 +111,7 @@ export default (hnMap: any) => {
111
111
  }
112
112
  }
113
113
 
114
- class siji_class extends siji_entity {
114
+ class siji_class extends SijiEntity {
115
115
  type: any = "polygon";
116
116
  id: any = null;
117
117
  option: any = JSON.parse(JSON.stringify(defaultOption));
@@ -4,9 +4,9 @@ import {
4
4
  createRectangleCoordinates,
5
5
  getLevelMiddleHeight,
6
6
  } from "../util";
7
- import mars3d_entity from "../base/mars3d_entity";
8
- import gaode_entity from "../base/gaode_entity";
9
- import siji_entity from "../base/siji_entity";
7
+ import Mars3dEntity from "../base/mars3d_entity";
8
+ import GaodeEntity from "../base/gaode_entity";
9
+ import SijiEntity from "../base/siji_entity";
10
10
  export default (hnMap: any) => {
11
11
  const defaultOption = {
12
12
  id: "",
@@ -24,7 +24,7 @@ export default (hnMap: any) => {
24
24
  data: null,
25
25
  };
26
26
 
27
- class mars3d_class extends mars3d_entity {
27
+ class mars3d_class extends Mars3dEntity {
28
28
  type: any = "retangle";
29
29
  id: any = null;
30
30
  option: any = JSON.parse(JSON.stringify(defaultOption));
@@ -73,7 +73,7 @@ export default (hnMap: any) => {
73
73
  }
74
74
  }
75
75
 
76
- class gaode_class extends gaode_entity {
76
+ class gaode_class extends GaodeEntity {
77
77
  id: any = null;
78
78
  option: any = JSON.parse(JSON.stringify(defaultOption));
79
79
  config: any = null;
@@ -113,7 +113,7 @@ export default (hnMap: any) => {
113
113
  this.graphic.setBounds(this.config.bounds);
114
114
  }
115
115
  }
116
- class siji_class extends siji_entity {
116
+ class siji_class extends SijiEntity {
117
117
  type: any = "rectangle";
118
118
  id: any = null;
119
119
  option: any = JSON.parse(JSON.stringify(defaultOption));