From 8d0a6d8bbc1beac9d935e438a41c880b201272bf Mon Sep 17 00:00:00 2001 From: breeze9527 Date: Sat, 23 Feb 2019 21:39:43 +0800 Subject: [PATCH 1/6] Adding types for amap-js-api --- types/amap-js-api/array-bounds.d.ts | 10 + types/amap-js-api/bounds.d.ts | 12 + types/amap-js-api/browser.d.ts | 51 +++ types/amap-js-api/common.d.ts | 22 ++ types/amap-js-api/convert-from.d.ts | 15 + types/amap-js-api/dom-util.d.ts | 31 ++ types/amap-js-api/event.d.ts | 59 +++ types/amap-js-api/geometry-util.d.ts | 122 +++++++ types/amap-js-api/index.d.ts | 48 +++ types/amap-js-api/layer/building.d.ts | 30 ++ types/amap-js-api/layer/flexible.d.ts | 20 ++ types/amap-js-api/layer/layer.d.ts | 20 ++ types/amap-js-api/layer/layerGroup.d.ts | 21 ++ types/amap-js-api/layer/massMarks.d.ts | 47 +++ types/amap-js-api/layer/mediaLayer.d.ts | 35 ++ types/amap-js-api/layer/tileLayer.d.ts | 37 ++ types/amap-js-api/layer/wms.d.ts | 29 ++ types/amap-js-api/layer/wmts.d.ts | 25 ++ types/amap-js-api/lngLat.d.ts | 17 + types/amap-js-api/map.d.ts | 187 ++++++++++ types/amap-js-api/overlay/bezierCurve.d.ts | 22 ++ types/amap-js-api/overlay/circle.d.ts | 49 +++ types/amap-js-api/overlay/circleMarker.d.ts | 4 + types/amap-js-api/overlay/contextMenu.d.ts | 23 ++ types/amap-js-api/overlay/ellipse.d.ts | 27 ++ types/amap-js-api/overlay/geoJSON.d.ts | 43 +++ types/amap-js-api/overlay/icon.d.ts | 16 + types/amap-js-api/overlay/infoWindow.d.ts | 37 ++ types/amap-js-api/overlay/marker.d.ts | 103 ++++++ types/amap-js-api/overlay/markerShape.d.ts | 21 ++ types/amap-js-api/overlay/overlay.d.ts | 37 ++ types/amap-js-api/overlay/overlayGroup.d.ts | 30 ++ types/amap-js-api/overlay/pathOverlay.d.ts | 20 ++ types/amap-js-api/overlay/polygon.d.ts | 32 ++ types/amap-js-api/overlay/polyline.d.ts | 46 +++ types/amap-js-api/overlay/rectangle.d.ts | 21 ++ types/amap-js-api/overlay/shapeOverlay.d.ts | 30 ++ types/amap-js-api/overlay/text.d.ts | 19 + types/amap-js-api/pixel.d.ts | 17 + types/amap-js-api/size.d.ts | 10 + types/amap-js-api/test/arryBounds.ts | 18 + types/amap-js-api/test/bounds.ts | 30 ++ types/amap-js-api/test/browser.ts | 141 ++++++++ types/amap-js-api/test/convert-from.ts | 25 ++ types/amap-js-api/test/dom-util.ts | 47 +++ types/amap-js-api/test/event.ts | 75 ++++ types/amap-js-api/test/geometry-util.ts | 158 ++++++++ types/amap-js-api/test/layer/buildings.ts | 40 +++ types/amap-js-api/test/layer/canvasLayer.ts | 53 +++ types/amap-js-api/test/layer/flexible.ts | 54 +++ types/amap-js-api/test/layer/imageLayer.ts | 51 +++ types/amap-js-api/test/layer/layer.ts | 34 ++ types/amap-js-api/test/layer/layerGroup.ts | 115 ++++++ types/amap-js-api/test/layer/massMarks.ts | 83 +++++ types/amap-js-api/test/layer/tileLayer.ts | 60 ++++ types/amap-js-api/test/layer/videoLayer.ts | 51 +++ types/amap-js-api/test/layer/wms.ts | 89 +++++ types/amap-js-api/test/layer/wmts.ts | 69 ++++ types/amap-js-api/test/lnglat.ts | 48 +++ types/amap-js-api/test/map.ts | 338 ++++++++++++++++++ types/amap-js-api/test/overlay/bezierCurve.ts | 155 ++++++++ types/amap-js-api/test/overlay/circle.ts | 150 ++++++++ types/amap-js-api/test/overlay/contextMenu.ts | 48 +++ types/amap-js-api/test/overlay/ellipse.ts | 117 ++++++ types/amap-js-api/test/overlay/geoJSON.ts | 106 ++++++ types/amap-js-api/test/overlay/icon.ts | 32 ++ types/amap-js-api/test/overlay/infoWindow.ts | 81 +++++ types/amap-js-api/test/overlay/marker.ts | 195 ++++++++++ types/amap-js-api/test/overlay/markerShape.ts | 26 ++ types/amap-js-api/test/overlay/overlay.ts | 27 ++ .../amap-js-api/test/overlay/overlayGroup.ts | 108 ++++++ types/amap-js-api/test/overlay/polygon.ts | 123 +++++++ types/amap-js-api/test/overlay/polyline.ts | 139 +++++++ types/amap-js-api/test/overlay/rectangle.ts | 121 +++++++ types/amap-js-api/test/overlay/text.ts | 169 +++++++++ types/amap-js-api/test/pixel.ts | 42 +++ types/amap-js-api/test/preset.ts | 29 ++ types/amap-js-api/test/size.ts | 16 + types/amap-js-api/test/util.ts | 79 ++++ types/amap-js-api/test/view2d.ts | 22 ++ types/amap-js-api/tsconfig.json | 20 ++ types/amap-js-api/tslint.json | 10 + types/amap-js-api/type-util.d.ts | 12 + types/amap-js-api/util.d.ts | 37 ++ types/amap-js-api/view2D.d.ts | 13 + 85 files changed, 4901 insertions(+) create mode 100644 types/amap-js-api/array-bounds.d.ts create mode 100644 types/amap-js-api/bounds.d.ts create mode 100644 types/amap-js-api/browser.d.ts create mode 100644 types/amap-js-api/common.d.ts create mode 100644 types/amap-js-api/convert-from.d.ts create mode 100644 types/amap-js-api/dom-util.d.ts create mode 100644 types/amap-js-api/event.d.ts create mode 100644 types/amap-js-api/geometry-util.d.ts create mode 100644 types/amap-js-api/index.d.ts create mode 100644 types/amap-js-api/layer/building.d.ts create mode 100644 types/amap-js-api/layer/flexible.d.ts create mode 100644 types/amap-js-api/layer/layer.d.ts create mode 100644 types/amap-js-api/layer/layerGroup.d.ts create mode 100644 types/amap-js-api/layer/massMarks.d.ts create mode 100644 types/amap-js-api/layer/mediaLayer.d.ts create mode 100644 types/amap-js-api/layer/tileLayer.d.ts create mode 100644 types/amap-js-api/layer/wms.d.ts create mode 100644 types/amap-js-api/layer/wmts.d.ts create mode 100644 types/amap-js-api/lngLat.d.ts create mode 100644 types/amap-js-api/map.d.ts create mode 100644 types/amap-js-api/overlay/bezierCurve.d.ts create mode 100644 types/amap-js-api/overlay/circle.d.ts create mode 100644 types/amap-js-api/overlay/circleMarker.d.ts create mode 100644 types/amap-js-api/overlay/contextMenu.d.ts create mode 100644 types/amap-js-api/overlay/ellipse.d.ts create mode 100644 types/amap-js-api/overlay/geoJSON.d.ts create mode 100644 types/amap-js-api/overlay/icon.d.ts create mode 100644 types/amap-js-api/overlay/infoWindow.d.ts create mode 100644 types/amap-js-api/overlay/marker.d.ts create mode 100644 types/amap-js-api/overlay/markerShape.d.ts create mode 100644 types/amap-js-api/overlay/overlay.d.ts create mode 100644 types/amap-js-api/overlay/overlayGroup.d.ts create mode 100644 types/amap-js-api/overlay/pathOverlay.d.ts create mode 100644 types/amap-js-api/overlay/polygon.d.ts create mode 100644 types/amap-js-api/overlay/polyline.d.ts create mode 100644 types/amap-js-api/overlay/rectangle.d.ts create mode 100644 types/amap-js-api/overlay/shapeOverlay.d.ts create mode 100644 types/amap-js-api/overlay/text.d.ts create mode 100644 types/amap-js-api/pixel.d.ts create mode 100644 types/amap-js-api/size.d.ts create mode 100644 types/amap-js-api/test/arryBounds.ts create mode 100644 types/amap-js-api/test/bounds.ts create mode 100644 types/amap-js-api/test/browser.ts create mode 100644 types/amap-js-api/test/convert-from.ts create mode 100644 types/amap-js-api/test/dom-util.ts create mode 100644 types/amap-js-api/test/event.ts create mode 100644 types/amap-js-api/test/geometry-util.ts create mode 100644 types/amap-js-api/test/layer/buildings.ts create mode 100644 types/amap-js-api/test/layer/canvasLayer.ts create mode 100644 types/amap-js-api/test/layer/flexible.ts create mode 100644 types/amap-js-api/test/layer/imageLayer.ts create mode 100644 types/amap-js-api/test/layer/layer.ts create mode 100644 types/amap-js-api/test/layer/layerGroup.ts create mode 100644 types/amap-js-api/test/layer/massMarks.ts create mode 100644 types/amap-js-api/test/layer/tileLayer.ts create mode 100644 types/amap-js-api/test/layer/videoLayer.ts create mode 100644 types/amap-js-api/test/layer/wms.ts create mode 100644 types/amap-js-api/test/layer/wmts.ts create mode 100644 types/amap-js-api/test/lnglat.ts create mode 100644 types/amap-js-api/test/map.ts create mode 100644 types/amap-js-api/test/overlay/bezierCurve.ts create mode 100644 types/amap-js-api/test/overlay/circle.ts create mode 100644 types/amap-js-api/test/overlay/contextMenu.ts create mode 100644 types/amap-js-api/test/overlay/ellipse.ts create mode 100644 types/amap-js-api/test/overlay/geoJSON.ts create mode 100644 types/amap-js-api/test/overlay/icon.ts create mode 100644 types/amap-js-api/test/overlay/infoWindow.ts create mode 100644 types/amap-js-api/test/overlay/marker.ts create mode 100644 types/amap-js-api/test/overlay/markerShape.ts create mode 100644 types/amap-js-api/test/overlay/overlay.ts create mode 100644 types/amap-js-api/test/overlay/overlayGroup.ts create mode 100644 types/amap-js-api/test/overlay/polygon.ts create mode 100644 types/amap-js-api/test/overlay/polyline.ts create mode 100644 types/amap-js-api/test/overlay/rectangle.ts create mode 100644 types/amap-js-api/test/overlay/text.ts create mode 100644 types/amap-js-api/test/pixel.ts create mode 100644 types/amap-js-api/test/preset.ts create mode 100644 types/amap-js-api/test/size.ts create mode 100644 types/amap-js-api/test/util.ts create mode 100644 types/amap-js-api/test/view2d.ts create mode 100644 types/amap-js-api/tsconfig.json create mode 100644 types/amap-js-api/tslint.json create mode 100644 types/amap-js-api/type-util.d.ts create mode 100644 types/amap-js-api/util.d.ts create mode 100644 types/amap-js-api/view2D.d.ts diff --git a/types/amap-js-api/array-bounds.d.ts b/types/amap-js-api/array-bounds.d.ts new file mode 100644 index 0000000000..419d8e4b1d --- /dev/null +++ b/types/amap-js-api/array-bounds.d.ts @@ -0,0 +1,10 @@ +declare namespace AMap { + class ArrayBounds { + constructor(bounds: LocationValue[]); + bounds: LngLat[]; + contains(point: LocationValue): boolean; + // internal + toBounds(): Bounds; + getCenter(): LngLat; + } +} diff --git a/types/amap-js-api/bounds.d.ts b/types/amap-js-api/bounds.d.ts new file mode 100644 index 0000000000..63e880fe65 --- /dev/null +++ b/types/amap-js-api/bounds.d.ts @@ -0,0 +1,12 @@ +declare namespace AMap { + class Bounds { + constructor(southWest: LngLat, northEast: LngLat); + contains(point: LocationValue): boolean; + getCenter(): LngLat; + getSouthWest(): LngLat; + getSouthEast(): LngLat; + getNorthEast(): LngLat; + getNorthWest(): LngLat; + toString(): string; + } +} diff --git a/types/amap-js-api/browser.d.ts b/types/amap-js-api/browser.d.ts new file mode 100644 index 0000000000..71bfaa8fea --- /dev/null +++ b/types/amap-js-api/browser.d.ts @@ -0,0 +1,51 @@ +declare namespace AMap { + namespace Browser { + const ua: string; + const mobile: boolean; + const plat: 'android' | 'ios' | 'windows' | 'mac' | 'other'; + const mac: boolean; + const windows: boolean; + const ios: boolean; + const iPad: boolean; + const iPhone: boolean; + const android: boolean; + const android23: boolean; + const chrome: boolean; + const firefox: boolean; + const safari: boolean; + const wechat: boolean; + const uc: boolean; + const qq: boolean; + const ie: boolean; + const ie6: boolean; + const ie7: boolean; + const ie8: boolean; + const ie9: boolean; + const ie10: boolean; + const ie11: boolean; + const edge: boolean; + const ielt9: boolean; + const baidu: boolean; + const isLocalStorage: boolean; + const isGeolocation: boolean; + const mobileWebkit: boolean; + const mobileWebkit3d: boolean; + const mobileOpera: boolean; + const retina: boolean; + const touch: boolean; + const msPointer: boolean; + const pointer: boolean; + const webkit: boolean; + const ie3d: boolean; + const webkit3d: boolean; + const gecko3d: boolean; + const opera3d: boolean; + const any3d: boolean; + const isCanvas: boolean; + const isSvg: boolean; + const isVML: boolean; + const isWorker: boolean; + const isWebsocket: boolean; + function isWebGL(): boolean; + } +} diff --git a/types/amap-js-api/common.d.ts b/types/amap-js-api/common.d.ts new file mode 100644 index 0000000000..3d51dc719e --- /dev/null +++ b/types/amap-js-api/common.d.ts @@ -0,0 +1,22 @@ +declare namespace AMap { + type SizeValue = Size | [number, number]; + type LocationValue = LngLat | [number, number]; + type Lang = 'zh_cn' | 'en' | 'zh_en'; + + type Event = { type: N } & + (V extends HTMLElement ? { value: V } + : V extends object ? V + : V extends undefined ? {} + : { value: V }); + type MapsEvent = Event; + + type StrokeLineJoin = 'miter' | 'round' | 'bevel'; + type StrokeLineCap = 'butt' | 'round' | 'square'; + type StrokeStyle = 'dashed' | 'solid'; + + type AnimationName = 'AMAP_ANIMATION_NONE' | 'AMAP_ANIMATION_DROP' | 'AMAP_ANIMATION_BOUNCE'; +} diff --git a/types/amap-js-api/convert-from.d.ts b/types/amap-js-api/convert-from.d.ts new file mode 100644 index 0000000000..9fe1f1e76d --- /dev/null +++ b/types/amap-js-api/convert-from.d.ts @@ -0,0 +1,15 @@ +declare namespace AMap { + namespace convertFrom { + interface Result { + info: string; // 'ok' + locations: LngLat[]; + } + type Type = 'gps' | 'baidu' | 'mapbar'; + type SearchStatus = 'complete' | 'error'; + } + function convertFrom( + lnglat: LocationValue | LocationValue[], + type: convertFrom.Type | null, + callback: (status: convertFrom.SearchStatus, result: string | convertFrom.Result) => void + ): void; +} diff --git a/types/amap-js-api/dom-util.d.ts b/types/amap-js-api/dom-util.d.ts new file mode 100644 index 0000000000..d83a2ca69a --- /dev/null +++ b/types/amap-js-api/dom-util.d.ts @@ -0,0 +1,31 @@ +declare namespace AMap { + namespace DomUtil { + function getViewport(dom: HTMLElement): Size; + + function getViewportOffset(dom: HTMLElement): Pixel; + + function create( + tagName: K, + parent?: HTMLElement, + className?: string + ): HTMLElementTagNameMap[K]; + + function setClass(dom: HTMLElement, className?: string): void; + + function hasClass(dom: HTMLElement, className: string): boolean; + + function addClass(dom: HTMLElement, className: string): void; + + function removeClass(dom: HTMLElement, className: string): void; + + function setOpacity(dom: HTMLElement, opacity: number): void; + + function rotate(dom: HTMLElement, deg: number, origin?: { x: number, y: number }): void; + + function setCss(dom: HTMLElement | HTMLElement[], style: Partial): typeof DomUtil; // this + + function empty(dom: HTMLElement): void; + + function remove(dom: HTMLElement): void; + } +} diff --git a/types/amap-js-api/event.d.ts b/types/amap-js-api/event.d.ts new file mode 100644 index 0000000000..d8ff5753c9 --- /dev/null +++ b/types/amap-js-api/event.d.ts @@ -0,0 +1,59 @@ +declare namespace AMap { + abstract class EventEmitter { + on( + eventName: string, + // tslint:disable-next-line:no-unnecessary-generics + handler: (this: C, event: E) => void, + context?: C, + once?: boolean, + unshift?: boolean + ): this; + + off( + eventName: string, + // tslint:disable-next-line + handler: ((this: C, event: E) => void) | 'mv', + context?: C + ): this; + + emit(eventName: string, data?: any): this; + } + + namespace event { + interface EventListener { + type: T; + } + + function addDomListener( + // tslint:disable-next-line: no-unnecessary-generics + instance: HTMLElementTagNameMap[N], + eventName: E, + handler: (this: C, event: HTMLElementEventMap[E]) => void, + context?: C + ): EventListener<0>; + + function addListener( + // tslint:disable-next-line: no-unnecessary-generics + instance: I, + eventName: string, + // tslint:disable-next-line: no-unnecessary-generics + handler: (this: C, event: E) => void, + // tslint:disable-next-line: no-unnecessary-generics + context?: C + ): EventListener<1>; + + function addListenerOnce( + // tslint:disable-next-line: no-unnecessary-generics + instance: I, + eventName: string, + // tslint:disable-next-line: no-unnecessary-generics + handler: (this: C, event: E) => void, + // tslint:disable-next-line: no-unnecessary-generics + context?: C + ): EventListener<1>; + + function removeListener(listener: EventListener<0 | 1>): void; + + function trigger(instance: EventEmitter, eventName: string, data?: any): void; + } +} diff --git a/types/amap-js-api/geometry-util.d.ts b/types/amap-js-api/geometry-util.d.ts new file mode 100644 index 0000000000..03f6800088 --- /dev/null +++ b/types/amap-js-api/geometry-util.d.ts @@ -0,0 +1,122 @@ +declare namespace AMap { + namespace GeometryUtil { + function distance( + point1: LocationValue, + point2: LocationValue | LocationValue[] + ): number; + + function ringArea(ring: LocationValue[]): number; + + function isClockwise(path: LocationValue[]): boolean; + + function distanceOfLine(line: LocationValue[]): number; + + function ringRingClip( + ring1: LocationValue[], + ring2: LocationValue[] + ): Array<[number, number]>; + + function doesRingRingIntersect( + ring1: LocationValue[], + ring2: LocationValue[] + ): boolean; + + function doesLineRingIntersect( + line: LocationValue[], + ring: LocationValue[] + ): boolean; + + function doesLineLineIntersect( + line1: LocationValue[], + line2: LocationValue[] + ): boolean; + + function doesSegmentPolygonIntersect( + point1: LocationValue, + point2: LocationValue, + polygon: LocationValue[][] + ): boolean; + + function doesSegmentRingIntersect( + point1: LocationValue, + point2: LocationValue, + ring: LocationValue[] + ): boolean; + + function doesSegmentLineIntersect( + point1: LocationValue, + point2: LocationValue, + line: LocationValue[] + ): boolean; + + function doesSegmentsIntersect( + point1: LocationValue, + point2: LocationValue, + point3: LocationValue, + point4: LocationValue + ): boolean; + + function isPointInRing(point: LocationValue, ring: LocationValue[]): boolean; + + function isRingInRing(ring1: LocationValue[], ring2: LocationValue[]): boolean; + + function isPointInPolygon(point: LocationValue, polygon: LocationValue[][]): boolean; + + function makesureClockwise(path: Array<[number, number]>): Array<[number, number]>; + + function makesureAntiClockwise(path: Array<[number, number]>): Array<[number, number]>; + + function closestOnSegment( + point1: LocationValue, + point2: LocationValue, + point3: LocationValue + ): [number, number]; + + function closestOnLine(point: LocationValue, line: LocationValue[]): [number, number]; + + function distanceToSegment( + point1: LocationValue, + point2: LocationValue, + point3: LocationValue + ): number; + + function distanceToLine(point: LocationValue, line: LocationValue[]): number; + + function isPointOnSegment( + point1: LocationValue, + point2: LocationValue, + point3: LocationValue, + tolerance?: number + ): boolean; + + function isPointOnLine( + point: LocationValue, + line: LocationValue[], + tolerance?: number + ): boolean; + + function isPointOnRing( + point: LocationValue, + ring: LocationValue[], + tolerance?: number + ): boolean; + + function isPointOnPolygon( + point: LocationValue, + polygon: LocationValue[][], + tolerance?: number + ): boolean; + + function doesPolygonPolygonIntersect( + polygon1: LocationValue[], + polygon2: LocationValue[] + ): boolean; + + function distanceToPolygon(point: LocationValue, polygon: LocationValue[]): number; + + function triangulateShape( + shape1: LngLat[] | Pixel[] | [number, number], + shape2: LngLat[] | Pixel[] | [number, number] + ): number[]; + } +} diff --git a/types/amap-js-api/index.d.ts b/types/amap-js-api/index.d.ts new file mode 100644 index 0000000000..54f79c08ea --- /dev/null +++ b/types/amap-js-api/index.d.ts @@ -0,0 +1,48 @@ +// Type definitions for non-npm package amap-js-sdk 1.4 +// Project: https://lbs.amap.com/api/javascript-api/summary +// Definitions by: breeze9527 +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.8 + +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// +/// diff --git a/types/amap-js-api/layer/building.d.ts b/types/amap-js-api/layer/building.d.ts new file mode 100644 index 0000000000..30dd7c4092 --- /dev/null +++ b/types/amap-js-api/layer/building.d.ts @@ -0,0 +1,30 @@ +declare namespace AMap { + namespace Buildings { + interface Options extends Layer.Options { + zooms?: [number, number]; + opacity?: number; + heightFactor?: number; + visible?: boolean; + zIndex?: number; + // inner + merge?: boolean; + sort?: boolean; + } + interface AreaStyle { + color1: string; + path: LocationValue[]; + color2?: string; + visible?: boolean; + rejectTexture?: boolean; + } + interface Style { + hideWithoutStyle?: boolean; + areas: AreaStyle[]; + } + } + + class Buildings extends Layer { + constructor(opts?: Buildings.Options); + setStyle(style: Buildings.Style): void; + } +} diff --git a/types/amap-js-api/layer/flexible.d.ts b/types/amap-js-api/layer/flexible.d.ts new file mode 100644 index 0000000000..bdb4001a7c --- /dev/null +++ b/types/amap-js-api/layer/flexible.d.ts @@ -0,0 +1,20 @@ +declare namespace AMap { + namespace TileLayer { + namespace Flexible { + interface Options extends TileLayer.Options { + createTile?( + x: number, + y: number, + z: number, + success: (tile: HTMLImageElement | HTMLCanvasElement) => void, + fail: () => void + ): void; + cacheSize?: number; + visible?: boolean; + } + } + class Flexible extends TileLayer { + constructor(options?: Flexible.Options); + } + } +} diff --git a/types/amap-js-api/layer/layer.d.ts b/types/amap-js-api/layer/layer.d.ts new file mode 100644 index 0000000000..8f35d949fd --- /dev/null +++ b/types/amap-js-api/layer/layer.d.ts @@ -0,0 +1,20 @@ +declare namespace AMap { + namespace Layer { + interface Options { + map?: Map; + } + } + + abstract class Layer extends EventEmitter { + getContainer(): HTMLDivElement | undefined; + getZooms(): [number, number]; + setOpacity(alpha: number): void; + getOpacity(): number; + show(): void; + hide(): void; + setMap(map?: Map | null): void; + getMap(): Map | null | undefined; + setzIndex(index: number): void; + getzIndex(): number; + } +} diff --git a/types/amap-js-api/layer/layerGroup.d.ts b/types/amap-js-api/layer/layerGroup.d.ts new file mode 100644 index 0000000000..4cc463eef7 --- /dev/null +++ b/types/amap-js-api/layer/layerGroup.d.ts @@ -0,0 +1,21 @@ +declare namespace AMap { + class LayerGroup extends Layer { + constructor(layers: L | L[]); + addLayer(layer: L | L[]): this; + addLayers(layers: L | L[]): this; + getLayers(): L[]; + getLayer(finder: (this: null, item: L, index: number, list: L[]) => boolean): L | null; + hasLayer(layer: L | ((this: null, item: L, index: number, list: L[]) => boolean)): boolean; + removeLayer(layer: L | L[]): this; + removeLayers(layer: L | L[]): this; + clearLayers(): this; + eachLayer(iterator: (this: C, layer: L, index: number, list: L[]) => void, context?: C): void; + + // overwrite + setMap(map?: Map): this; + hide(): this; + show(): this; + reload(): this; + setOptions(options: any): this; + } +} diff --git a/types/amap-js-api/layer/massMarks.d.ts b/types/amap-js-api/layer/massMarks.d.ts new file mode 100644 index 0000000000..1ab5464a5b --- /dev/null +++ b/types/amap-js-api/layer/massMarks.d.ts @@ -0,0 +1,47 @@ +declare namespace AMap { + namespace MassMarks { + interface EventMap { + click: UIEvent<'click', I>; + dblclick: UIEvent<'dblclick', I>; + mousedown: UIEvent<'mousedown', I>; + mouseup: UIEvent<'mouseup', I>; + mouseover: UIEvent<'mouseover', I>; + mouseout: UIEvent<'mouseout', I>; + touchstart: UIEvent<'touchstart', I>; + touchend: UIEvent<'touchend', I>; + } + + interface Style { + anchor: Pixel; + url: string; + size: Size; + rotation?: number; + } + + type UIEvent = Event ? D : Data; + }>; + + interface Options extends Layer.Options { + zIndex?: number; + cursor?: string; + alwayRender?: boolean; + style: Style | Style[]; + // rejectMapMask + } + interface Data { + lnglat: LocationValue; + style?: number; + } + } + + class MassMarks extends Layer { + constructor(data: D[] | string, opts: MassMarks.Options); + setStyle(style: MassMarks.Style | MassMarks.Style[]): void; + getStyle(): MassMarks.Style | MassMarks.Style[]; + setData(data: D[] | string): void; + getData(): Array> & { lnglat: LngLat }>; + clear(): void; + } +} diff --git a/types/amap-js-api/layer/mediaLayer.d.ts b/types/amap-js-api/layer/mediaLayer.d.ts new file mode 100644 index 0000000000..a38f5ba025 --- /dev/null +++ b/types/amap-js-api/layer/mediaLayer.d.ts @@ -0,0 +1,35 @@ +declare namespace AMap { + namespace MediaLayer { + interface Options extends Layer.Options { + bounds?: Bounds; + visible?: boolean; + zooms?: [number, number]; + opacity?: number; + } + } + + abstract class MediaLayer extends Layer { + constructor(options?: MediaLayer.Options); + setBounds(bounds: Bounds): void; + getBounds(): Bounds; + setOptions(options: Partial): void; + getOptions(): Partial; + getElement(): E | null; + } + + class ImageLayer extends MediaLayer { + setImageUrl(url: string): void; + getImageUrl(): string | undefined; + } + + class VideoLayer extends MediaLayer { + setVideoUrl(source: string | string[]): void; + getVideoUrl(): string | string[] | undefined; + } + + class CanvasLayer extends MediaLayer { + setCanvas(canvas: HTMLCanvasElement): void; + getCanvas(): HTMLCanvasElement | undefined; + reFresh(): void; + } +} diff --git a/types/amap-js-api/layer/tileLayer.d.ts b/types/amap-js-api/layer/tileLayer.d.ts new file mode 100644 index 0000000000..7576a70664 --- /dev/null +++ b/types/amap-js-api/layer/tileLayer.d.ts @@ -0,0 +1,37 @@ +declare namespace AMap { + namespace TileLayer { + interface EventMap { + complete: Event<'complete'>; + } + + interface Options extends Layer.Options { + tileSize?: number; + tileUrl?: string; + errorUrl?: string; + getTileUrl?: string | ((x: number, y: number, level: number) => string); + zIndex?: number; + opacity?: number; + zooms?: [number, number]; + detectRetina?: boolean; + } + class Satellite extends TileLayer { } + class RoadNet extends TileLayer { } + + namespace Traffic { + interface Options extends TileLayer.Options { + autoRefresh?: boolean; + interval?: number; + } + } + class Traffic extends TileLayer { + constructor(options?: Traffic.Options); + } + } + + class TileLayer extends Layer { + constructor(options?: TileLayer.Options); + getTiles(): string[]; + reload(): void; + setTileUrl(url: string | ((x: number, y: number, level: number) => string)): void; + } +} diff --git a/types/amap-js-api/layer/wms.d.ts b/types/amap-js-api/layer/wms.d.ts new file mode 100644 index 0000000000..c4561ddf14 --- /dev/null +++ b/types/amap-js-api/layer/wms.d.ts @@ -0,0 +1,29 @@ +declare namespace AMap { + namespace TileLayer { + namespace WMS { + interface Params { + VERSION?: string; + LAYERS?: string; + STYLES?: string; + FORMAT?: string; + TRANSPARENT?: 'TRUE' | 'FALSE'; + BGCOLOR?: string; + EXCEPTIONS?: string; + TIME?: string; + ELEVATION?: string; + } + interface Options extends Flexible.Options { + url: string; + params: Params; + blend?: boolean; + } + } + class WMS extends Flexible { + constructor(options: WMS.Options); + setUrl(url: string): void; + getUrl(): string; + setParams(params: WMS.Params): void; + getParams(): WMS.Params; + } + } +} diff --git a/types/amap-js-api/layer/wmts.d.ts b/types/amap-js-api/layer/wmts.d.ts new file mode 100644 index 0000000000..5d85e5df48 --- /dev/null +++ b/types/amap-js-api/layer/wmts.d.ts @@ -0,0 +1,25 @@ +declare namespace AMap { + namespace TileLayer { + namespace WMTS { + interface Params { + Version?: string; + Layer?: string; + Style?: string; + Format?: string; + } + interface Options extends Flexible.Options { + url: string; + params: Params; + blend?: boolean; + } + } + + class WMTS extends Flexible { + constructor(options: WMTS.Options); + setUrl(url: string): void; + getUrl(): string; + setParams(params: WMTS.Params): void; + getParams(): WMTS.Params; + } + } +} diff --git a/types/amap-js-api/lngLat.d.ts b/types/amap-js-api/lngLat.d.ts new file mode 100644 index 0000000000..4247002b2b --- /dev/null +++ b/types/amap-js-api/lngLat.d.ts @@ -0,0 +1,17 @@ +declare namespace AMap { + class LngLat { + constructor(lng: number, lat: number, noAutofix?: boolean); + offset(east: number, north: number): LngLat; + distance(lnglat: LngLat | LngLat[]): number; + getLng(): number; + getLat(): number; + equals(lnglat: LngLat): boolean; + toString(): string; + + // internal + add(lnglat: LngLat, noAutofix?: boolean): LngLat; + subtract(lnglat: LngLat, noAutofix?: boolean): LngLat; + divideBy(num: number, noAutofix?: boolean): LngLat; + multiplyBy(num: number, noAutofix?: boolean): LngLat; + } +} diff --git a/types/amap-js-api/map.d.ts b/types/amap-js-api/map.d.ts new file mode 100644 index 0000000000..46edc68577 --- /dev/null +++ b/types/amap-js-api/map.d.ts @@ -0,0 +1,187 @@ +declare namespace AMap { + namespace Map { + type Feature = 'bg' | 'point' | 'road' | 'building'; + type ViewMode = '2D' | '3D'; + interface Options { + view?: View2D; + layers?: Layer[]; + zoom?: number; + center?: LocationValue; + labelzIndex?: number; + zooms?: [number, number]; + lang?: Lang; + defaultCursor?: string; + crs?: 'EPSG3857' | 'EPSG3395' | 'EPSG4326'; + animateEnable?: boolean; + isHotspot?: boolean; + defaultLayer?: TileLayer; + rotateEnable?: boolean; + resizeEnable?: boolean; + showIndoorMap?: boolean; + expandZoomRange?: boolean; + dragEnable?: boolean; + zoomEnable?: boolean; + doubleClickZoom?: boolean; + keyboardEnable?: boolean; + jogEnable?: boolean; + scrollWheel?: boolean; + touchZoom?: boolean; + touchZoomCenter?: number; + mapStyle?: string; + features?: Feature[] | 'all' | Feature; + showBuildingBlock?: boolean; + viewMode?: ViewMode; + pitch?: number; + pitchEnable?: boolean; + buildingAnimation?: boolean; + skyColor?: string; + preloadMode?: boolean; + mask?: Array<[number, number]> | Array> | Array>>; + maxPitch?: number; + rotation?: number; + forceVector?: boolean; + + // internal + baseRender?: 'vw' | 'd' | 'dv' | 'v'; + overlayRender?: 'c' | 'd'; + showLabel?: boolean; + gridMapForeign?: boolean; + logoUrl?: string; + logoUrlRetina?: string; + copyright?: string; + turboMode?: boolean; + workerMode?: boolean; + // continuousZoomEnable?: boolean; + // showFog: boolean; + // yaw: number; + // scale: number; + // detectRetina: number; + } + interface Status { + animateEnable: boolean; + doubleClickZoom: boolean; + dragEnable: boolean; + isHotspot: boolean; + jogEnable: boolean; + keyboardEnable: boolean; + pitchEnable: boolean; + resizeEnable: boolean; + rotateEnable: boolean; + scrollWheel: boolean; + touchZoom: boolean; + zoomEnable: boolean; + } + type HotspotEvent = Event; + interface EventMap { + click: MapsEvent<'click', Map>; + dblclick: MapsEvent<'dblclick', Map>; + rightclick: MapsEvent<'rightclick', Map>; + rdblclick: MapsEvent<'rdblclick', Map>; + mouseup: MapsEvent<'mouseup', Map>; + mousedown: MapsEvent<'mousedown', Map>; + mousemove: MapsEvent<'mousemove', Map>; + mousewheel: MapsEvent<'mousewheel', Map>; + mouseover: MapsEvent<'mouseover', Map>; + mouseout: MapsEvent<'mouseout', Map>; + touchstart: MapsEvent<'touchstart', Map>; + touchmove: MapsEvent<'touchmove', Map>; + touchend: MapsEvent<'touchend', Map>; + contextmenu: MapsEvent<'contextmenu', Map>; + + hotspotclick: HotspotEvent<'hotspotclick'>; + hotspotover: HotspotEvent<'hotspotover'>; + hotspotout: HotspotEvent<'hotspotout'>; + + complete: Event<'complete'>; + mapmove: Event<'mapmove'>; + movestart: Event<'movestart'>; + moveend: Event<'moveend'>; + zoomchange: Event<'zoomchange'>; + zoomstart: Event<'zoomstart'>; + zoomend: Event<'zoomend'>; + dragstart: Event<'dragstart'>; + dragging: Event<'dragging'>; + dragend: Event<'dragend'>; + resize: Event<'resize'>; + } + } + + class Map extends EventEmitter { + constructor(container: string | HTMLElement, opts?: Map.Options); + poiOnAMAP(obj: { id: string; location?: LocationValue; name?: string }): void; + detailOnAMAP(obj: { id: string; location?: LocationValue; name?: string }): void; + getZoom(): number; + getLayers(): Layer[]; + getCenter(): LngLat; + getContainer(): HTMLElement | null; + getCity(callback: (cityData: { + city: string; + citycode: string; + district: string; + province: string | never[]; // province is empty array when getCity fail + }) => void): void; + getBounds(): Bounds; + getLabelzIndex(): number; + getLimitBounds(): Bounds; + getLang(): Lang; + getSize(): Size; + getRotation(): number; + getStatus(): Map.Status; + getDefaultCursor(): string; + getResolution(point?: LocationValue): number; + getScale(dpi?: number): number; + setZoom(level: number): void; + setLabelzIndex(index: number): void; + setLayers(layers: Layer[]): void; + add(overlay: Overlay | Overlay[]): void; + remove(overlay: Overlay | Overlay[]): void; + getAllOverlays(type?: 'marker' | 'circle' | 'polyline' | 'polygon'): Overlay[]; + setCenter(center: LocationValue): void; + setZoomAndCenter(zoomLevel: number, center: LocationValue): void; + setCity(city: string, callback: (this: this, coord: [string, string], zoom: number) => void): void; + setBounds(bound: Bounds): Bounds; + setLimitBounds(bound: Bounds): void; + clearLimitBounds(): void; + setLang(lang: Lang): void; + setRotation(rotation: number): void; + setStatus(status: Partial): void; + setDefaultCursor(cursor: string): void; + zoomIn(): void; + zoomOut(): void; + panTo(position: LocationValue): void; + panBy(x: number, y: number): void; + setFitView( + overlayList?: Overlay | Overlay[], + immediately?: boolean, + avoid?: [number, number, number, number], + maxZoom?: number + ): Bounds | false | undefined; + clearMap(): void; + destroy(): void; + plugin(name: string | string[], callback: () => void): this; + addControl(control: {}): void; // TODO + removeControl(control: {}): void; // TODO + clearInfoWindow(): void; + pixelToLngLat(pixel: Pixel, level?: number): LngLat; + lnglatToPixel(lnglat: LocationValue, level?: number): Pixel; + containerToLngLat(pixel: Pixel): LngLat; + lngLatToContainer(lnglat: LocationValue): Pixel; + lnglatTocontainer(lnglat: LocationValue): Pixel; + setMapStyle(style: string): void; + getMapStyle(): string; + setFeatures(feature: Map.Feature | Map.Feature[] | 'all'): void; + getFeatures(): Map.Feature | Map.Feature[] | 'all'; + setDefaultLayer(layer: TileLayer): void; + setPitch(pitch: number): void; + getPitch(): number; + getViewMode_(): Map.ViewMode; + lngLatToGeodeticCoord(lnglat: LocationValue): Pixel; + geodeticCoordToLngLat(pixel: Pixel): LngLat; + } +} diff --git a/types/amap-js-api/overlay/bezierCurve.d.ts b/types/amap-js-api/overlay/bezierCurve.d.ts new file mode 100644 index 0000000000..5778cb72a6 --- /dev/null +++ b/types/amap-js-api/overlay/bezierCurve.d.ts @@ -0,0 +1,22 @@ +declare namespace AMap { + namespace BezierCurve { + interface EventMap extends Polyline.EventMap { } + type Options = Merge, { + // internal + path: Array>>; + tolerance?: number; + interpolateNumLimit?: [number | number]; + }>; + + interface GetOptionsResult extends Polyline.GetOptionsResult { + path: Array; + } + } + class BezierCurve extends Polyline { + constructor(options: BezierCurve.Options); + getOptions(): Partial>; + // internal + getInterpolateLngLats(): LngLat[]; + getSerializedPath(): number[][]; + } +} diff --git a/types/amap-js-api/overlay/circle.d.ts b/types/amap-js-api/overlay/circle.d.ts new file mode 100644 index 0000000000..2a1cbd9020 --- /dev/null +++ b/types/amap-js-api/overlay/circle.d.ts @@ -0,0 +1,49 @@ +declare namespace AMap { + namespace Circle { + interface EventMap extends ShapeOverlay.EventMap { + setCenter: Event<'setCenter'>; + setRadius: Event<'setRadius'>; + } + + interface Options { + map?: Map; + zIndex?: number; + center?: LocationValue; + bubble?: boolean; + cursor?: string; + radius?: number; + strokeColor?: string; + strokeOpcity?: number; + strokeWeight?: number; + fillColor?: string; + fillOpacity?: number; + strokeStyle?: StrokeStyle; + extData?: ExtraData; + strokeDasharray?: number[]; + + // internal + visible?: boolean; + unit?: 'meter' | 'px'; // 'might be typo' + } + + type GetOptionsResult = Merge, { + path: LngLat[]; + center: LngLat; + radius: number; + }>; + } + + class Circle extends ShapeOverlay { + constructor(options?: Circle.Options); + setCenter(center: LocationValue, preventEvent?: boolean): void; + getCenter(): LngLat | undefined; + getBounds(): Bounds | null; + setRadius(radius: number, preventEvent?: boolean): void; + getRadius(): number; + setOptions(options?: Circle.Options): void; + getOptions(): Partial>; + contains(point: LocationValue): boolean; + // internal + getPath(count?: number): LngLat[]; + } +} diff --git a/types/amap-js-api/overlay/circleMarker.d.ts b/types/amap-js-api/overlay/circleMarker.d.ts new file mode 100644 index 0000000000..13e4162f46 --- /dev/null +++ b/types/amap-js-api/overlay/circleMarker.d.ts @@ -0,0 +1,4 @@ +declare namespace AMap { + // tslint:disable-next-line; + class CircleMarker extends Circle {} +} diff --git a/types/amap-js-api/overlay/contextMenu.d.ts b/types/amap-js-api/overlay/contextMenu.d.ts new file mode 100644 index 0000000000..72c7fc2852 --- /dev/null +++ b/types/amap-js-api/overlay/contextMenu.d.ts @@ -0,0 +1,23 @@ +declare namespace AMap { + namespace ContextMenu { + interface Options { + content?: string | HTMLElement; + // internal + visible?: boolean; + } + + interface EventMap { + items: Event<'items'>; + open: Event<'open', { target: I }>; + close: Event<'close', { target: I }>; + } + } + + class ContextMenu extends Overlay { + constructor(options?: ContextMenu.Options); + addItem(text: string, fn: (this: HTMLLIElement) => void, num?: number): void; + removeItem(test: string, fn: (this: HTMLLIElement) => void): void; + open(map: Map, position: LocationValue): void; + close(): void; + } +} diff --git a/types/amap-js-api/overlay/ellipse.d.ts b/types/amap-js-api/overlay/ellipse.d.ts new file mode 100644 index 0000000000..55feaf3112 --- /dev/null +++ b/types/amap-js-api/overlay/ellipse.d.ts @@ -0,0 +1,27 @@ +declare namespace AMap { + namespace Ellipse { + interface EventMap extends ShapeOverlay.EventMap { + setPath: Event<'setPath'>; + setCenter: Event<'setCenter'>; + } + + interface Options extends Polygon.Options { + center?: LocationValue; + radius?: [number, number]; + } + type GetOptionsResult = Merge, { + radius: [number, number]; + }>; + } + + class Ellipse extends Polygon { + constructor(options?: Ellipse.Options); + getCenter(): LngLat | undefined; + setCenter(center: LocationValue, preventEvent?: boolean): void; + setOptions(options: Ellipse.Options): void; + + // internal + setRadius(radius: [number, number], preventEvent?: boolean): void; + getRadius(): [number, number]; + } +} diff --git a/types/amap-js-api/overlay/geoJSON.d.ts b/types/amap-js-api/overlay/geoJSON.d.ts new file mode 100644 index 0000000000..75098a59f0 --- /dev/null +++ b/types/amap-js-api/overlay/geoJSON.d.ts @@ -0,0 +1,43 @@ +declare namespace AMap { + namespace GeoJSON { + type Geometry = { + type: 'Point'; + coordinates: [number, number]; + } | { + type: 'MultiPoint' | 'LineString' | 'Polygon'; + coordinates: Array<[number, number]>; + } | { + type: 'MultiLineString' | 'MultiPolygon'; + coordinates: Array>; + } | { + type: 'GeometryCollection'; + geometries: Geometry[]; + }; + + type GeoJSONObject = { + type: 'Feature'; + properties: any; + geometry: Geometry; + } | { + type: 'FeatureCollection', + properties: any; + features: GeoJSONObject[]; + }; + interface Options { + geoJSON?: GeoJSONObject | GeoJSONObject[]; + getMarker?(obj: GeoJSONObject, lnglat: LngLat): Marker; + getPolyline?(obj: GeoJSONObject, lnglats: LngLat[]): Polyline; + getPolygon?(obj: GeoJSONObject, lnglats: LngLat[]): Polygon; + coordsToLatLng?(lnglat: LngLat): LngLat; + + // internal + coordsToLatLngs?(lnglats: LngLat[]): LngLat[]; + } + } + + class GeoJSON extends OverlayGroup { + constructor(options?: GeoJSON.Options); + importData(obj: GeoJSON.GeoJSONObject | GeoJSON.GeoJSONObject[]): void; + toGeoJSON(): GeoJSON.GeoJSONObject[]; + } +} diff --git a/types/amap-js-api/overlay/icon.d.ts b/types/amap-js-api/overlay/icon.d.ts new file mode 100644 index 0000000000..be300feef3 --- /dev/null +++ b/types/amap-js-api/overlay/icon.d.ts @@ -0,0 +1,16 @@ +declare namespace AMap { + namespace Icon { + interface Options { + size?: SizeValue; + imageOffset?: Pixel; + image?: string; + imageSize?: SizeValue; + } + } + + class Icon extends EventEmitter { + constructor(options?: Icon.Options); + setImageSize(size: SizeValue): void; + getImageSize(): Size; + } +} diff --git a/types/amap-js-api/overlay/infoWindow.d.ts b/types/amap-js-api/overlay/infoWindow.d.ts new file mode 100644 index 0000000000..54bedd95a8 --- /dev/null +++ b/types/amap-js-api/overlay/infoWindow.d.ts @@ -0,0 +1,37 @@ +declare namespace AMap { + namespace InfoWindow { + interface EventMap { + change: Event<'change', { target: I }>; + open: Event<'open', { target: I }>; + close: Event<'close', { target: I }>; + } + + interface Options extends Overlay.Options { + isCustom?: boolean; + autoMove?: boolean; + closeWhenClickMap?: boolean; + content?: string | HTMLElement; + size?: SizeValue; + offset?: Pixel; + position?: LocationValue; + showShadow?: boolean; + // internal + height?: number; + } + } + + class InfoWindow extends Overlay { + constructor(options?: InfoWindow.Options); + open(map: Map, position?: LocationValue): void; + close(): void; + getIsOpen(): boolean; + setContent(content: string | HTMLElement): void; + getContent(): string | HTMLElement | undefined; + setPosition(lnglat: LocationValue): void; + getPosition(): LngLat | undefined; + setSize(size: SizeValue): void; + getSize(): Size | undefined; + // internal + setOffset(offset: Pixel): void; + } +} diff --git a/types/amap-js-api/overlay/marker.d.ts b/types/amap-js-api/overlay/marker.d.ts new file mode 100644 index 0000000000..e24ce7be8f --- /dev/null +++ b/types/amap-js-api/overlay/marker.d.ts @@ -0,0 +1,103 @@ +declare namespace AMap { + namespace Marker { + interface EventMap { + click: MapsEvent<'click', I>; + dblclick: MapsEvent<'dblclick', I>; + rightclick: MapsEvent<'rightclick', I>; + mousemove: MapsEvent<'mousemove', I>; + mouseover: MapsEvent<'mouseover', I>; + mouseout: MapsEvent<'mouseout', I>; + mousedown: MapsEvent<'mousedown', I>; + mouseup: MapsEvent<'mouseup', I>; + dragstart: MapsEvent<'dragstart', I>; + dragging: MapsEvent<'dragging', I>; + dragend: MapsEvent<'dragend', I>; + moving: Event<'moving', { passwdPath: LngLat[]; }>; + moveend: Event<'moveend'>; + movealong: Event<'movealong'>; + touchstart: MapsEvent<'touchstart', I>; + touchmove: MapsEvent<'touchmove', I>; + touchend: MapsEvent<'touchend', I>; + } + + interface Label { + content?: string; + offset?: Pixel; + } + + interface Options extends Overlay.Options { + position?: LocationValue; + offset?: Pixel; + icon?: string | Icon; + content?: string | HTMLElement; + topWhenClick?: boolean; + bubble?: boolean; + draggable?: boolean; + raiseOnDrag?: boolean; + cursor?: string; + visible?: boolean; + zIndex?: number; + angle?: number; + autoRotation?: boolean; + animation?: AnimationName; + shadow?: Icon | string; + title?: string; + shape?: MarkerShape; + label?: Label; + zooms?: [number, number]; + + // internal + topWhenMouseOver?: boolean; + height?: number; + } + } + + class Marker extends Overlay { + constructor(options?: Marker.Options); + markOnAMAP(obj?: { name?: string, position?: LocationValue }): void; + getOffset(): Pixel; + setOffset(offset: Pixel): void; + setAnimation(animate: AnimationName, prevent?: boolean): void; + getAnimation(): AnimationName; + setClickable(cilckable: boolean): void; + getClickable(): boolean; + getPosition(): LngLat | undefined; + setPosition(position: LocationValue): void; + setAngle(angle: number): void; + setLabel(label?: Marker.Label): void; + getLabel(): Marker.Label | undefined; + getAngle(): number; + setzIndex(index: number): void; + getzIndex(): number; + setIcon(content: string | Icon): void; + getIcon(): string | Icon | undefined; + setDraggable(draggable: boolean): void; + getDraggable(): boolean; + setCursor(cursor: string): void; + setContent(content: string | HTMLElement): void; + getContent(): string | HTMLElement; + moveAlong( + path: LngLat[], + speed: number, + timingFunction?: (t: number) => number, + circleable?: boolean + ): void; + moveTo( + path: LocationValue, + speed: number, + timingFunction?: (t: number) => number + ): void; + stopMove(): void; + pauseMove(): boolean; + resumeMove(): boolean; + setMap(map: null | Map): void; + setTitle(title: string): void; + getTitle(): string | undefined; + setTop(isTop: boolean): void; + getTop(): boolean; + setShadow(icon?: Icon | string): void; + getShadow(): Icon | undefined | string; + setShape(shape?: MarkerShape): void; + getShape(): MarkerShape | undefined; + } +} diff --git a/types/amap-js-api/overlay/markerShape.d.ts b/types/amap-js-api/overlay/markerShape.d.ts new file mode 100644 index 0000000000..c8efd93850 --- /dev/null +++ b/types/amap-js-api/overlay/markerShape.d.ts @@ -0,0 +1,21 @@ +declare namespace AMap { + namespace MarkerShape { + interface CircleOptions { + type: 'circle'; + coords: [number, number, number]; + } + interface PolyOptions { + type: 'poly'; + coords: number[]; + } + interface RectOptions { + type: 'rect'; + coords: [number, number, number, number]; + } + type Options = CircleOptions | PolyOptions | RectOptions; + } + + class MarkerShape { + constructor(options: MarkerShape.Options); + } +} diff --git a/types/amap-js-api/overlay/overlay.d.ts b/types/amap-js-api/overlay/overlay.d.ts new file mode 100644 index 0000000000..1726b39c3e --- /dev/null +++ b/types/amap-js-api/overlay/overlay.d.ts @@ -0,0 +1,37 @@ +declare namespace AMap { + namespace Overlay { + interface EventMap { + touchstart: MapsEvent<'touchstart', I>; + touchmove: MapsEvent<'touchmove', I>; + touchend: MapsEvent<'touchend', I>; + click: MapsEvent<'click', I>; + rightclick: MapsEvent<'rightclick', I>; + dblclick: MapsEvent<'dblclick', I>; + mousemove: MapsEvent<'mousemove', I>; + mouseover: MapsEvent<'mouseover', I>; + mousedown: MapsEvent<'mousedown', I>; + mouseup: MapsEvent<'mouseup', I>; + } + interface Options { + map?: Map; + cursor?: string; + extData?: ExtraData; + bubble?: boolean; + clickable?: boolean; + draggable?: boolean; + } + } + abstract class Overlay extends EventEmitter { + constructor(options?: Overlay.Options); + show(): void; + hide(): void; + getMap(): Map | null | undefined; + setMap(map: Map | null): void; + setExtData(extData: ExtraData): void; + getExtData(): ExtraData | {}; + + // internal + setHeight(height?: number | string): void; + getHeight(): number | string; + } +} diff --git a/types/amap-js-api/overlay/overlayGroup.d.ts b/types/amap-js-api/overlay/overlayGroup.d.ts new file mode 100644 index 0000000000..d397505b04 --- /dev/null +++ b/types/amap-js-api/overlay/overlayGroup.d.ts @@ -0,0 +1,30 @@ +type ReferOverlayOptions = + O extends AMap.BezierCurve ? AMap.BezierCurve.Options + : O extends AMap.Polyline ? AMap.Polyline.Options + : O extends AMap.Circle ? AMap.Circle.Options + : O extends AMap.Ellipse ? AMap.Ellipse.Options + : O extends AMap.Polygon ? AMap.Polygon.Options + : O extends AMap.Text ? AMap.Text.Options + : O extends AMap.Marker ? AMap.Marker.Options + : O extends AMap.Rectangle ? AMap.Rectangle.Options + : any; + +declare namespace AMap { + class OverlayGroup extends Overlay { + constructor(overlays?: O | O[]); + addOverlay(overlay: O | O[]): this; + addOverlays(overlay: O | O[]): this; + getOverlays(): O[]; + hasOverlay(overlay: O | ((this: null, item: O, index: number, list: O[]) => boolean)): boolean; + removeOverlay(overlay: O | O[]): this; + removeOverlays(overlay: O | O[]): this; + clearOverlays(): this; + eachOverlay(iterator: (this: C, overlay: O, index: number, overlays: O[]) => void, context?: C): this; + setMap(map: null | Map): this; + setOptions(options: ReferOverlayOptions): this; + show(): this; + hide(): this; + + getOverlay(finder: ((this: null, item: O, index: number, list: O[]) => boolean) | O): O | null; + } +} diff --git a/types/amap-js-api/overlay/pathOverlay.d.ts b/types/amap-js-api/overlay/pathOverlay.d.ts new file mode 100644 index 0000000000..de21aa35a7 --- /dev/null +++ b/types/amap-js-api/overlay/pathOverlay.d.ts @@ -0,0 +1,20 @@ +declare namespace AMap { + namespace PathOverlay { + interface EventMap extends ShapeOverlay.EventMap { } + interface Options extends Overlay.Options { + visible?: boolean; + zIndex?: number; + strokeColor?: string; + strokeOpacity?: number; + strokeWeight?: number; + strokeStyle?: StrokeStyle; + strokeDasharray?: number[]; + lineJoin?: StrokeLineJoin; + lineCap?: StrokeLineCap; + } + } + abstract class PathOverlay extends ShapeOverlay { + constructor(options?: PathOverlay.Options); + getBounds(): Bounds | (this extends Rectangle ? undefined : null); + } +} diff --git a/types/amap-js-api/overlay/polygon.d.ts b/types/amap-js-api/overlay/polygon.d.ts new file mode 100644 index 0000000000..8792e0e135 --- /dev/null +++ b/types/amap-js-api/overlay/polygon.d.ts @@ -0,0 +1,32 @@ +declare namespace AMap { + namespace Polygon { + interface EventMap extends PathOverlay.EventMap { } + interface Options extends PathOverlay.Options { + path?: LocationValue[] | LocationValue[][]; + fillColor?: string; + fillOpacity?: number; + } + + interface GetOptionsResult extends ShapeOverlay.GetOptionsResult { + fillColor: string; + fillOpacity: number; + path: LngLat[] | LngLat[][]; + lineJoin: StrokeLineJoin; + texture: string; + } + } + + class Polygon extends PathOverlay { + constructor(options?: Polygon.Options); + setPath(path: LocationValue[] | LocationValue[][]): void; + getPath(): LngLat[] | LngLat[][]; + setOptions(options: Polygon.Options): void; + getOptions(): Partial< + this extends Omit ? Ellipse.GetOptionsResult : + this extends Omit ? Rectangle.GetOptionsResult : + Polygon.GetOptionsResult + >; + getArea(): number; + contains(point: LocationValue): boolean; + } +} diff --git a/types/amap-js-api/overlay/polyline.d.ts b/types/amap-js-api/overlay/polyline.d.ts new file mode 100644 index 0000000000..207279b208 --- /dev/null +++ b/types/amap-js-api/overlay/polyline.d.ts @@ -0,0 +1,46 @@ +declare namespace AMap { + namespace Polyline { + interface EventMap extends PathOverlay.EventMap { } + interface GetOptionsResult extends ShapeOverlay.GetOptionsResult { + isOutline: boolean; + outlineColor: string; + geodesic: boolean; + path: LngLat[]; + lineJoin: StrokeLineJoin; + lineCap: StrokeLineCap; + borderWeight: number; + showDir: boolean; + dirColor: string; + dirImg: string; + } + + interface Options extends PathOverlay.Options { + isOutline?: boolean; + outlineColor?: string; + geodesic?: boolean; + dirColor?: string; + borderWeight?: number; + showDir?: boolean; + // internal + path?: LocationValue[]; + } + } + + class Polyline extends PathOverlay { + constructor(options?: BezierCurve.Options | Polyline.Options); + setPath( + path: this extends Omit ? + Array>> + : LocationValue[] + ): void; + getPath(): this extends Omit ? + Array + : LngLat[]; + getLength(): number; + setOptions(options: this extends Omit ? + Partial> + : Polyline.Options + ): void; + getOptions(): Partial>; + } +} diff --git a/types/amap-js-api/overlay/rectangle.d.ts b/types/amap-js-api/overlay/rectangle.d.ts new file mode 100644 index 0000000000..259e2072de --- /dev/null +++ b/types/amap-js-api/overlay/rectangle.d.ts @@ -0,0 +1,21 @@ +declare namespace AMap { + namespace Rectangle { + interface EventMap extends Polygon.EventMap { + setBounds: Event<'setBounds'>; + } + + interface Options extends Polygon.Options { + bounds?: Bounds; + } + type GetOptionsResult = Merge, { + path: LngLat[]; + bounds: Bounds; + texture: string; + }>; + } + class Rectangle extends Polygon { + constructor(options?: Rectangle.Options); + setBounds(bounds: Bounds, preventEvent?: boolean): void; + setOptions(options: Partial): void; + } +} diff --git a/types/amap-js-api/overlay/shapeOverlay.d.ts b/types/amap-js-api/overlay/shapeOverlay.d.ts new file mode 100644 index 0000000000..b8f239aac1 --- /dev/null +++ b/types/amap-js-api/overlay/shapeOverlay.d.ts @@ -0,0 +1,30 @@ +declare namespace AMap { + namespace ShapeOverlay { + interface EventMap extends Overlay.EventMap { + show: Event<'show', { target: I }>; + hide: Event<'hide', { target: I }>; + options: Event<'options'>; + change: Event<'change', { target: I }>; + } + interface GetOptionsResult { + map: Map; + zIndex: number; + strokeColor: string; + strokeOpacity: number; + strokeWeight: number; + strokeStyle: StrokeStyle; + strokeDasharray: number[]; + extData: ExtraData | {}; + bubble: boolean; + clickable: boolean; + } + } + abstract class ShapeOverlay extends Overlay { + abstract setOptions(options: {}): void; + abstract getOptions(): {}; + getzIndex(): number; + setzIndex(zIndex: number): void; + getVisible(): boolean; + setDraggable(draggable: boolean): void; + } +} diff --git a/types/amap-js-api/overlay/text.d.ts b/types/amap-js-api/overlay/text.d.ts new file mode 100644 index 0000000000..db15ae08ce --- /dev/null +++ b/types/amap-js-api/overlay/text.d.ts @@ -0,0 +1,19 @@ +declare namespace AMap { + namespace Text { + type TextAlign = 'left' | 'right' | 'center'; + type VerticalAlign = 'top' | 'middle' | 'bottom'; + interface EventMap extends Marker.EventMap { } + interface Options extends Marker.Options { + text?: string; + textAlign?: TextAlign; + verticalAlign?: VerticalAlign; + } + } + + class Text extends Marker { + constructor(options?: Text.Options); + getText(): string; + setText(text: string): void; + setStyle(style: object): void; + } +} diff --git a/types/amap-js-api/pixel.d.ts b/types/amap-js-api/pixel.d.ts new file mode 100644 index 0000000000..fab4605b7a --- /dev/null +++ b/types/amap-js-api/pixel.d.ts @@ -0,0 +1,17 @@ +declare namespace AMap { + class Pixel { + constructor(x: number, y: number, round?: boolean); + getX(): number; + getY(): number; + equals(point: Pixel): boolean; + toString(): string; + + // internal + add(offset: {x: number; y: number}, round?: boolean): Pixel; + round(): Pixel; + floor(): Pixel; + length(): number; + direction(): null | number; + toFixed(decimals?: number): this; + } +} diff --git a/types/amap-js-api/size.d.ts b/types/amap-js-api/size.d.ts new file mode 100644 index 0000000000..12a1e25423 --- /dev/null +++ b/types/amap-js-api/size.d.ts @@ -0,0 +1,10 @@ +declare namespace AMap { + class Size { + constructor(width: number, height: number); + getWidth(): number; + getHeight(): number; + toString(): string; + // internal + contains(size: { x: number; y: number }): boolean; + } +} diff --git a/types/amap-js-api/test/arryBounds.ts b/types/amap-js-api/test/arryBounds.ts new file mode 100644 index 0000000000..1ccc4d0488 --- /dev/null +++ b/types/amap-js-api/test/arryBounds.ts @@ -0,0 +1,18 @@ +import { + lnglat +} from './preset'; + +// $ExpectType ArrayBounds +const arrayBounds = new AMap.ArrayBounds([lnglat, lnglat, lnglat]); + +// $ExpectType LngLat[] +arrayBounds.bounds; + +// $ExpectType boolean +arrayBounds.contains(lnglat); + +// $ExpectType Bounds +arrayBounds.toBounds(); + +// $ExpectType LngLat +arrayBounds.getCenter(); diff --git a/types/amap-js-api/test/bounds.ts b/types/amap-js-api/test/bounds.ts new file mode 100644 index 0000000000..d22ba697f9 --- /dev/null +++ b/types/amap-js-api/test/bounds.ts @@ -0,0 +1,30 @@ +import { + lnglat, + lnglatTuple +} from './preset'; + +// $ExpectType Bounds +const bounds = new AMap.Bounds(lnglat, lnglat); + +// $ExpectType boolean +bounds.contains(lnglat); +// $ExpectType boolean +bounds.contains(lnglatTuple); + +// $ExpectType LngLat +bounds.getCenter(); + +// $ExpectType LngLat +bounds.getSouthWest(); + +// $ExpectType LngLat +bounds.getSouthEast(); + +// $ExpectType LngLat +bounds.getNorthEast(); + +// $ExpectType LngLat +bounds.getNorthWest(); + +// $ExpectType string +bounds.toString(); diff --git a/types/amap-js-api/test/browser.ts b/types/amap-js-api/test/browser.ts new file mode 100644 index 0000000000..b80d8cd3ff --- /dev/null +++ b/types/amap-js-api/test/browser.ts @@ -0,0 +1,141 @@ +const brwoser = AMap.Browser; + +// $ExpectType string +brwoser.ua; + +// $ExpectType boolean +brwoser.mobile; + +const plat: 'android' | 'ios' | 'windows' | 'mac' | 'other' = brwoser.plat; + +// $ExpectType boolean +brwoser.mac; + +// $ExpectType boolean +brwoser.windows; + +// $ExpectType boolean +brwoser.ios; + +// $ExpectType boolean +brwoser.iPad; + +// $ExpectType boolean +brwoser.iPhone; + +// $ExpectType boolean +brwoser.android; + +// $ExpectType boolean +brwoser.android23; + +// $ExpectType boolean +brwoser.chrome; + +// $ExpectType boolean +brwoser.firefox; + +// $ExpectType boolean +brwoser.safari; + +// $ExpectType boolean +brwoser.wechat; + +// $ExpectType boolean +brwoser.uc; + +// $ExpectType boolean +brwoser.qq; + +// $ExpectType boolean +brwoser.ie; + +// $ExpectType boolean +brwoser.ie6; + +// $ExpectType boolean +brwoser.ie7; + +// $ExpectType boolean +brwoser.ie8; + +// $ExpectType boolean +brwoser.ie9; + +// $ExpectType boolean +brwoser.ie10; + +// $ExpectType boolean +brwoser.ie11; + +// $ExpectType boolean +brwoser.edge; + +// $ExpectType boolean +brwoser.ielt9; + +// $ExpectType boolean +brwoser.baidu; + +// $ExpectType boolean +brwoser.isLocalStorage; + +// $ExpectType boolean +brwoser.isGeolocation; + +// $ExpectType boolean +brwoser.mobileWebkit; + +// $ExpectType boolean +brwoser.mobileWebkit3d; + +// $ExpectType boolean +brwoser.mobileOpera; + +// $ExpectType boolean +brwoser.retina; + +// $ExpectType boolean +brwoser.touch; + +// $ExpectType boolean +brwoser.msPointer; + +// $ExpectType boolean +brwoser.pointer; + +// $ExpectType boolean +brwoser.webkit; + +// $ExpectType boolean +brwoser.ie3d; + +// $ExpectType boolean +brwoser.webkit3d; + +// $ExpectType boolean +brwoser.gecko3d; + +// $ExpectType boolean +brwoser.opera3d; + +// $ExpectType boolean +brwoser.any3d; + +// $ExpectType boolean +brwoser.isCanvas; + +// $ExpectType boolean +brwoser.isSvg; + +// $ExpectType boolean +brwoser.isVML; + +// $ExpectType boolean +brwoser.isWorker; + +// $ExpectType boolean +brwoser.isWebsocket; + +// $ExpectType boolean +brwoser.isWebGL(); diff --git a/types/amap-js-api/test/convert-from.ts b/types/amap-js-api/test/convert-from.ts new file mode 100644 index 0000000000..8cb9b8502c --- /dev/null +++ b/types/amap-js-api/test/convert-from.ts @@ -0,0 +1,25 @@ +import { + lnglat, + lnglatTuple +} from './preset'; + +declare const convertType: 'baidu' | 'mapbar' | 'gps' | null; +// $ExpectType void +AMap.convertFrom(lnglat, convertType, (status, result) => { + const temp: 'complete' | 'error' = status; + if (typeof result !== 'string') { + // $ExpectType string + result.info; + // $ExpectType LngLat[] + result.locations; + } else { + // $ExpectType string + result; + } +}); +// $ExpectType void +AMap.convertFrom([lnglat], null, () => { }); +// $ExpectType void +AMap.convertFrom(lnglatTuple, null, () => { }); +// $ExpectType void +AMap.convertFrom([lnglatTuple], null, () => { }); diff --git a/types/amap-js-api/test/dom-util.ts b/types/amap-js-api/test/dom-util.ts new file mode 100644 index 0000000000..6cb0bce511 --- /dev/null +++ b/types/amap-js-api/test/dom-util.ts @@ -0,0 +1,47 @@ +import { div } from './preset'; + +const util = AMap.DomUtil; + +// $ExpectType Size +util.getViewport(div); + +// $ExpectType Pixel +util.getViewportOffset(div); + +// $ExpectType HTMLDivElement +util.create('div'); +// $ExpectType HTMLAnchorElement +util.create('a'); +// $ExpectType HTMLDivElement +util.create('div', div); +// $ExpectType HTMLDivElement +util.create('div', div, 'className'); + +// $ExpectType void +util.setClass(div); +// $ExpectType void +util.setClass(div, 'className'); + +// $ExpectType boolean +util.hasClass(div, 'className'); + +// $ExpectType void +util.removeClass(div, 'className'); + +// $ExpectType void +util.setOpacity(div, 1); + +// $ExpectType void +util.rotate(div, 10); +// $ExpectType void +util.rotate(div, 10, { x: 10, y: 10 }); + +const util2: typeof AMap.DomUtil = util.setCss(div, { textAlign: 'left' }); +// $ExpectError +util.setCss(div, { textAlign: 10 }); + +// $ExpectType void +util.empty(div); + +// $ExpectType void +util.remove(div); diff --git a/types/amap-js-api/test/event.ts b/types/amap-js-api/test/event.ts new file mode 100644 index 0000000000..8678045158 --- /dev/null +++ b/types/amap-js-api/test/event.ts @@ -0,0 +1,75 @@ +import { + lnglat, + pixel, + map +} from './preset'; +declare var div: HTMLDivElement; +declare var input: HTMLInputElement; + +// $ExpectType Map +map.on('hotspotclick', (event: AMap.Map.EventMap['hotspotclick']) => { + // $ExpectType "hotspotclick" + event.type; + // $ExpectType string + event.id; + // $ExpectType LngLat + event.lnglat; +}); + +// $ExpectType EventListener<0> +AMap.event.addDomListener(div, 'click', event => { + // $ExpectType number + event.clientX; +}); + +// $ExpectType EventListener<1> +AMap.event.addListener(map, 'hotspotclick', function (event: AMap.Map.EventMap['hotspotclick']) { + // $ExpectType "hotspotclick" + event.type; + // $ExpectType string + event.id; + // $ExpectType LngLat + event.lnglat; + // $ExpectType number + this.test; +}, { test: 1 }); +AMap.event.addListener(map, 'click', (event: AMap.Map.EventMap['click']) => { + // $ExpectType "click" + event.type; + // $ExpectType LngLat + event.lnglat; + // $ExpectType Map + event.target; +}); + +// $ExpectType EventListener<1> +AMap.event.addListenerOnce(map, 'hotspotclick', function (event: AMap.Map.EventMap['hotspotclick']) { + // $ExpectType "hotspotclick" + event.type; + // $ExpectType string + event.id; + // $ExpectType LngLat + event.lnglat; + // $ExpectType number + this.test; +}, { test: 1 }); + +declare const eventListener: AMap.event.EventListener<0>; +// $ExpectType void +AMap.event.removeListener(eventListener); + +// $ExpectType void +AMap.event.trigger(map, 'click', { + lnglat, + pixel, + target: map +}); +// $ExpectType void +AMap.event.trigger(map, 'hotspotclick', { + lnglat, + name: 'name', + id: 'id', + isIndoorPOI: true +}); +// $ExpectType void +AMap.event.trigger(map, 'complete'); diff --git a/types/amap-js-api/test/geometry-util.ts b/types/amap-js-api/test/geometry-util.ts new file mode 100644 index 0000000000..98a8263fb0 --- /dev/null +++ b/types/amap-js-api/test/geometry-util.ts @@ -0,0 +1,158 @@ +import { + lnglat as point, + lnglatTuple as pointTuple +} from './preset'; + +const line = [point]; +const lineTuple = [pointTuple]; +const ring = [point]; +const ringTuple = [pointTuple]; +const polygon = [ring]; +const polygonTuple = [ringTuple]; +const util = AMap.GeometryUtil; + +// $ExpectType number +util.distance(point, point); +// $ExpectType number +util.distance(pointTuple, pointTuple); +// $ExpectType number +util.distance(point, line); +// $ExpectType number +util.distance(pointTuple, lineTuple); + +// $ExpectType number +util.ringArea(ring); +// $ExpectType number +util.ringArea(ringTuple); + +// $ExpectType boolean +util.isClockwise(ring); +// $ExpectType boolean +util.isClockwise(ringTuple); + +// $ExpectType number +util.distanceOfLine(line); +// $ExpectType number +util.distanceOfLine(lineTuple); + +// $ExpectType [number, number][] +util.ringRingClip(ring, ring); +// $ExpectType [number, number][] +util.ringRingClip(ringTuple, ringTuple); + +// $ExpectType boolean +util.doesRingRingIntersect(ring, ring); +// $ExpectType boolean +util.doesRingRingIntersect(ringTuple, ringTuple); + +// $ExpectType boolean +util.doesLineRingIntersect(line, ring); +// $ExpectType boolean +util.doesLineRingIntersect(lineTuple, ringTuple); + +// $ExpectType boolean +util.doesLineLineIntersect(line, line); +// $ExpectType boolean +util.doesLineLineIntersect(lineTuple, lineTuple); + +// $ExpectType boolean +util.doesSegmentPolygonIntersect(point, point, polygon); +// $ExpectType boolean +util.doesSegmentPolygonIntersect(pointTuple, pointTuple, polygonTuple); + +// $ExpectType boolean +util.doesSegmentRingIntersect(point, point, ring); +// $ExpectType boolean +util.doesSegmentRingIntersect(pointTuple, pointTuple, ringTuple); + +// $ExpectType boolean +util.doesSegmentLineIntersect(point, point, line); +// $ExpectType boolean +util.doesSegmentLineIntersect(pointTuple, pointTuple, lineTuple); + +// $ExpectType boolean +util.doesSegmentsIntersect(point, point, point, point); +// $ExpectType boolean +util.doesSegmentsIntersect(pointTuple, pointTuple, pointTuple, pointTuple); + +// $ExpectType boolean +util.isPointInRing(point, ring); +// $ExpectType boolean +util.isPointInRing(pointTuple, ringTuple); + +// $ExpectType boolean +util.isRingInRing(ring, ring); +// $ExpectType boolean +util.isRingInRing(ringTuple, ringTuple); + +// $ExpectType boolean +util.isPointInPolygon(point, polygon); +// $ExpectType boolean +util.isPointInPolygon(pointTuple, polygonTuple); + +// $ExpectType [number, number][] +util.makesureClockwise(lineTuple); + +// $ExpectType [number, number][] +util.makesureAntiClockwise(lineTuple); + +// $ExpectType [number, number] +util.closestOnSegment(point, point, point); +// $ExpectType [number, number] +util.closestOnSegment(pointTuple, pointTuple, pointTuple); + +// $ExpectType [number, number] +util.closestOnSegment(point, point, point); +// $ExpectType [number, number] +util.closestOnSegment(pointTuple, pointTuple, pointTuple); + +// $ExpectType [number, number] +util.closestOnLine(point, line); +// $ExpectType [number, number] +util.closestOnLine(pointTuple, lineTuple); + +// $ExpectType number +util.distanceToSegment(point, point, point); +// $ExpectType number +util.distanceToSegment(pointTuple, pointTuple, pointTuple); + +// $ExpectType number +util.distanceToLine(point, line); +// $ExpectType number +util.distanceToLine(pointTuple, lineTuple); + +// $ExpectType boolean +util.isPointOnSegment(point, point, point); +// $ExpectType boolean +util.isPointOnSegment(point, point, point, 1); +// $ExpectType boolean +util.isPointOnSegment(pointTuple, pointTuple, pointTuple); +// $ExpectType boolean +util.isPointOnSegment(pointTuple, pointTuple, pointTuple, 1); + +// $ExpectType boolean +util.isPointOnLine(point, line); +// $ExpectType boolean +util.isPointOnLine(point, line, 1); +// $ExpectType boolean +util.isPointOnLine(pointTuple, lineTuple); +// $ExpectType boolean +util.isPointOnLine(pointTuple, lineTuple, 1); + +// $ExpectType boolean +util.isPointOnRing(point, ring); +// $ExpectType boolean +util.isPointOnRing(point, ring, 1); +// $ExpectType boolean +util.isPointOnRing(pointTuple, ringTuple); +// $ExpectType boolean +util.isPointOnRing(pointTuple, ringTuple, 1); + +// $ExpectType boolean +util.isPointOnPolygon(point, polygon); +// $ExpectType boolean +util.isPointOnPolygon(point, polygon, 1); +// $ExpectType boolean +util.isPointOnPolygon(pointTuple, polygonTuple); +// $ExpectType boolean +util.isPointOnPolygon(pointTuple, polygonTuple, 1); diff --git a/types/amap-js-api/test/layer/buildings.ts b/types/amap-js-api/test/layer/buildings.ts new file mode 100644 index 0000000000..209b3c490b --- /dev/null +++ b/types/amap-js-api/test/layer/buildings.ts @@ -0,0 +1,40 @@ +declare var map: AMap.Map; +declare var lnglat: AMap.LngLat; + +// $ExpectType Buildings +var buildings = new AMap.Buildings(); +// $ExpectType Buildings +new AMap.Buildings(); +// $ExpectType Buildings +new AMap.Buildings({ + zooms: [1, 18], + opacity: 0.8, + heightFactor: 1, + visible: true, + zIndex: 10, + map +}); + +buildings.setStyle({ + hideWithoutStyle: false, + areas: [ + { + visible: true, + rejectTexture: true, + color1: 'ffffff00', + color2: 'ffffcc00', + path: [[1, 2]] + }, + { + visible: true, + rejectTexture: true, + color1: 'ffffff00', + color2: 'ffffcc00', + path: [lnglat] + }, + { + color1: 'ff99ff00', + path: [lnglat] + }, + ] +}); diff --git a/types/amap-js-api/test/layer/canvasLayer.ts b/types/amap-js-api/test/layer/canvasLayer.ts new file mode 100644 index 0000000000..577d032b2c --- /dev/null +++ b/types/amap-js-api/test/layer/canvasLayer.ts @@ -0,0 +1,53 @@ +import { + map, + bounds +} from '../preset'; + +declare const canvas: HTMLCanvasElement; + +// $ExpectType CanvasLayer +new AMap.CanvasLayer({ + map, + bounds, + visible: true, + zooms: [1, 2], + opacity: 1 +}); + +// $ExpectType CanvasLayer +new AMap.CanvasLayer(); +// $ExpectType CanvasLayer +new AMap.CanvasLayer({}); +// $ExpectType CanvasLayer +const canvasLayer = new AMap.CanvasLayer({ + bounds +}); + +// $ExpectType void +canvasLayer.setMap(null); +// $ExpectType void +canvasLayer.setMap(map); + +// $ExpectType Map | null | undefined +canvasLayer.getMap(); + +// $ExpectType void +canvasLayer.show(); + +// $ExpectType void +canvasLayer.hide(); + +// $ExpectType number +canvasLayer.getzIndex(); + +// $ExpectType void +canvasLayer.setzIndex(10); + +// $ExpectType HTMLCanvasElement | null +canvasLayer.getElement(); + +// $ExpectType void +canvasLayer.setCanvas(canvas); + +// $ExpectType HTMLCanvasElement | undefined +canvasLayer.getCanvas(); diff --git a/types/amap-js-api/test/layer/flexible.ts b/types/amap-js-api/test/layer/flexible.ts new file mode 100644 index 0000000000..5a0e3f7aa7 --- /dev/null +++ b/types/amap-js-api/test/layer/flexible.ts @@ -0,0 +1,54 @@ +import { + map +} from '../preset'; + +const img = document.createElement('img'); +const canvas = document.createElement('canvas'); + +// $ExpectType Flexible +new AMap.TileLayer.Flexible(); +// $ExpectType Flexible +new AMap.TileLayer.Flexible({}); +// $ExpectType Flexible +const flexible = new AMap.TileLayer.Flexible({ + createTile(x, y, z, success, fail) { + // $ExpectType number + x; + // $ExpectType number + y; + // $ExpectType number + z; + // $ExpectType void + success(img); + // $ExpectType void + success(canvas); + // $ExpectType void + fail(); + }, + cacheSize: 10, + opacity: 1, + visible: true, + map, + zIndex: 1, + zooms: [1, 2] +}); + +// $ExpectType void +flexible.setMap(null); +// $ExpectType void +flexible.setMap(map); + +// $ExpectType Map | null | undefined +flexible.getMap(); + +// $ExpectType void +flexible.show(); + +// $ExpectType void +flexible.hide(); + +// $ExpectType void +flexible.setzIndex(10); + +// $ExpectType number +flexible.getzIndex(); diff --git a/types/amap-js-api/test/layer/imageLayer.ts b/types/amap-js-api/test/layer/imageLayer.ts new file mode 100644 index 0000000000..06b9fc076e --- /dev/null +++ b/types/amap-js-api/test/layer/imageLayer.ts @@ -0,0 +1,51 @@ +import { + map, + bounds +} from '../preset'; + +// $ExpectType ImageLayer +new AMap.ImageLayer({ + map, + bounds, + visible: true, + zooms: [1, 2], + opacity: 1 +}); + +// $ExpectType ImageLayer +new AMap.ImageLayer(); +// $ExpectType ImageLayer +new AMap.ImageLayer({}); +// $ExpectType ImageLayer +const imageLayer = new AMap.ImageLayer({ + bounds +}); + +// $ExpectType void +imageLayer.setMap(null); +// $ExpectType void +imageLayer.setMap(map); + +// $ExpectType Map | null | undefined +imageLayer.getMap(); + +// $ExpectType void +imageLayer.show(); + +// $ExpectType void +imageLayer.hide(); + +// $ExpectType number +imageLayer.getzIndex(); + +// $ExpectType void +imageLayer.setzIndex(10); + +// $ExpectType HTMLImageElement | null +imageLayer.getElement(); + +// $ExpectType void +imageLayer.setImageUrl('url'); + +// $ExpectType string | undefined +imageLayer.getImageUrl(); diff --git a/types/amap-js-api/test/layer/layer.ts b/types/amap-js-api/test/layer/layer.ts new file mode 100644 index 0000000000..921c90e52d --- /dev/null +++ b/types/amap-js-api/test/layer/layer.ts @@ -0,0 +1,34 @@ +declare var layer: AMap.Layer; +declare var map: AMap.Map; + +// $ExpectError +new AMap.Layer(); + +// $ExpectType HTMLDivElement | undefined +layer.getContainer(); + +// $ExpectType [number, number] +layer.getZooms(); + +// $ExpectType void +layer.setOpacity(1); + +// $ExpectType number +layer.getOpacity(); + +// $ExpectType void +layer.show(); + +// $ExpectType void +layer.hide(); + +// $ExpectType void +layer.setMap(); +// $ExpectType void +layer.setMap(map); + +// $ExpectType void +layer.setzIndex(1); + +// $ExpectType number +layer.getzIndex(); diff --git a/types/amap-js-api/test/layer/layerGroup.ts b/types/amap-js-api/test/layer/layerGroup.ts new file mode 100644 index 0000000000..bcad7d6f50 --- /dev/null +++ b/types/amap-js-api/test/layer/layerGroup.ts @@ -0,0 +1,115 @@ +declare var map: AMap.Map; +declare var tileLayer: AMap.TileLayer; +declare var massMarksLayer: AMap.MassMarks; +declare var layer: AMap.Layer; + +// $ExpectError +new AMap.LayerGroup(); + +// $ExpectType LayerGroup +new AMap.LayerGroup(tileLayer); +// $ExpectType LayerGroup +new AMap.LayerGroup([tileLayer]); + +declare var layerGruop: AMap.LayerGroup; + +// $ExpectType LayerGroup +layerGruop.addLayer(tileLayer); +// $ExpectType LayerGroup +layerGruop.addLayer([tileLayer]); +// $ExpectError +layerGruop.addLayer(massMarksLayer); + +// $ExpectType TileLayer[] +layerGruop.getLayers(); + +// $ExpectType TileLayer | null +layerGruop.getLayer(function (item, index, list) { + // $ExpectType TileLayer + item; + // $ExpectType number + index; + // $ExpectType TileLayer[] + list; + // $ExpectType null + this; + + return true; +}); + +layerGruop.hasLayer(function (item, index, list) { + // $ExpectType TileLayer + item; + // $ExpectType number + index; + // $ExpectType TileLayer[] + list; + // $ExpectType null + this; + + return true; +}); +layerGruop.hasLayer(tileLayer); + +// $ExpectType LayerGroup +layerGruop.removeLayer(tileLayer); +// $ExpectType LayerGroup +layerGruop.removeLayer([tileLayer]); + +// $ExpectType LayerGroup +layerGruop.clearLayers(); + +layerGruop.eachLayer(function (item, index, list) { + // $ExpectType TileLayer + item; + // $ExpectType number + index; + // $ExpectType TileLayer[] + list; + // $ExpectType TileLayer + this; +}); +layerGruop.eachLayer(function (item, index, list) { + // $ExpectType TileLayer + item; + // $ExpectType number + index; + // $ExpectType TileLayer[] + list; + // $ExpectType number + this.test; +}, { test: 1 }); + +// $ExpectType LayerGroup +layerGruop.setMap(map); + +// $ExpectType LayerGroup +layerGruop.hide(); + +// $ExpectType LayerGroup +layerGruop.show(); + +// $ExpectType LayerGroup +layerGruop.reload(); + +// $ExpectType LayerGroup +layerGruop.setOptions({}); + +// $ExpectType LayerGroup +layerGruop.setOptions({ + tileSize: 256 +}); +// layerGruop.setOptions({ +// // $ExpectError +// interval: 1 +// }); + +declare var layerGroup2: AMap.LayerGroup; + +layerGroup2.addLayer(tileLayer); + +layerGroup2.addLayer(massMarksLayer); + +layerGroup2.setOptions({ + test: 1 +}); diff --git a/types/amap-js-api/test/layer/massMarks.ts b/types/amap-js-api/test/layer/massMarks.ts new file mode 100644 index 0000000000..5f4bfbf455 --- /dev/null +++ b/types/amap-js-api/test/layer/massMarks.ts @@ -0,0 +1,83 @@ +declare var pixel: AMap.Pixel; +declare var size: AMap.Size; +declare var lnglat: AMap.LngLat; +var massMarksStyle1 = { + anchor: pixel, + url: '', + size, + rotation: 1 +}; +var massMarksStyle2 = { + anchor: pixel, + url: '', + size +}; +var massMarksData1 = { + lnglat +}; + +interface CustomData extends AMap.MassMarks.Data { + name: string; + id: string; +} +var massMarksCustomData: CustomData = { + lnglat: [1, 2], + style: 1, + name: '', + id: '' +}; + +// $ExpectError +new AMap.MassMarks(); +// $ExpectError +new AMap.MassMarks([], {}); + +new AMap.MassMarks([], { + style: [massMarksStyle1, massMarksStyle2] +}); +new AMap.MassMarks([massMarksData1], { + style: [massMarksStyle1, massMarksStyle2] +}); + +// $ExpectType MassMarks +var massMarks = new AMap.MassMarks([massMarksCustomData], { + style: [massMarksStyle1, massMarksStyle2] +}); + +// $ExpectType void +massMarks.setStyle(massMarksStyle1); +// $ExpectType void +massMarks.setStyle([massMarksStyle1]); + +// $ExpectType Style | Style[] +massMarks.getStyle(); + +// $ExpectType void +massMarks.setData(''); + +// $ExpectError +massMarks.setData(massMarksData1); +// $ExpectError +massMarks.setData(massMarksCustomData); + +var _customData = massMarks.getData()[0]; +// $ExpectType string +_customData.name; +// $ExpectType string +_customData.id; +// $ExpectType LngLat +_customData.lnglat; + +// $ExpectType void +massMarks.clear(); + +massMarks.on('click', (event: AMap.MassMarks.EventMap['click']) => { + // $ExpectType "click" + event.type; + + // $ExpectType CustomData + event.data; + + // $ExpectType MassMarks + event.target; +}); diff --git a/types/amap-js-api/test/layer/tileLayer.ts b/types/amap-js-api/test/layer/tileLayer.ts new file mode 100644 index 0000000000..7e4e2dc2e4 --- /dev/null +++ b/types/amap-js-api/test/layer/tileLayer.ts @@ -0,0 +1,60 @@ +declare var map: AMap.Map; + +// $ExpectType TileLayer +var tileLayer = new AMap.TileLayer(); + +// $ExpectType TileLayer +new AMap.TileLayer({}); + +// $ExpectType TileLayer +new AMap.TileLayer({ + map, + tileSize: 256, + tileUrl: '', + errorUrl: '', + getTileUrl: (x, y, z) => '', + zIndex: 1, + opacity: 0.1, + zooms: [3, 18], + detectRetina: true +}); + +// $ExpectType string[] +tileLayer.getTiles(); + +// $ExpectType void +tileLayer.reload(); + +// $ExpectType void +tileLayer.setTileUrl(''); +// $ExpectType void +tileLayer.setTileUrl((x, y, level) => { + // $ExpectType number + x; + // $ExpectType number + y; + // $ExpectType number + level; + return ''; +}); + +// Traffic + +// $ExpectType Traffic +let trafficLayer = new AMap.TileLayer.Traffic(); +// $ExpectType Traffic +new AMap.TileLayer.Traffic({}); +// $ExpectType Traffic +new AMap.TileLayer.Traffic({ + autoRefresh: true, + interval: 180 +}); + +// $ExpectType TileLayer +tileLayer.on('complete', () => { }); + +tileLayer.off('complete', () => { }); + +tileLayer.emit('complete'); + +trafficLayer.on('complete', () => { }); diff --git a/types/amap-js-api/test/layer/videoLayer.ts b/types/amap-js-api/test/layer/videoLayer.ts new file mode 100644 index 0000000000..e34718193c --- /dev/null +++ b/types/amap-js-api/test/layer/videoLayer.ts @@ -0,0 +1,51 @@ +import { + map, + bounds +} from '../preset'; + +// $ExpectType VideoLayer +new AMap.VideoLayer({ + map, + bounds, + visible: true, + zooms: [1, 2], + opacity: 1 +}); + +// $ExpectType VideoLayer +new AMap.VideoLayer(); +// $ExpectType VideoLayer +new AMap.VideoLayer({}); +// $ExpectType VideoLayer +const videoLayer = new AMap.VideoLayer({ + bounds +}); + +// $ExpectType void +videoLayer.setMap(null); +// $ExpectType void +videoLayer.setMap(map); + +// $ExpectType Map | null | undefined +videoLayer.getMap(); + +// $ExpectType void +videoLayer.show(); + +// $ExpectType void +videoLayer.hide(); + +// $ExpectType number +videoLayer.getzIndex(); + +// $ExpectType void +videoLayer.setzIndex(10); + +// $ExpectType HTMLVideoElement | null +videoLayer.getElement(); + +// $ExpectType void +videoLayer.setVideoUrl('url'); + +// $ExpectType string | string[] | undefined +videoLayer.getVideoUrl(); diff --git a/types/amap-js-api/test/layer/wms.ts b/types/amap-js-api/test/layer/wms.ts new file mode 100644 index 0000000000..255affa216 --- /dev/null +++ b/types/amap-js-api/test/layer/wms.ts @@ -0,0 +1,89 @@ +import { + map +} from '../preset'; + +// $ExpectType WMS +new AMap.TileLayer.WMS({ + url: 'url', + params: {} +}); +// $ExpectType WMS +const wms = new AMap.TileLayer.WMS({ + url: 'url', + blend: true, + params: { + VERSION: 'version', + LAYERS: 'layers', + STYLES: 'styles', + FORMAT: 'format', + TRANSPARENT: 'TRUE', + BGCOLOR: '#000', + EXCEPTIONS: 'exceptions', + TIME: 'time', + ELEVATION: 'elevation' + }, + zooms: [1, 2], + tileSize: 256, + opacity: 1, + zIndex: 10, + visible: true +}); + +// $ExpectType void +wms.setMap(map); +// $ExpectType void +wms.setMap(null); + +// $ExpectType Map | null | undefined +wms.getMap(); + +// $ExpectType void +wms.show(); + +// $ExpectType void +wms.hide(); + +// $ExpectType void +wms.setzIndex(10); + +// $ExpectType number +wms.getzIndex(); + +// $ExpectType void +wms.setUrl('url'); + +// $ExpectType string +wms.getUrl(); + +// $ExpectType void +wms.setParams({ + VERSION: 'version', + LAYERS: 'layers', + STYLES: 'styles', + FORMAT: 'format', + TRANSPARENT: 'TRUE', + BGCOLOR: '#000', + EXCEPTIONS: 'exceptions', + TIME: 'time', + ELEVATION: 'elevation' +}); + +const params = wms.getParams(); +// $ExpectType string | undefined +params.VERSION; +// $ExpectType string | undefined +params.LAYERS; +// $ExpectType string | undefined +params.STYLES; +// $ExpectType string | undefined +params.FORMAT; +// $ExpectType "TRUE" | "FALSE" | undefined +params.TRANSPARENT; +// $ExpectType string | undefined +params.BGCOLOR; +// $ExpectType string | undefined +params.EXCEPTIONS; +// $ExpectType string | undefined +params.TIME; +// $ExpectType string | undefined +params.ELEVATION; diff --git a/types/amap-js-api/test/layer/wmts.ts b/types/amap-js-api/test/layer/wmts.ts new file mode 100644 index 0000000000..bc167c1189 --- /dev/null +++ b/types/amap-js-api/test/layer/wmts.ts @@ -0,0 +1,69 @@ +import { + map +} from '../preset'; + +// $ExpectType WMTS +new AMap.TileLayer.WMTS({ + url: 'url', + params: {} +}); +// $ExpectType WMTS +const wmts = new AMap.TileLayer.WMTS({ + url: 'url', + blend: true, + tileSize: 256, + zooms: [1, 2], + opacity: 1, + zIndex: 10, + visible: true, + params: { + Version: 'version', + Layer: 'layers', + Style: 'style', + Format: 'format' + } +}); + +// $ExpectType void +wmts.setMap(map); +// $ExpectType void +wmts.setMap(null); + +// $ExpectType Map | null | undefined +wmts.getMap(); + +// $ExpectType void +wmts.show(); + +// $ExpectType void +wmts.hide(); + +// $ExpectType void +wmts.setzIndex(10); + +// $ExpectType number +wmts.getzIndex(); + +// $ExpectType void +wmts.setUrl('url'); + +// $ExpectType string +wmts.getUrl(); + +// $ExpectType void +wmts.setParams({ + Version: 'version', + Layer: 'layers', + Style: 'style', + Format: 'format' +}); + +const params = wmts.getParams(); +// $ExpectType string | undefined +params.Version; +// $ExpectType string | undefined +params.Layer; +// $ExpectType string | undefined +params.Style; +// $ExpectType string | undefined +params.Format; diff --git a/types/amap-js-api/test/lnglat.ts b/types/amap-js-api/test/lnglat.ts new file mode 100644 index 0000000000..92057953ee --- /dev/null +++ b/types/amap-js-api/test/lnglat.ts @@ -0,0 +1,48 @@ +import { + lnglat +} from './preset'; + +// $ExpectType LngLat +new AMap.LngLat(114, 22); +// $ExpectType LngLat +new AMap.LngLat(113, 21); + +// $ExpectType LngLat +lnglat.offset(1, 2); + +// $ExpectType number +lnglat.distance(lnglat); +// $ExpectType number +lnglat.distance([lnglat]); + +// $ExpectType number +lnglat.getLng(); + +// $ExpectType number +lnglat.getLat(); + +// $ExpectType boolean +lnglat.equals(lnglat); + +// $ExpectType string +lnglat.toString(); + +// $ExpectType LngLat +lnglat.add(lnglat); +// $ExpectType LngLat +lnglat.add(lnglat, true); + +// $ExpectType LngLat +lnglat.subtract(lnglat); +// $ExpectType LngLat +lnglat.subtract(lnglat, true); + +// $ExpectType LngLat +lnglat.divideBy(1); +// $ExpectType LngLat +lnglat.divideBy(1, true); + +// $ExpectType LngLat +lnglat.multiplyBy(1); +// $ExpectType LngLat +lnglat.multiplyBy(1, true); diff --git a/types/amap-js-api/test/map.ts b/types/amap-js-api/test/map.ts new file mode 100644 index 0000000000..6f2b027e60 --- /dev/null +++ b/types/amap-js-api/test/map.ts @@ -0,0 +1,338 @@ +import { + lnglat, + bounds, + lnglatTuple, + pixel +} from './preset'; + +declare const container: HTMLDivElement; +declare const tileLayer: AMap.TileLayer; + +// declare var indoorMap: AMap.IndoorMap + +// $ExpectType Map +new AMap.Map('map'); +// $ExpectType Map +new AMap.Map(container); + +// $ExpectType Map +new AMap.Map(container, {}); + +// $ExpectType Map +const map = new AMap.Map(container, { + layers: [tileLayer], + zoom: 15, + center: [1, 2], + labelzIndex: 110, + zooms: [5, 15], + lang: 'zh_cn', + defaultCursor: 'default', + crs: 'EPSG4326', + animateEnable: true, + isHotspot: false, + defaultLayer: tileLayer, + rotateEnable: true, + resizeEnable: true, + showIndoorMap: true, + // indoorMap, // TODO + expandZoomRange: true, + dragEnable: true, + zoomEnable: true, + doubleClickZoom: true, + keyboardEnable: true, + jogEnable: true, + scrollWheel: true, + touchZoom: true, + mapStyle: '', + features: ['road'], + showBuildingBlock: true, + skyColor: '#fff', + preloadMode: true, + mask: [[1, 2], [2, 3], [3, 4]] +}); + +// $ExpectType number +map.getZoom(); + +// $ExpectType Layer[] +map.getLayers(); + +// $ExpectType LngLat +map.getCenter(); + +// $ExpectType HTMLElement | null +map.getContainer(); + +map.getCity(city => { + // $ExpectType string + city.city; + // $ExpectType string + city.citycode; + // $ExpectType string + city.district; + // $ExpectType string | never[] + city.province; +}); + +// $ExpectType Bounds +map.getBounds(); + +// $ExpectType number +map.getLabelzIndex(); + +// $ExpectType Lang +map.getLang(); + +// $ExpectType Size +map.getSize(); + +// $ExpectType number +map.getRotation(); + +// $ExpectType Status +const mapStatus = map.getStatus(); +// $ExpectType boolean +mapStatus.animateEnable; +// $ExpectType boolean +mapStatus.doubleClickZoom; +// $ExpectType boolean +mapStatus.dragEnable; +// $ExpectType boolean +mapStatus.isHotspot; +// $ExpectType boolean +mapStatus.jogEnable; +// $ExpectType boolean +mapStatus.keyboardEnable; +// $ExpectType boolean +mapStatus.pitchEnable; +// $ExpectType boolean +mapStatus.resizeEnable; +// $ExpectType boolean +mapStatus.rotateEnable; +// $ExpectType boolean +mapStatus.scrollWheel; +// $ExpectType boolean +mapStatus.touchZoom; +// $ExpectType boolean +mapStatus.zoomEnable; + +// $ExpectType string +map.getDefaultCursor(); + +// $ExpectType number +map.getResolution(); + +// $ExpectType number +map.getScale(); +// $ExpectType number +map.getScale(1); + +// $ExpectType void +map.setZoom(1); + +// $ExpectType void +map.setLabelzIndex(1); + +// $ExpectType void +map.setLayers([tileLayer]); + +// $ExpectType void +map.setCenter(lnglat); +// $ExpectType void +map.setCenter([1, 2]); + +// $ExpectType void +map.setZoomAndCenter(13, lnglat); +// $ExpectType void +map.setZoomAndCenter(13, [1, 2]); + +// $ExpectType void +map.setCity('city', (coord, zoom) => { + // $ExpectType string + coord[0]; + // $ExpectType string + coord[1]; + // $ExpectType number + zoom; +}); + +// $ExpectType Bounds +map.setBounds(bounds); + +// $ExpectType void +map.setLimitBounds(bounds); + +// $ExpectType void +map.clearLimitBounds(); + +// $ExpectType void +map.setLang('zh_cn'); + +// $ExpectType void +map.setRotation(1); + +// $ExpectType void +map.setStatus({}); +// $ExpectType void +map.setStatus({ + animateEnable: true, + doubleClickZoom: true, + dragEnable: true, + isHotspot: true, + jogEnable: true, + keyboardEnable: true, + pitchEnable: false, + resizeEnable: false, + rotateEnable: false, + scrollWheel: true, + touchZoom: true, + zoomEnable: true +}); + +// $ExpectType void +map.setDefaultCursor('default'); + +// $ExpectType void +map.zoomIn(); + +// $ExpectType void +map.zoomOut(); + +// $ExpectType void +map.panTo([1, 2]); +// $ExpectType void +map.panTo(lnglat); + +// $ExpectType void +map.panBy(1, 2); + +// $ExpectType void +map.clearMap(); + +// $ExpectType Map +map.plugin('plugin name', () => { }); +// $ExpectType Map +map.plugin(['plugin name'], () => { }); + +// $ExpectType void +map.clearInfoWindow(); + +// $ExpectType LngLat +map.pixelToLngLat(pixel); +// $ExpectType LngLat +map.pixelToLngLat(pixel, 1); + +// $ExpectType Pixel +map.lnglatToPixel(lnglat); +// $ExpectType Pixel +map.lnglatToPixel(lnglat, 1); + +// $ExpectType LngLat +map.containerToLngLat(pixel); + +// $ExpectType Pixel +map.lngLatToContainer(lnglat); +// $ExpectType Pixel +map.lnglatTocontainer(lnglat); + +// $ExpectType void +map.setMapStyle(''); +// $ExpectType string +map.getMapStyle(); + +// $ExpectType void +map.setFeatures('all'); +// $ExpectType void +map.setFeatures(['bg']); + +const feature: 'all' | 'bg' | 'point' | 'road' | 'building' | AMap.Map.Feature[] = map.getFeatures(); + +// $ExpectType void +map.setDefaultLayer(tileLayer); + +// $ExpectType void +map.setPitch(1); +// $ExpectType number +map.getPitch(); + +// $ExpectType ViewMode +map.getViewMode_(); + +// $ExpectType Pixel +map.lngLatToGeodeticCoord(lnglat); +// $ExpectType Pixel +map.lngLatToGeodeticCoord(lnglatTuple); + +// $ExpectType LngLat +map.geodeticCoordToLngLat(pixel); + +// $ExpectType void +map.destroy(); + +declare function dblClickHandler(this: AMap.Map, event: AMap.Map.EventMap['dblclick']): void; + +// $ExpectType Map +map.on('click', (event: AMap.Map.EventMap['click']) => { + // $ExpectType "click" + event.type; + // $ExpectType Pixel + event.pixel; + // $ExpectType LngLat + event.lnglat; + // $ExpectType Map + event.target; +}); +// $ExpectType Map +map.on('dblclick', dblClickHandler); +// $ExpectType Map +map.on('complete', (event: AMap.Map.EventMap['complete']) => { + // $ExpectType "complete" + event.type; + // $ExpectError + event.value; +}); +// $ExpectType Map +map.on('hotspotclick', (event: AMap.Map.EventMap['hotspotclick']) => { + // $ExpectType string + event.id; + // $ExpectType LngLat + event.lnglat; + // $ExpectType string + event.name; + // $ExpectType "hotspotclick" + event.type; +}); +// $ExpectType Map +map.on('custom', (event: AMap.Event<'custom', { test: string }>) => { + // $ExpectType "custom" + event.type; + // $ExpectType string + event.test; +}); + +// $ExpectType Map +map.off('dblclick', dblClickHandler); +// $ExpectType Map +map.off('click', 'mv'); + +// $ExpectType Map +map.emit('click', { + target: map, + lnglat, + pixel +}); + +map.emit('complete'); +// $ExpectType Map +map.emit('hotspotclick', { + lnglat, + name: '123', + id: '123', + isIndoorPOI: true +}); +// $ExpectType Map +map.emit('custom', { + test: 1 +}); +// $ExpectType Map +map.emit('custom', undefined); diff --git a/types/amap-js-api/test/overlay/bezierCurve.ts b/types/amap-js-api/test/overlay/bezierCurve.ts new file mode 100644 index 0000000000..abf0640fc9 --- /dev/null +++ b/types/amap-js-api/test/overlay/bezierCurve.ts @@ -0,0 +1,155 @@ +import { + map, + lnglat +} from '../preset'; + +interface ExtraData { + test: number; +} + +const path = [ + [1, 2, 3, 4], + [1, 2, 3], + [ + [1, 2, 3], + [1, 2] + ], + [1, 2] +]; + +// $ExpectError +new AMap.BezierCurve(); +// $ExpectError +new AMap.BezierCurve({}); +// $ExpectType BezierCurve +const bezierCurve = new AMap.BezierCurve({ + map, + path, + strokeColor: '#FF0000', + strokeOpacity: 0.6, + strokeWeight: 10, + strokeStyle: 'dashed', + strokeDasharray: [1, 5], + zIndex: 10, + bubble: false, + showDir: true, + cursor: 'pointer', + isOutline: true, + outlineColor: '#00FF00', + borderWeight: 2 +}); + +// $ExpectType void +bezierCurve.setPath(path); + +// $ExpectType void +bezierCurve.setPath(path); + +// $ExpectType void +bezierCurve.setOptions({}); +bezierCurve.setOptions({ + map, + path, + strokeColor: '#FF0000', + strokeOpacity: 0.6, + strokeWeight: 10, + strokeStyle: 'dashed', + strokeDasharray: [1, 5], + zIndex: 10, + bubble: false, + showDir: true, + cursor: 'pointer', + isOutline: true, + outlineColor: '#00FF00', + borderWeight: 2 +}); + +const options = bezierCurve.getOptions(); + +// $ExpectType number | undefined +options.borderWeight; +// $ExpectType boolean | undefined +options.bubble; +// $ExpectType boolean | undefined +options.clickable; +// $ExpectType string | undefined +options.dirColor; +// $ExpectType string | undefined +options.dirImg; +// $ExpectType {} | ExtraData | undefined +options.extData; +// $ExpectType boolean | undefined +options.geodesic; +// $ExpectType boolean | undefined +options.isOutline; +// $ExpectType "round" | "butt" | "square" | undefined +options.lineCap; +// $ExpectType "miter" | "round" | "bevel" | undefined +options.lineJoin; +// $ExpectType Map | undefined +options.map; +// $ExpectType string | undefined +options.outlineColor; +// $ExpectType (LngLat & { controlPoints: LngLat[]; })[] | undefined +options.path; +// $ExpectType boolean | undefined +options.showDir; +// $ExpectType string | undefined +options.strokeColor; +// $ExpectType number[] | undefined +options.strokeDasharray; +// $ExpectType number | undefined +options.strokeOpacity; +// $ExpectType "dashed" | "solid" | undefined +options.strokeStyle; +// $ExpectType number | undefined +options.strokeWeight; +// $ExpectType number | undefined +options.zIndex; + +// $ExpectType number +bezierCurve.getLength(); + +// $ExpectType Bounds | null +bezierCurve.getBounds(); + +// $ExpectType void +bezierCurve.show(); + +// $ExpectType void +bezierCurve.hide(); + +// $ExpectType void +bezierCurve.setMap(null); +bezierCurve.setMap(map); + +// $ExpectType void +bezierCurve.setExtData({ test: 1 }); +// $ExpectError +bezierCurve.setExtData({ test: '123' }); + +// $ExpectType {} | ExtraData +bezierCurve.getExtData(); + +bezierCurve.on('click', (event: AMap.BezierCurve.EventMap['click']) => { + // $ExpectType "click" + event.type; + // $ExpectType LngLat + event.lnglat; + // $ExpectType BezierCurve + event.target; +}); + +bezierCurve.on('show', (event: AMap.BezierCurve.EventMap['show']) => { + // $ExpectType "show" + event.type; + // $ExpectType BezierCurve + event.target; +}); + +bezierCurve.on('options', (event: AMap.BezierCurve.EventMap['options']) => { + // $ExpectType "options" + event.type; + // $ExpectError + event.target; +}); diff --git a/types/amap-js-api/test/overlay/circle.ts b/types/amap-js-api/test/overlay/circle.ts new file mode 100644 index 0000000000..28822b9ec9 --- /dev/null +++ b/types/amap-js-api/test/overlay/circle.ts @@ -0,0 +1,150 @@ +import { + map, + lnglat, + lnglatTuple +} from '../preset'; + +interface ExtraData { + test: number; +} + +// $ExpectType Circle +new AMap.Circle(); +new AMap.Circle({}); +// $ExpectType Circle +const circle = new AMap.Circle({ + map, + zIndex: 10, + center: lnglat, + bubble: true, + cursor: 'pointer', + radius: 1000, + strokeColor: '#FF0000', + strokeOpcity: 0.8, + strokeWeight: 3, + fillColor: '#00FF00', + fillOpacity: 0.5, + strokeStyle: 'dashed', + extData: { test: 1 }, + strokeDasharray: [2, 4] +}); + +// $ExpectType void +circle.setCenter(lnglat); +// $ExpectType void +circle.setCenter(lnglatTuple); + +// $ExpectType LngLat | undefined +circle.getCenter(); + +// $ExpectType Bounds | null +circle.getBounds(); + +// $ExpectType void +circle.setRadius(100); + +// $ExpectType number +circle.getRadius(); + +// $ExpectType void +circle.setOptions({}); +circle.setOptions({ + map, + zIndex: 10, + center: lnglat, + bubble: true, + cursor: 'pointer', + radius: 1000, + strokeColor: '#FF0000', + strokeOpcity: 0.8, + strokeWeight: 3, + fillColor: '#00FF00', + fillOpacity: 0.5, + strokeStyle: 'dashed', + extData: { test: 1 }, + strokeDasharray: [2, 4] +}); + +const options = circle.getOptions(); +// $ExpectType boolean | undefined +options.bubble; +// $ExpectType LngLat | undefined +options.center; +// $ExpectType boolean | undefined +options.clickable; +// $ExpectType {} | ExtraData | undefined +options.extData; +// $ExpectType string | undefined +options.fillColor; +// $ExpectType number | undefined +options.fillOpacity; +// $ExpectType "miter" | "round" | "bevel" | undefined +options.lineJoin; +// $ExpectType Map | undefined +options.map; +// $ExpectType LngLat[] | undefined +options.path; +// $ExpectType number | undefined +options.radius; +// $ExpectType string | undefined +options.strokeColor; +// $ExpectType number[] | undefined +options.strokeDasharray; +// $ExpectType number | undefined +options.strokeOpacity; +// $ExpectType "dashed" | "solid" | undefined +options.strokeStyle; +// $ExpectType number | undefined +options.strokeWeight; +// $ExpectType string | undefined +options.texture; +// $ExpectType number | undefined +options.zIndex; + +// $ExpectType Bounds | null +circle.getBounds(); + +// $ExpectType void +circle.hide(); + +// $ExpectType void +circle.show(); + +// $ExpectType void +circle.setMap(null); +// $ExpectType void +circle.setMap(map); + +// $ExpectType void +circle.setExtData({ test: 2 }); +// $ExpectError +circle.setExtData({ test: '1' }); + +// $ExpectType {} | ExtraData +circle.getExtData(); + +// $ExpectType boolean +circle.contains(lnglat); +// $ExpectType boolean +circle.contains(lnglatTuple); + +circle.on('click', (event: AMap.Circle.EventMap['click']) => { + // $ExpectType "click" + event.type; + // $ExpectType Circle + event.target; +}); + +circle.on('setCenter', (event: AMap.Circle.EventMap['setCenter']) => { + // $ExpectType "setCenter" + event.type; + // $ExpectError + event.target; +}); + +circle.on('change', (event: AMap.Circle.EventMap['change']) => { + // $ExpectType "change" + event.type; + // $ExpectType Circle + event.target; +}); diff --git a/types/amap-js-api/test/overlay/contextMenu.ts b/types/amap-js-api/test/overlay/contextMenu.ts new file mode 100644 index 0000000000..5c7173d26b --- /dev/null +++ b/types/amap-js-api/test/overlay/contextMenu.ts @@ -0,0 +1,48 @@ +import { + map, + lnglat, + lnglatTuple +} from '../preset'; + +interface ExtraData { + test: number; +} +// $ExpectType ContextMenu +new AMap.ContextMenu(); +// $ExpectType ContextMenu +new AMap.ContextMenu({}); +// $ExpectType ContextMenu +const contextMenu = new AMap.ContextMenu({ + content: '
content
', +}); + +// $ExpectType void +contextMenu.addItem('item', function () { + // $ExpectType HTMLLIElement + this; +}); +// $ExpectType void +contextMenu.addItem('item', () => { }, 1); + +// $ExpectType void +contextMenu.removeItem('item', () => {}); + +// $ExpectType void +contextMenu.open(map, lnglatTuple); +// $ExpectType void +contextMenu.open(map, lnglat); + +// $ExpectType void +contextMenu.close(); + +contextMenu.on('items', (event: AMap.ContextMenu.EventMap['items']) => { + // $ExpectType "items" + event.type; +}); + +contextMenu.on('open', (event: AMap.ContextMenu.EventMap['open']) => { + // $ExpectType "open" + event.type; + // $ExpectType ContextMenu + event.target; +}); diff --git a/types/amap-js-api/test/overlay/ellipse.ts b/types/amap-js-api/test/overlay/ellipse.ts new file mode 100644 index 0000000000..c5205d9915 --- /dev/null +++ b/types/amap-js-api/test/overlay/ellipse.ts @@ -0,0 +1,117 @@ +import { + map, + lnglat, + lnglatTuple +} from '../preset'; + +interface ExtraData { + test: number; +} +// $ExpectType Ellipse +new AMap.Ellipse(); +// $ExpectType Ellipse +new AMap.Ellipse({}); +// $ExpectType Ellipse +const ellipse = new AMap.Ellipse({ + map, + zIndex: 10, + center: lnglat, + radius: [10000, 15000], + bubble: false, + cursor: 'pointer', + strokeColor: '#FF0000', + strokeOpacity: 0.8, + strokeWeight: 2, + fillColor: '#0000FF', + fillOpacity: 0.5, + strokeStyle: 'dashed', + extData: { test: 1 }, + strokeDasharray: [1, 5] +}); + +// $ExpectType LngLat | undefined +ellipse.getCenter(); + +// $ExpectType void +ellipse.setCenter(lnglat); +// $ExpectType void +ellipse.setCenter(lnglatTuple); + +// $ExpectType Bounds | null +ellipse.getBounds(); + +// $ExpectType void +ellipse.setOptions({ + map, + zIndex: 10, + center: lnglat, + radius: [10000, 15000], + bubble: false, + cursor: 'pointer', + strokeColor: '#FF0000', + strokeOpacity: 0.8, + strokeWeight: 2, + fillColor: '#0000FF', + fillOpacity: 0.5, + strokeStyle: 'dashed', + extData: { test: 1 }, + strokeDasharray: [1, 5] +}); + +const options = ellipse.getOptions(); + +// $ExpectType boolean | undefined +options.bubble; +// $ExpectType LngLat | undefined +options.center; +// $ExpectType boolean | undefined +options.clickable; +// $ExpectType {} | ExtraData | undefined +options.extData; +// $ExpectType string | undefined +options.fillColor; +// $ExpectType number | undefined +options.fillOpacity; +// $ExpectType "miter" | "round" | "bevel" | undefined +options.lineJoin; +// $ExpectType Map | undefined +options.map; +// $ExpectType LngLat[] | undefined +options.path; +// $ExpectType [number, number] | undefined +options.radius; +// $ExpectType string | undefined +options.strokeColor; +// $ExpectType number[] | undefined +options.strokeDasharray; +// $ExpectType number | undefined +options.strokeOpacity; +// $ExpectType "dashed" | "solid" | undefined +options.strokeStyle; +// $ExpectType number | undefined +options.strokeWeight; +// $ExpectType string | undefined +options.texture; +// $ExpectType number | undefined +options.zIndex; + +// $ExpectType void +ellipse.hide(); + +// $ExpectType void +ellipse.show(); + +// $ExpectType void +ellipse.setMap(null); +// $ExpectType void +ellipse.setMap(map); + +// $ExpectType void +ellipse.setExtData({test: 2}); +// $ExpectType {} | ExtraData +ellipse.getExtData(); + +// $ExpectType boolean +ellipse.contains(lnglat); +// $ExpectType boolean +ellipse.contains(lnglatTuple); diff --git a/types/amap-js-api/test/overlay/geoJSON.ts b/types/amap-js-api/test/overlay/geoJSON.ts new file mode 100644 index 0000000000..ee8c501472 --- /dev/null +++ b/types/amap-js-api/test/overlay/geoJSON.ts @@ -0,0 +1,106 @@ +import { + map, + lnglatTuple +} from '../preset'; + +declare const marker: AMap.Marker; +declare const polyline: AMap.Polyline; +declare const polygon: AMap.Polygon; + +interface ExtraData { + test: number; +} + +const geoJSONObject: AMap.GeoJSON.GeoJSONObject[] = [ + { + type: 'Feature', + properties: {}, + geometry: { + type: 'Point', + coordinates: lnglatTuple + } + }, + { + type: 'Feature', + properties: { test: 1 }, + geometry: { + type: 'LineString', + coordinates: [lnglatTuple, lnglatTuple] + } + } +]; + +// $ExpectType GeoJSON +new AMap.GeoJSON(); +// $ExpectType GeoJSON +new AMap.GeoJSON({}); +// $ExpectType GeoJSON +const geoJSON = new AMap.GeoJSON({ + geoJSON: geoJSONObject, + getMarker(obj, lnglat) { + // $ExpectType GeoJSONObject + obj; + // $ExpectType LngLat + lnglat; + return marker; + }, + getPolyline(obj, lnglats) { + // $ExpectType GeoJSONObject + obj; + // $ExpectType LngLat[] + lnglats; + return polyline; + }, + getPolygon(obj, lnglats) { + // $ExpectType GeoJSONObject + obj; + // $ExpectType LngLat[] + lnglats; + return polygon; + }, + coordsToLatLng(coord) { + // $ExpectType LngLat + coord; + return coord; + } +}); + +// $ExpectType void +geoJSON.importData(geoJSONObject); + +// $ExpectType GeoJSON +geoJSON.removeOverlay(marker); +// $ExpectType GeoJSON +geoJSON.removeOverlay([marker]); + +// $ExpectType boolean +geoJSON.hasOverlay(marker); +// $ExpectType boolean +geoJSON.hasOverlay(m => m === marker); + +// $ExpectType GeoJSON +geoJSON.addOverlay(marker); +// $ExpectType GeoJSON +geoJSON.addOverlay([marker]); + +// $ExpectType GeoJSONObject[] +geoJSON.toGeoJSON(); + +// $ExpectType GeoJSON +geoJSON.setMap(null); +// $ExpectType GeoJSON +geoJSON.setMap(map); + +// $ExpectType GeoJSON +geoJSON.hide(); + +// $ExpectType GeoJSON +geoJSON.show(); + +type ClickEvent = AMap.MapsEvent<'click', AMap.Overlay>; +geoJSON.on('click', (event: ClickEvent) => { + // $ExpectType "click" + event.type; + // $ExpectType Overlay + event.target; +}); diff --git a/types/amap-js-api/test/overlay/icon.ts b/types/amap-js-api/test/overlay/icon.ts new file mode 100644 index 0000000000..8576685b8a --- /dev/null +++ b/types/amap-js-api/test/overlay/icon.ts @@ -0,0 +1,32 @@ +import { + size, + pixel, + icon +} from '../preset'; + +// $ExpectType Icon +new AMap.Icon(); +// $ExpectType Icon +new AMap.Icon({}); +// $ExpectType Icon +new AMap.Icon({ + size, + imageOffset: pixel, + image: 'image uri', + imageSize: size +}); +// $ExpectType Icon +new AMap.Icon({ + size: [1, 2], + imageOffset: pixel, + image: 'image uri', + imageSize: [1, 2] +}); + +// $ExpectType Size +icon.getImageSize(); + +// $ExpectType void +icon.setImageSize(size); +// $ExpectType void +icon.setImageSize([1, 2]); diff --git a/types/amap-js-api/test/overlay/infoWindow.ts b/types/amap-js-api/test/overlay/infoWindow.ts new file mode 100644 index 0000000000..3fa4b0e656 --- /dev/null +++ b/types/amap-js-api/test/overlay/infoWindow.ts @@ -0,0 +1,81 @@ +import { + map, + lnglat, + size, + pixel, + div, + lnglatTuple +} from '../preset'; + +interface ExtraData { + test: number; +} + +// $ExpectType InfoWindow +new AMap.InfoWindow(); +// $ExpectType InfoWindow +new AMap.InfoWindow({}); +// $ExpectType InfoWindow +const infoWindow = new AMap.InfoWindow({ + isCustom: false, + autoMove: false, + closeWhenClickMap: false, + content: 'content', + size: [100, 100], + offset: new AMap.Pixel(10, 10), + position: lnglat, + showShadow: true +}); + +// $ExpectType void +infoWindow.open(map); +// $ExpectType void +infoWindow.open(map, lnglat); +// $ExpectType void +infoWindow.open(map, lnglatTuple); + +// $ExpectType void +infoWindow.close(); + +// $ExpectType boolean +infoWindow.getIsOpen(); + +// $ExpectType void +infoWindow.setContent('content'); +// $ExpectType void +infoWindow.setContent(div); + +// $ExpectType string | HTMLElement | undefined +infoWindow.getContent(); + +// $ExpectType void +infoWindow.setPosition(lnglat); +// $ExpectType void +infoWindow.setPosition(lnglatTuple); + +// $ExpectType LngLat | undefined +infoWindow.getPosition(); + +// $ExpectType Size | undefined +infoWindow.getSize(); + +infoWindow.on('change', (event: AMap.InfoWindow.EventMap['change']) => { + // $ExpectType "change" + event.type; + // $ExpectType InfoWindow + event.target; +}); + +infoWindow.on('close', (event: AMap.InfoWindow.EventMap['close']) => { + // $ExpectType "close" + event.type; + // $ExpectType InfoWindow + event.target; +}); + +infoWindow.on('open', (event: AMap.InfoWindow.EventMap['open']) => { + // $ExpectType "open" + event.type; + // $ExpectType InfoWindow + event.target; +}); diff --git a/types/amap-js-api/test/overlay/marker.ts b/types/amap-js-api/test/overlay/marker.ts new file mode 100644 index 0000000000..635ce724c8 --- /dev/null +++ b/types/amap-js-api/test/overlay/marker.ts @@ -0,0 +1,195 @@ +import { + map, + lnglat +} from '../preset'; + +declare var pixel: AMap.Pixel; +declare var domEle: HTMLElement; +declare var markerShape: AMap.MarkerShape; +declare var icon: AMap.Icon; + +interface ExtraData { + test: number; +} + +// $ExpectType Marker +new AMap.Marker(); +// $ExpectType Marker +new AMap.Marker(); +// $ExpectType Marker +new AMap.Marker({}); +// $ExpectType Marker +const marker = new AMap.Marker({ + map, + position: lnglat, + offset: pixel, + icon: 'iconUrl', + content: 'htmlString', + topWhenClick: true, + raiseOnDrag: true, + cursor: 'default', + visible: true, + zIndex: 10, + angle: 10, + autoRotation: true, + animation: 'AMAP_ANIMATION_BOUNCE', + shadow: icon, + title: '123', + clickable: true, + shape: markerShape, + extData: { + test: 123 + } +}); + +// $ExpectType void +marker.markOnAMAP({ + name: '123', + position: [1, 2] +}); +// $ExpectType void +marker.markOnAMAP(); +// $ExpectType void +marker.markOnAMAP({}); +// $ExpectType void +marker.markOnAMAP({ + position: [1, 2], + name: '123' +}); + +// $ExpectType Pixel +marker.getOffset(); + +// $ExpectType void +marker.setOffset(pixel); + +// $ExpectType void +marker.setAnimation('AMAP_ANIMATION_BOUNCE'); + +// $ExpectType AnimationName +marker.getAnimation(); + +// $ExpectType void +marker.setClickable(true); + +// $ExpectType boolean +marker.getClickable(); + +// $ExpectType LngLat | undefined +marker.getPosition(); + +// $ExpectType void +marker.setPosition(lnglat); + +// $ExpectType void +marker.setAngle(0); + +// $ExpectType void +marker.setLabel(); +// $ExpectType void +marker.setLabel({}); +// $ExpectType void +marker.setLabel({ + content: 'label content', + offset: pixel +}); + +// $ExpectType Label | undefined +marker.getLabel(); + +// $ExpectType number +marker.getAngle(); + +// $ExpectType void +marker.setzIndex(100); + +// $ExpectType number +marker.getzIndex(); + +// $ExpectType void +marker.setIcon('icon uri'); +// $ExpectType void +marker.setIcon(icon); + +// $ExpectType string | Icon | undefined +marker.getIcon(); + +// $ExpectType void +marker.setDraggable(true); + +// $ExpectType boolean +marker.getDraggable(); + +// $ExpectType void +marker.setCursor('default'); + +// $ExpectType void +marker.setContent('content'); +// $ExpectType void +marker.setContent(domEle); + +// $ExpectType string | HTMLElement +marker.getContent(); + +// $ExpectType void +marker.moveAlong([lnglat], 100); +// $ExpectError +marker.moveAlong([[1, 2]], 100); +// $ExpectType void +marker.moveAlong([lnglat], 100, t => t, false); + +// $ExpectType void +marker.moveTo(lnglat, 100); +// $ExpectType void +marker.moveTo([1, 2], 100); +// $ExpectType void +marker.moveTo([1, 2], 100, t => t); + +// $ExpectType void +marker.stopMove(); + +// $ExpectType boolean +marker.pauseMove(); + +// $ExpectType boolean +marker.resumeMove(); + +// $ExpectType void +marker.setMap(map); + +// $ExpectType void +marker.setTitle('title'); +// $ExpectError +marker.setTitle(); + +// $ExpectType string | undefined +marker.getTitle(); + +// $ExpectType void +marker.setTop(true); + +// $ExpectType boolean +marker.getTop(); + +// $ExpectType void +marker.setShadow(); +// $ExpectType void +marker.setShadow(icon); +// $ExpectType void +marker.setShadow('shadow url'); + +// $ExpectType string | Icon | undefined +marker.getShadow(); + +// $ExpectType void +marker.setShape(); +// $ExpectType void +marker.setShape(markerShape); + +// $ExpectType MarkerShape | undefined +marker.getShape(); + +marker.on('click', (event: AMap.Marker.EventMap['click']) => { + // $ExpectType {} | ExtraData + event.target.getExtData(); +}); diff --git a/types/amap-js-api/test/overlay/markerShape.ts b/types/amap-js-api/test/overlay/markerShape.ts new file mode 100644 index 0000000000..259b68cf20 --- /dev/null +++ b/types/amap-js-api/test/overlay/markerShape.ts @@ -0,0 +1,26 @@ +// $ExpectType MarkerShape +new AMap.MarkerShape({ + type: 'circle', + coords: [1, 1, 1] +}); +// $ExpectType MarkerShape +new AMap.MarkerShape({ + type: 'rect', + coords: [1, 1, 1, 2] +}); +// $ExpectType MarkerShape +new AMap.MarkerShape({ + type: 'poly', + coords: [1, 2, 3, 4, 5] +}); + +// $ExpectError +new AMap.MarkerShape({ + type: 'circle', + coords: [1, 1] +}); +// $ExpectError +new AMap.MarkerShape({ + type: 'rect', + coords: [1, 1, 1, 2, 2] +}); diff --git a/types/amap-js-api/test/overlay/overlay.ts b/types/amap-js-api/test/overlay/overlay.ts new file mode 100644 index 0000000000..6a301e7091 --- /dev/null +++ b/types/amap-js-api/test/overlay/overlay.ts @@ -0,0 +1,27 @@ +import { + map +} from '../preset'; +interface ExtraData { + test: number; +} +declare const overlay: AMap.Overlay; + +// $ExpectType void +overlay.show(); + +// $ExpectType void +overlay.hide(); + +// $ExpectType Map | null | undefined +overlay.getMap(); + +// $ExpectType void +overlay.setMap(map); +// $ExpectType void +overlay.setMap(null); + +// $ExpectError +overlay.setExtData({ any: 123 }); + +// $ExpectError ExtraData +overlay.getExtData(); diff --git a/types/amap-js-api/test/overlay/overlayGroup.ts b/types/amap-js-api/test/overlay/overlayGroup.ts new file mode 100644 index 0000000000..11e04f91cf --- /dev/null +++ b/types/amap-js-api/test/overlay/overlayGroup.ts @@ -0,0 +1,108 @@ +import { + map, + lnglat, + pixel, + circle, + marker, + markerShape, + icon +} from '../preset'; + +// $ExpectType OverlayGroup, any> +const overlayGroup2 = new AMap.OverlayGroup(); +// $ExpectType OverlayGroup, any> +new AMap.OverlayGroup(marker); +// $ExpectType OverlayGroup, any> +const overlayGroup = new AMap.OverlayGroup([marker]); + +// $ExpectType OverlayGroup, any> +overlayGroup.addOverlay(marker); +// $ExpectType OverlayGroup, any> +overlayGroup.addOverlay([marker]); +// $ExpectError +overlayGroup.addOverlay([circle]); + +// $ExpectType OverlayGroup, any> +overlayGroup.addOverlays(marker); +// $ExpectType OverlayGroup, any> +overlayGroup.addOverlays([marker]); + +// $ExpectType Marker[] +overlayGroup.getOverlays(); + +// $ExpectType boolean +overlayGroup.hasOverlay(marker); +// $ExpectType boolean +overlayGroup.hasOverlay(o => o === marker); + +// $ExpectType OverlayGroup, any> +overlayGroup.removeOverlay(marker); +// $ExpectType OverlayGroup, any> +overlayGroup.removeOverlay([marker]); + +// $ExpectType OverlayGroup, any> +overlayGroup.removeOverlays(marker); +// $ExpectType OverlayGroup, any> +overlayGroup.removeOverlays([marker]); + +// $ExpectType OverlayGroup, any> +overlayGroup.clearOverlays(); + +// $ExpectType OverlayGroup, any> +overlayGroup.eachOverlay(function(overlay, index, overlays) { + // $ExpectType Marker + overlay; + // $ExpectType number + index; + // $ExpectType Marker[] + overlays; + // $ExpectType Marker + this; +}); + +// $ExpectType OverlayGroup, any> +overlayGroup.setMap(null); +// $ExpectType OverlayGroup, any> +overlayGroup.setMap(map); + +// $ExpectType OverlayGroup, any> +overlayGroup2.setOptions({ + test: 1 +}); +// $ExpectType OverlayGroup, any> +overlayGroup.setOptions({ + map, + position: lnglat, + offset: pixel, + icon: 'iconUrl', + content: 'htmlString', + topWhenClick: true, + raiseOnDrag: true, + cursor: 'default', + visible: true, + zIndex: 10, + angle: 10, + autoRotation: true, + animation: 'AMAP_ANIMATION_BOUNCE', + shadow: icon, + title: '123', + clickable: true, + shape: markerShape, + extData: { + test: 123 + } +}); + +// $ExpectType OverlayGroup, any> +overlayGroup.show(); + +// $ExpectType OverlayGroup, any> +overlayGroup.hide(); + +type ClickEvent = AMap.MapsEvent<'click', AMap.Overlay>; +overlayGroup.on('click', (event: ClickEvent) => { + // $ExpectType "click" + event.type; + // $ExpectType Overlay + event.target; +}); diff --git a/types/amap-js-api/test/overlay/polygon.ts b/types/amap-js-api/test/overlay/polygon.ts new file mode 100644 index 0000000000..d41a597d45 --- /dev/null +++ b/types/amap-js-api/test/overlay/polygon.ts @@ -0,0 +1,123 @@ +import { + map, + lnglat, + lnglatTuple +} from '../preset'; + +interface ExtraData { + test: number; +} + +const path1 = [lnglatTuple, lnglatTuple, lnglatTuple, lnglatTuple, lnglatTuple]; +const path2 = [lnglat, lnglat, lnglat, lnglat, lnglat]; + +// $ExpectType Polygon +new AMap.Polygon(); +// $ExpectType Polygon +new AMap.Polygon({}); +// $ExpectType Polygon +const polygon = new AMap.Polygon({ + map, + zIndex: 10, + bubble: true, + cursor: 'pointer', + strokeColor: '#00FF00', + strokeOpacity: 0.3, + strokeWeight: 5, + fillColor: '#0000FF', + fillOpacity: 0.5, + draggable: true, + extData: { test: 1 }, + strokeStyle: 'dashed', + strokeDasharray: [2, 4], + path: path1 +}); + +// $ExpectType void +polygon.setPath(path1); +// $ExpectType void +polygon.setPath(path2); +// $ExpectType void +polygon.setPath([path1, path2]); + +// $ExpectType LngLat[] | LngLat[][] +polygon.getPath(); + +// $ExpectType void +polygon.setOptions({ + map, + zIndex: 10, + bubble: true, + cursor: 'pointer', + strokeColor: '#00FF00', + strokeOpacity: 0.8, + strokeWeight: 5, + fillColor: '#0000FF', + fillOpacity: 0.5, + draggable: true, + extData: { test: 1 }, + strokeStyle: 'dashed', + strokeDasharray: [4, 2], + path: [path2, path1] +}); + +const options = polygon.getOptions(); +// $ExpectType boolean | undefined +options.bubble; +// $ExpectType boolean | undefined +options.clickable; +// $ExpectType {} | ExtraData | undefined +options.extData; +// $ExpectType string | undefined +options.fillColor; +// $ExpectType number | undefined +options.fillOpacity; +// $ExpectType "miter" | "round" | "bevel" | undefined +options.lineJoin; +// $ExpectType Map | undefined +options.map; +// $ExpectType LngLat[] | LngLat[][] | undefined +options.path; +// $ExpectType string | undefined +options.strokeColor; +// $ExpectType number[] | undefined +options.strokeDasharray; +// $ExpectType number | undefined +options.strokeOpacity; +// $ExpectType "dashed" | "solid" | undefined +options.strokeStyle; +// $ExpectType number | undefined +options.strokeWeight; +// $ExpectType string | undefined +options.texture; +// $ExpectType number | undefined +options.zIndex; + +// $ExpectType Bounds | null +polygon.getBounds(); + +// $ExpectType number +polygon.getArea(); + +// $ExpectType void +polygon.setMap(null); +// $ExpectType void +polygon.setMap(map); + +// $ExpectType void +polygon.setExtData({ test: 1 }); + +// $ExpectType {} | ExtraData +polygon.getExtData(); + +// $ExpectType boolean +polygon.contains(lnglat); +// $ExpectType boolean +polygon.contains(lnglatTuple); + +polygon.on('click', (event: AMap.Polygon.EventMap['click']) => { + // $ExpectType "click" + event.type; + // $ExpectType Polygon + event.target; +}); diff --git a/types/amap-js-api/test/overlay/polyline.ts b/types/amap-js-api/test/overlay/polyline.ts new file mode 100644 index 0000000000..fc8d52b058 --- /dev/null +++ b/types/amap-js-api/test/overlay/polyline.ts @@ -0,0 +1,139 @@ +import { + map, + lnglat, + lnglatTuple +} from '../preset'; + +interface ExtraData { + test: number; +} + +// $ExpectType Polyline +new AMap.Polyline(); +// $ExpectType Polyline +new AMap.Polyline({}); +// $ExpectType Polyline +const polyline = new AMap.Polyline({ + map, + zIndex: 10, + bubble: true, + cursor: 'default', + geodesic: true, + isOutline: true, + borderWeight: 1, + outlineColor: '#AA0000', + path: [lnglat], + strokeColor: '#0000AA', + strokeOpacity: 0.5, + strokeWeight: 10, + strokeStyle: 'dashed', + strokeDasharray: [20, 10, 20], + lineJoin: 'bevel', + lineCap: 'butt', + draggable: true, + extData: { test: 1 }, + showDir: true +}); +// Polyline + +// $ExpectType void +polyline.setPath([lnglat]); +// $ExpectType void +polyline.setPath([lnglatTuple]); + +// $ExpectType void +polyline.setOptions({}); +// $ExpectType void +polyline.setOptions({ + map, + zIndex: 10, + bubble: true, + cursor: 'default', + geodesic: true, + isOutline: true, + borderWeight: 1, + outlineColor: '#AA0000', + path: [lnglat, lnglat], + strokeColor: '#0000AA', + strokeOpacity: 0.5, + strokeWeight: 10, + strokeStyle: 'dashed', + strokeDasharray: [20, 10, 20], + lineJoin: 'bevel', + lineCap: 'butt', + draggable: true, + extData: { test: 1 }, + showDir: true +}); + +const options = polyline.getOptions(); +// $ExpectType number | undefined +options.borderWeight; +// $ExpectType boolean | undefined +options.bubble; +// $ExpectType boolean | undefined +options.clickable; +// $ExpectType string | undefined +options.dirColor; +// $ExpectType string | undefined +options.dirImg; +// $ExpectType {} | ExtraData | undefined +options.extData; +// $ExpectType boolean | undefined +options.geodesic; +// $ExpectType boolean | undefined +options.isOutline; +// $ExpectType "round" | "butt" | "square" | undefined +options.lineCap; +// $ExpectType "miter" | "round" | "bevel" | undefined +options.lineJoin; +// $ExpectType Map | undefined +options.map; +// $ExpectType string | undefined +options.outlineColor; +// $ExpectType LngLat[] | undefined +options.path; +// $ExpectType boolean | undefined +options.showDir; +// $ExpectType string | undefined +options.strokeColor; +// $ExpectType number[] | undefined +options.strokeDasharray; +// $ExpectType number | undefined +options.strokeOpacity; +// $ExpectType "dashed" | "solid" | undefined +options.strokeStyle; +// $ExpectType number | undefined +options.strokeWeight; +// $ExpectType number | undefined +options.zIndex; + +// $ExpectType number +polyline.getLength(); + +// $ExpectType Bounds | null +polyline.getBounds(); + +// $ExpectType void +polyline.hide(); + +// $ExpectType void +polyline.show(); + +// $ExpectType void +polyline.setMap(null); +// $ExpectType void +polyline.setMap(map); + +// $ExpectType void +polyline.setExtData({test: 1}); + +// $ExpectType {} | ExtraData +polyline.getExtData(); + +polyline.on('click', (event: AMap.Polyline.EventMap['click']) => { + // $ExpectType "click" + event.type; + // $ExpectType Polyline + event.target; +}); diff --git a/types/amap-js-api/test/overlay/rectangle.ts b/types/amap-js-api/test/overlay/rectangle.ts new file mode 100644 index 0000000000..d2cafa8f09 --- /dev/null +++ b/types/amap-js-api/test/overlay/rectangle.ts @@ -0,0 +1,121 @@ +import { + map, + lnglat, + bounds, + lnglatTuple +} from '../preset'; + +interface ExtraData { + test: number; +} + +// $ExpectType Rectangle +new AMap.Rectangle(); +// $ExpectType Rectangle +new AMap.Rectangle({}); +// $ExpectType Rectangle +const rectangle = new AMap.Rectangle({ + map, + zIndex: 10, + bounds, + bubble: false, + cursor: 'pointer', + strokeColor: '#00FF00', + strokeOpacity: 0.8, + strokeWeight: 2, + fillColor: '#0000FF', + fillOpacity: 0.5, + strokeStyle: 'solid', + extData: { test: 1 }, + strokeDasharray: [1, 5] +}); + +// $ExpectType Bounds | undefined +rectangle.getBounds(); + +// $ExpectType void +rectangle.setBounds(bounds); + +// $ExpectType void +rectangle.setOptions({}); +// $ExpectType void +rectangle.setOptions({ + map, + zIndex: 10, + bounds, + bubble: false, + cursor: 'pointer', + strokeColor: '#00FF00', + strokeOpacity: 0.8, + strokeWeight: 2, + fillColor: '#0000FF', + fillOpacity: 0.5, + strokeStyle: 'solid', + extData: { test: 1 }, + strokeDasharray: [1, 5] +}); + +const options = rectangle.getOptions(); +// $ExpectType Bounds | undefined +options.bounds; +// $ExpectType boolean | undefined +options.bubble; +// $ExpectType boolean | undefined +options.clickable; +// $ExpectType {} | ExtraData | undefined +options.extData; +// $ExpectType string | undefined +options.fillColor; +// $ExpectType number | undefined +options.fillOpacity; +// $ExpectType "miter" | "round" | "bevel" | undefined +options.lineJoin; +// $ExpectType Map | undefined +options.map; +// $ExpectType LngLat[] | undefined +options.path; +// $ExpectType string | undefined +options.strokeColor; +// $ExpectType number[] | undefined +options.strokeDasharray; +// $ExpectType number | undefined +options.strokeOpacity; +// $ExpectType "dashed" | "solid" | undefined +options.strokeStyle; +// $ExpectType number | undefined +options.strokeWeight; +// $ExpectType string | undefined +options.texture; +// $ExpectType number | undefined +options.zIndex; + +// $ExpectType void +rectangle.hide(); + +// $ExpectType void +rectangle.show(); + +// $ExpectType void +rectangle.setExtData({test: 2}); + +// $ExpectType {} | ExtraData +rectangle.getExtData(); + +// $ExpectType boolean +rectangle.contains(lnglat); +// $ExpectType boolean +rectangle.contains(lnglatTuple); + +rectangle.on('click', (event: AMap.Rectangle.EventMap['click']) => { + // $ExpectType "click" + event.type; + // $ExpectType Rectangle + event.target; +}); + +rectangle.on('setBounds', (event: AMap.Rectangle.EventMap['setBounds']) => { + // $ExpectType "setBounds" + event.type; + // $ExpectError + event.target; +}); diff --git a/types/amap-js-api/test/overlay/text.ts b/types/amap-js-api/test/overlay/text.ts new file mode 100644 index 0000000000..c4d678493c --- /dev/null +++ b/types/amap-js-api/test/overlay/text.ts @@ -0,0 +1,169 @@ +import { + map, + marker, + lnglat, + pixel, + lnglatTuple, + icon +} from '../preset'; + +interface ExtraData { + test: number; +} + +// $ExpectType Text +new AMap.Text(); +// $ExpectType Text +new AMap.Text({}); +// $ExpectType Text +const text = new AMap.Text({ + text: 'content', + textAlign: 'center', + verticalAlign: 'top', + map, + position: lnglat, + offset: pixel, + topWhenClick: true, + bubble: true, + draggable: true, + raiseOnDrag: true, + cursor: 'default', + visible: true, + zIndex: 100, + angle: 45, + autoRotation: true, + animation: 'AMAP_ANIMATION_BOUNCE', + shadow: 'https://webapi.amap.com/theme/v1.3/markers/0.png', + title: 'title', + clickable: true, + extData: { test: 1 } +}); + +// $ExpectType string +text.getText(); + +// $ExpectType void +text.setText('123'); + +// $ExpectType void +text.setStyle({ + background: 'red', + width: '200px' +}); + +// $ExpectType void +text.markOnAMAP({ + name: '123', + position: lnglatTuple +}); + +// $ExpectType Pixel +text.getOffset(); + +// $ExpectType void +text.setOffset(pixel); + +// $ExpectType void +text.setAnimation('AMAP_ANIMATION_BOUNCE'); + +// $ExpectType AnimationName +text.getAnimation(); + +// $ExpectType void +text.setClickable(true); + +// $ExpectType boolean +text.getClickable(); + +// $ExpectType LngLat | undefined +text.getPosition(); + +// $ExpectType void +text.setAngle(10); + +// $ExpectType number +text.getAngle(); + +// $ExpectType void +text.setzIndex(1); + +// $ExpectType number +text.getzIndex(); + +// $ExpectType void +text.setDraggable(true); + +// $ExpectType boolean +text.getDraggable(); + +// $ExpectType void +text.hide(); + +// $ExpectType void +text.show(); + +// $ExpectType void +text.setCursor('default'); + +// $ExpectType void +text.moveAlong([lnglat], 100); + +// $ExpectType void +text.moveAlong([lnglat], 100); +// $ExpectError +text.moveAlong([[1, 2]], 100); +// $ExpectType void +text.moveAlong([lnglat], 100, t => t, false); + +// $ExpectType void +text.moveTo(lnglat, 100); +// $ExpectType void +text.moveTo([1, 2], 100); +// $ExpectType void +text.moveTo([1, 2], 100, t => t); + +// $ExpectType void +text.stopMove(); + +// $ExpectType boolean +text.pauseMove(); + +// $ExpectType boolean +text.resumeMove(); + +// $ExpectType void +text.setMap(map); + +// $ExpectType void +text.setTitle('title'); +// $ExpectError +text.setTitle(); + +// $ExpectType string | undefined +text.getTitle(); + +// $ExpectType void +text.setTop(true); + +// $ExpectType boolean +text.getTop(); + +// $ExpectType void +text.setShadow(); +// $ExpectType void +text.setShadow(icon); +// $ExpectType void +text.setShadow('shadow url'); + +// $ExpectType void +text.setExtData({test: 1}); + +// $ExpectType {} | ExtraData +text.getExtData(); + +text.on('click', (event: AMap.Text.EventMap['click']) => { + // $ExpectType "click" + event.type; + // $ExpectType Text + event.target; +}); diff --git a/types/amap-js-api/test/pixel.ts b/types/amap-js-api/test/pixel.ts new file mode 100644 index 0000000000..bcb96e4b77 --- /dev/null +++ b/types/amap-js-api/test/pixel.ts @@ -0,0 +1,42 @@ +import { + pixel +} from './preset'; + +// $ExpectType Pixel +new AMap.Pixel(10, 20); +// $ExpectType Pixel +new AMap.Pixel(10, 20); + +// $ExpectType number +pixel.getX(); + +// $ExpectType number +pixel.getY(); + +// $ExpectType boolean +pixel.equals(pixel); + +// $ExpectType string +pixel.toString(); + +// $ExpectType Pixel +pixel.add({ x: 1, y: 2 }); +// $ExpectType Pixel +pixel.add({ x: 1, y: 2 }, false); + +// $ExpectType Pixel +pixel.round(); + +// $ExpectType Pixel +pixel.floor(); + +// $ExpectType number +pixel.length(); + +// $ExpectType number | null +pixel.direction(); + +// $ExpectType Pixel +pixel.toFixed(); +// $ExpectType Pixel +pixel.toFixed(2); diff --git a/types/amap-js-api/test/preset.ts b/types/amap-js-api/test/preset.ts new file mode 100644 index 0000000000..2c7bb37d59 --- /dev/null +++ b/types/amap-js-api/test/preset.ts @@ -0,0 +1,29 @@ +declare const map: AMap.Map; +declare const lnglat: AMap.LngLat; +declare const size: AMap.Size; +declare const lnglatTuple: [number, number]; +declare const pixel: AMap.Pixel; +declare const marker: AMap.Marker; +declare const circle: AMap.Circle; +declare const markerShape: AMap.MarkerShape; +declare const icon: AMap.Icon; +declare const bounds: AMap.Bounds; +declare const div: HTMLDivElement; +declare const polygon: AMap.Polygon; +declare const lang: AMap.Lang; + +export { + map, + lnglat, + size, + lnglatTuple, + pixel, + marker, + circle, + markerShape, + icon, + bounds, + div, + polygon, + lang +}; diff --git a/types/amap-js-api/test/size.ts b/types/amap-js-api/test/size.ts new file mode 100644 index 0000000000..bdd700f532 --- /dev/null +++ b/types/amap-js-api/test/size.ts @@ -0,0 +1,16 @@ +import { size } from './preset'; + +// $ExpectType Size +new AMap.Size(10, 20); + +// $ExpectType number +size.getHeight(); + +// $ExpectType number +size.getWidth(); + +// $ExpectType string +size.toString(); + +// $ExpectType boolean +size.contains({ x: 10, y: 10 }); diff --git a/types/amap-js-api/test/util.ts b/types/amap-js-api/test/util.ts new file mode 100644 index 0000000000..c238070e21 --- /dev/null +++ b/types/amap-js-api/test/util.ts @@ -0,0 +1,79 @@ +import * as preset from './preset'; + +const util = AMap.Util; + +// $ExpectType string +util.colorNameToHex('colorName'); + +// $ExpectType string +util.rgbHex2Rgba('rgbHex'); + +// $ExpectType string +util.argbHex2Rgba('argbHex'); + +// $ExpectType boolean +util.isEmpty({}); +// $ExpectError +util.isEmpty(1); + +// $ExpectType number[] +util.deleteItemFromArray([1], 1); + +// $ExpectType number[] +util.deleteItemFromArrayByIndex([1], 1); + +// $ExpectType number +util.indexOf([1], 1); +// $ExpectError +util.indexOf([1], '1'); + +// $ExpectType number +util.format(1); +// $ExpectType number +util.format(1, 1); + +declare const value1: number | number[]; +// $ExpectType boolean +util.isArray(value1); +if (util.isArray(value1)) { + // $ExpectType number[] + value1; +} else { + // $ExpectType number + value1; +} + +declare const value2: number | HTMLElement; +// $ExpectType boolean +util.isDOM(value2); +if (util.isDOM(value2)) { + // $ExpectType HTMLElement + value2; +} else { + // $ExpectType number + value2; +} + +// $ExpectType boolean +util.includes([1], 1); +// $ExpectError +util.includes([1], '1'); + +// $ExpectType number +util.requestIdleCallback(() => { }); +// $ExpectType number +const idleCallbackHandle = util.requestIdleCallback(() => { }, { timeout: 1 }); + +// $ExpectType void +util.cancelIdleCallback(idleCallbackHandle); + +// $ExpectType number +util.requestAnimFrame(() => { }); +// $ExpectType number +const animFrameHandle = util.requestAnimFrame(function () { + // $ExpectType number + this.test; +}, { test: 1 }); + +// $ExpectType void +util.cancelAnimFrame(animFrameHandle); diff --git a/types/amap-js-api/test/view2d.ts b/types/amap-js-api/test/view2d.ts new file mode 100644 index 0000000000..2560922a5a --- /dev/null +++ b/types/amap-js-api/test/view2d.ts @@ -0,0 +1,22 @@ +import { lnglat } from './preset'; + +// $ExpectType View2D +new AMap.View2D(); +// $ExpectType View2D +new AMap.View2D({}); + +// $ExpectType View2D +new AMap.View2D({ + center: [1, 2], + rotation: 1, + zoom: 10, + crs: 'EPGS3395' +}); + +// $ExpectType View2D +const view2d = new AMap.View2D({ + center: lnglat +}); + +// $ExpectType View2D +view2d.on('complete', () => { }); diff --git a/types/amap-js-api/tsconfig.json b/types/amap-js-api/tsconfig.json new file mode 100644 index 0000000000..3e8b8b3282 --- /dev/null +++ b/types/amap-js-api/tsconfig.json @@ -0,0 +1,20 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6", + "dom" + ], + "noEmit": true, + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "forceConsistentCasingInFileNames": true + } +} diff --git a/types/amap-js-api/tslint.json b/types/amap-js-api/tslint.json new file mode 100644 index 0000000000..ab1e56673f --- /dev/null +++ b/types/amap-js-api/tslint.json @@ -0,0 +1,10 @@ +{ + "extends": "dtslint/dt.json", + "rules": { + "only-arrow-functions": false, + "space-before-function-paren": false, + "no-var-keyword": false, + "no-unnecessary-class": false, + "file-name-casing": false + } +} diff --git a/types/amap-js-api/type-util.d.ts b/types/amap-js-api/type-util.d.ts new file mode 100644 index 0000000000..1ced3d69c1 --- /dev/null +++ b/types/amap-js-api/type-util.d.ts @@ -0,0 +1,12 @@ +type Omit = { + [K in Exclude]: T[K] +}; + +type OptionalKey = { [K in keyof T]-?: undefined extends T[K] ? K : never }[keyof T]; +// type OmitUndefined = Omit; +// type PickUndefined = Omit>; + +type Merge = + { [K in Exclude>]-?: O[K]; } & + { [K in Extract, OptionalKey>]?: O[K]; } & + T; diff --git a/types/amap-js-api/util.d.ts b/types/amap-js-api/util.d.ts new file mode 100644 index 0000000000..70b48c31d1 --- /dev/null +++ b/types/amap-js-api/util.d.ts @@ -0,0 +1,37 @@ +declare namespace AMap { + namespace Util { + function colorNameToHex(colorName: string): string; + + function rgbHex2Rgba(hex: string): string; + + function argbHex2Rgba(hex: string): string; + + function isEmpty(obj: object): boolean; + + function deleteItemFromArray(array: T[], item: T): T[]; + + function deleteItemFromArrayByIndex(array: T[], index: number): T[]; + + function indexOf(array: T[], item: T): number; + + function format(floatNumber: number, digits?: number): number; + + function isArray(data: any): data is any[]; + + function isDOM(data: any): data is HTMLElement; + + function includes(array: T[], item: T): boolean; + + function requestIdleCallback(callback: (...args: any[]) => any, options?: { timeout?: number }): number; + + function cancelIdleCallback(handle: number): void; + + function requestAnimFrame(callback: (this: C, ...args: any[]) => any, context?: C): number; + + function cancelAnimFrame(handle: number): void; + + function color2RgbaArray(color: string | number[]): [number, number, number, number]; + + function color2Rgba(color: string | number[]): string; + } +} diff --git a/types/amap-js-api/view2D.d.ts b/types/amap-js-api/view2D.d.ts new file mode 100644 index 0000000000..d662b4c50e --- /dev/null +++ b/types/amap-js-api/view2D.d.ts @@ -0,0 +1,13 @@ +declare namespace AMap { + namespace View2D { + interface Options { + center?: LocationValue; + rotation?: number; + zoom?: number; + crs?: 'EPGS3857' | 'EPGS3395' | 'EPGS4326'; + } + } + class View2D extends EventEmitter { + constructor(options?: View2D.Options); + } +} From ba755ce6a7b8bc72e05301757cb66c2d73ae14e6 Mon Sep 17 00:00:00 2001 From: breeze9527 Date: Mon, 25 Feb 2019 13:31:45 +0800 Subject: [PATCH 2/6] [amap-js-api] list files in tsconfig.json --- types/amap-js-api/tsconfig.json | 89 ++++++++++++++++++++++++++++++++- 1 file changed, 88 insertions(+), 1 deletion(-) diff --git a/types/amap-js-api/tsconfig.json b/types/amap-js-api/tsconfig.json index 3e8b8b3282..8d2306a1a6 100644 --- a/types/amap-js-api/tsconfig.json +++ b/types/amap-js-api/tsconfig.json @@ -16,5 +16,92 @@ ], "types": [], "forceConsistentCasingInFileNames": true - } + }, + "files": [ + "array-bounds.d.ts", + "bounds.d.ts", + "browser.d.ts", + "common.d.ts", + "convert-from.d.ts", + "dom-util.d.ts", + "event.d.ts", + "geometry-util.d.ts", + "index.d.ts", + "layer/building.d.ts", + "layer/flexible.d.ts", + "layer/layer.d.ts", + "layer/layerGroup.d.ts", + "layer/massMarks.d.ts", + "layer/mediaLayer.d.ts", + "layer/tileLayer.d.ts", + "layer/wms.d.ts", + "layer/wmts.d.ts", + "lngLat.d.ts", + "map.d.ts", + "overlay/bezierCurve.d.ts", + "overlay/circle.d.ts", + "overlay/circleMarker.d.ts", + "overlay/contextMenu.d.ts", + "overlay/ellipse.d.ts", + "overlay/geoJSON.d.ts", + "overlay/icon.d.ts", + "overlay/infoWindow.d.ts", + "overlay/marker.d.ts", + "overlay/markerShape.d.ts", + "overlay/overlay.d.ts", + "overlay/overlayGroup.d.ts", + "overlay/pathOverlay.d.ts", + "overlay/polygon.d.ts", + "overlay/polyline.d.ts", + "overlay/rectangle.d.ts", + "overlay/shapeOverlay.d.ts", + "overlay/text.d.ts", + "pixel.d.ts", + "size.d.ts", + "test/arryBounds.ts", + "test/bounds.ts", + "test/browser.ts", + "test/convert-from.ts", + "test/dom-util.ts", + "test/event.ts", + "test/geometry-util.ts", + "test/layer/buildings.ts", + "test/layer/canvasLayer.ts", + "test/layer/flexible.ts", + "test/layer/imageLayer.ts", + "test/layer/layer.ts", + "test/layer/layerGroup.ts", + "test/layer/massMarks.ts", + "test/layer/tileLayer.ts", + "test/layer/videoLayer.ts", + "test/layer/wms.ts", + "test/layer/wmts.ts", + "test/lnglat.ts", + "test/map.ts", + "test/overlay/bezierCurve.ts", + "test/overlay/circle.ts", + "test/overlay/contextMenu.ts", + "test/overlay/ellipse.ts", + "test/overlay/geoJSON.ts", + "test/overlay/icon.ts", + "test/overlay/infoWindow.ts", + "test/overlay/marker.ts", + "test/overlay/markerShape.ts", + "test/overlay/overlay.ts", + "test/overlay/overlayGroup.ts", + "test/overlay/polygon.ts", + "test/overlay/polyline.ts", + "test/overlay/rectangle.ts", + "test/overlay/text.ts", + "test/pixel.ts", + "test/preset.ts", + "test/size.ts", + "test/util.ts", + "test/view2d.ts", + "tsconfig.json", + "tslint.json", + "type-util.d.ts", + "util.d.ts", + "view2D.d.ts" + ] } From 264b33318697a9c2269c0ae1bd690d161995f6d6 Mon Sep 17 00:00:00 2001 From: breeze9527 Date: Mon, 25 Feb 2019 13:44:27 +0800 Subject: [PATCH 3/6] [amap-js-api] remove .json in files in tsconfig.json --- types/amap-js-api/tsconfig.json | 2 -- 1 file changed, 2 deletions(-) diff --git a/types/amap-js-api/tsconfig.json b/types/amap-js-api/tsconfig.json index 8d2306a1a6..e63a35d326 100644 --- a/types/amap-js-api/tsconfig.json +++ b/types/amap-js-api/tsconfig.json @@ -98,8 +98,6 @@ "test/size.ts", "test/util.ts", "test/view2d.ts", - "tsconfig.json", - "tslint.json", "type-util.d.ts", "util.d.ts", "view2D.d.ts" From b39156db9fb2a4ae5fb9b8a2b4c2aaa706b2e414 Mon Sep 17 00:00:00 2001 From: breeze9527 Date: Mon, 25 Feb 2019 14:49:36 +0800 Subject: [PATCH 4/6] [amap-js-api] no-restricted-globals --- types/amap-js-api/test/event.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/types/amap-js-api/test/event.ts b/types/amap-js-api/test/event.ts index 8678045158..8061b0d747 100644 --- a/types/amap-js-api/test/event.ts +++ b/types/amap-js-api/test/event.ts @@ -43,7 +43,7 @@ AMap.event.addListener(map, 'click', (event: AMap.Map.EventMap['click']) => { }); // $ExpectType EventListener<1> -AMap.event.addListenerOnce(map, 'hotspotclick', function (event: AMap.Map.EventMap['hotspotclick']) { +const eventListener = AMap.event.addListenerOnce(map, 'hotspotclick', function (event: AMap.Map.EventMap['hotspotclick']) { // $ExpectType "hotspotclick" event.type; // $ExpectType string @@ -54,7 +54,6 @@ AMap.event.addListenerOnce(map, 'hotspotclick', function (event: AMap.Map.EventM this.test; }, { test: 1 }); -declare const eventListener: AMap.event.EventListener<0>; // $ExpectType void AMap.event.removeListener(eventListener); From 704068364b2b32773ca32a8b2178625dec4715f7 Mon Sep 17 00:00:00 2001 From: breeze9527 Date: Thu, 7 Mar 2019 14:26:10 +0800 Subject: [PATCH 5/6] [amap-js-api] merge test file & update lint rule --- types/amap-js-api/amap-js-api-tests.ts | 3376 +++++++++++++++++ types/amap-js-api/index.d.ts | 2 +- types/amap-js-api/overlay/markerShape.d.ts | 2 +- types/amap-js-api/test/arryBounds.ts | 18 - types/amap-js-api/test/bounds.ts | 30 - types/amap-js-api/test/browser.ts | 141 - types/amap-js-api/test/convert-from.ts | 25 - types/amap-js-api/test/dom-util.ts | 47 - types/amap-js-api/test/event.ts | 74 - types/amap-js-api/test/geometry-util.ts | 158 - types/amap-js-api/test/layer/buildings.ts | 40 - types/amap-js-api/test/layer/canvasLayer.ts | 53 - types/amap-js-api/test/layer/flexible.ts | 54 - types/amap-js-api/test/layer/imageLayer.ts | 51 - types/amap-js-api/test/layer/layer.ts | 34 - types/amap-js-api/test/layer/layerGroup.ts | 115 - types/amap-js-api/test/layer/massMarks.ts | 83 - types/amap-js-api/test/layer/tileLayer.ts | 60 - types/amap-js-api/test/layer/videoLayer.ts | 51 - types/amap-js-api/test/layer/wms.ts | 89 - types/amap-js-api/test/layer/wmts.ts | 69 - types/amap-js-api/test/lnglat.ts | 48 - types/amap-js-api/test/map.ts | 338 -- types/amap-js-api/test/overlay/bezierCurve.ts | 155 - types/amap-js-api/test/overlay/circle.ts | 150 - types/amap-js-api/test/overlay/contextMenu.ts | 48 - types/amap-js-api/test/overlay/ellipse.ts | 117 - types/amap-js-api/test/overlay/geoJSON.ts | 106 - types/amap-js-api/test/overlay/icon.ts | 32 - types/amap-js-api/test/overlay/infoWindow.ts | 81 - types/amap-js-api/test/overlay/marker.ts | 195 - types/amap-js-api/test/overlay/markerShape.ts | 26 - types/amap-js-api/test/overlay/overlay.ts | 27 - .../amap-js-api/test/overlay/overlayGroup.ts | 108 - types/amap-js-api/test/overlay/polygon.ts | 123 - types/amap-js-api/test/overlay/polyline.ts | 139 - types/amap-js-api/test/overlay/rectangle.ts | 121 - types/amap-js-api/test/overlay/text.ts | 169 - types/amap-js-api/test/pixel.ts | 42 - types/amap-js-api/test/preset.ts | 29 - types/amap-js-api/test/size.ts | 16 - types/amap-js-api/test/util.ts | 79 - types/amap-js-api/test/view2d.ts | 22 - types/amap-js-api/tsconfig.json | 43 +- types/amap-js-api/tslint.json | 9 +- 45 files changed, 3381 insertions(+), 3414 deletions(-) create mode 100644 types/amap-js-api/amap-js-api-tests.ts delete mode 100644 types/amap-js-api/test/arryBounds.ts delete mode 100644 types/amap-js-api/test/bounds.ts delete mode 100644 types/amap-js-api/test/browser.ts delete mode 100644 types/amap-js-api/test/convert-from.ts delete mode 100644 types/amap-js-api/test/dom-util.ts delete mode 100644 types/amap-js-api/test/event.ts delete mode 100644 types/amap-js-api/test/geometry-util.ts delete mode 100644 types/amap-js-api/test/layer/buildings.ts delete mode 100644 types/amap-js-api/test/layer/canvasLayer.ts delete mode 100644 types/amap-js-api/test/layer/flexible.ts delete mode 100644 types/amap-js-api/test/layer/imageLayer.ts delete mode 100644 types/amap-js-api/test/layer/layer.ts delete mode 100644 types/amap-js-api/test/layer/layerGroup.ts delete mode 100644 types/amap-js-api/test/layer/massMarks.ts delete mode 100644 types/amap-js-api/test/layer/tileLayer.ts delete mode 100644 types/amap-js-api/test/layer/videoLayer.ts delete mode 100644 types/amap-js-api/test/layer/wms.ts delete mode 100644 types/amap-js-api/test/layer/wmts.ts delete mode 100644 types/amap-js-api/test/lnglat.ts delete mode 100644 types/amap-js-api/test/map.ts delete mode 100644 types/amap-js-api/test/overlay/bezierCurve.ts delete mode 100644 types/amap-js-api/test/overlay/circle.ts delete mode 100644 types/amap-js-api/test/overlay/contextMenu.ts delete mode 100644 types/amap-js-api/test/overlay/ellipse.ts delete mode 100644 types/amap-js-api/test/overlay/geoJSON.ts delete mode 100644 types/amap-js-api/test/overlay/icon.ts delete mode 100644 types/amap-js-api/test/overlay/infoWindow.ts delete mode 100644 types/amap-js-api/test/overlay/marker.ts delete mode 100644 types/amap-js-api/test/overlay/markerShape.ts delete mode 100644 types/amap-js-api/test/overlay/overlay.ts delete mode 100644 types/amap-js-api/test/overlay/overlayGroup.ts delete mode 100644 types/amap-js-api/test/overlay/polygon.ts delete mode 100644 types/amap-js-api/test/overlay/polyline.ts delete mode 100644 types/amap-js-api/test/overlay/rectangle.ts delete mode 100644 types/amap-js-api/test/overlay/text.ts delete mode 100644 types/amap-js-api/test/pixel.ts delete mode 100644 types/amap-js-api/test/preset.ts delete mode 100644 types/amap-js-api/test/size.ts delete mode 100644 types/amap-js-api/test/util.ts delete mode 100644 types/amap-js-api/test/view2d.ts diff --git a/types/amap-js-api/amap-js-api-tests.ts b/types/amap-js-api/amap-js-api-tests.ts new file mode 100644 index 0000000000..41b0638526 --- /dev/null +++ b/types/amap-js-api/amap-js-api-tests.ts @@ -0,0 +1,3376 @@ +/** + * preset.ts + */ + +declare const map: AMap.Map; +declare const lnglat: AMap.LngLat; +declare const size: AMap.Size; +declare const lnglatTuple: [number, number]; +declare const pixel: AMap.Pixel; +declare const markerShape: AMap.MarkerShape; +declare const icon: AMap.Icon; +declare const bounds: AMap.Bounds; +declare const div: HTMLDivElement; +declare const lang: AMap.Lang; +declare const domEle: HTMLElement; +declare const canvasEle: HTMLCanvasElement; +declare const imgEle: HTMLImageElement; + +declare const circle: AMap.Circle; +declare const marker: AMap.Marker; +declare const layer: AMap.Layer; +declare const tileLayer: AMap.TileLayer; +declare const massMarksLayer: AMap.MassMarks; + +// declare const videoLayer: AMap.VideoLayer; +// declare const buildings: AMap.Buildings; +// declare const canvasLayer: AMap.CanvasLayer; +// declare const flexible: AMap.TileLayer.Flexible; +// declare const imageLayer: AMap.ImageLayer; +// declare const tileLayerGroup: AMap.LayerGroup; +// declare const layerGroup: AMap.LayerGroup; +// declare const trafficLayer: AMap.TileLayer.Traffic; +// declare const bezierCurve: AMap.BezierCurve; +// declare const contextMenu: AMap.ContextMenu; +// declare const polyline: AMap.Polyline; +// declare const polygon: AMap.Polygon; + +/** + * arryBounds.ts + */ + +// $ExpectType ArrayBounds +const testArrayBounds = new AMap.ArrayBounds([lnglat, lnglat, lnglat]); + +// $ExpectType LngLat[] +testArrayBounds.bounds; + +// $ExpectType boolean +testArrayBounds.contains(lnglat); + +// $ExpectType Bounds +testArrayBounds.toBounds(); + +// $ExpectType LngLat +testArrayBounds.getCenter(); + +/** + * bounds.ts + */ + +// $ExpectType Bounds +const testBounds = new AMap.Bounds(lnglat, lnglat); + +// $ExpectType boolean +testBounds.contains(lnglat); +// $ExpectType boolean +testBounds.contains(lnglatTuple); + +// $ExpectType LngLat +testBounds.getCenter(); + +// $ExpectType LngLat +testBounds.getSouthWest(); + +// $ExpectType LngLat +testBounds.getSouthEast(); + +// $ExpectType LngLat +testBounds.getNorthEast(); + +// $ExpectType LngLat +testBounds.getNorthWest(); + +// $ExpectType string +testBounds.toString(); + +/** + * browser.ts + */ + +const brwoser = AMap.Browser; + +// $ExpectType string +brwoser.ua; + +// $ExpectType boolean +brwoser.mobile; + +const plat: 'android' | 'ios' | 'windows' | 'mac' | 'other' = brwoser.plat; + +// $ExpectType boolean +brwoser.mac; + +// $ExpectType boolean +brwoser.windows; + +// $ExpectType boolean +brwoser.ios; + +// $ExpectType boolean +brwoser.iPad; + +// $ExpectType boolean +brwoser.iPhone; + +// $ExpectType boolean +brwoser.android; + +// $ExpectType boolean +brwoser.android23; + +// $ExpectType boolean +brwoser.chrome; + +// $ExpectType boolean +brwoser.firefox; + +// $ExpectType boolean +brwoser.safari; + +// $ExpectType boolean +brwoser.wechat; + +// $ExpectType boolean +brwoser.uc; + +// $ExpectType boolean +brwoser.qq; + +// $ExpectType boolean +brwoser.ie; + +// $ExpectType boolean +brwoser.ie6; + +// $ExpectType boolean +brwoser.ie7; + +// $ExpectType boolean +brwoser.ie8; + +// $ExpectType boolean +brwoser.ie9; + +// $ExpectType boolean +brwoser.ie10; + +// $ExpectType boolean +brwoser.ie11; + +// $ExpectType boolean +brwoser.edge; + +// $ExpectType boolean +brwoser.ielt9; + +// $ExpectType boolean +brwoser.baidu; + +// $ExpectType boolean +brwoser.isLocalStorage; + +// $ExpectType boolean +brwoser.isGeolocation; + +// $ExpectType boolean +brwoser.mobileWebkit; + +// $ExpectType boolean +brwoser.mobileWebkit3d; + +// $ExpectType boolean +brwoser.mobileOpera; + +// $ExpectType boolean +brwoser.retina; + +// $ExpectType boolean +brwoser.touch; + +// $ExpectType boolean +brwoser.msPointer; + +// $ExpectType boolean +brwoser.pointer; + +// $ExpectType boolean +brwoser.webkit; + +// $ExpectType boolean +brwoser.ie3d; + +// $ExpectType boolean +brwoser.webkit3d; + +// $ExpectType boolean +brwoser.gecko3d; + +// $ExpectType boolean +brwoser.opera3d; + +// $ExpectType boolean +brwoser.any3d; + +// $ExpectType boolean +brwoser.isCanvas; + +// $ExpectType boolean +brwoser.isSvg; + +// $ExpectType boolean +brwoser.isVML; + +// $ExpectType boolean +brwoser.isWorker; + +// $ExpectType boolean +brwoser.isWebsocket; + +// $ExpectType boolean +brwoser.isWebGL(); + +/** + * convert-from.ts + */ + +declare const convertType: 'baidu' | 'mapbar' | 'gps' | null; +// $ExpectType void +AMap.convertFrom(lnglat, convertType, (status, result) => { + const temp: 'complete' | 'error' = status; + if (typeof result !== 'string') { + // $ExpectType string + result.info; + // $ExpectType LngLat[] + result.locations; + } else { + // $ExpectType string + result; + } +}); +// $ExpectType void +AMap.convertFrom([lnglat], null, () => { }); +// $ExpectType void +AMap.convertFrom(lnglatTuple, null, () => { }); +// $ExpectType void +AMap.convertFrom([lnglatTuple], null, () => { }); + +/** + * dom-util.ts + */ + +const domUtil = AMap.DomUtil; + +// $ExpectType Size +domUtil.getViewport(div); + +// $ExpectType Pixel +domUtil.getViewportOffset(div); + +// $ExpectType HTMLDivElement +domUtil.create('div'); +// $ExpectType HTMLAnchorElement +domUtil.create('a'); +// $ExpectType HTMLDivElement +domUtil.create('div', div); +// $ExpectType HTMLDivElement +domUtil.create('div', div, 'className'); + +// $ExpectType void +domUtil.setClass(div); +// $ExpectType void +domUtil.setClass(div, 'className'); + +// $ExpectType boolean +domUtil.hasClass(div, 'className'); + +// $ExpectType void +domUtil.removeClass(div, 'className'); + +// $ExpectType void +domUtil.setOpacity(div, 1); + +// $ExpectType void +domUtil.rotate(div, 10); +// $ExpectType void +domUtil.rotate(div, 10, { x: 10, y: 10 }); + +const util2: typeof AMap.DomUtil = domUtil.setCss(div, { textAlign: 'left' }); +// $ExpectError +domUtil.setCss(div, { textAlign: 10 }); + +// $ExpectType void +domUtil.empty(div); + +// $ExpectType void +domUtil.remove(div); + +/** + * event.ts + */ + +// $ExpectType Map +map.on('hotspotclick', (event: AMap.Map.EventMap['hotspotclick']) => { + // $ExpectType "hotspotclick" + event.type; + // $ExpectType string + event.id; + // $ExpectType LngLat + event.lnglat; +}); + +// $ExpectType EventListener<0> +AMap.event.addDomListener(div, 'click', event => { + // $ExpectType number + event.clientX; +}); + +// $ExpectType EventListener<1> +AMap.event.addListener(map, 'hotspotclick', function(event: AMap.Map.EventMap['hotspotclick']) { + // $ExpectType "hotspotclick" + event.type; + // $ExpectType string + event.id; + // $ExpectType LngLat + event.lnglat; + // $ExpectType number + this.test; +}, { test: 1 }); +AMap.event.addListener(map, 'click', (event: AMap.Map.EventMap['click']) => { + // $ExpectType "click" + event.type; + // $ExpectType LngLat + event.lnglat; + // $ExpectType Map + event.target; +}); + +// $ExpectType EventListener<1> +const eventListener = AMap.event.addListenerOnce(map, 'hotspotclick', function(event: AMap.Map.EventMap['hotspotclick']) { + // $ExpectType "hotspotclick" + event.type; + // $ExpectType string + event.id; + // $ExpectType LngLat + event.lnglat; + // $ExpectType number + this.test; +}, { test: 1 }); + +// $ExpectType void +AMap.event.removeListener(eventListener); + +// $ExpectType void +AMap.event.trigger(map, 'click', { + lnglat, + pixel, + target: map +}); +// $ExpectType void +AMap.event.trigger(map, 'hotspotclick', { + lnglat, + name: 'name', + id: 'id', + isIndoorPOI: true +}); +// $ExpectType void +AMap.event.trigger(map, 'complete'); + +/** + * geometry-util.ts + */ + +{ + const point = lnglat; + const pointTuple = lnglatTuple; + const line = [point]; + const lineTuple = [pointTuple]; + const ring = [point]; + const ringTuple = [pointTuple]; + const polygon = [ring]; + const polygonTuple = [ringTuple]; + const geometryUtil = AMap.GeometryUtil; + + // $ExpectType number + geometryUtil.distance(point, point); + // $ExpectType number + geometryUtil.distance(pointTuple, pointTuple); + // $ExpectType number + geometryUtil.distance(point, line); + // $ExpectType number + geometryUtil.distance(pointTuple, lineTuple); + + // $ExpectType number + geometryUtil.ringArea(ring); + // $ExpectType number + geometryUtil.ringArea(ringTuple); + + // $ExpectType boolean + geometryUtil.isClockwise(ring); + // $ExpectType boolean + geometryUtil.isClockwise(ringTuple); + + // $ExpectType number + geometryUtil.distanceOfLine(line); + // $ExpectType number + geometryUtil.distanceOfLine(lineTuple); + + // $ExpectType [number, number][] + geometryUtil.ringRingClip(ring, ring); + // $ExpectType [number, number][] + geometryUtil.ringRingClip(ringTuple, ringTuple); + + // $ExpectType boolean + geometryUtil.doesRingRingIntersect(ring, ring); + // $ExpectType boolean + geometryUtil.doesRingRingIntersect(ringTuple, ringTuple); + + // $ExpectType boolean + geometryUtil.doesLineRingIntersect(line, ring); + // $ExpectType boolean + geometryUtil.doesLineRingIntersect(lineTuple, ringTuple); + + // $ExpectType boolean + geometryUtil.doesLineLineIntersect(line, line); + // $ExpectType boolean + geometryUtil.doesLineLineIntersect(lineTuple, lineTuple); + + // $ExpectType boolean + geometryUtil.doesSegmentPolygonIntersect(point, point, polygon); + // $ExpectType boolean + geometryUtil.doesSegmentPolygonIntersect(pointTuple, pointTuple, polygonTuple); + + // $ExpectType boolean + geometryUtil.doesSegmentRingIntersect(point, point, ring); + // $ExpectType boolean + geometryUtil.doesSegmentRingIntersect(pointTuple, pointTuple, ringTuple); + + // $ExpectType boolean + geometryUtil.doesSegmentLineIntersect(point, point, line); + // $ExpectType boolean + geometryUtil.doesSegmentLineIntersect(pointTuple, pointTuple, lineTuple); + + // $ExpectType boolean + geometryUtil.doesSegmentsIntersect(point, point, point, point); + // $ExpectType boolean + geometryUtil.doesSegmentsIntersect(pointTuple, pointTuple, pointTuple, pointTuple); + + // $ExpectType boolean + geometryUtil.isPointInRing(point, ring); + // $ExpectType boolean + geometryUtil.isPointInRing(pointTuple, ringTuple); + + // $ExpectType boolean + geometryUtil.isRingInRing(ring, ring); + // $ExpectType boolean + geometryUtil.isRingInRing(ringTuple, ringTuple); + + // $ExpectType boolean + geometryUtil.isPointInPolygon(point, polygon); + // $ExpectType boolean + geometryUtil.isPointInPolygon(pointTuple, polygonTuple); + + // $ExpectType [number, number][] + geometryUtil.makesureClockwise(lineTuple); + + // $ExpectType [number, number][] + geometryUtil.makesureAntiClockwise(lineTuple); + + // $ExpectType [number, number] + geometryUtil.closestOnSegment(point, point, point); + // $ExpectType [number, number] + geometryUtil.closestOnSegment(pointTuple, pointTuple, pointTuple); + + // $ExpectType [number, number] + geometryUtil.closestOnSegment(point, point, point); + // $ExpectType [number, number] + geometryUtil.closestOnSegment(pointTuple, pointTuple, pointTuple); + + // $ExpectType [number, number] + geometryUtil.closestOnLine(point, line); + // $ExpectType [number, number] + geometryUtil.closestOnLine(pointTuple, lineTuple); + + // $ExpectType number + geometryUtil.distanceToSegment(point, point, point); + // $ExpectType number + geometryUtil.distanceToSegment(pointTuple, pointTuple, pointTuple); + + // $ExpectType number + geometryUtil.distanceToLine(point, line); + // $ExpectType number + geometryUtil.distanceToLine(pointTuple, lineTuple); + + // $ExpectType boolean + geometryUtil.isPointOnSegment(point, point, point); + // $ExpectType boolean + geometryUtil.isPointOnSegment(point, point, point, 1); + // $ExpectType boolean + geometryUtil.isPointOnSegment(pointTuple, pointTuple, pointTuple); + // $ExpectType boolean + geometryUtil.isPointOnSegment(pointTuple, pointTuple, pointTuple, 1); + + // $ExpectType boolean + geometryUtil.isPointOnLine(point, line); + // $ExpectType boolean + geometryUtil.isPointOnLine(point, line, 1); + // $ExpectType boolean + geometryUtil.isPointOnLine(pointTuple, lineTuple); + // $ExpectType boolean + geometryUtil.isPointOnLine(pointTuple, lineTuple, 1); + + // $ExpectType boolean + geometryUtil.isPointOnRing(point, ring); + // $ExpectType boolean + geometryUtil.isPointOnRing(point, ring, 1); + // $ExpectType boolean + geometryUtil.isPointOnRing(pointTuple, ringTuple); + // $ExpectType boolean + geometryUtil.isPointOnRing(pointTuple, ringTuple, 1); + + // $ExpectType boolean + geometryUtil.isPointOnPolygon(point, polygon); + // $ExpectType boolean + geometryUtil.isPointOnPolygon(point, polygon, 1); + // $ExpectType boolean + geometryUtil.isPointOnPolygon(pointTuple, polygonTuple); + // $ExpectType boolean + geometryUtil.isPointOnPolygon(pointTuple, polygonTuple, 1); +} + +/** + * lnglat.ts + */ + +// $ExpectType LngLat +new AMap.LngLat(114, 22); +// $ExpectType LngLat +const testLnglat = new AMap.LngLat(113, 21); + +// $ExpectType LngLat +testLnglat.offset(1, 2); + +// $ExpectType number +testLnglat.distance(testLnglat); +// $ExpectType number +testLnglat.distance([testLnglat]); + +// $ExpectType number +testLnglat.getLng(); + +// $ExpectType number +testLnglat.getLat(); + +// $ExpectType boolean +testLnglat.equals(testLnglat); + +// $ExpectType string +testLnglat.toString(); + +// $ExpectType LngLat +testLnglat.add(testLnglat); +// $ExpectType LngLat +testLnglat.add(testLnglat, true); + +// $ExpectType LngLat +testLnglat.subtract(testLnglat); +// $ExpectType LngLat +testLnglat.subtract(testLnglat, true); + +// $ExpectType LngLat +testLnglat.divideBy(1); +// $ExpectType LngLat +testLnglat.divideBy(1, true); + +// $ExpectType LngLat +testLnglat.multiplyBy(1); +// $ExpectType LngLat +testLnglat.multiplyBy(1, true); + +/** + * map.ts + */ + +// $ExpectType Map +new AMap.Map('map'); +// $ExpectType Map +new AMap.Map(div); + +// $ExpectType Map +new AMap.Map(div, {}); + +// $ExpectType Map +const testMap = new AMap.Map(div, { + layers: [tileLayer], + zoom: 15, + center: [1, 2], + labelzIndex: 110, + zooms: [5, 15], + lang: 'zh_cn', + defaultCursor: 'default', + crs: 'EPSG4326', + animateEnable: true, + isHotspot: false, + defaultLayer: tileLayer, + rotateEnable: true, + resizeEnable: true, + showIndoorMap: true, + // indoorMap, // TODO + expandZoomRange: true, + dragEnable: true, + zoomEnable: true, + doubleClickZoom: true, + keyboardEnable: true, + jogEnable: true, + scrollWheel: true, + touchZoom: true, + mapStyle: '', + features: ['road'], + showBuildingBlock: true, + skyColor: '#fff', + preloadMode: true, + mask: [[1, 2], [2, 3], [3, 4]] +}); + +// $ExpectType number +testMap.getZoom(); + +// $ExpectType Layer[] +testMap.getLayers(); + +// $ExpectType LngLat +testMap.getCenter(); + +// $ExpectType HTMLElement | null +testMap.getContainer(); + +testMap.getCity(city => { + // $ExpectType string + city.city; + // $ExpectType string + city.citycode; + // $ExpectType string + city.district; + // $ExpectType string | never[] + city.province; +}); + +// $ExpectType Bounds +testMap.getBounds(); + +// $ExpectType number +testMap.getLabelzIndex(); + +// $ExpectType Lang +testMap.getLang(); + +// $ExpectType Size +testMap.getSize(); + +// $ExpectType number +testMap.getRotation(); + +// $ExpectType Status +const mapStatus = testMap.getStatus(); +// $ExpectType boolean +mapStatus.animateEnable; +// $ExpectType boolean +mapStatus.doubleClickZoom; +// $ExpectType boolean +mapStatus.dragEnable; +// $ExpectType boolean +mapStatus.isHotspot; +// $ExpectType boolean +mapStatus.jogEnable; +// $ExpectType boolean +mapStatus.keyboardEnable; +// $ExpectType boolean +mapStatus.pitchEnable; +// $ExpectType boolean +mapStatus.resizeEnable; +// $ExpectType boolean +mapStatus.rotateEnable; +// $ExpectType boolean +mapStatus.scrollWheel; +// $ExpectType boolean +mapStatus.touchZoom; +// $ExpectType boolean +mapStatus.zoomEnable; + +// $ExpectType string +testMap.getDefaultCursor(); + +// $ExpectType number +testMap.getResolution(); + +// $ExpectType number +testMap.getScale(); +// $ExpectType number +testMap.getScale(1); + +// $ExpectType void +testMap.setZoom(1); + +// $ExpectType void +testMap.setLabelzIndex(1); + +// $ExpectType void +testMap.setLayers([tileLayer]); + +// $ExpectType void +testMap.setCenter(lnglat); +// $ExpectType void +testMap.setCenter([1, 2]); + +// $ExpectType void +testMap.setZoomAndCenter(13, lnglat); +// $ExpectType void +testMap.setZoomAndCenter(13, [1, 2]); + +// $ExpectType void +testMap.setCity('city', (coord, zoom) => { + // $ExpectType string + coord[0]; + // $ExpectType string + coord[1]; + // $ExpectType number + zoom; +}); + +// $ExpectType Bounds +testMap.setBounds(bounds); + +// $ExpectType void +testMap.setLimitBounds(bounds); + +// $ExpectType void +testMap.clearLimitBounds(); + +// $ExpectType void +testMap.setLang('zh_cn'); + +// $ExpectType void +testMap.setRotation(1); + +// $ExpectType void +testMap.setStatus({}); +// $ExpectType void +testMap.setStatus({ + animateEnable: true, + doubleClickZoom: true, + dragEnable: true, + isHotspot: true, + jogEnable: true, + keyboardEnable: true, + pitchEnable: false, + resizeEnable: false, + rotateEnable: false, + scrollWheel: true, + touchZoom: true, + zoomEnable: true +}); + +// $ExpectType void +testMap.setDefaultCursor('default'); + +// $ExpectType void +testMap.zoomIn(); + +// $ExpectType void +testMap.zoomOut(); + +// $ExpectType void +testMap.panTo([1, 2]); +// $ExpectType void +testMap.panTo(lnglat); + +// $ExpectType void +testMap.panBy(1, 2); + +// $ExpectType void +testMap.clearMap(); + +// $ExpectType Map +testMap.plugin('plugin name', () => { }); +// $ExpectType Map +testMap.plugin(['plugin name'], () => { }); + +// $ExpectType void +testMap.clearInfoWindow(); + +// $ExpectType LngLat +testMap.pixelToLngLat(pixel); +// $ExpectType LngLat +testMap.pixelToLngLat(pixel, 1); + +// $ExpectType Pixel +testMap.lnglatToPixel(lnglat); +// $ExpectType Pixel +testMap.lnglatToPixel(lnglat, 1); + +// $ExpectType LngLat +testMap.containerToLngLat(pixel); + +// $ExpectType Pixel +testMap.lngLatToContainer(lnglat); +// $ExpectType Pixel +testMap.lnglatTocontainer(lnglat); + +// $ExpectType void +testMap.setMapStyle(''); +// $ExpectType string +testMap.getMapStyle(); + +// $ExpectType void +testMap.setFeatures('all'); +// $ExpectType void +testMap.setFeatures(['bg']); + +const feature: 'all' | 'bg' | 'point' | 'road' | 'building' | AMap.Map.Feature[] = testMap.getFeatures(); + +// $ExpectType void +testMap.setDefaultLayer(tileLayer); + +// $ExpectType void +testMap.setPitch(1); +// $ExpectType number +testMap.getPitch(); + +// $ExpectType ViewMode +testMap.getViewMode_(); + +// $ExpectType Pixel +testMap.lngLatToGeodeticCoord(lnglat); +// $ExpectType Pixel +testMap.lngLatToGeodeticCoord(lnglatTuple); + +// $ExpectType LngLat +testMap.geodeticCoordToLngLat(pixel); + +// $ExpectType void +testMap.destroy(); + +declare function dblClickHandler(this: AMap.Map, event: AMap.Map.EventMap['dblclick']): void; + +// $ExpectType Map +testMap.on('click', (event: AMap.Map.EventMap['click']) => { + // $ExpectType "click" + event.type; + // $ExpectType Pixel + event.pixel; + // $ExpectType LngLat + event.lnglat; + // $ExpectType Map + event.target; +}); +// $ExpectType Map +testMap.on('dblclick', dblClickHandler); +// $ExpectType Map +testMap.on('complete', (event: AMap.Map.EventMap['complete']) => { + // $ExpectType "complete" + event.type; + // $ExpectError + event.value; +}); +// $ExpectType Map +testMap.on('hotspotclick', (event: AMap.Map.EventMap['hotspotclick']) => { + // $ExpectType string + event.id; + // $ExpectType LngLat + event.lnglat; + // $ExpectType string + event.name; + // $ExpectType "hotspotclick" + event.type; +}); +// $ExpectType Map +testMap.on('custom', (event: AMap.Event<'custom', { test: string }>) => { + // $ExpectType "custom" + event.type; + // $ExpectType string + event.test; +}); + +// $ExpectType Map +testMap.off('dblclick', dblClickHandler); +// $ExpectType Map +testMap.off('click', 'mv'); + +// $ExpectType Map +testMap.emit('click', { + target: testMap, + lnglat, + pixel +}); + +testMap.emit('complete'); +// $ExpectType Map +testMap.emit('hotspotclick', { + lnglat, + name: '123', + id: '123', + isIndoorPOI: true +}); +// $ExpectType Map +testMap.emit('custom', { + test: 1 +}); +// $ExpectType Map +testMap.emit('custom', undefined); + +/** + * pixel.ts + */ + +// $ExpectType Pixel +new AMap.Pixel(10, 20); +// $ExpectType Pixel +const testPixel = new AMap.Pixel(10, 20); + +// $ExpectType number +testPixel.getX(); + +// $ExpectType number +testPixel.getY(); + +// $ExpectType boolean +testPixel.equals(testPixel); + +// $ExpectType string +testPixel.toString(); + +// $ExpectType Pixel +testPixel.add({ x: 1, y: 2 }); +// $ExpectType Pixel +testPixel.add({ x: 1, y: 2 }, false); + +// $ExpectType Pixel +testPixel.round(); + +// $ExpectType Pixel +testPixel.floor(); + +// $ExpectType number +testPixel.length(); + +// $ExpectType number | null +testPixel.direction(); + +// $ExpectType Pixel +testPixel.toFixed(); +// $ExpectType Pixel +testPixel.toFixed(2); + +/** + * size.ts + */ + +// $ExpectType Size +const testSize = new AMap.Size(10, 20); + +// $ExpectType number +testSize.getHeight(); + +// $ExpectType number +testSize.getWidth(); + +// $ExpectType string +testSize.toString(); + +// $ExpectType boolean +testSize.contains({ x: 10, y: 10 }); + +/** + * util.ts + */ + +const util = AMap.Util; + +// $ExpectType string +util.colorNameToHex('colorName'); + +// $ExpectType string +util.rgbHex2Rgba('rgbHex'); + +// $ExpectType string +util.argbHex2Rgba('argbHex'); + +// $ExpectType boolean +util.isEmpty({}); +// $ExpectError +util.isEmpty(1); + +// $ExpectType number[] +util.deleteItemFromArray([1], 1); + +// $ExpectType number[] +util.deleteItemFromArrayByIndex([1], 1); + +// $ExpectType number +util.indexOf([1], 1); +// $ExpectError +util.indexOf([1], '1'); + +// $ExpectType number +util.format(1); +// $ExpectType number +util.format(1, 1); + +declare const value1: number | number[]; +// $ExpectType boolean +util.isArray(value1); +if (util.isArray(value1)) { + // $ExpectType number[] + value1; +} else { + // $ExpectType number + value1; +} + +declare const value2: number | HTMLElement; +// $ExpectType boolean +util.isDOM(value2); +if (util.isDOM(value2)) { + // $ExpectType HTMLElement + value2; +} else { + // $ExpectType number + value2; +} + +// $ExpectType boolean +util.includes([1], 1); +// $ExpectError +util.includes([1], '1'); + +// $ExpectType number +util.requestIdleCallback(() => { }); +// $ExpectType number +const idleCallbackHandle = util.requestIdleCallback(() => { }, { timeout: 1 }); + +// $ExpectType void +util.cancelIdleCallback(idleCallbackHandle); + +// $ExpectType number +util.requestAnimFrame(() => { }); +// $ExpectType number +const animFrameHandle = util.requestAnimFrame(function() { + // $ExpectType number + this.test; +}, { test: 1 }); + +// $ExpectType void +util.cancelAnimFrame(animFrameHandle); + +/** + * view2d.ts + */ + +// $ExpectType View2D +new AMap.View2D(); +// $ExpectType View2D +new AMap.View2D({}); + +// $ExpectType View2D +new AMap.View2D({ + center: [1, 2], + rotation: 1, + zoom: 10, + crs: 'EPGS3395' +}); + +// $ExpectType View2D +const testView2d = new AMap.View2D({ + center: lnglat +}); + +// $ExpectType View2D +testView2d.on('complete', () => { }); + +/** + * layer/buildings.ts + */ + +// $ExpectType Buildings +new AMap.Buildings(); +// $ExpectType Buildings +new AMap.Buildings(); +// $ExpectType Buildings +const testBuildings = new AMap.Buildings({ + zooms: [1, 18], + opacity: 0.8, + heightFactor: 1, + visible: true, + zIndex: 10, + map +}); + +testBuildings.setStyle({ + hideWithoutStyle: false, + areas: [ + { + visible: true, + rejectTexture: true, + color1: 'ffffff00', + color2: 'ffffcc00', + path: [[1, 2]] + }, + { + visible: true, + rejectTexture: true, + color1: 'ffffff00', + color2: 'ffffcc00', + path: [lnglat] + }, + { + color1: 'ff99ff00', + path: [lnglat] + }, + ] +}); + +/** + * layer/canvasLayer.ts + */ + +// $ExpectType CanvasLayer +new AMap.CanvasLayer({ + map, + bounds, + visible: true, + zooms: [1, 2], + opacity: 1 +}); + +// $ExpectType CanvasLayer +new AMap.CanvasLayer(); +// $ExpectType CanvasLayer +new AMap.CanvasLayer({}); +// $ExpectType CanvasLayer +const testCanvasLayer = new AMap.CanvasLayer({ + bounds +}); + +// $ExpectType void +testCanvasLayer.setMap(null); +// $ExpectType void +testCanvasLayer.setMap(map); + +// $ExpectType Map | null | undefined +testCanvasLayer.getMap(); + +// $ExpectType void +testCanvasLayer.show(); + +// $ExpectType void +testCanvasLayer.hide(); + +// $ExpectType number +testCanvasLayer.getzIndex(); + +// $ExpectType void +testCanvasLayer.setzIndex(10); + +// $ExpectType HTMLCanvasElement | null +testCanvasLayer.getElement(); + +// $ExpectType void +testCanvasLayer.setCanvas(canvasEle); + +// $ExpectType HTMLCanvasElement | undefined +testCanvasLayer.getCanvas(); + +/** + * layer/flexible.ts + */ + +// $ExpectType Flexible +new AMap.TileLayer.Flexible(); +// $ExpectType Flexible +new AMap.TileLayer.Flexible({}); +// $ExpectType Flexible +const testFlexible = new AMap.TileLayer.Flexible({ + createTile(x, y, z, success, fail) { + // $ExpectType number + x; + // $ExpectType number + y; + // $ExpectType number + z; + // $ExpectType void + success(imgEle); + // $ExpectType void + success(canvasEle); + // $ExpectType void + fail(); + }, + cacheSize: 10, + opacity: 1, + visible: true, + map, + zIndex: 1, + zooms: [1, 2] +}); + +// $ExpectType void +testFlexible.setMap(null); +// $ExpectType void +testFlexible.setMap(map); + +// $ExpectType Map | null | undefined +testFlexible.getMap(); + +// $ExpectType void +testFlexible.show(); + +// $ExpectType void +testFlexible.hide(); + +// $ExpectType void +testFlexible.setzIndex(10); + +// $ExpectType number +testFlexible.getzIndex(); + +/** + * layer/imageLayer.ts + */ + +// $ExpectType ImageLayer +new AMap.ImageLayer({ + map, + bounds, + visible: true, + zooms: [1, 2], + opacity: 1 +}); + +// $ExpectType ImageLayer +new AMap.ImageLayer(); +// $ExpectType ImageLayer +new AMap.ImageLayer({}); +// $ExpectType ImageLayer +const testImageLayer = new AMap.ImageLayer({ + bounds +}); + +// $ExpectType void +testImageLayer.setMap(null); +// $ExpectType void +testImageLayer.setMap(map); + +// $ExpectType Map | null | undefined +testImageLayer.getMap(); + +// $ExpectType void +testImageLayer.show(); + +// $ExpectType void +testImageLayer.hide(); + +// $ExpectType number +testImageLayer.getzIndex(); + +// $ExpectType void +testImageLayer.setzIndex(10); + +// $ExpectType HTMLImageElement | null +testImageLayer.getElement(); + +// $ExpectType void +testImageLayer.setImageUrl('url'); + +// $ExpectType string | undefined +testImageLayer.getImageUrl(); + +/** + * layer/layer.ts + */ + +// $ExpectError +new AMap.Layer(); + +// $ExpectType HTMLDivElement | undefined +layer.getContainer(); + +// $ExpectType [number, number] +layer.getZooms(); + +// $ExpectType void +layer.setOpacity(1); + +// $ExpectType number +layer.getOpacity(); + +// $ExpectType void +layer.show(); + +// $ExpectType void +layer.hide(); + +// $ExpectType void +layer.setMap(); +// $ExpectType void +layer.setMap(map); + +// $ExpectType void +layer.setzIndex(1); + +// $ExpectType number +layer.getzIndex(); + +/** + * layer/layerGroup.ts + */ + +// $ExpectError +new AMap.LayerGroup(); + +// $ExpectType LayerGroup +new AMap.LayerGroup(tileLayer); +// $ExpectType LayerGroup +const testTileLayerGroup = new AMap.LayerGroup([tileLayer]); +// $ExpectType LayerGroup +const testAnyLauerGroup = new AMap.LayerGroup([]); + +// $ExpectType LayerGroup +testTileLayerGroup.addLayer(tileLayer); +// $ExpectType LayerGroup +testTileLayerGroup.addLayer([tileLayer]); +// $ExpectError +testTileLayerGroup.addLayer(massMarksLayer); + +// $ExpectType TileLayer[] +testTileLayerGroup.getLayers(); + +// $ExpectType TileLayer | null +testTileLayerGroup.getLayer(function(item, index, list) { + // $ExpectType TileLayer + item; + // $ExpectType number + index; + // $ExpectType TileLayer[] + list; + // $ExpectType null + this; + + return true; +}); + +testTileLayerGroup.hasLayer(function(item, index, list) { + // $ExpectType TileLayer + item; + // $ExpectType number + index; + // $ExpectType TileLayer[] + list; + // $ExpectType null + this; + + return true; +}); +testTileLayerGroup.hasLayer(tileLayer); + +// $ExpectType LayerGroup +testTileLayerGroup.removeLayer(tileLayer); +// $ExpectType LayerGroup +testTileLayerGroup.removeLayer([tileLayer]); + +// $ExpectType LayerGroup +testTileLayerGroup.clearLayers(); + +testTileLayerGroup.eachLayer(function(item, index, list) { + // $ExpectType TileLayer + item; + // $ExpectType number + index; + // $ExpectType TileLayer[] + list; + // $ExpectType TileLayer + this; +}); +testTileLayerGroup.eachLayer(function(item, index, list) { + // $ExpectType TileLayer + item; + // $ExpectType number + index; + // $ExpectType TileLayer[] + list; + // $ExpectType number + this.test; +}, { test: 1 }); + +// $ExpectType LayerGroup +testTileLayerGroup.setMap(map); + +// $ExpectType LayerGroup +testTileLayerGroup.hide(); + +// $ExpectType LayerGroup +testTileLayerGroup.show(); + +// $ExpectType LayerGroup +testTileLayerGroup.reload(); + +// $ExpectType LayerGroup +testTileLayerGroup.setOptions({}); + +// $ExpectType LayerGroup +testTileLayerGroup.setOptions({ + tileSize: 256 +}); +// layerGruop.setOptions({ +// // $ExpectError +// interval: 1 +// }); + +testAnyLauerGroup.addLayer(tileLayer); + +testAnyLauerGroup.addLayer(massMarksLayer); + +testAnyLauerGroup.setOptions({ + test: 1 +}); + +/** + * layer/massMarks.ts + */ + +const massMarksStyle1 = { + anchor: pixel, + url: '', + size, + rotation: 1 +}; +const massMarksStyle2 = { + anchor: pixel, + url: '', + size +}; +const massMarksData1 = { + lnglat +}; + +interface MassMarksCustomData extends AMap.MassMarks.Data { + name: string; + id: string; +} +const massMarksMassMarksCustomData: MassMarksCustomData = { + lnglat: [1, 2], + style: 1, + name: '', + id: '' +}; + +// $ExpectError +new AMap.MassMarks(); +// $ExpectError +new AMap.MassMarks([], {}); + +new AMap.MassMarks([], { + style: [massMarksStyle1, massMarksStyle2] +}); +new AMap.MassMarks([massMarksData1], { + style: [massMarksStyle1, massMarksStyle2] +}); + +// $ExpectType MassMarks +const testMassMarks = new AMap.MassMarks([massMarksMassMarksCustomData], { + style: [massMarksStyle1, massMarksStyle2] +}); + +// $ExpectType void +testMassMarks.setStyle(massMarksStyle1); +// $ExpectType void +testMassMarks.setStyle([massMarksStyle1]); + +// $ExpectType Style | Style[] +testMassMarks.getStyle(); + +// $ExpectType void +testMassMarks.setData(''); + +// $ExpectError +testMassMarks.setData(massMarksData1); +// $ExpectError +testMassMarks.setData(massMarksMassMarksCustomData); + +const massMarksCustomData = testMassMarks.getData()[0]; +// $ExpectType string +massMarksCustomData.name; +// $ExpectType string +massMarksCustomData.id; +// $ExpectType LngLat +massMarksCustomData.lnglat; + +// $ExpectType void +testMassMarks.clear(); + +testMassMarks.on('click', (event: AMap.MassMarks.EventMap['click']) => { + // $ExpectType "click" + event.type; + + // $ExpectType MassMarksCustomData + event.data; + + // $ExpectType MassMarks + event.target; +}); + +/** + * layer/tileLayer.ts + */ + +// $ExpectType TileLayer +new AMap.TileLayer(); + +// $ExpectType TileLayer +new AMap.TileLayer({}); + +// $ExpectType TileLayer +const testTileLayer = new AMap.TileLayer({ + map, + tileSize: 256, + tileUrl: '', + errorUrl: '', + getTileUrl: (x, y, z) => '', + zIndex: 1, + opacity: 0.1, + zooms: [3, 18], + detectRetina: true +}); + +// $ExpectType string[] +testTileLayer.getTiles(); + +// $ExpectType void +testTileLayer.reload(); + +// $ExpectType void +testTileLayer.setTileUrl(''); +// $ExpectType void +testTileLayer.setTileUrl((x, y, level) => { + // $ExpectType number + x; + // $ExpectType number + y; + // $ExpectType number + level; + return ''; +}); + +// $ExpectType TileLayer +testTileLayer.on('complete', () => { }); + +testTileLayer.off('complete', () => { }); + +testTileLayer.emit('complete'); + +// $ExpectType Traffic +const testTrafficLayer = new AMap.TileLayer.Traffic({}); +// $ExpectType Traffic +new AMap.TileLayer.Traffic({ + autoRefresh: true, + interval: 180 +}); + +testTrafficLayer.on('complete', () => { }); + +/** + * layer/videoLayer.ts + */ + +// $ExpectType VideoLayer +new AMap.VideoLayer({ + map, + bounds, + visible: true, + zooms: [1, 2], + opacity: 1 +}); + +// $ExpectType VideoLayer +new AMap.VideoLayer(); +// $ExpectType VideoLayer +new AMap.VideoLayer({}); +// $ExpectType VideoLayer +const testVideoLayer = new AMap.VideoLayer({ + bounds +}); + +// $ExpectType void +testVideoLayer.setMap(null); +// $ExpectType void +testVideoLayer.setMap(map); + +// $ExpectType Map | null | undefined +testVideoLayer.getMap(); + +// $ExpectType void +testVideoLayer.show(); + +// $ExpectType void +testVideoLayer.hide(); + +// $ExpectType number +testVideoLayer.getzIndex(); + +// $ExpectType void +testVideoLayer.setzIndex(10); + +// $ExpectType HTMLVideoElement | null +testVideoLayer.getElement(); + +// $ExpectType void +testVideoLayer.setVideoUrl('url'); + +// $ExpectType string | string[] | undefined +testVideoLayer.getVideoUrl(); + +/** + * layer/wms.ts + */ + +// $ExpectType WMS +new AMap.TileLayer.WMS({ + url: 'url', + params: {} +}); +// $ExpectType WMS +const testWms = new AMap.TileLayer.WMS({ + url: 'url', + blend: true, + params: { + VERSION: 'version', + LAYERS: 'layers', + STYLES: 'styles', + FORMAT: 'format', + TRANSPARENT: 'TRUE', + BGCOLOR: '#000', + EXCEPTIONS: 'exceptions', + TIME: 'time', + ELEVATION: 'elevation' + }, + zooms: [1, 2], + tileSize: 256, + opacity: 1, + zIndex: 10, + visible: true +}); + +// $ExpectType void +testWms.setMap(map); +// $ExpectType void +testWms.setMap(null); + +// $ExpectType Map | null | undefined +testWms.getMap(); + +// $ExpectType void +testWms.show(); + +// $ExpectType void +testWms.hide(); + +// $ExpectType void +testWms.setzIndex(10); + +// $ExpectType number +testWms.getzIndex(); + +// $ExpectType void +testWms.setUrl('url'); + +// $ExpectType string +testWms.getUrl(); + +// $ExpectType void +testWms.setParams({ + VERSION: 'version', + LAYERS: 'layers', + STYLES: 'styles', + FORMAT: 'format', + TRANSPARENT: 'TRUE', + BGCOLOR: '#000', + EXCEPTIONS: 'exceptions', + TIME: 'time', + ELEVATION: 'elevation' +}); + +{ + const params = testWms.getParams(); + // $ExpectType string | undefined + params.VERSION; + // $ExpectType string | undefined + params.LAYERS; + // $ExpectType string | undefined + params.STYLES; + // $ExpectType string | undefined + params.FORMAT; + // $ExpectType "TRUE" | "FALSE" | undefined + params.TRANSPARENT; + // $ExpectType string | undefined + params.BGCOLOR; + // $ExpectType string | undefined + params.EXCEPTIONS; + // $ExpectType string | undefined + params.TIME; + // $ExpectType string | undefined + params.ELEVATION; +} + +/** + * layer/wmts.ts + */ + +// $ExpectType WMTS +new AMap.TileLayer.WMTS({ + url: 'url', + params: {} +}); +// $ExpectType WMTS +const testWmts = new AMap.TileLayer.WMTS({ + url: 'url', + blend: true, + tileSize: 256, + zooms: [1, 2], + opacity: 1, + zIndex: 10, + visible: true, + params: { + Version: 'version', + Layer: 'layers', + Style: 'style', + Format: 'format' + } +}); + +// $ExpectType void +testWmts.setMap(map); +// $ExpectType void +testWmts.setMap(null); + +// $ExpectType Map | null | undefined +testWmts.getMap(); + +// $ExpectType void +testWmts.show(); + +// $ExpectType void +testWmts.hide(); + +// $ExpectType void +testWmts.setzIndex(10); + +// $ExpectType number +testWmts.getzIndex(); + +// $ExpectType void +testWmts.setUrl('url'); + +// $ExpectType string +testWmts.getUrl(); + +// $ExpectType void +testWmts.setParams({ + Version: 'version', + Layer: 'layers', + Style: 'style', + Format: 'format' +}); + +{ + const params = testWmts.getParams(); + // $ExpectType string | undefined + params.Version; + // $ExpectType string | undefined + params.Layer; + // $ExpectType string | undefined + params.Style; + // $ExpectType string | undefined + params.Format; +} + +/** + * overlay/bezierCurve.ts + */ + +interface BezierCurveExtraData { + test: number; +} + +const bezierCurvePath = [ + [1, 2, 3, 4], + [1, 2, 3], + [ + [1, 2, 3], + [1, 2] + ], + [1, 2] +]; + +// $ExpectError +new AMap.BezierCurve(); +// $ExpectError +new AMap.BezierCurve({}); +// $ExpectType BezierCurve +const testBezierCurve = new AMap.BezierCurve({ + map, + path: bezierCurvePath, + strokeColor: '#FF0000', + strokeOpacity: 0.6, + strokeWeight: 10, + strokeStyle: 'dashed', + strokeDasharray: [1, 5], + zIndex: 10, + bubble: false, + showDir: true, + cursor: 'pointer', + isOutline: true, + outlineColor: '#00FF00', + borderWeight: 2 +}); + +// $ExpectType void +testBezierCurve.setPath(bezierCurvePath); + +// $ExpectType void +testBezierCurve.setPath(bezierCurvePath); + +// $ExpectType void +testBezierCurve.setOptions({}); +testBezierCurve.setOptions({ + map, + path: bezierCurvePath, + strokeColor: '#FF0000', + strokeOpacity: 0.6, + strokeWeight: 10, + strokeStyle: 'dashed', + strokeDasharray: [1, 5], + zIndex: 10, + bubble: false, + showDir: true, + cursor: 'pointer', + isOutline: true, + outlineColor: '#00FF00', + borderWeight: 2 +}); + +{ + const options = testBezierCurve.getOptions(); + + // $ExpectType number | undefined + options.borderWeight; + // $ExpectType boolean | undefined + options.bubble; + // $ExpectType boolean | undefined + options.clickable; + // $ExpectType string | undefined + options.dirColor; + // $ExpectType string | undefined + options.dirImg; + // $ExpectType {} | BezierCurveExtraData | undefined + options.extData; + // $ExpectType boolean | undefined + options.geodesic; + // $ExpectType boolean | undefined + options.isOutline; + // $ExpectType "round" | "butt" | "square" | undefined + options.lineCap; + // $ExpectType "miter" | "round" | "bevel" | undefined + options.lineJoin; + // $ExpectType Map | undefined + options.map; + // $ExpectType string | undefined + options.outlineColor; + // $ExpectType (LngLat & { controlPoints: LngLat[]; })[] | undefined + options.path; + // $ExpectType boolean | undefined + options.showDir; + // $ExpectType string | undefined + options.strokeColor; + // $ExpectType number[] | undefined + options.strokeDasharray; + // $ExpectType number | undefined + options.strokeOpacity; + // $ExpectType "dashed" | "solid" | undefined + options.strokeStyle; + // $ExpectType number | undefined + options.strokeWeight; + // $ExpectType number | undefined + options.zIndex; +} + +// $ExpectType number +testBezierCurve.getLength(); + +// $ExpectType Bounds | null +testBezierCurve.getBounds(); + +// $ExpectType void +testBezierCurve.show(); + +// $ExpectType void +testBezierCurve.hide(); + +// $ExpectType void +testBezierCurve.setMap(null); +testBezierCurve.setMap(map); + +// $ExpectType void +testBezierCurve.setExtData({ test: 1 }); +// $ExpectError +testBezierCurve.setExtData({ test: '123' }); + +// $ExpectType {} | BezierCurveExtraData +testBezierCurve.getExtData(); + +testBezierCurve.on('click', (event: AMap.BezierCurve.EventMap['click']) => { + // $ExpectType "click" + event.type; + // $ExpectType LngLat + event.lnglat; + // $ExpectType BezierCurve + event.target; +}); + +testBezierCurve.on('show', (event: AMap.BezierCurve.EventMap['show']) => { + // $ExpectType "show" + event.type; + // $ExpectType BezierCurve + event.target; +}); + +testBezierCurve.on('options', (event: AMap.BezierCurve.EventMap['options']) => { + // $ExpectType "options" + event.type; + // $ExpectError + event.target; +}); + +/** + * overlay/circle.ts + */ + +interface CircleExtraData { + test: number; +} + +// $ExpectType Circle +new AMap.Circle(); +new AMap.Circle({}); +// $ExpectType Circle +const testCircle = new AMap.Circle({ + map, + zIndex: 10, + center: lnglat, + bubble: true, + cursor: 'pointer', + radius: 1000, + strokeColor: '#FF0000', + strokeOpcity: 0.8, + strokeWeight: 3, + fillColor: '#00FF00', + fillOpacity: 0.5, + strokeStyle: 'dashed', + extData: { test: 1 }, + strokeDasharray: [2, 4] +}); + +// $ExpectType void +testCircle.setCenter(lnglat); +// $ExpectType void +testCircle.setCenter(lnglatTuple); + +// $ExpectType LngLat | undefined +testCircle.getCenter(); + +// $ExpectType Bounds | null +testCircle.getBounds(); + +// $ExpectType void +testCircle.setRadius(100); + +// $ExpectType number +testCircle.getRadius(); + +// $ExpectType void +testCircle.setOptions({}); +testCircle.setOptions({ + map, + zIndex: 10, + center: lnglat, + bubble: true, + cursor: 'pointer', + radius: 1000, + strokeColor: '#FF0000', + strokeOpcity: 0.8, + strokeWeight: 3, + fillColor: '#00FF00', + fillOpacity: 0.5, + strokeStyle: 'dashed', + extData: { test: 1 }, + strokeDasharray: [2, 4] +}); + +{ + const options = testCircle.getOptions(); + // $ExpectType boolean | undefined + options.bubble; + // $ExpectType LngLat | undefined + options.center; + // $ExpectType boolean | undefined + options.clickable; + // $ExpectType {} | CircleExtraData | undefined + options.extData; + // $ExpectType string | undefined + options.fillColor; + // $ExpectType number | undefined + options.fillOpacity; + // $ExpectType "miter" | "round" | "bevel" | undefined + options.lineJoin; + // $ExpectType Map | undefined + options.map; + // $ExpectType LngLat[] | undefined + options.path; + // $ExpectType number | undefined + options.radius; + // $ExpectType string | undefined + options.strokeColor; + // $ExpectType number[] | undefined + options.strokeDasharray; + // $ExpectType number | undefined + options.strokeOpacity; + // $ExpectType "dashed" | "solid" | undefined + options.strokeStyle; + // $ExpectType number | undefined + options.strokeWeight; + // $ExpectType string | undefined + options.texture; + // $ExpectType number | undefined + options.zIndex; +} + +// $ExpectType Bounds | null +testCircle.getBounds(); + +// $ExpectType void +testCircle.hide(); + +// $ExpectType void +testCircle.show(); + +// $ExpectType void +testCircle.setMap(null); +// $ExpectType void +testCircle.setMap(map); + +// $ExpectType void +testCircle.setExtData({ test: 2 }); +// $ExpectError +testCircle.setExtData({ test: '1' }); + +// $ExpectType {} | CircleExtraData +testCircle.getExtData(); + +// $ExpectType boolean +testCircle.contains(lnglat); +// $ExpectType boolean +testCircle.contains(lnglatTuple); + +testCircle.on('click', (event: AMap.Circle.EventMap['click']) => { + // $ExpectType "click" + event.type; + // $ExpectType Circle + event.target; +}); + +testCircle.on('setCenter', (event: AMap.Circle.EventMap['setCenter']) => { + // $ExpectType "setCenter" + event.type; + // $ExpectError + event.target; +}); + +testCircle.on('change', (event: AMap.Circle.EventMap['change']) => { + // $ExpectType "change" + event.type; + // $ExpectType Circle + event.target; +}); + +/** + * overlay/contextMenu.ts + */ + +interface ContextMenuExtraData { + test: number; +} +// $ExpectType ContextMenu +new AMap.ContextMenu(); +// $ExpectType ContextMenu +new AMap.ContextMenu({}); +// $ExpectType ContextMenu +const testContextMenu = new AMap.ContextMenu({ + content: '
content
', +}); + +// $ExpectType void +testContextMenu.addItem('item', function() { + // $ExpectType HTMLLIElement + this; +}); +// $ExpectType void +testContextMenu.addItem('item', () => { }, 1); + +// $ExpectType void +testContextMenu.removeItem('item', () => {}); + +// $ExpectType void +testContextMenu.open(map, lnglatTuple); +// $ExpectType void +testContextMenu.open(map, lnglat); + +// $ExpectType void +testContextMenu.close(); + +testContextMenu.on('items', (event: AMap.ContextMenu.EventMap['items']) => { + // $ExpectType "items" + event.type; +}); + +testContextMenu.on('open', (event: AMap.ContextMenu.EventMap['open']) => { + // $ExpectType "open" + event.type; + // $ExpectType ContextMenu + event.target; +}); + +/** + * overlay/ellipse.ts + */ + +interface EllipseExtraData { + test: number; +} +// $ExpectType Ellipse +new AMap.Ellipse(); +// $ExpectType Ellipse +new AMap.Ellipse({}); +// $ExpectType Ellipse +const testEllipse = new AMap.Ellipse({ + map, + zIndex: 10, + center: lnglat, + radius: [10000, 15000], + bubble: false, + cursor: 'pointer', + strokeColor: '#FF0000', + strokeOpacity: 0.8, + strokeWeight: 2, + fillColor: '#0000FF', + fillOpacity: 0.5, + strokeStyle: 'dashed', + extData: { test: 1 }, + strokeDasharray: [1, 5] +}); + +// $ExpectType LngLat | undefined +testEllipse.getCenter(); + +// $ExpectType void +testEllipse.setCenter(lnglat); +// $ExpectType void +testEllipse.setCenter(lnglatTuple); + +// $ExpectType Bounds | null +testEllipse.getBounds(); + +// $ExpectType void +testEllipse.setOptions({ + map, + zIndex: 10, + center: lnglat, + radius: [10000, 15000], + bubble: false, + cursor: 'pointer', + strokeColor: '#FF0000', + strokeOpacity: 0.8, + strokeWeight: 2, + fillColor: '#0000FF', + fillOpacity: 0.5, + strokeStyle: 'dashed', + extData: { test: 1 }, + strokeDasharray: [1, 5] +}); + +{ + const options = testEllipse.getOptions(); + + // $ExpectType boolean | undefined + options.bubble; + // $ExpectType LngLat | undefined + options.center; + // $ExpectType boolean | undefined + options.clickable; + // $ExpectType {} | EllipseExtraData | undefined + options.extData; + // $ExpectType string | undefined + options.fillColor; + // $ExpectType number | undefined + options.fillOpacity; + // $ExpectType "miter" | "round" | "bevel" | undefined + options.lineJoin; + // $ExpectType Map | undefined + options.map; + // $ExpectType LngLat[] | undefined + options.path; + // $ExpectType [number, number] | undefined + options.radius; + // $ExpectType string | undefined + options.strokeColor; + // $ExpectType number[] | undefined + options.strokeDasharray; + // $ExpectType number | undefined + options.strokeOpacity; + // $ExpectType "dashed" | "solid" | undefined + options.strokeStyle; + // $ExpectType number | undefined + options.strokeWeight; + // $ExpectType string | undefined + options.texture; + // $ExpectType number | undefined + options.zIndex; +} + +// $ExpectType void +testEllipse.hide(); + +// $ExpectType void +testEllipse.show(); + +// $ExpectType void +testEllipse.setMap(null); +// $ExpectType void +testEllipse.setMap(map); + +// $ExpectType void +testEllipse.setExtData({ test: 2 }); +// $ExpectType {} | EllipseExtraData +testEllipse.getExtData(); + +// $ExpectType boolean +testEllipse.contains(lnglat); +// $ExpectType boolean +testEllipse.contains(lnglatTuple); + +/** + * overlay/geoJSON.ts + */ + +interface GeoJSONExtraData { + test: number; +} + +const geoJSONObject: AMap.GeoJSON.GeoJSONObject[] = [ + { + type: 'Feature', + properties: {}, + geometry: { + type: 'Point', + coordinates: lnglatTuple + } + }, + { + type: 'Feature', + properties: { test: 1 }, + geometry: { + type: 'LineString', + coordinates: [lnglatTuple, lnglatTuple] + } + } +]; + +// $ExpectType GeoJSON +new AMap.GeoJSON(); +// $ExpectType GeoJSON +new AMap.GeoJSON({}); +// $ExpectType GeoJSON +const testGeoJSON = new AMap.GeoJSON({ + geoJSON: geoJSONObject, + getMarker(obj, lnglat) { + // $ExpectType GeoJSONObject + obj; + // $ExpectType LngLat + lnglat; + return testMarker; + }, + getPolyline(obj, lnglats) { + // $ExpectType GeoJSONObject + obj; + // $ExpectType LngLat[] + lnglats; + return testPolyline; + }, + getPolygon(obj, lnglats) { + // $ExpectType GeoJSONObject + obj; + // $ExpectType LngLat[] + lnglats; + return testPolygon; + }, + coordsToLatLng(coord) { + // $ExpectType LngLat + coord; + return coord; + } +}); + +// $ExpectType void +testGeoJSON.importData(geoJSONObject); + +// $ExpectType GeoJSON +testGeoJSON.removeOverlay(testMarker); +// $ExpectType GeoJSON +testGeoJSON.removeOverlay([testMarker]); + +// $ExpectType boolean +testGeoJSON.hasOverlay(testMarker); +// $ExpectType boolean +testGeoJSON.hasOverlay(m => m === testMarker); + +// $ExpectType GeoJSON +testGeoJSON.addOverlay(testMarker); +// $ExpectType GeoJSON +testGeoJSON.addOverlay([testMarker]); + +// $ExpectType GeoJSONObject[] +testGeoJSON.toGeoJSON(); + +// $ExpectType GeoJSON +testGeoJSON.setMap(null); +// $ExpectType GeoJSON +testGeoJSON.setMap(map); + +// $ExpectType GeoJSON +testGeoJSON.hide(); + +// $ExpectType GeoJSON +testGeoJSON.show(); + +testGeoJSON.on('click', (event: AMap.MapsEvent<'click', AMap.Overlay>) => { + // $ExpectType "click" + event.type; + // $ExpectType Overlay + event.target; +}); + +/** + * overlay/icon.ts + */ + +// $ExpectType Icon +new AMap.Icon(); +// $ExpectType Icon +new AMap.Icon({}); +// $ExpectType Icon +new AMap.Icon({ + size, + imageOffset: pixel, + image: 'image uri', + imageSize: size +}); +// $ExpectType Icon +const testIcon = new AMap.Icon({ + size: [1, 2], + imageOffset: pixel, + image: 'image uri', + imageSize: [1, 2] +}); + +// $ExpectType Size +testIcon.getImageSize(); + +// $ExpectType void +testIcon.setImageSize(size); +// $ExpectType void +testIcon.setImageSize([1, 2]); + +/** + * overlay/infoWindow.ts + */ + +interface InfoWindowExtraData { + test: number; +} + +// $ExpectType InfoWindow +new AMap.InfoWindow(); +// $ExpectType InfoWindow +new AMap.InfoWindow({}); +// $ExpectType InfoWindow +const testInfoWindow = new AMap.InfoWindow({ + isCustom: false, + autoMove: false, + closeWhenClickMap: false, + content: 'content', + size: [100, 100], + offset: new AMap.Pixel(10, 10), + position: lnglat, + showShadow: true +}); + +// $ExpectType void +testInfoWindow.open(map); +// $ExpectType void +testInfoWindow.open(map, lnglat); +// $ExpectType void +testInfoWindow.open(map, lnglatTuple); + +// $ExpectType void +testInfoWindow.close(); + +// $ExpectType boolean +testInfoWindow.getIsOpen(); + +// $ExpectType void +testInfoWindow.setContent('content'); +// $ExpectType void +testInfoWindow.setContent(div); + +// $ExpectType string | HTMLElement | undefined +testInfoWindow.getContent(); + +// $ExpectType void +testInfoWindow.setPosition(lnglat); +// $ExpectType void +testInfoWindow.setPosition(lnglatTuple); + +// $ExpectType LngLat | undefined +testInfoWindow.getPosition(); + +// $ExpectType Size | undefined +testInfoWindow.getSize(); + +testInfoWindow.on('change', (event: AMap.InfoWindow.EventMap['change']) => { + // $ExpectType "change" + event.type; + // $ExpectType InfoWindow + event.target; +}); + +testInfoWindow.on('close', (event: AMap.InfoWindow.EventMap['close']) => { + // $ExpectType "close" + event.type; + // $ExpectType InfoWindow + event.target; +}); + +testInfoWindow.on('open', (event: AMap.InfoWindow.EventMap['open']) => { + // $ExpectType "open" + event.type; + // $ExpectType InfoWindow + event.target; +}); + +/** + * overlay/marker.ts + */ + +interface MarkerExtraData { + test: number; +} + +// $ExpectType Marker +new AMap.Marker(); +// $ExpectType Marker +new AMap.Marker(); +// $ExpectType Marker +new AMap.Marker({}); +// $ExpectType Marker +const testMarker = new AMap.Marker({ + map, + position: lnglat, + offset: pixel, + icon: 'iconUrl', + content: 'htmlString', + topWhenClick: true, + raiseOnDrag: true, + cursor: 'default', + visible: true, + zIndex: 10, + angle: 10, + autoRotation: true, + animation: 'AMAP_ANIMATION_BOUNCE', + shadow: icon, + title: '123', + clickable: true, + shape: markerShape, + extData: { + test: 123 + } +}); + +// $ExpectType void +testMarker.markOnAMAP({ + name: '123', + position: [1, 2] +}); +// $ExpectType void +testMarker.markOnAMAP(); +// $ExpectType void +testMarker.markOnAMAP({}); +// $ExpectType void +testMarker.markOnAMAP({ + position: [1, 2], + name: '123' +}); + +// $ExpectType Pixel +testMarker.getOffset(); + +// $ExpectType void +testMarker.setOffset(pixel); + +// $ExpectType void +testMarker.setAnimation('AMAP_ANIMATION_BOUNCE'); + +// $ExpectType AnimationName +testMarker.getAnimation(); + +// $ExpectType void +testMarker.setClickable(true); + +// $ExpectType boolean +testMarker.getClickable(); + +// $ExpectType LngLat | undefined +testMarker.getPosition(); + +// $ExpectType void +testMarker.setPosition(lnglat); + +// $ExpectType void +testMarker.setAngle(0); + +// $ExpectType void +testMarker.setLabel(); +// $ExpectType void +testMarker.setLabel({}); +// $ExpectType void +testMarker.setLabel({ + content: 'label content', + offset: pixel +}); + +// $ExpectType Label | undefined +testMarker.getLabel(); + +// $ExpectType number +testMarker.getAngle(); + +// $ExpectType void +testMarker.setzIndex(100); + +// $ExpectType number +testMarker.getzIndex(); + +// $ExpectType void +testMarker.setIcon('icon uri'); +// $ExpectType void +testMarker.setIcon(icon); + +// $ExpectType string | Icon | undefined +testMarker.getIcon(); + +// $ExpectType void +testMarker.setDraggable(true); + +// $ExpectType boolean +testMarker.getDraggable(); + +// $ExpectType void +testMarker.setCursor('default'); + +// $ExpectType void +testMarker.setContent('content'); +// $ExpectType void +testMarker.setContent(domEle); + +// $ExpectType string | HTMLElement +testMarker.getContent(); + +// $ExpectType void +testMarker.moveAlong([lnglat], 100); +// $ExpectError +testMarker.moveAlong([[1, 2]], 100); +// $ExpectType void +testMarker.moveAlong([lnglat], 100, t => t, false); + +// $ExpectType void +testMarker.moveTo(lnglat, 100); +// $ExpectType void +testMarker.moveTo([1, 2], 100); +// $ExpectType void +testMarker.moveTo([1, 2], 100, t => t); + +// $ExpectType void +testMarker.stopMove(); + +// $ExpectType boolean +testMarker.pauseMove(); + +// $ExpectType boolean +testMarker.resumeMove(); + +// $ExpectType void +testMarker.setMap(map); + +// $ExpectType void +testMarker.setTitle('title'); +// $ExpectError +testMarker.setTitle(); + +// $ExpectType string | undefined +testMarker.getTitle(); + +// $ExpectType void +testMarker.setTop(true); + +// $ExpectType boolean +testMarker.getTop(); + +// $ExpectType void +testMarker.setShadow(); +// $ExpectType void +testMarker.setShadow(icon); +// $ExpectType void +testMarker.setShadow('shadow url'); + +// $ExpectType string | Icon | undefined +testMarker.getShadow(); + +// $ExpectType void +testMarker.setShape(); +// $ExpectType void +testMarker.setShape(markerShape); + +// $ExpectType MarkerShape | undefined +testMarker.getShape(); + +testMarker.on('click', (event: AMap.Marker.EventMap['click']) => { + // $ExpectType {} | MarkerExtraData + event.target.getExtData(); +}); + +/** + * overlay/markerShape.ts + */ + +// $ExpectType MarkerShape +new AMap.MarkerShape({ + type: 'circle', + coords: [1, 1, 1] +}); +// $ExpectType MarkerShape +new AMap.MarkerShape({ + type: 'rect', + coords: [1, 1, 1, 2] +}); +// $ExpectType MarkerShape +new AMap.MarkerShape({ + type: 'poly', + coords: [1, 2, 3, 4, 5] +}); + +// $ExpectError +new AMap.MarkerShape({ + type: 'circle', + coords: [1, 1] +}); +// $ExpectError +new AMap.MarkerShape({ + type: 'rect', + coords: [1, 1, 1, 2, 2] +}); + +/** + * overlay/overlay.ts + */ + +interface OverlayExtraData { + test: number; +} +declare const testOverlay: AMap.Overlay; + +// $ExpectType void +testOverlay.show(); + +// $ExpectType void +testOverlay.hide(); + +// $ExpectType Map | null | undefined +testOverlay.getMap(); + +// $ExpectType void +testOverlay.setMap(map); +// $ExpectType void +testOverlay.setMap(null); + +// $ExpectError +testOverlay.setExtData({ any: 123 }); + +// $ExpectError OverlayExtraData +testOverlay.getExtData(); + +/** + * overlay/overlayGroup.ts + */ + +// $ExpectType OverlayGroup, any> +const testOverlayGroup2 = new AMap.OverlayGroup(); +// $ExpectType OverlayGroup, any> +new AMap.OverlayGroup(testMarker); +// $ExpectType OverlayGroup, any> +const testOverlayGroup = new AMap.OverlayGroup([testMarker]); + +// $ExpectType OverlayGroup, any> +testOverlayGroup.addOverlay(testMarker); +// $ExpectType OverlayGroup, any> +testOverlayGroup.addOverlay([testMarker]); +// $ExpectError +testOverlayGroup.addOverlay([testCircle]); + +// $ExpectType OverlayGroup, any> +testOverlayGroup.addOverlays(testMarker); +// $ExpectType OverlayGroup, any> +testOverlayGroup.addOverlays([testMarker]); + +// $ExpectType Marker[] +testOverlayGroup.getOverlays(); + +// $ExpectType boolean +testOverlayGroup.hasOverlay(testMarker); +// $ExpectType boolean +testOverlayGroup.hasOverlay(o => o === testMarker); + +// $ExpectType OverlayGroup, any> +testOverlayGroup.removeOverlay(testMarker); +// $ExpectType OverlayGroup, any> +testOverlayGroup.removeOverlay([testMarker]); + +// $ExpectType OverlayGroup, any> +testOverlayGroup.removeOverlays(testMarker); +// $ExpectType OverlayGroup, any> +testOverlayGroup.removeOverlays([testMarker]); + +// $ExpectType OverlayGroup, any> +testOverlayGroup.clearOverlays(); + +// $ExpectType OverlayGroup, any> +testOverlayGroup.eachOverlay(function(overlay, index, overlays) { + // $ExpectType Marker + overlay; + // $ExpectType number + index; + // $ExpectType Marker[] + overlays; + // $ExpectType Marker + this; +}); + +// $ExpectType OverlayGroup, any> +testOverlayGroup.setMap(null); +// $ExpectType OverlayGroup, any> +testOverlayGroup.setMap(map); + +// $ExpectType OverlayGroup, any> +testOverlayGroup2.setOptions({ + test: 1 +}); +// $ExpectType OverlayGroup, any> +testOverlayGroup.setOptions({ + map, + position: lnglat, + offset: pixel, + icon: 'iconUrl', + content: 'htmlString', + topWhenClick: true, + raiseOnDrag: true, + cursor: 'default', + visible: true, + zIndex: 10, + angle: 10, + autoRotation: true, + animation: 'AMAP_ANIMATION_BOUNCE', + shadow: icon, + title: '123', + clickable: true, + shape: markerShape, + extData: { + test: 123 + } +}); + +// $ExpectType OverlayGroup, any> +testOverlayGroup.show(); + +// $ExpectType OverlayGroup, any> +testOverlayGroup.hide(); + +testOverlayGroup.on('click', (event: AMap.MapsEvent<'click', AMap.Overlay>) => { + // $ExpectType "click" + event.type; + // $ExpectType Overlay + event.target; +}); + +/** + * overlay/polygon.ts + */ + +interface PolygonExtraData { + test: number; +} + +const polygonPath1 = [lnglatTuple, lnglatTuple, lnglatTuple, lnglatTuple, lnglatTuple]; +const polygonPath2 = [lnglat, lnglat, lnglat, lnglat, lnglat]; + +// $ExpectType Polygon +new AMap.Polygon(); +// $ExpectType Polygon +new AMap.Polygon({}); +// $ExpectType Polygon +const testPolygon = new AMap.Polygon({ + map, + zIndex: 10, + bubble: true, + cursor: 'pointer', + strokeColor: '#00FF00', + strokeOpacity: 0.3, + strokeWeight: 5, + fillColor: '#0000FF', + fillOpacity: 0.5, + draggable: true, + extData: { test: 1 }, + strokeStyle: 'dashed', + strokeDasharray: [2, 4], + path: polygonPath1 +}); + +// $ExpectType void +testPolygon.setPath(polygonPath1); +// $ExpectType void +testPolygon.setPath(polygonPath2); +// $ExpectType void +testPolygon.setPath([polygonPath1, polygonPath2]); + +// $ExpectType LngLat[] | LngLat[][] +testPolygon.getPath(); + +// $ExpectType void +testPolygon.setOptions({ + map, + zIndex: 10, + bubble: true, + cursor: 'pointer', + strokeColor: '#00FF00', + strokeOpacity: 0.8, + strokeWeight: 5, + fillColor: '#0000FF', + fillOpacity: 0.5, + draggable: true, + extData: { test: 1 }, + strokeStyle: 'dashed', + strokeDasharray: [4, 2], + path: [polygonPath2, polygonPath1] +}); + +{ + const options = testPolygon.getOptions(); + // $ExpectType boolean | undefined + options.bubble; + // $ExpectType boolean | undefined + options.clickable; + // $ExpectType {} | PolygonExtraData | undefined + options.extData; + // $ExpectType string | undefined + options.fillColor; + // $ExpectType number | undefined + options.fillOpacity; + // $ExpectType "miter" | "round" | "bevel" | undefined + options.lineJoin; + // $ExpectType Map | undefined + options.map; + // $ExpectType LngLat[] | LngLat[][] | undefined + options.path; + // $ExpectType string | undefined + options.strokeColor; + // $ExpectType number[] | undefined + options.strokeDasharray; + // $ExpectType number | undefined + options.strokeOpacity; + // $ExpectType "dashed" | "solid" | undefined + options.strokeStyle; + // $ExpectType number | undefined + options.strokeWeight; + // $ExpectType string | undefined + options.texture; + // $ExpectType number | undefined + options.zIndex; +} + +// $ExpectType Bounds | null +testPolygon.getBounds(); + +// $ExpectType number +testPolygon.getArea(); + +// $ExpectType void +testPolygon.setMap(null); +// $ExpectType void +testPolygon.setMap(map); + +// $ExpectType void +testPolygon.setExtData({ test: 1 }); + +// $ExpectType {} | PolygonExtraData +testPolygon.getExtData(); + +// $ExpectType boolean +testPolygon.contains(lnglat); +// $ExpectType boolean +testPolygon.contains(lnglatTuple); + +testPolygon.on('click', (event: AMap.Polygon.EventMap['click']) => { + // $ExpectType "click" + event.type; + // $ExpectType Polygon + event.target; +}); + +/** + * overlay/polyline.ts + */ + +interface PolylineExtraData { + test: number; +} + +// $ExpectType Polyline +new AMap.Polyline(); +// $ExpectType Polyline +new AMap.Polyline({}); +// $ExpectType Polyline +const testPolyline = new AMap.Polyline({ + map, + zIndex: 10, + bubble: true, + cursor: 'default', + geodesic: true, + isOutline: true, + borderWeight: 1, + outlineColor: '#AA0000', + path: [lnglat], + strokeColor: '#0000AA', + strokeOpacity: 0.5, + strokeWeight: 10, + strokeStyle: 'dashed', + strokeDasharray: [20, 10, 20], + lineJoin: 'bevel', + lineCap: 'butt', + draggable: true, + extData: { test: 1 }, + showDir: true +}); +// Polyline + +// $ExpectType void +testPolyline.setPath([lnglat]); +// $ExpectType void +testPolyline.setPath([lnglatTuple]); + +// $ExpectType void +testPolyline.setOptions({}); +// $ExpectType void +testPolyline.setOptions({ + map, + zIndex: 10, + bubble: true, + cursor: 'default', + geodesic: true, + isOutline: true, + borderWeight: 1, + outlineColor: '#AA0000', + path: [lnglat, lnglat], + strokeColor: '#0000AA', + strokeOpacity: 0.5, + strokeWeight: 10, + strokeStyle: 'dashed', + strokeDasharray: [20, 10, 20], + lineJoin: 'bevel', + lineCap: 'butt', + draggable: true, + extData: { test: 1 }, + showDir: true +}); + +{ + const options = testPolyline.getOptions(); + // $ExpectType number | undefined + options.borderWeight; + // $ExpectType boolean | undefined + options.bubble; + // $ExpectType boolean | undefined + options.clickable; + // $ExpectType string | undefined + options.dirColor; + // $ExpectType string | undefined + options.dirImg; + // $ExpectType {} | PolylineExtraData | undefined + options.extData; + // $ExpectType boolean | undefined + options.geodesic; + // $ExpectType boolean | undefined + options.isOutline; + // $ExpectType "round" | "butt" | "square" | undefined + options.lineCap; + // $ExpectType "miter" | "round" | "bevel" | undefined + options.lineJoin; + // $ExpectType Map | undefined + options.map; + // $ExpectType string | undefined + options.outlineColor; + // $ExpectType LngLat[] | undefined + options.path; + // $ExpectType boolean | undefined + options.showDir; + // $ExpectType string | undefined + options.strokeColor; + // $ExpectType number[] | undefined + options.strokeDasharray; + // $ExpectType number | undefined + options.strokeOpacity; + // $ExpectType "dashed" | "solid" | undefined + options.strokeStyle; + // $ExpectType number | undefined + options.strokeWeight; + // $ExpectType number | undefined + options.zIndex; +} + +// $ExpectType number +testPolyline.getLength(); + +// $ExpectType Bounds | null +testPolyline.getBounds(); + +// $ExpectType void +testPolyline.hide(); + +// $ExpectType void +testPolyline.show(); + +// $ExpectType void +testPolyline.setMap(null); +// $ExpectType void +testPolyline.setMap(map); + +// $ExpectType void +testPolyline.setExtData({ test: 1 }); + +// $ExpectType {} | PolylineExtraData +testPolyline.getExtData(); + +testPolyline.on('click', (event: AMap.Polyline.EventMap['click']) => { + // $ExpectType "click" + event.type; + // $ExpectType Polyline + event.target; +}); + +/** + * overlay/rectangle.ts + */ + +interface RectangleExtraData { + test: number; +} + +// $ExpectType Rectangle +new AMap.Rectangle(); +// $ExpectType Rectangle +new AMap.Rectangle({}); +// $ExpectType Rectangle +const testRectangle = new AMap.Rectangle({ + map, + zIndex: 10, + bounds, + bubble: false, + cursor: 'pointer', + strokeColor: '#00FF00', + strokeOpacity: 0.8, + strokeWeight: 2, + fillColor: '#0000FF', + fillOpacity: 0.5, + strokeStyle: 'solid', + extData: { test: 1 }, + strokeDasharray: [1, 5] +}); + +// $ExpectType Bounds | undefined +testRectangle.getBounds(); + +// $ExpectType void +testRectangle.setBounds(bounds); + +// $ExpectType void +testRectangle.setOptions({}); +// $ExpectType void +testRectangle.setOptions({ + map, + zIndex: 10, + bounds, + bubble: false, + cursor: 'pointer', + strokeColor: '#00FF00', + strokeOpacity: 0.8, + strokeWeight: 2, + fillColor: '#0000FF', + fillOpacity: 0.5, + strokeStyle: 'solid', + extData: { test: 1 }, + strokeDasharray: [1, 5] +}); + +{ + const options = testRectangle.getOptions(); + // $ExpectType Bounds | undefined + options.bounds; + // $ExpectType boolean | undefined + options.bubble; + // $ExpectType boolean | undefined + options.clickable; + // $ExpectType {} | RectangleExtraData | undefined + options.extData; + // $ExpectType string | undefined + options.fillColor; + // $ExpectType number | undefined + options.fillOpacity; + // $ExpectType "miter" | "round" | "bevel" | undefined + options.lineJoin; + // $ExpectType Map | undefined + options.map; + // $ExpectType LngLat[] | undefined + options.path; + // $ExpectType string | undefined + options.strokeColor; + // $ExpectType number[] | undefined + options.strokeDasharray; + // $ExpectType number | undefined + options.strokeOpacity; + // $ExpectType "dashed" | "solid" | undefined + options.strokeStyle; + // $ExpectType number | undefined + options.strokeWeight; + // $ExpectType string | undefined + options.texture; + // $ExpectType number | undefined + options.zIndex; +} + +// $ExpectType void +testRectangle.hide(); + +// $ExpectType void +testRectangle.show(); + +// $ExpectType void +testRectangle.setExtData({test: 2}); + +// $ExpectType {} | RectangleExtraData +testRectangle.getExtData(); + +// $ExpectType boolean +testRectangle.contains(lnglat); +// $ExpectType boolean +testRectangle.contains(lnglatTuple); + +testRectangle.on('click', (event: AMap.Rectangle.EventMap['click']) => { + // $ExpectType "click" + event.type; + // $ExpectType Rectangle + event.target; +}); + +testRectangle.on('setBounds', (event: AMap.Rectangle.EventMap['setBounds']) => { + // $ExpectType "setBounds" + event.type; + // $ExpectError + event.target; +}); + +/** + * overlay/text.ts + */ + +interface TextExtraData { + test: number; +} + +// $ExpectType Text +new AMap.Text(); +// $ExpectType Text +new AMap.Text({}); +// $ExpectType Text +const testText = new AMap.Text({ + text: 'content', + textAlign: 'center', + verticalAlign: 'top', + map, + position: lnglat, + offset: pixel, + topWhenClick: true, + bubble: true, + draggable: true, + raiseOnDrag: true, + cursor: 'default', + visible: true, + zIndex: 100, + angle: 45, + autoRotation: true, + animation: 'AMAP_ANIMATION_BOUNCE', + shadow: 'https://webapi.amap.com/theme/v1.3/markers/0.png', + title: 'title', + clickable: true, + extData: { test: 1 } +}); + +// $ExpectType string +testText.getText(); + +// $ExpectType void +testText.setText('123'); + +// $ExpectType void +testText.setStyle({ + background: 'red', + width: '200px' +}); + +// $ExpectType void +testText.markOnAMAP({ + name: '123', + position: lnglatTuple +}); + +// $ExpectType Pixel +testText.getOffset(); + +// $ExpectType void +testText.setOffset(pixel); + +// $ExpectType void +testText.setAnimation('AMAP_ANIMATION_BOUNCE'); + +// $ExpectType AnimationName +testText.getAnimation(); + +// $ExpectType void +testText.setClickable(true); + +// $ExpectType boolean +testText.getClickable(); + +// $ExpectType LngLat | undefined +testText.getPosition(); + +// $ExpectType void +testText.setAngle(10); + +// $ExpectType number +testText.getAngle(); + +// $ExpectType void +testText.setzIndex(1); + +// $ExpectType number +testText.getzIndex(); + +// $ExpectType void +testText.setDraggable(true); + +// $ExpectType boolean +testText.getDraggable(); + +// $ExpectType void +testText.hide(); + +// $ExpectType void +testText.show(); + +// $ExpectType void +testText.setCursor('default'); + +// $ExpectType void +testText.moveAlong([lnglat], 100); + +// $ExpectType void +testText.moveAlong([lnglat], 100); +// $ExpectError +testText.moveAlong([[1, 2]], 100); +// $ExpectType void +testText.moveAlong([lnglat], 100, t => t, false); + +// $ExpectType void +testText.moveTo(lnglat, 100); +// $ExpectType void +testText.moveTo([1, 2], 100); +// $ExpectType void +testText.moveTo([1, 2], 100, t => t); + +// $ExpectType void +testText.stopMove(); + +// $ExpectType boolean +testText.pauseMove(); + +// $ExpectType boolean +testText.resumeMove(); + +// $ExpectType void +testText.setMap(map); + +// $ExpectType void +testText.setTitle('title'); +// $ExpectError +testText.setTitle(); + +// $ExpectType string | undefined +testText.getTitle(); + +// $ExpectType void +testText.setTop(true); + +// $ExpectType boolean +testText.getTop(); + +// $ExpectType void +testText.setShadow(); +// $ExpectType void +testText.setShadow(icon); +// $ExpectType void +testText.setShadow('shadow url'); + +// $ExpectType void +testText.setExtData({test: 1}); + +// $ExpectType {} | TextExtraData +testText.getExtData(); + +testText.on('click', (event: AMap.Text.EventMap['click']) => { + // $ExpectType "click" + event.type; + // $ExpectType Text + event.target; +}); diff --git a/types/amap-js-api/index.d.ts b/types/amap-js-api/index.d.ts index 54f79c08ea..5b8c1a5b94 100644 --- a/types/amap-js-api/index.d.ts +++ b/types/amap-js-api/index.d.ts @@ -1,4 +1,4 @@ -// Type definitions for non-npm package amap-js-sdk 1.4 +// Type definitions for non-npm package amap-js-api 1.4 // Project: https://lbs.amap.com/api/javascript-api/summary // Definitions by: breeze9527 // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped diff --git a/types/amap-js-api/overlay/markerShape.d.ts b/types/amap-js-api/overlay/markerShape.d.ts index c8efd93850..f0d6c39bac 100644 --- a/types/amap-js-api/overlay/markerShape.d.ts +++ b/types/amap-js-api/overlay/markerShape.d.ts @@ -15,7 +15,7 @@ declare namespace AMap { type Options = CircleOptions | PolyOptions | RectOptions; } - class MarkerShape { + class MarkerShape extends EventEmitter { constructor(options: MarkerShape.Options); } } diff --git a/types/amap-js-api/test/arryBounds.ts b/types/amap-js-api/test/arryBounds.ts deleted file mode 100644 index 1ccc4d0488..0000000000 --- a/types/amap-js-api/test/arryBounds.ts +++ /dev/null @@ -1,18 +0,0 @@ -import { - lnglat -} from './preset'; - -// $ExpectType ArrayBounds -const arrayBounds = new AMap.ArrayBounds([lnglat, lnglat, lnglat]); - -// $ExpectType LngLat[] -arrayBounds.bounds; - -// $ExpectType boolean -arrayBounds.contains(lnglat); - -// $ExpectType Bounds -arrayBounds.toBounds(); - -// $ExpectType LngLat -arrayBounds.getCenter(); diff --git a/types/amap-js-api/test/bounds.ts b/types/amap-js-api/test/bounds.ts deleted file mode 100644 index d22ba697f9..0000000000 --- a/types/amap-js-api/test/bounds.ts +++ /dev/null @@ -1,30 +0,0 @@ -import { - lnglat, - lnglatTuple -} from './preset'; - -// $ExpectType Bounds -const bounds = new AMap.Bounds(lnglat, lnglat); - -// $ExpectType boolean -bounds.contains(lnglat); -// $ExpectType boolean -bounds.contains(lnglatTuple); - -// $ExpectType LngLat -bounds.getCenter(); - -// $ExpectType LngLat -bounds.getSouthWest(); - -// $ExpectType LngLat -bounds.getSouthEast(); - -// $ExpectType LngLat -bounds.getNorthEast(); - -// $ExpectType LngLat -bounds.getNorthWest(); - -// $ExpectType string -bounds.toString(); diff --git a/types/amap-js-api/test/browser.ts b/types/amap-js-api/test/browser.ts deleted file mode 100644 index b80d8cd3ff..0000000000 --- a/types/amap-js-api/test/browser.ts +++ /dev/null @@ -1,141 +0,0 @@ -const brwoser = AMap.Browser; - -// $ExpectType string -brwoser.ua; - -// $ExpectType boolean -brwoser.mobile; - -const plat: 'android' | 'ios' | 'windows' | 'mac' | 'other' = brwoser.plat; - -// $ExpectType boolean -brwoser.mac; - -// $ExpectType boolean -brwoser.windows; - -// $ExpectType boolean -brwoser.ios; - -// $ExpectType boolean -brwoser.iPad; - -// $ExpectType boolean -brwoser.iPhone; - -// $ExpectType boolean -brwoser.android; - -// $ExpectType boolean -brwoser.android23; - -// $ExpectType boolean -brwoser.chrome; - -// $ExpectType boolean -brwoser.firefox; - -// $ExpectType boolean -brwoser.safari; - -// $ExpectType boolean -brwoser.wechat; - -// $ExpectType boolean -brwoser.uc; - -// $ExpectType boolean -brwoser.qq; - -// $ExpectType boolean -brwoser.ie; - -// $ExpectType boolean -brwoser.ie6; - -// $ExpectType boolean -brwoser.ie7; - -// $ExpectType boolean -brwoser.ie8; - -// $ExpectType boolean -brwoser.ie9; - -// $ExpectType boolean -brwoser.ie10; - -// $ExpectType boolean -brwoser.ie11; - -// $ExpectType boolean -brwoser.edge; - -// $ExpectType boolean -brwoser.ielt9; - -// $ExpectType boolean -brwoser.baidu; - -// $ExpectType boolean -brwoser.isLocalStorage; - -// $ExpectType boolean -brwoser.isGeolocation; - -// $ExpectType boolean -brwoser.mobileWebkit; - -// $ExpectType boolean -brwoser.mobileWebkit3d; - -// $ExpectType boolean -brwoser.mobileOpera; - -// $ExpectType boolean -brwoser.retina; - -// $ExpectType boolean -brwoser.touch; - -// $ExpectType boolean -brwoser.msPointer; - -// $ExpectType boolean -brwoser.pointer; - -// $ExpectType boolean -brwoser.webkit; - -// $ExpectType boolean -brwoser.ie3d; - -// $ExpectType boolean -brwoser.webkit3d; - -// $ExpectType boolean -brwoser.gecko3d; - -// $ExpectType boolean -brwoser.opera3d; - -// $ExpectType boolean -brwoser.any3d; - -// $ExpectType boolean -brwoser.isCanvas; - -// $ExpectType boolean -brwoser.isSvg; - -// $ExpectType boolean -brwoser.isVML; - -// $ExpectType boolean -brwoser.isWorker; - -// $ExpectType boolean -brwoser.isWebsocket; - -// $ExpectType boolean -brwoser.isWebGL(); diff --git a/types/amap-js-api/test/convert-from.ts b/types/amap-js-api/test/convert-from.ts deleted file mode 100644 index 8cb9b8502c..0000000000 --- a/types/amap-js-api/test/convert-from.ts +++ /dev/null @@ -1,25 +0,0 @@ -import { - lnglat, - lnglatTuple -} from './preset'; - -declare const convertType: 'baidu' | 'mapbar' | 'gps' | null; -// $ExpectType void -AMap.convertFrom(lnglat, convertType, (status, result) => { - const temp: 'complete' | 'error' = status; - if (typeof result !== 'string') { - // $ExpectType string - result.info; - // $ExpectType LngLat[] - result.locations; - } else { - // $ExpectType string - result; - } -}); -// $ExpectType void -AMap.convertFrom([lnglat], null, () => { }); -// $ExpectType void -AMap.convertFrom(lnglatTuple, null, () => { }); -// $ExpectType void -AMap.convertFrom([lnglatTuple], null, () => { }); diff --git a/types/amap-js-api/test/dom-util.ts b/types/amap-js-api/test/dom-util.ts deleted file mode 100644 index 6cb0bce511..0000000000 --- a/types/amap-js-api/test/dom-util.ts +++ /dev/null @@ -1,47 +0,0 @@ -import { div } from './preset'; - -const util = AMap.DomUtil; - -// $ExpectType Size -util.getViewport(div); - -// $ExpectType Pixel -util.getViewportOffset(div); - -// $ExpectType HTMLDivElement -util.create('div'); -// $ExpectType HTMLAnchorElement -util.create('a'); -// $ExpectType HTMLDivElement -util.create('div', div); -// $ExpectType HTMLDivElement -util.create('div', div, 'className'); - -// $ExpectType void -util.setClass(div); -// $ExpectType void -util.setClass(div, 'className'); - -// $ExpectType boolean -util.hasClass(div, 'className'); - -// $ExpectType void -util.removeClass(div, 'className'); - -// $ExpectType void -util.setOpacity(div, 1); - -// $ExpectType void -util.rotate(div, 10); -// $ExpectType void -util.rotate(div, 10, { x: 10, y: 10 }); - -const util2: typeof AMap.DomUtil = util.setCss(div, { textAlign: 'left' }); -// $ExpectError -util.setCss(div, { textAlign: 10 }); - -// $ExpectType void -util.empty(div); - -// $ExpectType void -util.remove(div); diff --git a/types/amap-js-api/test/event.ts b/types/amap-js-api/test/event.ts deleted file mode 100644 index 8061b0d747..0000000000 --- a/types/amap-js-api/test/event.ts +++ /dev/null @@ -1,74 +0,0 @@ -import { - lnglat, - pixel, - map -} from './preset'; -declare var div: HTMLDivElement; -declare var input: HTMLInputElement; - -// $ExpectType Map -map.on('hotspotclick', (event: AMap.Map.EventMap['hotspotclick']) => { - // $ExpectType "hotspotclick" - event.type; - // $ExpectType string - event.id; - // $ExpectType LngLat - event.lnglat; -}); - -// $ExpectType EventListener<0> -AMap.event.addDomListener(div, 'click', event => { - // $ExpectType number - event.clientX; -}); - -// $ExpectType EventListener<1> -AMap.event.addListener(map, 'hotspotclick', function (event: AMap.Map.EventMap['hotspotclick']) { - // $ExpectType "hotspotclick" - event.type; - // $ExpectType string - event.id; - // $ExpectType LngLat - event.lnglat; - // $ExpectType number - this.test; -}, { test: 1 }); -AMap.event.addListener(map, 'click', (event: AMap.Map.EventMap['click']) => { - // $ExpectType "click" - event.type; - // $ExpectType LngLat - event.lnglat; - // $ExpectType Map - event.target; -}); - -// $ExpectType EventListener<1> -const eventListener = AMap.event.addListenerOnce(map, 'hotspotclick', function (event: AMap.Map.EventMap['hotspotclick']) { - // $ExpectType "hotspotclick" - event.type; - // $ExpectType string - event.id; - // $ExpectType LngLat - event.lnglat; - // $ExpectType number - this.test; -}, { test: 1 }); - -// $ExpectType void -AMap.event.removeListener(eventListener); - -// $ExpectType void -AMap.event.trigger(map, 'click', { - lnglat, - pixel, - target: map -}); -// $ExpectType void -AMap.event.trigger(map, 'hotspotclick', { - lnglat, - name: 'name', - id: 'id', - isIndoorPOI: true -}); -// $ExpectType void -AMap.event.trigger(map, 'complete'); diff --git a/types/amap-js-api/test/geometry-util.ts b/types/amap-js-api/test/geometry-util.ts deleted file mode 100644 index 98a8263fb0..0000000000 --- a/types/amap-js-api/test/geometry-util.ts +++ /dev/null @@ -1,158 +0,0 @@ -import { - lnglat as point, - lnglatTuple as pointTuple -} from './preset'; - -const line = [point]; -const lineTuple = [pointTuple]; -const ring = [point]; -const ringTuple = [pointTuple]; -const polygon = [ring]; -const polygonTuple = [ringTuple]; -const util = AMap.GeometryUtil; - -// $ExpectType number -util.distance(point, point); -// $ExpectType number -util.distance(pointTuple, pointTuple); -// $ExpectType number -util.distance(point, line); -// $ExpectType number -util.distance(pointTuple, lineTuple); - -// $ExpectType number -util.ringArea(ring); -// $ExpectType number -util.ringArea(ringTuple); - -// $ExpectType boolean -util.isClockwise(ring); -// $ExpectType boolean -util.isClockwise(ringTuple); - -// $ExpectType number -util.distanceOfLine(line); -// $ExpectType number -util.distanceOfLine(lineTuple); - -// $ExpectType [number, number][] -util.ringRingClip(ring, ring); -// $ExpectType [number, number][] -util.ringRingClip(ringTuple, ringTuple); - -// $ExpectType boolean -util.doesRingRingIntersect(ring, ring); -// $ExpectType boolean -util.doesRingRingIntersect(ringTuple, ringTuple); - -// $ExpectType boolean -util.doesLineRingIntersect(line, ring); -// $ExpectType boolean -util.doesLineRingIntersect(lineTuple, ringTuple); - -// $ExpectType boolean -util.doesLineLineIntersect(line, line); -// $ExpectType boolean -util.doesLineLineIntersect(lineTuple, lineTuple); - -// $ExpectType boolean -util.doesSegmentPolygonIntersect(point, point, polygon); -// $ExpectType boolean -util.doesSegmentPolygonIntersect(pointTuple, pointTuple, polygonTuple); - -// $ExpectType boolean -util.doesSegmentRingIntersect(point, point, ring); -// $ExpectType boolean -util.doesSegmentRingIntersect(pointTuple, pointTuple, ringTuple); - -// $ExpectType boolean -util.doesSegmentLineIntersect(point, point, line); -// $ExpectType boolean -util.doesSegmentLineIntersect(pointTuple, pointTuple, lineTuple); - -// $ExpectType boolean -util.doesSegmentsIntersect(point, point, point, point); -// $ExpectType boolean -util.doesSegmentsIntersect(pointTuple, pointTuple, pointTuple, pointTuple); - -// $ExpectType boolean -util.isPointInRing(point, ring); -// $ExpectType boolean -util.isPointInRing(pointTuple, ringTuple); - -// $ExpectType boolean -util.isRingInRing(ring, ring); -// $ExpectType boolean -util.isRingInRing(ringTuple, ringTuple); - -// $ExpectType boolean -util.isPointInPolygon(point, polygon); -// $ExpectType boolean -util.isPointInPolygon(pointTuple, polygonTuple); - -// $ExpectType [number, number][] -util.makesureClockwise(lineTuple); - -// $ExpectType [number, number][] -util.makesureAntiClockwise(lineTuple); - -// $ExpectType [number, number] -util.closestOnSegment(point, point, point); -// $ExpectType [number, number] -util.closestOnSegment(pointTuple, pointTuple, pointTuple); - -// $ExpectType [number, number] -util.closestOnSegment(point, point, point); -// $ExpectType [number, number] -util.closestOnSegment(pointTuple, pointTuple, pointTuple); - -// $ExpectType [number, number] -util.closestOnLine(point, line); -// $ExpectType [number, number] -util.closestOnLine(pointTuple, lineTuple); - -// $ExpectType number -util.distanceToSegment(point, point, point); -// $ExpectType number -util.distanceToSegment(pointTuple, pointTuple, pointTuple); - -// $ExpectType number -util.distanceToLine(point, line); -// $ExpectType number -util.distanceToLine(pointTuple, lineTuple); - -// $ExpectType boolean -util.isPointOnSegment(point, point, point); -// $ExpectType boolean -util.isPointOnSegment(point, point, point, 1); -// $ExpectType boolean -util.isPointOnSegment(pointTuple, pointTuple, pointTuple); -// $ExpectType boolean -util.isPointOnSegment(pointTuple, pointTuple, pointTuple, 1); - -// $ExpectType boolean -util.isPointOnLine(point, line); -// $ExpectType boolean -util.isPointOnLine(point, line, 1); -// $ExpectType boolean -util.isPointOnLine(pointTuple, lineTuple); -// $ExpectType boolean -util.isPointOnLine(pointTuple, lineTuple, 1); - -// $ExpectType boolean -util.isPointOnRing(point, ring); -// $ExpectType boolean -util.isPointOnRing(point, ring, 1); -// $ExpectType boolean -util.isPointOnRing(pointTuple, ringTuple); -// $ExpectType boolean -util.isPointOnRing(pointTuple, ringTuple, 1); - -// $ExpectType boolean -util.isPointOnPolygon(point, polygon); -// $ExpectType boolean -util.isPointOnPolygon(point, polygon, 1); -// $ExpectType boolean -util.isPointOnPolygon(pointTuple, polygonTuple); -// $ExpectType boolean -util.isPointOnPolygon(pointTuple, polygonTuple, 1); diff --git a/types/amap-js-api/test/layer/buildings.ts b/types/amap-js-api/test/layer/buildings.ts deleted file mode 100644 index 209b3c490b..0000000000 --- a/types/amap-js-api/test/layer/buildings.ts +++ /dev/null @@ -1,40 +0,0 @@ -declare var map: AMap.Map; -declare var lnglat: AMap.LngLat; - -// $ExpectType Buildings -var buildings = new AMap.Buildings(); -// $ExpectType Buildings -new AMap.Buildings(); -// $ExpectType Buildings -new AMap.Buildings({ - zooms: [1, 18], - opacity: 0.8, - heightFactor: 1, - visible: true, - zIndex: 10, - map -}); - -buildings.setStyle({ - hideWithoutStyle: false, - areas: [ - { - visible: true, - rejectTexture: true, - color1: 'ffffff00', - color2: 'ffffcc00', - path: [[1, 2]] - }, - { - visible: true, - rejectTexture: true, - color1: 'ffffff00', - color2: 'ffffcc00', - path: [lnglat] - }, - { - color1: 'ff99ff00', - path: [lnglat] - }, - ] -}); diff --git a/types/amap-js-api/test/layer/canvasLayer.ts b/types/amap-js-api/test/layer/canvasLayer.ts deleted file mode 100644 index 577d032b2c..0000000000 --- a/types/amap-js-api/test/layer/canvasLayer.ts +++ /dev/null @@ -1,53 +0,0 @@ -import { - map, - bounds -} from '../preset'; - -declare const canvas: HTMLCanvasElement; - -// $ExpectType CanvasLayer -new AMap.CanvasLayer({ - map, - bounds, - visible: true, - zooms: [1, 2], - opacity: 1 -}); - -// $ExpectType CanvasLayer -new AMap.CanvasLayer(); -// $ExpectType CanvasLayer -new AMap.CanvasLayer({}); -// $ExpectType CanvasLayer -const canvasLayer = new AMap.CanvasLayer({ - bounds -}); - -// $ExpectType void -canvasLayer.setMap(null); -// $ExpectType void -canvasLayer.setMap(map); - -// $ExpectType Map | null | undefined -canvasLayer.getMap(); - -// $ExpectType void -canvasLayer.show(); - -// $ExpectType void -canvasLayer.hide(); - -// $ExpectType number -canvasLayer.getzIndex(); - -// $ExpectType void -canvasLayer.setzIndex(10); - -// $ExpectType HTMLCanvasElement | null -canvasLayer.getElement(); - -// $ExpectType void -canvasLayer.setCanvas(canvas); - -// $ExpectType HTMLCanvasElement | undefined -canvasLayer.getCanvas(); diff --git a/types/amap-js-api/test/layer/flexible.ts b/types/amap-js-api/test/layer/flexible.ts deleted file mode 100644 index 5a0e3f7aa7..0000000000 --- a/types/amap-js-api/test/layer/flexible.ts +++ /dev/null @@ -1,54 +0,0 @@ -import { - map -} from '../preset'; - -const img = document.createElement('img'); -const canvas = document.createElement('canvas'); - -// $ExpectType Flexible -new AMap.TileLayer.Flexible(); -// $ExpectType Flexible -new AMap.TileLayer.Flexible({}); -// $ExpectType Flexible -const flexible = new AMap.TileLayer.Flexible({ - createTile(x, y, z, success, fail) { - // $ExpectType number - x; - // $ExpectType number - y; - // $ExpectType number - z; - // $ExpectType void - success(img); - // $ExpectType void - success(canvas); - // $ExpectType void - fail(); - }, - cacheSize: 10, - opacity: 1, - visible: true, - map, - zIndex: 1, - zooms: [1, 2] -}); - -// $ExpectType void -flexible.setMap(null); -// $ExpectType void -flexible.setMap(map); - -// $ExpectType Map | null | undefined -flexible.getMap(); - -// $ExpectType void -flexible.show(); - -// $ExpectType void -flexible.hide(); - -// $ExpectType void -flexible.setzIndex(10); - -// $ExpectType number -flexible.getzIndex(); diff --git a/types/amap-js-api/test/layer/imageLayer.ts b/types/amap-js-api/test/layer/imageLayer.ts deleted file mode 100644 index 06b9fc076e..0000000000 --- a/types/amap-js-api/test/layer/imageLayer.ts +++ /dev/null @@ -1,51 +0,0 @@ -import { - map, - bounds -} from '../preset'; - -// $ExpectType ImageLayer -new AMap.ImageLayer({ - map, - bounds, - visible: true, - zooms: [1, 2], - opacity: 1 -}); - -// $ExpectType ImageLayer -new AMap.ImageLayer(); -// $ExpectType ImageLayer -new AMap.ImageLayer({}); -// $ExpectType ImageLayer -const imageLayer = new AMap.ImageLayer({ - bounds -}); - -// $ExpectType void -imageLayer.setMap(null); -// $ExpectType void -imageLayer.setMap(map); - -// $ExpectType Map | null | undefined -imageLayer.getMap(); - -// $ExpectType void -imageLayer.show(); - -// $ExpectType void -imageLayer.hide(); - -// $ExpectType number -imageLayer.getzIndex(); - -// $ExpectType void -imageLayer.setzIndex(10); - -// $ExpectType HTMLImageElement | null -imageLayer.getElement(); - -// $ExpectType void -imageLayer.setImageUrl('url'); - -// $ExpectType string | undefined -imageLayer.getImageUrl(); diff --git a/types/amap-js-api/test/layer/layer.ts b/types/amap-js-api/test/layer/layer.ts deleted file mode 100644 index 921c90e52d..0000000000 --- a/types/amap-js-api/test/layer/layer.ts +++ /dev/null @@ -1,34 +0,0 @@ -declare var layer: AMap.Layer; -declare var map: AMap.Map; - -// $ExpectError -new AMap.Layer(); - -// $ExpectType HTMLDivElement | undefined -layer.getContainer(); - -// $ExpectType [number, number] -layer.getZooms(); - -// $ExpectType void -layer.setOpacity(1); - -// $ExpectType number -layer.getOpacity(); - -// $ExpectType void -layer.show(); - -// $ExpectType void -layer.hide(); - -// $ExpectType void -layer.setMap(); -// $ExpectType void -layer.setMap(map); - -// $ExpectType void -layer.setzIndex(1); - -// $ExpectType number -layer.getzIndex(); diff --git a/types/amap-js-api/test/layer/layerGroup.ts b/types/amap-js-api/test/layer/layerGroup.ts deleted file mode 100644 index bcad7d6f50..0000000000 --- a/types/amap-js-api/test/layer/layerGroup.ts +++ /dev/null @@ -1,115 +0,0 @@ -declare var map: AMap.Map; -declare var tileLayer: AMap.TileLayer; -declare var massMarksLayer: AMap.MassMarks; -declare var layer: AMap.Layer; - -// $ExpectError -new AMap.LayerGroup(); - -// $ExpectType LayerGroup -new AMap.LayerGroup(tileLayer); -// $ExpectType LayerGroup -new AMap.LayerGroup([tileLayer]); - -declare var layerGruop: AMap.LayerGroup; - -// $ExpectType LayerGroup -layerGruop.addLayer(tileLayer); -// $ExpectType LayerGroup -layerGruop.addLayer([tileLayer]); -// $ExpectError -layerGruop.addLayer(massMarksLayer); - -// $ExpectType TileLayer[] -layerGruop.getLayers(); - -// $ExpectType TileLayer | null -layerGruop.getLayer(function (item, index, list) { - // $ExpectType TileLayer - item; - // $ExpectType number - index; - // $ExpectType TileLayer[] - list; - // $ExpectType null - this; - - return true; -}); - -layerGruop.hasLayer(function (item, index, list) { - // $ExpectType TileLayer - item; - // $ExpectType number - index; - // $ExpectType TileLayer[] - list; - // $ExpectType null - this; - - return true; -}); -layerGruop.hasLayer(tileLayer); - -// $ExpectType LayerGroup -layerGruop.removeLayer(tileLayer); -// $ExpectType LayerGroup -layerGruop.removeLayer([tileLayer]); - -// $ExpectType LayerGroup -layerGruop.clearLayers(); - -layerGruop.eachLayer(function (item, index, list) { - // $ExpectType TileLayer - item; - // $ExpectType number - index; - // $ExpectType TileLayer[] - list; - // $ExpectType TileLayer - this; -}); -layerGruop.eachLayer(function (item, index, list) { - // $ExpectType TileLayer - item; - // $ExpectType number - index; - // $ExpectType TileLayer[] - list; - // $ExpectType number - this.test; -}, { test: 1 }); - -// $ExpectType LayerGroup -layerGruop.setMap(map); - -// $ExpectType LayerGroup -layerGruop.hide(); - -// $ExpectType LayerGroup -layerGruop.show(); - -// $ExpectType LayerGroup -layerGruop.reload(); - -// $ExpectType LayerGroup -layerGruop.setOptions({}); - -// $ExpectType LayerGroup -layerGruop.setOptions({ - tileSize: 256 -}); -// layerGruop.setOptions({ -// // $ExpectError -// interval: 1 -// }); - -declare var layerGroup2: AMap.LayerGroup; - -layerGroup2.addLayer(tileLayer); - -layerGroup2.addLayer(massMarksLayer); - -layerGroup2.setOptions({ - test: 1 -}); diff --git a/types/amap-js-api/test/layer/massMarks.ts b/types/amap-js-api/test/layer/massMarks.ts deleted file mode 100644 index 5f4bfbf455..0000000000 --- a/types/amap-js-api/test/layer/massMarks.ts +++ /dev/null @@ -1,83 +0,0 @@ -declare var pixel: AMap.Pixel; -declare var size: AMap.Size; -declare var lnglat: AMap.LngLat; -var massMarksStyle1 = { - anchor: pixel, - url: '', - size, - rotation: 1 -}; -var massMarksStyle2 = { - anchor: pixel, - url: '', - size -}; -var massMarksData1 = { - lnglat -}; - -interface CustomData extends AMap.MassMarks.Data { - name: string; - id: string; -} -var massMarksCustomData: CustomData = { - lnglat: [1, 2], - style: 1, - name: '', - id: '' -}; - -// $ExpectError -new AMap.MassMarks(); -// $ExpectError -new AMap.MassMarks([], {}); - -new AMap.MassMarks([], { - style: [massMarksStyle1, massMarksStyle2] -}); -new AMap.MassMarks([massMarksData1], { - style: [massMarksStyle1, massMarksStyle2] -}); - -// $ExpectType MassMarks -var massMarks = new AMap.MassMarks([massMarksCustomData], { - style: [massMarksStyle1, massMarksStyle2] -}); - -// $ExpectType void -massMarks.setStyle(massMarksStyle1); -// $ExpectType void -massMarks.setStyle([massMarksStyle1]); - -// $ExpectType Style | Style[] -massMarks.getStyle(); - -// $ExpectType void -massMarks.setData(''); - -// $ExpectError -massMarks.setData(massMarksData1); -// $ExpectError -massMarks.setData(massMarksCustomData); - -var _customData = massMarks.getData()[0]; -// $ExpectType string -_customData.name; -// $ExpectType string -_customData.id; -// $ExpectType LngLat -_customData.lnglat; - -// $ExpectType void -massMarks.clear(); - -massMarks.on('click', (event: AMap.MassMarks.EventMap['click']) => { - // $ExpectType "click" - event.type; - - // $ExpectType CustomData - event.data; - - // $ExpectType MassMarks - event.target; -}); diff --git a/types/amap-js-api/test/layer/tileLayer.ts b/types/amap-js-api/test/layer/tileLayer.ts deleted file mode 100644 index 7e4e2dc2e4..0000000000 --- a/types/amap-js-api/test/layer/tileLayer.ts +++ /dev/null @@ -1,60 +0,0 @@ -declare var map: AMap.Map; - -// $ExpectType TileLayer -var tileLayer = new AMap.TileLayer(); - -// $ExpectType TileLayer -new AMap.TileLayer({}); - -// $ExpectType TileLayer -new AMap.TileLayer({ - map, - tileSize: 256, - tileUrl: '', - errorUrl: '', - getTileUrl: (x, y, z) => '', - zIndex: 1, - opacity: 0.1, - zooms: [3, 18], - detectRetina: true -}); - -// $ExpectType string[] -tileLayer.getTiles(); - -// $ExpectType void -tileLayer.reload(); - -// $ExpectType void -tileLayer.setTileUrl(''); -// $ExpectType void -tileLayer.setTileUrl((x, y, level) => { - // $ExpectType number - x; - // $ExpectType number - y; - // $ExpectType number - level; - return ''; -}); - -// Traffic - -// $ExpectType Traffic -let trafficLayer = new AMap.TileLayer.Traffic(); -// $ExpectType Traffic -new AMap.TileLayer.Traffic({}); -// $ExpectType Traffic -new AMap.TileLayer.Traffic({ - autoRefresh: true, - interval: 180 -}); - -// $ExpectType TileLayer -tileLayer.on('complete', () => { }); - -tileLayer.off('complete', () => { }); - -tileLayer.emit('complete'); - -trafficLayer.on('complete', () => { }); diff --git a/types/amap-js-api/test/layer/videoLayer.ts b/types/amap-js-api/test/layer/videoLayer.ts deleted file mode 100644 index e34718193c..0000000000 --- a/types/amap-js-api/test/layer/videoLayer.ts +++ /dev/null @@ -1,51 +0,0 @@ -import { - map, - bounds -} from '../preset'; - -// $ExpectType VideoLayer -new AMap.VideoLayer({ - map, - bounds, - visible: true, - zooms: [1, 2], - opacity: 1 -}); - -// $ExpectType VideoLayer -new AMap.VideoLayer(); -// $ExpectType VideoLayer -new AMap.VideoLayer({}); -// $ExpectType VideoLayer -const videoLayer = new AMap.VideoLayer({ - bounds -}); - -// $ExpectType void -videoLayer.setMap(null); -// $ExpectType void -videoLayer.setMap(map); - -// $ExpectType Map | null | undefined -videoLayer.getMap(); - -// $ExpectType void -videoLayer.show(); - -// $ExpectType void -videoLayer.hide(); - -// $ExpectType number -videoLayer.getzIndex(); - -// $ExpectType void -videoLayer.setzIndex(10); - -// $ExpectType HTMLVideoElement | null -videoLayer.getElement(); - -// $ExpectType void -videoLayer.setVideoUrl('url'); - -// $ExpectType string | string[] | undefined -videoLayer.getVideoUrl(); diff --git a/types/amap-js-api/test/layer/wms.ts b/types/amap-js-api/test/layer/wms.ts deleted file mode 100644 index 255affa216..0000000000 --- a/types/amap-js-api/test/layer/wms.ts +++ /dev/null @@ -1,89 +0,0 @@ -import { - map -} from '../preset'; - -// $ExpectType WMS -new AMap.TileLayer.WMS({ - url: 'url', - params: {} -}); -// $ExpectType WMS -const wms = new AMap.TileLayer.WMS({ - url: 'url', - blend: true, - params: { - VERSION: 'version', - LAYERS: 'layers', - STYLES: 'styles', - FORMAT: 'format', - TRANSPARENT: 'TRUE', - BGCOLOR: '#000', - EXCEPTIONS: 'exceptions', - TIME: 'time', - ELEVATION: 'elevation' - }, - zooms: [1, 2], - tileSize: 256, - opacity: 1, - zIndex: 10, - visible: true -}); - -// $ExpectType void -wms.setMap(map); -// $ExpectType void -wms.setMap(null); - -// $ExpectType Map | null | undefined -wms.getMap(); - -// $ExpectType void -wms.show(); - -// $ExpectType void -wms.hide(); - -// $ExpectType void -wms.setzIndex(10); - -// $ExpectType number -wms.getzIndex(); - -// $ExpectType void -wms.setUrl('url'); - -// $ExpectType string -wms.getUrl(); - -// $ExpectType void -wms.setParams({ - VERSION: 'version', - LAYERS: 'layers', - STYLES: 'styles', - FORMAT: 'format', - TRANSPARENT: 'TRUE', - BGCOLOR: '#000', - EXCEPTIONS: 'exceptions', - TIME: 'time', - ELEVATION: 'elevation' -}); - -const params = wms.getParams(); -// $ExpectType string | undefined -params.VERSION; -// $ExpectType string | undefined -params.LAYERS; -// $ExpectType string | undefined -params.STYLES; -// $ExpectType string | undefined -params.FORMAT; -// $ExpectType "TRUE" | "FALSE" | undefined -params.TRANSPARENT; -// $ExpectType string | undefined -params.BGCOLOR; -// $ExpectType string | undefined -params.EXCEPTIONS; -// $ExpectType string | undefined -params.TIME; -// $ExpectType string | undefined -params.ELEVATION; diff --git a/types/amap-js-api/test/layer/wmts.ts b/types/amap-js-api/test/layer/wmts.ts deleted file mode 100644 index bc167c1189..0000000000 --- a/types/amap-js-api/test/layer/wmts.ts +++ /dev/null @@ -1,69 +0,0 @@ -import { - map -} from '../preset'; - -// $ExpectType WMTS -new AMap.TileLayer.WMTS({ - url: 'url', - params: {} -}); -// $ExpectType WMTS -const wmts = new AMap.TileLayer.WMTS({ - url: 'url', - blend: true, - tileSize: 256, - zooms: [1, 2], - opacity: 1, - zIndex: 10, - visible: true, - params: { - Version: 'version', - Layer: 'layers', - Style: 'style', - Format: 'format' - } -}); - -// $ExpectType void -wmts.setMap(map); -// $ExpectType void -wmts.setMap(null); - -// $ExpectType Map | null | undefined -wmts.getMap(); - -// $ExpectType void -wmts.show(); - -// $ExpectType void -wmts.hide(); - -// $ExpectType void -wmts.setzIndex(10); - -// $ExpectType number -wmts.getzIndex(); - -// $ExpectType void -wmts.setUrl('url'); - -// $ExpectType string -wmts.getUrl(); - -// $ExpectType void -wmts.setParams({ - Version: 'version', - Layer: 'layers', - Style: 'style', - Format: 'format' -}); - -const params = wmts.getParams(); -// $ExpectType string | undefined -params.Version; -// $ExpectType string | undefined -params.Layer; -// $ExpectType string | undefined -params.Style; -// $ExpectType string | undefined -params.Format; diff --git a/types/amap-js-api/test/lnglat.ts b/types/amap-js-api/test/lnglat.ts deleted file mode 100644 index 92057953ee..0000000000 --- a/types/amap-js-api/test/lnglat.ts +++ /dev/null @@ -1,48 +0,0 @@ -import { - lnglat -} from './preset'; - -// $ExpectType LngLat -new AMap.LngLat(114, 22); -// $ExpectType LngLat -new AMap.LngLat(113, 21); - -// $ExpectType LngLat -lnglat.offset(1, 2); - -// $ExpectType number -lnglat.distance(lnglat); -// $ExpectType number -lnglat.distance([lnglat]); - -// $ExpectType number -lnglat.getLng(); - -// $ExpectType number -lnglat.getLat(); - -// $ExpectType boolean -lnglat.equals(lnglat); - -// $ExpectType string -lnglat.toString(); - -// $ExpectType LngLat -lnglat.add(lnglat); -// $ExpectType LngLat -lnglat.add(lnglat, true); - -// $ExpectType LngLat -lnglat.subtract(lnglat); -// $ExpectType LngLat -lnglat.subtract(lnglat, true); - -// $ExpectType LngLat -lnglat.divideBy(1); -// $ExpectType LngLat -lnglat.divideBy(1, true); - -// $ExpectType LngLat -lnglat.multiplyBy(1); -// $ExpectType LngLat -lnglat.multiplyBy(1, true); diff --git a/types/amap-js-api/test/map.ts b/types/amap-js-api/test/map.ts deleted file mode 100644 index 6f2b027e60..0000000000 --- a/types/amap-js-api/test/map.ts +++ /dev/null @@ -1,338 +0,0 @@ -import { - lnglat, - bounds, - lnglatTuple, - pixel -} from './preset'; - -declare const container: HTMLDivElement; -declare const tileLayer: AMap.TileLayer; - -// declare var indoorMap: AMap.IndoorMap - -// $ExpectType Map -new AMap.Map('map'); -// $ExpectType Map -new AMap.Map(container); - -// $ExpectType Map -new AMap.Map(container, {}); - -// $ExpectType Map -const map = new AMap.Map(container, { - layers: [tileLayer], - zoom: 15, - center: [1, 2], - labelzIndex: 110, - zooms: [5, 15], - lang: 'zh_cn', - defaultCursor: 'default', - crs: 'EPSG4326', - animateEnable: true, - isHotspot: false, - defaultLayer: tileLayer, - rotateEnable: true, - resizeEnable: true, - showIndoorMap: true, - // indoorMap, // TODO - expandZoomRange: true, - dragEnable: true, - zoomEnable: true, - doubleClickZoom: true, - keyboardEnable: true, - jogEnable: true, - scrollWheel: true, - touchZoom: true, - mapStyle: '', - features: ['road'], - showBuildingBlock: true, - skyColor: '#fff', - preloadMode: true, - mask: [[1, 2], [2, 3], [3, 4]] -}); - -// $ExpectType number -map.getZoom(); - -// $ExpectType Layer[] -map.getLayers(); - -// $ExpectType LngLat -map.getCenter(); - -// $ExpectType HTMLElement | null -map.getContainer(); - -map.getCity(city => { - // $ExpectType string - city.city; - // $ExpectType string - city.citycode; - // $ExpectType string - city.district; - // $ExpectType string | never[] - city.province; -}); - -// $ExpectType Bounds -map.getBounds(); - -// $ExpectType number -map.getLabelzIndex(); - -// $ExpectType Lang -map.getLang(); - -// $ExpectType Size -map.getSize(); - -// $ExpectType number -map.getRotation(); - -// $ExpectType Status -const mapStatus = map.getStatus(); -// $ExpectType boolean -mapStatus.animateEnable; -// $ExpectType boolean -mapStatus.doubleClickZoom; -// $ExpectType boolean -mapStatus.dragEnable; -// $ExpectType boolean -mapStatus.isHotspot; -// $ExpectType boolean -mapStatus.jogEnable; -// $ExpectType boolean -mapStatus.keyboardEnable; -// $ExpectType boolean -mapStatus.pitchEnable; -// $ExpectType boolean -mapStatus.resizeEnable; -// $ExpectType boolean -mapStatus.rotateEnable; -// $ExpectType boolean -mapStatus.scrollWheel; -// $ExpectType boolean -mapStatus.touchZoom; -// $ExpectType boolean -mapStatus.zoomEnable; - -// $ExpectType string -map.getDefaultCursor(); - -// $ExpectType number -map.getResolution(); - -// $ExpectType number -map.getScale(); -// $ExpectType number -map.getScale(1); - -// $ExpectType void -map.setZoom(1); - -// $ExpectType void -map.setLabelzIndex(1); - -// $ExpectType void -map.setLayers([tileLayer]); - -// $ExpectType void -map.setCenter(lnglat); -// $ExpectType void -map.setCenter([1, 2]); - -// $ExpectType void -map.setZoomAndCenter(13, lnglat); -// $ExpectType void -map.setZoomAndCenter(13, [1, 2]); - -// $ExpectType void -map.setCity('city', (coord, zoom) => { - // $ExpectType string - coord[0]; - // $ExpectType string - coord[1]; - // $ExpectType number - zoom; -}); - -// $ExpectType Bounds -map.setBounds(bounds); - -// $ExpectType void -map.setLimitBounds(bounds); - -// $ExpectType void -map.clearLimitBounds(); - -// $ExpectType void -map.setLang('zh_cn'); - -// $ExpectType void -map.setRotation(1); - -// $ExpectType void -map.setStatus({}); -// $ExpectType void -map.setStatus({ - animateEnable: true, - doubleClickZoom: true, - dragEnable: true, - isHotspot: true, - jogEnable: true, - keyboardEnable: true, - pitchEnable: false, - resizeEnable: false, - rotateEnable: false, - scrollWheel: true, - touchZoom: true, - zoomEnable: true -}); - -// $ExpectType void -map.setDefaultCursor('default'); - -// $ExpectType void -map.zoomIn(); - -// $ExpectType void -map.zoomOut(); - -// $ExpectType void -map.panTo([1, 2]); -// $ExpectType void -map.panTo(lnglat); - -// $ExpectType void -map.panBy(1, 2); - -// $ExpectType void -map.clearMap(); - -// $ExpectType Map -map.plugin('plugin name', () => { }); -// $ExpectType Map -map.plugin(['plugin name'], () => { }); - -// $ExpectType void -map.clearInfoWindow(); - -// $ExpectType LngLat -map.pixelToLngLat(pixel); -// $ExpectType LngLat -map.pixelToLngLat(pixel, 1); - -// $ExpectType Pixel -map.lnglatToPixel(lnglat); -// $ExpectType Pixel -map.lnglatToPixel(lnglat, 1); - -// $ExpectType LngLat -map.containerToLngLat(pixel); - -// $ExpectType Pixel -map.lngLatToContainer(lnglat); -// $ExpectType Pixel -map.lnglatTocontainer(lnglat); - -// $ExpectType void -map.setMapStyle(''); -// $ExpectType string -map.getMapStyle(); - -// $ExpectType void -map.setFeatures('all'); -// $ExpectType void -map.setFeatures(['bg']); - -const feature: 'all' | 'bg' | 'point' | 'road' | 'building' | AMap.Map.Feature[] = map.getFeatures(); - -// $ExpectType void -map.setDefaultLayer(tileLayer); - -// $ExpectType void -map.setPitch(1); -// $ExpectType number -map.getPitch(); - -// $ExpectType ViewMode -map.getViewMode_(); - -// $ExpectType Pixel -map.lngLatToGeodeticCoord(lnglat); -// $ExpectType Pixel -map.lngLatToGeodeticCoord(lnglatTuple); - -// $ExpectType LngLat -map.geodeticCoordToLngLat(pixel); - -// $ExpectType void -map.destroy(); - -declare function dblClickHandler(this: AMap.Map, event: AMap.Map.EventMap['dblclick']): void; - -// $ExpectType Map -map.on('click', (event: AMap.Map.EventMap['click']) => { - // $ExpectType "click" - event.type; - // $ExpectType Pixel - event.pixel; - // $ExpectType LngLat - event.lnglat; - // $ExpectType Map - event.target; -}); -// $ExpectType Map -map.on('dblclick', dblClickHandler); -// $ExpectType Map -map.on('complete', (event: AMap.Map.EventMap['complete']) => { - // $ExpectType "complete" - event.type; - // $ExpectError - event.value; -}); -// $ExpectType Map -map.on('hotspotclick', (event: AMap.Map.EventMap['hotspotclick']) => { - // $ExpectType string - event.id; - // $ExpectType LngLat - event.lnglat; - // $ExpectType string - event.name; - // $ExpectType "hotspotclick" - event.type; -}); -// $ExpectType Map -map.on('custom', (event: AMap.Event<'custom', { test: string }>) => { - // $ExpectType "custom" - event.type; - // $ExpectType string - event.test; -}); - -// $ExpectType Map -map.off('dblclick', dblClickHandler); -// $ExpectType Map -map.off('click', 'mv'); - -// $ExpectType Map -map.emit('click', { - target: map, - lnglat, - pixel -}); - -map.emit('complete'); -// $ExpectType Map -map.emit('hotspotclick', { - lnglat, - name: '123', - id: '123', - isIndoorPOI: true -}); -// $ExpectType Map -map.emit('custom', { - test: 1 -}); -// $ExpectType Map -map.emit('custom', undefined); diff --git a/types/amap-js-api/test/overlay/bezierCurve.ts b/types/amap-js-api/test/overlay/bezierCurve.ts deleted file mode 100644 index abf0640fc9..0000000000 --- a/types/amap-js-api/test/overlay/bezierCurve.ts +++ /dev/null @@ -1,155 +0,0 @@ -import { - map, - lnglat -} from '../preset'; - -interface ExtraData { - test: number; -} - -const path = [ - [1, 2, 3, 4], - [1, 2, 3], - [ - [1, 2, 3], - [1, 2] - ], - [1, 2] -]; - -// $ExpectError -new AMap.BezierCurve(); -// $ExpectError -new AMap.BezierCurve({}); -// $ExpectType BezierCurve -const bezierCurve = new AMap.BezierCurve({ - map, - path, - strokeColor: '#FF0000', - strokeOpacity: 0.6, - strokeWeight: 10, - strokeStyle: 'dashed', - strokeDasharray: [1, 5], - zIndex: 10, - bubble: false, - showDir: true, - cursor: 'pointer', - isOutline: true, - outlineColor: '#00FF00', - borderWeight: 2 -}); - -// $ExpectType void -bezierCurve.setPath(path); - -// $ExpectType void -bezierCurve.setPath(path); - -// $ExpectType void -bezierCurve.setOptions({}); -bezierCurve.setOptions({ - map, - path, - strokeColor: '#FF0000', - strokeOpacity: 0.6, - strokeWeight: 10, - strokeStyle: 'dashed', - strokeDasharray: [1, 5], - zIndex: 10, - bubble: false, - showDir: true, - cursor: 'pointer', - isOutline: true, - outlineColor: '#00FF00', - borderWeight: 2 -}); - -const options = bezierCurve.getOptions(); - -// $ExpectType number | undefined -options.borderWeight; -// $ExpectType boolean | undefined -options.bubble; -// $ExpectType boolean | undefined -options.clickable; -// $ExpectType string | undefined -options.dirColor; -// $ExpectType string | undefined -options.dirImg; -// $ExpectType {} | ExtraData | undefined -options.extData; -// $ExpectType boolean | undefined -options.geodesic; -// $ExpectType boolean | undefined -options.isOutline; -// $ExpectType "round" | "butt" | "square" | undefined -options.lineCap; -// $ExpectType "miter" | "round" | "bevel" | undefined -options.lineJoin; -// $ExpectType Map | undefined -options.map; -// $ExpectType string | undefined -options.outlineColor; -// $ExpectType (LngLat & { controlPoints: LngLat[]; })[] | undefined -options.path; -// $ExpectType boolean | undefined -options.showDir; -// $ExpectType string | undefined -options.strokeColor; -// $ExpectType number[] | undefined -options.strokeDasharray; -// $ExpectType number | undefined -options.strokeOpacity; -// $ExpectType "dashed" | "solid" | undefined -options.strokeStyle; -// $ExpectType number | undefined -options.strokeWeight; -// $ExpectType number | undefined -options.zIndex; - -// $ExpectType number -bezierCurve.getLength(); - -// $ExpectType Bounds | null -bezierCurve.getBounds(); - -// $ExpectType void -bezierCurve.show(); - -// $ExpectType void -bezierCurve.hide(); - -// $ExpectType void -bezierCurve.setMap(null); -bezierCurve.setMap(map); - -// $ExpectType void -bezierCurve.setExtData({ test: 1 }); -// $ExpectError -bezierCurve.setExtData({ test: '123' }); - -// $ExpectType {} | ExtraData -bezierCurve.getExtData(); - -bezierCurve.on('click', (event: AMap.BezierCurve.EventMap['click']) => { - // $ExpectType "click" - event.type; - // $ExpectType LngLat - event.lnglat; - // $ExpectType BezierCurve - event.target; -}); - -bezierCurve.on('show', (event: AMap.BezierCurve.EventMap['show']) => { - // $ExpectType "show" - event.type; - // $ExpectType BezierCurve - event.target; -}); - -bezierCurve.on('options', (event: AMap.BezierCurve.EventMap['options']) => { - // $ExpectType "options" - event.type; - // $ExpectError - event.target; -}); diff --git a/types/amap-js-api/test/overlay/circle.ts b/types/amap-js-api/test/overlay/circle.ts deleted file mode 100644 index 28822b9ec9..0000000000 --- a/types/amap-js-api/test/overlay/circle.ts +++ /dev/null @@ -1,150 +0,0 @@ -import { - map, - lnglat, - lnglatTuple -} from '../preset'; - -interface ExtraData { - test: number; -} - -// $ExpectType Circle -new AMap.Circle(); -new AMap.Circle({}); -// $ExpectType Circle -const circle = new AMap.Circle({ - map, - zIndex: 10, - center: lnglat, - bubble: true, - cursor: 'pointer', - radius: 1000, - strokeColor: '#FF0000', - strokeOpcity: 0.8, - strokeWeight: 3, - fillColor: '#00FF00', - fillOpacity: 0.5, - strokeStyle: 'dashed', - extData: { test: 1 }, - strokeDasharray: [2, 4] -}); - -// $ExpectType void -circle.setCenter(lnglat); -// $ExpectType void -circle.setCenter(lnglatTuple); - -// $ExpectType LngLat | undefined -circle.getCenter(); - -// $ExpectType Bounds | null -circle.getBounds(); - -// $ExpectType void -circle.setRadius(100); - -// $ExpectType number -circle.getRadius(); - -// $ExpectType void -circle.setOptions({}); -circle.setOptions({ - map, - zIndex: 10, - center: lnglat, - bubble: true, - cursor: 'pointer', - radius: 1000, - strokeColor: '#FF0000', - strokeOpcity: 0.8, - strokeWeight: 3, - fillColor: '#00FF00', - fillOpacity: 0.5, - strokeStyle: 'dashed', - extData: { test: 1 }, - strokeDasharray: [2, 4] -}); - -const options = circle.getOptions(); -// $ExpectType boolean | undefined -options.bubble; -// $ExpectType LngLat | undefined -options.center; -// $ExpectType boolean | undefined -options.clickable; -// $ExpectType {} | ExtraData | undefined -options.extData; -// $ExpectType string | undefined -options.fillColor; -// $ExpectType number | undefined -options.fillOpacity; -// $ExpectType "miter" | "round" | "bevel" | undefined -options.lineJoin; -// $ExpectType Map | undefined -options.map; -// $ExpectType LngLat[] | undefined -options.path; -// $ExpectType number | undefined -options.radius; -// $ExpectType string | undefined -options.strokeColor; -// $ExpectType number[] | undefined -options.strokeDasharray; -// $ExpectType number | undefined -options.strokeOpacity; -// $ExpectType "dashed" | "solid" | undefined -options.strokeStyle; -// $ExpectType number | undefined -options.strokeWeight; -// $ExpectType string | undefined -options.texture; -// $ExpectType number | undefined -options.zIndex; - -// $ExpectType Bounds | null -circle.getBounds(); - -// $ExpectType void -circle.hide(); - -// $ExpectType void -circle.show(); - -// $ExpectType void -circle.setMap(null); -// $ExpectType void -circle.setMap(map); - -// $ExpectType void -circle.setExtData({ test: 2 }); -// $ExpectError -circle.setExtData({ test: '1' }); - -// $ExpectType {} | ExtraData -circle.getExtData(); - -// $ExpectType boolean -circle.contains(lnglat); -// $ExpectType boolean -circle.contains(lnglatTuple); - -circle.on('click', (event: AMap.Circle.EventMap['click']) => { - // $ExpectType "click" - event.type; - // $ExpectType Circle - event.target; -}); - -circle.on('setCenter', (event: AMap.Circle.EventMap['setCenter']) => { - // $ExpectType "setCenter" - event.type; - // $ExpectError - event.target; -}); - -circle.on('change', (event: AMap.Circle.EventMap['change']) => { - // $ExpectType "change" - event.type; - // $ExpectType Circle - event.target; -}); diff --git a/types/amap-js-api/test/overlay/contextMenu.ts b/types/amap-js-api/test/overlay/contextMenu.ts deleted file mode 100644 index 5c7173d26b..0000000000 --- a/types/amap-js-api/test/overlay/contextMenu.ts +++ /dev/null @@ -1,48 +0,0 @@ -import { - map, - lnglat, - lnglatTuple -} from '../preset'; - -interface ExtraData { - test: number; -} -// $ExpectType ContextMenu -new AMap.ContextMenu(); -// $ExpectType ContextMenu -new AMap.ContextMenu({}); -// $ExpectType ContextMenu -const contextMenu = new AMap.ContextMenu({ - content: '
content
', -}); - -// $ExpectType void -contextMenu.addItem('item', function () { - // $ExpectType HTMLLIElement - this; -}); -// $ExpectType void -contextMenu.addItem('item', () => { }, 1); - -// $ExpectType void -contextMenu.removeItem('item', () => {}); - -// $ExpectType void -contextMenu.open(map, lnglatTuple); -// $ExpectType void -contextMenu.open(map, lnglat); - -// $ExpectType void -contextMenu.close(); - -contextMenu.on('items', (event: AMap.ContextMenu.EventMap['items']) => { - // $ExpectType "items" - event.type; -}); - -contextMenu.on('open', (event: AMap.ContextMenu.EventMap['open']) => { - // $ExpectType "open" - event.type; - // $ExpectType ContextMenu - event.target; -}); diff --git a/types/amap-js-api/test/overlay/ellipse.ts b/types/amap-js-api/test/overlay/ellipse.ts deleted file mode 100644 index c5205d9915..0000000000 --- a/types/amap-js-api/test/overlay/ellipse.ts +++ /dev/null @@ -1,117 +0,0 @@ -import { - map, - lnglat, - lnglatTuple -} from '../preset'; - -interface ExtraData { - test: number; -} -// $ExpectType Ellipse -new AMap.Ellipse(); -// $ExpectType Ellipse -new AMap.Ellipse({}); -// $ExpectType Ellipse -const ellipse = new AMap.Ellipse({ - map, - zIndex: 10, - center: lnglat, - radius: [10000, 15000], - bubble: false, - cursor: 'pointer', - strokeColor: '#FF0000', - strokeOpacity: 0.8, - strokeWeight: 2, - fillColor: '#0000FF', - fillOpacity: 0.5, - strokeStyle: 'dashed', - extData: { test: 1 }, - strokeDasharray: [1, 5] -}); - -// $ExpectType LngLat | undefined -ellipse.getCenter(); - -// $ExpectType void -ellipse.setCenter(lnglat); -// $ExpectType void -ellipse.setCenter(lnglatTuple); - -// $ExpectType Bounds | null -ellipse.getBounds(); - -// $ExpectType void -ellipse.setOptions({ - map, - zIndex: 10, - center: lnglat, - radius: [10000, 15000], - bubble: false, - cursor: 'pointer', - strokeColor: '#FF0000', - strokeOpacity: 0.8, - strokeWeight: 2, - fillColor: '#0000FF', - fillOpacity: 0.5, - strokeStyle: 'dashed', - extData: { test: 1 }, - strokeDasharray: [1, 5] -}); - -const options = ellipse.getOptions(); - -// $ExpectType boolean | undefined -options.bubble; -// $ExpectType LngLat | undefined -options.center; -// $ExpectType boolean | undefined -options.clickable; -// $ExpectType {} | ExtraData | undefined -options.extData; -// $ExpectType string | undefined -options.fillColor; -// $ExpectType number | undefined -options.fillOpacity; -// $ExpectType "miter" | "round" | "bevel" | undefined -options.lineJoin; -// $ExpectType Map | undefined -options.map; -// $ExpectType LngLat[] | undefined -options.path; -// $ExpectType [number, number] | undefined -options.radius; -// $ExpectType string | undefined -options.strokeColor; -// $ExpectType number[] | undefined -options.strokeDasharray; -// $ExpectType number | undefined -options.strokeOpacity; -// $ExpectType "dashed" | "solid" | undefined -options.strokeStyle; -// $ExpectType number | undefined -options.strokeWeight; -// $ExpectType string | undefined -options.texture; -// $ExpectType number | undefined -options.zIndex; - -// $ExpectType void -ellipse.hide(); - -// $ExpectType void -ellipse.show(); - -// $ExpectType void -ellipse.setMap(null); -// $ExpectType void -ellipse.setMap(map); - -// $ExpectType void -ellipse.setExtData({test: 2}); -// $ExpectType {} | ExtraData -ellipse.getExtData(); - -// $ExpectType boolean -ellipse.contains(lnglat); -// $ExpectType boolean -ellipse.contains(lnglatTuple); diff --git a/types/amap-js-api/test/overlay/geoJSON.ts b/types/amap-js-api/test/overlay/geoJSON.ts deleted file mode 100644 index ee8c501472..0000000000 --- a/types/amap-js-api/test/overlay/geoJSON.ts +++ /dev/null @@ -1,106 +0,0 @@ -import { - map, - lnglatTuple -} from '../preset'; - -declare const marker: AMap.Marker; -declare const polyline: AMap.Polyline; -declare const polygon: AMap.Polygon; - -interface ExtraData { - test: number; -} - -const geoJSONObject: AMap.GeoJSON.GeoJSONObject[] = [ - { - type: 'Feature', - properties: {}, - geometry: { - type: 'Point', - coordinates: lnglatTuple - } - }, - { - type: 'Feature', - properties: { test: 1 }, - geometry: { - type: 'LineString', - coordinates: [lnglatTuple, lnglatTuple] - } - } -]; - -// $ExpectType GeoJSON -new AMap.GeoJSON(); -// $ExpectType GeoJSON -new AMap.GeoJSON({}); -// $ExpectType GeoJSON -const geoJSON = new AMap.GeoJSON({ - geoJSON: geoJSONObject, - getMarker(obj, lnglat) { - // $ExpectType GeoJSONObject - obj; - // $ExpectType LngLat - lnglat; - return marker; - }, - getPolyline(obj, lnglats) { - // $ExpectType GeoJSONObject - obj; - // $ExpectType LngLat[] - lnglats; - return polyline; - }, - getPolygon(obj, lnglats) { - // $ExpectType GeoJSONObject - obj; - // $ExpectType LngLat[] - lnglats; - return polygon; - }, - coordsToLatLng(coord) { - // $ExpectType LngLat - coord; - return coord; - } -}); - -// $ExpectType void -geoJSON.importData(geoJSONObject); - -// $ExpectType GeoJSON -geoJSON.removeOverlay(marker); -// $ExpectType GeoJSON -geoJSON.removeOverlay([marker]); - -// $ExpectType boolean -geoJSON.hasOverlay(marker); -// $ExpectType boolean -geoJSON.hasOverlay(m => m === marker); - -// $ExpectType GeoJSON -geoJSON.addOverlay(marker); -// $ExpectType GeoJSON -geoJSON.addOverlay([marker]); - -// $ExpectType GeoJSONObject[] -geoJSON.toGeoJSON(); - -// $ExpectType GeoJSON -geoJSON.setMap(null); -// $ExpectType GeoJSON -geoJSON.setMap(map); - -// $ExpectType GeoJSON -geoJSON.hide(); - -// $ExpectType GeoJSON -geoJSON.show(); - -type ClickEvent = AMap.MapsEvent<'click', AMap.Overlay>; -geoJSON.on('click', (event: ClickEvent) => { - // $ExpectType "click" - event.type; - // $ExpectType Overlay - event.target; -}); diff --git a/types/amap-js-api/test/overlay/icon.ts b/types/amap-js-api/test/overlay/icon.ts deleted file mode 100644 index 8576685b8a..0000000000 --- a/types/amap-js-api/test/overlay/icon.ts +++ /dev/null @@ -1,32 +0,0 @@ -import { - size, - pixel, - icon -} from '../preset'; - -// $ExpectType Icon -new AMap.Icon(); -// $ExpectType Icon -new AMap.Icon({}); -// $ExpectType Icon -new AMap.Icon({ - size, - imageOffset: pixel, - image: 'image uri', - imageSize: size -}); -// $ExpectType Icon -new AMap.Icon({ - size: [1, 2], - imageOffset: pixel, - image: 'image uri', - imageSize: [1, 2] -}); - -// $ExpectType Size -icon.getImageSize(); - -// $ExpectType void -icon.setImageSize(size); -// $ExpectType void -icon.setImageSize([1, 2]); diff --git a/types/amap-js-api/test/overlay/infoWindow.ts b/types/amap-js-api/test/overlay/infoWindow.ts deleted file mode 100644 index 3fa4b0e656..0000000000 --- a/types/amap-js-api/test/overlay/infoWindow.ts +++ /dev/null @@ -1,81 +0,0 @@ -import { - map, - lnglat, - size, - pixel, - div, - lnglatTuple -} from '../preset'; - -interface ExtraData { - test: number; -} - -// $ExpectType InfoWindow -new AMap.InfoWindow(); -// $ExpectType InfoWindow -new AMap.InfoWindow({}); -// $ExpectType InfoWindow -const infoWindow = new AMap.InfoWindow({ - isCustom: false, - autoMove: false, - closeWhenClickMap: false, - content: 'content', - size: [100, 100], - offset: new AMap.Pixel(10, 10), - position: lnglat, - showShadow: true -}); - -// $ExpectType void -infoWindow.open(map); -// $ExpectType void -infoWindow.open(map, lnglat); -// $ExpectType void -infoWindow.open(map, lnglatTuple); - -// $ExpectType void -infoWindow.close(); - -// $ExpectType boolean -infoWindow.getIsOpen(); - -// $ExpectType void -infoWindow.setContent('content'); -// $ExpectType void -infoWindow.setContent(div); - -// $ExpectType string | HTMLElement | undefined -infoWindow.getContent(); - -// $ExpectType void -infoWindow.setPosition(lnglat); -// $ExpectType void -infoWindow.setPosition(lnglatTuple); - -// $ExpectType LngLat | undefined -infoWindow.getPosition(); - -// $ExpectType Size | undefined -infoWindow.getSize(); - -infoWindow.on('change', (event: AMap.InfoWindow.EventMap['change']) => { - // $ExpectType "change" - event.type; - // $ExpectType InfoWindow - event.target; -}); - -infoWindow.on('close', (event: AMap.InfoWindow.EventMap['close']) => { - // $ExpectType "close" - event.type; - // $ExpectType InfoWindow - event.target; -}); - -infoWindow.on('open', (event: AMap.InfoWindow.EventMap['open']) => { - // $ExpectType "open" - event.type; - // $ExpectType InfoWindow - event.target; -}); diff --git a/types/amap-js-api/test/overlay/marker.ts b/types/amap-js-api/test/overlay/marker.ts deleted file mode 100644 index 635ce724c8..0000000000 --- a/types/amap-js-api/test/overlay/marker.ts +++ /dev/null @@ -1,195 +0,0 @@ -import { - map, - lnglat -} from '../preset'; - -declare var pixel: AMap.Pixel; -declare var domEle: HTMLElement; -declare var markerShape: AMap.MarkerShape; -declare var icon: AMap.Icon; - -interface ExtraData { - test: number; -} - -// $ExpectType Marker -new AMap.Marker(); -// $ExpectType Marker -new AMap.Marker(); -// $ExpectType Marker -new AMap.Marker({}); -// $ExpectType Marker -const marker = new AMap.Marker({ - map, - position: lnglat, - offset: pixel, - icon: 'iconUrl', - content: 'htmlString', - topWhenClick: true, - raiseOnDrag: true, - cursor: 'default', - visible: true, - zIndex: 10, - angle: 10, - autoRotation: true, - animation: 'AMAP_ANIMATION_BOUNCE', - shadow: icon, - title: '123', - clickable: true, - shape: markerShape, - extData: { - test: 123 - } -}); - -// $ExpectType void -marker.markOnAMAP({ - name: '123', - position: [1, 2] -}); -// $ExpectType void -marker.markOnAMAP(); -// $ExpectType void -marker.markOnAMAP({}); -// $ExpectType void -marker.markOnAMAP({ - position: [1, 2], - name: '123' -}); - -// $ExpectType Pixel -marker.getOffset(); - -// $ExpectType void -marker.setOffset(pixel); - -// $ExpectType void -marker.setAnimation('AMAP_ANIMATION_BOUNCE'); - -// $ExpectType AnimationName -marker.getAnimation(); - -// $ExpectType void -marker.setClickable(true); - -// $ExpectType boolean -marker.getClickable(); - -// $ExpectType LngLat | undefined -marker.getPosition(); - -// $ExpectType void -marker.setPosition(lnglat); - -// $ExpectType void -marker.setAngle(0); - -// $ExpectType void -marker.setLabel(); -// $ExpectType void -marker.setLabel({}); -// $ExpectType void -marker.setLabel({ - content: 'label content', - offset: pixel -}); - -// $ExpectType Label | undefined -marker.getLabel(); - -// $ExpectType number -marker.getAngle(); - -// $ExpectType void -marker.setzIndex(100); - -// $ExpectType number -marker.getzIndex(); - -// $ExpectType void -marker.setIcon('icon uri'); -// $ExpectType void -marker.setIcon(icon); - -// $ExpectType string | Icon | undefined -marker.getIcon(); - -// $ExpectType void -marker.setDraggable(true); - -// $ExpectType boolean -marker.getDraggable(); - -// $ExpectType void -marker.setCursor('default'); - -// $ExpectType void -marker.setContent('content'); -// $ExpectType void -marker.setContent(domEle); - -// $ExpectType string | HTMLElement -marker.getContent(); - -// $ExpectType void -marker.moveAlong([lnglat], 100); -// $ExpectError -marker.moveAlong([[1, 2]], 100); -// $ExpectType void -marker.moveAlong([lnglat], 100, t => t, false); - -// $ExpectType void -marker.moveTo(lnglat, 100); -// $ExpectType void -marker.moveTo([1, 2], 100); -// $ExpectType void -marker.moveTo([1, 2], 100, t => t); - -// $ExpectType void -marker.stopMove(); - -// $ExpectType boolean -marker.pauseMove(); - -// $ExpectType boolean -marker.resumeMove(); - -// $ExpectType void -marker.setMap(map); - -// $ExpectType void -marker.setTitle('title'); -// $ExpectError -marker.setTitle(); - -// $ExpectType string | undefined -marker.getTitle(); - -// $ExpectType void -marker.setTop(true); - -// $ExpectType boolean -marker.getTop(); - -// $ExpectType void -marker.setShadow(); -// $ExpectType void -marker.setShadow(icon); -// $ExpectType void -marker.setShadow('shadow url'); - -// $ExpectType string | Icon | undefined -marker.getShadow(); - -// $ExpectType void -marker.setShape(); -// $ExpectType void -marker.setShape(markerShape); - -// $ExpectType MarkerShape | undefined -marker.getShape(); - -marker.on('click', (event: AMap.Marker.EventMap['click']) => { - // $ExpectType {} | ExtraData - event.target.getExtData(); -}); diff --git a/types/amap-js-api/test/overlay/markerShape.ts b/types/amap-js-api/test/overlay/markerShape.ts deleted file mode 100644 index 259b68cf20..0000000000 --- a/types/amap-js-api/test/overlay/markerShape.ts +++ /dev/null @@ -1,26 +0,0 @@ -// $ExpectType MarkerShape -new AMap.MarkerShape({ - type: 'circle', - coords: [1, 1, 1] -}); -// $ExpectType MarkerShape -new AMap.MarkerShape({ - type: 'rect', - coords: [1, 1, 1, 2] -}); -// $ExpectType MarkerShape -new AMap.MarkerShape({ - type: 'poly', - coords: [1, 2, 3, 4, 5] -}); - -// $ExpectError -new AMap.MarkerShape({ - type: 'circle', - coords: [1, 1] -}); -// $ExpectError -new AMap.MarkerShape({ - type: 'rect', - coords: [1, 1, 1, 2, 2] -}); diff --git a/types/amap-js-api/test/overlay/overlay.ts b/types/amap-js-api/test/overlay/overlay.ts deleted file mode 100644 index 6a301e7091..0000000000 --- a/types/amap-js-api/test/overlay/overlay.ts +++ /dev/null @@ -1,27 +0,0 @@ -import { - map -} from '../preset'; -interface ExtraData { - test: number; -} -declare const overlay: AMap.Overlay; - -// $ExpectType void -overlay.show(); - -// $ExpectType void -overlay.hide(); - -// $ExpectType Map | null | undefined -overlay.getMap(); - -// $ExpectType void -overlay.setMap(map); -// $ExpectType void -overlay.setMap(null); - -// $ExpectError -overlay.setExtData({ any: 123 }); - -// $ExpectError ExtraData -overlay.getExtData(); diff --git a/types/amap-js-api/test/overlay/overlayGroup.ts b/types/amap-js-api/test/overlay/overlayGroup.ts deleted file mode 100644 index 11e04f91cf..0000000000 --- a/types/amap-js-api/test/overlay/overlayGroup.ts +++ /dev/null @@ -1,108 +0,0 @@ -import { - map, - lnglat, - pixel, - circle, - marker, - markerShape, - icon -} from '../preset'; - -// $ExpectType OverlayGroup, any> -const overlayGroup2 = new AMap.OverlayGroup(); -// $ExpectType OverlayGroup, any> -new AMap.OverlayGroup(marker); -// $ExpectType OverlayGroup, any> -const overlayGroup = new AMap.OverlayGroup([marker]); - -// $ExpectType OverlayGroup, any> -overlayGroup.addOverlay(marker); -// $ExpectType OverlayGroup, any> -overlayGroup.addOverlay([marker]); -// $ExpectError -overlayGroup.addOverlay([circle]); - -// $ExpectType OverlayGroup, any> -overlayGroup.addOverlays(marker); -// $ExpectType OverlayGroup, any> -overlayGroup.addOverlays([marker]); - -// $ExpectType Marker[] -overlayGroup.getOverlays(); - -// $ExpectType boolean -overlayGroup.hasOverlay(marker); -// $ExpectType boolean -overlayGroup.hasOverlay(o => o === marker); - -// $ExpectType OverlayGroup, any> -overlayGroup.removeOverlay(marker); -// $ExpectType OverlayGroup, any> -overlayGroup.removeOverlay([marker]); - -// $ExpectType OverlayGroup, any> -overlayGroup.removeOverlays(marker); -// $ExpectType OverlayGroup, any> -overlayGroup.removeOverlays([marker]); - -// $ExpectType OverlayGroup, any> -overlayGroup.clearOverlays(); - -// $ExpectType OverlayGroup, any> -overlayGroup.eachOverlay(function(overlay, index, overlays) { - // $ExpectType Marker - overlay; - // $ExpectType number - index; - // $ExpectType Marker[] - overlays; - // $ExpectType Marker - this; -}); - -// $ExpectType OverlayGroup, any> -overlayGroup.setMap(null); -// $ExpectType OverlayGroup, any> -overlayGroup.setMap(map); - -// $ExpectType OverlayGroup, any> -overlayGroup2.setOptions({ - test: 1 -}); -// $ExpectType OverlayGroup, any> -overlayGroup.setOptions({ - map, - position: lnglat, - offset: pixel, - icon: 'iconUrl', - content: 'htmlString', - topWhenClick: true, - raiseOnDrag: true, - cursor: 'default', - visible: true, - zIndex: 10, - angle: 10, - autoRotation: true, - animation: 'AMAP_ANIMATION_BOUNCE', - shadow: icon, - title: '123', - clickable: true, - shape: markerShape, - extData: { - test: 123 - } -}); - -// $ExpectType OverlayGroup, any> -overlayGroup.show(); - -// $ExpectType OverlayGroup, any> -overlayGroup.hide(); - -type ClickEvent = AMap.MapsEvent<'click', AMap.Overlay>; -overlayGroup.on('click', (event: ClickEvent) => { - // $ExpectType "click" - event.type; - // $ExpectType Overlay - event.target; -}); diff --git a/types/amap-js-api/test/overlay/polygon.ts b/types/amap-js-api/test/overlay/polygon.ts deleted file mode 100644 index d41a597d45..0000000000 --- a/types/amap-js-api/test/overlay/polygon.ts +++ /dev/null @@ -1,123 +0,0 @@ -import { - map, - lnglat, - lnglatTuple -} from '../preset'; - -interface ExtraData { - test: number; -} - -const path1 = [lnglatTuple, lnglatTuple, lnglatTuple, lnglatTuple, lnglatTuple]; -const path2 = [lnglat, lnglat, lnglat, lnglat, lnglat]; - -// $ExpectType Polygon -new AMap.Polygon(); -// $ExpectType Polygon -new AMap.Polygon({}); -// $ExpectType Polygon -const polygon = new AMap.Polygon({ - map, - zIndex: 10, - bubble: true, - cursor: 'pointer', - strokeColor: '#00FF00', - strokeOpacity: 0.3, - strokeWeight: 5, - fillColor: '#0000FF', - fillOpacity: 0.5, - draggable: true, - extData: { test: 1 }, - strokeStyle: 'dashed', - strokeDasharray: [2, 4], - path: path1 -}); - -// $ExpectType void -polygon.setPath(path1); -// $ExpectType void -polygon.setPath(path2); -// $ExpectType void -polygon.setPath([path1, path2]); - -// $ExpectType LngLat[] | LngLat[][] -polygon.getPath(); - -// $ExpectType void -polygon.setOptions({ - map, - zIndex: 10, - bubble: true, - cursor: 'pointer', - strokeColor: '#00FF00', - strokeOpacity: 0.8, - strokeWeight: 5, - fillColor: '#0000FF', - fillOpacity: 0.5, - draggable: true, - extData: { test: 1 }, - strokeStyle: 'dashed', - strokeDasharray: [4, 2], - path: [path2, path1] -}); - -const options = polygon.getOptions(); -// $ExpectType boolean | undefined -options.bubble; -// $ExpectType boolean | undefined -options.clickable; -// $ExpectType {} | ExtraData | undefined -options.extData; -// $ExpectType string | undefined -options.fillColor; -// $ExpectType number | undefined -options.fillOpacity; -// $ExpectType "miter" | "round" | "bevel" | undefined -options.lineJoin; -// $ExpectType Map | undefined -options.map; -// $ExpectType LngLat[] | LngLat[][] | undefined -options.path; -// $ExpectType string | undefined -options.strokeColor; -// $ExpectType number[] | undefined -options.strokeDasharray; -// $ExpectType number | undefined -options.strokeOpacity; -// $ExpectType "dashed" | "solid" | undefined -options.strokeStyle; -// $ExpectType number | undefined -options.strokeWeight; -// $ExpectType string | undefined -options.texture; -// $ExpectType number | undefined -options.zIndex; - -// $ExpectType Bounds | null -polygon.getBounds(); - -// $ExpectType number -polygon.getArea(); - -// $ExpectType void -polygon.setMap(null); -// $ExpectType void -polygon.setMap(map); - -// $ExpectType void -polygon.setExtData({ test: 1 }); - -// $ExpectType {} | ExtraData -polygon.getExtData(); - -// $ExpectType boolean -polygon.contains(lnglat); -// $ExpectType boolean -polygon.contains(lnglatTuple); - -polygon.on('click', (event: AMap.Polygon.EventMap['click']) => { - // $ExpectType "click" - event.type; - // $ExpectType Polygon - event.target; -}); diff --git a/types/amap-js-api/test/overlay/polyline.ts b/types/amap-js-api/test/overlay/polyline.ts deleted file mode 100644 index fc8d52b058..0000000000 --- a/types/amap-js-api/test/overlay/polyline.ts +++ /dev/null @@ -1,139 +0,0 @@ -import { - map, - lnglat, - lnglatTuple -} from '../preset'; - -interface ExtraData { - test: number; -} - -// $ExpectType Polyline -new AMap.Polyline(); -// $ExpectType Polyline -new AMap.Polyline({}); -// $ExpectType Polyline -const polyline = new AMap.Polyline({ - map, - zIndex: 10, - bubble: true, - cursor: 'default', - geodesic: true, - isOutline: true, - borderWeight: 1, - outlineColor: '#AA0000', - path: [lnglat], - strokeColor: '#0000AA', - strokeOpacity: 0.5, - strokeWeight: 10, - strokeStyle: 'dashed', - strokeDasharray: [20, 10, 20], - lineJoin: 'bevel', - lineCap: 'butt', - draggable: true, - extData: { test: 1 }, - showDir: true -}); -// Polyline - -// $ExpectType void -polyline.setPath([lnglat]); -// $ExpectType void -polyline.setPath([lnglatTuple]); - -// $ExpectType void -polyline.setOptions({}); -// $ExpectType void -polyline.setOptions({ - map, - zIndex: 10, - bubble: true, - cursor: 'default', - geodesic: true, - isOutline: true, - borderWeight: 1, - outlineColor: '#AA0000', - path: [lnglat, lnglat], - strokeColor: '#0000AA', - strokeOpacity: 0.5, - strokeWeight: 10, - strokeStyle: 'dashed', - strokeDasharray: [20, 10, 20], - lineJoin: 'bevel', - lineCap: 'butt', - draggable: true, - extData: { test: 1 }, - showDir: true -}); - -const options = polyline.getOptions(); -// $ExpectType number | undefined -options.borderWeight; -// $ExpectType boolean | undefined -options.bubble; -// $ExpectType boolean | undefined -options.clickable; -// $ExpectType string | undefined -options.dirColor; -// $ExpectType string | undefined -options.dirImg; -// $ExpectType {} | ExtraData | undefined -options.extData; -// $ExpectType boolean | undefined -options.geodesic; -// $ExpectType boolean | undefined -options.isOutline; -// $ExpectType "round" | "butt" | "square" | undefined -options.lineCap; -// $ExpectType "miter" | "round" | "bevel" | undefined -options.lineJoin; -// $ExpectType Map | undefined -options.map; -// $ExpectType string | undefined -options.outlineColor; -// $ExpectType LngLat[] | undefined -options.path; -// $ExpectType boolean | undefined -options.showDir; -// $ExpectType string | undefined -options.strokeColor; -// $ExpectType number[] | undefined -options.strokeDasharray; -// $ExpectType number | undefined -options.strokeOpacity; -// $ExpectType "dashed" | "solid" | undefined -options.strokeStyle; -// $ExpectType number | undefined -options.strokeWeight; -// $ExpectType number | undefined -options.zIndex; - -// $ExpectType number -polyline.getLength(); - -// $ExpectType Bounds | null -polyline.getBounds(); - -// $ExpectType void -polyline.hide(); - -// $ExpectType void -polyline.show(); - -// $ExpectType void -polyline.setMap(null); -// $ExpectType void -polyline.setMap(map); - -// $ExpectType void -polyline.setExtData({test: 1}); - -// $ExpectType {} | ExtraData -polyline.getExtData(); - -polyline.on('click', (event: AMap.Polyline.EventMap['click']) => { - // $ExpectType "click" - event.type; - // $ExpectType Polyline - event.target; -}); diff --git a/types/amap-js-api/test/overlay/rectangle.ts b/types/amap-js-api/test/overlay/rectangle.ts deleted file mode 100644 index d2cafa8f09..0000000000 --- a/types/amap-js-api/test/overlay/rectangle.ts +++ /dev/null @@ -1,121 +0,0 @@ -import { - map, - lnglat, - bounds, - lnglatTuple -} from '../preset'; - -interface ExtraData { - test: number; -} - -// $ExpectType Rectangle -new AMap.Rectangle(); -// $ExpectType Rectangle -new AMap.Rectangle({}); -// $ExpectType Rectangle -const rectangle = new AMap.Rectangle({ - map, - zIndex: 10, - bounds, - bubble: false, - cursor: 'pointer', - strokeColor: '#00FF00', - strokeOpacity: 0.8, - strokeWeight: 2, - fillColor: '#0000FF', - fillOpacity: 0.5, - strokeStyle: 'solid', - extData: { test: 1 }, - strokeDasharray: [1, 5] -}); - -// $ExpectType Bounds | undefined -rectangle.getBounds(); - -// $ExpectType void -rectangle.setBounds(bounds); - -// $ExpectType void -rectangle.setOptions({}); -// $ExpectType void -rectangle.setOptions({ - map, - zIndex: 10, - bounds, - bubble: false, - cursor: 'pointer', - strokeColor: '#00FF00', - strokeOpacity: 0.8, - strokeWeight: 2, - fillColor: '#0000FF', - fillOpacity: 0.5, - strokeStyle: 'solid', - extData: { test: 1 }, - strokeDasharray: [1, 5] -}); - -const options = rectangle.getOptions(); -// $ExpectType Bounds | undefined -options.bounds; -// $ExpectType boolean | undefined -options.bubble; -// $ExpectType boolean | undefined -options.clickable; -// $ExpectType {} | ExtraData | undefined -options.extData; -// $ExpectType string | undefined -options.fillColor; -// $ExpectType number | undefined -options.fillOpacity; -// $ExpectType "miter" | "round" | "bevel" | undefined -options.lineJoin; -// $ExpectType Map | undefined -options.map; -// $ExpectType LngLat[] | undefined -options.path; -// $ExpectType string | undefined -options.strokeColor; -// $ExpectType number[] | undefined -options.strokeDasharray; -// $ExpectType number | undefined -options.strokeOpacity; -// $ExpectType "dashed" | "solid" | undefined -options.strokeStyle; -// $ExpectType number | undefined -options.strokeWeight; -// $ExpectType string | undefined -options.texture; -// $ExpectType number | undefined -options.zIndex; - -// $ExpectType void -rectangle.hide(); - -// $ExpectType void -rectangle.show(); - -// $ExpectType void -rectangle.setExtData({test: 2}); - -// $ExpectType {} | ExtraData -rectangle.getExtData(); - -// $ExpectType boolean -rectangle.contains(lnglat); -// $ExpectType boolean -rectangle.contains(lnglatTuple); - -rectangle.on('click', (event: AMap.Rectangle.EventMap['click']) => { - // $ExpectType "click" - event.type; - // $ExpectType Rectangle - event.target; -}); - -rectangle.on('setBounds', (event: AMap.Rectangle.EventMap['setBounds']) => { - // $ExpectType "setBounds" - event.type; - // $ExpectError - event.target; -}); diff --git a/types/amap-js-api/test/overlay/text.ts b/types/amap-js-api/test/overlay/text.ts deleted file mode 100644 index c4d678493c..0000000000 --- a/types/amap-js-api/test/overlay/text.ts +++ /dev/null @@ -1,169 +0,0 @@ -import { - map, - marker, - lnglat, - pixel, - lnglatTuple, - icon -} from '../preset'; - -interface ExtraData { - test: number; -} - -// $ExpectType Text -new AMap.Text(); -// $ExpectType Text -new AMap.Text({}); -// $ExpectType Text -const text = new AMap.Text({ - text: 'content', - textAlign: 'center', - verticalAlign: 'top', - map, - position: lnglat, - offset: pixel, - topWhenClick: true, - bubble: true, - draggable: true, - raiseOnDrag: true, - cursor: 'default', - visible: true, - zIndex: 100, - angle: 45, - autoRotation: true, - animation: 'AMAP_ANIMATION_BOUNCE', - shadow: 'https://webapi.amap.com/theme/v1.3/markers/0.png', - title: 'title', - clickable: true, - extData: { test: 1 } -}); - -// $ExpectType string -text.getText(); - -// $ExpectType void -text.setText('123'); - -// $ExpectType void -text.setStyle({ - background: 'red', - width: '200px' -}); - -// $ExpectType void -text.markOnAMAP({ - name: '123', - position: lnglatTuple -}); - -// $ExpectType Pixel -text.getOffset(); - -// $ExpectType void -text.setOffset(pixel); - -// $ExpectType void -text.setAnimation('AMAP_ANIMATION_BOUNCE'); - -// $ExpectType AnimationName -text.getAnimation(); - -// $ExpectType void -text.setClickable(true); - -// $ExpectType boolean -text.getClickable(); - -// $ExpectType LngLat | undefined -text.getPosition(); - -// $ExpectType void -text.setAngle(10); - -// $ExpectType number -text.getAngle(); - -// $ExpectType void -text.setzIndex(1); - -// $ExpectType number -text.getzIndex(); - -// $ExpectType void -text.setDraggable(true); - -// $ExpectType boolean -text.getDraggable(); - -// $ExpectType void -text.hide(); - -// $ExpectType void -text.show(); - -// $ExpectType void -text.setCursor('default'); - -// $ExpectType void -text.moveAlong([lnglat], 100); - -// $ExpectType void -text.moveAlong([lnglat], 100); -// $ExpectError -text.moveAlong([[1, 2]], 100); -// $ExpectType void -text.moveAlong([lnglat], 100, t => t, false); - -// $ExpectType void -text.moveTo(lnglat, 100); -// $ExpectType void -text.moveTo([1, 2], 100); -// $ExpectType void -text.moveTo([1, 2], 100, t => t); - -// $ExpectType void -text.stopMove(); - -// $ExpectType boolean -text.pauseMove(); - -// $ExpectType boolean -text.resumeMove(); - -// $ExpectType void -text.setMap(map); - -// $ExpectType void -text.setTitle('title'); -// $ExpectError -text.setTitle(); - -// $ExpectType string | undefined -text.getTitle(); - -// $ExpectType void -text.setTop(true); - -// $ExpectType boolean -text.getTop(); - -// $ExpectType void -text.setShadow(); -// $ExpectType void -text.setShadow(icon); -// $ExpectType void -text.setShadow('shadow url'); - -// $ExpectType void -text.setExtData({test: 1}); - -// $ExpectType {} | ExtraData -text.getExtData(); - -text.on('click', (event: AMap.Text.EventMap['click']) => { - // $ExpectType "click" - event.type; - // $ExpectType Text - event.target; -}); diff --git a/types/amap-js-api/test/pixel.ts b/types/amap-js-api/test/pixel.ts deleted file mode 100644 index bcb96e4b77..0000000000 --- a/types/amap-js-api/test/pixel.ts +++ /dev/null @@ -1,42 +0,0 @@ -import { - pixel -} from './preset'; - -// $ExpectType Pixel -new AMap.Pixel(10, 20); -// $ExpectType Pixel -new AMap.Pixel(10, 20); - -// $ExpectType number -pixel.getX(); - -// $ExpectType number -pixel.getY(); - -// $ExpectType boolean -pixel.equals(pixel); - -// $ExpectType string -pixel.toString(); - -// $ExpectType Pixel -pixel.add({ x: 1, y: 2 }); -// $ExpectType Pixel -pixel.add({ x: 1, y: 2 }, false); - -// $ExpectType Pixel -pixel.round(); - -// $ExpectType Pixel -pixel.floor(); - -// $ExpectType number -pixel.length(); - -// $ExpectType number | null -pixel.direction(); - -// $ExpectType Pixel -pixel.toFixed(); -// $ExpectType Pixel -pixel.toFixed(2); diff --git a/types/amap-js-api/test/preset.ts b/types/amap-js-api/test/preset.ts deleted file mode 100644 index 2c7bb37d59..0000000000 --- a/types/amap-js-api/test/preset.ts +++ /dev/null @@ -1,29 +0,0 @@ -declare const map: AMap.Map; -declare const lnglat: AMap.LngLat; -declare const size: AMap.Size; -declare const lnglatTuple: [number, number]; -declare const pixel: AMap.Pixel; -declare const marker: AMap.Marker; -declare const circle: AMap.Circle; -declare const markerShape: AMap.MarkerShape; -declare const icon: AMap.Icon; -declare const bounds: AMap.Bounds; -declare const div: HTMLDivElement; -declare const polygon: AMap.Polygon; -declare const lang: AMap.Lang; - -export { - map, - lnglat, - size, - lnglatTuple, - pixel, - marker, - circle, - markerShape, - icon, - bounds, - div, - polygon, - lang -}; diff --git a/types/amap-js-api/test/size.ts b/types/amap-js-api/test/size.ts deleted file mode 100644 index bdd700f532..0000000000 --- a/types/amap-js-api/test/size.ts +++ /dev/null @@ -1,16 +0,0 @@ -import { size } from './preset'; - -// $ExpectType Size -new AMap.Size(10, 20); - -// $ExpectType number -size.getHeight(); - -// $ExpectType number -size.getWidth(); - -// $ExpectType string -size.toString(); - -// $ExpectType boolean -size.contains({ x: 10, y: 10 }); diff --git a/types/amap-js-api/test/util.ts b/types/amap-js-api/test/util.ts deleted file mode 100644 index c238070e21..0000000000 --- a/types/amap-js-api/test/util.ts +++ /dev/null @@ -1,79 +0,0 @@ -import * as preset from './preset'; - -const util = AMap.Util; - -// $ExpectType string -util.colorNameToHex('colorName'); - -// $ExpectType string -util.rgbHex2Rgba('rgbHex'); - -// $ExpectType string -util.argbHex2Rgba('argbHex'); - -// $ExpectType boolean -util.isEmpty({}); -// $ExpectError -util.isEmpty(1); - -// $ExpectType number[] -util.deleteItemFromArray([1], 1); - -// $ExpectType number[] -util.deleteItemFromArrayByIndex([1], 1); - -// $ExpectType number -util.indexOf([1], 1); -// $ExpectError -util.indexOf([1], '1'); - -// $ExpectType number -util.format(1); -// $ExpectType number -util.format(1, 1); - -declare const value1: number | number[]; -// $ExpectType boolean -util.isArray(value1); -if (util.isArray(value1)) { - // $ExpectType number[] - value1; -} else { - // $ExpectType number - value1; -} - -declare const value2: number | HTMLElement; -// $ExpectType boolean -util.isDOM(value2); -if (util.isDOM(value2)) { - // $ExpectType HTMLElement - value2; -} else { - // $ExpectType number - value2; -} - -// $ExpectType boolean -util.includes([1], 1); -// $ExpectError -util.includes([1], '1'); - -// $ExpectType number -util.requestIdleCallback(() => { }); -// $ExpectType number -const idleCallbackHandle = util.requestIdleCallback(() => { }, { timeout: 1 }); - -// $ExpectType void -util.cancelIdleCallback(idleCallbackHandle); - -// $ExpectType number -util.requestAnimFrame(() => { }); -// $ExpectType number -const animFrameHandle = util.requestAnimFrame(function () { - // $ExpectType number - this.test; -}, { test: 1 }); - -// $ExpectType void -util.cancelAnimFrame(animFrameHandle); diff --git a/types/amap-js-api/test/view2d.ts b/types/amap-js-api/test/view2d.ts deleted file mode 100644 index 2560922a5a..0000000000 --- a/types/amap-js-api/test/view2d.ts +++ /dev/null @@ -1,22 +0,0 @@ -import { lnglat } from './preset'; - -// $ExpectType View2D -new AMap.View2D(); -// $ExpectType View2D -new AMap.View2D({}); - -// $ExpectType View2D -new AMap.View2D({ - center: [1, 2], - rotation: 1, - zoom: 10, - crs: 'EPGS3395' -}); - -// $ExpectType View2D -const view2d = new AMap.View2D({ - center: lnglat -}); - -// $ExpectType View2D -view2d.on('complete', () => { }); diff --git a/types/amap-js-api/tsconfig.json b/types/amap-js-api/tsconfig.json index e63a35d326..a26facba9e 100644 --- a/types/amap-js-api/tsconfig.json +++ b/types/amap-js-api/tsconfig.json @@ -58,48 +58,9 @@ "overlay/text.d.ts", "pixel.d.ts", "size.d.ts", - "test/arryBounds.ts", - "test/bounds.ts", - "test/browser.ts", - "test/convert-from.ts", - "test/dom-util.ts", - "test/event.ts", - "test/geometry-util.ts", - "test/layer/buildings.ts", - "test/layer/canvasLayer.ts", - "test/layer/flexible.ts", - "test/layer/imageLayer.ts", - "test/layer/layer.ts", - "test/layer/layerGroup.ts", - "test/layer/massMarks.ts", - "test/layer/tileLayer.ts", - "test/layer/videoLayer.ts", - "test/layer/wms.ts", - "test/layer/wmts.ts", - "test/lnglat.ts", - "test/map.ts", - "test/overlay/bezierCurve.ts", - "test/overlay/circle.ts", - "test/overlay/contextMenu.ts", - "test/overlay/ellipse.ts", - "test/overlay/geoJSON.ts", - "test/overlay/icon.ts", - "test/overlay/infoWindow.ts", - "test/overlay/marker.ts", - "test/overlay/markerShape.ts", - "test/overlay/overlay.ts", - "test/overlay/overlayGroup.ts", - "test/overlay/polygon.ts", - "test/overlay/polyline.ts", - "test/overlay/rectangle.ts", - "test/overlay/text.ts", - "test/pixel.ts", - "test/preset.ts", - "test/size.ts", - "test/util.ts", - "test/view2d.ts", "type-util.d.ts", "util.d.ts", - "view2D.d.ts" + "view2D.d.ts", + "amap-js-api-tests.ts" ] } diff --git a/types/amap-js-api/tslint.json b/types/amap-js-api/tslint.json index ab1e56673f..f93cf8562a 100644 --- a/types/amap-js-api/tslint.json +++ b/types/amap-js-api/tslint.json @@ -1,10 +1,3 @@ { - "extends": "dtslint/dt.json", - "rules": { - "only-arrow-functions": false, - "space-before-function-paren": false, - "no-var-keyword": false, - "no-unnecessary-class": false, - "file-name-casing": false - } + "extends": "dtslint/dt.json" } From bc341d3bc709dd8e3288c46cb9811f235ff22546 Mon Sep 17 00:00:00 2001 From: breeze9527 Date: Thu, 7 Mar 2019 14:52:59 +0800 Subject: [PATCH 6/6] [amap-js-api] fix lint error --- types/amap-js-api/amap-js-api-tests.ts | 40 +++++++++++++------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/types/amap-js-api/amap-js-api-tests.ts b/types/amap-js-api/amap-js-api-tests.ts index 41b0638526..ee7a2ac583 100644 --- a/types/amap-js-api/amap-js-api-tests.ts +++ b/types/amap-js-api/amap-js-api-tests.ts @@ -2303,7 +2303,7 @@ const testGeoJSON = new AMap.GeoJSON({ obj; // $ExpectType LngLat lnglat; - return testMarker; + return marker; }, getPolyline(obj, lnglats) { // $ExpectType GeoJSONObject @@ -2330,19 +2330,19 @@ const testGeoJSON = new AMap.GeoJSON({ testGeoJSON.importData(geoJSONObject); // $ExpectType GeoJSON -testGeoJSON.removeOverlay(testMarker); +testGeoJSON.removeOverlay(marker); // $ExpectType GeoJSON -testGeoJSON.removeOverlay([testMarker]); +testGeoJSON.removeOverlay([marker]); // $ExpectType boolean -testGeoJSON.hasOverlay(testMarker); +testGeoJSON.hasOverlay(marker); // $ExpectType boolean -testGeoJSON.hasOverlay(m => m === testMarker); +testGeoJSON.hasOverlay(m => m === marker); // $ExpectType GeoJSON -testGeoJSON.addOverlay(testMarker); +testGeoJSON.addOverlay(marker); // $ExpectType GeoJSON -testGeoJSON.addOverlay([testMarker]); +testGeoJSON.addOverlay([marker]); // $ExpectType GeoJSONObject[] testGeoJSON.toGeoJSON(); @@ -2488,7 +2488,7 @@ new AMap.Marker(); // $ExpectType Marker new AMap.Marker({}); // $ExpectType Marker -const testMarker = new AMap.Marker({ +export const testMarker = new AMap.Marker({ map, position: lnglat, offset: pixel, @@ -2730,39 +2730,39 @@ testOverlay.getExtData(); // $ExpectType OverlayGroup, any> const testOverlayGroup2 = new AMap.OverlayGroup(); // $ExpectType OverlayGroup, any> -new AMap.OverlayGroup(testMarker); +new AMap.OverlayGroup(marker); // $ExpectType OverlayGroup, any> -const testOverlayGroup = new AMap.OverlayGroup([testMarker]); +const testOverlayGroup = new AMap.OverlayGroup([marker]); // $ExpectType OverlayGroup, any> -testOverlayGroup.addOverlay(testMarker); +testOverlayGroup.addOverlay(marker); // $ExpectType OverlayGroup, any> -testOverlayGroup.addOverlay([testMarker]); +testOverlayGroup.addOverlay([marker]); // $ExpectError testOverlayGroup.addOverlay([testCircle]); // $ExpectType OverlayGroup, any> -testOverlayGroup.addOverlays(testMarker); +testOverlayGroup.addOverlays(marker); // $ExpectType OverlayGroup, any> -testOverlayGroup.addOverlays([testMarker]); +testOverlayGroup.addOverlays([marker]); // $ExpectType Marker[] testOverlayGroup.getOverlays(); // $ExpectType boolean -testOverlayGroup.hasOverlay(testMarker); +testOverlayGroup.hasOverlay(marker); // $ExpectType boolean -testOverlayGroup.hasOverlay(o => o === testMarker); +testOverlayGroup.hasOverlay(o => o === marker); // $ExpectType OverlayGroup, any> -testOverlayGroup.removeOverlay(testMarker); +testOverlayGroup.removeOverlay(marker); // $ExpectType OverlayGroup, any> -testOverlayGroup.removeOverlay([testMarker]); +testOverlayGroup.removeOverlay([marker]); // $ExpectType OverlayGroup, any> -testOverlayGroup.removeOverlays(testMarker); +testOverlayGroup.removeOverlays(marker); // $ExpectType OverlayGroup, any> -testOverlayGroup.removeOverlays([testMarker]); +testOverlayGroup.removeOverlays([marker]); // $ExpectType OverlayGroup, any> testOverlayGroup.clearOverlays();