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.
Files changed (66) hide show
  1. package/dist/index.cjs +6394 -0
  2. package/dist/index.css +77 -0
  3. package/dist/index.mjs +6277 -0
  4. package/dist/src/index.d.ts +50 -0
  5. package/dist/src/map/event-target.d.ts +80 -0
  6. package/dist/src/map/event.d.ts +50 -0
  7. package/dist/src/map/lat-lng.d.ts +160 -0
  8. package/dist/src/map/map/baidu-map.d.ts +82 -0
  9. package/dist/src/map/map/controls/control.d.ts +112 -0
  10. package/dist/src/map/map/controls/map-type.control.d.ts +29 -0
  11. package/dist/src/map/map/controls/scale.control.d.ts +19 -0
  12. package/dist/src/map/map/controls/street-view.control.d.ts +25 -0
  13. package/dist/src/map/map/controls/zoom.control.d.ts +19 -0
  14. package/dist/src/map/map/extra/autocomplete.d.ts +42 -0
  15. package/dist/src/map/map/extra/heatmap.d.ts +71 -0
  16. package/dist/src/map/map/extra/map-urls.d.ts +59 -0
  17. package/dist/src/map/map/extra/marker-clusterer.d.ts +73 -0
  18. package/dist/src/map/map/extra/places-service.d.ts +47 -0
  19. package/dist/src/map/map/extra/search-box.d.ts +38 -0
  20. package/dist/src/map/map/google-map.d.ts +81 -0
  21. package/dist/src/map/map/here-map.d.ts +78 -0
  22. package/dist/src/map/map/map-options.d.ts +60 -0
  23. package/dist/src/map/map/map-type.d.ts +110 -0
  24. package/dist/src/map/map/map.d.ts +198 -0
  25. package/dist/src/map/map/overlay/baidu-info-box.d.ts +82 -0
  26. package/dist/src/map/map/overlay/circle.d.ts +51 -0
  27. package/dist/src/map/map/overlay/element-overlay.d.ts +37 -0
  28. package/dist/src/map/map/overlay/google-label.d.ts +68 -0
  29. package/dist/src/map/map/overlay/icon.d.ts +122 -0
  30. package/dist/src/map/map/overlay/info-box.d.ts +60 -0
  31. package/dist/src/map/map/overlay/info-window.d.ts +111 -0
  32. package/dist/src/map/map/overlay/label.d.ts +102 -0
  33. package/dist/src/map/map/overlay/marker-label.d.ts +19 -0
  34. package/dist/src/map/map/overlay/marker.d.ts +144 -0
  35. package/dist/src/map/map/overlay/overlay.d.ts +46 -0
  36. package/dist/src/map/map/overlay/polygon.d.ts +42 -0
  37. package/dist/src/map/map/overlay/polyline.d.ts +71 -0
  38. package/dist/src/map/map/overlay/rectangle.d.ts +50 -0
  39. package/dist/src/map/map/overlay/shape.d.ts +76 -0
  40. package/dist/src/map/map/talks-map.d.ts +81 -0
  41. package/dist/src/map/map-config.d.ts +29 -0
  42. package/dist/src/map/map-factory.d.ts +33 -0
  43. package/dist/src/map/map-loader.d.ts +19 -0
  44. package/dist/src/map/talks/talks-layers.d.ts +9 -0
  45. package/dist/src/map/talks/talks-utils.d.ts +7 -0
  46. package/dist/src/map/types.d.ts +17 -0
  47. package/dist/src/map/unions.d.ts +20 -0
  48. package/dist/src/utils/arrays.d.ts +19 -0
  49. package/dist/src/utils/baidu-utils.d.ts +23 -0
  50. package/dist/src/utils/elements.d.ts +4 -0
  51. package/dist/src/utils/formatter.d.ts +1 -0
  52. package/dist/src/utils/google-utils.d.ts +34 -0
  53. package/dist/src/utils/here-utils.d.ts +10 -0
  54. package/dist/src/utils/map-utils.d.ts +7 -0
  55. package/dist/src/utils/mapped-types.d.ts +110 -0
  56. package/dist/src/utils/maps-utils/index.d.ts +2 -0
  57. package/dist/src/utils/maps-utils/math-util.d.ts +59 -0
  58. package/dist/src/utils/maps-utils/poly-util.d.ts +103 -0
  59. package/dist/src/utils/maps-utils/spherical-util.d.ts +67 -0
  60. package/dist/src/utils/objects.d.ts +27 -0
  61. package/dist/src/utils/spherical-utils.d.ts +27 -0
  62. package/dist/src/utils/strings.d.ts +21 -0
  63. package/dist/src/utils/utils.d.ts +14 -0
  64. package/dist/src/utils/values.d.ts +34 -0
  65. package/dist/tsconfig.tsbuildinfo +1 -0
  66. package/package.json +60 -0
@@ -0,0 +1,50 @@
1
+ /// <reference path="../../src/map/dts/index.d.ts" preserve="true" />
2
+ export { bindEvents, type Tg } from './map/event';
3
+ export { AbstractEventTargetDelegate, TalksEventTargetDelegate } from './map/event-target';
4
+ export * from './map/lat-lng';
5
+ export { getTgMapConfig, setTgMapConfig, type PartialTgMapConfig, type TgMapConfig } from './map/map-config';
6
+ export * from './map/map-factory';
7
+ export { loadCachedMap } from './map/map-loader';
8
+ export * from './map/map/baidu-map';
9
+ export * from './map/map/controls/control';
10
+ export * from './map/map/controls/map-type.control';
11
+ export * from './map/map/controls/scale.control';
12
+ export * from './map/map/controls/street-view.control';
13
+ export * from './map/map/controls/zoom.control';
14
+ export * from './map/map/extra/autocomplete';
15
+ export * from './map/map/extra/heatmap';
16
+ export * from './map/map/extra/map-urls';
17
+ export * from './map/map/extra/marker-clusterer';
18
+ export * from './map/map/extra/places-service';
19
+ export * from './map/map/extra/search-box';
20
+ export * from './map/map/google-map';
21
+ export * from './map/map/here-map';
22
+ export * from './map/map/map';
23
+ export * from './map/map/map-options';
24
+ export * from './map/map/map-type';
25
+ export * from './map/map/overlay/circle';
26
+ export * from './map/map/overlay/element-overlay';
27
+ export * from './map/map/overlay/icon';
28
+ export * from './map/map/overlay/info-box';
29
+ export * from './map/map/overlay/info-window';
30
+ export * from './map/map/overlay/label';
31
+ export * from './map/map/overlay/marker';
32
+ export * from './map/map/overlay/marker-label';
33
+ export * from './map/map/overlay/overlay';
34
+ export * from './map/map/overlay/polygon';
35
+ export * from './map/map/overlay/polyline';
36
+ export * from './map/map/overlay/rectangle';
37
+ export * from './map/map/talks-map';
38
+ export * from './map/talks/talks-layers';
39
+ export * from './map/talks/talks-utils';
40
+ export * from './map/types';
41
+ export * from './utils/arrays';
42
+ export * from './utils/formatter';
43
+ export * from './utils/map-utils';
44
+ export * from './utils/mapped-types';
45
+ export * from './utils/maps-utils';
46
+ export { Objects } from './utils/objects';
47
+ export * from './utils/spherical-utils';
48
+ export * from './utils/strings';
49
+ export * from './utils/utils';
50
+ export * from './utils/values';
@@ -0,0 +1,80 @@
1
+ import * as maptalks from 'maptalks';
2
+ import { type Tg } from './event';
3
+ import { type CoordTypeSupplier } from './lat-lng';
4
+ import type { AbstractMapEventMap, BaseMap } from './map/map';
5
+ import type { UnionBaiduEventTarget, UnionGoogleEventTarget } from './unions';
6
+ /**
7
+ * 移除事件监听的函数
8
+ *
9
+ * 实现{@link EventTarget}有点复杂, 对于简单的情况, 实现一个设置监听的函数+返回{@link RemoveEventListenerFunction}就够了
10
+ * @see addBaiduEventListener
11
+ * @see addGoogleEventListener
12
+ * */
13
+ export interface RemoveEventListenerFunction {
14
+ (): void;
15
+ }
16
+ export declare function addGoogleEventListener(target: UnionGoogleEventTarget, type: string, listener: (...args: any[]) => void): RemoveEventListenerFunction;
17
+ export declare function addBaiduEventListener(target: UnionBaiduEventTarget, type: string, listener: (...args: any[]) => void): RemoveEventListenerFunction;
18
+ export declare function addHtmlEventListener<K extends keyof EventMap, EventMap = HTMLElementEventMap, T extends EventTarget = HTMLElement>(target: T, type: K, listener: (this: T, ev: EventMap[K]) => any, options?: AddEventListenerOptions | boolean): RemoveEventListenerFunction;
19
+ export declare function addTgEventListener<K extends keyof EventMap, EventMap = AbstractMapEventMap, T extends Tg.EventTarget = BaseMap>(target: T, type: K, listener: (this: T, ev: EventMap[K]) => any): RemoveEventListenerFunction;
20
+ export interface EventTargetDelegate extends Tg.EventTarget {
21
+ setTarget(target: Tg.EventTarget): this;
22
+ }
23
+ /**
24
+ * ## Delegate(代理) VS Mixin(混合)
25
+ * Delegate相对于Mixin的优点是调用路径更明确, 缺点是js/ts原生不支持, 需要写样板代码
26
+ */
27
+ export declare abstract class AbstractEventTargetDelegate<T = any> implements EventTargetDelegate {
28
+ protected inner: T;
29
+ protected coordTypeSupplier: CoordTypeSupplier;
30
+ protected eventMap: Map<string, any>;
31
+ protected target: Tg.EventTarget;
32
+ constructor(inner: T, coordTypeSupplier: CoordTypeSupplier);
33
+ setTarget(target: Tg.EventTarget): this;
34
+ abstract addEventListener(type: string, listener: Tg.EventListener): void;
35
+ abstract removeEventListener(type: string, listener: Tg.EventListener): void;
36
+ }
37
+ export declare class EventHubEventTargetDelegate<EventTypes extends string = string> implements EventTargetDelegate {
38
+ private delegate;
39
+ private options;
40
+ private eventHub;
41
+ constructor(delegate: EventTargetDelegate, options: {
42
+ /** 由{@link eventHub}手动处理的事件 */
43
+ types: EventTypes[];
44
+ /** 用户开始监听{@link type} */
45
+ onListen: (type: EventTypes) => void;
46
+ /** 用户结束监听{@link type} */
47
+ onCancel: (type: EventTypes) => void;
48
+ });
49
+ notify(event: Tg.Event): void;
50
+ hasListener(type: EventTypes): boolean;
51
+ setTarget(target: Tg.EventTarget): this;
52
+ addEventListener(type: string, listener: Tg.EventListener): void;
53
+ removeEventListener(type: string, listener: Tg.EventListener): void;
54
+ }
55
+ export declare class GoogleEventTargetDelegate<T extends UnionGoogleEventTarget = UnionGoogleEventTarget> extends AbstractEventTargetDelegate<T> {
56
+ private static EVENT_TYPE_MAP;
57
+ addEventListener(type: string, listener: Tg.EventListener): void;
58
+ removeEventListener(type: string, listener: Tg.EventListener): void;
59
+ }
60
+ export declare class BaiduEventTargetDelegate<T extends UnionBaiduEventTarget = UnionBaiduEventTarget> extends AbstractEventTargetDelegate<T> {
61
+ private static EVENT_TYPE_MAP;
62
+ addEventListener(type: string, listener: Tg.EventListener): void;
63
+ removeEventListener(type: string, listener: Tg.EventListener): void;
64
+ }
65
+ export declare class TalksEventTargetDelegate<T extends maptalks.Eventable = maptalks.Eventable> extends AbstractEventTargetDelegate<T> {
66
+ static EVENT_TYPE_MAP: {
67
+ 'center-changed': string;
68
+ 'zoom-changed': string;
69
+ } & Record<string, string | undefined>;
70
+ addEventListener(type: string, listener: Tg.EventListener): void;
71
+ removeEventListener(type: string, listener: Tg.EventListener): void;
72
+ }
73
+ /** 手动维护事件 */
74
+ export declare class EventHub implements Tg.EventTarget {
75
+ private typeMap;
76
+ addEventListener(type: string, listener: Tg.EventListener): void;
77
+ removeEventListener(type: string, listener: Tg.EventListener): void;
78
+ hasListener(type: string): boolean;
79
+ notify(event: Tg.Event): void;
80
+ }
@@ -0,0 +1,50 @@
1
+ import type { LatLng } from './lat-lng';
2
+ /**
3
+ * ## 事件机制对比
4
+ * - DOM: add/removeEventListener, Event {type, target}
5
+ * - Vue: $on/$off, 没有Event, listener直接接收数据
6
+ * - baidu: 模仿DOM
7
+ * - here: 模仿DOM
8
+ * - google: addListener+remove, 没有Event, listener直接接收数据
9
+ *
10
+ * 综合对比之后, 决定模仿DOM的事件机制
11
+ */
12
+ export declare namespace Tg {
13
+ interface Event {
14
+ type: string;
15
+ target: EventTarget;
16
+ originalEvent?: any;
17
+ }
18
+ interface MouseEvent extends Event {
19
+ position: LatLng;
20
+ }
21
+ interface EventListener {
22
+ (this: EventTarget, event: Event): void;
23
+ /** 唯一id */
24
+ __id__?: number;
25
+ }
26
+ interface EventTarget {
27
+ addEventListener(type: string, listener: EventListener): void;
28
+ removeEventListener(type: string, listener: EventListener): void;
29
+ }
30
+ /**
31
+ * 带事件的类型信息, 只能监听指定的事件
32
+ * @see EventTarget
33
+ * */
34
+ interface EventTargetTyped<THIS extends EventTarget, MAP extends {
35
+ [k: string]: Event;
36
+ }> extends EventTarget {
37
+ addEventListener<K extends keyof MAP>(type: K, listener: (this: THIS, event: MAP[K]) => void): void;
38
+ removeEventListener<K extends keyof MAP>(type: K, listener: (this: THIS, event: MAP[K]) => void): void;
39
+ }
40
+ /** 带事件的类型信息, 可以监听任何事件 */
41
+ type EventTargetTyped2<THIS extends EventTarget, MAP extends {
42
+ [k: string]: Event;
43
+ }> = EventTargetTyped<THIS, MAP> & EventTarget;
44
+ }
45
+ export declare function bindEvents(listeners: Record<string, unknown>, target: Tg.EventTarget, excludes?: string[]): void;
46
+ export declare function generateNextEventListenerId(): number;
47
+ /**
48
+ * JS的Map/object的key都不支持自定义hashCode()/equals(), 故只能生成字符串当作key
49
+ */
50
+ export declare function generateEventKey(type: string, listener: Tg.EventListener): string;
@@ -0,0 +1,160 @@
1
+ import { type LngLatTuple } from 'coordtransform';
2
+ import * as maptalks from 'maptalks';
3
+ import { type StringEnumValue } from '../utils/mapped-types';
4
+ export declare enum CoordType {
5
+ wgs84 = "wgs84",
6
+ gcj02 = "gcj02",
7
+ bd09 = "bd09"
8
+ }
9
+ export interface CoordTypeSupplier {
10
+ readonly coordType: CoordType;
11
+ }
12
+ export interface LatLngLiteral {
13
+ readonly lat: number;
14
+ readonly lng: number;
15
+ readonly coord?: CoordType;
16
+ }
17
+ export interface WeightedLatLng {
18
+ position: LatLng;
19
+ weight: number;
20
+ }
21
+ export declare class LatLng {
22
+ /**
23
+ * 纬度, 分南北, [-90, 90], 0点为赤道
24
+ */
25
+ readonly lat: number;
26
+ /**
27
+ * 经度, 分东西, [-180, 180], 0点为本初子午线
28
+ */
29
+ readonly lng: number;
30
+ /** 坐标系 */
31
+ readonly coord: CoordType;
32
+ static ZERO: LatLng;
33
+ /**
34
+ * {@template latlng_normalize}
35
+ *
36
+ * 对经纬度进行标准化, 参考google的实现
37
+ *
38
+ * ## 行为不一致
39
+ * - google: google.maps.LatLng的构造器会对经纬度进行标准化, 所有点都能正常显示
40
+ * - baidu: BMap.Point的构造器不会对经纬度进行标准化, 超出范围的点显示到(0, 0)位置
41
+ *
42
+ * {@endtemplate}
43
+ */
44
+ static _normalize(lng: number, lat: number): number[];
45
+ /** @param coord Baidu Map的坐标一般都是bd09 */
46
+ static fromBaidu(point: BMap.Point, coord: CoordType): LatLng;
47
+ /** @param coord Google Map的坐标依据地图类型不同是不一样的 */
48
+ static fromGoogle(latlng: google.maps.LatLng, coord: CoordType): LatLng;
49
+ static fromHere(point: H.geo.IPoint, coord: CoordType): LatLng;
50
+ static fromTalks(coordinate: maptalks.Coordinate, coord: CoordType): LatLng;
51
+ static fromLiteral(latlng: LatLngLiteral): LatLng;
52
+ static fromLngLat(lng: number, lat: number, coord?: CoordType): LatLng;
53
+ static create(lat: number, lng: number, coord?: CoordType): LatLng;
54
+ constructor(
55
+ /**
56
+ * 纬度, 分南北, [-90, 90], 0点为赤道
57
+ */
58
+ lat: number,
59
+ /**
60
+ * 经度, 分东西, [-180, 180], 0点为本初子午线
61
+ */
62
+ lng: number,
63
+ /** 坐标系 */
64
+ coord: CoordType);
65
+ /** 转换坐标到指定坐标系 */
66
+ to(coordType: StringEnumValue<typeof CoordType>): LatLng;
67
+ /**
68
+ * TODO: normalize要不要默认设为true, 和google的行为保持一致?
69
+ * 转换成baidu的经纬度
70
+ * @param normalize 转换时是否进行标准化, 默认false
71
+ * @see _normalize {@macro latlng_normalize}
72
+ */
73
+ toBaidu(coord: CoordType, normalize?: boolean): BMap.Point;
74
+ /**
75
+ * 转换成google的经纬度, 内部会自动进行标准化
76
+ * @see _normalize {@macro latlng_normalize}
77
+ */
78
+ toGoogle(coord: CoordType): google.maps.LatLng;
79
+ toHere(coord: CoordType): H.geo.Point;
80
+ toTalks(coord: CoordType): maptalks.Coordinate;
81
+ /**
82
+ * 该方法之所以设计的这么不友好, 是为了防止不必要的开销(大概有点影响😅)
83
+ *
84
+ * 私有方法, 外部需要转换坐标系, 请使用{@link to}/toBaidu/Google/Here, 之所以不添加private关键字, 是因为设成私有后, 有的地方会报类型错误...
85
+ *
86
+ * @returns `[lng, lat]` 注意不要取错顺序
87
+ * @throws 若当前coord和targetCoord相同, 会抛异常, 故请在外部判断
88
+ */
89
+ _convert(targetCoord: CoordType): LngLatTuple;
90
+ /**
91
+ * 标准化, 返回合法的坐标点
92
+ * @see _normalize {@macro latlng_normalize}
93
+ */
94
+ normalize(): LatLng;
95
+ equals(other: LatLng): boolean;
96
+ toString(): string;
97
+ }
98
+ /** 少数接口同时支持对象形式和字面量形式 */
99
+ export type LatLngType = LatLng | LatLngLiteral;
100
+ /**
101
+ * 反编译自{@link com.google.android.gms.maps.model.LatLngBounds}
102
+ */
103
+ export declare class LatLngBounds {
104
+ sw: LatLng;
105
+ ne: LatLng;
106
+ static EMPTY: LatLngBounds;
107
+ static isBetweenLng(minLng: number, maxLng: number, lng: number): boolean;
108
+ /**
109
+ * 从数组创建bounds
110
+ *
111
+ * 只有{@link positions}为空时, 才会返回`undefined`, 可以借助{@link Arrays.isNotEmpty}协助进行类型推断
112
+ */
113
+ static fromArray(positions: readonly []): undefined;
114
+ /** @see Arrays.isNotEmpty */
115
+ static fromArray(positions: readonly [LatLng, ...LatLng[]]): LatLngBounds;
116
+ static fromArray(positions: readonly LatLng[]): LatLngBounds | undefined;
117
+ static from(...positions: LatLng[]): LatLngBounds;
118
+ static fromGoogle(bounds: google.maps.LatLngBounds, coord: CoordType): LatLngBounds;
119
+ static fromBaidu(bounds: BMap.Bounds, coord: CoordType): LatLngBounds;
120
+ static create(sw: LatLng, ne: LatLng): LatLngBounds;
121
+ coord: CoordType;
122
+ /**
123
+ * 不推荐直接创建LatLngBounds, sw和ne的大小关系可能没法保证, 推荐用LatLngBounds.Builder或者LatLngBounds.from等静态方法来创建
124
+ * @param sw 西南, lat/lng更小
125
+ * @param ne 东北, lat/lng更大
126
+ */
127
+ constructor(sw: LatLng, ne: LatLng);
128
+ isEmpty(): boolean;
129
+ contains(position: LatLng): boolean;
130
+ getCenter(): LatLng;
131
+ toString(): string;
132
+ equals(other: LatLngBounds): boolean;
133
+ /**
134
+ * 矩形的四个点数组
135
+ * 顺时针: sw(西南) -> nw(西北) -> ne(东北) -> se(东南)
136
+ * */
137
+ toRectArray(): LatLng[];
138
+ toGoogle(coord: CoordType): google.maps.LatLngBounds;
139
+ toBaidu(coord: CoordType): BMap.Bounds;
140
+ toBaiduArray(coord: CoordType): BMap.Point[];
141
+ }
142
+ export declare namespace LatLngBounds {
143
+ class Builder {
144
+ private coord;
145
+ private minLat;
146
+ private minLng;
147
+ private maxLat;
148
+ private maxLng;
149
+ constructor(start: LatLng);
150
+ build(): LatLngBounds;
151
+ include(position: LatLng): this;
152
+ private delta;
153
+ }
154
+ }
155
+ /** 在导航/搜索等接口中使用的 位置 */
156
+ export type Location = string | LatLng;
157
+ export declare namespace Location {
158
+ function toString(place: Location | undefined, coordType: CoordType): string | undefined;
159
+ function getCoordType(place: Location | undefined): CoordType | undefined;
160
+ }
@@ -0,0 +1,82 @@
1
+ import { LatLng, LatLngBounds } from '../lat-lng';
2
+ import type { Padding, Point } from '../types';
3
+ import { CustomControl } from './controls/control';
4
+ import { BaiduMapTypeControl } from './controls/map-type.control';
5
+ import { BaiduScaleControl } from './controls/scale.control';
6
+ import { BaiduStreetViewControl } from './controls/street-view.control';
7
+ import { BaiduZoomControl } from './controls/zoom.control';
8
+ import { type Autocomplete, type AutocompleteOptions } from './extra/autocomplete';
9
+ import { type Heatmap, type HeatmapOptions } from './extra/heatmap';
10
+ import { type MapUrls, type MapUrlsOptions } from './extra/map-urls';
11
+ import { BaiduMarkerClusterer, type MarkerClustererOptions } from './extra/marker-clusterer';
12
+ import { type PlacesService, type PlacesServiceOptions } from './extra/places-service';
13
+ import { type SearchBox, type SearchBoxOptions } from './extra/search-box';
14
+ import { BaseMap, type AbstractMapEventMap } from './map';
15
+ import { GestureHandlingOptions, MapOptions, type MapStyle } from './map-options';
16
+ import { BuildInMapTypeId, MapType, type Layer } from './map-type';
17
+ import { BaiduCircle } from './overlay/circle';
18
+ import type { ElementOverlay } from './overlay/element-overlay';
19
+ import { BaiduInfoBoxOverlay } from './overlay/info-box';
20
+ import { BaiduInfoWindow } from './overlay/info-window';
21
+ import { BaiduLabelOverlay } from './overlay/label';
22
+ import { BaiduMarker } from './overlay/marker';
23
+ import type { BaiduOverlay } from './overlay/overlay';
24
+ import { BaiduPolygon } from './overlay/polygon';
25
+ import { BaiduPolyline } from './overlay/polyline';
26
+ import { BaiduRectangle } from './overlay/rectangle';
27
+ export declare class BaiduMap extends BaseMap {
28
+ private buildInMapTypeId2BIMT;
29
+ private baiduMapType2BIMT;
30
+ private map;
31
+ constructor(element: HTMLElement, mapOptions: MapOptions);
32
+ setGestureHandling(gestureHandling?: GestureHandlingOptions): void;
33
+ get innerMap(): BMap.Map;
34
+ get coordType(): import("../lat-lng").CoordType;
35
+ addEventListener<K extends keyof AbstractMapEventMap>(type: K, listener: (event: AbstractMapEventMap[K]) => void): void;
36
+ removeEventListener<K extends keyof AbstractMapEventMap>(type: K, listener: (event: AbstractMapEventMap[K]) => void): void;
37
+ fromContainerPointToLatLng(point: Point): LatLng;
38
+ fromLatLngToContainerPoint(latLng: LatLng): Point;
39
+ setDefaultCursor(cursor: string): void;
40
+ setDraggable(draggable: boolean): void;
41
+ setDoubleClickZoom(enable: boolean): void;
42
+ getCenter(): LatLng;
43
+ setCenter(latlng: LatLng): void;
44
+ getZoom(): number;
45
+ setZoom(zoom: number): void;
46
+ setMinZoom(zoom: number): void;
47
+ setMaxZoom(zoom: number): void;
48
+ setMapStyle(mapStyle?: MapStyle): void;
49
+ setBuildInMapTypeId(id: BuildInMapTypeId): void;
50
+ setMapType(mapType: MapType): void;
51
+ getMapType(): MapType;
52
+ addLayer(layer: Layer): void;
53
+ removeLayer(layer: Layer): void;
54
+ panTo(position: LatLng): void;
55
+ panBy(x: number, y: number): void;
56
+ fitBounds(bounds: LatLngBounds, padding?: Padding): void;
57
+ getBounds(): LatLngBounds;
58
+ addElementOverlay(overlay: ElementOverlay): void;
59
+ removeElementOverlay(overlay: ElementOverlay): void;
60
+ addOverlay(overlay: BaiduOverlay): void;
61
+ removeOverlay(overlay: BaiduOverlay): void;
62
+ addCustomControl(control: CustomControl): void;
63
+ removeCustomControl(control: CustomControl): void;
64
+ createLabel: typeof BaiduLabelOverlay.create;
65
+ createCircle: typeof BaiduCircle.create;
66
+ createPolygon: typeof BaiduPolygon.create;
67
+ createPolyline: typeof BaiduPolyline.create;
68
+ createRectangle: typeof BaiduRectangle.create;
69
+ createInfoWindow: typeof BaiduInfoWindow.create;
70
+ createInfoBox: typeof BaiduInfoBoxOverlay.create;
71
+ createMarker: typeof BaiduMarker.create;
72
+ createMapTypeControl: typeof BaiduMapTypeControl.create;
73
+ createZoomControl: typeof BaiduZoomControl.create;
74
+ createStreetViewControl: typeof BaiduStreetViewControl.create;
75
+ createScaleControl: typeof BaiduScaleControl.create;
76
+ createMarkerClusterer(options: MarkerClustererOptions): BaiduMarkerClusterer;
77
+ createHeatmap(options: HeatmapOptions): Heatmap;
78
+ createAutocomplete(options: AutocompleteOptions): Autocomplete;
79
+ createSearchBox(options: SearchBoxOptions): SearchBox;
80
+ createPlacesService(options: PlacesServiceOptions): PlacesService;
81
+ createMapUrls(options: MapUrlsOptions): MapUrls;
82
+ }
@@ -0,0 +1,112 @@
1
+ import { KeyValue } from '../../../utils/values';
2
+ import type { UnionControl } from '../../unions';
3
+ import type { BaiduMap } from '../baidu-map';
4
+ import type { GoogleMap } from '../google-map';
5
+ import type { AbstractMap } from '../map';
6
+ export declare enum ControlPosition {
7
+ /** 左上 */
8
+ TOP_LEFT = "top-left",
9
+ TOP_CENTER = "top-center",
10
+ /** 右上 */
11
+ TOP_RIGHT = "top-right",
12
+ BOTTOM_LEFT = "bottom-left",
13
+ BOTTOM_CENTER = "bottom-center",
14
+ BOTTOM_RIGHT = "bottom-right",
15
+ LEFT_TOP = "left-top",
16
+ LEFT_CENTER = "left-center",
17
+ /** 左下 */
18
+ LEFT_BOTTOM = "left-bottom",
19
+ RIGHT_TOP = "right-top",
20
+ RIGHT_CENTER = "right-center",
21
+ /** 右下 */
22
+ RIGHT_BOTTOM = "right-bottom"
23
+ }
24
+ export declare namespace ControlPositionConverter {
25
+ function getBaidu(): KeyValue<ControlPosition, number>;
26
+ function getGoogle(): KeyValue<ControlPosition, google.maps.ControlPosition>;
27
+ }
28
+ /**
29
+ * 自定义的Control
30
+ * @see BaiduMap.addCustomControl
31
+ * @see GoogleMap.addCustomControl
32
+ * */
33
+ export declare abstract class CustomControl {
34
+ position: ControlPosition;
35
+ /** 实际添加到地图中的control对象 */
36
+ inner?: UnionControl;
37
+ constructor(position: ControlPosition);
38
+ /** 创建UI元素 */
39
+ abstract onCreateElement(): HTMLElement;
40
+ }
41
+ /** 内置的Control */
42
+ export declare abstract class AbstractControl {
43
+ abstract isVisible(): boolean;
44
+ abstract setVisible(visible: boolean): void;
45
+ abstract getPosition(): ControlPosition;
46
+ abstract setPosition(position: ControlPosition): void;
47
+ abstract addTo(map: AbstractMap): void;
48
+ abstract removeFrom(map: AbstractMap): void;
49
+ }
50
+ /** Control的空实现 */
51
+ export declare class EmptyControl extends AbstractControl {
52
+ private visible;
53
+ private position;
54
+ constructor(visible: boolean, position: ControlPosition);
55
+ isVisible(): boolean;
56
+ setVisible(visible: boolean): void;
57
+ getPosition(): ControlPosition;
58
+ setPosition(position: ControlPosition): void;
59
+ addTo(_map: AbstractMap): void;
60
+ removeFrom(_map: AbstractMap): void;
61
+ }
62
+ /**
63
+ * baidu内置的Control
64
+ * - NavigationControl
65
+ * - OverviewMapControl
66
+ * - ScaleControl
67
+ * - MapTypeControl
68
+ * - CopyrightControl
69
+ * - GeolocationControl
70
+ */
71
+ export declare class BaiduControl<CONTROL extends BMap.Control = BMap.Control> extends AbstractControl {
72
+ private inner;
73
+ /** 由于@tg/map的position和baidu的position是多对一的关系, 为了防止set后再get, 得到不同的值, 应该用this.position保存set的值 */
74
+ private position?;
75
+ constructor(inner: CONTROL,
76
+ /** 由于@tg/map的position和baidu的position是多对一的关系, 为了防止set后再get, 得到不同的值, 应该用this.position保存set的值 */
77
+ position?: ControlPosition | undefined);
78
+ isVisible(): boolean;
79
+ setVisible(visible: boolean): void;
80
+ getPosition(): ControlPosition;
81
+ setPosition(position: ControlPosition): void;
82
+ addTo(map: BaiduMap): void;
83
+ removeFrom(map: BaiduMap): void;
84
+ }
85
+ export type GoogleControlType = 'zoom' | 'mapType' | 'scale' | 'streetView' | 'rotate' | 'fullscreen';
86
+ /**
87
+ * google内置的Control
88
+ * - ZoomControl
89
+ * - MapTypeControl
90
+ * - ScaleControl
91
+ * - StreetViewControl
92
+ * - RotateControl
93
+ * - FullscreenControl
94
+ */
95
+ export declare class GoogleControl extends AbstractControl {
96
+ private _type;
97
+ /** 每种类型的position的初始值不一样, 需要外部传入 */
98
+ private position;
99
+ visible: boolean;
100
+ private map;
101
+ constructor(_type: GoogleControlType,
102
+ /** 每种类型的position的初始值不一样, 需要外部传入 */
103
+ position: ControlPosition);
104
+ isVisible(): boolean;
105
+ setVisible(visible: boolean): void;
106
+ getPosition(): ControlPosition;
107
+ setPosition(position: ControlPosition): void;
108
+ addTo(map: GoogleMap): void;
109
+ removeFrom(): void;
110
+ protected onCreateOptions(): any;
111
+ protected tryUpdateOptions(): void;
112
+ }
@@ -0,0 +1,29 @@
1
+ import type { BaiduMap } from '../baidu-map';
2
+ import type { GoogleMap } from '../google-map';
3
+ import { MapType } from '../map-type';
4
+ import { AbstractControl, BaiduControl, ControlPosition, GoogleControl } from './control';
5
+ export interface MapTypeControl extends AbstractControl {
6
+ }
7
+ export declare enum MapTypeControlType {
8
+ DEFAULT = "default",
9
+ HORIZONTAL = "horizontal",
10
+ DROPDOWN = "dropdown"
11
+ }
12
+ export interface MapTypeControlOptions {
13
+ position?: ControlPosition;
14
+ type?: MapTypeControlType;
15
+ /** @default MAP_TYPES_DEFAULT 这有这些mapTypes才是各种地图都兼容的 */
16
+ mapTypes?: MapType[];
17
+ }
18
+ export declare class BaiduMapTypeControl extends BaiduControl<BMap.MapTypeControl> implements MapTypeControl {
19
+ static create(this: BaiduMap, options: MapTypeControlOptions): BaiduMapTypeControl;
20
+ }
21
+ export declare class GoogleMapTypeControl extends GoogleControl implements MapTypeControl {
22
+ type: MapTypeControlType;
23
+ private mapTypes;
24
+ static create(this: GoogleMap, options: MapTypeControlOptions): GoogleMapTypeControl;
25
+ private static type2google;
26
+ constructor(type?: MapTypeControlType, position?: ControlPosition, mapTypes?: MapType[]);
27
+ onCreateOptions(): any;
28
+ addTo(map: GoogleMap): void;
29
+ }
@@ -0,0 +1,19 @@
1
+ import type { BaiduMap } from '../baidu-map';
2
+ import type { GoogleMap } from '../google-map';
3
+ import type { TalksMap } from '../talks-map';
4
+ import { AbstractControl, BaiduControl, ControlPosition, EmptyControl, GoogleControl } from './control';
5
+ export interface ScaleControl extends AbstractControl {
6
+ }
7
+ export interface ScaleControlOptions {
8
+ position?: ControlPosition;
9
+ }
10
+ export declare class BaiduScaleControl extends BaiduControl implements ScaleControl {
11
+ static create(this: BaiduMap, options: ScaleControlOptions): BaiduScaleControl;
12
+ }
13
+ export declare class GoogleScaleControl extends GoogleControl implements ScaleControl {
14
+ static create(this: GoogleMap, options: ScaleControlOptions): GoogleScaleControl;
15
+ constructor(position?: ControlPosition);
16
+ }
17
+ export declare class TalksScaleControl extends EmptyControl implements ScaleControl {
18
+ static create(this: TalksMap, options: ScaleControlOptions): TalksScaleControl;
19
+ }
@@ -0,0 +1,25 @@
1
+ import type { BaiduMap } from '../baidu-map';
2
+ import type { GoogleMap } from '../google-map';
3
+ import type { TalksMap } from '../talks-map';
4
+ import { AbstractControl, ControlPosition, EmptyControl, GoogleControl } from './control';
5
+ /**
6
+ * ## 不同实现
7
+ * - google: 支持街景控件
8
+ * - baidu: 不支持, {@link BaiduStreetViewControl}是一个空实现
9
+ * - talks: 不支持
10
+ */
11
+ export interface StreetViewControl extends AbstractControl {
12
+ }
13
+ export interface StreetViewControlOptions {
14
+ position?: ControlPosition;
15
+ }
16
+ export declare class BaiduStreetViewControl extends EmptyControl implements StreetViewControl {
17
+ static create(this: BaiduMap, options: StreetViewControlOptions): BaiduStreetViewControl;
18
+ }
19
+ export declare class GoogleStreetViewControl extends GoogleControl implements StreetViewControl {
20
+ static create(this: GoogleMap, options: StreetViewControlOptions): GoogleStreetViewControl;
21
+ constructor(position?: ControlPosition);
22
+ }
23
+ export declare class TalksStreetViewControl extends EmptyControl implements StreetViewControl {
24
+ static create(this: TalksMap, options: StreetViewControlOptions): TalksStreetViewControl;
25
+ }
@@ -0,0 +1,19 @@
1
+ import type { BaiduMap } from '../baidu-map';
2
+ import type { GoogleMap } from '../google-map';
3
+ import type { TalksMap } from '../talks-map';
4
+ import { AbstractControl, BaiduControl, ControlPosition, EmptyControl, GoogleControl } from './control';
5
+ export interface ZoomControl extends AbstractControl {
6
+ }
7
+ export interface ZoomControlOptions {
8
+ position?: ControlPosition;
9
+ }
10
+ export declare class BaiduZoomControl extends BaiduControl<BMap.NavigationControl> implements ZoomControl {
11
+ static create(this: BaiduMap, options: ZoomControlOptions): BaiduZoomControl;
12
+ }
13
+ export declare class GoogleZoomControl extends GoogleControl implements ZoomControl {
14
+ static create(this: GoogleMap, options: ZoomControlOptions): GoogleZoomControl;
15
+ constructor(position?: ControlPosition);
16
+ }
17
+ export declare class TalksZoomControl extends EmptyControl implements ZoomControl {
18
+ static create(this: TalksMap, options: ZoomControlOptions): TalksZoomControl;
19
+ }