tg-map-vue3 3.7.0 → 3.7.3

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/CHANGELOG.md CHANGED
@@ -3,6 +3,7 @@
3
3
  ## 3.7.x
4
4
 
5
5
  - feat: 添加[IconSequence]到[TgPolyline]中
6
+ - ***BREAKING CHANGE***: [MapStyle]简化成纯对象, 方便使用
6
7
 
7
8
  ## 3.6.x
8
9
 
@@ -67,3 +68,4 @@
67
68
  [LatLngBounds]: src/map/lat-lng.ts#L157
68
69
  [LatLng]: src/map/lat-lng.ts#L26
69
70
  [BaiduShape]: src/map/map/overlay/shape.ts#L32
71
+ [MapStyle]: src/map/map/map-options.ts#72
@@ -202,16 +202,16 @@ declare const _default: import("vue").DefineComponent<{
202
202
  "onUpdate:last-center"?: ((event: LatLng) => any) | undefined;
203
203
  onClick?: ((event: import("../map/event").Tg.MouseEvent) => any) | undefined;
204
204
  onDblclick?: ((event: import("../map/event").Tg.MouseEvent) => any) | undefined;
205
- onRightclick?: ((event: import("../map/event").Tg.MouseEvent) => any) | undefined;
206
- onContextmenu?: ((event: import("../map/event").Tg.MouseEvent) => any) | undefined;
207
205
  onMousedown?: ((event: import("../map/event").Tg.MouseEvent) => any) | undefined;
208
206
  onMouseup?: ((event: import("../map/event").Tg.MouseEvent) => any) | undefined;
209
207
  onMouseout?: ((event: import("../map/event").Tg.MouseEvent) => any) | undefined;
210
208
  onMouseover?: ((event: import("../map/event").Tg.MouseEvent) => any) | undefined;
209
+ "onCenter-changed"?: ((event: import("../map/event").Tg.Event) => any) | undefined;
210
+ onRightclick?: ((event: import("../map/event").Tg.MouseEvent) => any) | undefined;
211
+ onContextmenu?: ((event: import("../map/event").Tg.MouseEvent) => any) | undefined;
211
212
  onDragstart?: ((event: import("../map/event").Tg.Event) => any) | undefined;
212
213
  onDrag?: ((event: import("../map/event").Tg.Event) => any) | undefined;
213
214
  onDragend?: ((event: import("../map/event").Tg.Event) => any) | undefined;
214
- "onCenter-changed"?: ((event: import("../map/event").Tg.Event) => any) | undefined;
215
215
  onMousemove?: ((event: import("../map/event").Tg.MouseEvent) => any) | undefined;
216
216
  onTilesloaded?: ((event: import("../map/event").Tg.Event) => any) | undefined;
217
217
  "onZoom-changed"?: ((event: import("../map/event").Tg.Event) => any) | undefined;
@@ -243,12 +243,12 @@ declare const TgMarker: import("vue").DefineComponent<{
243
243
  }>> & {
244
244
  onClick?: ((event: import("../../map/event").Tg.MouseEvent) => any) | undefined;
245
245
  onDblclick?: ((event: import("../../map/event").Tg.MouseEvent) => any) | undefined;
246
- onRightclick?: ((event: import("../../map/event").Tg.MouseEvent) => any) | undefined;
247
- onContextmenu?: ((event: import("../../map/event").Tg.MouseEvent) => any) | undefined;
248
246
  onMousedown?: ((event: import("../../map/event").Tg.MouseEvent) => any) | undefined;
249
247
  onMouseup?: ((event: import("../../map/event").Tg.MouseEvent) => any) | undefined;
250
248
  onMouseout?: ((event: import("../../map/event").Tg.MouseEvent) => any) | undefined;
251
249
  onMouseover?: ((event: import("../../map/event").Tg.MouseEvent) => any) | undefined;
250
+ onRightclick?: ((event: import("../../map/event").Tg.MouseEvent) => any) | undefined;
251
+ onContextmenu?: ((event: import("../../map/event").Tg.MouseEvent) => any) | undefined;
252
252
  onDragstart?: ((event: import("../../map/event").Tg.MouseEvent) => any) | undefined;
253
253
  onDrag?: ((event: import("../../map/event").Tg.MouseEvent) => any) | undefined;
254
254
  onDragend?: ((event: import("../../map/event").Tg.MouseEvent) => any) | undefined;
@@ -43,7 +43,7 @@ export declare class BaiduMap extends AbstractMap {
43
43
  setZoom(zoom: number): void;
44
44
  setMinZoom(zoom: number): void;
45
45
  setMaxZoom(zoom: number): void;
46
- setMapStyle(mapStyle: MapStyle): void;
46
+ setMapStyle(mapStyle?: MapStyle): void;
47
47
  setBuildInMapTypeId(id: BuildInMapTypeId): void;
48
48
  setMapType(mapType: MapType): void;
49
49
  getMapType(): MapType;
@@ -41,7 +41,7 @@ export declare class GoogleMap extends AbstractMap {
41
41
  setCenter(latlng: LatLng): void;
42
42
  setMinZoom(zoom: number): void;
43
43
  setMaxZoom(zoom: number): void;
44
- setMapStyle(mapStyle: MapStyle): void;
44
+ setMapStyle(mapStyle?: MapStyle): void;
45
45
  setBuildInMapTypeId(id: BuildInMapTypeId): void;
46
46
  setMapType(mapType: MapType): void;
47
47
  getMapType(): MapType;
@@ -40,7 +40,7 @@ export declare class HereMap extends AbstractMap {
40
40
  setDoubleClickZoom(enable: boolean): void;
41
41
  setMinZoom(zoom: number): void;
42
42
  setMaxZoom(zoom: number): void;
43
- setMapStyle(mapStyle: MapStyle): void;
43
+ setMapStyle(mapStyle?: MapStyle): void;
44
44
  setBuildInMapTypeId(id: BuildInMapTypeId): void;
45
45
  setMapType(mapType: MapType): void;
46
46
  getMapType(): MapType;
@@ -1,3 +1,4 @@
1
+ /// <reference types="baidumap-web-sdk" />
1
2
  /// <reference types="google.maps" />
2
3
  import { LatLng } from '../lat-lng';
3
4
  import type { BuildInMapTypeId } from './map-type';
@@ -43,14 +44,19 @@ export interface MapOptions {
43
44
  export declare namespace MapOptions {
44
45
  function create(options?: Partial<MapOptions>): MapOptions;
45
46
  }
47
+ /**
48
+ * ## 本地样式编辑器
49
+ * - google: https://mapstyle.withgoogle.com/
50
+ * - baidu: https://lbsyun.baidu.com/apiconsole/custommap
51
+ *
52
+ * ## 关于云端样式
53
+ * - google: mapId只有创建时有效, 之后再更改无效
54
+ * - baidu: styleId无效, 原因未知
55
+ */
46
56
  export interface MapStyle {
47
- toBaidu(): BMap.MapStyleV2;
48
- toGoogle(): google.maps.MapTypeStyle[];
49
- }
50
- export declare class SimpleMapStyle implements MapStyle {
51
57
  baidu: BMap.MapStyleV2;
52
- google: google.maps.MapTypeStyle[];
53
- constructor(baidu: BMap.MapStyleV2, google: google.maps.MapTypeStyle[]);
54
- toBaidu(): BMap.MapStyleV2;
55
- toGoogle(): google.maps.MapTypeStyle[];
58
+ google: {
59
+ styles?: google.maps.MapTypeStyle[];
60
+ mapId?: string;
61
+ };
56
62
  }
@@ -116,7 +116,7 @@ export declare abstract class AbstractMap implements CoordTypeSupplier, Tg.Event
116
116
  abstract setCenter(latlng: LatLng): void;
117
117
  abstract setMinZoom(zoom: number): void;
118
118
  abstract setMaxZoom(zoom: number): void;
119
- abstract setMapStyle(mapStyle: MapStyle): void;
119
+ abstract setMapStyle(mapStyle?: MapStyle): void;
120
120
  /** setMapType的便利版, 只能够用来设置内置地图类型 */
121
121
  abstract setBuildInMapTypeId(id: BuildInMapTypeId): void;
122
122
  abstract setMapType(mapType: MapType): void;
@@ -5,7 +5,6 @@ import { CoordType, LatLng } from '../../lat-lng';
5
5
  import type { UnionBaiduIcon, UnionGoogleIcon } from '../../unions';
6
6
  import type { BaiduMap } from '../baidu-map';
7
7
  import type { GoogleMap } from '../google-map';
8
- import type { AbstractMap } from '../map';
9
8
  import type { BaiduInfoBox } from './baidu-info-box';
10
9
  import { UnionIcon } from './icon';
11
10
  import type { BaiduLabelOverlay, GoogleLabelOverlay, LabelOverlay } from './label';
@@ -86,12 +85,13 @@ export interface Marker extends Tg.EventTargetTyped<Marker, MarkerEventMap> {
86
85
  export type MarkerOverlay = Marker & Overlay;
87
86
  export type BMarker = BMap.Marker & {
88
87
  __info_box__?: BaiduInfoBox;
88
+ __create_by_tg__?: boolean;
89
89
  };
90
90
  export declare class BaiduMarker extends BaiduOverlay<BMarker> implements Marker {
91
91
  /** baidu的Marker不支持读/写clickable等属性, 故只能将创建临时的clickable保存在这个state中 */
92
92
  private state;
93
93
  static create(this: BaiduMap, options: MarkerOptions): BaiduMarker;
94
- constructor(innerOverlay: BMap.Marker, coordType: CoordType, map: AbstractMap,
94
+ constructor(innerOverlay: BMap.Marker, coordType: CoordType, map: BaiduMap,
95
95
  /** baidu的Marker不支持读/写clickable等属性, 故只能将创建临时的clickable保存在这个state中 */
96
96
  state: {
97
97
  clickable: boolean;
@@ -2,6 +2,8 @@ import type { Tg } from '../../event';
2
2
  import { type EventTargetDelegate } from '../../event-target';
3
3
  import type { CoordType } from '../../lat-lng';
4
4
  import type { UnionBaiduOverlay, UnionGoogleOverlay } from '../../unions';
5
+ import type { BaiduMap } from '../baidu-map';
6
+ import type { GoogleMap } from '../google-map';
5
7
  import type { AbstractMap } from '../map';
6
8
  export interface OverlayOptions {
7
9
  /** @default true */
@@ -11,10 +13,10 @@ export declare abstract class Overlay<T = unknown> implements Tg.EventTarget {
11
13
  innerOverlay: T;
12
14
  /** 用于保存Overlay内部点的坐标, 它的值有可能和map的不同 */
13
15
  protected coordType: CoordType;
14
- protected map: AbstractMap;
15
16
  constructor(innerOverlay: T,
16
17
  /** 用于保存Overlay内部点的坐标, 它的值有可能和map的不同 */
17
- coordType: CoordType, map: AbstractMap);
18
+ coordType: CoordType);
19
+ protected abstract map: AbstractMap;
18
20
  protected abstract createDelegate(): EventTargetDelegate;
19
21
  private _delegate;
20
22
  private get delegate();
@@ -25,13 +27,15 @@ export declare abstract class Overlay<T = unknown> implements Tg.EventTarget {
25
27
  abstract setVisible(visible: boolean): void;
26
28
  }
27
29
  export declare class GoogleOverlay<T extends UnionGoogleOverlay = UnionGoogleOverlay> extends Overlay<T> {
28
- constructor(innerOverlay: T, coordType: CoordType, map: AbstractMap);
30
+ protected map: GoogleMap;
31
+ constructor(innerOverlay: T, coordType: CoordType, map: GoogleMap);
29
32
  protected createDelegate(): EventTargetDelegate;
30
33
  isVisible(): boolean;
31
34
  setVisible(visible: boolean): void;
32
35
  }
33
36
  export declare class BaiduOverlay<T extends UnionBaiduOverlay = UnionBaiduOverlay> extends Overlay<T> {
34
- constructor(innerOverlay: T, coordType: CoordType, map: AbstractMap);
37
+ protected map: BaiduMap;
38
+ constructor(innerOverlay: T, coordType: CoordType, map: BaiduMap);
35
39
  protected createDelegate(): EventTargetDelegate;
36
40
  /** 仅限内部使用; 设为private时, 生成的d.ts文件中, 方法返回值会变成any, 故改成了public */
37
41
  get overlay(): Required<Pick<UnionBaiduOverlay, "isVisible" | "show" | "hide">>;
@@ -29,6 +29,11 @@ export type PolylineEventMap = {
29
29
  };
30
30
  export interface PolylineOptions extends NotFillableShapeOptions {
31
31
  path: LatLng[];
32
+ /**
33
+ * ## 不同行为
34
+ * - google: 功能正常
35
+ * - baidu: 百度地图在移除Polyline时, icons不会被移除, 导致错乱, 这里通过复写{@link BaiduPolyline.remove}, 规避了该bug
36
+ */
32
37
  icons?: IconSequence[];
33
38
  }
34
39
  export interface Polyline extends Tg.EventTargetTyped<Polyline, PolylineEventMap>, NotFillableShape {
@@ -52,6 +57,7 @@ export declare class BaiduPolyline extends BaiduPolyShape<BMap.Polyline> impleme
52
57
  protected pathEditedEventType: string;
53
58
  getPath(): LatLng[];
54
59
  setPath(path: LatLng[]): void;
60
+ remove(): void;
55
61
  }
56
62
  /**
57
63
  * Google地图的网页版不支持Advanced Polyline(纹理/渐变等效果), 详见: https://issuetracker.google.com/issues/267845944
@@ -1,12 +1,18 @@
1
1
  import type { CoordType } from '../../lat-lng';
2
2
  import type { UnionBaiduShape, UnionGoogleShape } from '../../unions';
3
3
  import type { BaiduMap } from '../baidu-map';
4
+ import type { SymbolIcon } from './icon';
4
5
  import { BaiduOverlay, GoogleOverlay, type OverlayOptions } from './overlay';
5
6
  export interface ShapeOptions extends OverlayOptions {
6
7
  clickable?: boolean;
7
8
  editable?: boolean;
8
9
  strokeColor?: string;
9
10
  strokeOpacity?: number;
11
+ /**
12
+ * ## 取值范围不同
13
+ * - google: 最大值约为32, 更大的值不影响线宽
14
+ * - baidu: 没有上限
15
+ */
10
16
  strokeWeight?: number;
11
17
  fillColor?: string;
12
18
  fillOpacity?: number;
@@ -27,6 +33,7 @@ export type NotFillableShapeOptions = Omit<ShapeOptions, 'fillColor' | 'fillOpac
27
33
  export declare abstract class BaiduShape<T extends UnionBaiduShape> extends BaiduOverlay<T> implements Shape {
28
34
  protected state: {
29
35
  editable: boolean;
36
+ symbolIcons?: SymbolIcon[];
30
37
  };
31
38
  /**
32
39
  * baidu地图的透明度属性有如下问题:
@@ -37,6 +44,7 @@ export declare abstract class BaiduShape<T extends UnionBaiduShape> extends Baid
37
44
  static OPACITY_DELTA: number;
38
45
  constructor(innerOverlay: T, coordType: CoordType, map: BaiduMap, state: {
39
46
  editable: boolean;
47
+ symbolIcons?: SymbolIcon[];
40
48
  });
41
49
  isEditable(): boolean;
42
50
  setEditable(editable: boolean): void;
package/dist/tg-map.js CHANGED
@@ -2871,9 +2871,9 @@ var j = /* @__PURE__ */ ((i) => (i.auto = "auto", i.none = "none", i.greedy = "g
2871
2871
  i.create = t;
2872
2872
  })(lt || (lt = {}));
2873
2873
  class Er {
2874
- constructor(t, e, r) {
2874
+ constructor(t, e) {
2875
2875
  c(this, "_delegate");
2876
- this.innerOverlay = t, this.coordType = e, this.map = r;
2876
+ this.innerOverlay = t, this.coordType = e;
2877
2877
  }
2878
2878
  get delegate() {
2879
2879
  return this._delegate ?? (this._delegate = this.createDelegate().setTarget(this)), this._delegate;
@@ -2890,7 +2890,7 @@ class Er {
2890
2890
  }
2891
2891
  class Mt extends Er {
2892
2892
  constructor(t, e, r) {
2893
- super(t, e, r);
2893
+ super(t, e), this.map = r;
2894
2894
  }
2895
2895
  createDelegate() {
2896
2896
  return new re(this.innerOverlay, this.map);
@@ -2904,7 +2904,7 @@ class Mt extends Er {
2904
2904
  }
2905
2905
  class Ye extends Er {
2906
2906
  constructor(t, e, r) {
2907
- super(t, e, r);
2907
+ super(t, e), this.map = r;
2908
2908
  }
2909
2909
  createDelegate() {
2910
2910
  return new ae(this.innerOverlay, this.map);
@@ -3777,7 +3777,7 @@ class Le extends Ye {
3777
3777
  raiseOnDrag: t.crossOnDrag === void 0 ? !0 : t.crossOnDrag,
3778
3778
  draggingCursor: t.cursor
3779
3779
  }, n = new BMap.Marker(t.position.toBaidu(e, t.normalizePositionForBaidu), s);
3780
- t.zIndex !== void 0 && n.setZIndex(t.zIndex);
3780
+ n.__create_by_tg__ = !0, t.zIndex !== void 0 && n.setZIndex(t.zIndex);
3781
3781
  const a = t.clickable === void 0 ? !0 : t.clickable, h = !!t.draggable;
3782
3782
  return new Le(n, e, this, { clickable: a, draggable: h, zIndex: t.zIndex, normalize: t.normalizePositionForBaidu }).visibleOptionInternal(t.visible);
3783
3783
  }
@@ -3948,8 +3948,8 @@ class At extends St {
3948
3948
  c(this, "pathEditedEventType", "path-edited");
3949
3949
  }
3950
3950
  static create(e) {
3951
- var n;
3952
- const r = this.coordType, s = new BMap.Polyline(e.path.map((a) => a.toBaidu(r)), {
3951
+ var n, a;
3952
+ const r = this.coordType, s = new BMap.Polyline(e.path.map((h) => h.toBaidu(r)), {
3953
3953
  enableClicking: e.clickable,
3954
3954
  enableEditing: e.editable,
3955
3955
  strokeColor: e.strokeColor,
@@ -3957,7 +3957,10 @@ class At extends St {
3957
3957
  strokeWeight: e.strokeWeight,
3958
3958
  icons: (n = e.icons) == null ? void 0 : n.map(Ze.toBaidu)
3959
3959
  });
3960
- return new At(s, r, this, { editable: !!e.editable }).visibleOptionInternal(e.visible);
3960
+ return new At(s, r, this, {
3961
+ editable: !!e.editable,
3962
+ symbolIcons: (a = e.icons) == null ? void 0 : a.map((h) => h.icon)
3963
+ }).visibleOptionInternal(e.visible);
3961
3964
  }
3962
3965
  getPath() {
3963
3966
  return this.innerOverlay.getPath().map((e) => y.fromBaidu(e, this.coordType));
@@ -3965,6 +3968,22 @@ class At extends St {
3965
3968
  setPath(e) {
3966
3969
  this.coordType = this.map.coordType, this.setPathInternal(e.map((r) => r.toBaidu(this.coordType)));
3967
3970
  }
3971
+ remove() {
3972
+ var e;
3973
+ super.remove(), (e = this.state.symbolIcons) != null && e.length && this.map.innerMap.getOverlays().filter((s) => {
3974
+ var o;
3975
+ if (!(s instanceof BMap.Marker))
3976
+ return !1;
3977
+ const n = s;
3978
+ if (n.__create_by_tg__)
3979
+ return !1;
3980
+ const a = n.getIcon();
3981
+ if (!(a instanceof BMap.Symbol))
3982
+ return !1;
3983
+ const h = a;
3984
+ return h.__icon__ ? (o = this.state.symbolIcons) == null ? void 0 : o.includes(h.__icon__) : !1;
3985
+ }).forEach((s) => this.map.innerMap.removeOverlay(s));
3986
+ }
3968
3987
  }
3969
3988
  class Rt extends qe {
3970
3989
  constructor() {
@@ -4203,7 +4222,7 @@ class Gi extends Tt {
4203
4222
  mapType: r.buildInMapTypeId && ((s = this.buildInMapTypeId2BIMT.get(r.buildInMapTypeId)) == null ? void 0 : s.asBaiduMapType()),
4204
4223
  enableMapClick: !1
4205
4224
  // 关闭底图点击功能
4206
- }), this.map.centerAndZoom(r.center.toBaidu(this.coordType), r.zoom + ee), this.setGestureHandling(r.gestureHandling), r.infoWindowMode === "multi" && console.warn("baidu不支持多个InfoWindow, 可能会出现未知问题"), r.mapStyle && this.map.setMapStyleV2(r.mapStyle.toBaidu()), this.setEventTargetDelegate(new ae(this.map, this)), this.map.addEventListener("addoverlay", (n) => {
4225
+ }), this.map.centerAndZoom(r.center.toBaidu(this.coordType), r.zoom + ee), this.setGestureHandling(r.gestureHandling), r.infoWindowMode === "multi" && console.warn("baidu不支持多个InfoWindow, 可能会出现未知问题"), r.mapStyle && this.map.setMapStyleV2(r.mapStyle.baidu), this.setEventTargetDelegate(new ae(this.map, this)), this.map.addEventListener("addoverlay", (n) => {
4207
4226
  const a = n.target.__info_box__;
4208
4227
  a && (console.debug("add:info-box", a), this.map.addOverlay(a));
4209
4228
  }), this.map.addEventListener("removeoverlay", (n) => {
@@ -4278,7 +4297,7 @@ class Gi extends Tt {
4278
4297
  this.map.setMaxZoom(e + ee);
4279
4298
  }
4280
4299
  setMapStyle(e) {
4281
- this.map.setMapStyleV2(e.toBaidu());
4300
+ this.map.setMapStyleV2((e == null ? void 0 : e.baidu) ?? { styleJson: [] });
4282
4301
  }
4283
4302
  setBuildInMapTypeId(e) {
4284
4303
  var s;
@@ -4362,7 +4381,7 @@ class Gi extends Tt {
4362
4381
  }
4363
4382
  class Zi extends Tt {
4364
4383
  constructor(e, r) {
4365
- var n;
4384
+ var n, a;
4366
4385
  super(e);
4367
4386
  c(this, "buildInMapTypeId2BIMT");
4368
4387
  c(this, "googleMapTypeId2BIMT");
@@ -4388,7 +4407,8 @@ class Zi extends Tt {
4388
4407
  gestureHandling: r.gestureHandling,
4389
4408
  minZoom: r.minZoom,
4390
4409
  maxZoom: r.maxZoom,
4391
- styles: (n = r.mapStyle) == null ? void 0 : n.toGoogle(),
4410
+ styles: (n = r.mapStyle) == null ? void 0 : n.google.styles,
4411
+ mapId: (a = r.mapStyle) == null ? void 0 : a.google.mapId,
4392
4412
  mapTypeId: s == null ? void 0 : s.getGoogleMapTypeId()
4393
4413
  }), this.setEventTargetDelegate(new re(this.map, this));
4394
4414
  }
@@ -4445,7 +4465,10 @@ class Zi extends Tt {
4445
4465
  this.map.setOptions({ maxZoom: e });
4446
4466
  }
4447
4467
  setMapStyle(e) {
4448
- this.map.setOptions({ styles: e.toGoogle() });
4468
+ this.map.setOptions({
4469
+ styles: e == null ? void 0 : e.google.styles,
4470
+ mapId: e == null ? void 0 : e.google.mapId
4471
+ });
4449
4472
  }
4450
4473
  setBuildInMapTypeId(e) {
4451
4474
  var s;
@@ -5922,7 +5945,7 @@ const Es = /* @__PURE__ */ K(Cs, [["render", ws]]), Ls = w({
5922
5945
  });
5923
5946
  },
5924
5947
  onDestroy() {
5925
- this.$map.removeOverlay(this.overlay);
5948
+ this.overlay.remove();
5926
5949
  }
5927
5950
  }), Ps = w({
5928
5951
  name: "tg-rectangle",