hn-map 1.1.7 → 1.1.9

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,163 +1,313 @@
1
- import {deepMerge, wgs84ToGcj02Format} from '../util'
1
+ import { deepMerge, wgs84ToGcj02Format } from "../util";
2
2
 
3
3
  export default (hnMap: any) => {
4
+ const defaultOption = {
5
+ id: "",
6
+ position: [],
7
+ allowDrillPick: true,
8
+ max: null,
9
+ min: null,
10
+ radius: 25,
11
+ minOpacity: 0.1,
12
+ maxOpacity: 0.8,
13
+ opacity: 1,
14
+ blur: 0.85,
15
+ gradient: {},
16
+ scaleByDistance: false,
17
+ clampToGround: true,
18
+ data: null,
19
+ };
4
20
 
5
- const defaultOption = {
6
- id: "",
7
- position: [],
8
- allowDrillPick: true,
9
- max: null,
10
- min: null,
11
- radius: 25,
12
- minOpacity: 0.1,
13
- maxOpacity: 0.8,
14
- opacity: 1,
15
- blur: 0.85,
16
- gradient: {},
17
- scaleByDistance: false,
18
- clampToGround: true,
19
- data: null
20
- }
21
-
22
- class mars3d_class {
23
- type: any = 'heatMap'
24
- id: any = null
25
- option: any = JSON.parse(JSON.stringify(defaultOption))
26
- config: any = null
27
- layerEntity: any = null
28
-
29
- constructor(option: any) {
30
- this.id = option.id
31
- deepMerge(this.option, option)
32
- this.config = this.formatConfig(this.option)
33
- this.layerEntity = new mars3d.layer.HeatLayer(JSON.parse(JSON.stringify(this.config)))
34
- }
35
-
36
- formatConfig(option: any) {
37
- return {
38
- id: option.id,
39
- positions: option.position,
40
- allowDrillPick: option.allowDrillPick,
41
- max: option.max,
42
- min: option.min,
43
- heatStyle: {
44
- radius: option.radius,
45
- minOpacity: option.minOpacity,
46
- maxOpacity: option.maxOpacity,
47
- blur: option.blur,
48
- gradient: option.gradient,
49
- },
50
- style: {
51
- opacity: option.opacity,
52
- scaleByDistance: option.scaleByDistance,
53
- clampToGround: option.clampToGround,
54
- },
55
- redrawZoom: true,
56
- attr: option.data
57
- }
58
- }
59
-
60
- set(option: any) {
61
- deepMerge(this.option, option)
62
- this.config = this.formatConfig(this.option)
63
- this.layerEntity.setOptions(this.config)
64
- }
65
-
66
- destroy() {
67
- this.layerEntity.remove(true)
68
- hnMap.map.layerList = hnMap.map.layerList.filter((v: any) => v.id !== this.id)
69
- }
70
-
71
- flyTo() {
72
- this.layerEntity.flyTo()
73
- }
74
-
75
- clear() {
76
- this.layerEntity.clear()
77
- }
78
-
79
- setPosition(position: any) {
80
- deepMerge(this.option, {position})
81
- this.layerEntity.setPositions(position)
82
- }
83
-
84
- show() {
85
- this.layerEntity.show = true
86
- }
87
-
88
- hide() {
89
- this.layerEntity.show = false
90
- }
91
-
92
- }
93
-
94
- class gaode_class {
95
-
96
- id: any = null
97
- option: any = JSON.parse(JSON.stringify(defaultOption))
98
- config: any = null
99
- layerEntity: any = null
100
-
101
- constructor(option: any) {
102
- this.id = option.id
103
- deepMerge(this.option, option)
104
- this.config = this.formatConfig(this.option)
105
- this.layerEntity = new AMap.HeatMap(hnMap.map.map, this.config)
106
- this.layerEntity.setDataSet({data: this.config.data, max: this.config.max, min: this.config.min});
107
-
108
- }
109
-
110
- formatConfig(option: any) {
111
- const data = option.position.map((v: any) => {
112
- return {lng: v.lng, lat: v.lat, count: v.value}
113
- })
114
- const amapData = wgs84ToGcj02Format(data)
115
-
116
- return {
117
- id: option.id,
118
- radius: option.radius,
119
- max: option.max,
120
- min: option.min,
121
- opacity: [option.minOpacity, option.maxOpacity],
122
- gradient: option.gradient,
123
- data: amapData,
124
- extData: {
125
- id: option.id,
126
- data: option.data,
127
- },
128
- }
129
- }
130
-
131
- set(option: any) {
132
- deepMerge(this.option, option)
133
- this.config = this.formatConfig(this.option)
134
- this.layerEntity.setOptions(this.config)
135
- }
136
-
137
- destroy() {
138
- this.layerEntity.setMap(null)
139
- hnMap.map.layerList = hnMap.map.layerList.filter((v: any) => v.id !== this.id)
140
- }
141
-
142
-
143
- flyTo() {
144
- let totalLng = 0;
145
- let totalLat = 0;
146
- this.config.data.map((item: any) => {
147
- totalLng += item.lng;
148
- totalLat += item.lat;
149
- })
150
- const centerLng = totalLng / this.config.data.length;
151
- const centerLat = totalLat / this.config.data.length;
152
- hnMap.map.map.setCenter([centerLng, centerLat])
153
- }
154
-
155
- }
156
-
157
- const fn: any = {
158
- mars3d: mars3d_class,
159
- gaode: gaode_class
160
- }
161
-
162
- return fn[hnMap.mapType]
163
- }
21
+ class mars3d_class {
22
+ type: any = "heatMap";
23
+ id: any = null;
24
+ option: any = JSON.parse(JSON.stringify(defaultOption));
25
+ config: any = null;
26
+ layerEntity: any = null;
27
+
28
+ constructor(option: any) {
29
+ this.id = option.id;
30
+ deepMerge(this.option, option);
31
+ this.config = this.formatConfig(this.option);
32
+ this.layerEntity = new mars3d.layer.HeatLayer(
33
+ JSON.parse(JSON.stringify(this.config))
34
+ );
35
+ }
36
+
37
+ formatConfig(option: any) {
38
+ return {
39
+ id: option.id,
40
+ positions: option.position,
41
+ allowDrillPick: option.allowDrillPick,
42
+ max: option.max,
43
+ min: option.min,
44
+ heatStyle: {
45
+ radius: option.radius,
46
+ minOpacity: option.minOpacity,
47
+ maxOpacity: option.maxOpacity,
48
+ blur: option.blur,
49
+ gradient: option.gradient,
50
+ },
51
+ style: {
52
+ opacity: option.opacity,
53
+ scaleByDistance: option.scaleByDistance,
54
+ clampToGround: option.clampToGround,
55
+ },
56
+ redrawZoom: true,
57
+ flyTo: true,
58
+ attr: option.data,
59
+ };
60
+ }
61
+
62
+ set(option: any) {
63
+ deepMerge(this.option, option);
64
+ this.config = this.formatConfig(this.option);
65
+ this.layerEntity.setOptions(this.config);
66
+ }
67
+
68
+ destroy() {
69
+ this.layerEntity.remove(true);
70
+ hnMap.map.layerList = hnMap.map.layerList.filter(
71
+ (v: any) => v.id !== this.id
72
+ );
73
+ }
74
+
75
+ flyTo() {
76
+ this.layerEntity.flyTo();
77
+ }
78
+
79
+ clear() {
80
+ this.layerEntity.clear();
81
+ }
82
+
83
+ setPosition(position: any) {
84
+ deepMerge(this.option, { position });
85
+ this.layerEntity.setPositions(position);
86
+ }
87
+
88
+ show() {
89
+ this.layerEntity.show = true;
90
+ }
91
+
92
+ hide() {
93
+ this.layerEntity.show = false;
94
+ }
95
+ }
96
+
97
+ class gaode_class {
98
+ id: any = null;
99
+ option: any = JSON.parse(JSON.stringify(defaultOption));
100
+ config: any = null;
101
+ layerEntity: any = null;
102
+
103
+ constructor(option: any) {
104
+ this.id = option.id;
105
+ deepMerge(this.option, option);
106
+ this.config = this.formatConfig(this.option);
107
+ this.layerEntity = new AMap.HeatMap(hnMap.map.map, this.config);
108
+ this.layerEntity.setDataSet({
109
+ data: this.config.data,
110
+ max: this.config.max,
111
+ min: this.config.min,
112
+ });
113
+ }
114
+
115
+ formatConfig(option: any) {
116
+ const data = option.position.map((v: any) => {
117
+ return { lng: v.lng, lat: v.lat, count: v.value };
118
+ });
119
+ const amapData = wgs84ToGcj02Format(data);
120
+
121
+ return {
122
+ id: option.id,
123
+ radius: option.radius,
124
+ max: option.max,
125
+ min: option.min,
126
+ opacity: [option.minOpacity, option.maxOpacity],
127
+ gradient: option.gradient,
128
+ data: amapData,
129
+ extData: {
130
+ id: option.id,
131
+ data: option.data,
132
+ },
133
+ };
134
+ }
135
+
136
+ set(option: any) {
137
+ deepMerge(this.option, option);
138
+ this.config = this.formatConfig(this.option);
139
+ this.layerEntity.setOptions(this.config);
140
+ }
141
+
142
+ destroy() {
143
+ this.layerEntity.setMap(null);
144
+ hnMap.map.layerList = hnMap.map.layerList.filter(
145
+ (v: any) => v.id !== this.id
146
+ );
147
+ }
148
+
149
+ flyTo() {
150
+ let totalLng = 0;
151
+ let totalLat = 0;
152
+ this.config.data.map((item: any) => {
153
+ totalLng += item.lng;
154
+ totalLat += item.lat;
155
+ });
156
+ const centerLng = totalLng / this.config.data.length;
157
+ const centerLat = totalLat / this.config.data.length;
158
+ hnMap.map.map.setCenter([centerLng, centerLat]);
159
+ }
160
+ }
161
+
162
+ class siji_class {
163
+ type: any = "heatMap";
164
+ id: any = null;
165
+ option: any = JSON.parse(JSON.stringify(defaultOption));
166
+ config_heatmap: any = null;
167
+ config_point: any = null;
168
+ layerEntity: any = null;
169
+
170
+ constructor(option: any) {
171
+ this.id = option.id;
172
+ deepMerge(this.option, option);
173
+ hnMap.map.map.addSource("themeData", {
174
+ type: "geojson",
175
+ data: {
176
+ type: "FeatureCollection",
177
+ features: this.option.position.map((v: any) => ({
178
+ type: "Feature",
179
+ geometry: {
180
+ type: "Point",
181
+ coordinates: [v.lng, v.lat],
182
+ },
183
+ properties: {
184
+ value: v.value,
185
+ },
186
+ })),
187
+ },
188
+ });
189
+ this.config_heatmap = this.formatConfig_heatmap(this.option);
190
+ this.config_point = this.formatConfig_point(this.option);
191
+ }
192
+
193
+ formatConfig_heatmap(option: any) {
194
+ let config: any = {};
195
+ config = {
196
+ id: option.id,
197
+ type: "heatmap",
198
+ source: "themeData",
199
+ maxzoom: 17,
200
+ paint: {
201
+ /**
202
+ * 数据点的影响力,weight=10的点相当于十个weight=1的点
203
+ * 下述为插值表达式,输入是点geojson的properties的mag,输出随mag线性增大
204
+ */
205
+ "heatmap-weight": [
206
+ "interpolate",
207
+ ["linear"],
208
+ ["get", "value"],
209
+ 0,
210
+ 0,
211
+ 150,
212
+ 1.5,
213
+ ],
214
+ /**
215
+ * 热力图强度,类似heatmap-weight
216
+ * 下述为插值表达式,输出随zoom线性变化,zoom为0时值为1,zoom为12时值为3
217
+ */
218
+ "heatmap-intensity": [
219
+ "interpolate",
220
+ ["linear"],
221
+ ["zoom"],
222
+ 0,
223
+ 1,
224
+ 17,
225
+ 1,
226
+ ],
227
+ /**
228
+ * 像素的颜色,必须以heatmap-density(热力图像素的密度)为输入
229
+ * 下述为插值表达式,输出随heatmap-density变化而变化
230
+ */
231
+ "heatmap-color": [
232
+ "interpolate",
233
+ ["linear"],
234
+ ["heatmap-density"],
235
+ 0,
236
+ "rgba(255, 0, 0, 0)",
237
+ 0.4,
238
+ option.gradient["0.4"],
239
+ 0.6,
240
+ option.gradient["0.6"],
241
+ 0.8,
242
+ option.gradient["0.8"],
243
+ 0.9,
244
+ option.gradient["0.9"],
245
+ // 0,
246
+ // "rgba(255, 0, 0, 0)",
247
+ // 0.1,
248
+ // option.gradient["0.4"], // "rgba(0, 30, 255, .6)",
249
+ // 0.2,
250
+ // "rgba(7, 208, 255, .6)",
251
+ // 0.3,
252
+ // option.gradient["0.6"], //"#2cc946",
253
+ // 0.4,
254
+ // "#d5fb0c",
255
+ // 0.5,
256
+ // option.gradient["0.8"], //"#e04e4e",
257
+ // 0.6,
258
+ // option.gradient["0.9"], //"#f33900",
259
+ // 0.9,
260
+ // "rgba(243, 57, 0, .6)",
261
+ // 1,
262
+ // "rgba(243, 57, 0, .8)",
263
+ ],
264
+ /**
265
+ * 该值越大,热力图越平滑,信息越不详细。
266
+ * 下述为插值表达式,输出随zoom线性变化,zoom为0时值为8,zoom为9时值为20
267
+ */
268
+ "heatmap-radius": ["interpolate", ["linear"], ["zoom"], 0, 5, 17, 50],
269
+ /**
270
+ * 透明度,输出为1则不透明
271
+ * 下述为插值表达式,输出随zoom线性变化,zoom为5时值为0.8,zoom为12时值为0.4
272
+ */
273
+ "heatmap-opacity": [
274
+ "interpolate",
275
+ ["linear"],
276
+ ["zoom"],
277
+ 5,
278
+ option.maxOpacity, //0.8,
279
+ 17,
280
+ option.minOpacity, // 0.8
281
+ ],
282
+ },
283
+ };
284
+ return config;
285
+ }
286
+
287
+ formatConfig_point(option: any) {
288
+ let config_point: any = {};
289
+ config_point = {
290
+ id: "earthquakes-point",
291
+ type: "circle",
292
+ source: "themeData",
293
+ minzoom: 17,
294
+ paint: {
295
+ "circle-radius": ["interpolate", ["linear"], ["zoom"], 5, 1, 20, 12],
296
+ "circle-color": "rgb(255, 148, 0)",
297
+ "circle-stroke-color": "white",
298
+ "circle-stroke-width": 1,
299
+ "circle-opacity": ["interpolate", ["linear"], ["zoom"], 9, 0, 20, 1],
300
+ },
301
+ };
302
+ return config_point;
303
+ }
304
+ }
305
+
306
+ const fn: any = {
307
+ mars3d: mars3d_class,
308
+ gaode: gaode_class,
309
+ siji: siji_class,
310
+ };
311
+
312
+ return fn[hnMap.mapType];
313
+ };
@@ -32,9 +32,14 @@ export default (hnMap: any) => {
32
32
  console.error("已存在同名图形" + entity.id);
33
33
  } else {
34
34
  this.children.push(entity);
35
- this.layerEntity.addGraphic(entity.graphic); // 添加图形
35
+
36
36
  if (entity.type == "route") {
37
+ this.layerEntity.addGraphic(entity.graphic); // 添加图形
37
38
  entity.start();
39
+ } else if (entity.type == "pointCloud" || entity.type == "heatMap") {
40
+ hnMap.map.map.addLayer(entity.layerEntity);
41
+ } else {
42
+ this.layerEntity.addGraphic(entity.graphic); // 添加图形
38
43
  }
39
44
  }
40
45
  }
@@ -47,6 +52,11 @@ export default (hnMap: any) => {
47
52
  return v.id !== entity.id;
48
53
  });
49
54
  console.log("layerEntity", this.layerEntity);
55
+ if (entity.type === "pointCloud" || entity.type === "heatMap") {
56
+ alert(entity.id);
57
+ hnMap.map.map.removeLayer(entity.id);
58
+ // entity.id.destroy();
59
+ }
50
60
  this.layerEntity.removeGraphic(entity.graphic);
51
61
  }
52
62
  }
@@ -113,7 +123,6 @@ export default (hnMap: any) => {
113
123
  // 添加属性弹窗
114
124
  addPopupByAttr() {
115
125
  this.layerEntity.bindPopup((event: any) => {
116
- console.log(event.graphic, "====event.graphic==");
117
126
  if (event.graphic.attr) {
118
127
  const data = event.graphic.attr;
119
128
  return mars3d.Util.getTemplateHtml({
@@ -381,6 +390,19 @@ export default (hnMap: any) => {
381
390
  entity.createCar();
382
391
  entity.chunkData = entity.joinLinePoint();
383
392
  entity.start();
393
+ } else if (entity.type == "pointCloud") {
394
+ hnMap.map.map.addLayer(entity.config);
395
+ } else if (entity.type == "heatMap") {
396
+ hnMap.map.map.addLayer(entity.config_heatmap);
397
+ hnMap.map.map.addLayer(entity.config_point);
398
+ hnMap.map.map.flyTo({
399
+ center: [
400
+ entity.option.position[0].lng,
401
+ entity.option.position[0].lat,
402
+ ],
403
+ duration: 2000,
404
+ essential: true,
405
+ });
384
406
  } else {
385
407
  hnMap.map.map.addLayer(entity.config);
386
408
  }