tg-map-vue3 3.3.8 → 3.4.0

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 (33) hide show
  1. package/dist/src/components/index.d.ts +2 -0
  2. package/dist/src/components/overlays/TgCircle.vue.d.ts +25 -3
  3. package/dist/src/components/overlays/TgInfoWindow.vue.d.ts +14 -3
  4. package/dist/src/components/overlays/TgLabel.vue.d.ts +7 -4
  5. package/dist/src/components/overlays/TgMarker.vue.d.ts +31 -7
  6. package/dist/src/components/overlays/TgPolygon.vue.d.ts +20 -4
  7. package/dist/src/components/overlays/TgPolyline.vue.d.ts +21 -5
  8. package/dist/src/components/overlays/TgRectangle.vue.d.ts +88 -0
  9. package/dist/src/map/event-target.d.ts +22 -1
  10. package/dist/src/map/lat-lng.d.ts +29 -3
  11. package/dist/src/map/map/baidu-map.d.ts +2 -0
  12. package/dist/src/map/map/google-map.d.ts +2 -0
  13. package/dist/src/map/map/here-map.d.ts +1 -0
  14. package/dist/src/map/map/map.d.ts +4 -2
  15. package/dist/src/map/map/overlay/circle.d.ts +13 -2
  16. package/dist/src/map/map/overlay/info-window.d.ts +1 -2
  17. package/dist/src/map/map/overlay/marker.d.ts +4 -5
  18. package/dist/src/map/map/overlay/overlay.d.ts +9 -5
  19. package/dist/src/map/map/overlay/polygon.d.ts +13 -4
  20. package/dist/src/map/map/overlay/polyline.d.ts +31 -3
  21. package/dist/src/map/map/overlay/rectangle.d.ts +52 -0
  22. package/dist/src/map/map/overlay/shape.d.ts +3 -1
  23. package/dist/src/map/unions.d.ts +1 -1
  24. package/dist/src/utils/arrays.d.ts +17 -1
  25. package/dist/src/utils/baidu-utils.d.ts +4 -0
  26. package/dist/src/utils/google-utils.d.ts +1 -0
  27. package/dist/src/utils/mapped-types.d.ts +6 -0
  28. package/dist/src/utils/vue-utils.d.ts +3 -7
  29. package/dist/tg-map.js +2664 -2236
  30. package/dist/tg-map.js.map +1 -1
  31. package/dist/tg-map.umd.cjs +7 -7
  32. package/dist/tg-map.umd.cjs.map +1 -1
  33. package/package.json +1 -1
@@ -1,18 +1,21 @@
1
1
  /// <reference types="baidumap-web-sdk" />
2
2
  /// <reference types="google.maps" />
3
3
  import type { Tg } from '../../event';
4
+ import { EventHubEventTargetDelegate } from '../../event-target';
4
5
  import { LatLng } from '../../lat-lng';
5
6
  import type { BaiduMap } from '../baidu-map';
6
7
  import type { GoogleMap } from '../google-map';
7
8
  import type { Overlay } from './overlay';
8
9
  import { BaiduShape, GoogleShape, type Shape, type ShapeOptions } from './shape';
9
- type CircleEventMap = {
10
+ export type CircleEventMap = {
10
11
  click: Tg.Event;
11
12
  dblclick: Tg.Event;
12
13
  mousedown: Tg.MouseEvent;
13
14
  mouseup: Tg.MouseEvent;
14
15
  mouseout: Tg.MouseEvent;
15
16
  mouseover: Tg.MouseEvent;
17
+ 'radius-changed': Tg.Event;
18
+ 'center-changed': Tg.Event;
16
19
  };
17
20
  export interface CircleOptions extends ShapeOptions {
18
21
  center: LatLng;
@@ -27,6 +30,15 @@ export interface Circle extends Tg.EventTargetTyped<Circle, CircleEventMap>, Sha
27
30
  export type CircleOverlay = Circle & Overlay;
28
31
  export declare class BaiduCircle extends BaiduShape<BMap.Circle> implements Circle {
29
32
  static create(this: BaiduMap, options: CircleOptions): BaiduCircle;
33
+ private prevCenter;
34
+ private prevRadius;
35
+ private isDoingSetCenter;
36
+ private isDoingSetRadius;
37
+ private eventHubDelegate;
38
+ protected createDelegate(): EventHubEventTargetDelegate<"radius-changed" | "center-changed">;
39
+ private onRadiusChanged;
40
+ private onCenterChanged;
41
+ private resetEditableTimeoutId;
30
42
  setCenter(center: LatLng): void;
31
43
  getCenter(): LatLng;
32
44
  setRadius(radius: number): void;
@@ -39,4 +51,3 @@ export declare class GoogleCircle extends GoogleShape<google.maps.Circle> implem
39
51
  setRadius(radius: number): void;
40
52
  getRadius(): number;
41
53
  }
42
- export {};
@@ -47,7 +47,7 @@ export interface InfoWindowOptions {
47
47
  *
48
48
  * 结论: 在baidu以外的地图上模拟open/close事件, 保证行为一致
49
49
  */
50
- type InfoWindowEventMap = {
50
+ export type InfoWindowEventMap = {
51
51
  closeclick: Tg.Event;
52
52
  /**
53
53
  * ## 不同实现
@@ -109,4 +109,3 @@ export declare class GoogleInfoWindow extends InfoWindow {
109
109
  getPosition(): LatLng;
110
110
  setPosition(position: LatLng): void;
111
111
  }
112
- export {};
@@ -33,15 +33,15 @@ export interface MarkerOptions extends OverlayOptions {
33
33
  zIndex?: number;
34
34
  }
35
35
  /** 仅仅起到类型声明的作用... */
36
- type MarkerEventMap = {
37
- click: Tg.Event;
36
+ export type MarkerEventMap = {
37
+ click: Tg.MouseEvent;
38
38
  dblclick: Tg.MouseEvent;
39
- rightclick: Tg.Event;
39
+ rightclick: Tg.MouseEvent;
40
40
  mousedown: Tg.MouseEvent;
41
41
  mouseup: Tg.MouseEvent;
42
42
  mouseout: Tg.MouseEvent;
43
43
  mouseover: Tg.MouseEvent;
44
- dragstart: Tg.Event;
44
+ dragstart: Tg.MouseEvent;
45
45
  drag: Tg.MouseEvent;
46
46
  dragend: Tg.MouseEvent;
47
47
  };
@@ -122,4 +122,3 @@ export declare class GoogleMarker extends GoogleOverlay<google.maps.Marker> impl
122
122
  getZIndex(): number | undefined;
123
123
  setLabel(label: GoogleLabelOverlay | undefined): void;
124
124
  }
125
- export {};
@@ -1,5 +1,5 @@
1
1
  import type { Tg } from '../../event';
2
- import { AbstractEventTargetDelegate } from '../../event-target';
2
+ import { type EventTargetDelegate } from '../../event-target';
3
3
  import type { CoordType } from '../../lat-lng';
4
4
  import type { UnionBaiduOverlay, UnionGoogleOverlay } from '../../unions';
5
5
  import type { AbstractMap } from '../map';
@@ -12,23 +12,27 @@ export declare abstract class Overlay<T = unknown> implements Tg.EventTarget {
12
12
  /** 用于保存Overlay内部点的坐标, 它的值有可能和map的不同 */
13
13
  protected coordType: CoordType;
14
14
  protected map: AbstractMap;
15
- private delegate;
16
- addEventListener: (type: string, listener: Tg.EventListener) => void;
17
- removeEventListener: (type: string, listener: Tg.EventListener) => void;
18
15
  constructor(innerOverlay: T,
19
16
  /** 用于保存Overlay内部点的坐标, 它的值有可能和map的不同 */
20
- coordType: CoordType, map: AbstractMap, delegate: AbstractEventTargetDelegate);
17
+ coordType: CoordType, map: AbstractMap);
18
+ protected abstract createDelegate(): EventTargetDelegate;
19
+ private _delegate;
20
+ private get delegate();
21
+ addEventListener(type: string, listener: Tg.EventListener): void;
22
+ removeEventListener(type: string, listener: Tg.EventListener): void;
21
23
  remove(): void;
22
24
  abstract isVisible(): boolean;
23
25
  abstract setVisible(visible: boolean): void;
24
26
  }
25
27
  export declare class GoogleOverlay<T extends UnionGoogleOverlay = UnionGoogleOverlay> extends Overlay<T> {
26
28
  constructor(innerOverlay: T, coordType: CoordType, map: AbstractMap);
29
+ protected createDelegate(): EventTargetDelegate;
27
30
  isVisible(): boolean;
28
31
  setVisible(visible: boolean): void;
29
32
  }
30
33
  export declare class BaiduOverlay<T extends UnionBaiduOverlay = UnionBaiduOverlay> extends Overlay<T> {
31
34
  constructor(innerOverlay: T, coordType: CoordType, map: AbstractMap);
35
+ protected createDelegate(): EventTargetDelegate;
32
36
  /** 仅限内部使用; 设为private时, 生成的d.ts文件中, 方法返回值会变成any, 故改成了public */
33
37
  get overlay(): Required<Pick<UnionBaiduOverlay, "isVisible" | "show" | "hide">>;
34
38
  isVisible(): boolean;
@@ -1,18 +1,22 @@
1
1
  /// <reference types="baidumap-web-sdk" />
2
2
  /// <reference types="google.maps" />
3
3
  import type { Tg } from '../../event';
4
+ import { EventHubEventTargetDelegate } from '../../event-target';
4
5
  import { LatLng } from '../../lat-lng';
5
6
  import type { BaiduMap } from '../baidu-map';
6
7
  import type { GoogleMap } from '../google-map';
7
8
  import type { Overlay } from './overlay';
8
- import { BaiduShape, GoogleShape, type Shape, type ShapeOptions } from './shape';
9
- type PolygonEventMap = {
9
+ import { BaiduPolyShape } from './polyline';
10
+ import { GoogleShape, type Shape, type ShapeOptions } from './shape';
11
+ export type PolygonEventMap = {
10
12
  click: Tg.Event;
11
13
  dblclick: Tg.Event;
12
14
  mousedown: Tg.MouseEvent;
13
15
  mouseup: Tg.MouseEvent;
14
16
  mouseout: Tg.MouseEvent;
15
17
  mouseover: Tg.MouseEvent;
18
+ /** @see PolylineEventMap `.path-edited` */
19
+ 'paths-edited': Tg.Event;
16
20
  };
17
21
  export interface PolygonOptions extends ShapeOptions {
18
22
  paths: LatLng[][];
@@ -22,14 +26,19 @@ export interface Polygon extends Tg.EventTargetTyped<Polygon, PolygonEventMap>,
22
26
  setPaths(paths: LatLng[][]): void;
23
27
  }
24
28
  export type PolygonOverlay = Polygon & Overlay;
25
- export declare class BaiduPolygon extends BaiduShape<BMap.Polygon> implements Polygon {
29
+ export declare class BaiduPolygon extends BaiduPolyShape<BMap.Polygon> implements Polygon {
26
30
  static create(this: BaiduMap, options: PolygonOptions): BaiduPolygon;
31
+ protected pathEditedEventType: string;
27
32
  getPaths(): LatLng[][];
28
33
  setPaths(paths: LatLng[][]): void;
29
34
  }
30
35
  export declare class GooglePolygon extends GoogleShape<google.maps.Polygon> implements Polygon {
31
36
  static create(this: GoogleMap, options: PolygonOptions): GooglePolygon;
37
+ private pathChangedListeners;
38
+ private setupPathChangedListeners;
39
+ private clearPathChangedListeners;
40
+ private eventHubDelegate;
41
+ protected createDelegate(): EventHubEventTargetDelegate<"paths-edited">;
32
42
  getPaths(): LatLng[][];
33
43
  setPaths(paths: LatLng[][]): void;
34
44
  }
35
- export {};
@@ -1,18 +1,30 @@
1
1
  /// <reference types="baidumap-web-sdk" />
2
+ /// <reference types="baidumap-web-sdk" />
2
3
  /// <reference types="google.maps" />
3
4
  import type { Tg } from '../../event';
5
+ import { EventHubEventTargetDelegate } from '../../event-target';
4
6
  import { LatLng } from '../../lat-lng';
5
7
  import type { BaiduMap } from '../baidu-map';
6
8
  import type { GoogleMap } from '../google-map';
7
9
  import type { Overlay } from './overlay';
8
10
  import { BaiduShape, GoogleShape, type NotFillableShape, type NotFillableShapeOptions } from './shape';
9
- type PolylineEventMap = {
11
+ export type PolylineEventMap = {
10
12
  click: Tg.Event;
11
13
  dblclick: Tg.Event;
12
14
  mousedown: Tg.MouseEvent;
13
15
  mouseup: Tg.MouseEvent;
14
16
  mouseout: Tg.MouseEvent;
15
17
  mouseover: Tg.MouseEvent;
18
+ /**
19
+ * 在`editable`模式下编辑了path的事件
20
+ * 外部调用{@link Polyline#setPath}, 不触发该事件 (之所以这样设计, 是为了避免频繁的进行LatLng<=>地图点对象的相互转换)
21
+ *
22
+ * ## 原理
23
+ * 该事件的实现比较杂, 原始地图并没有等效的事件, 都是通过转换实现的
24
+ * - google: 通过监听path的`insert/remove/set_at`实现
25
+ * - baidu: 通过监听`lineupdate`事件, 然后判断path有没有被修改, 来实现的
26
+ */
27
+ 'path-edited': Tg.Event;
16
28
  };
17
29
  export interface PolylineOptions extends NotFillableShapeOptions {
18
30
  path: LatLng[];
@@ -22,14 +34,30 @@ export interface Polyline extends Tg.EventTargetTyped<Polyline, PolylineEventMap
22
34
  setPath(path: LatLng[]): void;
23
35
  }
24
36
  export type PolylineOverlay = Polyline & Overlay;
25
- export declare class BaiduPolyline extends BaiduShape<BMap.Polyline> implements Polyline {
37
+ export declare abstract class BaiduPolyShape<T extends BMap.Polyline | BMap.Polygon> extends BaiduShape<T> {
38
+ /** 路径被编辑的事件名 */
39
+ protected abstract pathEditedEventType: string;
40
+ /** 修改路径, 仅内部使用 */
41
+ protected setPathInternal(path: BMap.Point[]): void;
42
+ private eventHubDelegate;
43
+ protected createDelegate(): EventHubEventTargetDelegate<string>;
44
+ private prevPath;
45
+ private isDoingSetPath;
46
+ private onLineUpdate;
47
+ }
48
+ export declare class BaiduPolyline extends BaiduPolyShape<BMap.Polyline> implements Polyline {
26
49
  static create(this: BaiduMap, options: PolylineOptions): BaiduPolyline;
50
+ protected pathEditedEventType: string;
27
51
  getPath(): LatLng[];
28
52
  setPath(path: LatLng[]): void;
29
53
  }
30
54
  export declare class GooglePolyline extends GoogleShape<google.maps.Polyline> implements Polyline {
31
55
  static create(this: GoogleMap, options: PolylineOptions): GooglePolyline;
56
+ private pathChangedListeners;
57
+ private setupPathChangedListeners;
58
+ private clearPathChangedListeners;
59
+ private eventHubDelegate;
60
+ protected createDelegate(): EventHubEventTargetDelegate<"path-edited">;
32
61
  getPath(): LatLng[];
33
62
  setPath(path: LatLng[]): void;
34
63
  }
35
- export {};
@@ -0,0 +1,52 @@
1
+ /// <reference types="baidumap-web-sdk" />
2
+ /// <reference types="google.maps" />
3
+ import type { Tg } from '../../event';
4
+ import { CoordType, LatLngBounds } from '../../lat-lng';
5
+ import type { BaiduMap } from '../baidu-map';
6
+ import type { GoogleMap } from '../google-map';
7
+ import type { Overlay } from './overlay';
8
+ import { BaiduPolyShape } from './polyline';
9
+ import { GoogleShape, type Shape, type ShapeOptions } from './shape';
10
+ export type RectangleEventMap = {
11
+ click: Tg.Event;
12
+ dblclick: Tg.Event;
13
+ mousedown: Tg.MouseEvent;
14
+ mouseup: Tg.MouseEvent;
15
+ mouseout: Tg.MouseEvent;
16
+ mouseover: Tg.MouseEvent;
17
+ /**
18
+ * - google: 监听[bounds_changed](https://developers.google.com/maps/documentation/javascript/shapes#editable_events)
19
+ * - baidu: 内部使用Polygon并监听`lineupdate`实现
20
+ */
21
+ 'bounds-changed': Tg.Event;
22
+ };
23
+ export interface RectangleOptions extends ShapeOptions {
24
+ bounds: LatLngBounds;
25
+ }
26
+ export interface Rectangle extends Tg.EventTargetTyped<Rectangle, RectangleEventMap>, Shape {
27
+ getBounds(): LatLngBounds;
28
+ setBounds(bounds: LatLngBounds): void;
29
+ }
30
+ /**
31
+ * 矩形覆盖物
32
+ *
33
+ * - google: 有矩形
34
+ * - baidu: 没有矩形, 使用{@link BMap.Polygon}变相实现
35
+ */
36
+ export type RectangleOverlay = Rectangle & Overlay;
37
+ export declare class BaiduRectangle extends BaiduPolyShape<BMap.Polygon> implements Rectangle {
38
+ static create(this: BaiduMap, options: RectangleOptions): BaiduRectangle;
39
+ constructor(innerOverlay: BMap.Polygon, coordType: CoordType, map: BaiduMap, state: {
40
+ editable: boolean;
41
+ });
42
+ protected pathEditedEventType: string;
43
+ private isDoingUpdateRectangle;
44
+ private onBoundsChanged;
45
+ getBounds(): LatLngBounds;
46
+ setBounds(bounds: LatLngBounds): void;
47
+ }
48
+ export declare class GoogleRectangle extends GoogleShape<google.maps.Rectangle> implements Rectangle {
49
+ static create(this: GoogleMap, options: RectangleOptions): GoogleRectangle;
50
+ getBounds(): LatLngBounds;
51
+ setBounds(bounds: LatLngBounds): void;
52
+ }
@@ -25,7 +25,9 @@ export interface Shape {
25
25
  export type NotFillableShape = Omit<Shape, 'setFillColor' | 'setFillOpacity'>;
26
26
  export type NotFillableShapeOptions = Omit<ShapeOptions, 'fillColor' | 'fillOpacity'>;
27
27
  export declare abstract class BaiduShape<T extends UnionBaiduShape> extends BaiduOverlay<T> implements Shape {
28
- private state;
28
+ protected state: {
29
+ editable: boolean;
30
+ };
29
31
  constructor(innerOverlay: T, coordType: CoordType, map: BaiduMap, state: {
30
32
  editable: boolean;
31
33
  });
@@ -18,6 +18,6 @@ export type UnionBaiduOverlay = BMap.Marker | BMap.Polyline | BMap.Polygon | BMa
18
18
  export type UnionGoogleEventTarget = google.maps.MVCObject;
19
19
  export type UnionBaiduEventTarget = UnionBaiduOverlay | BMap.InfoWindow | BMap.Autocomplete | BMap.Map;
20
20
  export type UnionBaiduShape = BMap.Polyline | BMap.Polygon | BMap.Circle;
21
- export type UnionGoogleShape = google.maps.Polyline | google.maps.Polygon | google.maps.Circle;
21
+ export type UnionGoogleShape = google.maps.Polyline | google.maps.Polygon | google.maps.Circle | google.maps.Rectangle;
22
22
  export type UnionControl = BMap.Control | HTMLElement;
23
23
  export type GoogleLayer = google.maps.TrafficLayer | google.maps.TransitLayer | google.maps.KmlLayer | google.maps.BicyclingLayer;
@@ -1,10 +1,26 @@
1
1
  /// <reference types="google.maps" />
2
- import type { Constructor } from '../components';
2
+ import type { AnyFunction, Constructor } from '../components';
3
3
  export declare namespace Arrays {
4
+ /**
5
+ * 浅层比较
6
+ * @see https://stackoverflow.com/questions/7837456/how-to-compare-arrays-in-javascript
7
+ * */
8
+ function equals<T>(a: T[], b: T[]): boolean;
4
9
  function remove<T>(arr: T[], item: T): T | undefined;
5
10
  function findByType<T>(arr: any[], constructor: Constructor<T>): T | undefined;
11
+ /** 自动推断item的类型的{@link Array.includes} */
12
+ function includesTyped<T extends E, E>(arr: T[], item: E): item is T;
13
+ /** 设置 指定位置的值 */
14
+ function at<T>(arr: T[], index: number, value: T): void;
15
+ /** 获取 指定位置的值 */
16
+ function at<T>(arr: T[], index: number): T | undefined;
6
17
  }
7
18
  export declare namespace MVCArrays {
8
19
  function indexOf<T>(arr: google.maps.MVCArray<T>, item: T): number;
9
20
  function remove<T>(arr: google.maps.MVCArray<T>, item: T): T | undefined;
21
+ /**
22
+ * 监听数组内容变化
23
+ * @see https://developers.google.com/maps/documentation/javascript/shapes#editable_events
24
+ * */
25
+ function listenChanged<T>(path: google.maps.MVCArray<T>, handler: AnyFunction): google.maps.MapsEventListener[];
10
26
  }
@@ -3,3 +3,7 @@
3
3
  * @see http://lbsyun.baidu.com/cms/jsapi/reference/jsapi_reference_3_0.html#a3b0
4
4
  */
5
5
  export declare function ensureBaiduV3(): void;
6
+ export declare const BMapPoints: {
7
+ /** {@link BMap.Point.equals} 无效, 故需要自己写一个 */
8
+ equals(a: BMap.Point, b: BMap.Point): boolean;
9
+ };
@@ -15,6 +15,7 @@ export declare function initGoogleMapDynamicLibraryImport(args: {
15
15
  export declare const GoogleConst: {
16
16
  /** Google的坐标0点 */
17
17
  readonly LATLNG_ZERO: google.maps.LatLng;
18
+ readonly BOUNDS_ZERO: google.maps.LatLngBounds;
18
19
  };
19
20
  export interface AddressFields {
20
21
  /** 国家 */
@@ -3,6 +3,8 @@ import type { Component, ComponentPublicInstance } from 'vue';
3
3
  export type DeepPartial<T> = {
4
4
  [U in keyof T]?: T[U] extends object ? DeepPartial<T[U]> : T[U];
5
5
  };
6
+ /** 表示一个函数 */
7
+ export type AnyFunction = (...args: any[]) => any;
6
8
  /**
7
9
  * 表示一个构造器
8
10
  * {@link import('vue/types/options').Constructor}
@@ -72,7 +74,11 @@ export declare function unwrapStringEnumValue<E extends StringEnumLike>(value: S
72
74
  export declare function unwrapStringEnumValue<E extends StringEnumLike>(value: StringEnumValue<E> | undefined, enumObject?: E): E[keyof E] | undefined;
73
75
  /**
74
76
  * 非空的值
77
+ *
78
+ * 类型`{}`也表示"任何非空的值", 但由于它看起来像空对象, 所以一般更推荐用Thing
79
+ *
75
80
  * @see https://github.com/microsoft/TypeScript/issues/7648#issuecomment-541625573
81
+ * @see https://github.com/typescript-eslint/typescript-eslint/issues/2063#issuecomment-675156492
76
82
  */
77
83
  export type Thing = string | number | boolean | bigint | object | symbol;
78
84
  /** 除T指定的类型外, 其他参数 */
@@ -176,12 +176,8 @@ export type EventEmits<T> = {
176
176
  };
177
177
  /** 给事件类型的属性标注类型 */
178
178
  export declare function eventProp<E = any>(): Prop<EventCallback<E>>;
179
- export declare const eventLogMethods: {
180
- /**
181
- * @event 一般来说传{@link Tg.Event}对象, 但传其他对象也不会报错
182
- */
183
- eventLog(this: any, event: Thing | null | undefined): void;
184
- /** @see eventLog */
185
- eventLogLess(this: any, event: Thing | null | undefined): void;
179
+ export declare const useEventLogMethods: () => {
180
+ eventLog: (event: Thing | null | undefined) => void;
181
+ eventLogLess: (this: any, event: Thing | null | undefined) => void;
186
182
  };
187
183
  export {};