gdmap-utils 1.2.2 → 1.2.3
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 +2 -2
- package/dist/index.js +94 -1
- package/dist/index.js.map +1 -1
- 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/index.html +134 -134
- package/package.json +51 -48
- package/src/LayerManager.ts +57 -49
- package/src/MapSourceImport.ts +23 -23
- package/src/MapUtils.ts +167 -154
- package/src/gdMap/gdHelper.js +194 -194
- package/src/gdMap/gdHelper.ts +85 -85
- package/src/index.ts +1 -1
- package/src/layers/baseMarkerLayer/LabelMarkerLayer.ts +240 -238
- package/src/layers/baseMarkerLayer/MarkerLayer.ts +208 -206
- package/src/layers/baseMarkerLayer/index.ts +354 -354
- package/src/layers/clusterMarkerLayer/MarkerClusterLayer.ts +53 -30
- package/src/layers/clusterMarkerLayer/index.ts +177 -0
- package/src/layers/index.ts +9 -5
- package/src/types/BaseMarkerLayer.d.ts +87 -87
- package/src/types/MapUtils.d.ts +53 -53
- package/src/types/amap.d.ts +11 -11
- package/src/types/clusterMarkerLayer.d.ts +88 -0
- package/src/types/index.d.ts +14 -12
- package/tsconfig.json +26 -26
- package/webpack.config.js +126 -126
- package/src/gdMapUtils.js +0 -377
- package/src/index.html +0 -14
- package/src/layers/clusterMarkerLayer/MarkerClusterLayer.js +0 -155
package/src/gdMapUtils.js
DELETED
|
@@ -1,377 +0,0 @@
|
|
|
1
|
-
import AMapLoader from '@amap/amap-jsapi-loader';
|
|
2
|
-
import gdHelperMixin from './gdHelper.js'; //抽取的高德mixin工具函数
|
|
3
|
-
import OverlayGroupManager from './layers/OverlayGroupManager.js';
|
|
4
|
-
import eventMixin from '../eventMixin.js';
|
|
5
|
-
import LayerManager from './LayerManager.js';
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* 针对高德的二次封装
|
|
9
|
-
* 目前高德地图使用的是 GCJ-02 坐标,如果你采集的是 WGS84 坐标或者其他,请先进行坐标转换
|
|
10
|
-
*/
|
|
11
|
-
class GdMapUtils {
|
|
12
|
-
// 地图实例对象
|
|
13
|
-
map = null;
|
|
14
|
-
//高德AMap对象
|
|
15
|
-
AMap = null;
|
|
16
|
-
// 地图Ui对象
|
|
17
|
-
AMapUI = null;
|
|
18
|
-
// loadOpts加载的配置信息 地图配置和加载地图配置分开
|
|
19
|
-
loadOpts = {};
|
|
20
|
-
// 地图容器id
|
|
21
|
-
id = '';
|
|
22
|
-
// 地图的配置对象
|
|
23
|
-
mapOpts = {};
|
|
24
|
-
|
|
25
|
-
mapTitleLayers = {}; //图层map对象 第三方图层
|
|
26
|
-
|
|
27
|
-
// 缓存实例集合
|
|
28
|
-
static mapInstance = new Map();
|
|
29
|
-
|
|
30
|
-
overlayGroupManagerMap = new Map(); //HACK 是否移入到OverlayGroupManager中。
|
|
31
|
-
|
|
32
|
-
// 图层实例映射
|
|
33
|
-
layerInstances = new Map();
|
|
34
|
-
|
|
35
|
-
// 图层管理器
|
|
36
|
-
layerManager = LayerManager;
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* 加载地图和初始化地图分开
|
|
40
|
-
* @param {Object} options 加载高德初始化地图配置
|
|
41
|
-
*/
|
|
42
|
-
//TODO 构造函数能够接收this.map对象
|
|
43
|
-
constructor(options) {
|
|
44
|
-
if (!options) {
|
|
45
|
-
this.error('请传入配置对象');
|
|
46
|
-
}
|
|
47
|
-
// 某些API加载前必须设置秘钥
|
|
48
|
-
window._AMapSecurityConfig = {
|
|
49
|
-
securityJsCode: process.env.VUE_APP_GD_MAP_CODE, // 安全密钥
|
|
50
|
-
};
|
|
51
|
-
options.key = process.env.VUE_APP_GD_MAP_KEY;
|
|
52
|
-
this.loadOpts = options;
|
|
53
|
-
this.clickMapRestMarkers = options.clickMapRestMarkers ?? true;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
error(msg) {
|
|
57
|
-
console.error(`[AmapUtils Error]:${msg}`);
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* 异步加载地图插件
|
|
62
|
-
* @param {String} plugins AMap.ToolBar
|
|
63
|
-
* @returns {Promise}
|
|
64
|
-
* @memberof GdMapUtils
|
|
65
|
-
*/
|
|
66
|
-
loadPlugins(plugins) {
|
|
67
|
-
return new Promise((resolve, reject) => {
|
|
68
|
-
this.AMap.plugin(plugins, function (result) {
|
|
69
|
-
resolve(result);
|
|
70
|
-
});
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
/**
|
|
75
|
-
* 异步加载UI插件
|
|
76
|
-
* @param {String} plugins overlay/AwesomeMarker
|
|
77
|
-
* @return {Promise}
|
|
78
|
-
* @memberof GdMapUtils
|
|
79
|
-
*/
|
|
80
|
-
loadUIPlugins(plugins) {
|
|
81
|
-
return new Promise((resolve, reject) => {
|
|
82
|
-
if (!this.AMapUI) {
|
|
83
|
-
reject(new Error('AMapUI is not initialized.')); // 提供错误信息
|
|
84
|
-
return;
|
|
85
|
-
}
|
|
86
|
-
this.AMapUI.loadUI(plugins, function (result) {
|
|
87
|
-
if (result) {
|
|
88
|
-
resolve(result);
|
|
89
|
-
} else {
|
|
90
|
-
reject(new Error('Failed to load UI plugin.')); // 处理加载失败的情况
|
|
91
|
-
}
|
|
92
|
-
});
|
|
93
|
-
});
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
/**
|
|
97
|
-
* 初始化地图
|
|
98
|
-
* @param {String} id DOM 的id
|
|
99
|
-
* @param {Object} options Map地图配置项
|
|
100
|
-
* @return {Promise}
|
|
101
|
-
* @memberof GdMapUtils
|
|
102
|
-
*/
|
|
103
|
-
initMap(id, options) {
|
|
104
|
-
this.id = id;
|
|
105
|
-
this.mapOpts = options;
|
|
106
|
-
return new Promise((resolve, reject) => {
|
|
107
|
-
// 确保每次的AMap都是合法的所以不分开创建
|
|
108
|
-
AMapLoader.load(this.loadOpts)
|
|
109
|
-
.then(AMap => {
|
|
110
|
-
// 将 AMap 全局对象挂载到 window 上
|
|
111
|
-
window.AMap = AMap;
|
|
112
|
-
|
|
113
|
-
this.AMapUI = window.AMapUI;
|
|
114
|
-
|
|
115
|
-
this.AMap = AMap;
|
|
116
|
-
|
|
117
|
-
this.map = new AMap.Map(this.id, this.mapOpts); //"container"为 <div> 容器的 id
|
|
118
|
-
|
|
119
|
-
resolve(this.map);
|
|
120
|
-
// 将当前实例存储到 mapInstance 中
|
|
121
|
-
GdMapUtils.mapInstance.set(id, this);
|
|
122
|
-
|
|
123
|
-
this.bindMapClickEvent(); //初始化绑定事件
|
|
124
|
-
})
|
|
125
|
-
.catch(e => {
|
|
126
|
-
reject(e);
|
|
127
|
-
console.error(e);
|
|
128
|
-
throw new Error(e);
|
|
129
|
-
});
|
|
130
|
-
});
|
|
131
|
-
}
|
|
132
|
-
/**
|
|
133
|
-
* 连接到已有地图
|
|
134
|
-
* @param {String} id DOM 的id
|
|
135
|
-
* @param {Object} map 已经存在的地图实例
|
|
136
|
-
* @return {Promise}
|
|
137
|
-
* @memberof GdMapUtils
|
|
138
|
-
*/
|
|
139
|
-
linkToExistMap(id, gdMapIns) {
|
|
140
|
-
if (!id || !('options' in gdMapIns)) {
|
|
141
|
-
//HACK map上挂属性标识他为地图实例
|
|
142
|
-
return this.error('请传入正确的地图id和地图实例');
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
this.id = id;
|
|
146
|
-
// 关联地图配置
|
|
147
|
-
this.mapOpts = gdMapIns.options;
|
|
148
|
-
|
|
149
|
-
this.AMap = AMap; //HACK 异步获取AMap对象, 根据map获取当前地图AMap
|
|
150
|
-
|
|
151
|
-
this.AMapUI = window.AMapUI; //HACK AMapUI 是个啥
|
|
152
|
-
|
|
153
|
-
this.map = gdMapIns; // 关联地图实例
|
|
154
|
-
|
|
155
|
-
this.bindMapClickEvent(); //初始化绑定事件
|
|
156
|
-
// 将当前实例存储到 mapInstance 中
|
|
157
|
-
GdMapUtils.mapInstance.set(id, this);
|
|
158
|
-
|
|
159
|
-
return this.map;
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
// 初始化绑定地图事件
|
|
163
|
-
bindMapClickEvent() {
|
|
164
|
-
this.map.on('click', () => {
|
|
165
|
-
if (this.clickMapRestMarkers) {
|
|
166
|
-
this.overlayGroupManagerMap.forEach(overlayGroup => {
|
|
167
|
-
overlayGroup.resetActiveMarker(); // 清除图层上的所有覆盖物
|
|
168
|
-
});
|
|
169
|
-
}
|
|
170
|
-
});
|
|
171
|
-
|
|
172
|
-
// 绑定缩放时间获取当前层级
|
|
173
|
-
this.map.on('zoomchange', () => {
|
|
174
|
-
const zoom = this.map.getZoom(); // 获取当前缩放级别
|
|
175
|
-
});
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
//给所有的marker绑定事件
|
|
179
|
-
bindEventMarker(type, clickType, callback) {
|
|
180
|
-
if (!this.getOverlayGroupManager(type)) {
|
|
181
|
-
return this.error('图层不存在,请检查输入!');
|
|
182
|
-
}
|
|
183
|
-
this.getOverlayGroupManager(type).bindEventMarker(clickType, callback); // 绑定事件到图层管理器
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
//创建点位
|
|
187
|
-
createMarker(type, Opts) {
|
|
188
|
-
const overlayGroupManager = this.createOverlayGroupManager(Opts, type); // 关联图层管理器
|
|
189
|
-
// 创建图标
|
|
190
|
-
const marker = new AMap.Marker(Opts);
|
|
191
|
-
|
|
192
|
-
// marker上地图
|
|
193
|
-
overlayGroupManager.addOverlay(marker);
|
|
194
|
-
|
|
195
|
-
return marker;
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
// 关联图层管理器
|
|
199
|
-
createOverlayGroupManager(overlays, overlayType) {
|
|
200
|
-
const overlayManager = this.getOverlayGroupManager(overlayType); //获取图层管理器
|
|
201
|
-
|
|
202
|
-
if (overlayManager) return overlayManager; //图层已经关联了
|
|
203
|
-
|
|
204
|
-
const overlayGroupManager = new OverlayGroupManager({
|
|
205
|
-
overlays,
|
|
206
|
-
overlayType,
|
|
207
|
-
map: this.map,
|
|
208
|
-
});
|
|
209
|
-
|
|
210
|
-
this.overlayGroupManagerMap.set(overlayType, overlayGroupManager); //保存图层管理器
|
|
211
|
-
|
|
212
|
-
return overlayGroupManager;
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
// 获取图层管理器
|
|
216
|
-
getOverlayGroupManager(overlayType) {
|
|
217
|
-
if (typeof overlayType !== 'string' && overlayType.length === 0) {
|
|
218
|
-
return this.error('请传入图层类型');
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
return this.overlayGroupManagerMap.get(overlayType);
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
updateMarker(marker, Opts) {
|
|
225
|
-
if (!marker) {
|
|
226
|
-
return this.error('参数错误');
|
|
227
|
-
}
|
|
228
|
-
// 获取旧marker的类型
|
|
229
|
-
const { type } = marker.getExtData();
|
|
230
|
-
// 移除点位数据
|
|
231
|
-
this.removeMarker(type, marker);
|
|
232
|
-
// 更新Marker
|
|
233
|
-
this.createMarker(type, Opts);
|
|
234
|
-
}
|
|
235
|
-
//移除某一个marker或者多个marker
|
|
236
|
-
removeMarker(overlayType, overlay) {
|
|
237
|
-
if (!this.overlayGroupManagerMap.has(overlayType)) {
|
|
238
|
-
return this.error('图层不存在,请检查输入!');
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
const overlayGroupManager = this.getOverlayGroupManager(overlayType);
|
|
242
|
-
|
|
243
|
-
overlayGroupManager.removeOverlay(overlay); // 关联图层管理器
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
// 清楚所有覆盖物
|
|
247
|
-
removeAllOverlay() {
|
|
248
|
-
//BUG 这里只能移除用overlayGroupManagerManager管理的图层
|
|
249
|
-
this.overlayGroupManagerMap.forEach(overlayGroup => {
|
|
250
|
-
overlayGroup.OverlayGroup.clearOverlays(); // 清除图层上的所有覆盖物
|
|
251
|
-
});
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
// 高德地图添加覆盖物
|
|
255
|
-
mapToAdd(overlay, autoFit = true) {
|
|
256
|
-
this.map.add(overlay);
|
|
257
|
-
// 调整到合适的视角
|
|
258
|
-
// autoFit && this.map.setFitView();
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
// 创建海量点图层
|
|
262
|
-
createMarkerCluster(data, options) {
|
|
263
|
-
return new AMap.MarkerCluster(this.map, data, options);
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
// 创建标签图层
|
|
267
|
-
createLabelLayer(options) {
|
|
268
|
-
return new AMap.LabelLayer(options);
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
/**
|
|
272
|
-
* 通过图层类型创建图层
|
|
273
|
-
* @param {string} layerType - 图层类型
|
|
274
|
-
* @param {Object} options - 图层配置选项
|
|
275
|
-
* @returns {Object} 图层控制器实例
|
|
276
|
-
*/
|
|
277
|
-
createLayer(layerType, options) {
|
|
278
|
-
// 使用图层管理器创建图层控制器实例
|
|
279
|
-
const layerController = this.layerManager.createLayer(layerType, options);
|
|
280
|
-
|
|
281
|
-
if (layerController) {
|
|
282
|
-
// 存储图层实例
|
|
283
|
-
this.layerInstances.set(
|
|
284
|
-
options?.config?.name || layerType,
|
|
285
|
-
layerController
|
|
286
|
-
);
|
|
287
|
-
|
|
288
|
-
// 初始化创建图层
|
|
289
|
-
layerController.createLayer(this).catch(err => {
|
|
290
|
-
console.error(
|
|
291
|
-
`[GdMapUtils Error]: Failed to create layer '${layerType}':`,
|
|
292
|
-
err
|
|
293
|
-
);
|
|
294
|
-
});
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
return layerController;
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
/**
|
|
301
|
-
* 获取指定名称的图层实例
|
|
302
|
-
* @param {string} layerName - 图层名称
|
|
303
|
-
* @returns {Object|null} 图层控制器实例
|
|
304
|
-
*/
|
|
305
|
-
getLayer(layerName) {
|
|
306
|
-
return this.layerInstances.get(layerName);
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
/**
|
|
310
|
-
* 移除指定名称的图层
|
|
311
|
-
* @param {string} layerName - 图层名称
|
|
312
|
-
* @returns {boolean} 是否移除成功
|
|
313
|
-
*/
|
|
314
|
-
removeLayer(layerName) {
|
|
315
|
-
const layerController = this.layerInstances.get(layerName);
|
|
316
|
-
|
|
317
|
-
if (layerController) {
|
|
318
|
-
// 隐藏图层
|
|
319
|
-
if (typeof layerController.hideLayer === 'function') {
|
|
320
|
-
layerController.hideLayer();
|
|
321
|
-
}
|
|
322
|
-
|
|
323
|
-
// 从映射中移除
|
|
324
|
-
this.layerInstances.delete(layerName);
|
|
325
|
-
return true;
|
|
326
|
-
}
|
|
327
|
-
|
|
328
|
-
return false;
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
/**
|
|
332
|
-
* 获取所有图层实例
|
|
333
|
-
* @returns {Array} 图层控制器实例数组
|
|
334
|
-
*/
|
|
335
|
-
getAllLayers() {
|
|
336
|
-
return Array.from(this.layerInstances.values());
|
|
337
|
-
}
|
|
338
|
-
|
|
339
|
-
/**
|
|
340
|
-
* 显示指定名称的图层
|
|
341
|
-
* @param {string} layerName - 图层名称
|
|
342
|
-
* @returns {boolean} 是否显示成功
|
|
343
|
-
*/
|
|
344
|
-
showLayer(layerName) {
|
|
345
|
-
const layerController = this.layerInstances.get(layerName);
|
|
346
|
-
|
|
347
|
-
if (layerController && typeof layerController.showLayer === 'function') {
|
|
348
|
-
layerController.showLayer();
|
|
349
|
-
return true;
|
|
350
|
-
}
|
|
351
|
-
|
|
352
|
-
return false;
|
|
353
|
-
}
|
|
354
|
-
|
|
355
|
-
/**
|
|
356
|
-
* 隐藏指定名称的图层
|
|
357
|
-
* @param {string} layerName - 图层名称
|
|
358
|
-
* @returns {boolean} 是否隐藏成功
|
|
359
|
-
*/
|
|
360
|
-
hideLayer(layerName) {
|
|
361
|
-
const layerController = this.layerInstances.get(layerName);
|
|
362
|
-
|
|
363
|
-
if (layerController && typeof layerController.hideLayer === 'function') {
|
|
364
|
-
layerController.hideLayer();
|
|
365
|
-
return true;
|
|
366
|
-
}
|
|
367
|
-
|
|
368
|
-
return false;
|
|
369
|
-
}
|
|
370
|
-
}
|
|
371
|
-
// 加载工具类方法到gdMapUtils中
|
|
372
|
-
Object.assign(GdMapUtils.prototype, {
|
|
373
|
-
...eventMixin,
|
|
374
|
-
...gdHelperMixin,
|
|
375
|
-
});
|
|
376
|
-
|
|
377
|
-
export default GdMapUtils;
|
package/src/index.html
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
<!DOCTYPE html>
|
|
2
|
-
<html lang="zh-CN">
|
|
3
|
-
<head>
|
|
4
|
-
<meta charset="UTF-8">
|
|
5
|
-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
6
|
-
<title><%= htmlWebpackPlugin.options.title %></title>
|
|
7
|
-
</head>
|
|
8
|
-
<body>
|
|
9
|
-
<h1>地图工具库演示</h1>
|
|
10
|
-
<div id="app">
|
|
11
|
-
<p>使用 F12 打开控制台,查看 MapUtils 的使用示例。</p>
|
|
12
|
-
</div>
|
|
13
|
-
</body>
|
|
14
|
-
</html>
|
|
@@ -1,155 +0,0 @@
|
|
|
1
|
-
// import useEnvSanStore from "@/store/modules/envSan.js";
|
|
2
|
-
import GdMapUtils from '@/utils/gdMap/gdMapUtils.js';
|
|
3
|
-
|
|
4
|
-
/*
|
|
5
|
-
CollectionPointLayerController
|
|
6
|
-
*/
|
|
7
|
-
// 海量点图层渲染封装
|
|
8
|
-
export default class MarkerClusterLayer {
|
|
9
|
-
dataList = []; // 数据列表
|
|
10
|
-
|
|
11
|
-
// 去掉私有属性标识
|
|
12
|
-
layerInstance = null; // 图层实例
|
|
13
|
-
|
|
14
|
-
// 去掉私有属性标识
|
|
15
|
-
isLayerCreated = false; // 图层是否已创建
|
|
16
|
-
|
|
17
|
-
activeNames = []; // 存储激活图层显示name
|
|
18
|
-
/**
|
|
19
|
-
* 经纬度坐标,用来描述地图上的一个点位置
|
|
20
|
-
* @param {Object} config 图层的config
|
|
21
|
-
* @param {Function} createOverlay 创建marker的方法
|
|
22
|
-
* @param {Function} noWrap requestCallback 拉去marker请求数据并按规定格式返回
|
|
23
|
-
* @param {Boolean} detectingPosition 是否检测位置变化
|
|
24
|
-
*/
|
|
25
|
-
constructor({ config, createOverlay, requestCallback }) {
|
|
26
|
-
this.config = config ?? {}; //保存图层配置
|
|
27
|
-
|
|
28
|
-
this.createOverlay = createOverlay;
|
|
29
|
-
|
|
30
|
-
this.requestCallback = requestCallback;
|
|
31
|
-
|
|
32
|
-
this.activeNames = [
|
|
33
|
-
...(this?.config?.extraActiveName ?? []),
|
|
34
|
-
this.config.name,
|
|
35
|
-
]; //图层额外的激活数组
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
// 获取地图工具类实例
|
|
39
|
-
getGdMapUtilsIns(id = 'gisMap') {
|
|
40
|
-
return GdMapUtils.mapInstance.get(id);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
// 创建图层
|
|
44
|
-
async createLayer(gdMapUtils) {
|
|
45
|
-
// 获取数据
|
|
46
|
-
this.dataList = await this.requestCallback();
|
|
47
|
-
|
|
48
|
-
const { dataList, config } = this; //保存数据
|
|
49
|
-
|
|
50
|
-
if (!this.shouldCreationLayer(config.name)) return; //避免网络时间过长用户切换到切tab
|
|
51
|
-
|
|
52
|
-
// 创建海量点渲染
|
|
53
|
-
this.layerInstance = gdMapUtils.createMarkerCluster(dataList, {
|
|
54
|
-
gridSize: 80,
|
|
55
|
-
_renderClusterMarker(context) {
|
|
56
|
-
// 绘制聚合点时调用
|
|
57
|
-
const count = dataList.length;
|
|
58
|
-
const factor = Math.pow(context.count / count, 1 / 18);
|
|
59
|
-
const div = document.createElement('div');
|
|
60
|
-
const Hue = 180 - factor * 180;
|
|
61
|
-
const bgColor = 'hsla(' + Hue + ',100%,50%,0.7)';
|
|
62
|
-
const fontColor = 'hsla(' + Hue + ',100%,20%,1)';
|
|
63
|
-
const borderColor = 'hsla(' + Hue + ',100%,40%,1)';
|
|
64
|
-
const shadowColor = 'hsla(' + Hue + ',100%,50%,1)';
|
|
65
|
-
div.style.backgroundColor = bgColor;
|
|
66
|
-
const size = Math.round(
|
|
67
|
-
30 + Math.pow(context.count / count, 1 / 5) * 20
|
|
68
|
-
);
|
|
69
|
-
div.style.width = div.style.height = size + 'px';
|
|
70
|
-
div.style.border = 'solid 1px ' + borderColor;
|
|
71
|
-
div.style.borderRadius = size / 2 + 'px';
|
|
72
|
-
div.style.boxShadow = '0 0 1px ' + shadowColor;
|
|
73
|
-
div.innerHTML = context.count;
|
|
74
|
-
div.style.lineHeight = size + 'px';
|
|
75
|
-
div.style.color = fontColor;
|
|
76
|
-
div.style.fontSize = '14px';
|
|
77
|
-
div.style.textAlign = 'center';
|
|
78
|
-
const Pixel = gdMapUtils.Size(-size / 2, -size / 2);
|
|
79
|
-
context.marker.setOffset(Pixel);
|
|
80
|
-
context.marker.setContent(div);
|
|
81
|
-
}, // 自定义聚合点样式
|
|
82
|
-
_renderMarker: context => {
|
|
83
|
-
// 外部控制单个marker的样式
|
|
84
|
-
this.createOverlay({ context, gdMapUtils, config }); // 创建marker
|
|
85
|
-
},
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
// 绑定监听控制label显示
|
|
89
|
-
this.layerInstance.on('click', e => {
|
|
90
|
-
const { lnglat, marker, clusterData } = e;
|
|
91
|
-
|
|
92
|
-
if (clusterData.length > 1) {
|
|
93
|
-
//点击集合样式地图放大一级
|
|
94
|
-
gdMapUtils.setCenter(lnglat, false);
|
|
95
|
-
gdMapUtils.map.zoomIn(); // 放大地图
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
if (marker instanceof AMap.Marker) {
|
|
99
|
-
// marker?.dom?.querySelector('.sydw-label').classList.remove('display-none');
|
|
100
|
-
gdMapUtils.trigger(
|
|
101
|
-
'pointerClick',
|
|
102
|
-
marker,
|
|
103
|
-
e,
|
|
104
|
-
gdMapUtils.map,
|
|
105
|
-
this.config
|
|
106
|
-
);
|
|
107
|
-
}
|
|
108
|
-
});
|
|
109
|
-
|
|
110
|
-
this.isLayerCreated = true; // 设置图层创建状态为true
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
// 显示图层
|
|
114
|
-
showLayer(v) {
|
|
115
|
-
if (
|
|
116
|
-
this.layerInstance &&
|
|
117
|
-
this.dataList.length &&
|
|
118
|
-
this.shouldCreationLayer(v)
|
|
119
|
-
) {
|
|
120
|
-
this.layerInstance.setData(this.dataList);
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
// 判断是否跳过图层创建
|
|
124
|
-
shouldCreationLayer(activeName) {
|
|
125
|
-
return this.activeNames.includes(activeName);
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
// 隐藏图层
|
|
129
|
-
hideLayer() {
|
|
130
|
-
if (this.layerInstance && this.dataList.length) {
|
|
131
|
-
this.layerInstance.setData([]);
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
// 监听地图类型变化
|
|
136
|
-
handleMapTypeChange(newVal, oldVal) {
|
|
137
|
-
let gdMapUtils = this.getGdMapUtilsIns(); // 获取地图实例
|
|
138
|
-
|
|
139
|
-
if (!gdMapUtils) return; // 如果地图实例不存在,则不执行后续操作
|
|
140
|
-
|
|
141
|
-
if (this.shouldCreationLayer(newVal)) {
|
|
142
|
-
if (this.isLayerCreated) {
|
|
143
|
-
this.showLayer(newVal); // 显示图层
|
|
144
|
-
} else {
|
|
145
|
-
this.createLayer(gdMapUtils); // 创建图层
|
|
146
|
-
}
|
|
147
|
-
} else {
|
|
148
|
-
this.hideLayer(); // 隐藏图层
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
get dataOfLayer() {
|
|
153
|
-
return this.dataList;
|
|
154
|
-
}
|
|
155
|
-
}
|