gdmap-utils 1.1.8 → 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/.husky/pre-commit +1 -1
- package/.prettierrc.json +17 -17
- package/README.md +50 -50
- package/dist/index.js +1 -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 +48 -45
- package/src/LayerManager.ts +49 -49
- package/src/MapSourceImport.ts +23 -23
- package/src/MapUtils.ts +154 -150
- package/src/gdMap/gdHelper.js +194 -194
- package/src/gdMap/gdHelper.ts +85 -85
- package/src/gdMapUtils.js +377 -377
- package/src/index.ts +1 -1
- package/src/layers/MarkerClusterLayer.ts +30 -30
- package/src/layers/baseMarkerLayer/LabelMarkerLayer.ts +238 -238
- package/src/layers/baseMarkerLayer/MarkerLayer.ts +206 -206
- package/src/layers/baseMarkerLayer/index.ts +354 -354
- package/src/layers/index.ts +5 -5
- package/src/layers copy/LabelMarkerLayer.js +122 -122
- package/src/layers copy/MarkerClusterLayer.js +155 -155
- package/src/layers copy/MarkerLayer.js +267 -267
- package/src/layers copy/OverlayGroupManager.js +254 -254
- 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/index.d.ts +12 -12
- package/tsconfig.json +26 -26
- package/webpack.config.js +104 -98
package/src/layers/index.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
// 图层模块入口文件
|
|
2
|
-
// 从baseMarkerLayer目录导入BaseMarkerLayer相关内容并重新导出
|
|
3
|
-
export type * from './baseMarkerLayer';
|
|
4
|
-
|
|
5
|
-
export { default as BaseMarkerLayer } from './baseMarkerLayer';
|
|
1
|
+
// 图层模块入口文件
|
|
2
|
+
// 从baseMarkerLayer目录导入BaseMarkerLayer相关内容并重新导出
|
|
3
|
+
export type * from './baseMarkerLayer';
|
|
4
|
+
|
|
5
|
+
export { default as BaseMarkerLayer } from './baseMarkerLayer';
|
|
@@ -1,122 +1,122 @@
|
|
|
1
|
-
import useEnvSanStore from '@/store/modules/envSan.js';
|
|
2
|
-
import GdMapUtils from '@/utils/gdMap/gdMapUtils.js';
|
|
3
|
-
|
|
4
|
-
// 海量点图层渲染封装
|
|
5
|
-
export default class LabelMarkerLayer {
|
|
6
|
-
dataList = []; // 数据列表
|
|
7
|
-
|
|
8
|
-
// 去掉私有属性标识
|
|
9
|
-
layerInstance = null; // 图层实例
|
|
10
|
-
|
|
11
|
-
// 去掉私有属性标识
|
|
12
|
-
isLayerCreated = false; // 图层是否已创建
|
|
13
|
-
|
|
14
|
-
envSanStore = useEnvSanStore(); // 使用环境状态存储
|
|
15
|
-
|
|
16
|
-
activeNames = []; // 存储激活图层显示name
|
|
17
|
-
/**
|
|
18
|
-
* 经纬度坐标,用来描述地图上的一个点位置
|
|
19
|
-
* @param {Object} config 图层的config
|
|
20
|
-
* @param {Function} createOverlay 创建marker的方法
|
|
21
|
-
* @param {Function} noWrap requestCallback 拉去marker请求数据并按规定格式返回
|
|
22
|
-
* @param {Boolean} detectingPosition 是否检测位置变化
|
|
23
|
-
*/
|
|
24
|
-
constructor({ config, createOverlay, requestCallback }) {
|
|
25
|
-
this.config = config ?? {}; //保存图层配置
|
|
26
|
-
|
|
27
|
-
this.createOverlay = createOverlay;
|
|
28
|
-
|
|
29
|
-
this.requestCallback = requestCallback;
|
|
30
|
-
|
|
31
|
-
this.activeNames = [
|
|
32
|
-
...(this?.config?.extraActiveName ?? []),
|
|
33
|
-
this.config.name,
|
|
34
|
-
]; //图层额外的激活数组
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
// 获取地图工具类实例
|
|
38
|
-
getGdMapUtilsIns(id = 'gisMap') {
|
|
39
|
-
return GdMapUtils.mapInstance.get(id);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
// 创建图层
|
|
43
|
-
async createLayer(gdMapUtils) {
|
|
44
|
-
// 获取数据
|
|
45
|
-
this.dataList = await this.requestCallback();
|
|
46
|
-
|
|
47
|
-
if (!this.shouldSkipLayerCreation) return; //避免网络时间过长用户切换到切tab
|
|
48
|
-
|
|
49
|
-
// 创建地图图层
|
|
50
|
-
this.layerInstance = gdMapUtils.createLabelLayer(this.config.layerOptions);
|
|
51
|
-
|
|
52
|
-
// 创建标记
|
|
53
|
-
let markers = this.dataList.map(item => {
|
|
54
|
-
return this.createOverlay(gdMapUtils, this.config, item);
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
this.layerInstance.add(markers); // 添加标记到图层
|
|
58
|
-
//HACK labelLayer没有统一绑定事件的方法
|
|
59
|
-
markers.forEach(overlay => {
|
|
60
|
-
overlay.on('click', e => {
|
|
61
|
-
const marker = e.target;
|
|
62
|
-
|
|
63
|
-
if (marker.getExtData().type === this.config.className) {
|
|
64
|
-
// 触发全局的地图弹框
|
|
65
|
-
gdMapUtils.trigger(
|
|
66
|
-
'pointerClick',
|
|
67
|
-
marker,
|
|
68
|
-
e,
|
|
69
|
-
gdMapUtils.map,
|
|
70
|
-
this.config
|
|
71
|
-
);
|
|
72
|
-
}
|
|
73
|
-
});
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
this.isLayerCreated = true; // 设置图层创建状态为true
|
|
77
|
-
|
|
78
|
-
markers = null; // 释放内存
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
// 显示图层
|
|
82
|
-
showLayer() {
|
|
83
|
-
if (
|
|
84
|
-
this.layerInstance &&
|
|
85
|
-
this.dataList.length &&
|
|
86
|
-
this.shouldSkipLayerCreation
|
|
87
|
-
) {
|
|
88
|
-
this.layerInstance.show(); // 显示图层
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
get shouldSkipLayerCreation() {
|
|
92
|
-
return this.activeNames.includes(this.envSanStore.mapActiveType);
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
// 隐藏图层
|
|
96
|
-
hideLayer() {
|
|
97
|
-
if (this.layerInstance && this.dataList.length) {
|
|
98
|
-
this.layerInstance.hide(); // 隐藏图层
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
// 监听地图类型变化
|
|
103
|
-
handleMapTypeChange(newVal, oldVal) {
|
|
104
|
-
let gdMapUtils = this.getGdMapUtilsIns(); // 获取地图实例
|
|
105
|
-
|
|
106
|
-
if (!gdMapUtils) return; // 如果地图实例不存在,则不执行后续操作
|
|
107
|
-
|
|
108
|
-
if (this.shouldSkipLayerCreation) {
|
|
109
|
-
if (this.isLayerCreated) {
|
|
110
|
-
this.showLayer(); // 显示图层
|
|
111
|
-
} else {
|
|
112
|
-
this.createLayer(gdMapUtils); // 创建图层
|
|
113
|
-
}
|
|
114
|
-
} else {
|
|
115
|
-
this.hideLayer(); // 隐藏图层
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
get dataOfLayer() {
|
|
120
|
-
return this.dataList;
|
|
121
|
-
}
|
|
122
|
-
}
|
|
1
|
+
import useEnvSanStore from '@/store/modules/envSan.js';
|
|
2
|
+
import GdMapUtils from '@/utils/gdMap/gdMapUtils.js';
|
|
3
|
+
|
|
4
|
+
// 海量点图层渲染封装
|
|
5
|
+
export default class LabelMarkerLayer {
|
|
6
|
+
dataList = []; // 数据列表
|
|
7
|
+
|
|
8
|
+
// 去掉私有属性标识
|
|
9
|
+
layerInstance = null; // 图层实例
|
|
10
|
+
|
|
11
|
+
// 去掉私有属性标识
|
|
12
|
+
isLayerCreated = false; // 图层是否已创建
|
|
13
|
+
|
|
14
|
+
envSanStore = useEnvSanStore(); // 使用环境状态存储
|
|
15
|
+
|
|
16
|
+
activeNames = []; // 存储激活图层显示name
|
|
17
|
+
/**
|
|
18
|
+
* 经纬度坐标,用来描述地图上的一个点位置
|
|
19
|
+
* @param {Object} config 图层的config
|
|
20
|
+
* @param {Function} createOverlay 创建marker的方法
|
|
21
|
+
* @param {Function} noWrap requestCallback 拉去marker请求数据并按规定格式返回
|
|
22
|
+
* @param {Boolean} detectingPosition 是否检测位置变化
|
|
23
|
+
*/
|
|
24
|
+
constructor({ config, createOverlay, requestCallback }) {
|
|
25
|
+
this.config = config ?? {}; //保存图层配置
|
|
26
|
+
|
|
27
|
+
this.createOverlay = createOverlay;
|
|
28
|
+
|
|
29
|
+
this.requestCallback = requestCallback;
|
|
30
|
+
|
|
31
|
+
this.activeNames = [
|
|
32
|
+
...(this?.config?.extraActiveName ?? []),
|
|
33
|
+
this.config.name,
|
|
34
|
+
]; //图层额外的激活数组
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// 获取地图工具类实例
|
|
38
|
+
getGdMapUtilsIns(id = 'gisMap') {
|
|
39
|
+
return GdMapUtils.mapInstance.get(id);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// 创建图层
|
|
43
|
+
async createLayer(gdMapUtils) {
|
|
44
|
+
// 获取数据
|
|
45
|
+
this.dataList = await this.requestCallback();
|
|
46
|
+
|
|
47
|
+
if (!this.shouldSkipLayerCreation) return; //避免网络时间过长用户切换到切tab
|
|
48
|
+
|
|
49
|
+
// 创建地图图层
|
|
50
|
+
this.layerInstance = gdMapUtils.createLabelLayer(this.config.layerOptions);
|
|
51
|
+
|
|
52
|
+
// 创建标记
|
|
53
|
+
let markers = this.dataList.map(item => {
|
|
54
|
+
return this.createOverlay(gdMapUtils, this.config, item);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
this.layerInstance.add(markers); // 添加标记到图层
|
|
58
|
+
//HACK labelLayer没有统一绑定事件的方法
|
|
59
|
+
markers.forEach(overlay => {
|
|
60
|
+
overlay.on('click', e => {
|
|
61
|
+
const marker = e.target;
|
|
62
|
+
|
|
63
|
+
if (marker.getExtData().type === this.config.className) {
|
|
64
|
+
// 触发全局的地图弹框
|
|
65
|
+
gdMapUtils.trigger(
|
|
66
|
+
'pointerClick',
|
|
67
|
+
marker,
|
|
68
|
+
e,
|
|
69
|
+
gdMapUtils.map,
|
|
70
|
+
this.config
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
this.isLayerCreated = true; // 设置图层创建状态为true
|
|
77
|
+
|
|
78
|
+
markers = null; // 释放内存
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// 显示图层
|
|
82
|
+
showLayer() {
|
|
83
|
+
if (
|
|
84
|
+
this.layerInstance &&
|
|
85
|
+
this.dataList.length &&
|
|
86
|
+
this.shouldSkipLayerCreation
|
|
87
|
+
) {
|
|
88
|
+
this.layerInstance.show(); // 显示图层
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
get shouldSkipLayerCreation() {
|
|
92
|
+
return this.activeNames.includes(this.envSanStore.mapActiveType);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// 隐藏图层
|
|
96
|
+
hideLayer() {
|
|
97
|
+
if (this.layerInstance && this.dataList.length) {
|
|
98
|
+
this.layerInstance.hide(); // 隐藏图层
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// 监听地图类型变化
|
|
103
|
+
handleMapTypeChange(newVal, oldVal) {
|
|
104
|
+
let gdMapUtils = this.getGdMapUtilsIns(); // 获取地图实例
|
|
105
|
+
|
|
106
|
+
if (!gdMapUtils) return; // 如果地图实例不存在,则不执行后续操作
|
|
107
|
+
|
|
108
|
+
if (this.shouldSkipLayerCreation) {
|
|
109
|
+
if (this.isLayerCreated) {
|
|
110
|
+
this.showLayer(); // 显示图层
|
|
111
|
+
} else {
|
|
112
|
+
this.createLayer(gdMapUtils); // 创建图层
|
|
113
|
+
}
|
|
114
|
+
} else {
|
|
115
|
+
this.hideLayer(); // 隐藏图层
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
get dataOfLayer() {
|
|
120
|
+
return this.dataList;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
@@ -1,155 +1,155 @@
|
|
|
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
|
-
}
|
|
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
|
+
}
|