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
package/index.html
CHANGED
|
@@ -1,135 +1,135 @@
|
|
|
1
|
-
<!doctype html>
|
|
2
|
-
<html lang="en">
|
|
3
|
-
<head>
|
|
4
|
-
<meta charset="utf-8">
|
|
5
|
-
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
|
6
|
-
<meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=device-width">
|
|
7
|
-
<title>点聚合</title>
|
|
8
|
-
<link rel="stylesheet" href="https://a.amap.com/jsapi_demos/static/demo-center/css/demo-center.css"/>
|
|
9
|
-
<style>
|
|
10
|
-
html, body, #container {
|
|
11
|
-
height: 100%;
|
|
12
|
-
width: 100%;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
.input-card {
|
|
16
|
-
width: 25rem;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
.input-card .btn {
|
|
20
|
-
width: 7rem;
|
|
21
|
-
margin-right: .7rem;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
.input-card .btn:last-child {
|
|
25
|
-
margin-right: 0;
|
|
26
|
-
}
|
|
27
|
-
</style>
|
|
28
|
-
</head>
|
|
29
|
-
<body>
|
|
30
|
-
<div id="container" class="map" tabindex="0"></div>
|
|
31
|
-
<div class="input-card">
|
|
32
|
-
<h4>聚合点效果切换</h4>
|
|
33
|
-
<div class="input-item">
|
|
34
|
-
<input type="button" class="btn" value="默认样式" id="add0" onclick='addCluster(0)'/>
|
|
35
|
-
<input type="button" class="btn" value="自定义图标" id="add1" onclick='addCluster(1)'/>
|
|
36
|
-
<input type="button" class="btn" value="完全自定义" id="add2" onclick='addCluster(2)'/>
|
|
37
|
-
</div>
|
|
38
|
-
</div>
|
|
39
|
-
<script src="//a.amap.com/jsapi_demos/static/china.js"></script>
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
<script src="https://webapi.amap.com/maps?v=2.0&key=9506c73ed67acb0a09f1aabf88df4819&plugin=AMap.MarkerCluster"></script>
|
|
43
|
-
|
|
44
|
-
<script type="text/javascript">
|
|
45
|
-
var cluster;
|
|
46
|
-
|
|
47
|
-
var map = new AMap.Map("container", {
|
|
48
|
-
center: [104.937478,35.439575],
|
|
49
|
-
zoom: 5
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
var gridSize = 60
|
|
53
|
-
// 数据中需包含经纬度信息字段 lnglat
|
|
54
|
-
// var points = [
|
|
55
|
-
// { lnglat: ["108.939621", "34.343147"] },
|
|
56
|
-
// { lnglat: ["112.985037", "23.15046"] },
|
|
57
|
-
// ...
|
|
58
|
-
// ...
|
|
59
|
-
// ]
|
|
60
|
-
var count = points.length;
|
|
61
|
-
|
|
62
|
-
var _renderClusterMarker = function (context) {
|
|
63
|
-
var factor = Math.pow(context.count / count, 1 / 18);
|
|
64
|
-
var div = document.createElement('div');
|
|
65
|
-
var Hue = 180 - factor * 180;
|
|
66
|
-
var bgColor = 'hsla(' + Hue + ',100%,40%,0.7)';
|
|
67
|
-
var fontColor = 'hsla(' + Hue + ',100%,90%,1)';
|
|
68
|
-
var borderColor = 'hsla(' + Hue + ',100%,40%,1)';
|
|
69
|
-
var shadowColor = 'hsla(' + Hue + ',100%,90%,1)';
|
|
70
|
-
div.style.backgroundColor = bgColor;
|
|
71
|
-
var size = Math.round(30 + Math.pow(context.count / count, 1 / 5) * 20);
|
|
72
|
-
div.style.width = div.style.height = size + 'px';
|
|
73
|
-
div.style.border = 'solid 1px ' + borderColor;
|
|
74
|
-
div.style.borderRadius = size / 2 + 'px';
|
|
75
|
-
div.style.boxShadow = '0 0 5px ' + shadowColor;
|
|
76
|
-
div.innerHTML = context.count;
|
|
77
|
-
div.style.lineHeight = size + 'px';
|
|
78
|
-
div.style.color = fontColor;
|
|
79
|
-
div.style.fontSize = '14px';
|
|
80
|
-
div.style.textAlign = 'center';
|
|
81
|
-
context.marker.setOffset(new AMap.Pixel(-size / 2, -size / 2));
|
|
82
|
-
context.marker.setContent(div)
|
|
83
|
-
};
|
|
84
|
-
var _renderMarker = function(context) {
|
|
85
|
-
var content = '<div style="background-color: hsla(180, 100%, 50%, 0.3); height: 18px; width: 18px; border: 1px solid hsl(180, 100%, 40%); border-radius: 12px; box-shadow: hsl(180, 100%, 50%) 0px 0px 3px;"></div>';
|
|
86
|
-
var offset = new AMap.Pixel(-9, -9);
|
|
87
|
-
context.marker.setContent(content)
|
|
88
|
-
context.marker.setOffset(offset)
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
addCluster(2);
|
|
92
|
-
|
|
93
|
-
function addCluster(tag) {
|
|
94
|
-
if (cluster) {
|
|
95
|
-
cluster.setMap(null);
|
|
96
|
-
}
|
|
97
|
-
if (tag == 2) {//完全自定义
|
|
98
|
-
cluster = new AMap.MarkerCluster(map, points, {
|
|
99
|
-
gridSize: gridSize, // 设置网格像素大小
|
|
100
|
-
renderClusterMarker: _renderClusterMarker, // 自定义聚合点样式
|
|
101
|
-
renderMarker: _renderMarker, // 自定义非聚合点样式
|
|
102
|
-
});
|
|
103
|
-
} else if (tag == 1) {//自定义图标
|
|
104
|
-
var sts = [{
|
|
105
|
-
url: "//a.amap.com/jsapi_demos/static/images/blue.png",
|
|
106
|
-
size: new AMap.Size(32, 32),
|
|
107
|
-
offset: new AMap.Pixel(-16, -16)
|
|
108
|
-
}, {
|
|
109
|
-
url: "//a.amap.com/jsapi_demos/static/images/green.png",
|
|
110
|
-
size: new AMap.Size(32, 32),
|
|
111
|
-
offset: new AMap.Pixel(-16, -16)
|
|
112
|
-
}, {
|
|
113
|
-
url: "//a.amap.com/jsapi_demos/static/images/orange.png",
|
|
114
|
-
size: new AMap.Size(36, 36),
|
|
115
|
-
offset: new AMap.Pixel(-18, -18)
|
|
116
|
-
}, {
|
|
117
|
-
url: "//a.amap.com/jsapi_demos/static/images/red.png",
|
|
118
|
-
size: new AMap.Size(48, 48),
|
|
119
|
-
offset: new AMap.Pixel(-24, -24)
|
|
120
|
-
}, {
|
|
121
|
-
url: "//a.amap.com/jsapi_demos/static/images/darkRed.png",
|
|
122
|
-
size: new AMap.Size(48, 48),
|
|
123
|
-
offset: new AMap.Pixel(-24, -24)
|
|
124
|
-
}];
|
|
125
|
-
cluster = new AMap.MarkerCluster(map, points, {
|
|
126
|
-
styles: sts,
|
|
127
|
-
gridSize: gridSize
|
|
128
|
-
});
|
|
129
|
-
} else {//默认样式
|
|
130
|
-
cluster = new AMap.MarkerCluster(map, points, {gridSize: gridSize});
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
</script>
|
|
134
|
-
</body>
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8">
|
|
5
|
+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
|
6
|
+
<meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=device-width">
|
|
7
|
+
<title>点聚合</title>
|
|
8
|
+
<link rel="stylesheet" href="https://a.amap.com/jsapi_demos/static/demo-center/css/demo-center.css"/>
|
|
9
|
+
<style>
|
|
10
|
+
html, body, #container {
|
|
11
|
+
height: 100%;
|
|
12
|
+
width: 100%;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
.input-card {
|
|
16
|
+
width: 25rem;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
.input-card .btn {
|
|
20
|
+
width: 7rem;
|
|
21
|
+
margin-right: .7rem;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
.input-card .btn:last-child {
|
|
25
|
+
margin-right: 0;
|
|
26
|
+
}
|
|
27
|
+
</style>
|
|
28
|
+
</head>
|
|
29
|
+
<body>
|
|
30
|
+
<div id="container" class="map" tabindex="0"></div>
|
|
31
|
+
<div class="input-card">
|
|
32
|
+
<h4>聚合点效果切换</h4>
|
|
33
|
+
<div class="input-item">
|
|
34
|
+
<input type="button" class="btn" value="默认样式" id="add0" onclick='addCluster(0)'/>
|
|
35
|
+
<input type="button" class="btn" value="自定义图标" id="add1" onclick='addCluster(1)'/>
|
|
36
|
+
<input type="button" class="btn" value="完全自定义" id="add2" onclick='addCluster(2)'/>
|
|
37
|
+
</div>
|
|
38
|
+
</div>
|
|
39
|
+
<script src="//a.amap.com/jsapi_demos/static/china.js"></script>
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
<script src="https://webapi.amap.com/maps?v=2.0&key=9506c73ed67acb0a09f1aabf88df4819&plugin=AMap.MarkerCluster"></script>
|
|
43
|
+
|
|
44
|
+
<script type="text/javascript">
|
|
45
|
+
var cluster;
|
|
46
|
+
|
|
47
|
+
var map = new AMap.Map("container", {
|
|
48
|
+
center: [104.937478,35.439575],
|
|
49
|
+
zoom: 5
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
var gridSize = 60
|
|
53
|
+
// 数据中需包含经纬度信息字段 lnglat
|
|
54
|
+
// var points = [
|
|
55
|
+
// { lnglat: ["108.939621", "34.343147"] },
|
|
56
|
+
// { lnglat: ["112.985037", "23.15046"] },
|
|
57
|
+
// ...
|
|
58
|
+
// ...
|
|
59
|
+
// ]
|
|
60
|
+
var count = points.length;
|
|
61
|
+
|
|
62
|
+
var _renderClusterMarker = function (context) {
|
|
63
|
+
var factor = Math.pow(context.count / count, 1 / 18);
|
|
64
|
+
var div = document.createElement('div');
|
|
65
|
+
var Hue = 180 - factor * 180;
|
|
66
|
+
var bgColor = 'hsla(' + Hue + ',100%,40%,0.7)';
|
|
67
|
+
var fontColor = 'hsla(' + Hue + ',100%,90%,1)';
|
|
68
|
+
var borderColor = 'hsla(' + Hue + ',100%,40%,1)';
|
|
69
|
+
var shadowColor = 'hsla(' + Hue + ',100%,90%,1)';
|
|
70
|
+
div.style.backgroundColor = bgColor;
|
|
71
|
+
var size = Math.round(30 + Math.pow(context.count / count, 1 / 5) * 20);
|
|
72
|
+
div.style.width = div.style.height = size + 'px';
|
|
73
|
+
div.style.border = 'solid 1px ' + borderColor;
|
|
74
|
+
div.style.borderRadius = size / 2 + 'px';
|
|
75
|
+
div.style.boxShadow = '0 0 5px ' + shadowColor;
|
|
76
|
+
div.innerHTML = context.count;
|
|
77
|
+
div.style.lineHeight = size + 'px';
|
|
78
|
+
div.style.color = fontColor;
|
|
79
|
+
div.style.fontSize = '14px';
|
|
80
|
+
div.style.textAlign = 'center';
|
|
81
|
+
context.marker.setOffset(new AMap.Pixel(-size / 2, -size / 2));
|
|
82
|
+
context.marker.setContent(div)
|
|
83
|
+
};
|
|
84
|
+
var _renderMarker = function(context) {
|
|
85
|
+
var content = '<div style="background-color: hsla(180, 100%, 50%, 0.3); height: 18px; width: 18px; border: 1px solid hsl(180, 100%, 40%); border-radius: 12px; box-shadow: hsl(180, 100%, 50%) 0px 0px 3px;"></div>';
|
|
86
|
+
var offset = new AMap.Pixel(-9, -9);
|
|
87
|
+
context.marker.setContent(content)
|
|
88
|
+
context.marker.setOffset(offset)
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
addCluster(2);
|
|
92
|
+
|
|
93
|
+
function addCluster(tag) {
|
|
94
|
+
if (cluster) {
|
|
95
|
+
cluster.setMap(null);
|
|
96
|
+
}
|
|
97
|
+
if (tag == 2) {//完全自定义
|
|
98
|
+
cluster = new AMap.MarkerCluster(map, points, {
|
|
99
|
+
gridSize: gridSize, // 设置网格像素大小
|
|
100
|
+
renderClusterMarker: _renderClusterMarker, // 自定义聚合点样式
|
|
101
|
+
renderMarker: _renderMarker, // 自定义非聚合点样式
|
|
102
|
+
});
|
|
103
|
+
} else if (tag == 1) {//自定义图标
|
|
104
|
+
var sts = [{
|
|
105
|
+
url: "//a.amap.com/jsapi_demos/static/images/blue.png",
|
|
106
|
+
size: new AMap.Size(32, 32),
|
|
107
|
+
offset: new AMap.Pixel(-16, -16)
|
|
108
|
+
}, {
|
|
109
|
+
url: "//a.amap.com/jsapi_demos/static/images/green.png",
|
|
110
|
+
size: new AMap.Size(32, 32),
|
|
111
|
+
offset: new AMap.Pixel(-16, -16)
|
|
112
|
+
}, {
|
|
113
|
+
url: "//a.amap.com/jsapi_demos/static/images/orange.png",
|
|
114
|
+
size: new AMap.Size(36, 36),
|
|
115
|
+
offset: new AMap.Pixel(-18, -18)
|
|
116
|
+
}, {
|
|
117
|
+
url: "//a.amap.com/jsapi_demos/static/images/red.png",
|
|
118
|
+
size: new AMap.Size(48, 48),
|
|
119
|
+
offset: new AMap.Pixel(-24, -24)
|
|
120
|
+
}, {
|
|
121
|
+
url: "//a.amap.com/jsapi_demos/static/images/darkRed.png",
|
|
122
|
+
size: new AMap.Size(48, 48),
|
|
123
|
+
offset: new AMap.Pixel(-24, -24)
|
|
124
|
+
}];
|
|
125
|
+
cluster = new AMap.MarkerCluster(map, points, {
|
|
126
|
+
styles: sts,
|
|
127
|
+
gridSize: gridSize
|
|
128
|
+
});
|
|
129
|
+
} else {//默认样式
|
|
130
|
+
cluster = new AMap.MarkerCluster(map, points, {gridSize: gridSize});
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
</script>
|
|
134
|
+
</body>
|
|
135
135
|
</html>
|
package/package.json
CHANGED
|
@@ -1,51 +1,54 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "gdmap-utils",
|
|
3
|
-
"version": "1.2.
|
|
4
|
-
"description": "高德地图工具库",
|
|
5
|
-
"main": "dist/index.js",
|
|
6
|
-
"types": "dist/index.d.ts",
|
|
7
|
-
"scripts": {
|
|
8
|
-
"build": "cross-env NODE_ENV=production webpack --mode production",
|
|
9
|
-
"dev": "cross-env NODE_ENV=development webpack serve --mode development",
|
|
10
|
-
"test": "echo \"Error: no test specified\" && exit 1",
|
|
11
|
-
"format": "prettier --write \"src/**/*.{ts,tsx,js,jsx,json,css,md}\"",
|
|
12
|
-
"format:check": "prettier --check \"src/**/*.{ts,tsx,js,jsx,json,css,md}\"",
|
|
13
|
-
"prepare": "husky",
|
|
14
|
-
"release": "npm run build && npm publish"
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
"
|
|
19
|
-
"
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
"
|
|
23
|
-
"
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
"@types
|
|
29
|
-
"
|
|
30
|
-
"
|
|
31
|
-
"
|
|
32
|
-
"
|
|
33
|
-
"
|
|
34
|
-
"
|
|
35
|
-
"
|
|
36
|
-
"
|
|
37
|
-
"
|
|
38
|
-
"
|
|
39
|
-
"
|
|
40
|
-
"
|
|
41
|
-
"
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
"
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
}
|
|
51
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "gdmap-utils",
|
|
3
|
+
"version": "1.2.5",
|
|
4
|
+
"description": "高德地图工具库",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"build": "cross-env NODE_ENV=production webpack --mode production",
|
|
9
|
+
"dev": "cross-env NODE_ENV=development webpack serve --mode development",
|
|
10
|
+
"test": "echo \"Error: no test specified\" && exit 1",
|
|
11
|
+
"format": "prettier --write \"src/**/*.{ts,tsx,js,jsx,json,css,md}\"",
|
|
12
|
+
"format:check": "prettier --check \"src/**/*.{ts,tsx,js,jsx,json,css,md}\"",
|
|
13
|
+
"prepare": "husky",
|
|
14
|
+
"release": "npm run build && npm publish --registry https://registry.npmjs.org/",
|
|
15
|
+
"docs": "typedoc && node scripts/cleanDocs.js"
|
|
16
|
+
},
|
|
17
|
+
"keywords": [
|
|
18
|
+
"map",
|
|
19
|
+
"utils",
|
|
20
|
+
"typescript"
|
|
21
|
+
],
|
|
22
|
+
"author": "quyue",
|
|
23
|
+
"license": "ISC",
|
|
24
|
+
"peerDependencies": {
|
|
25
|
+
"@amap/amap-jsapi-loader": "^1.0.1"
|
|
26
|
+
},
|
|
27
|
+
"devDependencies": {
|
|
28
|
+
"@amap/amap-jsapi-types": "^0.0.15",
|
|
29
|
+
"@types/node": "^24.10.1",
|
|
30
|
+
"cross-env": "^10.1.0",
|
|
31
|
+
"fork-ts-checker-webpack-plugin": "^9.1.0",
|
|
32
|
+
"html-webpack-plugin": "^5.6.6",
|
|
33
|
+
"husky": "^9.1.7",
|
|
34
|
+
"lint-staged": "^16.2.7",
|
|
35
|
+
"prettier": "^3.7.4",
|
|
36
|
+
"ts-loader": "^9.5.4",
|
|
37
|
+
"type-fest": "^5.3.1",
|
|
38
|
+
"typedoc": "^0.28.16",
|
|
39
|
+
"typedoc-plugin-markdown": "^4.9.0",
|
|
40
|
+
"typescript": "^5.9.3",
|
|
41
|
+
"webpack": "^5.103.0",
|
|
42
|
+
"webpack-cli": "^6.0.1",
|
|
43
|
+
"webpack-dev-server": "^5.2.3",
|
|
44
|
+
"yargs": "^18.0.0"
|
|
45
|
+
},
|
|
46
|
+
"lint-staged": {
|
|
47
|
+
"src/**/*.{ts,tsx,js,jsx,json,css,md}": [
|
|
48
|
+
"prettier --write"
|
|
49
|
+
]
|
|
50
|
+
},
|
|
51
|
+
"volta": {
|
|
52
|
+
"node": "22.22.0"
|
|
53
|
+
}
|
|
54
|
+
}
|
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
|
|
4
|
+
// 要处理的文档目录
|
|
5
|
+
const docsDir = path.join(__dirname, '../docs');
|
|
6
|
+
// 源代码目录
|
|
7
|
+
const srcDir = path.join(__dirname, '../src');
|
|
8
|
+
|
|
9
|
+
// 从TypeScript源文件中提取方法参数类型
|
|
10
|
+
function extractMethodParamTypes() {
|
|
11
|
+
const paramTypes = {};
|
|
12
|
+
|
|
13
|
+
// 递归遍历源代码文件
|
|
14
|
+
function traverseDir(dir) {
|
|
15
|
+
const files = fs.readdirSync(dir);
|
|
16
|
+
|
|
17
|
+
files.forEach(file => {
|
|
18
|
+
const filePath = path.join(dir, file);
|
|
19
|
+
const stats = fs.statSync(filePath);
|
|
20
|
+
|
|
21
|
+
if (stats.isDirectory()) {
|
|
22
|
+
traverseDir(filePath);
|
|
23
|
+
} else if (path.extname(file) === '.ts') {
|
|
24
|
+
const content = fs.readFileSync(filePath, 'utf8');
|
|
25
|
+
|
|
26
|
+
// 按行读取文件内容
|
|
27
|
+
const lines = content.split('\n');
|
|
28
|
+
let currentMethod = null;
|
|
29
|
+
let currentParams = [];
|
|
30
|
+
let inMethod = false;
|
|
31
|
+
|
|
32
|
+
lines.forEach(line => {
|
|
33
|
+
// 检查是否是方法定义的开始
|
|
34
|
+
const methodStartMatch = line.match(/(?:public|private|protected)?\s*(\w+)\s*<[^>]*>?\s*\(([^)]*)\)\s*(?::\s*([^\{]+))?\s*(?:\{|=>)/);
|
|
35
|
+
|
|
36
|
+
if (methodStartMatch) {
|
|
37
|
+
// 如果之前有正在处理的方法,保存它
|
|
38
|
+
if (currentMethod && currentParams.length > 0) {
|
|
39
|
+
paramTypes[currentMethod] = currentParams;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// 开始处理新方法
|
|
43
|
+
currentMethod = methodStartMatch[1];
|
|
44
|
+
currentParams = [];
|
|
45
|
+
inMethod = true;
|
|
46
|
+
|
|
47
|
+
// 提取当前行的参数
|
|
48
|
+
const paramsStr = methodStartMatch[2];
|
|
49
|
+
if (paramsStr && paramsStr.trim() !== '') {
|
|
50
|
+
const params = paramsStr.split(',').map(param => {
|
|
51
|
+
const paramMatch = param.trim().match(/(\w+)\s*:\s*([^=]+)/);
|
|
52
|
+
if (paramMatch) {
|
|
53
|
+
return {
|
|
54
|
+
name: paramMatch[1],
|
|
55
|
+
type: paramMatch[2].trim()
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
return null;
|
|
59
|
+
}).filter(Boolean);
|
|
60
|
+
|
|
61
|
+
currentParams = currentParams.concat(params);
|
|
62
|
+
}
|
|
63
|
+
} else if (inMethod) {
|
|
64
|
+
// 检查是否是方法定义的结束
|
|
65
|
+
if (line.trim() === '{' || line.trim() === '};') {
|
|
66
|
+
// 保存当前方法
|
|
67
|
+
if (currentMethod && currentParams.length > 0) {
|
|
68
|
+
paramTypes[currentMethod] = currentParams;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
currentMethod = null;
|
|
72
|
+
currentParams = [];
|
|
73
|
+
inMethod = false;
|
|
74
|
+
} else {
|
|
75
|
+
// 提取跨多行的参数
|
|
76
|
+
const paramMatch = line.trim().match(/(\w+)\s*:\s*([^=]+)/);
|
|
77
|
+
if (paramMatch) {
|
|
78
|
+
currentParams.push({
|
|
79
|
+
name: paramMatch[1],
|
|
80
|
+
type: paramMatch[2].trim()
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
// 保存最后一个方法
|
|
88
|
+
if (currentMethod && currentParams.length > 0) {
|
|
89
|
+
paramTypes[currentMethod] = currentParams;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
traverseDir(srcDir);
|
|
96
|
+
|
|
97
|
+
// 添加硬编码的参数类型映射,为那些难以通过正则表达式提取的方法提供类型信息
|
|
98
|
+
const hardcodedParamTypes = {
|
|
99
|
+
'removeLayer': [{ name: 'layer', type: 'BaseMarkerLayerIns | ClusterMarkerLayerIns' }],
|
|
100
|
+
'setFitView': [{ name: 'opts', type: 'Parameters<mapIns[\'setFitView\']>' }],
|
|
101
|
+
'seZoomAndCenter': [{ name: 'opts', type: '{ zoom: number; center: AMap.LngLat | [number, number]; immediately?: boolean; duration?: number }' }]
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
// 合并硬编码的参数类型映射
|
|
105
|
+
Object.assign(paramTypes, hardcodedParamTypes);
|
|
106
|
+
|
|
107
|
+
return paramTypes;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// 递归处理所有.md文件
|
|
111
|
+
function processMarkdownFiles(dir) {
|
|
112
|
+
const files = fs.readdirSync(dir);
|
|
113
|
+
const paramTypes = extractMethodParamTypes();
|
|
114
|
+
|
|
115
|
+
files.forEach(file => {
|
|
116
|
+
const filePath = path.join(dir, file);
|
|
117
|
+
const stats = fs.statSync(filePath);
|
|
118
|
+
|
|
119
|
+
if (stats.isDirectory()) {
|
|
120
|
+
processMarkdownFiles(filePath);
|
|
121
|
+
} else if (path.extname(file) === '.md') {
|
|
122
|
+
processMarkdownFile(filePath, paramTypes);
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// 在分类标题后添加描述文字
|
|
128
|
+
function addCategoryDescription(content) {
|
|
129
|
+
// 定义分类描述映射
|
|
130
|
+
const categoryDescriptions = {
|
|
131
|
+
'高德地图工具': '本分类封装了高德地图(AMap)的核心功能,包括标记点、图标、折线、信息窗口等常用地图元素的创建和管理。这些静态方法提供了便捷的API,帮助开发者快速构建地图应用。'
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
// 遍历所有分类,添加描述文字
|
|
135
|
+
Object.keys(categoryDescriptions).forEach(category => {
|
|
136
|
+
const regex = new RegExp(`##\\s*${category}\\s*\\n`, 'g');
|
|
137
|
+
content = content.replace(regex, `## ${category}\n\n${categoryDescriptions[category]}\n\n`);
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
return content;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
// 处理单个Markdown文件,移除Params和Return部分,并添加参数类型
|
|
144
|
+
function processMarkdownFile(filePath, paramTypes) {
|
|
145
|
+
let content = fs.readFileSync(filePath, 'utf8');
|
|
146
|
+
|
|
147
|
+
// 在分类标题后添加描述文字
|
|
148
|
+
content = addCategoryDescription(content);
|
|
149
|
+
|
|
150
|
+
// 移除Params部分
|
|
151
|
+
content = content.replace(/#### Parameters[\s\S]*?(?=#### Returns|\*\*\*|$)/g, '');
|
|
152
|
+
|
|
153
|
+
// 移除Returns部分
|
|
154
|
+
content = content.replace(/#### Returns[\s\S]*?(?=####|\*\*\*|$)/g, '');
|
|
155
|
+
|
|
156
|
+
// 移除Memberof部分
|
|
157
|
+
content = content.replace(/#### Memberof[\s\S]*?(?=####|\*\*\*|$)/g, '');
|
|
158
|
+
|
|
159
|
+
// 移除Type Parameters部分(包含#### Type Parameters标题和后续的所有参数行)
|
|
160
|
+
content = content.replace(/#### Type Parameters[\s\S]*?(?=\*\*\*|$)/g, '');
|
|
161
|
+
|
|
162
|
+
// 移除单独的Type Parameter行(如##### U, ##### T等)
|
|
163
|
+
content = content.replace(/#####\s+\w+[\s\S]*?(?=#####|\*\*\*|$)/g, '');
|
|
164
|
+
|
|
165
|
+
// 移除单独的Type Parameter描述行(如`U` *extends* `object`)
|
|
166
|
+
content = content.replace(/`\w+`\s*\*extends\*\s*`[^`]+`[^\n]*\n/g, '');
|
|
167
|
+
|
|
168
|
+
// 为方法参数添加类型信息
|
|
169
|
+
content = content.replace(/(###\s+(\w+)\(\)[\s\S]*?>\s*\*\*\w+\*\*\s*)\(([^)]*)\)(:\s*`[^`]+`)/g, (match, prefix, methodName, paramsStr, returnType) => {
|
|
170
|
+
if (paramTypes[methodName]) {
|
|
171
|
+
const params = paramTypes[methodName];
|
|
172
|
+
let newParamsStr = '';
|
|
173
|
+
|
|
174
|
+
params.forEach((param, index) => {
|
|
175
|
+
if (index > 0) {
|
|
176
|
+
newParamsStr += ', ';
|
|
177
|
+
}
|
|
178
|
+
newParamsStr += `${param.name}: ${param.type}`;
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
return `${prefix}(${newParamsStr})${returnType}`;
|
|
182
|
+
}
|
|
183
|
+
return match;
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
// 处理带有反引号的参数
|
|
187
|
+
content = content.replace(/###\s+(\w+)\(\)[\s\S]*?>(\s*\*\*\w+\*\*\s*)\(`([^`]+)`\)(:\s*`[^`]+`)/g, (match, methodName, prefix, paramName, returnType) => {
|
|
188
|
+
if (paramTypes[methodName]) {
|
|
189
|
+
const params = paramTypes[methodName];
|
|
190
|
+
let newParamsStr = '';
|
|
191
|
+
|
|
192
|
+
params.forEach((param, index) => {
|
|
193
|
+
if (index > 0) {
|
|
194
|
+
newParamsStr += ', ';
|
|
195
|
+
}
|
|
196
|
+
newParamsStr += `${param.name}: ${param.type}`;
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
return match.replace(/\(`[^`]+`\)/, `(${newParamsStr})`);
|
|
200
|
+
}
|
|
201
|
+
return match;
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
// 移除多余的换行
|
|
205
|
+
content = content.replace(/\n{3,}/g, '\n\n');
|
|
206
|
+
|
|
207
|
+
// 移除分隔线前的多余换行
|
|
208
|
+
content = content.replace(/\n+\*\*\*/g, '\n***');
|
|
209
|
+
|
|
210
|
+
// 移除多余的分隔线
|
|
211
|
+
content = content.replace(/\*\*\*\n\*\*\*/g, '***');
|
|
212
|
+
|
|
213
|
+
// 保存处理后的内容
|
|
214
|
+
fs.writeFileSync(filePath, content, 'utf8');
|
|
215
|
+
console.log(`Processed: ${filePath}`);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
// 执行处理
|
|
219
|
+
processMarkdownFiles(docsDir);
|
|
220
|
+
console.log('All markdown files processed successfully!');
|