hn-map 1.0.10 → 1.1.1
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/README.md +5 -22
- package/dist/index.js +2313 -610
- package/package.json +11 -8
- package/src/base/gaode_entity.ts +61 -0
- package/src/base/mars3d_entity.ts +64 -0
- package/src/base/siji_entity.ts +118 -0
- package/src/graphic/circle.ts +218 -0
- package/src/graphic/divPoint.ts +133 -0
- package/src/graphic/imagePoint.ts +237 -0
- package/src/graphic/label.ts +330 -0
- package/src/graphic/line.ts +345 -0
- package/src/graphic/numPoint.ts +290 -0
- package/src/graphic/point.ts +234 -0
- package/src/graphic/polygon.ts +188 -0
- package/src/graphic/rectangle.ts +202 -0
- package/src/index.ts +213 -0
- package/src/layer/cluster.ts +276 -0
- package/src/layer/geoJson.ts +174 -0
- package/src/layer/heatMap.ts +163 -0
- package/src/layer/layer.ts +464 -0
- package/src/layer/pointCloud.ts +78 -0
- package/src/map.ts +433 -0
- package/src/other/route.ts +457 -0
- package/src/types/globals.d.ts +5 -0
- package/src/util.ts +216 -0
- package/src/base/gaode_entity.js +0 -59
- package/src/base/mars3d_entity.js +0 -50
- package/src/graphic/circle.js +0 -159
- package/src/graphic/divPoint.js +0 -86
- package/src/graphic/imagePoint.js +0 -163
- package/src/graphic/label.js +0 -176
- package/src/graphic/line.js +0 -203
- package/src/graphic/numPoint.js +0 -119
- package/src/graphic/point.js +0 -144
- package/src/graphic/polygon.js +0 -111
- package/src/graphic/rectangle.js +0 -115
- package/src/index.js +0 -105
- package/src/layer/cluster.js +0 -277
- package/src/layer/geoJson.js +0 -174
- package/src/layer/heatMap.js +0 -163
- package/src/layer/layer.js +0 -311
- package/src/layer/pointCloud.js +0 -78
- package/src/map.js +0 -303
- package/src/other/route.js +0 -217
- package/src/util.js +0 -103
|
@@ -0,0 +1,345 @@
|
|
|
1
|
+
import {deepMerge, getLevelMiddleHeight, wgs84ToGcj02Format} from "../util";
|
|
2
|
+
import mars3d_entity from "../base/mars3d_entity";
|
|
3
|
+
import gaode_entity from "../base/gaode_entity";
|
|
4
|
+
import siji_entity from "../base/siji_entity";
|
|
5
|
+
|
|
6
|
+
export default (hnMap: any) => {
|
|
7
|
+
const defaultOption = {
|
|
8
|
+
id: "",
|
|
9
|
+
position: [],
|
|
10
|
+
type: "line",
|
|
11
|
+
color: "#ffffff",
|
|
12
|
+
width: 2,
|
|
13
|
+
opacity: 1,
|
|
14
|
+
outline: false,
|
|
15
|
+
outlineColor: "#ffffff",
|
|
16
|
+
outlineWidth: 2,
|
|
17
|
+
dashColor: "#00ff00",
|
|
18
|
+
dashLength: 16,
|
|
19
|
+
image: "",
|
|
20
|
+
repeat: [1, 1],
|
|
21
|
+
speed: 5,
|
|
22
|
+
scaleByDistance: true,
|
|
23
|
+
distanceDisplayCondition: false,
|
|
24
|
+
distanceDisplayCondition_far: 1,
|
|
25
|
+
distanceDisplayCondition_near: 18,
|
|
26
|
+
data: null,
|
|
27
|
+
combine: false,
|
|
28
|
+
instances: [],
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
class mars3d_class extends mars3d_entity {
|
|
32
|
+
type: any = "line";
|
|
33
|
+
id: any = null;
|
|
34
|
+
option: any = JSON.parse(JSON.stringify(defaultOption));
|
|
35
|
+
config: any = null;
|
|
36
|
+
graphic: any = null;
|
|
37
|
+
|
|
38
|
+
constructor(option: any) {
|
|
39
|
+
// debugger
|
|
40
|
+
super(hnMap);
|
|
41
|
+
this.id = option.id;
|
|
42
|
+
deepMerge(this.option, option);
|
|
43
|
+
this.config = this.formatConfig(this.option);
|
|
44
|
+
if (option.combine) {
|
|
45
|
+
this.graphic = new mars3d.graphic.PolylineCombine(this.config);
|
|
46
|
+
} else {
|
|
47
|
+
this.graphic = new mars3d.graphic.PolylineEntity(this.config);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
formatConfig(option: any) {
|
|
52
|
+
let config: any = {};
|
|
53
|
+
const distanceDisplayCondition_far = getLevelMiddleHeight(option.distanceDisplayCondition_far)
|
|
54
|
+
const distanceDisplayCondition_near = getLevelMiddleHeight(option.distanceDisplayCondition_near)
|
|
55
|
+
if (option.combine) {
|
|
56
|
+
config = {
|
|
57
|
+
id: option.id,
|
|
58
|
+
combine: true,
|
|
59
|
+
instances: option.instances.map((item: any) => {
|
|
60
|
+
let itemOption = JSON.parse(JSON.stringify(defaultOption));
|
|
61
|
+
deepMerge(itemOption, item);
|
|
62
|
+
return this.formatConfig(itemOption);
|
|
63
|
+
}),
|
|
64
|
+
};
|
|
65
|
+
} else {
|
|
66
|
+
config = {
|
|
67
|
+
id: option.id,
|
|
68
|
+
positions: option.position,
|
|
69
|
+
style: {
|
|
70
|
+
materialType: "Color",
|
|
71
|
+
color: option.color,
|
|
72
|
+
width: option.width,
|
|
73
|
+
opacity: option.opacity,
|
|
74
|
+
outline: option.outline,
|
|
75
|
+
outlineColor: option.outlineColor,
|
|
76
|
+
outlineWidth: option.outlineWidth,
|
|
77
|
+
clampToGround: !option.position[0][2],
|
|
78
|
+
scaleByDistance: option.scaleByDistance,
|
|
79
|
+
distanceDisplayCondition: option.distanceDisplayCondition,
|
|
80
|
+
distanceDisplayCondition_far: distanceDisplayCondition_far,
|
|
81
|
+
distanceDisplayCondition_near: distanceDisplayCondition_near,
|
|
82
|
+
},
|
|
83
|
+
attr: option.data,
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
switch (option.type) {
|
|
87
|
+
case "line":
|
|
88
|
+
config.style.materialType = "Color";
|
|
89
|
+
break;
|
|
90
|
+
case "dash":
|
|
91
|
+
config.style.materialType = "PolylineDash";
|
|
92
|
+
config.style.materialOptions = {
|
|
93
|
+
color: option.color,
|
|
94
|
+
gapColor: option.dashColor,
|
|
95
|
+
dashPattern: option.dashPattern,
|
|
96
|
+
};
|
|
97
|
+
break;
|
|
98
|
+
case "flicker":
|
|
99
|
+
config.style.materialType = "LineFlicker";
|
|
100
|
+
config.style.materialOptions = {
|
|
101
|
+
color: option.color,
|
|
102
|
+
speed: option.speed,
|
|
103
|
+
};
|
|
104
|
+
break;
|
|
105
|
+
case "flow":
|
|
106
|
+
config.style.materialType = "LineFlow";
|
|
107
|
+
config.style.materialOptions = {
|
|
108
|
+
color: option.color,
|
|
109
|
+
image: option.image,
|
|
110
|
+
repeat: new Cesium.Cartesian2(option.repeat[0], option.repeat[1]),
|
|
111
|
+
speed: option.speed,
|
|
112
|
+
};
|
|
113
|
+
break;
|
|
114
|
+
case "arrow":
|
|
115
|
+
config.style.materialType = "PolylineArrow";
|
|
116
|
+
config.style.materialOptions = {
|
|
117
|
+
color: option.color,
|
|
118
|
+
};
|
|
119
|
+
break;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
return config;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
set(option: any) {
|
|
127
|
+
deepMerge(this.option, option);
|
|
128
|
+
this.config = this.formatConfig(this.option);
|
|
129
|
+
this.graphic.setOptions(this.config);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// flyTo(option = {}) {
|
|
133
|
+
// let config = {}
|
|
134
|
+
// if(option.height){
|
|
135
|
+
// config.scale = this.calculateScaleFromHeight(this.graphic, option.height)
|
|
136
|
+
// }
|
|
137
|
+
// console.log(config)
|
|
138
|
+
// this.graphic.flyTo(config);
|
|
139
|
+
// }
|
|
140
|
+
|
|
141
|
+
openPopup() {
|
|
142
|
+
this.graphic.openPopup();
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* 判断给定的经纬度坐标是否在某个多边形内
|
|
147
|
+
*
|
|
148
|
+
* @param {number} lng - 经度
|
|
149
|
+
* @param {number} lat - 纬度
|
|
150
|
+
* @returns {boolean} 返回一个布尔值,如果给定的坐标在多边形内则为true,否则为false
|
|
151
|
+
*/
|
|
152
|
+
isInPoly(lng: any, lat: any) {
|
|
153
|
+
return this.graphic.isInPoly(new mars3d.LngLatPoint(lng, lat));
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
class gaode_class extends gaode_entity {
|
|
158
|
+
id: any = null;
|
|
159
|
+
option: any = JSON.parse(JSON.stringify(defaultOption));
|
|
160
|
+
config: any = null;
|
|
161
|
+
graphic: any = null;
|
|
162
|
+
|
|
163
|
+
constructor(option: any) {
|
|
164
|
+
super(hnMap);
|
|
165
|
+
this.id = option.id;
|
|
166
|
+
deepMerge(this.option, option);
|
|
167
|
+
this.config = this.formatConfig(this.option);
|
|
168
|
+
this.graphic = new AMap.Polyline(this.config);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
formatConfig(option: any) {
|
|
172
|
+
let amapPosition = wgs84ToGcj02Format(option.position);
|
|
173
|
+
return {
|
|
174
|
+
path: amapPosition,
|
|
175
|
+
strokeColor: option.color,
|
|
176
|
+
strokeOpacity: option.opacity,
|
|
177
|
+
strokeWeight: option.width,
|
|
178
|
+
outlineColor: option.outlineColor,
|
|
179
|
+
borderWeight: option.outlineWidth,
|
|
180
|
+
extData: {
|
|
181
|
+
id: option.id,
|
|
182
|
+
data: option.data,
|
|
183
|
+
},
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
set(option: any) {
|
|
188
|
+
deepMerge(this.option, option);
|
|
189
|
+
this.config = this.formatConfig(this.option);
|
|
190
|
+
this.graphic.setOptions(this.config);
|
|
191
|
+
this.graphic.setPath(this.config.path);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
class siji_class extends siji_entity {
|
|
195
|
+
type: any = "line";
|
|
196
|
+
id: any = null;
|
|
197
|
+
option: any = JSON.parse(JSON.stringify(defaultOption));
|
|
198
|
+
config: any = null;
|
|
199
|
+
graphic: any = null;
|
|
200
|
+
intervalId: any = null;
|
|
201
|
+
constructor(option: any) {
|
|
202
|
+
// debugger;
|
|
203
|
+
super(hnMap);
|
|
204
|
+
this.id = option.id;
|
|
205
|
+
deepMerge(this.option, option);
|
|
206
|
+
this.config = this.formatConfig(this.option);
|
|
207
|
+
// this.graphic = hnMap.map.map.addLayer(this.config);
|
|
208
|
+
}
|
|
209
|
+
flickers(speed: number, isShow: boolean) {
|
|
210
|
+
if (this.intervalId !== null) {
|
|
211
|
+
clearInterval(this.intervalId);
|
|
212
|
+
}
|
|
213
|
+
let opacity = isShow ? 1 : 0;
|
|
214
|
+
const that = this;
|
|
215
|
+
this.intervalId = setInterval(() => {
|
|
216
|
+
isShow = !isShow;
|
|
217
|
+
opacity = isShow ? 1 : 0;
|
|
218
|
+
that.config["line-opacity"] = opacity;
|
|
219
|
+
}, speed);
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
formatConfig(option: any) {
|
|
223
|
+
let config: any = {};
|
|
224
|
+
config = {
|
|
225
|
+
id: option.id,
|
|
226
|
+
type: "line",
|
|
227
|
+
source: {
|
|
228
|
+
type: "geojson",
|
|
229
|
+
data: {
|
|
230
|
+
type: "FeatureCollection",
|
|
231
|
+
features: [
|
|
232
|
+
{
|
|
233
|
+
type: "Feature",
|
|
234
|
+
geometry: {
|
|
235
|
+
type: "LineString",
|
|
236
|
+
coordinates: option.position,
|
|
237
|
+
},
|
|
238
|
+
properties: {
|
|
239
|
+
id: option.id,
|
|
240
|
+
...option.data,
|
|
241
|
+
},
|
|
242
|
+
},
|
|
243
|
+
],
|
|
244
|
+
},
|
|
245
|
+
},
|
|
246
|
+
layout: {
|
|
247
|
+
"line-cap": "round",
|
|
248
|
+
"line-join": "round",
|
|
249
|
+
},
|
|
250
|
+
paint: {
|
|
251
|
+
"line-color": option.type == "dash" ? option.dashColor : option.color,
|
|
252
|
+
"line-width": Number(option.width),
|
|
253
|
+
"line-opacity": Number(option.opacity),
|
|
254
|
+
},
|
|
255
|
+
};
|
|
256
|
+
let isShow: boolean = true;
|
|
257
|
+
switch (option.type) {
|
|
258
|
+
case "line":
|
|
259
|
+
break;
|
|
260
|
+
case "dash":
|
|
261
|
+
config.paint["line-dasharray"] = [
|
|
262
|
+
option.dashLength * 1,
|
|
263
|
+
option.dashLength * 1,
|
|
264
|
+
];
|
|
265
|
+
|
|
266
|
+
break;
|
|
267
|
+
case "flicker":
|
|
268
|
+
this.flickers(option.speed * 1, isShow); // 调用 flickers 方法
|
|
269
|
+
break;
|
|
270
|
+
case "flow":
|
|
271
|
+
break;
|
|
272
|
+
case "arrow":
|
|
273
|
+
break;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
return config;
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
set(option: any) {
|
|
280
|
+
deepMerge(this.option, option);
|
|
281
|
+
this.config = this.formatConfig(this.option);
|
|
282
|
+
for (let key in this.config) {
|
|
283
|
+
if (this.config.hasOwnProperty(key)) {
|
|
284
|
+
if (key == "paint") {
|
|
285
|
+
for (let key2 in this.config[key]) {
|
|
286
|
+
if (this.config[key].hasOwnProperty(key2)) {
|
|
287
|
+
// 遍历 paint 属性
|
|
288
|
+
hnMap.map.map.setPaintProperty(
|
|
289
|
+
this.config.id,
|
|
290
|
+
key2,
|
|
291
|
+
key2 == "line-opacity" || key2 == "line-width"
|
|
292
|
+
? Number(this.config[key][key2])
|
|
293
|
+
: this.config[key][key2]
|
|
294
|
+
);
|
|
295
|
+
if (option.type == "dash") {
|
|
296
|
+
hnMap.map.map.setPaintProperty(
|
|
297
|
+
this.config.id,
|
|
298
|
+
"line-dasharray",
|
|
299
|
+
[option.dashLength, option.dashLength]
|
|
300
|
+
);
|
|
301
|
+
}
|
|
302
|
+
// else {
|
|
303
|
+
// hnMap.map.map.setPaintProperty(
|
|
304
|
+
// this.config.id,
|
|
305
|
+
// "line-dasharray",
|
|
306
|
+
// [0, 0]
|
|
307
|
+
// );
|
|
308
|
+
// }
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
openPopup() {
|
|
317
|
+
this.graphic.openPopup();
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
/**
|
|
321
|
+
* 判断给定的经纬度坐标是否在某个多边形内
|
|
322
|
+
*
|
|
323
|
+
* @param {number} lng - 经度
|
|
324
|
+
* @param {number} lat - 纬度
|
|
325
|
+
* @returns {boolean} 返回一个布尔值,如果给定的坐标在多边形内则为true,否则为false
|
|
326
|
+
*/
|
|
327
|
+
isInPoly(lng: any, lat: any) {
|
|
328
|
+
return this.graphic.isInPoly(new mars3d.LngLatPoint(lng, lat));
|
|
329
|
+
}
|
|
330
|
+
dispose() {
|
|
331
|
+
if (this.intervalId) {
|
|
332
|
+
clearInterval(this.intervalId); // 清除定时器
|
|
333
|
+
this.intervalId = null; // 重置定时器ID
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
const fn: any = {
|
|
339
|
+
mars3d: mars3d_class,
|
|
340
|
+
gaode: gaode_class,
|
|
341
|
+
siji: siji_class,
|
|
342
|
+
};
|
|
343
|
+
|
|
344
|
+
return fn[hnMap.mapType];
|
|
345
|
+
};
|
|
@@ -0,0 +1,290 @@
|
|
|
1
|
+
import {deepMerge, getLevelMiddleHeight, wgs84ToGcj02Format} from "../util";
|
|
2
|
+
import mars3d_entity from "../base/mars3d_entity";
|
|
3
|
+
import gaode_entity from "../base/gaode_entity";
|
|
4
|
+
import siji_entity from "../base/siji_entity";
|
|
5
|
+
export default (hnMap: any) => {
|
|
6
|
+
const defaultOption = {
|
|
7
|
+
id: "",
|
|
8
|
+
position: [],
|
|
9
|
+
num: 0,
|
|
10
|
+
color: "#ffffff",
|
|
11
|
+
opacity: 1,
|
|
12
|
+
size: 6,
|
|
13
|
+
fontColor: "#000000",
|
|
14
|
+
scale: 1,
|
|
15
|
+
scaleByDistance: true,
|
|
16
|
+
distanceDisplayCondition: false,
|
|
17
|
+
distanceDisplayCondition_far: 1,
|
|
18
|
+
distanceDisplayCondition_near: 18,
|
|
19
|
+
data: null,
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
class mars3d_class extends mars3d_entity {
|
|
23
|
+
type: any = "numPoint";
|
|
24
|
+
id: any = null;
|
|
25
|
+
option: any = JSON.parse(JSON.stringify(defaultOption));
|
|
26
|
+
config: any = null;
|
|
27
|
+
graphic: any = null;
|
|
28
|
+
|
|
29
|
+
constructor(option: any) {
|
|
30
|
+
super(hnMap);
|
|
31
|
+
this.id = option.id;
|
|
32
|
+
deepMerge(this.option, option);
|
|
33
|
+
this.config = this.formatConfig(this.option);
|
|
34
|
+
this.graphic = new mars3d.graphic.BillboardEntity(this.config);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
formatConfig(option: any) {
|
|
38
|
+
const distanceDisplayCondition_far = getLevelMiddleHeight(option.distanceDisplayCondition_far)
|
|
39
|
+
const distanceDisplayCondition_near = getLevelMiddleHeight(option.distanceDisplayCondition_near)
|
|
40
|
+
return {
|
|
41
|
+
id: option.id,
|
|
42
|
+
position: option.position,
|
|
43
|
+
style: {
|
|
44
|
+
image: mars3d.Util.getCircleImage(option.num, {
|
|
45
|
+
color: option.color,
|
|
46
|
+
radius: option.size / 2,
|
|
47
|
+
borderWidth: 0,
|
|
48
|
+
fontColor: option.fontColor,
|
|
49
|
+
}),
|
|
50
|
+
scale: option.scale,
|
|
51
|
+
clampToGround: !option.position[2],
|
|
52
|
+
scaleByDistance: option.scaleByDistance,
|
|
53
|
+
distanceDisplayCondition: option.distanceDisplayCondition,
|
|
54
|
+
distanceDisplayCondition_far: distanceDisplayCondition_far,
|
|
55
|
+
distanceDisplayCondition_near: distanceDisplayCondition_near,
|
|
56
|
+
},
|
|
57
|
+
attr: option.data,
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
set(option: any) {
|
|
62
|
+
deepMerge(this.option, option);
|
|
63
|
+
this.config = this.formatConfig(this.option);
|
|
64
|
+
this.graphic.setOptions(this.config);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
class gaode_class extends gaode_entity {
|
|
69
|
+
id: any = null;
|
|
70
|
+
option: any = JSON.parse(JSON.stringify(defaultOption));
|
|
71
|
+
config: any = null;
|
|
72
|
+
graphic: any = null;
|
|
73
|
+
|
|
74
|
+
constructor(option: any) {
|
|
75
|
+
super(hnMap);
|
|
76
|
+
this.id = option.id;
|
|
77
|
+
deepMerge(this.option, option);
|
|
78
|
+
this.config = this.formatConfig(this.option);
|
|
79
|
+
this.graphic = new AMap.Marker(this.config);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
formatConfig(option: any) {
|
|
83
|
+
const amapPosition = wgs84ToGcj02Format(option.position);
|
|
84
|
+
var markerContent = `<div style="
|
|
85
|
+
background-color: ${option.color || "#ffff00"};
|
|
86
|
+
font-size: ${option.size / 2}px;
|
|
87
|
+
border-radius: 50%;
|
|
88
|
+
width: ${option.size}px;
|
|
89
|
+
height: ${option.size}px;
|
|
90
|
+
text-align: center;
|
|
91
|
+
line-height: ${option.size}px;
|
|
92
|
+
color: ${option.fontColor};"
|
|
93
|
+
>${option.num}</div>`;
|
|
94
|
+
return {
|
|
95
|
+
id: option.id,
|
|
96
|
+
position: new AMap.LngLat(amapPosition[0], amapPosition[1]),
|
|
97
|
+
content: markerContent,
|
|
98
|
+
anchor: "top-center",
|
|
99
|
+
offset: [0, -20],
|
|
100
|
+
extData: {
|
|
101
|
+
id: option.id,
|
|
102
|
+
data: option.data,
|
|
103
|
+
},
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
set(option: any) {
|
|
108
|
+
deepMerge(this.option, option);
|
|
109
|
+
this.config = this.formatConfig(this.option);
|
|
110
|
+
this.graphic.setOptions(this.config);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
class siji_class extends siji_entity {
|
|
115
|
+
type: any = "numPoint";
|
|
116
|
+
id: any = null;
|
|
117
|
+
option: any = JSON.parse(JSON.stringify(defaultOption));
|
|
118
|
+
config: any = null;
|
|
119
|
+
configLabel: any = null;
|
|
120
|
+
|
|
121
|
+
constructor(option: any) {
|
|
122
|
+
super(hnMap);
|
|
123
|
+
this.id = option.id;
|
|
124
|
+
deepMerge(this.option, option);
|
|
125
|
+
this.config = this.formatConfig(this.option);
|
|
126
|
+
this.configLabel = this.formatConfigNum(this.option);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
formatConfig(option: any) {
|
|
130
|
+
let config: any = {};
|
|
131
|
+
config = {
|
|
132
|
+
id: option.id,
|
|
133
|
+
type: "circle",
|
|
134
|
+
source: {
|
|
135
|
+
type: "geojson",
|
|
136
|
+
data: {
|
|
137
|
+
type: "FeatureCollection",
|
|
138
|
+
features: [
|
|
139
|
+
{
|
|
140
|
+
type: "Feature",
|
|
141
|
+
geometry: {
|
|
142
|
+
type: "Point",
|
|
143
|
+
coordinates: option.position,
|
|
144
|
+
},
|
|
145
|
+
properties: {
|
|
146
|
+
name: option.text,
|
|
147
|
+
},
|
|
148
|
+
},
|
|
149
|
+
],
|
|
150
|
+
},
|
|
151
|
+
},
|
|
152
|
+
paint: {
|
|
153
|
+
"circle-opacity": Number(option.opacity),
|
|
154
|
+
"circle-radius": Number(option.size),
|
|
155
|
+
"circle-color": option.color,
|
|
156
|
+
}, // 填充样式
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
return config;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
formatConfigNum(option: any) {
|
|
163
|
+
let configLabel: any = {};
|
|
164
|
+
configLabel = {
|
|
165
|
+
id: "num_" + option.id,
|
|
166
|
+
type: "symbol",
|
|
167
|
+
source: {
|
|
168
|
+
type: "geojson",
|
|
169
|
+
data: {
|
|
170
|
+
type: "FeatureCollection",
|
|
171
|
+
features: [
|
|
172
|
+
{
|
|
173
|
+
type: "Feature",
|
|
174
|
+
geometry: {
|
|
175
|
+
type: "Point",
|
|
176
|
+
coordinates: option.position,
|
|
177
|
+
},
|
|
178
|
+
properties: {
|
|
179
|
+
name: option.num,
|
|
180
|
+
},
|
|
181
|
+
},
|
|
182
|
+
],
|
|
183
|
+
},
|
|
184
|
+
},
|
|
185
|
+
layout: {
|
|
186
|
+
"icon-anchor": "center",
|
|
187
|
+
"text-field": "{name}",
|
|
188
|
+
"text-size": Number(option.size),
|
|
189
|
+
"text-anchor": "center", // 顶部对齐
|
|
190
|
+
}, // 文本样式
|
|
191
|
+
paint: {
|
|
192
|
+
"text-color": option.fontColor,
|
|
193
|
+
}, // 填充样式
|
|
194
|
+
};
|
|
195
|
+
|
|
196
|
+
return configLabel;
|
|
197
|
+
}
|
|
198
|
+
set(option: any) {
|
|
199
|
+
deepMerge(this.option, option);
|
|
200
|
+
this.config = this.formatConfig(this.option);
|
|
201
|
+
this.configLabel = this.formatConfigNum(this.option);
|
|
202
|
+
|
|
203
|
+
let mySource = hnMap.map.map.getSource(this.config.id);
|
|
204
|
+
mySource.setData({
|
|
205
|
+
type: "FeatureCollection",
|
|
206
|
+
features: [
|
|
207
|
+
{
|
|
208
|
+
type: "Feature",
|
|
209
|
+
properties: { name: this.option.text },
|
|
210
|
+
geometry: {
|
|
211
|
+
type: "Point",
|
|
212
|
+
coordinates: this.option.position,
|
|
213
|
+
},
|
|
214
|
+
},
|
|
215
|
+
],
|
|
216
|
+
});
|
|
217
|
+
for (let key in this.config) {
|
|
218
|
+
if (this.config.hasOwnProperty(key)) {
|
|
219
|
+
if (key == "paint") {
|
|
220
|
+
for (let key2 in this.config[key]) {
|
|
221
|
+
if (this.config[key].hasOwnProperty(key2)) {
|
|
222
|
+
// 遍历 paint 属性
|
|
223
|
+
hnMap.map.map.setPaintProperty(
|
|
224
|
+
this.config.id,
|
|
225
|
+
key2,
|
|
226
|
+
key2 == "circle-opacity"
|
|
227
|
+
? Number(this.config[key][key2])
|
|
228
|
+
: this.config[key][key2]
|
|
229
|
+
);
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
// 数字更改
|
|
236
|
+
let mySource_num = hnMap.map.map.getSource(this.configLabel.id);
|
|
237
|
+
mySource_num.setData({
|
|
238
|
+
type: "FeatureCollection",
|
|
239
|
+
features: [
|
|
240
|
+
{
|
|
241
|
+
type: "Feature",
|
|
242
|
+
properties: { name: this.option.num },
|
|
243
|
+
geometry: {
|
|
244
|
+
type: "Point",
|
|
245
|
+
coordinates: this.option.position,
|
|
246
|
+
},
|
|
247
|
+
},
|
|
248
|
+
],
|
|
249
|
+
});
|
|
250
|
+
for (let key in this.configLabel) {
|
|
251
|
+
if (this.configLabel.hasOwnProperty(key)) {
|
|
252
|
+
if (key == "paint") {
|
|
253
|
+
for (let key2 in this.configLabel[key]) {
|
|
254
|
+
if (this.configLabel[key].hasOwnProperty(key2)) {
|
|
255
|
+
// 遍历 paint 属性
|
|
256
|
+
hnMap.map.map.setPaintProperty(
|
|
257
|
+
this.configLabel.id,
|
|
258
|
+
key2,
|
|
259
|
+
this.configLabel[key][key2]
|
|
260
|
+
);
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
if (key == "layout") {
|
|
265
|
+
for (let key2 in this.configLabel[key]) {
|
|
266
|
+
if (this.configLabel[key].hasOwnProperty(key2)) {
|
|
267
|
+
// 遍历 layout 属性
|
|
268
|
+
hnMap.map.map.setLayoutProperty(
|
|
269
|
+
this.configLabel.id,
|
|
270
|
+
key2,
|
|
271
|
+
key2 == "text-size"
|
|
272
|
+
? Number(this.configLabel[key][key2])
|
|
273
|
+
: this.configLabel[key][key2]
|
|
274
|
+
);
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
const fn: any = {
|
|
284
|
+
mars3d: mars3d_class,
|
|
285
|
+
gaode: gaode_class,
|
|
286
|
+
siji: siji_class,
|
|
287
|
+
};
|
|
288
|
+
|
|
289
|
+
return fn[hnMap.mapType];
|
|
290
|
+
};
|