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.
- package/dist/index.js +346 -57
- package/package.json +1 -1
- package/src/graphic/imagePoint.ts +1 -1
- package/src/index.ts +64 -31
- package/src/layer/heatMap.ts +310 -160
- package/src/layer/layer.ts +24 -2
- package/src/layer/pointCloud.ts +226 -78
package/src/layer/heatMap.ts
CHANGED
|
@@ -1,163 +1,313 @@
|
|
|
1
|
-
import {deepMerge, wgs84ToGcj02Format} from
|
|
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
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
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
|
+
};
|
package/src/layer/layer.ts
CHANGED
|
@@ -32,9 +32,14 @@ export default (hnMap: any) => {
|
|
|
32
32
|
console.error("已存在同名图形" + entity.id);
|
|
33
33
|
} else {
|
|
34
34
|
this.children.push(entity);
|
|
35
|
-
|
|
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
|
}
|