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,81 @@
1
+ import type { Property } from 'csstype';
2
+ import * as maptalks from 'maptalks';
3
+ import 'maptalks/dist/maptalks.css';
4
+ import { LatLng, type CoordType, type LatLngBounds } from '../lat-lng';
5
+ import { type TalksBaseLayerId } from '../talks/talks-layers';
6
+ import type { Padding, Point } from '../types';
7
+ import type { CustomControl } from './controls/control';
8
+ import type { MapTypeControl, MapTypeControlOptions } from './controls/map-type.control';
9
+ import { TalksScaleControl } from './controls/scale.control';
10
+ import { TalksStreetViewControl } from './controls/street-view.control';
11
+ import { TalksZoomControl } from './controls/zoom.control';
12
+ import type { Autocomplete, AutocompleteOptions } from './extra/autocomplete';
13
+ import type { Heatmap, HeatmapOptions } from './extra/heatmap';
14
+ import type { MapUrls, MapUrlsOptions } from './extra/map-urls';
15
+ import type { MarkerClusterer, MarkerClustererOptions } from './extra/marker-clusterer';
16
+ import type { PlacesService, PlacesServiceOptions } from './extra/places-service';
17
+ import type { SearchBox, SearchBoxOptions } from './extra/search-box';
18
+ import { BaseMap } from './map';
19
+ import type { GestureHandlingOptions, MapOptions, MapStyle } from './map-options';
20
+ import { BuildInMapTypeId, type Layer, type MapType } from './map-type';
21
+ import type { CircleOptions, CircleOverlay } from './overlay/circle';
22
+ import type { ElementOverlay } from './overlay/element-overlay';
23
+ import type { InfoBoxOptions, InfoBoxOverlay } from './overlay/info-box';
24
+ import type { InfoWindowOptions, InfoWindowOverlay } from './overlay/info-window';
25
+ import type { LabelOptions, LabelOverlay } from './overlay/label';
26
+ import type { MarkerOptions, MarkerOverlay } from './overlay/marker';
27
+ import type { Overlay } from './overlay/overlay';
28
+ import type { PolygonOptions, PolygonOverlay } from './overlay/polygon';
29
+ import type { PolylineOptions, PolylineOverlay } from './overlay/polyline';
30
+ import type { RectangleOptions, RectangleOverlay } from './overlay/rectangle';
31
+ export declare class TalksMap extends BaseMap {
32
+ private map;
33
+ private currentBaseLayerId;
34
+ constructor(element: HTMLElement, mapOptions: MapOptions, baseLayoutIds: [normal: TalksBaseLayerId] | [normal: TalksBaseLayerId, satellite: TalksBaseLayerId] | [normal: TalksBaseLayerId, satellite: TalksBaseLayerId, hybrid: TalksBaseLayerId]);
35
+ setGestureHandling(gestureHandling: GestureHandlingOptions): void;
36
+ get innerMap(): maptalks.Map;
37
+ get coordType(): CoordType;
38
+ fromContainerPointToLatLng(point: Point): LatLng;
39
+ fromLatLngToContainerPoint(latLng: LatLng): Point;
40
+ setDefaultCursor(cursor: Property.Cursor): void;
41
+ setDraggable(draggable: boolean): void;
42
+ setDoubleClickZoom(enable: boolean): void;
43
+ getCenter(): LatLng;
44
+ setCenter(latlng: LatLng): void;
45
+ setMinZoom(zoom: number): void;
46
+ setMaxZoom(zoom: number): void;
47
+ setMapStyle(mapStyle?: MapStyle): void;
48
+ setBuildInMapTypeId(id: BuildInMapTypeId): void;
49
+ setMapType(mapType: MapType): void;
50
+ getMapType(): MapType;
51
+ addLayer(layer: Layer): void;
52
+ removeLayer(layer: Layer): void;
53
+ panTo(position: LatLng): void;
54
+ panBy(x: number, y: number): void;
55
+ fitBounds(bounds: LatLngBounds, padding?: Padding): void;
56
+ getBounds(): LatLngBounds;
57
+ addElementOverlay(overlay: ElementOverlay): void;
58
+ removeElementOverlay(overlay: ElementOverlay): void;
59
+ addOverlay(overlay: Overlay): void;
60
+ removeOverlay(overlay: Overlay): void;
61
+ createMarker(options: MarkerOptions): MarkerOverlay;
62
+ createMarkerClusterer(options: MarkerClustererOptions): MarkerClusterer;
63
+ createHeatmap(options: HeatmapOptions): Heatmap;
64
+ createAutocomplete(options: AutocompleteOptions): Autocomplete;
65
+ createSearchBox(options: SearchBoxOptions): SearchBox;
66
+ createPlacesService(options: PlacesServiceOptions): PlacesService;
67
+ createMapUrls(options: MapUrlsOptions): MapUrls;
68
+ createInfoWindow(options: InfoWindowOptions): InfoWindowOverlay;
69
+ createInfoBox(options: InfoBoxOptions): InfoBoxOverlay;
70
+ createPolyline(options: PolylineOptions): PolylineOverlay;
71
+ createPolygon(options: PolygonOptions): PolygonOverlay;
72
+ createRectangle(options: RectangleOptions): RectangleOverlay;
73
+ createCircle(options: CircleOptions): CircleOverlay;
74
+ createLabel(options: LabelOptions): LabelOverlay;
75
+ addCustomControl(control: CustomControl): void;
76
+ removeCustomControl(control: CustomControl): void;
77
+ createMapTypeControl(options: MapTypeControlOptions): MapTypeControl;
78
+ createZoomControl: typeof TalksZoomControl.create;
79
+ createStreetViewControl: typeof TalksStreetViewControl.create;
80
+ createScaleControl: typeof TalksScaleControl.create;
81
+ }
@@ -0,0 +1,29 @@
1
+ import { HERE_SUPPORTED_VERSIONS } from '../utils/here-utils';
2
+ import type { DeepPartial, EmptyObject } from '../utils/mapped-types';
3
+ export interface MapConfig {
4
+ key: string;
5
+ version: string;
6
+ }
7
+ export interface TgMapConfig {
8
+ google: MapConfig & {
9
+ /** @see https://developers.google.com/maps/documentation/javascript/versions */
10
+ version: 'weekly' | 'quarterly' | 'beta' | 'alpha' | '3.49' | '3.50' | '3.51' | '3.52';
11
+ language: string;
12
+ /** @see https://developers.google.com/maps/documentation/javascript/libraries */
13
+ libraries: ('drawing' | 'geometry' | 'journeySharing' | 'localContext' | 'marker' | 'places' | 'visualization')[];
14
+ };
15
+ baidu: MapConfig & {
16
+ /** @see https://lbsyun.baidu.com/index.php?title=jspopular3.0/theupdatelog */
17
+ version: '3.0';
18
+ };
19
+ here: MapConfig & {
20
+ version: typeof HERE_SUPPORTED_VERSIONS[number];
21
+ };
22
+ baiduFree: EmptyObject;
23
+ yandex: EmptyObject;
24
+ amap: EmptyObject;
25
+ osm: EmptyObject;
26
+ }
27
+ export type PartialTgMapConfig = DeepPartial<TgMapConfig>;
28
+ export declare function getTgMapConfig(): TgMapConfig;
29
+ export declare function setTgMapConfig(config?: PartialTgMapConfig): void;
@@ -0,0 +1,33 @@
1
+ import type { BaseMap } from './map/map';
2
+ import { MapOptions } from './map/map-options';
3
+ export declare enum TgMapType {
4
+ /**
5
+ * Google地图
6
+ * - V1: 官方地图, 基本使用免费
7
+ * - V2: 使用maptalks
8
+ */
9
+ google = "google",
10
+ /**
11
+ * Baidu地图
12
+ * - V1: 官方地图, 年费5万
13
+ * - V2: 使用maptalks
14
+ */
15
+ baidu = "baidu",
16
+ /**
17
+ * Here地图
18
+ * - V1: 官方地图, 只实现了1%
19
+ * - V2: 使用maptalks
20
+ */
21
+ here = "here",
22
+ /** Baidu免费地图, 使用maptalks */
23
+ baiduFree = "baiduFree",
24
+ /** Yandex地图, 使用maptalks */
25
+ yandex = "yandex",
26
+ /** 高德地图, 使用maptalks */
27
+ amap = "amap",
28
+ /** 开源地图, 使用maptalks */
29
+ osm = "osm"
30
+ }
31
+ export declare namespace TgMapFactory {
32
+ function createMap(type: TgMapType, $map: HTMLElement, mapOptions?: Partial<MapOptions>): BaseMap;
33
+ }
@@ -0,0 +1,19 @@
1
+ import { type TgMapConfig } from './map-config';
2
+ import { TgMapType } from './map-factory';
3
+ /**
4
+ * 使用类型映射的方式`TgMapConfig[T]`, 确定`type`的类型之后, 不会自动推断`config`的类型,
5
+ * 故另外声明了一个联合类型{@link LoadMapOptionsImpl}, 在实现代码中使用它来自动推断类型
6
+ */
7
+ type LoadMapOptions<T extends TgMapType> = {
8
+ type: T;
9
+ config: TgMapConfig[T];
10
+ };
11
+ /**
12
+ * 加载缓存的地图, 保证一种地图只加载一次
13
+ */
14
+ export declare function loadCachedMap(type: TgMapType): Promise<unknown>;
15
+ /** 载入地图库 */
16
+ export declare function loadMap<T extends TgMapType>(options: LoadMapOptions<T>): Promise<unknown>;
17
+ export declare function loadJsonp(url: string, callbackParamName?: string): Promise<unknown>;
18
+ export declare function loadJs(url: string): Promise<unknown>;
19
+ export {};
@@ -0,0 +1,9 @@
1
+ import * as maptalks from 'maptalks';
2
+ import { CoordType } from '../lat-lng';
3
+ export declare const talksBaseLayerIds: readonly ["osm", "osm-simple", "google", "baidu", "amap", "tencent", "geoq", "tianditu", "yandex", "bing"];
4
+ export type TalksBaseLayerId = typeof talksBaseLayerIds[number];
5
+ export declare function talksBaseLayerIdToCoordType(layerId: TalksBaseLayerId): CoordType;
6
+ export declare function createTalksBaseLayer(layerId: TalksBaseLayerId, { id, visible, }?: {
7
+ id?: "google" | "osm" | "osm-simple" | "baidu" | "amap" | "tencent" | "geoq" | "tianditu" | "yandex" | "bing" | undefined;
8
+ visible?: boolean | undefined;
9
+ }): maptalks.TileLayer;
@@ -0,0 +1,7 @@
1
+ export declare namespace Talks {
2
+ function setVisible(that: {
3
+ isVisible(): boolean;
4
+ show(): void;
5
+ hide(): void;
6
+ }, visible: boolean): void;
7
+ }
@@ -0,0 +1,17 @@
1
+ export interface Size {
2
+ readonly width: number;
3
+ readonly height: number;
4
+ }
5
+ export interface Point {
6
+ readonly x: number;
7
+ readonly y: number;
8
+ }
9
+ export declare namespace Point {
10
+ const ZERO: Point;
11
+ }
12
+ export interface Padding {
13
+ top: number;
14
+ right: number;
15
+ bottom: number;
16
+ left: number;
17
+ }
@@ -0,0 +1,20 @@
1
+ import * as maptalks from 'maptalks';
2
+ import type { BaiduInfoBox } from './map/overlay/baidu-info-box';
3
+ import type { GoogleLabel } from './map/overlay/google-label';
4
+ /**
5
+ * Map相关的各种类型的联合, 可以用来简化一部分代码的书写
6
+ */
7
+ export type UnionMap = google.maps.Map | BMap.Map | H.Map | maptalks.Map;
8
+ export type UnionBaiduIcon = BMap.Icon | BMap.Symbol;
9
+ export type UnionGoogleIcon = google.maps.Icon | google.maps.Symbol | google.maps.UrlIcon;
10
+ export type UnionInfoWindow = google.maps.InfoWindow | BMap.InfoWindow;
11
+ export type UnionAutocomplete = google.maps.places.Autocomplete | BMap.Autocomplete;
12
+ export type UnionPlacesService = google.maps.places.PlacesService | BMap.LocalSearch;
13
+ export type UnionGoogleOverlay = google.maps.Marker | google.maps.Polyline | google.maps.Polygon | google.maps.Circle | google.maps.Rectangle | GoogleLabel;
14
+ export type UnionBaiduOverlay = BMap.Marker | BMap.Polyline | BMap.Polygon | BMap.Circle | BMap.Label | BaiduInfoBox;
15
+ export type UnionGoogleEventTarget = google.maps.MVCObject;
16
+ export type UnionBaiduEventTarget = UnionBaiduOverlay | BMap.InfoWindow | BMap.Autocomplete | BMap.Map;
17
+ export type UnionBaiduShape = BMap.Polyline | BMap.Polygon | BMap.Circle;
18
+ export type UnionGoogleShape = google.maps.Polyline | google.maps.Polygon | google.maps.Circle | google.maps.Rectangle;
19
+ export type UnionControl = BMap.Control | HTMLElement;
20
+ export type GoogleLayer = google.maps.TrafficLayer | google.maps.TransitLayer | google.maps.KmlLayer | google.maps.BicyclingLayer;
@@ -0,0 +1,19 @@
1
+ import type { AnyFunction, Constructor } from './mapped-types';
2
+ export declare namespace Arrays {
3
+ function findByType<T>(arr: any[], constructor: Constructor<T>): T | undefined;
4
+ /** 自动推断item的类型的{@link Array.includes} */
5
+ function includesTyped<T extends E, E>(arr: T[], item: E): item is T;
6
+ /** 设置 指定位置的值 */
7
+ function at<T>(arr: T[], index: number, value: T): void;
8
+ /** 获取 指定位置的值 */
9
+ function at<T>(arr: T[], index: number): T | undefined;
10
+ }
11
+ export declare namespace MVCArrays {
12
+ function indexOf<T>(arr: google.maps.MVCArray<T>, item: T): number;
13
+ function remove<T>(arr: google.maps.MVCArray<T>, item: T): T | undefined;
14
+ /**
15
+ * 监听数组内容变化
16
+ * @see https://developers.google.com/maps/documentation/javascript/shapes#editable_events
17
+ * */
18
+ function listenChanged<T>(path: google.maps.MVCArray<T>, handler: AnyFunction): google.maps.MapsEventListener[];
19
+ }
@@ -0,0 +1,23 @@
1
+ /**
2
+ * 3.0版的Overlay是类
3
+ * @see http://lbsyun.baidu.com/cms/jsapi/reference/jsapi_reference_3_0.html#a3b0
4
+ */
5
+ export declare function ensureBaiduV3(): void;
6
+ /**
7
+ * 尝试修复baidu内存占用会越来越大的问题
8
+ *
9
+ * 当前版本的baidu源码中, 存在如下代码:
10
+ * ```
11
+ * A.lang.qx = function(a) {
12
+ * var b = window[A.da]; // A.da等于'$BAIDU$'
13
+ * b.kT && delete b.kT[a] // kT属性不存在, 故永远无法移除成功
14
+ * }
15
+ * ```
16
+ * 最终会导致`$BAIDU$._instances`对象不断增长, 故我们把`$BAIDU$`对象的`kT`属性重定向到`_instances`
17
+ * 保证该方法能够执行成功
18
+ */
19
+ export declare function tryFixBaiduOutOfMemory(): void;
20
+ export declare const BMapPoints: {
21
+ /** {@link BMap.Point.equals} 无效, 故需要自己写一个 */
22
+ equals(a: BMap.Point, b: BMap.Point): boolean;
23
+ };
@@ -0,0 +1,4 @@
1
+ export declare namespace Elements {
2
+ /** @see https://stackoverflow.com/questions/4880381/check-whether-html-element-has-scrollbars */
3
+ function isScrollable(ele: Element): boolean;
4
+ }
@@ -0,0 +1 @@
1
+ export declare function dimen(value: string | number | null | undefined): string | undefined;
@@ -0,0 +1,34 @@
1
+ import { type CoordTypeSupplier } from '../map/lat-lng';
2
+ import type { Place } from '../map/map/extra/places-service';
3
+ /**
4
+ * Google地图官方提供的载入方式, 使用{@link google.map.importLibrary}动态载入依赖
5
+ *
6
+ * 实验性的特性, 实测当前只有`3.52`版支持
7
+ *
8
+ * @see https://developers.google.com/maps/documentation/javascript/load-maps-js-api#dynamic-library-import
9
+ */
10
+ export declare function initGoogleMapDynamicLibraryImport(args: {
11
+ key: string;
12
+ v?: string;
13
+ }): void;
14
+ export declare const GoogleConst: {
15
+ /** Google的坐标0点 */
16
+ readonly LATLNG_ZERO: google.maps.LatLng;
17
+ readonly BOUNDS_ZERO: google.maps.LatLngBounds;
18
+ };
19
+ export interface AddressFields {
20
+ /** 国家 */
21
+ country: string;
22
+ /** 省 */
23
+ province: string;
24
+ /** 市 */
25
+ city: string;
26
+ /** 区 */
27
+ district: string;
28
+ /** 街道 */
29
+ street: string;
30
+ /** 门牌号 */
31
+ streetNumber: string;
32
+ }
33
+ export declare function parseGoogleAddressComponents(addressComponents: google.maps.GeocoderAddressComponent[], outResult?: AddressFields): AddressFields;
34
+ export declare function parseGooglePlace(place: google.maps.places.PlaceResult, coordTypeSupplier: CoordTypeSupplier): Place;
@@ -0,0 +1,10 @@
1
+ /**
2
+ * 最新是3.1版, 但@types/heremaps和以前的项目都用的是3.0版, 故当前先用3.0...
3
+ * TODO: 改成使用3.1版实现
4
+ **/
5
+ export declare const HERE_SUPPORTED_VERSIONS: readonly ["3.0"];
6
+ /**
7
+ * 当前@types/heremaps是v3.0版, 和v3.1版api有区别, 若要使用3.1版, 需要用这个方法来做到类型注解兼容...
8
+ * @see https://developer.here.com/documentation/maps/topics/migration.html
9
+ */
10
+ export declare function ensureHereV31(): void;
@@ -0,0 +1,7 @@
1
+ import type { Point } from '../map/types';
2
+ /**
3
+ * Normalizes the coords that tiles repeat across the x axis (horizontally)
4
+ * like the standard Google map tiles.
5
+ * @see https://developers-dot-devsite-v2-prod.appspot.com/maps/documentation/javascript/examples/maptype-image
6
+ */
7
+ export declare function computeNormalizedTileCoord(tileCoord: Point, zoom: number): Point | null;
@@ -0,0 +1,110 @@
1
+ /** deep版的 `Partial` */
2
+ export type DeepPartial<T> = {
3
+ [U in keyof T]?: T[U] extends object ? DeepPartial<T[U]> : T[U];
4
+ };
5
+ /** 表示一个函数 */
6
+ export type AnyFunction = (...args: any[]) => any;
7
+ /**
8
+ * 表示一个构造器
9
+ * {@link import('vue/types/options').Constructor}
10
+ * */
11
+ export type Constructor<T = {}> = new (...args: any[]) => T;
12
+ /**
13
+ * 抽象构造器类型, 相比{@link Constructor}, 不能直接用new创建对象
14
+ * @see https://www.typescriptlang.org/docs/handbook/release-notes/typescript-4-2.html#abstract-construct-signatures
15
+ */
16
+ export type AbstractConstructor<T = {}> = abstract new (...args: any[]) => T;
17
+ /** 原始类型=>包装类型 */
18
+ export type PrimitiveToWrapper<T> = T extends boolean ? boolean : T extends string ? string : T extends number ? number : T;
19
+ /** 包装类型=>原始类型 */
20
+ export type WrapperToPrimitive<T> = T extends boolean ? boolean : T extends string ? string : T extends number ? number : T;
21
+ /**
22
+ * 扩展Record字面量的key的范围为string, 避免用string作为key读取内容时报类型错误的问题
23
+ *
24
+ * ```
25
+ * const r1 = {a: 'a'} // 类型: {a: string}
26
+ * const v1 = r1['b'] // 类型错误
27
+ * const r2 = typedRecord({a: 'a'}) // 类型: {a: string} & Record<string, string | undefined>
28
+ * const v2 = r2['b'] // 类型: string | undefined
29
+ * ```
30
+ * */
31
+ export declare function typedRecord<T extends Record<string, any>>(t: T): T & Record<string, T[keyof T] | undefined>;
32
+ /**
33
+ * `vue instanceof VueConstructor`时`vue`并不会自动转换成`VueConstructor`的子类, 用该方法可以实现这种转换
34
+ */
35
+ export declare function isInstanceOf<T>(obj: any, constructor: Constructor<T>): obj is T;
36
+ /** @see isInstanceOf */
37
+ export declare function safeAs<T>(obj: any, constructor: Constructor<T>): T | undefined;
38
+ /**
39
+ * 将可空类型, 强转成非空类型
40
+ *
41
+ * 相比`value!`, 若value不是可空类型, 会报类型错误
42
+ *
43
+ * @deprecated 和`value!`对比没有明显优势, 留在这里, 主要用来演示TsTypeError的使用...
44
+ * */
45
+ export declare function asNonNull<T>(value: T): null extends T ? T & {} : undefined extends T ? T & {} : TsTypeError<'value需要是可空类型'>;
46
+ /** {@link NonNullable} 的反义词 */
47
+ export type Nullable<T> = T | null | undefined;
48
+ /** T的所有value的联合类型 */
49
+ export type ValueOf<T> = T[keyof T];
50
+ /**
51
+ * 提取出T中value为V的子类的所有key
52
+ * @see https://stackoverflow.com/questions/54520676/in-typescript-how-to-specify-only-keys-of-a-generic-object-whose-values-are-stri
53
+ * */
54
+ export type KeysMatching<T, V> = {
55
+ [K in keyof T]: T[K] extends V ? K : never;
56
+ }[keyof T];
57
+ /**
58
+ * 并不存在可以精确表示一个枚举类型, 该类只能近似表示一个字符枚举
59
+ * */
60
+ export type StringEnumLike = {
61
+ [k: string]: string;
62
+ };
63
+ /**
64
+ * String枚举的值, 包括`string`类型
65
+ * @see https://stackoverflow.com/questions/52393730/typescript-string-literal-union-type-from-enum
66
+ */
67
+ export type StringEnumValue<E extends StringEnumLike> = ValueOf<E> | `${ValueOf<E>}`;
68
+ /**
69
+ * 包装`T`中的部分枚举字段的值为{@link StringEnumValue}
70
+ *
71
+ * 会校验{@link EnumObjects}中的类型是否书写正确, 若写错, 会推断成`never`
72
+ * */
73
+ export type WrapStringEnumValue<T, EnumObjects extends {
74
+ [k in keyof T]?: StringEnumLike;
75
+ }> = {
76
+ [P in keyof T]: P extends keyof EnumObjects ? EnumObjects[P] extends StringEnumLike ? T[P] extends ValueOf<EnumObjects[P]> | undefined ? StringEnumValue<EnumObjects[P]> : never : never : T[P];
77
+ };
78
+ /** 取消包装`T`中的{@link StringEnumValue}字段 */
79
+ export declare function unwrapStringEnumValue<T extends object>(value: T): {
80
+ [K in keyof T]: T[K] extends StringEnumValue<infer Enum> ? StringEnumLike extends Enum ? T[K] : Enum[keyof Enum] : Exclude<T[K], undefined> extends StringEnumValue<infer Enum> ? StringEnumLike extends Enum ? T[K] : Enum[keyof Enum] | undefined : T[K];
81
+ };
82
+ export declare function unwrapStringEnumValue<E extends StringEnumLike>(value: StringEnumValue<E>, enumObject?: E): E[keyof E];
83
+ export declare function unwrapStringEnumValue<E extends StringEnumLike>(value: StringEnumValue<E> | undefined, enumObject?: E): E[keyof E] | undefined;
84
+ /**
85
+ * 非空的值
86
+ *
87
+ * 类型`{}`也表示"任何非空的值", 但由于它看起来像空对象, 所以一般更推荐用Thing
88
+ *
89
+ * @see https://github.com/microsoft/TypeScript/issues/7648#issuecomment-541625573
90
+ * @see https://github.com/typescript-eslint/typescript-eslint/issues/2063#issuecomment-675156492
91
+ */
92
+ export type Thing = string | number | boolean | bigint | object | symbol;
93
+ /**
94
+ * 空对象, 对象里面不能有任何属性
95
+ * @see Thing
96
+ * @see https://github.com/typescript-eslint/typescript-eslint/issues/2063#issuecomment-675156492
97
+ */
98
+ export type EmptyObject = Record<string, never>;
99
+ /** 除T指定的类型外, 其他参数 */
100
+ export type TypedAny<T> = T & {
101
+ [k: string]: any;
102
+ };
103
+ declare const _message: unique symbol;
104
+ /**
105
+ * TS层级的编译时类型错误
106
+ */
107
+ export type TsTypeError<Message> = {
108
+ [_message]: Message;
109
+ };
110
+ export {};
@@ -0,0 +1,2 @@
1
+ export * as PolyUtil from './poly-util';
2
+ export * as SphericalUtil from './spherical-util';
@@ -0,0 +1,59 @@
1
+ /**
2
+ * The earth's radius, in meters.
3
+ * Mean radius as defined by IUGG.
4
+ */
5
+ export declare const EARTH_RADIUS = 6371009;
6
+ /**
7
+ * Restrict x to the range [low, high].
8
+ */
9
+ export declare function clamp(x: number, low: number, high: number): number;
10
+ /**
11
+ * Wraps the given value into the inclusive-exclusive interval between min and max.
12
+ *
13
+ * @param n The value to wrap.
14
+ * @param min The minimum.
15
+ * @param max The maximum.
16
+ */
17
+ export declare function wrap(n: number, min: number, max: number): number;
18
+ /**
19
+ * Returns the non-negative remainder of x / m.
20
+ *
21
+ * @param x The operand.
22
+ * @param m The modulus.
23
+ */
24
+ export declare function mod(x: number, m: number): number;
25
+ /**
26
+ * Returns mercator Y corresponding to latitude.
27
+ * See http://en.wikipedia.org/wiki/Mercator_projection .
28
+ */
29
+ export declare function mercator(lat: number): number;
30
+ /**
31
+ * Returns latitude from mercator Y.
32
+ */
33
+ export declare function inverseMercator(y: number): number;
34
+ /**
35
+ * Returns haversine(angle-in-radians).
36
+ * hav(x) == (1 - cos(x)) / 2 == sin(x / 2)^2.
37
+ */
38
+ export declare function hav(x: number): number;
39
+ /**
40
+ * Computes inverse haversine. Has good numerical stability around 0.
41
+ * arcHav(x) == acos(1 - 2 * x) == 2 * asin(sqrt(x)).
42
+ * The argument must be in [0, 1], and the result is positive.
43
+ */
44
+ export declare function arcHav(x: number): number;
45
+ export declare function sinFromHav(h: number): number;
46
+ export declare function havFromSin(x: number): number;
47
+ export declare function sinSumFromHav(x: number, y: number): number;
48
+ /**
49
+ * Returns hav() of distance from (lat1, lng1) to (lat2, lng2) on the unit sphere.
50
+ */
51
+ export declare function havDistance(lat1: number, lat2: number, dLng: number): number;
52
+ /**
53
+ * Converts degrees to radians.
54
+ */
55
+ export declare function toRadians(degrees: number): number;
56
+ /**
57
+ * Converts radians to degrees.
58
+ */
59
+ export declare function toDegrees(radians: number): number;
@@ -0,0 +1,103 @@
1
+ import type { LatLngLiteral } from '../../map/lat-lng';
2
+ export declare function containsLocation(point: LatLngLiteral, polygon: LatLngLiteral[], geodesic: boolean): boolean;
3
+ /**
4
+ * Computes whether the given point lies inside the specified polygon.
5
+ * The polygon is always considered closed, regardless of whether the last point equals
6
+ * the first or not.
7
+ * Inside is defined as not containing the South Pole -- the South Pole is always outside.
8
+ * The polygon is formed of great circle segments if geodesic is true, and of rhumb
9
+ * (loxodromic) segments otherwise.
10
+ */
11
+ export declare function containsLocationLatLng(latitude: number, longitude: number, polygon: LatLngLiteral[], geodesic: boolean): boolean;
12
+ /**
13
+ * Computes whether the given point lies on or near the edge of a polygon, within a specified
14
+ * tolerance in meters. The polygon edge is composed of great circle segments if geodesic
15
+ * is true, and of Rhumb segments otherwise. The polygon edge is implicitly closed -- the
16
+ * closing segment between the first point and the last point is included.
17
+ */
18
+ export declare function isLocationOnEdge(point: LatLngLiteral, polygon: LatLngLiteral[], geodesic?: boolean, tolerance?: number): boolean;
19
+ /**
20
+ * Computes whether the given point lies on or near a polyline, within a specified
21
+ * tolerance in meters. The polyline is composed of great circle segments if geodesic
22
+ * is true, and of Rhumb segments otherwise. The polyline is not closed -- the closing
23
+ * segment between the first point and the last point is not included.
24
+ */
25
+ export declare function isLocationOnPath(point: LatLngLiteral, polyline: LatLngLiteral[], geodesic?: boolean, tolerance?: number): boolean;
26
+ /**
27
+ * Computes whether (and where) a given point lies on or near a polyline, within a specified tolerance.
28
+ * The polyline is not closed -- the closing segment between the first point and the last point is not included.
29
+ *
30
+ * @param point our needle
31
+ * @param poly our haystack
32
+ * @param geodesic the polyline is composed of great circle segments if geodesic
33
+ * is true, and of Rhumb segments otherwise
34
+ * @param tolerance tolerance (in meters)
35
+ * @return -1 if point does not lie on or near the polyline.
36
+ * 0 if point is between poly[0] and poly[1] (inclusive),
37
+ * 1 if between poly[1] and poly[2],
38
+ * ...,
39
+ * poly.length-2 if between poly[poly.length - 2] and poly[poly.length - 1]
40
+ */
41
+ export declare function locationIndexOnPath(point: LatLngLiteral, poly: LatLngLiteral[], geodesic: boolean, tolerance?: number): number;
42
+ /**
43
+ * Computes whether (and where) a given point lies on or near a polyline, within a specified tolerance.
44
+ * If closed, the closing segment between the last and first points of the polyline is not considered.
45
+ *
46
+ * @param point our needle
47
+ * @param poly our haystack
48
+ * @param closed whether the polyline should be considered closed by a segment connecting the last point back to the first one
49
+ * @param geodesic the polyline is composed of great circle segments if geodesic
50
+ * is true, and of Rhumb segments otherwise
51
+ * @param toleranceEarth tolerance (in meters)
52
+ * @return -1 if point does not lie on or near the polyline.
53
+ * 0 if point is between poly[0] and poly[1] (inclusive),
54
+ * 1 if between poly[1] and poly[2],
55
+ * ...,
56
+ * poly.length-2 if between poly[poly.length - 2] and poly[poly.length - 1]
57
+ */
58
+ export declare function locationIndexOnEdgeOrPath(point: LatLngLiteral, poly: LatLngLiteral[], closed: boolean, geodesic: boolean, toleranceEarth: number): number;
59
+ /**
60
+ * Simplifies the given poly (polyline or polygon) using the Douglas-Peucker decimation
61
+ * algorithm. Increasing the tolerance will result in fewer points in the simplified polyline
62
+ * or polygon.
63
+ *
64
+ * When the providing a polygon as input, the first and last point of the list MUST have the
65
+ * same latitude and longitude (i.e., the polygon must be closed). If the input polygon is not
66
+ * closed, the resulting polygon may not be fully simplified.
67
+ *
68
+ * The time complexity of Douglas-Peucker is O(n^2), so take care that you do not call this
69
+ * algorithm too frequently in your code.
70
+ *
71
+ * @param poly polyline or polygon to be simplified. Polygon should be closed (i.e.,
72
+ * first and last points should have the same latitude and longitude).
73
+ * @param tolerance in meters. Increasing the tolerance will result in fewer points in the
74
+ * simplified poly.
75
+ * @return a simplified poly produced by the Douglas-Peucker algorithm
76
+ */
77
+ export declare function simplify(poly: LatLngLiteral[], tolerance: number): LatLngLiteral[];
78
+ /**
79
+ * Returns true if the provided list of points is a closed polygon (i.e., the first and last
80
+ * points are the same), and false if it is not
81
+ *
82
+ * @param poly polyline or polygon
83
+ * @return true if the provided list of points is a closed polygon (i.e., the first and last
84
+ * points are the same), and false if it is not
85
+ */
86
+ export declare function isClosedPolygon(poly: LatLngLiteral[]): boolean;
87
+ /**
88
+ * Computes the distance on the sphere between the point p and the line segment start to end.
89
+ *
90
+ * @param p the point to be measured
91
+ * @param start the beginning of the line segment
92
+ * @param end the end of the line segment
93
+ * @return the distance in meters (assuming spherical earth)
94
+ */
95
+ export declare function distanceToLine(p: LatLngLiteral, start: LatLngLiteral, end: LatLngLiteral): number;
96
+ /**
97
+ * Decodes an encoded path string into a sequence of LatLngs.
98
+ */
99
+ export declare function decode(encodedPath: string): LatLngLiteral[];
100
+ /**
101
+ * Encodes a sequence of LatLngs into an encoded path string.
102
+ */
103
+ export declare function encode(path: LatLngLiteral[]): string;