hn-map 1.1.16 → 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.
@@ -1,174 +1,174 @@
1
- import {deepMerge, wgs84ToGcj02Format} from '../util'
2
-
3
- let baseGeoData: any = {
4
- type: 'FeatureCollection',
5
- name: '',
6
- crs: {},
7
- features: [
8
- {
9
- type: 'Feature',
10
- properties: {},
11
- geometry: {
12
- type: 'MultiPolygon',
13
- coordinates: [[[]]]
14
- }
15
- }
16
- ]
17
- }
18
- export default (hnMap: any) => {
19
-
20
- const defaultOption = {
21
- id: "",
22
- data: baseGeoData,
23
- opacity: 1,
24
- line: {
25
- show: true,
26
- color: "#ff00ff",
27
- opacity: 1,
28
- width: 2,
29
- },
30
- area: {
31
- show: false,
32
- color: "#ffff00",
33
- opacity: 1,
34
- }
35
- }
36
-
37
- class mars3d_class {
38
- type: any = 'geoJson'
39
- id: any = null
40
- option: any = JSON.parse(JSON.stringify(defaultOption))
41
- config: any = null
42
- layerEntity: any = null
43
-
44
- constructor(option: any) {
45
- this.id = option.id
46
- deepMerge(this.option, option)
47
- this.config = this.formatConfig(this.option)
48
- this.layerEntity = new mars3d.layer.GeoJsonLayer(this.config)
49
- }
50
-
51
- formatConfig(option: any) {
52
- return {
53
- name: option.id,
54
- id: option.id,
55
- allowDrillPick: true,
56
- data: option.data,
57
- symbol: {
58
- styleOptions: {
59
- clampToGround: true,
60
- fill: option.area.show,
61
- randomColor: !!(option.area.show && option.area.color), // 随机色
62
- outline: option.line.show,
63
- opacity: option.opacity,
64
- outlineStyle: {
65
- color: option.line.color,
66
- width: option.line.width,
67
- opacity: option.line.opacity,
68
- },
69
- }
70
- },
71
- // flyTo: true,
72
- // attr: option.data
73
- }
74
- }
75
-
76
- set(option: any) {
77
- deepMerge(this.option, option)
78
- this.config = this.formatConfig(this.option)
79
- this.layerEntity.setOptions(this.config)
80
- }
81
-
82
- customStyle(callback: any) {
83
- this.layerEntity.options.symbol.callback = (attr: any) => {
84
- return callback(attr)
85
- }
86
- }
87
-
88
- destroy() {
89
- this.layerEntity.remove(true)
90
- hnMap.map.layerList = hnMap.map.layerList.filter((v: any) => v.id !== this.id)
91
- }
92
-
93
- setData(data: any) {
94
- this.layerEntity.loadGeoJSON(data, {clear: true})
95
- }
96
-
97
- clear() {
98
- this.layerEntity.clear()
99
- }
100
-
101
- flyTo() {
102
- this.layerEntity.flyTo()
103
- }
104
-
105
- // 添加属性弹窗
106
- addPopupByAttr() {
107
- this.layerEntity.bindPopup((event: any) => {
108
- if (event.graphic.attr) {
109
- const data = event.graphic.attr
110
- return mars3d.Util.getTemplateHtml({title: "详情", template: "all", attr: data})
111
- }
112
- })
113
- }
114
-
115
- // 添加自定义dom弹窗
116
- addCustomPopup(getCustomDom: any) {
117
- this.layerEntity.bindPopup(async (event: any) => {
118
- if (event.graphic.attr) {
119
- const data = event.graphic.attr || {};
120
- return await getCustomDom(data);
121
- }
122
- }, {offsetY: -20});
123
- }
124
-
125
- }
126
-
127
- class gaode_class {
128
-
129
- id: any = null
130
- option: any = JSON.parse(JSON.stringify(defaultOption))
131
- config: any = null
132
- layerEntity: any = null
133
-
134
- constructor(option: any) {
135
- this.id = option.id
136
- deepMerge(this.option, option)
137
- this.config = this.formatConfig(this.option)
138
- this.layerEntity = new AMap.HeatMap(hnMap.map.map, this.config)
139
- }
140
-
141
- formatConfig(option: any) {
142
- const data = option.position.map((v: any) => {
143
- return {lng: v.lng, lat: v.lat, count: v.value}
144
- })
145
- const amapData = wgs84ToGcj02Format(data)
146
-
147
- return {}
148
- }
149
-
150
- set(option: any) {
151
- deepMerge(this.option, option)
152
- this.config = this.formatConfig(this.option)
153
- this.layerEntity.setOptions(this.config)
154
- }
155
-
156
- destroy() {
157
- this.layerEntity.setMap(null)
158
- hnMap.map.layerList = hnMap.map.layerList.filter((v: any) => v.id !== this.id)
159
- }
160
-
161
-
162
- flyTo() {
163
-
164
- }
165
-
166
- }
167
-
168
- const fn: any = {
169
- mars3d: mars3d_class,
170
- gaode: gaode_class
171
- }
172
-
173
- return fn[hnMap.mapType]
174
- }
1
+ import {deepMerge, wgs84ToGcj02Format} from '../util'
2
+
3
+ let baseGeoData: any = {
4
+ type: 'FeatureCollection',
5
+ name: '',
6
+ crs: {},
7
+ features: [
8
+ {
9
+ type: 'Feature',
10
+ properties: {},
11
+ geometry: {
12
+ type: 'MultiPolygon',
13
+ coordinates: [[[]]]
14
+ }
15
+ }
16
+ ]
17
+ }
18
+ export default (hnMap: any) => {
19
+
20
+ const defaultOption = {
21
+ id: "",
22
+ data: baseGeoData,
23
+ opacity: 1,
24
+ line: {
25
+ show: true,
26
+ color: "#ff00ff",
27
+ opacity: 1,
28
+ width: 2,
29
+ },
30
+ area: {
31
+ show: false,
32
+ color: "#ffff00",
33
+ opacity: 1,
34
+ }
35
+ }
36
+
37
+ class mars3d_class {
38
+ type: any = 'geoJson'
39
+ id: any = null
40
+ option: any = JSON.parse(JSON.stringify(defaultOption))
41
+ config: any = null
42
+ layerEntity: any = null
43
+
44
+ constructor(option: any) {
45
+ this.id = option.id
46
+ deepMerge(this.option, option)
47
+ this.config = this.formatConfig(this.option)
48
+ this.layerEntity = new mars3d.layer.GeoJsonLayer(this.config)
49
+ }
50
+
51
+ formatConfig(option: any) {
52
+ return {
53
+ name: option.id,
54
+ id: option.id,
55
+ allowDrillPick: true,
56
+ data: option.data,
57
+ symbol: {
58
+ styleOptions: {
59
+ clampToGround: true,
60
+ fill: option.area.show,
61
+ randomColor: !!(option.area.show && option.area.color), // 随机色
62
+ outline: option.line.show,
63
+ opacity: option.opacity,
64
+ outlineStyle: {
65
+ color: option.line.color,
66
+ width: option.line.width,
67
+ opacity: option.line.opacity,
68
+ },
69
+ }
70
+ },
71
+ // flyTo: true,
72
+ // attr: option.data
73
+ }
74
+ }
75
+
76
+ set(option: any) {
77
+ deepMerge(this.option, option)
78
+ this.config = this.formatConfig(this.option)
79
+ this.layerEntity.setOptions(this.config)
80
+ }
81
+
82
+ customStyle(callback: any) {
83
+ this.layerEntity.options.symbol.callback = (attr: any) => {
84
+ return callback(attr)
85
+ }
86
+ }
87
+
88
+ destroy() {
89
+ this.layerEntity.remove(true)
90
+ hnMap.map.layerList = hnMap.map.layerList.filter((v: any) => v.id !== this.id)
91
+ }
92
+
93
+ setData(data: any) {
94
+ this.layerEntity.loadGeoJSON(data, {clear: true})
95
+ }
96
+
97
+ clear() {
98
+ this.layerEntity.clear()
99
+ }
100
+
101
+ flyTo() {
102
+ this.layerEntity.flyTo()
103
+ }
104
+
105
+ // 添加属性弹窗
106
+ addPopupByAttr() {
107
+ this.layerEntity.bindPopup((event: any) => {
108
+ if (event.graphic.attr) {
109
+ const data = event.graphic.attr
110
+ return mars3d.Util.getTemplateHtml({title: "详情", template: "all", attr: data})
111
+ }
112
+ })
113
+ }
114
+
115
+ // 添加自定义dom弹窗
116
+ addCustomPopup(getCustomDom: any) {
117
+ this.layerEntity.bindPopup(async (event: any) => {
118
+ if (event.graphic.attr) {
119
+ const data = event.graphic.attr || {};
120
+ return await getCustomDom(data);
121
+ }
122
+ }, {offsetY: -20});
123
+ }
124
+
125
+ }
126
+
127
+ class gaode_class {
128
+
129
+ id: any = null
130
+ option: any = JSON.parse(JSON.stringify(defaultOption))
131
+ config: any = null
132
+ layerEntity: any = null
133
+
134
+ constructor(option: any) {
135
+ this.id = option.id
136
+ deepMerge(this.option, option)
137
+ this.config = this.formatConfig(this.option)
138
+ this.layerEntity = new AMap.HeatMap(hnMap.map.map, this.config)
139
+ }
140
+
141
+ formatConfig(option: any) {
142
+ const data = option.position.map((v: any) => {
143
+ return {lng: v.lng, lat: v.lat, count: v.value}
144
+ })
145
+ const amapData = wgs84ToGcj02Format(data)
146
+
147
+ return {}
148
+ }
149
+
150
+ set(option: any) {
151
+ deepMerge(this.option, option)
152
+ this.config = this.formatConfig(this.option)
153
+ this.layerEntity.setOptions(this.config)
154
+ }
155
+
156
+ destroy() {
157
+ this.layerEntity.setMap(null)
158
+ hnMap.map.layerList = hnMap.map.layerList.filter((v: any) => v.id !== this.id)
159
+ }
160
+
161
+
162
+ flyTo() {
163
+
164
+ }
165
+
166
+ }
167
+
168
+ const fn: any = {
169
+ mars3d: mars3d_class,
170
+ gaode: gaode_class
171
+ }
172
+
173
+ return fn[hnMap.mapType]
174
+ }
@@ -552,13 +552,25 @@ export default (hnMap: any) => {
552
552
  this.layerEntity.show = this.show;
553
553
 
554
554
  // 添加到地图
555
- hnMap.map.dataSources.add(this.layerEntity);
555
+ // 注意:这里需要确保 hnMap.map.dataSources 存在且可用
556
+ if (hnMap.map && hnMap.map.dataSources) {
557
+ if (typeof hnMap.map.dataSources.add === "function") {
558
+ hnMap.map.dataSources.add(this.layerEntity);
559
+ } else {
560
+ console.warn("无法添加数据源到地图");
561
+ }
562
+ } else {
563
+ console.warn("地图数据源不可用");
564
+ }
556
565
  }
557
566
  formatConfig(option: any) {
558
567
  return option;
559
568
  }
560
569
  // 添加图形
570
+ // 添加图形
561
571
  addEntity(entity: any) {
572
+ console.log("添加图形到Cesium图层", entity);
573
+
562
574
  if (this.children.find((v: any) => v.id === entity.id)) {
563
575
  console.error(`已存在同名图形: ${entity.id}`);
564
576
  return;
@@ -577,13 +589,34 @@ export default (hnMap: any) => {
577
589
  } else if (entity.type === "heatMap") {
578
590
  // 热力图特殊处理
579
591
  this.handleHeatMap(entity);
592
+ } else if (entity.type === "line") {
593
+ // 线要素 - 确保添加到地图
594
+ this.handleLineEntity(entity);
580
595
  } else {
581
596
  // 普通实体
597
+ console.log("添加普通实体到Cesium:", entity.graphic);
582
598
  this.layerEntity.entities.add(entity.graphic);
583
599
  }
584
600
  }
585
601
  }
586
602
 
603
+ // 处理线实体
604
+ handleLineEntity(entity: any) {
605
+ console.log("处理线实体:", entity);
606
+
607
+ if (entity.entity) {
608
+ // 如果是Cesium实体,直接添加到数据源
609
+ console.log("添加线实体到数据源:", entity.entity);
610
+ this.layerEntity.entities.add(entity.entity);
611
+ } else if (entity.graphic && entity.graphic instanceof Cesium.Entity) {
612
+ // 如果graphic是Cesium实体
613
+ console.log("添加graphic作为Cesium实体");
614
+ this.layerEntity.entities.add(entity.graphic);
615
+ } else {
616
+ console.warn("线实体格式不支持:", entity);
617
+ }
618
+ }
619
+
587
620
  // 处理集群
588
621
  handleCluster(entity: any) {
589
622
  // 集群有自己的管理逻辑
@@ -653,7 +686,14 @@ export default (hnMap: any) => {
653
686
  // 销毁图层
654
687
  destroy() {
655
688
  this.clearEntity();
656
- hnMap.map.dataSources.remove(this.layerEntity);
689
+ // 从地图移除数据源
690
+ if (
691
+ hnMap.map &&
692
+ hnMap.map.dataSources &&
693
+ typeof hnMap.map.dataSources.remove === "function"
694
+ ) {
695
+ hnMap.map.dataSources.remove(this.layerEntity);
696
+ }
657
697
 
658
698
  // 从图层列表中移除
659
699
  const index = hnMap.map.layerList.findIndex((v: any) => v.id === this.id);