gdmap-utils 1.2.3 → 1.2.5
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/.husky/pre-commit +1 -1
- package/.prettierrc.json +17 -17
- package/README.md +467 -2
- package/dist/index.js +127 -7
- package/dist/index.js.map +1 -1
- package/docs/classes/MapUtils.md +153 -0
- package/docs/functions/createMapUtils.md +18 -0
- package/docs/functions/initMapSource.md +14 -0
- package/docs/globals.md +11 -0
- package/examples/1_init.html +23 -23
- package/examples/2_mapInit.html +48 -48
- package/examples/3_MarkerLayer.html +565 -565
- package/examples/4_LabelMarkerLayer.html +574 -574
- package/examples/5_markerCluster.html +528 -0
- package/index.html +134 -134
- package/package.json +54 -51
- package/scripts/cleanDocs.js +220 -0
- package/scripts/mergeDocs.js +129 -0
- package/src/LayerManager.ts +17 -1
- package/src/MapSourceImport.ts +23 -23
- package/src/MapUtils.ts +198 -22
- package/src/gdMap/gdHelper.ts +113 -85
- package/src/index.ts +3 -1
- package/src/layers/baseMarkerLayer/LabelMarkerLayer.ts +240 -240
- package/src/layers/baseMarkerLayer/MarkerLayer.ts +208 -208
- package/src/layers/baseMarkerLayer/index.ts +369 -354
- package/src/layers/clusterMarkerLayer/MarkerClusterLayer.ts +53 -53
- package/src/layers/clusterMarkerLayer/index.ts +204 -177
- package/src/layers/index.ts +9 -9
- package/src/types/MapUtils.d.ts +53 -53
- package/src/types/amap.d.ts +11 -11
- package/src/types/{BaseMarkerLayer.d.ts → baseMarkerLayer.d.ts} +86 -87
- package/src/types/clusterMarkerLayer.d.ts +89 -88
- package/src/types/index.d.ts +14 -14
- package/tsconfig.json +26 -26
- package/typedoc.json +22 -0
- package/webpack.config.js +125 -126
- package/src/gdMap/gdHelper.js +0 -194
|
@@ -0,0 +1,528 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html>
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8" />
|
|
5
|
+
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
|
6
|
+
<meta
|
|
7
|
+
name="viewport"
|
|
8
|
+
content="initial-scale=1.0, user-scalable=no, width=device-width"
|
|
9
|
+
/>
|
|
10
|
+
<link
|
|
11
|
+
rel="stylesheet"
|
|
12
|
+
href="https://cdn.jsdelivr.net/npm/reset.css@5.0.2/reset.min.css"
|
|
13
|
+
/>
|
|
14
|
+
<link
|
|
15
|
+
rel="stylesheet"
|
|
16
|
+
href="https://a.amap.com/jsapi_demos/static/demo-center/css/demo-center.css"
|
|
17
|
+
/>
|
|
18
|
+
<title>地图显示</title>
|
|
19
|
+
<style>
|
|
20
|
+
html,
|
|
21
|
+
body,
|
|
22
|
+
#container {
|
|
23
|
+
width: 100%;
|
|
24
|
+
height: 100%;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
.labelTitle {
|
|
28
|
+
background-color: rgba(27, 204, 253, 0.85);
|
|
29
|
+
border-radius: 8px;
|
|
30
|
+
padding: 8px 16px;
|
|
31
|
+
font-size: 16px;
|
|
32
|
+
font-weight: 600;
|
|
33
|
+
color: #fff;
|
|
34
|
+
border: 2px solid rgba(27, 204, 253, 1);
|
|
35
|
+
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
|
|
36
|
+
text-align: center;
|
|
37
|
+
min-width: 100px;
|
|
38
|
+
line-height: 1.4;
|
|
39
|
+
text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
|
|
40
|
+
transition: all 0.3s ease;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
.labelTitle:hover {
|
|
44
|
+
background-color: rgba(27, 204, 253, 1);
|
|
45
|
+
transform: translateY(-2px);
|
|
46
|
+
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
.control-panel {
|
|
50
|
+
position: fixed;
|
|
51
|
+
top: 10px;
|
|
52
|
+
left: 10px;
|
|
53
|
+
z-index: 1000;
|
|
54
|
+
background-color: white;
|
|
55
|
+
padding: 10px;
|
|
56
|
+
border-radius: 5px;
|
|
57
|
+
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
.control-panel button {
|
|
61
|
+
margin: 5px;
|
|
62
|
+
padding: 8px 12px;
|
|
63
|
+
cursor: pointer;
|
|
64
|
+
}
|
|
65
|
+
.sydw-label {
|
|
66
|
+
color: #000;
|
|
67
|
+
font-size: 17px;
|
|
68
|
+
}
|
|
69
|
+
.display-none {
|
|
70
|
+
visibility: hidden;
|
|
71
|
+
}
|
|
72
|
+
.amap-marker-label {
|
|
73
|
+
border: 0;
|
|
74
|
+
background-color: transparent;
|
|
75
|
+
box-shadow: none !important;
|
|
76
|
+
}
|
|
77
|
+
</style>
|
|
78
|
+
</head>
|
|
79
|
+
<body>
|
|
80
|
+
<div id="container"></div>
|
|
81
|
+
<!-- 控制按钮面板 -->
|
|
82
|
+
<div class="control-panel">
|
|
83
|
+
<button id="addBtn">添加标记</button>
|
|
84
|
+
<button id="removeBtn">删除标记</button>
|
|
85
|
+
<br /><br />
|
|
86
|
+
<input type="text" id="markerIdInput" placeholder="输入标记ID" />
|
|
87
|
+
<br /><br />
|
|
88
|
+
<button id="fitViewBtn">自适应视图</button>
|
|
89
|
+
<button id="zoomOutBtn">缩小视图</button>
|
|
90
|
+
<br /><br />
|
|
91
|
+
<button id="showBtn">显示图层</button>
|
|
92
|
+
<button id="hideBtn">隐藏图层</button>
|
|
93
|
+
<button id="getAllBtn">获取所有标记</button>
|
|
94
|
+
<br /><br />
|
|
95
|
+
<button id="clearAllBtn">清空所有标记</button>
|
|
96
|
+
<button id="destroyBtn">销毁图层</button>
|
|
97
|
+
</div>
|
|
98
|
+
<!-- 加载地图JSAPI脚本 -->
|
|
99
|
+
<!-- <script src="../dist/index.js"></script> -->
|
|
100
|
+
<script>
|
|
101
|
+
const data = [
|
|
102
|
+
{
|
|
103
|
+
id: 5194,
|
|
104
|
+
sydmc: '世茂滨江花园南区',
|
|
105
|
+
sydlx: '1',
|
|
106
|
+
ssqy: '潍坊街道',
|
|
107
|
+
cphm: '沪EB2317',
|
|
108
|
+
jd: 121.515844,
|
|
109
|
+
wd: 31.218427,
|
|
110
|
+
zt: 1,
|
|
111
|
+
sbsj: '2025-07-16 10:09:37',
|
|
112
|
+
dwsx: '1',
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
id: 2972,
|
|
116
|
+
sydmc: '滨江兰庭',
|
|
117
|
+
sydlx: '1',
|
|
118
|
+
ssqy: '潍坊街道',
|
|
119
|
+
cphm: '沪EB2317',
|
|
120
|
+
jd: 121.516452,
|
|
121
|
+
wd: 31.220885,
|
|
122
|
+
zt: 1,
|
|
123
|
+
sbsj: '2025-07-16 10:07:29',
|
|
124
|
+
dwsx: '0',
|
|
125
|
+
},
|
|
126
|
+
{
|
|
127
|
+
id: 2842,
|
|
128
|
+
sydmc: '浦城小区',
|
|
129
|
+
sydlx: '1',
|
|
130
|
+
ssqy: '潍坊街道',
|
|
131
|
+
cphm: '沪EB2317',
|
|
132
|
+
jd: 121.514702,
|
|
133
|
+
wd: 31.225064,
|
|
134
|
+
zt: 1,
|
|
135
|
+
sbsj: '2025-07-16 10:07:29',
|
|
136
|
+
dwsx: '1',
|
|
137
|
+
},
|
|
138
|
+
{
|
|
139
|
+
id: 1182,
|
|
140
|
+
sydmc: '南泉大楼',
|
|
141
|
+
sydlx: '1',
|
|
142
|
+
ssqy: '潍坊街道',
|
|
143
|
+
cphm: '沪EB2317',
|
|
144
|
+
jd: 121.521759,
|
|
145
|
+
wd: 31.219519,
|
|
146
|
+
zt: 1,
|
|
147
|
+
sbsj: '2025-07-16 10:07:29',
|
|
148
|
+
dwsx: '1',
|
|
149
|
+
},
|
|
150
|
+
{
|
|
151
|
+
id: 509,
|
|
152
|
+
sydmc: '东南新村',
|
|
153
|
+
sydlx: '1',
|
|
154
|
+
ssqy: '潍坊街道',
|
|
155
|
+
cphm: '沪EB2317',
|
|
156
|
+
jd: 121.515997,
|
|
157
|
+
wd: 31.225962,
|
|
158
|
+
zt: 1,
|
|
159
|
+
sbsj: '2025-07-16 10:07:29',
|
|
160
|
+
dwsx: '0',
|
|
161
|
+
},
|
|
162
|
+
{
|
|
163
|
+
id: 1603,
|
|
164
|
+
sydmc: '天后宫大楼',
|
|
165
|
+
sydlx: '1',
|
|
166
|
+
ssqy: '潍坊街道',
|
|
167
|
+
cphm: '沪EB2317',
|
|
168
|
+
jd: 121.515854,
|
|
169
|
+
wd: 31.226379,
|
|
170
|
+
zt: 1,
|
|
171
|
+
sbsj: '2025-07-16 10:07:29',
|
|
172
|
+
dwsx: '0',
|
|
173
|
+
},
|
|
174
|
+
{
|
|
175
|
+
id: 974,
|
|
176
|
+
sydmc: '兰园小区',
|
|
177
|
+
sydlx: '1',
|
|
178
|
+
ssqy: '潍坊街道',
|
|
179
|
+
cphm: '沪EB2317',
|
|
180
|
+
jd: 121.513274,
|
|
181
|
+
wd: 31.224613,
|
|
182
|
+
zt: 1,
|
|
183
|
+
sbsj: '2025-07-16 10:07:29',
|
|
184
|
+
dwsx: '0',
|
|
185
|
+
},
|
|
186
|
+
{
|
|
187
|
+
id: 3168,
|
|
188
|
+
sydmc: '百富达公寓',
|
|
189
|
+
sydlx: '1',
|
|
190
|
+
ssqy: '潍坊街道',
|
|
191
|
+
cphm: '沪EB2317',
|
|
192
|
+
jd: 121.517998,
|
|
193
|
+
wd: 31.219241,
|
|
194
|
+
zt: 1,
|
|
195
|
+
sbsj: '2025-07-16 10:07:29',
|
|
196
|
+
dwsx: '1',
|
|
197
|
+
},
|
|
198
|
+
{
|
|
199
|
+
id: 3526,
|
|
200
|
+
sydmc: '蔚蓝海岸天科苑',
|
|
201
|
+
sydlx: '1',
|
|
202
|
+
ssqy: '潍坊街道',
|
|
203
|
+
cphm: '沪EB2317',
|
|
204
|
+
jd: 121.51708,
|
|
205
|
+
wd: 31.220443,
|
|
206
|
+
zt: 1,
|
|
207
|
+
sbsj: '2025-07-16 10:07:29',
|
|
208
|
+
dwsx: '1',
|
|
209
|
+
},
|
|
210
|
+
{
|
|
211
|
+
id: 3059,
|
|
212
|
+
sydmc: '爱建大楼',
|
|
213
|
+
sydlx: '1',
|
|
214
|
+
ssqy: '潍坊街道',
|
|
215
|
+
cphm: '沪EB2317',
|
|
216
|
+
jd: 121.517637,
|
|
217
|
+
wd: 31.222101,
|
|
218
|
+
zt: 1,
|
|
219
|
+
sbsj: '2025-07-16 10:07:29',
|
|
220
|
+
dwsx: '1',
|
|
221
|
+
},
|
|
222
|
+
{
|
|
223
|
+
id: 3253,
|
|
224
|
+
sydmc: '竹南小区',
|
|
225
|
+
sydlx: '1',
|
|
226
|
+
ssqy: '潍坊街道',
|
|
227
|
+
cphm: '沪EB2317',
|
|
228
|
+
jd: 121.529235,
|
|
229
|
+
wd: 31.22615,
|
|
230
|
+
zt: 1,
|
|
231
|
+
sbsj: '2025-07-16 10:07:29',
|
|
232
|
+
dwsx: '1',
|
|
233
|
+
},
|
|
234
|
+
{
|
|
235
|
+
id: 1465,
|
|
236
|
+
sydmc: '地铁4号线世纪大道站',
|
|
237
|
+
sydlx: '0',
|
|
238
|
+
ssqy: '潍坊街道',
|
|
239
|
+
cphm: '沪EB2317',
|
|
240
|
+
jd: 121.528294,
|
|
241
|
+
wd: 31.228321,
|
|
242
|
+
zt: 1,
|
|
243
|
+
sbsj: '2025-07-16 10:07:29',
|
|
244
|
+
dwsx: '1',
|
|
245
|
+
},
|
|
246
|
+
{
|
|
247
|
+
id: 879,
|
|
248
|
+
sydmc: '众城公寓',
|
|
249
|
+
sydlx: '1',
|
|
250
|
+
ssqy: '潍坊街道',
|
|
251
|
+
cphm: '沪EB2317',
|
|
252
|
+
jd: 121.530018,
|
|
253
|
+
wd: 31.224475,
|
|
254
|
+
zt: 1,
|
|
255
|
+
sbsj: '2025-07-16 10:07:29',
|
|
256
|
+
dwsx: '0',
|
|
257
|
+
},
|
|
258
|
+
{
|
|
259
|
+
id: 3067,
|
|
260
|
+
sydmc: '爵士大厦',
|
|
261
|
+
sydlx: '1',
|
|
262
|
+
ssqy: '潍坊街道',
|
|
263
|
+
cphm: '沪EB2317',
|
|
264
|
+
jd: 121.529722,
|
|
265
|
+
wd: 31.225217,
|
|
266
|
+
zt: 1,
|
|
267
|
+
sbsj: '2025-07-16 10:07:29',
|
|
268
|
+
dwsx: '1',
|
|
269
|
+
},
|
|
270
|
+
{
|
|
271
|
+
id: 2726,
|
|
272
|
+
sydmc: '浦东南路1780弄',
|
|
273
|
+
sydlx: '1',
|
|
274
|
+
ssqy: '潍坊街道',
|
|
275
|
+
cphm: '沪EB2317',
|
|
276
|
+
jd: 121.518546,
|
|
277
|
+
wd: 31.216307,
|
|
278
|
+
zt: 1,
|
|
279
|
+
sbsj: '2025-07-16 10:07:29',
|
|
280
|
+
dwsx: '0',
|
|
281
|
+
},
|
|
282
|
+
{
|
|
283
|
+
id: 913,
|
|
284
|
+
sydmc: '保利One56',
|
|
285
|
+
sydlx: '1',
|
|
286
|
+
ssqy: '潍坊街道',
|
|
287
|
+
cphm: '沪EB2317',
|
|
288
|
+
jd: 121.513294,
|
|
289
|
+
wd: 31.21825,
|
|
290
|
+
zt: 1,
|
|
291
|
+
sbsj: '2025-07-16 10:07:29',
|
|
292
|
+
dwsx: '0',
|
|
293
|
+
},
|
|
294
|
+
{
|
|
295
|
+
id: 582,
|
|
296
|
+
sydmc: '东港公寓',
|
|
297
|
+
sydlx: '1',
|
|
298
|
+
ssqy: '潍坊街道',
|
|
299
|
+
cphm: '沪EB2317',
|
|
300
|
+
jd: 121.518218,
|
|
301
|
+
wd: 31.218001,
|
|
302
|
+
zt: 1,
|
|
303
|
+
sbsj: '2025-07-16 10:07:29',
|
|
304
|
+
dwsx: '0',
|
|
305
|
+
},
|
|
306
|
+
];
|
|
307
|
+
|
|
308
|
+
window.onload = () => {
|
|
309
|
+
// idDom获取
|
|
310
|
+
const getAllBtn = document.getElementById('getAllBtn');
|
|
311
|
+
const clearAllBtn = document.getElementById('clearAllBtn');
|
|
312
|
+
const removeByIdBtn = document.getElementById('removeByIdBtn');
|
|
313
|
+
const markerIdInput = document.getElementById('markerIdInput');
|
|
314
|
+
const fitViewBtn = document.getElementById('fitViewBtn');
|
|
315
|
+
const zoomOutBtn = document.getElementById('zoomOutBtn');
|
|
316
|
+
// 显示/隐藏/销毁
|
|
317
|
+
const destroyBtn = document.getElementById('destroyBtn');
|
|
318
|
+
const showBtn = document.getElementById('showBtn');
|
|
319
|
+
const hideBtn = document.getElementById('hideBtn');
|
|
320
|
+
|
|
321
|
+
const { createMapUtils, MapUtils: gdMapUtils } = GdMapUtils;
|
|
322
|
+
|
|
323
|
+
const loaderOpts = {
|
|
324
|
+
version: '2.0', // 指定要加载的 JSAPI 的版本,缺省时默认为 1.4.15
|
|
325
|
+
plugins: ['AMap.MarkerCluster'], // 需要使用的的插件列表,如比例尺'AMap.Scale'等
|
|
326
|
+
key: '9506c73ed67acb0a09f1aabf88df4819',
|
|
327
|
+
};
|
|
328
|
+
|
|
329
|
+
test();
|
|
330
|
+
const config = {
|
|
331
|
+
icon: 'https://www.shpfyh.com/static/img/sydw_icon.630a9e8f.png',
|
|
332
|
+
name: 'qy',
|
|
333
|
+
iconActive:
|
|
334
|
+
'https://www.shpfyh.com/static/img/sydw_icon_active.e3216544.png',
|
|
335
|
+
className: 'qyCollectionPoint',
|
|
336
|
+
size: [30, 30],
|
|
337
|
+
pixel: [0, 0],
|
|
338
|
+
windowConfig: {
|
|
339
|
+
offset: [0, -90],
|
|
340
|
+
},
|
|
341
|
+
updateTime: 10000 * 6, // 更新定时器时间
|
|
342
|
+
};
|
|
343
|
+
|
|
344
|
+
async function test() {
|
|
345
|
+
window.mapUtils = await createMapUtils(
|
|
346
|
+
{
|
|
347
|
+
viewMode: '2D', // 默认使用 2D 模式,如果希望使用带有俯仰角的 3D 模式,请设置 viewMode: '3D'
|
|
348
|
+
zoom: 11, // 初始化地图层级
|
|
349
|
+
center: [data[0].jd, data[1].wd], // 初始化地图中心点
|
|
350
|
+
mountSelector: 'container',
|
|
351
|
+
},
|
|
352
|
+
loaderOpts
|
|
353
|
+
);
|
|
354
|
+
|
|
355
|
+
const defaultIcon = gdMapUtils.createIcon({
|
|
356
|
+
size: config.size,
|
|
357
|
+
image: config.icon,
|
|
358
|
+
imageSize: config.size,
|
|
359
|
+
imageOffset: config.pixel,
|
|
360
|
+
});
|
|
361
|
+
|
|
362
|
+
// 激活图标
|
|
363
|
+
const activeIcon = gdMapUtils.createIcon({
|
|
364
|
+
size: config.size,
|
|
365
|
+
image: config.iconActive,
|
|
366
|
+
imageSize: config.size,
|
|
367
|
+
imageOffset: config.pixel,
|
|
368
|
+
});
|
|
369
|
+
|
|
370
|
+
//图层创建
|
|
371
|
+
window.clusterMarkerLayer = mapUtils.createClusterMarkerLayer({
|
|
372
|
+
layerType: 'markerClusterLayer',
|
|
373
|
+
layerName: 'sydwCollecte',
|
|
374
|
+
overlayList: data.slice(0, 10).map(item => {
|
|
375
|
+
return {
|
|
376
|
+
overlayData: {
|
|
377
|
+
lon: item.jd,
|
|
378
|
+
lat: item.wd,
|
|
379
|
+
title: item.sydmc,
|
|
380
|
+
id: item.id,
|
|
381
|
+
extData: item,
|
|
382
|
+
},
|
|
383
|
+
id: item.id,
|
|
384
|
+
labelShowed: false,
|
|
385
|
+
iconActive: false,
|
|
386
|
+
};
|
|
387
|
+
}),
|
|
388
|
+
layerOpts: {
|
|
389
|
+
gridSize: 80,
|
|
390
|
+
renderClusterMarker(context) {
|
|
391
|
+
// 绘制聚合点时调用
|
|
392
|
+
const count = data.length;
|
|
393
|
+
const factor = Math.pow(context.count / count, 1 / 18);
|
|
394
|
+
const div = document.createElement('div');
|
|
395
|
+
const Hue = 180 - factor * 180;
|
|
396
|
+
const bgColor = 'hsla(' + Hue + ',100%,50%,0.7)';
|
|
397
|
+
const fontColor = 'hsla(' + Hue + ',100%,20%,1)';
|
|
398
|
+
const borderColor = 'hsla(' + Hue + ',100%,40%,1)';
|
|
399
|
+
const shadowColor = 'hsla(' + Hue + ',100%,50%,1)';
|
|
400
|
+
div.style.backgroundColor = bgColor;
|
|
401
|
+
const size = Math.round(
|
|
402
|
+
30 + Math.pow(context.count / count, 1 / 5) * 20
|
|
403
|
+
);
|
|
404
|
+
div.style.width = div.style.height = size + 'px';
|
|
405
|
+
div.style.border = 'solid 1px ' + borderColor;
|
|
406
|
+
div.style.borderRadius = size / 2 + 'px';
|
|
407
|
+
div.style.boxShadow = '0 0 1px ' + shadowColor;
|
|
408
|
+
div.innerHTML = context.count;
|
|
409
|
+
div.style.lineHeight = size + 'px';
|
|
410
|
+
div.style.color = fontColor;
|
|
411
|
+
div.style.fontSize = '14px';
|
|
412
|
+
div.style.textAlign = 'center';
|
|
413
|
+
const Pixel = gdMapUtils.Size(-size / 2, -size / 2);
|
|
414
|
+
context.marker.setOffset(Pixel);
|
|
415
|
+
context.marker.setContent(div);
|
|
416
|
+
}, // 自定义聚合点样式
|
|
417
|
+
renderMarker: context => {
|
|
418
|
+
const {
|
|
419
|
+
overlayData: { extData },
|
|
420
|
+
iconActive,
|
|
421
|
+
labelShowed,
|
|
422
|
+
} = context.data[0];
|
|
423
|
+
|
|
424
|
+
const curIcon = iconActive ? activeIcon : defaultIcon;
|
|
425
|
+
|
|
426
|
+
context.marker.setOffset(gdMapUtils.Pixel(...config.pixel));
|
|
427
|
+
context.marker.setExtData(extData);
|
|
428
|
+
context.marker.setIcon(curIcon);
|
|
429
|
+
context.marker.setLabel({
|
|
430
|
+
offset: gdMapUtils.Pixel(0, 0),
|
|
431
|
+
content: `<div class="${!labelShowed ? 'display-none' : ''} sydw-label">${extData.sydmc}</div>`,
|
|
432
|
+
direction: 'top',
|
|
433
|
+
});
|
|
434
|
+
},
|
|
435
|
+
},
|
|
436
|
+
});
|
|
437
|
+
|
|
438
|
+
// 事件绑定
|
|
439
|
+
clusterMarkerLayer.bindEventOverlays('click', rest => {
|
|
440
|
+
const { lnglat, marker, clusterData } = rest;
|
|
441
|
+
|
|
442
|
+
clusterData[0].labelShowed = true;
|
|
443
|
+
|
|
444
|
+
if (clusterData.length > 1) {
|
|
445
|
+
//点击集合样式地图放大一级
|
|
446
|
+
mapUtils.map.setCenter(lnglat, false);
|
|
447
|
+
mapUtils.map.zoomIn(); // 放大地图
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
marker?.dom
|
|
451
|
+
?.querySelector('.sydw-label')
|
|
452
|
+
.classList.remove('display-none');
|
|
453
|
+
});
|
|
454
|
+
|
|
455
|
+
// 显示按钮点击事件
|
|
456
|
+
showBtn.addEventListener('click', () => {
|
|
457
|
+
clusterMarkerLayer.show();
|
|
458
|
+
});
|
|
459
|
+
|
|
460
|
+
// 隐藏按钮点击事件
|
|
461
|
+
hideBtn.addEventListener('click', () => {
|
|
462
|
+
clusterMarkerLayer.hide();
|
|
463
|
+
});
|
|
464
|
+
|
|
465
|
+
// 获取所有标记按钮点击事件
|
|
466
|
+
getAllBtn.addEventListener('click', () => {
|
|
467
|
+
const allMarkers = clusterMarkerLayer.overlayList;
|
|
468
|
+
|
|
469
|
+
alert(allMarkers.length + '个标记');
|
|
470
|
+
});
|
|
471
|
+
|
|
472
|
+
// 自适应按钮点击事件
|
|
473
|
+
fitViewBtn.addEventListener('click', () => {
|
|
474
|
+
mapUtils.map.setFitView();
|
|
475
|
+
});
|
|
476
|
+
|
|
477
|
+
clearAllBtn.addEventListener('click', () => {
|
|
478
|
+
clusterMarkerLayer.clearAllOverlay();
|
|
479
|
+
});
|
|
480
|
+
destroyBtn.addEventListener('click', () => {
|
|
481
|
+
clusterMarkerLayer.destroy();
|
|
482
|
+
});
|
|
483
|
+
|
|
484
|
+
zoomOutBtn.addEventListener('click', () => {
|
|
485
|
+
mapUtils.map.zoomOut();
|
|
486
|
+
});
|
|
487
|
+
const markerIdInput = document.querySelector('#markerIdInput');
|
|
488
|
+
// 添加一个新的标记按钮点击事件
|
|
489
|
+
addBtn.addEventListener('click', () => {
|
|
490
|
+
const newMarkerId = markerIdInput.value; // 生成一个唯一的ID
|
|
491
|
+
|
|
492
|
+
if (!newMarkerId) {
|
|
493
|
+
alert('请输入标记ID');
|
|
494
|
+
return;
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
// 创建一个新的标记数据
|
|
498
|
+
const newMarker = {
|
|
499
|
+
overlayData: {
|
|
500
|
+
lon: 121.515844 + Math.random() * 0.02 - 0.01, // 在中心点附近随机生成经度
|
|
501
|
+
lat: 31.218427 + Math.random() * 0.02 - 0.01, // 在中心点附近随机生成纬度
|
|
502
|
+
title: `新标记${newMarkerId}`,
|
|
503
|
+
id: newMarkerId,
|
|
504
|
+
extData: { id: newMarkerId, sydmc: `新标记${newMarkerId}` },
|
|
505
|
+
},
|
|
506
|
+
id: newMarkerId,
|
|
507
|
+
labelShowed: true,
|
|
508
|
+
iconActive: true,
|
|
509
|
+
};
|
|
510
|
+
|
|
511
|
+
clusterMarkerLayer.add([newMarker]);
|
|
512
|
+
});
|
|
513
|
+
|
|
514
|
+
removeBtn.addEventListener('click', () => {
|
|
515
|
+
const markerId = markerIdInput.value; // 生成一个唯一的ID
|
|
516
|
+
|
|
517
|
+
if (!markerId) {
|
|
518
|
+
alert('请输入标记ID');
|
|
519
|
+
return;
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
clusterMarkerLayer.remove([markerId]);
|
|
523
|
+
});
|
|
524
|
+
}
|
|
525
|
+
};
|
|
526
|
+
</script>
|
|
527
|
+
</body>
|
|
528
|
+
</html>
|