gdmap-utils 1.1.6 → 1.1.8

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.
@@ -1,53 +1,53 @@
1
- // 高德地图实例
2
- type mapIns = InstanceType<typeof AMap.Map>;
3
-
4
- type MapOptions = AMap.MapOptions;
5
-
6
- interface MapUtilsCreateOpts extends MapOptions {
7
- mountSelector: string;
8
- }
9
-
10
- interface MapUtilsUseExistingOpts extends MapOptions {
11
- mapIns: mapIns;
12
- }
13
-
14
- type MapUtilsOpts = {
15
- MapUtilsUseExistingOpts: MapUtilsUseExistingOpts;
16
- MapUtilsCreateOpts: MapUtilsCreateOpts;
17
- };
18
-
19
- interface MapUtilsStatic extends MapMixinType {
20
- new (
21
- opts: MapUtilsOpts[keyof MapUtilsOpts],
22
- AMap: Simplify<typeof gdAMap>
23
- ): MapUtils;
24
- }
25
-
26
- // 图层管理器
27
- interface LayerManger<T = new (...args: any[]) => any, K = InstanceType<T>> {
28
- layers: Map<string, K>; //组合模式
29
-
30
- addLayer(layer: K): void;
31
-
32
- removeLayer(layerIdOrLayer: K | string): void;
33
-
34
- show(): void;
35
-
36
- hide(): void;
37
-
38
- showAll(): void;
39
-
40
- hideAll(): void;
41
-
42
- reload(): void;
43
- }
44
-
45
- export type {
46
- mapIns,
47
- MapOptions,
48
- MapUtilsCreateOpts,
49
- MapUtilsUseExistingOpts,
50
- MapUtilsOpts,
51
- LayerManger,
52
- MapUtilsStatic,
53
- };
1
+ // 高德地图实例
2
+ type mapIns = InstanceType<typeof AMap.Map>;
3
+
4
+ type MapOptions = AMap.MapOptions;
5
+
6
+ interface MapUtilsCreateOpts extends MapOptions {
7
+ mountSelector: string;
8
+ }
9
+
10
+ interface MapUtilsUseExistingOpts extends MapOptions {
11
+ mapIns: mapIns;
12
+ }
13
+
14
+ type MapUtilsOpts = {
15
+ MapUtilsUseExistingOpts: MapUtilsUseExistingOpts;
16
+ MapUtilsCreateOpts: MapUtilsCreateOpts;
17
+ };
18
+
19
+ interface MapUtilsStatic extends MapMixinType {
20
+ new (
21
+ opts: MapUtilsOpts[keyof MapUtilsOpts],
22
+ AMap: Simplify<typeof gdAMap>
23
+ ): MapUtils;
24
+ }
25
+
26
+ // 图层管理器
27
+ interface LayerManger<T = new (...args: any[]) => any, K = InstanceType<T>> {
28
+ layers: Map<string, K>; //组合模式
29
+
30
+ addLayer(layer: K): void;
31
+
32
+ removeLayer(layerIdOrLayer: K | string): void;
33
+
34
+ show(): void;
35
+
36
+ hide(): void;
37
+
38
+ showAll(): void;
39
+
40
+ hideAll(): void;
41
+
42
+ reload(): void;
43
+ }
44
+
45
+ export type {
46
+ mapIns,
47
+ MapOptions,
48
+ MapUtilsCreateOpts,
49
+ MapUtilsUseExistingOpts,
50
+ MapUtilsOpts,
51
+ LayerManger,
52
+ MapUtilsStatic,
53
+ };
@@ -1,11 +1,11 @@
1
- // 导入高德地图类型声明
2
- import type { load } from '@amap/amap-jsapi-loader';
3
- import '@amap/amap-jsapi-types';
4
-
5
- type loaderOpts = Parameters<typeof load>[0]; //函数类型取出
6
-
7
- type MapOptions = AMap.MapOptions;
8
- type MarkerOptions = AMap.MarkerOptions;
9
- type LabelMarkerOptions = AMap.LabelMarkerOptions;
10
-
11
- export type { loaderOpts, AMap, MapOptions, MarkerOptions, LabelMarkerOptions };
1
+ // 导入高德地图类型声明
2
+ import type { load } from '@amap/amap-jsapi-loader';
3
+ import '@amap/amap-jsapi-types';
4
+
5
+ type loaderOpts = Parameters<typeof load>[0]; //函数类型取出
6
+
7
+ type MapOptions = AMap.MapOptions;
8
+ type MarkerOptions = AMap.MarkerOptions;
9
+ type LabelMarkerOptions = AMap.LabelMarkerOptions;
10
+
11
+ export type { loaderOpts, AMap, MapOptions, MarkerOptions, LabelMarkerOptions };
@@ -1,12 +1,12 @@
1
- // 从MapUtils.d.ts导入并重新导出类型
2
- export type * from './MapUtils';
3
-
4
- // 从BaseMarkerLayer.d.ts导入并重新导出类型
5
- export type * from './BaseMarkerLayer';
6
-
7
- interface Window {
8
- _AMapSecurityConfig?: {
9
- securityJsCode: string;
10
- serviceHost: string;
11
- };
12
- }
1
+ // 从MapUtils.d.ts导入并重新导出类型
2
+ export type * from './MapUtils';
3
+
4
+ // 从BaseMarkerLayer.d.ts导入并重新导出类型
5
+ export type * from './BaseMarkerLayer';
6
+
7
+ interface Window {
8
+ _AMapSecurityConfig?: {
9
+ securityJsCode: string;
10
+ serviceHost: string;
11
+ };
12
+ }
package/tsconfig.json CHANGED
@@ -1,27 +1,27 @@
1
- {
2
- "compilerOptions": {
3
- "target": "ES5",
4
- "module": "ESNext",
5
- "lib": ["ES5", "ES2015", "ES2016", "ES2017", "DOM"],
6
- "declaration": true,
7
- "declarationMap": true,
8
- "sourceMap": true,
9
- "outDir": "./dist",
10
- "rootDir": "./src",
11
- "strict": true,
12
- "esModuleInterop": true,
13
- "skipLibCheck": true,
14
- "forceConsistentCasingInFileNames": true,
15
- "moduleResolution": "node",
16
- "resolveJsonModule": true,
17
- "isolatedModules": true,
18
- "noEmit": false,
19
- "typeRoots": ["./src/types", "./node_modules/@types"],
20
- "baseUrl": "./",
21
- "paths": {
22
- "@/*": ["src/*"]
23
- }
24
- },
25
- "include": ["env.d.ts", "src/**/*", "src/**/*.vue"],
26
- "exclude": ["node_modules", "dist"]
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES5",
4
+ "module": "ESNext",
5
+ "lib": ["ES5", "ES2015", "ES2016", "ES2017", "DOM"],
6
+ "declaration": true,
7
+ "declarationMap": true,
8
+ "sourceMap": true,
9
+ "outDir": "./dist",
10
+ "rootDir": "./src",
11
+ "strict": true,
12
+ "esModuleInterop": true,
13
+ "skipLibCheck": true,
14
+ "forceConsistentCasingInFileNames": true,
15
+ "moduleResolution": "node",
16
+ "resolveJsonModule": true,
17
+ "isolatedModules": true,
18
+ "noEmit": false,
19
+ "typeRoots": ["./src/types", "./node_modules/@types"],
20
+ "baseUrl": "./",
21
+ "paths": {
22
+ "@/*": ["src/*"]
23
+ }
24
+ },
25
+ "include": ["env.d.ts", "src/**/*", "src/**/*.vue"],
26
+ "exclude": ["node_modules", "dist"]
27
27
  }
package/webpack.config.js CHANGED
@@ -1,104 +1,98 @@
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
-
6
- // 获取环境变量或默认值
7
- const isProduction = process.env.NODE_ENV === 'production';
8
-
9
- // 设置mode变量
10
- const mode = isProduction ? 'production' : 'development';
11
-
12
- // 配置对象
13
- const config = {
14
- entry: './src/index.ts',
15
- output: {
16
- // 打包后的文件名
17
- filename: 'index.js',
18
- // 输出目录路径
19
- path: path.resolve(__dirname, 'dist'),
20
- // 库的全局变量名,在浏览器中可以通过 window.MapUtils 访问
21
- library: 'MapUtils',
22
- // 库的输出格式,生产模式使用umd,开发模式使用window
23
- libraryTarget: isProduction ? 'umd' : 'window',
24
- // 浏览器: window node.js:global Web Worker: self
25
- globalObject: isProduction ? 'this' : 'window',
26
- // 为 UMD 模块命名,提高可读性
27
- umdNamedDefine: true,
28
- // 构建前清理输出目录
29
- clean: true,
30
- // 开发模式下输出到内存,生产模式下输出到 dist 目录
31
- publicPath: '/',
32
- },
33
- resolve: {
34
- extensions: ['.ts', '.tsx', '.js', '.jsx'],
35
- alias: {
36
- '@': path.resolve(__dirname, 'src'),
37
- },
38
- },
39
- externals: {
40
- '@amap/amap-jsapi-loader': {
41
- commonjs: '@amap/amap-jsapi-loader',
42
- commonjs2: '@amap/amap-jsapi-loader',
43
- amd: '@amap/amap-jsapi-loader',
44
- root: 'AMapLoader'
45
- }
46
- },
47
- module: {
48
- rules: [
49
- {
50
- test: /\.tsx?$/,
51
- loader: 'ts-loader',
52
- exclude: /node_modules/,
53
- options: {
54
- transpileOnly: true,
55
- compilerOptions: { noEmit: true },
56
- },
57
- },
58
- ],
59
- },
60
- plugins: [
61
- new ForkTsCheckerWebpackPlugin(),
62
- new webpack.DefinePlugin({
63
- 'process.env.NODE_ENV': JSON.stringify(isProduction ? 'production' : 'development'),
64
- }),
65
- ],
66
- devtool: isProduction ? 'source-map' : 'eval-cheap-module-source-map',
67
- mode: mode,
68
- };
69
-
70
- // 开发模式下添加开发服务器和HTML模板配置
71
- if (!isProduction) {
72
- config.devServer = {
73
- static: {
74
- directory: path.join(__dirname, 'examples'),
75
- watch: true,
76
- },
77
- compress: true,
78
- port: 8080,
79
- open: true,
80
- hot: true,
81
- historyApiFallback: true,
82
- };
83
-
84
- // 添加HTML模板插件
85
- config.plugins.push(
86
- new HtmlWebpackPlugin({
87
- template: path.resolve(__dirname, 'examples', '4_LabelMarkerLayer.html'),
88
- // template: path.resolve(__dirname, 'examples', '3_MarkerLayer.html'),
89
- filename: 'index.html',
90
- inject: { // 精确控制脚本的注入位置
91
- tagName: 'script',
92
- insertBefore: 'body > script:first-of-type' // 将库脚本注入到body内第一个script标签之前
93
- },
94
- scriptLoading: 'blocking', // 使用阻塞加载方式确保脚本按顺序执行
95
- })
96
- );
97
- //开发模式无需排除
98
- delete config.externals
99
-
100
- // 添加热模块替换插件
101
- config.plugins.push(new webpack.HotModuleReplacementPlugin());
102
- }
103
-
104
- 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
+
6
+ // 获取命令行参数,判断当前模式
7
+ const isProduction = process.env.NODE_ENV === 'production';
8
+
9
+ // 配置对象
10
+ const config = {
11
+ entry: './src/index.ts',
12
+ output: {
13
+ // 打包后的文件名
14
+ filename: isProduction ? 'index.js' : 'bundle.js',
15
+ // 输出目录路径
16
+ path: path.resolve(__dirname, 'dist'),
17
+ // 库的全局变量名,在浏览器中可以通过 window.MapUtils 访问
18
+ library: 'MapUtils',
19
+ // 库的输出格式,生产模式使用umd,开发模式使用window
20
+ libraryTarget: isProduction ? 'umd' : 'window',
21
+ // 浏览器: window node.js:global Web Worker: self
22
+ globalObject: isProduction ? 'this' : 'window',
23
+ // UMD 模块命名,提高可读性
24
+ umdNamedDefine: true,
25
+ // 构建前清理输出目录
26
+ clean: true,
27
+ // 开发模式下输出到内存,生产模式下输出到 dist 目录
28
+ publicPath: '/',
29
+ },
30
+ resolve: {
31
+ extensions: ['.ts', '.tsx', '.js', '.jsx'],
32
+ alias: {
33
+ '@': path.resolve(__dirname, 'src'),
34
+ },
35
+ },
36
+ externals: {
37
+ '@amap/amap-jsapi-loader': {
38
+ commonjs: '@amap/amap-jsapi-loader',
39
+ commonjs2: '@amap/amap-jsapi-loader',
40
+ amd: '@amap/amap-jsapi-loader',
41
+ root: 'AMapLoader'
42
+ }
43
+ },
44
+ module: {
45
+ rules: [
46
+ {
47
+ test: /\.tsx?$/,
48
+ loader: 'ts-loader',
49
+ exclude: /node_modules/,
50
+ options: {
51
+ transpileOnly: true,
52
+ compilerOptions: { noEmit: true },
53
+ },
54
+ },
55
+ ],
56
+ },
57
+ plugins: [
58
+ new ForkTsCheckerWebpackPlugin(),
59
+ ],
60
+ devtool: isProduction ? 'source-map' : 'eval-cheap-module-source-map',
61
+ mode: isProduction ? 'production' : 'development',
62
+ };
63
+
64
+ // 开发模式下添加开发服务器和HTML模板配置
65
+ if (!isProduction) {
66
+ config.devServer = {
67
+ static: {
68
+ directory: path.join(__dirname, 'examples'),
69
+ watch: true,
70
+ },
71
+ compress: true,
72
+ port: 8080,
73
+ open: true,
74
+ hot: true,
75
+ historyApiFallback: true,
76
+ };
77
+
78
+ // 添加HTML模板插件
79
+ config.plugins.push(
80
+ new HtmlWebpackPlugin({
81
+ // template: path.resolve(__dirname, 'examples', '4_LabelMarkerLayer.html'),
82
+ template: path.resolve(__dirname, 'examples', '3_MarkerLayer.html'),
83
+ filename: 'index.html',
84
+ inject: { // 精确控制脚本的注入位置
85
+ tagName: 'script',
86
+ insertBefore: 'body > script:first-of-type' // 将库脚本注入到body内第一个script标签之前
87
+ },
88
+ scriptLoading: 'blocking', // 使用阻塞加载方式确保脚本按顺序执行
89
+ })
90
+ );
91
+ //开发模式无需排除
92
+ delete config.externals
93
+
94
+ // 添加热模块替换插件
95
+ config.plugins.push(new webpack.HotModuleReplacementPlugin());
96
+ }
97
+
98
+ module.exports = config;