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.
Files changed (38) hide show
  1. package/.husky/pre-commit +1 -1
  2. package/.prettierrc.json +17 -17
  3. package/README.md +467 -2
  4. package/dist/index.js +127 -7
  5. package/dist/index.js.map +1 -1
  6. package/docs/classes/MapUtils.md +153 -0
  7. package/docs/functions/createMapUtils.md +18 -0
  8. package/docs/functions/initMapSource.md +14 -0
  9. package/docs/globals.md +11 -0
  10. package/examples/1_init.html +23 -23
  11. package/examples/2_mapInit.html +48 -48
  12. package/examples/3_MarkerLayer.html +565 -565
  13. package/examples/4_LabelMarkerLayer.html +574 -574
  14. package/examples/5_markerCluster.html +528 -0
  15. package/index.html +134 -134
  16. package/package.json +54 -51
  17. package/scripts/cleanDocs.js +220 -0
  18. package/scripts/mergeDocs.js +129 -0
  19. package/src/LayerManager.ts +17 -1
  20. package/src/MapSourceImport.ts +23 -23
  21. package/src/MapUtils.ts +198 -22
  22. package/src/gdMap/gdHelper.ts +113 -85
  23. package/src/index.ts +3 -1
  24. package/src/layers/baseMarkerLayer/LabelMarkerLayer.ts +240 -240
  25. package/src/layers/baseMarkerLayer/MarkerLayer.ts +208 -208
  26. package/src/layers/baseMarkerLayer/index.ts +369 -354
  27. package/src/layers/clusterMarkerLayer/MarkerClusterLayer.ts +53 -53
  28. package/src/layers/clusterMarkerLayer/index.ts +204 -177
  29. package/src/layers/index.ts +9 -9
  30. package/src/types/MapUtils.d.ts +53 -53
  31. package/src/types/amap.d.ts +11 -11
  32. package/src/types/{BaseMarkerLayer.d.ts → baseMarkerLayer.d.ts} +86 -87
  33. package/src/types/clusterMarkerLayer.d.ts +89 -88
  34. package/src/types/index.d.ts +14 -14
  35. package/tsconfig.json +26 -26
  36. package/typedoc.json +22 -0
  37. package/webpack.config.js +125 -126
  38. package/src/gdMap/gdHelper.js +0 -194
package/webpack.config.js CHANGED
@@ -1,126 +1,125 @@
1
- const path = require('path');
2
- const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
3
- const HtmlWebpackPlugin = require('html-webpack-plugin');
4
- const webpack = require('webpack');
5
- const TerserPlugin = require('terser-webpack-plugin');
6
-
7
- // 获取环境变量或默认值
8
- const isProduction = process.env.NODE_ENV === 'production';
9
-
10
- // 设置mode变量
11
- const mode = isProduction ? 'production' : 'development';
12
-
13
- // 配置对象
14
- const config = {
15
- entry: './src/index.ts',
16
- output: {
17
- // 打包后的文件名
18
- filename: 'index.js',
19
- // 输出目录路径
20
- path: path.resolve(__dirname, 'dist'),
21
- // 库的全局变量名,在浏览器中可以通过 window.MapUtils 访问
22
- library: 'MapUtils',
23
- // 库的输出格式,生产模式使用umd,开发模式使用window
24
- libraryTarget: isProduction ? 'umd' : 'window',
25
- // 浏览器: window node.js:global Web Worker: self
26
- globalObject: isProduction ? 'this' : 'window',
27
- // 为 UMD 模块命名,提高可读性
28
- umdNamedDefine: true,
29
- // 构建前清理输出目录
30
- clean: true,
31
- // 开发模式下输出到内存,生产模式下输出到 dist 目录
32
- publicPath: '/',
33
- },
34
- resolve: {
35
- extensions: ['.ts', '.tsx', '.js', '.jsx'],
36
- alias: {
37
- '@': path.resolve(__dirname, 'src'),
38
- },
39
- },
40
- externals: {
41
- '@amap/amap-jsapi-loader': {
42
- commonjs: '@amap/amap-jsapi-loader',
43
- commonjs2: '@amap/amap-jsapi-loader',
44
- amd: '@amap/amap-jsapi-loader',
45
- root: 'AMapLoader'
46
- }
47
- },
48
- module: {
49
- rules: [
50
- {
51
- test: /\.tsx?$/,
52
- loader: 'ts-loader',
53
- exclude: /node_modules/,
54
- options: {
55
- transpileOnly: true,
56
- compilerOptions: { noEmit: true },
57
- },
58
- },
59
- ],
60
- },
61
- plugins: [
62
- new ForkTsCheckerWebpackPlugin(),
63
- new webpack.DefinePlugin({
64
- 'process.env.NODE_ENV': JSON.stringify(isProduction ? 'production' : 'development'),
65
- }),
66
- ],
67
- devtool: isProduction ? 'source-map' : 'eval-cheap-module-source-map',
68
- mode: mode,
69
- optimization: {
70
- minimize: true,
71
- minimizer: [
72
- new TerserPlugin({
73
- terserOptions: {
74
- compress: {
75
- drop_console: false,
76
- drop_debugger: true,
77
- pure_funcs: [],
78
- },
79
- mangle: {
80
- keep_fnames: true,
81
- },
82
- output: {
83
- comments: /@preserve|@license|@copyright|@author|@description|@param|@returns|@type/i,
84
- },
85
- },
86
- extractComments: false,
87
- }),
88
- ],
89
- },
90
- };
91
-
92
- // 开发模式下添加开发服务器和HTML模板配置
93
- if (!isProduction) {
94
- config.devServer = {
95
- static: {
96
- directory: path.join(__dirname, 'examples'),
97
- watch: true,
98
- },
99
- compress: true,
100
- port: 8080,
101
- open: true,
102
- hot: true,
103
- historyApiFallback: true,
104
- };
105
-
106
- // 添加HTML模板插件
107
- config.plugins.push(
108
- new HtmlWebpackPlugin({
109
- template: path.resolve(__dirname, 'examples', '4_LabelMarkerLayer.html'),
110
- // template: path.resolve(__dirname, 'examples', '3_MarkerLayer.html'),
111
- filename: 'index.html',
112
- inject: { // 精确控制脚本的注入位置
113
- tagName: 'script',
114
- insertBefore: 'body > script:first-of-type' // 将库脚本注入到body内第一个script标签之前
115
- },
116
- scriptLoading: 'blocking', // 使用阻塞加载方式确保脚本按顺序执行
117
- })
118
- );
119
- //开发模式无需排除
120
- delete config.externals
121
-
122
- // 添加热模块替换插件
123
- config.plugins.push(new webpack.HotModuleReplacementPlugin());
124
- }
125
-
126
- module.exports = config;
1
+ const path = require('path');
2
+ const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
3
+ const HtmlWebpackPlugin = require('html-webpack-plugin');
4
+ const webpack = require('webpack');
5
+ const TerserPlugin = require('terser-webpack-plugin');
6
+
7
+ // 获取环境变量或默认值
8
+ const isProduction = process.env.NODE_ENV === 'production';
9
+
10
+ // 设置mode变量
11
+ const mode = isProduction ? 'production' : 'development';
12
+
13
+ // 配置对象
14
+ const config = {
15
+ entry: './src/index.ts',
16
+ output: {
17
+ // 打包后的文件名
18
+ filename: 'index.js',
19
+ // 输出目录路径
20
+ path: path.resolve(__dirname, 'dist'),
21
+ // 库的全局变量名,在浏览器中可以通过 window.GdMapUtils 访问
22
+ library: 'GdMapUtils',
23
+ // 库的输出格式,生产模式使用umd,开发模式使用window
24
+ libraryTarget: isProduction ? 'umd' : 'window',
25
+ // 浏览器: window node.js:global Web Worker: self
26
+ globalObject: isProduction ? 'this' : 'window',
27
+ // 为 UMD 模块命名,提高可读性
28
+ umdNamedDefine: true,
29
+ // 构建前清理输出目录
30
+ clean: true,
31
+ // 开发模式下输出到内存,生产模式下输出到 dist 目录
32
+ publicPath: '/',
33
+ },
34
+ resolve: {
35
+ extensions: ['.ts', '.tsx', '.js', '.jsx'],
36
+ alias: {
37
+ '@': path.resolve(__dirname, 'src'),
38
+ },
39
+ },
40
+ externals: {
41
+ '@amap/amap-jsapi-loader': {
42
+ commonjs: '@amap/amap-jsapi-loader',
43
+ commonjs2: '@amap/amap-jsapi-loader',
44
+ amd: '@amap/amap-jsapi-loader',
45
+ root: 'AMapLoader'
46
+ }
47
+ },
48
+ module: {
49
+ rules: [
50
+ {
51
+ test: /\.tsx?$/,
52
+ loader: 'ts-loader',
53
+ exclude: /node_modules/,
54
+ options: {
55
+ transpileOnly: true,
56
+ compilerOptions: { noEmit: true },
57
+ },
58
+ },
59
+ ],
60
+ },
61
+ plugins: [
62
+ new ForkTsCheckerWebpackPlugin(),
63
+ new webpack.DefinePlugin({
64
+ 'process.env.NODE_ENV': JSON.stringify(isProduction ? 'production' : 'development'),
65
+ }),
66
+ ],
67
+ devtool: isProduction ? 'source-map' : 'eval-cheap-module-source-map',
68
+ mode: mode,
69
+ optimization: {
70
+ minimize: true,
71
+ minimizer: [
72
+ new TerserPlugin({
73
+ terserOptions: {
74
+ compress: {
75
+ drop_console: false,
76
+ drop_debugger: true,
77
+ pure_funcs: [],
78
+ },
79
+ mangle: {
80
+ keep_fnames: true,
81
+ },
82
+ output: {
83
+ comments: /@preserve|@license|@copyright|@author|@description|@param|@returns|@type/i,
84
+ },
85
+ },
86
+ extractComments: false,
87
+ }),
88
+ ],
89
+ },
90
+ };
91
+
92
+ // 开发模式下添加开发服务器和HTML模板配置
93
+ if (!isProduction) {
94
+ config.devServer = {
95
+ static: {
96
+ directory: path.join(__dirname, 'examples'),
97
+ watch: true,
98
+ },
99
+ compress: true,
100
+ port: 8080,
101
+ open: true,
102
+ hot: true,
103
+ historyApiFallback: true,
104
+ };
105
+
106
+ // 添加HTML模板插件
107
+ config.plugins.push(
108
+ new HtmlWebpackPlugin({
109
+ template: path.resolve(__dirname, 'examples', '3_MarkerLayer.html'),
110
+ filename: 'index.html',
111
+ inject: { // 精确控制脚本的注入位置
112
+ tagName: 'script',
113
+ insertBefore: 'body > script:first-of-type' // 将库脚本注入到body内第一个script标签之前
114
+ },
115
+ scriptLoading: 'blocking', // 使用阻塞加载方式确保脚本按顺序执行
116
+ })
117
+ );
118
+ //开发模式无需排除
119
+ delete config.externals
120
+
121
+ // 添加热模块替换插件
122
+ config.plugins.push(new webpack.HotModuleReplacementPlugin());
123
+ }
124
+
125
+ module.exports = config;
@@ -1,194 +0,0 @@
1
- const gdHelperMixin = {
2
- /**
3
- * 设置地图中心
4
- * @param lnglat [xxx,xx]
5
- * @param zoom 地图层级
6
- */
7
- //TODO setGDMapCenter 你可以为后期迭代做准备
8
- //TODO setGDMapCenter 你可以为后期迭代做准备
9
- setCenter(lnglat, zoom) {
10
- if (zoom !== undefined) {
11
- this.map.setZoomAndCenter(zoom, lnglat); //同时设置地图层级与中心点
12
- } else {
13
- this.map.setCenter(lnglat, true);
14
- }
15
- },
16
- /**
17
- * 设置地图缩放级别
18
- * @param zoom 地图层级
19
- */
20
- setZoom(zoom) {
21
- this.map.setZoom(zoom);
22
- },
23
- /**
24
- * 根据地图上添加的覆盖物分布情况,自动缩放地图到合适的视野级别
25
- * @param {Array} overlays [marker, marker1] 覆盖物数组 缺省为全部覆盖物
26
- * @param {Boolean} immediately 是否立即过渡
27
- * @param {Array<Number>} avoid [60,60,60,60] 四周边距,上、下、左、右
28
- * @param {number} maxZoom 最大 地图zoom 级别 18
29
- */
30
- setFitView(...opts) {
31
- // 地图适应到最佳视角
32
- this.map.setFitView(...opts);
33
- },
34
- /**
35
- * 创建一个图标
36
- * @param {[number, number]} size - 图标尺寸,格式为 [width, height]
37
- * @param {string} image - 图片的 URL 地址
38
- * @param {[number, number]} imageSize - 图标所用图片的大小,格式为 [width, height]
39
- * @param {[number, number]} imageOffset - 图标取图的偏移量,格式为 [x, y]
40
- */
41
- createIcon(size, image, imageSize, imageOffset = [0, 0]) {
42
- return new this.AMap.Icon({
43
- // 图标尺寸
44
- size: this.Size(...size),
45
- // 图标的取图地址
46
- image: image,
47
- // 图标所用图片大小
48
- imageSize: this.Size(...imageSize),
49
- // 图标取图偏移量
50
- imageOffset: this.Pixel(...imageOffset),
51
- });
52
- },
53
- /**
54
- * 地物对象的像素尺寸
55
- * @param {number} width 宽度
56
- * @param {number} height 高度
57
- */
58
- Size(width, height) {
59
- return new this.AMap.Size(width, height);
60
- },
61
- /**
62
- * 像素坐标,确定地图上的一个像素点。
63
- * @param {number} x
64
- * @param {number} y
65
- */
66
- Pixel(x, y) {
67
- return new this.AMap.Pixel(x, y);
68
- },
69
- /**
70
- * 经纬度坐标,用来描述地图上的一个点位置
71
- * @param {Number} lng 经度值
72
- * @param {Number} lat 纬度值
73
- * @param {boolean} noWrap 是否自动将经度值修正到 [-180,180] 区间内
74
- */
75
- LngLat(lng, lat, noWrap = false) {
76
- return new this.AMap.LngLat(lng, lat, noWrap);
77
- },
78
-
79
- //TODO 海量点数据
80
- createLabelLayer({
81
- zoom = [1, 20],
82
- zIndex = 1000,
83
- collision = true,
84
- layerClassName,
85
- ...rest
86
- }) {
87
- const labelLayer = new this.AMap.LabelsLayer({
88
- zIndex,
89
- collision,
90
- zoom,
91
- ...rest,
92
- });
93
- labelLayer.setMap(this.map);
94
- // HACK: labelLayer获取图层节点方式与原来不同,获取可以抽象marker图层, labelLayer图层,实现多态
95
- // this.overlayGroupManagerMap.set(layerClassName,labelLayer);
96
- return labelLayer;
97
- },
98
- // 创建labelMarker标注
99
- createLabelLayerMarker({ icon, text, position, ...rest }) {
100
- const label = new this.AMap.LabelMarker({
101
- icon: icon,
102
- text: text,
103
- position: position,
104
- ...rest,
105
- });
106
- return label;
107
- },
108
-
109
- createMarkerCluster(
110
- points,
111
- { _renderClusterMarker, _renderMarker, gridSize }
112
- ) {
113
- return new AMap.MarkerCluster(this.map, points, {
114
- gridSize: gridSize, // 设置网格像素大小
115
- renderClusterMarker: _renderClusterMarker, // 自定义聚合点样式
116
- renderMarker: _renderMarker, // 自定义非聚合点样式
117
- });
118
- },
119
- /*
120
- 创建点位信息窗体
121
- */
122
- createInfoWindow({
123
- content,
124
- isCustom = true,
125
- closeWhenClickMap = true,
126
- ...rest
127
- }) {
128
- return new this.AMap.InfoWindow({
129
- content: content,
130
- isCustom,
131
- closeWhenClickMap: closeWhenClickMap,
132
- ...rest,
133
- });
134
- },
135
- /*
136
- 清楚地图所有信息窗体
137
- */
138
- clearInfoWindow() {
139
- this.map.clearInfoWindow();
140
- },
141
-
142
- //[ ] gdHelper.js中this.map.xxx得方法可以转移到gdUtils.js实例上,mapUtils
143
- /* 打开高德信息弹框 */
144
- openInfoWindow(infoWindow, ...rest) {
145
- infoWindow.open(this.map, ...rest);
146
- },
147
- // 绘制线路
148
- drawPolyline(paths) {
149
- return new this.AMap.Polyline({
150
- map: this.map,
151
- ...paths,
152
- });
153
- },
154
-
155
- clearOverlays() {
156
- this.map.clearMap(); // 清除地图上的所有覆盖物
157
- },
158
-
159
- removeSingleOverlay(overlay) {
160
- this.map.remove(overlay); // 清除地图上某个覆盖物
161
- },
162
- /**
163
- * 创建高德地图驾车导航
164
- * @param {Object} options 导航配置
165
- * @returns {AMap.Driving} 导航对象
166
- */
167
- createAMapDriving(options) {
168
- return new this.AMap.Driving(options);
169
- },
170
- /**
171
- * 创建高德地图标注
172
- * @param {Object} options 标注配置
173
- * @returns {AMap.Marker} 标注对象
174
- */
175
- createAMapMarker(options) {
176
- return new this.AMap.Marker({
177
- map: this.map,
178
- ...options,
179
- });
180
- },
181
- /**
182
- * 创建高德地图折线
183
- * @param {Object} options 折线配置
184
- * @returns {AMap.Polyline} 折线对象
185
- */
186
- createAMapPolyline(options) {
187
- return new this.AMap.Polyline({
188
- map: this.map,
189
- ...options,
190
- });
191
- },
192
- };
193
-
194
- export default gdHelperMixin;