@sl-utils/map 1.0.8 → 1.0.10

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/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@sl-utils/map",
3
- "version": "1.0.8",
3
+ "version": "1.0.10",
4
4
  "description": "",
5
5
  "main": "index.cjs",
6
6
  "module": "./src/sl-utils-map.ts",
7
7
  "type": "module",
8
- "types": "./src/sl-utils-map.d.ts",
8
+ "types": "./types/sl-utils-map.d.ts",
9
9
  "scripts": {
10
10
  "test": "echo \"Error: no test specified\" && exit 1",
11
11
  "build": "npm run build:cjs",
@@ -32,7 +32,7 @@
32
32
  "exports": {
33
33
  "./package.json": "./package.json",
34
34
  ".": {
35
- "types": "./src/sl-utils-map.d.ts",
35
+ "types": "./types/sl-utils-map.d.ts",
36
36
  "import": "./src/sl-utils-map.ts"
37
37
  }
38
38
  },
@@ -5,15 +5,30 @@ declare var AMap: any;
5
5
 
6
6
  export class SLUMap {
7
7
  constructor(ele: string)
8
- constructor(ele: string)
9
- constructor(ele: string, options: Partial<SLSMapOpt> = {}) {
10
- this.createMap(ele, options)
8
+ constructor(ele: string, options: Partial<SLPMapOpt> = {}) {
9
+ this.ele = ele;
10
+ }
11
+ private ele:string;
12
+ /**地图实例 */
13
+ private _map:L.Map | AMAP.Map;
14
+ public get map(){
15
+ return this._map
11
16
  }
12
-
13
- private map: L.Map | AMAP.Map;
14
17
  /**当前正在显示的网络图层 */
15
18
  private curs: Partial<{ [key in SLEMap]: SLULeafletNetMap | undefined }> = Object.create(null);
16
-
19
+ /**初始实例化地图
20
+ * @param options 地图初始化参数
21
+ */
22
+ public async init(options: Partial<SLPMapOpt> = {}){
23
+ const { type } = options,ele = this.ele;
24
+ let map: L.Map | AMAP.Map;
25
+ switch (type) {
26
+ case "A": this._map = await this.initAmap(ele, options); break;
27
+ default: this._map = await this.initLeaflet(ele, options);
28
+ this.showMap([SLEMap.tianDiTuNormalMap, SLEMap.tianDiTuNormalAnnotion]);
29
+ break;
30
+ }
31
+ }
17
32
  /**显示指定的网络图层 */
18
33
  public showMap(names: Array<SLEMap> = []): this {
19
34
  const { map, curs } = this;
@@ -40,18 +55,8 @@ export class SLUMap {
40
55
  }
41
56
  return this
42
57
  }
43
- private async createMap(ele: string, options: Partial<SLSMapOpt>) {
44
- const { type } = options;
45
- let map: L.Map | AMAP.Map;
46
- switch (type) {
47
- case "A": this.map = await this.initAmap(ele, options); break;
48
- default: this.map = await this.initLeaflet(ele, options);
49
- this.showMap([SLEMap.tianDiTuNormalMap, SLEMap.tianDiTuNormalAnnotion]);
50
- break;
51
- }
52
- }
53
58
  /**---------------leaflet地图的相关方法------------------- */
54
- private initLeaflet(ele: string, opt: Partial<SLSMapOpt>) {
59
+ private initLeaflet(ele: string, opt: Partial<SLPMapOpt>) {
55
60
  const { zoom = 11, minZoom = 2, maxZoom = 20, center: [lat, lng] = [22.68471, 114.12027], dragging = true, zoomControl = false, attributionControl = false, doubleClickZoom = false, closePopupOnClick = false } = opt;
56
61
  let param: L.MapOptions = {
57
62
  dragging,
@@ -69,7 +74,7 @@ export class SLUMap {
69
74
  return Promise.resolve(map)
70
75
  }
71
76
  /**---------------高德地图的相关方法------------------- */
72
- private async initAmap(ele: string, opt: Partial<SLSMapOpt>) {
77
+ private async initAmap(ele: string, opt: Partial<SLPMapOpt>) {
73
78
  const { zoom = 11, minZoom = 2, maxZoom = 20, center: [lat, lng] = [22.68471, 114.12027], dragging = true, zoomControl = false, attributionControl = false, doubleClickZoom = false, closePopupOnClick = false, showLabel = true } = opt;
74
79
  return AMapLoader.load({
75
80
  "key": "87e1b1e9aa88724f69208972546fdd57", // 申请好的Web端开发者Key,首次调用 load 时必填
@@ -101,27 +106,3 @@ export class SLUMap {
101
106
  }
102
107
  }
103
108
 
104
- interface SLSMapOpt {
105
- /**地图的类型 @param L leaflet插件 @param A 高德地图 @param B 百度地图 @default L*/
106
- type: 'L' | 'A' | 'B',
107
- /**地图中心点 [lat,lng] @default [22.68471,114.12027] */
108
- center: [number, number],
109
- /**地图初始层级 @default 11*/
110
- zoom: number,
111
- /**最小层级 @default 2*/
112
- minZoom: number,
113
- /**最大层级 @default 20*/
114
- maxZoom: number,
115
- /**拖拽功能 @default true */
116
- dragging: boolean,
117
- /**显示层级控制器 @default false */
118
- zoomControl: boolean,
119
- /**显示属性控制器 @default false */
120
- attributionControl: boolean,
121
- /**双击放大层级 @default false */
122
- doubleClickZoom: boolean,
123
- /**点击关闭弹窗 @default false */
124
- closePopupOnClick: boolean,
125
- /**显示标签(省会、地名等) @param AMap @default true */
126
- showLabel: boolean,
127
- }
@@ -0,0 +1,4 @@
1
+ export * from "./canvas-draw"
2
+ export * from "./canvas-event"
3
+ export * from "./canvas-layer"
4
+ export * from "./canvas-map"
@@ -0,0 +1 @@
1
+ export * from './plugin-draw'
@@ -0,0 +1,123 @@
1
+ import { MapCanvasDraw, MapCanvasLayer } from "../map";
2
+
3
+ /**地图插件----绘制 */
4
+ export class MapPluginDraw extends MapCanvasLayer {
5
+ constructor(map: AMAP.Map | L.Map, options?: AMAP.CustomLayerOption | MapCanvasPara) {
6
+ super(map, options);
7
+ this._draw = new MapCanvasDraw(map, this.canvas);
8
+ }
9
+ /**地图绘制控制类 */
10
+ protected _draw: MapCanvasDraw;
11
+ /**地图事件引起的重绘绘制 */
12
+ protected override renderFixedData() {
13
+ this.resetCanvas();
14
+ this.drawMapAll();
15
+ }
16
+ /**绘制所有需要绘制的类 */
17
+ public drawMapAll() {
18
+ this._draw.drawMapAll();
19
+ return this;
20
+ }
21
+ /**设置原点 */
22
+ public setAllArcs(arcs: MapArc[]) {
23
+ this._draw.setAllArcs(arcs);
24
+ return this;
25
+ }
26
+ /**设置线数据 */
27
+ public setAllLines(lines: MapLine[]) {
28
+ this._draw.setAllLines(lines);
29
+ return this;
30
+ }
31
+ /**设置贝塞尔曲线数据 */
32
+ public setAllBezierLines(lines: MapLine[]) {
33
+ this._draw.setAllBezierLines(lines);
34
+ return this;
35
+ }
36
+ /**设置多边形数据 */
37
+ public setAllRects(rects: MapRect[]) {
38
+ this._draw.setAllRects(rects);
39
+ return this;
40
+ }
41
+ /**设置文本数据 */
42
+ public setAllTexts(texts: MapText[]) {
43
+ this._draw.setAllTexts(texts);
44
+ return this;
45
+ }
46
+ /**设置图片数据 */
47
+ public setAllImgs(imgs: MapImage[]) {
48
+ this._draw.setAllImgs(imgs);
49
+ return this;
50
+ }
51
+ /**设置gif数据 */
52
+ public setAllGifs(gifs: MapGif[]) {
53
+ this._draw.setAllGifs(gifs);
54
+ return this;
55
+ }
56
+ /**增加原点 */
57
+ public addArc(arc: MapArc) {
58
+ this._draw.addArc(arc);
59
+ return this;
60
+ }
61
+ /**增加线 */
62
+ public addLine(line: MapLine) {
63
+ this._draw.addLine(line);
64
+ return this;
65
+ }
66
+ /**增加贝塞尔曲线 */
67
+ public addBezierLine(line: MapLine) {
68
+ this._draw.addBezierLine(line);
69
+ return this;
70
+ }
71
+ /**增加多边形 */
72
+ public addRect(rect: MapRect) {
73
+ this._draw.addRect(rect);
74
+ return this;
75
+ }
76
+ /**增加文本 */
77
+ public addText(text: MapText) {
78
+ this._draw.addText(text);
79
+ return this;
80
+ }
81
+ /**增加图片 */
82
+ public addImg(img: MapImage) {
83
+ this._draw.addImg(img);
84
+ return this;
85
+ }
86
+ /**删除指定圆点 */
87
+ public delArc(arc: MapArc) {
88
+ this._draw.delArc(arc);
89
+ return this;
90
+ }
91
+ /**删除指定线 */
92
+ public delLine(line: MapLine) {
93
+ this._draw.delLine(line);
94
+ return this;
95
+ }
96
+ /**删除指定贝塞尔曲线 */
97
+ public delBezierLine(line: MapLine) {
98
+ this._draw.delBezierLine(line);
99
+ return this;
100
+ }
101
+ /**删除指定多边形 */
102
+ public delRect(rect: MapRect) {
103
+ this._draw.delRect(rect);
104
+ return this;
105
+ }
106
+ /**删除指定多边形 */
107
+ public delText(text: MapText) {
108
+ this._draw.delText(text);
109
+ return this;
110
+ }
111
+ /**删除指定Img */
112
+ public delImg(img: MapImage) {
113
+ this._draw.delImg(img);
114
+ return this;
115
+ }
116
+ /**清空
117
+ * @param type 不填清空所有内容数据
118
+ */
119
+ public delAll(type: 'all' | 'arc' | 'line' | 'bezier' | 'rect' | 'img' | 'gif' = 'all') {
120
+ this._draw.delAll(type);
121
+ return this;
122
+ }
123
+ }
@@ -1,4 +1,5 @@
1
1
  export * from './canvas'
2
+ export * from './plugins'
2
3
  export { MapCanvasDraw } from './map/canvas-draw'
3
4
  export { MapCanvasEvent } from './map/canvas-event'
4
5
  export { MapCanvasLayer } from './map/canvas-layer'
package/tsconfig.json CHANGED
@@ -15,17 +15,12 @@
15
15
  "dom"
16
16
  ],
17
17
  "paths": {
18
- "@/*": ["src/*"],
19
- "@sl-utils/*": ["src/utils/*"] // 添加这行
18
+ "@sl-utils/map": ["types/sl-utils-map.d.ts"] // 添加这行
20
19
  }
21
20
  },
22
21
  "include": [
23
22
  "src/**/*",
24
23
  "types/**/*",
25
- "src/**/*.ts",
26
- "src/**/*.d.ts",
27
- "src/**/*.tsx",
28
- "src/**/*.vue"
29
24
  ],
30
25
  "exclude": []
31
26
  }
package/types/core.d.ts CHANGED
@@ -164,6 +164,31 @@ interface CanvasLine<I = any> extends SLPCanvas {
164
164
  }
165
165
 
166
166
  /**canvas绘图类型空间 */
167
+
168
+ interface SLPMapOpt {
169
+ /**地图的类型 @param L leaflet插件 @param A 高德地图 @param B 百度地图 @default L*/
170
+ type: 'L' | 'A' | 'B',
171
+ /**地图中心点 [lat,lng] @default [22.68471,114.12027] */
172
+ center: [number, number],
173
+ /**地图初始层级 @default 11*/
174
+ zoom: number,
175
+ /**最小层级 @default 2*/
176
+ minZoom: number,
177
+ /**最大层级 @default 20*/
178
+ maxZoom: number,
179
+ /**拖拽功能 @default true */
180
+ dragging: boolean,
181
+ /**显示层级控制器 @default false */
182
+ zoomControl: boolean,
183
+ /**显示属性控制器 @default false */
184
+ attributionControl: boolean,
185
+ /**双击放大层级 @default false */
186
+ doubleClickZoom: boolean,
187
+ /**点击关闭弹窗 @default false */
188
+ closePopupOnClick: boolean,
189
+ /**显示标签(省会、地名等) @param AMap @default true */
190
+ showLabel: boolean,
191
+ }
167
192
  declare namespace SLTCanvas {
168
193
  /**canvse上的点位信息 */
169
194
  type Point = CanvasPoint | CanvasPoints;
@@ -0,0 +1,134 @@
1
+ declare module '@sl-utils/map' {
2
+ /**leaflet 需要开发者在样式表中挂载leaflet样式 */
3
+ export class SLUMap {
4
+ constructor(ele: string,);
5
+ map: AMAP.Map | L.Map
6
+ /**初始实例化地图
7
+ * @param options 地图初始化参数
8
+ */
9
+ public init(options?: Partial<SLPMapOpt>): Promise<void>
10
+ }
11
+ // 添加其他导出...
12
+ export class MapCanvasDraw {
13
+ constructor();
14
+ }
15
+ export class MapCanvasEvent {
16
+ constructor();
17
+ }
18
+
19
+ /** 地图canvas基础图层类(基本所有插件都要继承此类) 删除永远比新增简单 */
20
+ export class MapCanvasLayer {
21
+ constructor(MAP: L.Map, opt?: MapCanvasPara)
22
+ constructor(MAP: AMAP.Map, opt?: AMAP.CustomLayerOption)
23
+ constructor(MAP: AMAP.Map | L.Map, opt?: AMAP.CustomLayerOption | MapCanvasPara)
24
+ /**开发自己设置项目使用了的地图插件类型Leaflet(0)、高德(1)、百度(2),防止网络加载的第三方插件再使用instanceof是为define*/
25
+ protected readonly type: 0 | 1 | 2;
26
+ protected readonly map: AMAP.Map | L.Map;
27
+ private layer: L.Layer | AMAP.CustomLayer;
28
+ protected readonly canvas: HTMLCanvasElement;
29
+ protected readonly ctx: CanvasRenderingContext2D;
30
+ protected width: number;
31
+ protected height: number;
32
+ public readonly options: SLPMap.Canvas;
33
+ /**动画循环的id标识 */
34
+ protected flagAnimation: number;
35
+ /**移除图层 */
36
+ public onRemove(): MapCanvasLayer;
37
+ /** 清空并重新设置画布 */
38
+ public resetCanvas(): void
39
+ /**添加或关闭地图特定的监听事件(_eventSwitch事件后自动调用) */
40
+ protected addMapEvents(map: AMAP.Map | L.Map, key: 'on' | 'off'): void
41
+ /**绘制静态数据推荐使用此方法(固定的图) */
42
+ protected renderFixedData(): void
43
+ /** 推荐使用此方法绘制动态图(跟随鼠标拖动,移动时需要立刻绘制时)
44
+ ** 动画图层绘制前的画布清空、计算等均在此方法中自行计算
45
+ ** 与renderFixedData本质是一样的
46
+ */
47
+ protected renderAnimation(): void
48
+ /** */
49
+ protected on(key: string, cb: Function): void
50
+ /** */
51
+ protected off(key: string, cb: Function): void
52
+ /**初始化canvas */
53
+ private initCanvas(): void
54
+ /** 将图层添加到map实例中显示 */
55
+ private onAdd(): this
56
+ /**基础的监听事件
57
+ * @param flag true开启重绘事件监听 false 关闭重绘事件监听
58
+ **/
59
+ private _eventSwitch(flag?: boolean): void
60
+ /**基础绘制 */
61
+ /** 重绘(子类重写也无效)
62
+ ** 清空之前的绘制
63
+ ** ①高德地图渲染配置alwaysRender:true后拖动缩放会多次渲染
64
+ */
65
+ protected _redraw: () => {};
66
+ /**------------------------------高德地图的实现------------------------------*/
67
+ private _onAmapAdd(): void
68
+ private _onAmapRemove(): void
69
+ /**------------------------------Leaflet地图的实现------------------------------*/
70
+ /**初始化画布并添加到Pane中 */
71
+ private initLeafletCanvas(): void
72
+ /**移除 */
73
+ private _onLeafletRemove(): void
74
+ private addLeafletEvent(flag?: boolean): void
75
+ /**重设画布,并重新渲染*/
76
+ private _reset(): void
77
+ /**缩放动画 */
78
+ private _animateZoom(e: any): void
79
+ private _onCanvasLoad(): void
80
+ }
81
+
82
+ /**地图插件----绘制 */
83
+ export class MapPluginDraw extends MapCanvasLayer {
84
+ constructor(map: AMAP.Map | L.Map, options?: AMAP.CustomLayerOption | MapCanvasPara)
85
+ /**地图绘制控制类 */
86
+ protected _draw: MapCanvasDraw;
87
+ /**地图事件引起的重绘绘制 */
88
+ protected override renderFixedData(): void
89
+ /**绘制所有需要绘制的类 */
90
+ public drawMapAll(): this
91
+ /**设置原点 */
92
+ public setAllArcs(arcs: MapArc[]): this
93
+ /**设置线数据 */
94
+ public setAllLines(lines: MapLine[]): this
95
+ /**设置贝塞尔曲线数据 */
96
+ public setAllBezierLines(lines: MapLine[]): this
97
+ /**设置多边形数据 */
98
+ public setAllRects(rects: MapRect[]): this
99
+ /**设置文本数据 */
100
+ public setAllTexts(texts: MapText[]): this
101
+ /**设置图片数据 */
102
+ public setAllImgs(imgs: MapImage[]): this
103
+ /**设置gif数据 */
104
+ public setAllGifs(gifs: MapGif[]): this
105
+ /**增加原点 */
106
+ public addArc(arc: MapArc): this
107
+ /**增加线 */
108
+ public addLine(line: MapLine): this
109
+ /**增加贝塞尔曲线 */
110
+ public addBezierLine(line: MapLine): this
111
+ /**增加多边形 */
112
+ public addRect(rect: MapRect): this
113
+ /**增加文本 */
114
+ public addText(text: MapText): this
115
+ /**增加图片 */
116
+ public addImg(img: MapImage): this
117
+ /**删除指定圆点 */
118
+ public delArc(arc: MapArc): this
119
+ /**删除指定线 */
120
+ public delLine(line: MapLine): this
121
+ /**删除指定贝塞尔曲线 */
122
+ public delBezierLine(line: MapLine): this
123
+ /**删除指定多边形 */
124
+ public delRect(rect: MapRect): this
125
+ /**删除指定多边形 */
126
+ public delText(text: MapText): this
127
+ /**删除指定Img */
128
+ public delImg(img: MapImage): this
129
+ /**清空
130
+ * @param type 不填清空所有内容数据
131
+ */
132
+ public delAll(type?: 'all' | 'arc' | 'line' | 'bezier' | 'rect' | 'img' | 'gif'): this;
133
+ }
134
+ }
package/demo/app.d.ts DELETED
@@ -1,3 +0,0 @@
1
- declare module "UU" {
2
- export class UU { }
3
- }
package/demo/main.js DELETED
@@ -1,7 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const vue_1 = require("vue");
4
- require("./style.css");
5
- const App_vue_1 = require("./App.vue");
6
- (0, vue_1.createApp)(App_vue_1.default).mount('#app');
7
- //# sourceMappingURL=main.js.map
package/demo/main.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"main.js","sourceRoot":"","sources":["main.ts"],"names":[],"mappings":";;AAAA,6BAA+B;AAC/B,uBAAoB;AACpB,uCAA2B;AAE3B,IAAA,eAAS,EAAC,iBAAG,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,CAAA"}
@@ -1,16 +0,0 @@
1
- declare module '@sl-utils/map' {
2
- /**leaflet 需要开发者在样式表中挂载leaflet样式 */
3
- export class SLUMap {
4
- constructor(ele: string);
5
- }
6
- // 添加其他导出...
7
- export class MapCanvasDraw {
8
- constructor();
9
- }
10
- export class MapCanvasEvent {
11
- constructor();
12
- }
13
- export class MapCanvasLayer {
14
- constructor();
15
- }
16
- }