gdmap-utils 1.2.0 → 1.2.2

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 (34) hide show
  1. package/.husky/pre-commit +1 -1
  2. package/.prettierrc.json +17 -17
  3. package/README.md +2 -50
  4. package/dist/index.js +1 -83
  5. package/dist/index.js.map +1 -1
  6. package/examples/1_init.html +23 -23
  7. package/examples/2_mapInit.html +48 -48
  8. package/examples/3_MarkerLayer.html +565 -565
  9. package/examples/4_LabelMarkerLayer.html +574 -574
  10. package/index.html +134 -134
  11. package/package.json +48 -48
  12. package/src/LayerManager.ts +49 -49
  13. package/src/MapSourceImport.ts +23 -23
  14. package/src/MapUtils.ts +154 -154
  15. package/src/gdMap/gdHelper.js +194 -194
  16. package/src/gdMap/gdHelper.ts +85 -85
  17. package/src/gdMapUtils.js +377 -377
  18. package/src/index.ts +1 -1
  19. package/src/layers/baseMarkerLayer/LabelMarkerLayer.ts +238 -238
  20. package/src/layers/baseMarkerLayer/MarkerLayer.ts +206 -206
  21. package/src/layers/baseMarkerLayer/index.ts +354 -354
  22. package/src/{layers copy/MarkerClusterLayer.js → layers/clusterMarkerLayer/MarkerClusterLayer.js} +155 -155
  23. package/src/layers/{MarkerClusterLayer.ts → clusterMarkerLayer/MarkerClusterLayer.ts} +30 -30
  24. package/src/layers/index.ts +5 -5
  25. package/src/types/BaseMarkerLayer.d.ts +87 -87
  26. package/src/types/MapUtils.d.ts +53 -53
  27. package/src/types/amap.d.ts +11 -11
  28. package/src/types/index.d.ts +12 -12
  29. package/tsconfig.json +26 -26
  30. package/webpack.config.js +126 -126
  31. package/src/layers copy/LabelMarkerLayer.js +0 -122
  32. package/src/layers copy/MarkerLayer.js +0 -267
  33. package/src/layers copy/OverlayGroupManager.js +0 -254
  34. package/src/layers copy/index.ts +0 -0
package/src/MapUtils.ts CHANGED
@@ -1,154 +1,154 @@
1
- import MapSourceImport from './MapSourceImport';
2
- import MapMixin from './gdMap/gdHelper';
3
- import type { AMap as gdAMap, loaderOpts, MapOptions } from './types/amap.d';
4
- import type {
5
- MapUtilsOpts,
6
- mapIns,
7
- MarkerLayerBaseType,
8
- LayerOpts,
9
- } from './types/index.d';
10
- import { BaseMarkerLayerIns, BaseMarkerLayer } from './layers/index';
11
- import type { SetOptional, Simplify } from 'type-fest';
12
- import LayerManager from './LayerManager';
13
-
14
- type MapUtilsConstructor = typeof MapUtils;
15
-
16
- type mapUtilsIns = InstanceType<typeof MapUtils>;
17
-
18
- export class MapUtils {
19
- // 地图实例信息
20
- map: mapIns;
21
-
22
- options: SetOptional<MapUtilsOpts['MapUtilsCreateOpts'], 'mountSelector'>;
23
-
24
- LayerManager: LayerManager = new LayerManager();
25
-
26
- static createAMapMarker = MapMixin.createAMapMarker;
27
-
28
- static createIcon = MapMixin.createIcon;
29
-
30
- static Size = MapMixin.Size;
31
-
32
- static Pixel = MapMixin.Pixel;
33
-
34
- static LngLat = MapMixin.LngLat;
35
-
36
- static createAMapInfoWindow = MapMixin.createAMapInfoWindow;
37
-
38
- constructor(
39
- opts: MapUtilsOpts[keyof MapUtilsOpts],
40
- AMap: Simplify<typeof gdAMap>
41
- ) {
42
- if (!(typeof AMap === 'object' && 'Map' in AMap)) {
43
- throw MapUtils.error('AMap is not exist');
44
- }
45
-
46
- if ('mapIns' in opts && opts.mapIns instanceof AMap.Map) {
47
- const { mapIns, ...rest } = opts;
48
- this.map = opts.mapIns;
49
- this.options = rest;
50
- } else {
51
- if (!('mountSelector' in opts)) {
52
- throw MapUtils.error('mountSelector is not exist');
53
- } else {
54
- this.options = opts;
55
-
56
- const { mountSelector, ...rest } = opts;
57
-
58
- this.map = this.initMap(mountSelector, rest); //地图初始化
59
- }
60
- }
61
-
62
- this.bindMapClickEvent();
63
- }
64
-
65
- // 初始化绑定地图事件
66
- bindMapClickEvent() {
67
- this.map.on('click', () => {
68
- // if (this.clickMapRestMarkers) {
69
- // this.overlayGroupManagerMap.forEach((overlayGroup) => {
70
- // overlayGroup.resetActiveMarker(); // 清除图层上的所有覆盖物
71
- // });
72
- // }
73
- });
74
- }
75
-
76
- initMap(id: string, opts: MapOptions): mapIns {
77
- //参数要作检验吗
78
- return new window.AMap.Map(id, opts);
79
- }
80
-
81
- createBaseMarkerLayer<
82
- U extends {},
83
- T extends MarkerLayerBaseType = 'markerLayer',
84
- >(opts: LayerOpts<U, T>) {
85
- const layer = new BaseMarkerLayer<U, T>(opts, this);
86
- // @ts-ignore
87
- this.LayerManager.addLayer(layer);
88
- return layer;
89
- }
90
-
91
- removeLayer(layer: BaseMarkerLayerIns) {
92
- const isLayerExist = this.LayerManager.hasLayer(layer);
93
-
94
- if (isLayerExist) {
95
- this.LayerManager.removeLayer(layer);
96
- } else {
97
- MapUtils.error(`${layer.layerName} is not exist`);
98
- }
99
- }
100
-
101
- /**
102
- * 根据地图上添加的覆盖物分布情况,自动缩放地图到合适的视野级别
103
- * @param {Array} overlays - 覆盖物数组,缺省为全部覆盖物
104
- * @param {Boolean} immediately - 是否立即过渡
105
- * @param {Array<Number>} avoid - 四周边距,上、下、左、右
106
- * @param {number} maxZoom - 最大地图zoom级别
107
- */
108
- setFitView(...opts: Parameters<mapIns['setFitView']>): void {
109
- this.map.setFitView(...opts);
110
- }
111
-
112
- clearInfoWindow() {
113
- this.map.clearInfoWindow();
114
- }
115
-
116
- seZoomAndCenter(opts: {
117
- zoom: number;
118
- center: AMap.LngLat | [number, number];
119
- immediately?: boolean;
120
- duration?: number;
121
- }): void {
122
- const curZoom = this.map.getZoom();
123
- const lngAndLat = this.map.getCenter();
124
- const curCenter: [number, number] = [lngAndLat.lng, lngAndLat.lat];
125
- let { center = curCenter, zoom = curZoom, immediately, duration } = opts;
126
-
127
- this.map.setZoomAndCenter(zoom, center, immediately, duration);
128
- }
129
-
130
- static error(msg: string) {
131
- console.error(`[MapUtils Error]:${msg}`);
132
- }
133
- }
134
-
135
- export type { mapUtilsIns, MapUtilsConstructor };
136
-
137
- export async function createMapUtils(
138
- opts: MapUtilsOpts[keyof MapUtilsOpts],
139
- loaderOPts?: loaderOpts
140
- ) {
141
- // window上存在属性已经加载
142
- let AMap = window.AMap;
143
-
144
- if (loaderOPts) {
145
- AMap = await initMapSource(loaderOPts);
146
- }
147
-
148
- return new MapUtils(opts, AMap);
149
- }
150
-
151
- // 地图拆分
152
- export async function initMapSource(Opts: loaderOpts) {
153
- return await MapSourceImport.loadScript(Opts);
154
- }
1
+ import MapSourceImport from './MapSourceImport';
2
+ import MapMixin from './gdMap/gdHelper';
3
+ import type { AMap as gdAMap, loaderOpts, MapOptions } from './types/amap.d';
4
+ import type {
5
+ MapUtilsOpts,
6
+ mapIns,
7
+ MarkerLayerBaseType,
8
+ LayerOpts,
9
+ } from './types/index.d';
10
+ import { BaseMarkerLayerIns, BaseMarkerLayer } from './layers/index';
11
+ import type { SetOptional, Simplify } from 'type-fest';
12
+ import LayerManager from './LayerManager';
13
+
14
+ type MapUtilsConstructor = typeof MapUtils;
15
+
16
+ type mapUtilsIns = InstanceType<typeof MapUtils>;
17
+
18
+ export class MapUtils {
19
+ // 地图实例信息
20
+ map: mapIns;
21
+
22
+ options: SetOptional<MapUtilsOpts['MapUtilsCreateOpts'], 'mountSelector'>;
23
+
24
+ LayerManager: LayerManager = new LayerManager();
25
+
26
+ static createAMapMarker = MapMixin.createAMapMarker;
27
+
28
+ static createIcon = MapMixin.createIcon;
29
+
30
+ static Size = MapMixin.Size;
31
+
32
+ static Pixel = MapMixin.Pixel;
33
+
34
+ static LngLat = MapMixin.LngLat;
35
+
36
+ static createAMapInfoWindow = MapMixin.createAMapInfoWindow;
37
+
38
+ constructor(
39
+ opts: MapUtilsOpts[keyof MapUtilsOpts],
40
+ AMap: Simplify<typeof gdAMap>
41
+ ) {
42
+ if (!(typeof AMap === 'object' && 'Map' in AMap)) {
43
+ throw MapUtils.error('AMap is not exist');
44
+ }
45
+
46
+ if ('mapIns' in opts && opts.mapIns instanceof AMap.Map) {
47
+ const { mapIns, ...rest } = opts;
48
+ this.map = opts.mapIns;
49
+ this.options = rest;
50
+ } else {
51
+ if (!('mountSelector' in opts)) {
52
+ throw MapUtils.error('mountSelector is not exist');
53
+ } else {
54
+ this.options = opts;
55
+
56
+ const { mountSelector, ...rest } = opts;
57
+
58
+ this.map = this.initMap(mountSelector, rest); //地图初始化
59
+ }
60
+ }
61
+
62
+ this.bindMapClickEvent();
63
+ }
64
+
65
+ // 初始化绑定地图事件
66
+ bindMapClickEvent() {
67
+ this.map.on('click', () => {
68
+ // if (this.clickMapRestMarkers) {
69
+ // this.overlayGroupManagerMap.forEach((overlayGroup) => {
70
+ // overlayGroup.resetActiveMarker(); // 清除图层上的所有覆盖物
71
+ // });
72
+ // }
73
+ });
74
+ }
75
+
76
+ initMap(id: string, opts: MapOptions): mapIns {
77
+ //参数要作检验吗
78
+ return new window.AMap.Map(id, opts);
79
+ }
80
+
81
+ createBaseMarkerLayer<
82
+ U extends {},
83
+ T extends MarkerLayerBaseType = 'markerLayer',
84
+ >(opts: LayerOpts<U, T>) {
85
+ const layer = new BaseMarkerLayer<U, T>(opts, this);
86
+ // @ts-ignore
87
+ this.LayerManager.addLayer(layer);
88
+ return layer;
89
+ }
90
+
91
+ removeLayer(layer: BaseMarkerLayerIns) {
92
+ const isLayerExist = this.LayerManager.hasLayer(layer);
93
+
94
+ if (isLayerExist) {
95
+ this.LayerManager.removeLayer(layer);
96
+ } else {
97
+ MapUtils.error(`${layer.layerName} is not exist`);
98
+ }
99
+ }
100
+
101
+ /**
102
+ * 根据地图上添加的覆盖物分布情况,自动缩放地图到合适的视野级别
103
+ * @param {Array} overlays - 覆盖物数组,缺省为全部覆盖物
104
+ * @param {Boolean} immediately - 是否立即过渡
105
+ * @param {Array<Number>} avoid - 四周边距,上、下、左、右
106
+ * @param {number} maxZoom - 最大地图zoom级别
107
+ */
108
+ setFitView(...opts: Parameters<mapIns['setFitView']>): void {
109
+ this.map.setFitView(...opts);
110
+ }
111
+
112
+ clearInfoWindow() {
113
+ this.map.clearInfoWindow();
114
+ }
115
+
116
+ seZoomAndCenter(opts: {
117
+ zoom: number;
118
+ center: AMap.LngLat | [number, number];
119
+ immediately?: boolean;
120
+ duration?: number;
121
+ }): void {
122
+ const curZoom = this.map.getZoom();
123
+ const lngAndLat = this.map.getCenter();
124
+ const curCenter: [number, number] = [lngAndLat.lng, lngAndLat.lat];
125
+ let { center = curCenter, zoom = curZoom, immediately, duration } = opts;
126
+
127
+ this.map.setZoomAndCenter(zoom, center, immediately, duration);
128
+ }
129
+
130
+ static error(msg: string) {
131
+ console.error(`[MapUtils Error]:${msg}`);
132
+ }
133
+ }
134
+
135
+ export type { mapUtilsIns, MapUtilsConstructor };
136
+
137
+ export async function createMapUtils(
138
+ opts: MapUtilsOpts[keyof MapUtilsOpts],
139
+ loaderOPts?: loaderOpts
140
+ ) {
141
+ // window上存在属性已经加载
142
+ let AMap = window.AMap;
143
+
144
+ if (loaderOPts) {
145
+ AMap = await initMapSource(loaderOPts);
146
+ }
147
+
148
+ return new MapUtils(opts, AMap);
149
+ }
150
+
151
+ // 地图拆分
152
+ export async function initMapSource(Opts: loaderOpts) {
153
+ return await MapSourceImport.loadScript(Opts);
154
+ }