tg-map-core 0.0.1
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/dist/index.cjs +6394 -0
- package/dist/index.css +77 -0
- package/dist/index.mjs +6277 -0
- package/dist/src/index.d.ts +50 -0
- package/dist/src/map/event-target.d.ts +80 -0
- package/dist/src/map/event.d.ts +50 -0
- package/dist/src/map/lat-lng.d.ts +160 -0
- package/dist/src/map/map/baidu-map.d.ts +82 -0
- package/dist/src/map/map/controls/control.d.ts +112 -0
- package/dist/src/map/map/controls/map-type.control.d.ts +29 -0
- package/dist/src/map/map/controls/scale.control.d.ts +19 -0
- package/dist/src/map/map/controls/street-view.control.d.ts +25 -0
- package/dist/src/map/map/controls/zoom.control.d.ts +19 -0
- package/dist/src/map/map/extra/autocomplete.d.ts +42 -0
- package/dist/src/map/map/extra/heatmap.d.ts +71 -0
- package/dist/src/map/map/extra/map-urls.d.ts +59 -0
- package/dist/src/map/map/extra/marker-clusterer.d.ts +73 -0
- package/dist/src/map/map/extra/places-service.d.ts +47 -0
- package/dist/src/map/map/extra/search-box.d.ts +38 -0
- package/dist/src/map/map/google-map.d.ts +81 -0
- package/dist/src/map/map/here-map.d.ts +78 -0
- package/dist/src/map/map/map-options.d.ts +60 -0
- package/dist/src/map/map/map-type.d.ts +110 -0
- package/dist/src/map/map/map.d.ts +198 -0
- package/dist/src/map/map/overlay/baidu-info-box.d.ts +82 -0
- package/dist/src/map/map/overlay/circle.d.ts +51 -0
- package/dist/src/map/map/overlay/element-overlay.d.ts +37 -0
- package/dist/src/map/map/overlay/google-label.d.ts +68 -0
- package/dist/src/map/map/overlay/icon.d.ts +122 -0
- package/dist/src/map/map/overlay/info-box.d.ts +60 -0
- package/dist/src/map/map/overlay/info-window.d.ts +111 -0
- package/dist/src/map/map/overlay/label.d.ts +102 -0
- package/dist/src/map/map/overlay/marker-label.d.ts +19 -0
- package/dist/src/map/map/overlay/marker.d.ts +144 -0
- package/dist/src/map/map/overlay/overlay.d.ts +46 -0
- package/dist/src/map/map/overlay/polygon.d.ts +42 -0
- package/dist/src/map/map/overlay/polyline.d.ts +71 -0
- package/dist/src/map/map/overlay/rectangle.d.ts +50 -0
- package/dist/src/map/map/overlay/shape.d.ts +76 -0
- package/dist/src/map/map/talks-map.d.ts +81 -0
- package/dist/src/map/map-config.d.ts +29 -0
- package/dist/src/map/map-factory.d.ts +33 -0
- package/dist/src/map/map-loader.d.ts +19 -0
- package/dist/src/map/talks/talks-layers.d.ts +9 -0
- package/dist/src/map/talks/talks-utils.d.ts +7 -0
- package/dist/src/map/types.d.ts +17 -0
- package/dist/src/map/unions.d.ts +20 -0
- package/dist/src/utils/arrays.d.ts +19 -0
- package/dist/src/utils/baidu-utils.d.ts +23 -0
- package/dist/src/utils/elements.d.ts +4 -0
- package/dist/src/utils/formatter.d.ts +1 -0
- package/dist/src/utils/google-utils.d.ts +34 -0
- package/dist/src/utils/here-utils.d.ts +10 -0
- package/dist/src/utils/map-utils.d.ts +7 -0
- package/dist/src/utils/mapped-types.d.ts +110 -0
- package/dist/src/utils/maps-utils/index.d.ts +2 -0
- package/dist/src/utils/maps-utils/math-util.d.ts +59 -0
- package/dist/src/utils/maps-utils/poly-util.d.ts +103 -0
- package/dist/src/utils/maps-utils/spherical-util.d.ts +67 -0
- package/dist/src/utils/objects.d.ts +27 -0
- package/dist/src/utils/spherical-utils.d.ts +27 -0
- package/dist/src/utils/strings.d.ts +21 -0
- package/dist/src/utils/utils.d.ts +14 -0
- package/dist/src/utils/values.d.ts +34 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +60 -0
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import type { Tg } from '../../event';
|
|
2
|
+
import { AbstractEventTargetDelegate } from '../../event-target';
|
|
3
|
+
import { LatLng } from '../../lat-lng';
|
|
4
|
+
import type { Point } from '../../types';
|
|
5
|
+
import type { UnionInfoWindow } from '../../unions';
|
|
6
|
+
import type { BaiduMap } from '../baidu-map';
|
|
7
|
+
import type { GoogleMap } from '../google-map';
|
|
8
|
+
import './google-info.scss';
|
|
9
|
+
import type { BaiduMarker, GoogleMarker, Marker } from './marker';
|
|
10
|
+
/**
|
|
11
|
+
* ## InfoWindow的初始偏移, 不同实现
|
|
12
|
+
* - baidu: 根据Icon的infoWindowAnchor选项, 确定相对Icon左上角的偏移
|
|
13
|
+
* - google: 根据Marker的anchorPoint选项, 确定相对marker的position的偏移
|
|
14
|
+
*
|
|
15
|
+
* 统一成: InfoWindow的底部中点对齐Marker的position, 需要多少偏移使用offset选项来设置
|
|
16
|
+
*/
|
|
17
|
+
export interface InfoWindowOptions {
|
|
18
|
+
content: string | HTMLElement;
|
|
19
|
+
/** @default {LatLng.ZERO} */
|
|
20
|
+
position?: LatLng;
|
|
21
|
+
maxWidth?: number;
|
|
22
|
+
offset?: Point;
|
|
23
|
+
disableAutoPan?: boolean;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* cSpell:words clickclose, statechange
|
|
27
|
+
* ## 打开/关闭InfoWindow的不同行为
|
|
28
|
+
* - google
|
|
29
|
+
* 0. 添加时, 默认不显示
|
|
30
|
+
* 1. close(), 不发送事件
|
|
31
|
+
* 2. 点击x, 发送`closeclick`事件
|
|
32
|
+
* 3. open(), 不发送事件
|
|
33
|
+
* 4. 可以同时打开多个InfoWindow
|
|
34
|
+
* - baidu:
|
|
35
|
+
* 0. 添加时, 默认不显示
|
|
36
|
+
* 1. close(), 发送`close`事件
|
|
37
|
+
* 2. 点击x, 先后发送`clickclose`, `close`事件
|
|
38
|
+
* 3. 点击地图的空白区域, 发送`close`事件
|
|
39
|
+
* 4. open(), 发送`open`事件
|
|
40
|
+
* 5. 同时只能打开一个, 之前的会自动关闭(发送`close`事件)
|
|
41
|
+
* - here(InfoBubble)
|
|
42
|
+
* 0. 添加时, 默认显示, 不发送事件
|
|
43
|
+
* 1. close(), 发送`statechange`事件
|
|
44
|
+
* 2. 点击x, 发送`statechange`事件
|
|
45
|
+
* 3. open(), 发送`statechange`事件
|
|
46
|
+
* 4. 可以同时打开多个InfoBubble
|
|
47
|
+
*
|
|
48
|
+
* 结论: 在baidu以外的地图上模拟open/close事件, 保证行为一致
|
|
49
|
+
*/
|
|
50
|
+
export type InfoWindowEventMap = {
|
|
51
|
+
closeclick: Tg.Event;
|
|
52
|
+
/**
|
|
53
|
+
* ## 不同实现
|
|
54
|
+
* baidu: 原生支持open/close事件
|
|
55
|
+
* google: 通过拦截open()/close()/closeclick, 实现open/close事件
|
|
56
|
+
*/
|
|
57
|
+
open: Tg.Event;
|
|
58
|
+
/** @see open */
|
|
59
|
+
close: Tg.Event;
|
|
60
|
+
};
|
|
61
|
+
/** 之所以需要这个type, 是为了将event的类型信息合并进去, 通过实现interface的方式似乎做不到这一点, 使用函数重载其实也可以做到 */
|
|
62
|
+
export type InfoWindowOverlay = InfoWindow & Tg.EventTargetTyped<InfoWindow, InfoWindowEventMap>;
|
|
63
|
+
/** 在@tg/map中 InfoWindow 不继承 Overlay... */
|
|
64
|
+
export declare abstract class InfoWindow implements Tg.EventTarget {
|
|
65
|
+
private delegate;
|
|
66
|
+
constructor(delegate: AbstractEventTargetDelegate<UnionInfoWindow>);
|
|
67
|
+
addEventListener(type: string, listener: Tg.EventListener): void;
|
|
68
|
+
removeEventListener(type: string, listener: Tg.EventListener): void;
|
|
69
|
+
abstract inner: UnionInfoWindow;
|
|
70
|
+
/**
|
|
71
|
+
* 若anchor为空, 则添加到地图上
|
|
72
|
+
*
|
|
73
|
+
* ## 不同行为
|
|
74
|
+
* - baidu: 一定要anchor添加到地图上之后, 才能正常打开infoWindow
|
|
75
|
+
* - google: 没有上述限制
|
|
76
|
+
**/
|
|
77
|
+
abstract open(anchor?: Marker): void;
|
|
78
|
+
abstract close(): void;
|
|
79
|
+
abstract getPosition(): LatLng;
|
|
80
|
+
abstract setPosition(position: LatLng): void;
|
|
81
|
+
abstract isOpen(): boolean;
|
|
82
|
+
}
|
|
83
|
+
export declare class BaiduInfoWindow extends InfoWindow {
|
|
84
|
+
inner: BMap.InfoWindow;
|
|
85
|
+
private map;
|
|
86
|
+
private state;
|
|
87
|
+
static create(this: BaiduMap, options: InfoWindowOptions): BaiduInfoWindow;
|
|
88
|
+
constructor(inner: BMap.InfoWindow, map: BaiduMap, state: {
|
|
89
|
+
position?: LatLng;
|
|
90
|
+
});
|
|
91
|
+
isOpen(): boolean;
|
|
92
|
+
open(anchor?: BaiduMarker): void;
|
|
93
|
+
close(): void;
|
|
94
|
+
getPosition(): LatLng;
|
|
95
|
+
setPosition(position: LatLng): void;
|
|
96
|
+
}
|
|
97
|
+
export declare class GoogleInfoWindow extends InfoWindow {
|
|
98
|
+
inner: google.maps.InfoWindow;
|
|
99
|
+
private map;
|
|
100
|
+
static create(this: GoogleMap, options: InfoWindowOptions): GoogleInfoWindow;
|
|
101
|
+
private eventHub;
|
|
102
|
+
private isOpened;
|
|
103
|
+
constructor(inner: google.maps.InfoWindow, map: GoogleMap);
|
|
104
|
+
isOpen(): boolean;
|
|
105
|
+
addEventListener<K extends keyof InfoWindowEventMap>(type: K, listener: (event: InfoWindowEventMap[K]) => void): void;
|
|
106
|
+
removeEventListener<K extends keyof InfoWindowEventMap>(type: K, listener: (event: InfoWindowEventMap[K]) => void): void;
|
|
107
|
+
open(anchor?: GoogleMarker): void;
|
|
108
|
+
close(): void;
|
|
109
|
+
getPosition(): LatLng;
|
|
110
|
+
setPosition(position: LatLng): void;
|
|
111
|
+
}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import type { Tg } from '../../event';
|
|
2
|
+
import { CoordType, LatLng } from '../../lat-lng';
|
|
3
|
+
import { Point } from '../../types';
|
|
4
|
+
import type { BaiduMap } from '../baidu-map';
|
|
5
|
+
import type { GoogleMap } from '../google-map';
|
|
6
|
+
import { MapPane } from './element-overlay';
|
|
7
|
+
import { type GoogleLabel } from './google-label';
|
|
8
|
+
import type { BaiduUnionIcon } from './icon';
|
|
9
|
+
import { BaiduOverlay, GoogleOverlay, Overlay } from './overlay';
|
|
10
|
+
export type BaiduLabel = BMap.Label & {
|
|
11
|
+
__label__?: BaiduLabelOverlay;
|
|
12
|
+
};
|
|
13
|
+
export type LabelEventMap = {
|
|
14
|
+
click: Tg.Event;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* 初始位置, 左上角对齐position
|
|
18
|
+
*/
|
|
19
|
+
export interface LabelOptions {
|
|
20
|
+
content: LabelContent;
|
|
21
|
+
position?: LatLng;
|
|
22
|
+
offset?: Point;
|
|
23
|
+
/**
|
|
24
|
+
* ## 不同行为
|
|
25
|
+
* 当将label添加到marker中时:
|
|
26
|
+
* - baidu: zIndex设置无效, Label的元素的z-index始终为80
|
|
27
|
+
* - google: 依然有效, 但貌似是由于marker元素的opacity:0;的原因, 调整成比marker小的zIndex后, 依然不能位于marker后方...
|
|
28
|
+
* */
|
|
29
|
+
zIndex?: number;
|
|
30
|
+
/**
|
|
31
|
+
* ## 不同行为
|
|
32
|
+
* - baidu: 不支持该属性
|
|
33
|
+
* - google: 支持, 默认为{@link MapPane.overlayMouseTarget}
|
|
34
|
+
*/
|
|
35
|
+
mapPane?: MapPane;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* ## 不同实现
|
|
39
|
+
* - baidu: 有Label类,
|
|
40
|
+
* - 添加到地图上时, 默认左上角对齐position
|
|
41
|
+
* - 添加到marker中时, 默认左上角对齐marker的icon的左上角
|
|
42
|
+
* - 内容只能是string, string可以是html字符串
|
|
43
|
+
* - google: 没有Label类, 我们用OverlayView实现了一个GoogleLabel
|
|
44
|
+
* - 添加到地图上时, 默认左上角对齐position
|
|
45
|
+
* - 没有添加到marker中的功能
|
|
46
|
+
* - 内容是HTMLElement
|
|
47
|
+
*
|
|
48
|
+
* 针对这些不同, 使用了如下方法使它们行为尽量一致:
|
|
49
|
+
* 1. {@link BaiduLabelOverlay.attachIcon}, 让BaiduLabelOverlay关联icon, 使其添加到地图上时也是左上角对齐position
|
|
50
|
+
* 2. {@link GoogleMarker.setLabel}, 让GoogleMarker关联GoogleLabel, 联动它们的显隐/位置, 使其支持添加到marker中
|
|
51
|
+
* 3. {@link BaiduLabelOverlay.setContentInternal}, 将HTMLElement转成string, 并让BaiduLabelOverlay监听HTMLElement的改变, 由于转换成了string, 故里面的事件监听是无效的, 只能使用{@link LabelEventMap}中的事件
|
|
52
|
+
*
|
|
53
|
+
* ## 后续
|
|
54
|
+
* 经过重新调研, baidu和google是有基本上一致行为的`label`API的, 我们将它抽象成了{@link MarkerLabel}, 对于显示少量文字的情况, 用它就够了
|
|
55
|
+
* 对于显示复杂布局的情况, 当前baidu的实现是通过html转string再转html, 效率可能有问题
|
|
56
|
+
* TODO: 考虑重构成类似google那种基于自定义Overlay的实现方式🤔️
|
|
57
|
+
*/
|
|
58
|
+
export interface Label {
|
|
59
|
+
setContent(content: LabelContent): void;
|
|
60
|
+
getPosition(): LatLng;
|
|
61
|
+
setPosition(position: LatLng): void;
|
|
62
|
+
getOffset(): Point;
|
|
63
|
+
setOffset(offset: Point): void;
|
|
64
|
+
setZIndex(zIndex: number): void;
|
|
65
|
+
}
|
|
66
|
+
export type LabelOverlay = Label & Overlay;
|
|
67
|
+
type LabelContent = string | HTMLElement;
|
|
68
|
+
declare namespace LabelContent {
|
|
69
|
+
function toString(content: LabelContent): string;
|
|
70
|
+
function toElement(content: LabelContent): HTMLElement;
|
|
71
|
+
}
|
|
72
|
+
/** 内容只能是固定不变的 */
|
|
73
|
+
export declare class BaiduLabelOverlay extends BaiduOverlay<BaiduLabel> implements Label {
|
|
74
|
+
static create(this: BaiduMap, options: LabelOptions): BaiduLabelOverlay;
|
|
75
|
+
private icon;
|
|
76
|
+
private iconAnchor;
|
|
77
|
+
private content;
|
|
78
|
+
private contentObserver;
|
|
79
|
+
constructor(innerOverlay: BaiduLabel, coordType: CoordType, map: BaiduMap, content: LabelContent);
|
|
80
|
+
private setContentInternal;
|
|
81
|
+
setZIndex(zIndex: number): void;
|
|
82
|
+
getPosition(): LatLng;
|
|
83
|
+
setPosition(position: LatLng): void;
|
|
84
|
+
getOffset(): Point;
|
|
85
|
+
setOffset(offset: Point): void;
|
|
86
|
+
setContent(content: LabelContent): void;
|
|
87
|
+
/**
|
|
88
|
+
* 关联新的Icon, 内部使用的方法
|
|
89
|
+
* @description baidu中Label默认左上角对齐Icon的左上, 我们要将其转换为对齐marker的position
|
|
90
|
+
* */
|
|
91
|
+
attachIcon(icon: BaiduUnionIcon | undefined): void;
|
|
92
|
+
}
|
|
93
|
+
export declare class GoogleLabelOverlay extends GoogleOverlay<GoogleLabel> implements Label {
|
|
94
|
+
static create(this: GoogleMap, options: LabelOptions): GoogleLabelOverlay;
|
|
95
|
+
setZIndex(zIndex: number): void;
|
|
96
|
+
setContent(content: LabelContent): void;
|
|
97
|
+
getPosition(): LatLng;
|
|
98
|
+
setPosition(position: LatLng): void;
|
|
99
|
+
getOffset(): Point;
|
|
100
|
+
setOffset(offset: Point): void;
|
|
101
|
+
}
|
|
102
|
+
export {};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import './marker-label.scss';
|
|
2
|
+
/**
|
|
3
|
+
* 和Marker关联的标签
|
|
4
|
+
*
|
|
5
|
+
* 与{@link Label}不同, 该类在google和baidu上都是使用Marker原生的label功能实现的, 更简单
|
|
6
|
+
* 当前baidu的{@link BaiduLabelOverlay}底层也是基于Marker的label, 故和该功能有冲突, 不能同时使用
|
|
7
|
+
*/
|
|
8
|
+
export interface MarkerLabel {
|
|
9
|
+
text: string;
|
|
10
|
+
className?: string;
|
|
11
|
+
color?: string;
|
|
12
|
+
fontSize?: string;
|
|
13
|
+
fontWeight?: string;
|
|
14
|
+
fontFamily?: string;
|
|
15
|
+
}
|
|
16
|
+
export declare const MarkerLabel: {
|
|
17
|
+
toBaidu: (label: MarkerLabel) => BMap.Label;
|
|
18
|
+
toGoogle: (label: MarkerLabel) => google.maps.MarkerLabel;
|
|
19
|
+
};
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import type { Nullable } from '../../../utils/mapped-types';
|
|
2
|
+
import type { Tg } from '../../event';
|
|
3
|
+
import { CoordType, LatLng } from '../../lat-lng';
|
|
4
|
+
import type { UnionBaiduIcon, UnionGoogleIcon } from '../../unions';
|
|
5
|
+
import type { BaiduMap } from '../baidu-map';
|
|
6
|
+
import type { GoogleMap } from '../google-map';
|
|
7
|
+
import type { BaiduInfoBox } from './baidu-info-box';
|
|
8
|
+
import { UnionIcon } from './icon';
|
|
9
|
+
import type { BaiduLabelOverlay, GoogleLabelOverlay, LabelOverlay } from './label';
|
|
10
|
+
import { MarkerLabel } from './marker-label';
|
|
11
|
+
import { BaiduOverlay, GoogleOverlay, Overlay, type OverlayOptions } from './overlay';
|
|
12
|
+
export interface MarkerOptions extends OverlayOptions {
|
|
13
|
+
position: LatLng;
|
|
14
|
+
/**
|
|
15
|
+
* 执行{@link LatLng.toBaidu}时是否对经纬度进行标准化
|
|
16
|
+
*
|
|
17
|
+
* 因为{@link LatLng.toGoogle}内部是会自动标准化的, 并且LatLng绝大部分情况下是合法的,
|
|
18
|
+
* 所以添加这个参数, 只在使用者认为必要的时候, 执行标准化
|
|
19
|
+
*
|
|
20
|
+
* {@macro latlng_normalize}
|
|
21
|
+
*/
|
|
22
|
+
normalizePositionForBaidu?: boolean;
|
|
23
|
+
title?: string;
|
|
24
|
+
/** @see MarkerLabel */
|
|
25
|
+
label?: MarkerLabel;
|
|
26
|
+
icon?: UnionIcon;
|
|
27
|
+
/** @default true */
|
|
28
|
+
clickable?: boolean;
|
|
29
|
+
/** @default false */
|
|
30
|
+
draggable?: boolean;
|
|
31
|
+
/**
|
|
32
|
+
* 拖拽时是否显示`x`
|
|
33
|
+
* @default true
|
|
34
|
+
* */
|
|
35
|
+
crossOnDrag?: boolean;
|
|
36
|
+
/**
|
|
37
|
+
* ## 不同行为
|
|
38
|
+
* - google: 有`cursor` 属性, 作用是hover时改变cursor
|
|
39
|
+
* - baidu: 有`draggingCursor`属性, 作用是拖动时改变cursor
|
|
40
|
+
* - maptalks: 同google
|
|
41
|
+
* @deprecated 不推荐使用
|
|
42
|
+
*/
|
|
43
|
+
cursor?: string;
|
|
44
|
+
zIndex?: number;
|
|
45
|
+
}
|
|
46
|
+
/** 仅仅起到类型声明的作用... */
|
|
47
|
+
export type MarkerEventMap = {
|
|
48
|
+
click: Tg.MouseEvent;
|
|
49
|
+
dblclick: Tg.MouseEvent;
|
|
50
|
+
/** @deprecated 使用`contextmenu`替代 */
|
|
51
|
+
rightclick: Tg.MouseEvent;
|
|
52
|
+
contextmenu: Tg.MouseEvent;
|
|
53
|
+
mousedown: Tg.MouseEvent;
|
|
54
|
+
mouseup: Tg.MouseEvent;
|
|
55
|
+
mouseout: Tg.MouseEvent;
|
|
56
|
+
mouseover: Tg.MouseEvent;
|
|
57
|
+
dragstart: Tg.MouseEvent;
|
|
58
|
+
drag: Tg.MouseEvent;
|
|
59
|
+
dragend: Tg.MouseEvent;
|
|
60
|
+
};
|
|
61
|
+
export interface Marker extends Tg.EventTargetTyped<Marker, MarkerEventMap> {
|
|
62
|
+
getPosition(): LatLng;
|
|
63
|
+
setPosition(position: LatLng): void;
|
|
64
|
+
setTitle(title: string): void;
|
|
65
|
+
getTitle(): string;
|
|
66
|
+
/** @see MarkerLabel */
|
|
67
|
+
setLabel(label: MarkerLabel): void;
|
|
68
|
+
setIcon(icon: UnionIcon): void;
|
|
69
|
+
/** 感觉并没有读取Icon的必要, 直接返回内部的Icon, 懒得写包装类_(:3」∠)_ */
|
|
70
|
+
getIcon(): Nullable<UnionGoogleIcon | UnionBaiduIcon>;
|
|
71
|
+
/**
|
|
72
|
+
* ## 不同行为
|
|
73
|
+
* - baidu: 不支持设置clickable
|
|
74
|
+
* - google: 支持
|
|
75
|
+
* @deprecated 不推荐使用
|
|
76
|
+
*/
|
|
77
|
+
setClickable(enable: boolean): void;
|
|
78
|
+
isClickable(): boolean;
|
|
79
|
+
setDraggable(enable: boolean): void;
|
|
80
|
+
isDraggable(): boolean;
|
|
81
|
+
/**
|
|
82
|
+
* ## 不同行为
|
|
83
|
+
* - baidu: 调用该方法无效
|
|
84
|
+
* - google: 有效
|
|
85
|
+
*/
|
|
86
|
+
setZIndex(zIndex?: number): void;
|
|
87
|
+
getZIndex(): number | undefined;
|
|
88
|
+
attachLabelOverlay(label: LabelOverlay | undefined): void;
|
|
89
|
+
}
|
|
90
|
+
export type MarkerOverlay = Marker & Overlay;
|
|
91
|
+
export type BMarker = BMap.Marker & {
|
|
92
|
+
__info_box__?: BaiduInfoBox;
|
|
93
|
+
__create_by_tg__?: boolean;
|
|
94
|
+
};
|
|
95
|
+
export declare class BaiduMarker extends BaiduOverlay<BMarker> implements Marker {
|
|
96
|
+
/** baidu的Marker不支持读/写clickable等属性, 故只能将创建临时的clickable保存在这个state中 */
|
|
97
|
+
private state;
|
|
98
|
+
static create(this: BaiduMap, options: MarkerOptions): BaiduMarker;
|
|
99
|
+
constructor(innerOverlay: BMap.Marker, coordType: CoordType, map: BaiduMap,
|
|
100
|
+
/** baidu的Marker不支持读/写clickable等属性, 故只能将创建临时的clickable保存在这个state中 */
|
|
101
|
+
state: {
|
|
102
|
+
clickable: boolean;
|
|
103
|
+
draggable: boolean;
|
|
104
|
+
zIndex: number | undefined;
|
|
105
|
+
normalize?: boolean;
|
|
106
|
+
});
|
|
107
|
+
getPosition(): LatLng;
|
|
108
|
+
setPosition(position: LatLng): void;
|
|
109
|
+
setTitle(title: string): void;
|
|
110
|
+
getTitle(): string;
|
|
111
|
+
setIcon(icon: UnionIcon): void;
|
|
112
|
+
getIcon(): UnionBaiduIcon;
|
|
113
|
+
setClickable(enable: boolean): void;
|
|
114
|
+
isClickable(): boolean;
|
|
115
|
+
setDraggable(enable: boolean): void;
|
|
116
|
+
isDraggable(): boolean;
|
|
117
|
+
setZIndex(zIndex?: number): void;
|
|
118
|
+
getZIndex(): number | undefined;
|
|
119
|
+
setLabel(label: MarkerLabel): void;
|
|
120
|
+
_updateMarkerLabelOffset(): void;
|
|
121
|
+
attachLabelOverlay(label: BaiduLabelOverlay | undefined): void;
|
|
122
|
+
getLabelOverlay(): BaiduLabelOverlay | undefined;
|
|
123
|
+
}
|
|
124
|
+
export declare class GoogleMarker extends GoogleOverlay<google.maps.Marker> implements Marker {
|
|
125
|
+
static create(this: GoogleMap, options: MarkerOptions): GoogleMarker;
|
|
126
|
+
private label;
|
|
127
|
+
private labelPositionListener;
|
|
128
|
+
private labelVisibleListener;
|
|
129
|
+
private labelMapChangedListener;
|
|
130
|
+
getPosition(): LatLng;
|
|
131
|
+
setPosition(position: LatLng): void;
|
|
132
|
+
setTitle(title: string): void;
|
|
133
|
+
getTitle(): string;
|
|
134
|
+
setIcon(icon: UnionIcon): void;
|
|
135
|
+
getIcon(): Nullable<UnionGoogleIcon>;
|
|
136
|
+
setClickable(flag: boolean): void;
|
|
137
|
+
isClickable(): boolean;
|
|
138
|
+
setDraggable(enable: boolean): void;
|
|
139
|
+
isDraggable(): boolean;
|
|
140
|
+
setZIndex(zIndex?: number): void;
|
|
141
|
+
getZIndex(): number | undefined;
|
|
142
|
+
setLabel(label: MarkerLabel): void;
|
|
143
|
+
attachLabelOverlay(label: GoogleLabelOverlay | undefined): void;
|
|
144
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { Tg } from '../../event';
|
|
2
|
+
import { type EventTargetDelegate } from '../../event-target';
|
|
3
|
+
import type { CoordType } from '../../lat-lng';
|
|
4
|
+
import type { UnionBaiduOverlay, UnionGoogleOverlay } from '../../unions';
|
|
5
|
+
import type { BaiduMap } from '../baidu-map';
|
|
6
|
+
import type { GoogleMap } from '../google-map';
|
|
7
|
+
import type { BaseMap } from '../map';
|
|
8
|
+
export interface OverlayOptions {
|
|
9
|
+
/** @default true */
|
|
10
|
+
visible?: boolean;
|
|
11
|
+
}
|
|
12
|
+
export declare abstract class Overlay<T = unknown> implements Tg.EventTarget {
|
|
13
|
+
innerOverlay: T;
|
|
14
|
+
/** 用于保存Overlay内部点的坐标, 它的值有可能和map的不同 */
|
|
15
|
+
protected coordType: CoordType;
|
|
16
|
+
constructor(innerOverlay: T,
|
|
17
|
+
/** 用于保存Overlay内部点的坐标, 它的值有可能和map的不同 */
|
|
18
|
+
coordType: CoordType);
|
|
19
|
+
protected abstract map: BaseMap;
|
|
20
|
+
protected abstract createDelegate(): EventTargetDelegate;
|
|
21
|
+
private _delegate;
|
|
22
|
+
private get delegate();
|
|
23
|
+
addEventListener(type: string, listener: Tg.EventListener): void;
|
|
24
|
+
removeEventListener(type: string, listener: Tg.EventListener): void;
|
|
25
|
+
remove(): void;
|
|
26
|
+
abstract isVisible(): boolean;
|
|
27
|
+
abstract setVisible(visible: boolean): void;
|
|
28
|
+
}
|
|
29
|
+
export declare class GoogleOverlay<T extends UnionGoogleOverlay = UnionGoogleOverlay> extends Overlay<T> {
|
|
30
|
+
protected map: GoogleMap;
|
|
31
|
+
constructor(innerOverlay: T, coordType: CoordType, map: GoogleMap);
|
|
32
|
+
protected createDelegate(): EventTargetDelegate;
|
|
33
|
+
isVisible(): boolean;
|
|
34
|
+
setVisible(visible: boolean): void;
|
|
35
|
+
}
|
|
36
|
+
export declare class BaiduOverlay<T extends UnionBaiduOverlay = UnionBaiduOverlay> extends Overlay<T> {
|
|
37
|
+
protected map: BaiduMap;
|
|
38
|
+
constructor(innerOverlay: T, coordType: CoordType, map: BaiduMap);
|
|
39
|
+
protected createDelegate(): EventTargetDelegate;
|
|
40
|
+
/** 仅限内部使用; 设为private时, 生成的d.ts文件中, 方法返回值会变成any, 故改成了public */
|
|
41
|
+
get overlay(): Required<Pick<UnionBaiduOverlay, "isVisible" | "show" | "hide">>;
|
|
42
|
+
isVisible(): boolean;
|
|
43
|
+
setVisible(visible: boolean): void;
|
|
44
|
+
/** 在创建BaiduOverlay时, 设置options.visible, 仅内部使用 */
|
|
45
|
+
visibleOptionInternal(visible: boolean | undefined): this;
|
|
46
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { Tg } from '../../event';
|
|
2
|
+
import { EventHubEventTargetDelegate } from '../../event-target';
|
|
3
|
+
import { LatLng } from '../../lat-lng';
|
|
4
|
+
import type { BaiduMap } from '../baidu-map';
|
|
5
|
+
import type { GoogleMap } from '../google-map';
|
|
6
|
+
import type { Overlay } from './overlay';
|
|
7
|
+
import { BaiduPolyShape } from './polyline';
|
|
8
|
+
import { GoogleShape, type Shape, type ShapeOptions } from './shape';
|
|
9
|
+
export type PolygonEventMap = {
|
|
10
|
+
click: Tg.Event;
|
|
11
|
+
dblclick: Tg.Event;
|
|
12
|
+
mousedown: Tg.MouseEvent;
|
|
13
|
+
mouseup: Tg.MouseEvent;
|
|
14
|
+
mouseout: Tg.MouseEvent;
|
|
15
|
+
mouseover: Tg.MouseEvent;
|
|
16
|
+
/** @see PolylineEventMap `.path-edited` */
|
|
17
|
+
'paths-edited': Tg.Event;
|
|
18
|
+
};
|
|
19
|
+
export interface PolygonOptions extends ShapeOptions {
|
|
20
|
+
paths: LatLng[][];
|
|
21
|
+
}
|
|
22
|
+
export interface Polygon extends Tg.EventTargetTyped<Polygon, PolygonEventMap>, Shape {
|
|
23
|
+
getPaths(): LatLng[][];
|
|
24
|
+
setPaths(paths: LatLng[][]): void;
|
|
25
|
+
}
|
|
26
|
+
export type PolygonOverlay = Polygon & Overlay;
|
|
27
|
+
export declare class BaiduPolygon extends BaiduPolyShape<BMap.Polygon> implements Polygon {
|
|
28
|
+
static create(this: BaiduMap, options: PolygonOptions): BaiduPolygon;
|
|
29
|
+
protected pathEditedEventType: string;
|
|
30
|
+
getPaths(): LatLng[][];
|
|
31
|
+
setPaths(paths: LatLng[][]): void;
|
|
32
|
+
}
|
|
33
|
+
export declare class GooglePolygon extends GoogleShape<google.maps.Polygon> implements Polygon {
|
|
34
|
+
static create(this: GoogleMap, options: PolygonOptions): GooglePolygon;
|
|
35
|
+
private pathChangedListeners;
|
|
36
|
+
private setupPathChangedListeners;
|
|
37
|
+
private clearPathChangedListeners;
|
|
38
|
+
private eventHubDelegate;
|
|
39
|
+
protected createDelegate(): EventHubEventTargetDelegate<"paths-edited">;
|
|
40
|
+
getPaths(): LatLng[][];
|
|
41
|
+
setPaths(paths: LatLng[][]): void;
|
|
42
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import type { Tg } from '../../event';
|
|
2
|
+
import { EventHubEventTargetDelegate } from '../../event-target';
|
|
3
|
+
import { LatLng } from '../../lat-lng';
|
|
4
|
+
import type { BaiduMap } from '../baidu-map';
|
|
5
|
+
import type { GoogleMap } from '../google-map';
|
|
6
|
+
import { IconSequence } from './icon';
|
|
7
|
+
import type { Overlay } from './overlay';
|
|
8
|
+
import { BaiduShape, GoogleShape, type NotFillableShape, type NotFillableShapeOptions } from './shape';
|
|
9
|
+
export type PolylineEventMap = {
|
|
10
|
+
click: Tg.Event;
|
|
11
|
+
dblclick: Tg.Event;
|
|
12
|
+
mousedown: Tg.MouseEvent;
|
|
13
|
+
mouseup: Tg.MouseEvent;
|
|
14
|
+
mouseout: Tg.MouseEvent;
|
|
15
|
+
mouseover: Tg.MouseEvent;
|
|
16
|
+
/**
|
|
17
|
+
* 在`editable`模式下编辑了path的事件
|
|
18
|
+
* 外部调用{@link Polyline#setPath}, 不触发该事件 (之所以这样设计, 是为了避免频繁的进行LatLng<=>地图点对象的相互转换)
|
|
19
|
+
*
|
|
20
|
+
* ## 原理
|
|
21
|
+
* 该事件的实现比较杂, 原始地图并没有等效的事件, 都是通过转换实现的
|
|
22
|
+
* - google: 通过监听path的`insert/remove/set_at`实现
|
|
23
|
+
* - baidu: 通过监听`lineupdate`事件, 然后判断path有没有被修改, 来实现的
|
|
24
|
+
*/
|
|
25
|
+
'path-edited': Tg.Event;
|
|
26
|
+
};
|
|
27
|
+
export interface PolylineOptions extends NotFillableShapeOptions {
|
|
28
|
+
path: LatLng[];
|
|
29
|
+
/**
|
|
30
|
+
* ## 不同行为
|
|
31
|
+
* - google: 功能正常
|
|
32
|
+
* - baidu: 百度地图在移除Polyline时, icons不会被移除, 导致错乱, 这里通过复写{@link BaiduPolyline.remove}, 规避了该bug
|
|
33
|
+
*/
|
|
34
|
+
icons?: IconSequence[];
|
|
35
|
+
}
|
|
36
|
+
export interface Polyline extends Tg.EventTargetTyped<Polyline, PolylineEventMap>, NotFillableShape {
|
|
37
|
+
getPath(): LatLng[];
|
|
38
|
+
setPath(path: LatLng[]): void;
|
|
39
|
+
}
|
|
40
|
+
export type PolylineOverlay = Polyline & Overlay;
|
|
41
|
+
export declare abstract class BaiduPolyShape<T extends BMap.Polyline | BMap.Polygon> extends BaiduShape<T> {
|
|
42
|
+
/** 路径被编辑的事件名 */
|
|
43
|
+
protected abstract pathEditedEventType: string;
|
|
44
|
+
/** 修改路径, 仅内部使用 */
|
|
45
|
+
protected setPathInternal(path: BMap.Point[]): void;
|
|
46
|
+
private eventHubDelegate;
|
|
47
|
+
protected createDelegate(): EventHubEventTargetDelegate<string>;
|
|
48
|
+
private prevPath;
|
|
49
|
+
private isDoingSetPath;
|
|
50
|
+
private onLineUpdate;
|
|
51
|
+
}
|
|
52
|
+
export declare class BaiduPolyline extends BaiduPolyShape<BMap.Polyline> implements Polyline {
|
|
53
|
+
static create(this: BaiduMap, options: PolylineOptions): BaiduPolyline;
|
|
54
|
+
protected pathEditedEventType: string;
|
|
55
|
+
getPath(): LatLng[];
|
|
56
|
+
setPath(path: LatLng[]): void;
|
|
57
|
+
remove(): void;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Google地图的网页版不支持Advanced Polyline(纹理/渐变等效果), 详见: https://issuetracker.google.com/issues/267845944
|
|
61
|
+
*/
|
|
62
|
+
export declare class GooglePolyline extends GoogleShape<google.maps.Polyline> implements Polyline {
|
|
63
|
+
static create(this: GoogleMap, options: PolylineOptions): GooglePolyline;
|
|
64
|
+
private pathChangedListeners;
|
|
65
|
+
private setupPathChangedListeners;
|
|
66
|
+
private clearPathChangedListeners;
|
|
67
|
+
private eventHubDelegate;
|
|
68
|
+
protected createDelegate(): EventHubEventTargetDelegate<"path-edited">;
|
|
69
|
+
getPath(): LatLng[];
|
|
70
|
+
setPath(path: LatLng[]): void;
|
|
71
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { Tg } from '../../event';
|
|
2
|
+
import { CoordType, LatLngBounds } from '../../lat-lng';
|
|
3
|
+
import type { BaiduMap } from '../baidu-map';
|
|
4
|
+
import type { GoogleMap } from '../google-map';
|
|
5
|
+
import type { Overlay } from './overlay';
|
|
6
|
+
import { BaiduPolyShape } from './polyline';
|
|
7
|
+
import { GoogleShape, type Shape, type ShapeOptions } from './shape';
|
|
8
|
+
export type RectangleEventMap = {
|
|
9
|
+
click: Tg.Event;
|
|
10
|
+
dblclick: Tg.Event;
|
|
11
|
+
mousedown: Tg.MouseEvent;
|
|
12
|
+
mouseup: Tg.MouseEvent;
|
|
13
|
+
mouseout: Tg.MouseEvent;
|
|
14
|
+
mouseover: Tg.MouseEvent;
|
|
15
|
+
/**
|
|
16
|
+
* - google: 监听[bounds_changed](https://developers.google.com/maps/documentation/javascript/shapes#editable_events)
|
|
17
|
+
* - baidu: 内部使用Polygon并监听`lineupdate`实现
|
|
18
|
+
*/
|
|
19
|
+
'bounds-changed': Tg.Event;
|
|
20
|
+
};
|
|
21
|
+
export interface RectangleOptions extends ShapeOptions {
|
|
22
|
+
bounds: LatLngBounds;
|
|
23
|
+
}
|
|
24
|
+
export interface Rectangle extends Tg.EventTargetTyped<Rectangle, RectangleEventMap>, Shape {
|
|
25
|
+
getBounds(): LatLngBounds;
|
|
26
|
+
setBounds(bounds: LatLngBounds): void;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* 矩形覆盖物
|
|
30
|
+
*
|
|
31
|
+
* - google: 有矩形
|
|
32
|
+
* - baidu: 没有矩形, 使用{@link BMap.Polygon}变相实现
|
|
33
|
+
*/
|
|
34
|
+
export type RectangleOverlay = Rectangle & Overlay;
|
|
35
|
+
export declare class BaiduRectangle extends BaiduPolyShape<BMap.Polygon> implements Rectangle {
|
|
36
|
+
static create(this: BaiduMap, options: RectangleOptions): BaiduRectangle;
|
|
37
|
+
constructor(innerOverlay: BMap.Polygon, coordType: CoordType, map: BaiduMap, state: {
|
|
38
|
+
editable: boolean;
|
|
39
|
+
});
|
|
40
|
+
protected pathEditedEventType: string;
|
|
41
|
+
private isDoingUpdateRectangle;
|
|
42
|
+
private onBoundsChanged;
|
|
43
|
+
getBounds(): LatLngBounds;
|
|
44
|
+
setBounds(bounds: LatLngBounds): void;
|
|
45
|
+
}
|
|
46
|
+
export declare class GoogleRectangle extends GoogleShape<google.maps.Rectangle> implements Rectangle {
|
|
47
|
+
static create(this: GoogleMap, options: RectangleOptions): GoogleRectangle;
|
|
48
|
+
getBounds(): LatLngBounds;
|
|
49
|
+
setBounds(bounds: LatLngBounds): void;
|
|
50
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import type { CoordType } from '../../lat-lng';
|
|
2
|
+
import type { UnionBaiduShape, UnionGoogleShape } from '../../unions';
|
|
3
|
+
import type { BaiduMap } from '../baidu-map';
|
|
4
|
+
import type { SymbolIcon } from './icon';
|
|
5
|
+
import { BaiduOverlay, GoogleOverlay, type OverlayOptions } from './overlay';
|
|
6
|
+
export interface ShapeOptions extends OverlayOptions {
|
|
7
|
+
clickable?: boolean;
|
|
8
|
+
editable?: boolean;
|
|
9
|
+
strokeColor?: string;
|
|
10
|
+
strokeOpacity?: number;
|
|
11
|
+
/**
|
|
12
|
+
* ## 取值范围不同
|
|
13
|
+
* - google: 最大值约为32, 更大的值不影响线宽
|
|
14
|
+
* - baidu: 没有上限
|
|
15
|
+
*/
|
|
16
|
+
strokeWeight?: number;
|
|
17
|
+
fillColor?: string;
|
|
18
|
+
fillOpacity?: number;
|
|
19
|
+
/**
|
|
20
|
+
* ## 不同实现
|
|
21
|
+
* - google: 支持, 但由于shape和marker所处的mapPan不同, 无法移动到marker上方
|
|
22
|
+
* - baidu: 不支持
|
|
23
|
+
* - maptalks: 为了兼容性, 参考google的效果来实现
|
|
24
|
+
*/
|
|
25
|
+
zIndex?: number;
|
|
26
|
+
}
|
|
27
|
+
export interface Shape {
|
|
28
|
+
isEditable(): boolean;
|
|
29
|
+
setEditable(editable: boolean): void;
|
|
30
|
+
setStrokeColor(color: string): void;
|
|
31
|
+
setStrokeOpacity(opacity: number): void;
|
|
32
|
+
setStrokeWeight(weight: number): void;
|
|
33
|
+
/** Polyline 没有该方法 */
|
|
34
|
+
setFillColor(color: string): void;
|
|
35
|
+
/** @see setFillColor */
|
|
36
|
+
setFillOpacity(opacity: number): void;
|
|
37
|
+
/** baidu不支持 */
|
|
38
|
+
setZIndex(zIndex: number): void;
|
|
39
|
+
}
|
|
40
|
+
export type NotFillableShape = Omit<Shape, 'setFillColor' | 'setFillOpacity'>;
|
|
41
|
+
export type NotFillableShapeOptions = Omit<ShapeOptions, 'fillColor' | 'fillOpacity'>;
|
|
42
|
+
export declare abstract class BaiduShape<T extends UnionBaiduShape> extends BaiduOverlay<T> implements Shape {
|
|
43
|
+
protected state: {
|
|
44
|
+
editable: boolean;
|
|
45
|
+
symbolIcons?: SymbolIcon[];
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
* baidu地图的透明度属性有如下问题:
|
|
49
|
+
* - 在透明度为0时, 无法隐藏掉颜色
|
|
50
|
+
* - 透明度为0.7和0.8时, 在maintain的发布模式下, polyline的线条会不可见 (原因未知, 在tg-map中无法复现)
|
|
51
|
+
* 故统一加个0.001, 规避这些问题...
|
|
52
|
+
*/
|
|
53
|
+
static OPACITY_DELTA: number;
|
|
54
|
+
constructor(innerOverlay: T, coordType: CoordType, map: BaiduMap, state: {
|
|
55
|
+
editable: boolean;
|
|
56
|
+
symbolIcons?: SymbolIcon[];
|
|
57
|
+
});
|
|
58
|
+
isEditable(): boolean;
|
|
59
|
+
setEditable(editable: boolean): void;
|
|
60
|
+
setStrokeColor(color: string): void;
|
|
61
|
+
setStrokeOpacity(opacity: number): void;
|
|
62
|
+
setStrokeWeight(weight: number): void;
|
|
63
|
+
setFillColor(color: string): void;
|
|
64
|
+
setFillOpacity(opacity: number): void;
|
|
65
|
+
setZIndex(zIndex: number): void;
|
|
66
|
+
}
|
|
67
|
+
export declare abstract class GoogleShape<T extends UnionGoogleShape> extends GoogleOverlay<T> implements Shape {
|
|
68
|
+
isEditable(): boolean;
|
|
69
|
+
setEditable(editable: boolean): void;
|
|
70
|
+
setStrokeColor(color: string): void;
|
|
71
|
+
setStrokeOpacity(opacity: number): void;
|
|
72
|
+
setStrokeWeight(weight: number): void;
|
|
73
|
+
setFillColor(color: string): void;
|
|
74
|
+
setFillOpacity(opacity: number): void;
|
|
75
|
+
setZIndex(zIndex: number): void;
|
|
76
|
+
}
|