From 4eb9a90d847e96eebadbeafdc9b4381b8999f394 Mon Sep 17 00:00:00 2001 From: breeze9527 Date: Tue, 19 Mar 2019 15:27:33 +0800 Subject: [PATCH 1/2] Added type definitions for amap-js-api-indoor-map(IndoorMap plugin of amap-js-api) --- .../amap-js-api-indoor-map-tests.ts | 114 ++++++++++++++++++ types/amap-js-api-indoor-map/index.d.ts | 111 +++++++++++++++++ types/amap-js-api-indoor-map/tsconfig.json | 24 ++++ types/amap-js-api-indoor-map/tslint.json | 3 + 4 files changed, 252 insertions(+) create mode 100644 types/amap-js-api-indoor-map/amap-js-api-indoor-map-tests.ts create mode 100644 types/amap-js-api-indoor-map/index.d.ts create mode 100644 types/amap-js-api-indoor-map/tsconfig.json create mode 100644 types/amap-js-api-indoor-map/tslint.json diff --git a/types/amap-js-api-indoor-map/amap-js-api-indoor-map-tests.ts b/types/amap-js-api-indoor-map/amap-js-api-indoor-map-tests.ts new file mode 100644 index 0000000000..f6efc2dc54 --- /dev/null +++ b/types/amap-js-api-indoor-map/amap-js-api-indoor-map-tests.ts @@ -0,0 +1,114 @@ +// $ExpectType IndoorMap +new AMap.IndoorMap(); +// $ExpectType IndoorMap +new AMap.IndoorMap({}); +// $ExpectType IndoorMap +const indoorMap = new AMap.IndoorMap({ + zIndex: 1, + opacity: 0.5, + cursor: 'cursor', + hideFloorBar: false, + alaysShow: true +}); + +// $ExpectType void +indoorMap.showIndoorMap('indoorMapId'); +// $ExpectType void +indoorMap.showIndoorMap('indoorMapId', (error, result) => { + // $ExpectType Error | null + error; + // $ExpectType SearchResult + result; + // $ExpectType string + result.id; + // $ExpectType 0 | 1 + result.status; + if (result.status === 0) { + // $ExpectType Building + const building = result.building; + { + // $ExpectType number + building.floor; + // $ExpectType FloorDetails + const floorDetails = building.floor_details; + { + // $ExpectType number[] + floorDetails.floor_indexs; + // $ExpectType string[] + floorDetails.floor_names; + // $ExpectType string[] + floorDetails.floor_nonas; + } + // $ExpectType string + building.id; + // $ExpectType LngLat + building.lnglat; + // $ExpectType string + building.name; + } + } else { + // $ExpectType Error + result.error; + } +}); +// $ExpectType void +indoorMap.showIndoorMap('indoorMapId', 1); +// $ExpectType void +indoorMap.showIndoorMap('indoorMapId', 1, () => { }); +// $ExpectType void +indoorMap.showIndoorMap('indoorMapId', 1, 'shopId'); +// $ExpectType void +indoorMap.showIndoorMap('indoorMapId', 1, 'shopId', () => { }); +// $ExpectType void +indoorMap.showIndoorMap('indoorMapId', 1, 'shopId', true); +// $ExpectType void +indoorMap.showIndoorMap('indoorMapId', 1, 'shopId', true, () => { }); + +let floor: undefined | false; +floor = indoorMap.showFloor(1); +floor = indoorMap.showFloor(1, true); + +// $ExpectType void +indoorMap.showFloorBar(); + +// $ExpectType void +indoorMap.hideFloorBar(); + +// $ExpectType void +indoorMap.hideLabels(); + +// $ExpectType string | null +indoorMap.getSelectedBuildingId(); + +// $ExpectType Building | null +const building = indoorMap.getSelectedBuilding(); +if (building) { + // $ExpectType number + building.floor; + // $ExpectType FloorDetails + building.floor_details; + // $ExpectType string + building.id; + // $ExpectType LngLat + building.lnglat; + // $ExpectType string + building.name; +} + +indoorMap.on('complete', (event: AMap.IndoorMap.EventMap['complete']) => { + // $ExpectType "complete" + event.type; +}); + +indoorMap.on('click', (event: AMap.IndoorMap.EventMap['click']) => { + // $ExpectType string + event.building_id; + // $ExpectType number + event.floor; + // $ExpectType LngLat + event.lnglat; + // $ExpectType Shop + event.shop; + // $ExpectType "click" + event.type; +}); diff --git a/types/amap-js-api-indoor-map/index.d.ts b/types/amap-js-api-indoor-map/index.d.ts new file mode 100644 index 0000000000..b19082e926 --- /dev/null +++ b/types/amap-js-api-indoor-map/index.d.ts @@ -0,0 +1,111 @@ +// Type definitions for non-npm package amap-js-api-indoor-map 1.4 +// Project: https://lbs.amap.com/api/javascript-api/reference/indoormap +// Definitions by: breeze9527 +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.8 + +/// + +declare namespace AMap { + namespace IndoorMap { + interface EventMap { + complete: Event<'complete'>; + click: MouseEvent<'click'>; + + floor_complete: Event<'floor_complete', SearchResult>; + mouseover: MouseEvent<'mouseover'>; + mouseout: MouseEvent<'mouseout'>; + } + type MouseEvent = Event; + interface Options extends Layer.Options { + zIndex?: number; + opacity?: number; + cursor?: string; + hideFloorBar?: boolean; + alaysShow?: boolean; + // internal + visible?: boolean; + featurezIndex?: number; + zooms?: [number, number]; + disableIconRender?: boolean; + disableLabelRender?: boolean; + disableHoverMarker?: boolean; + autoLoadBuildingsInTile?: boolean; + } + interface FloorDetails { + floor_indexs: number[]; + floor_nonas: string[]; + floor_names: string[]; + } + type ShopCategory = 'public' | 'connection' | 'shop'; + interface Shop { + id: string; + poiId: string; + building_id: string; + name: string; + lnglat: LngLat; + category: ShopCategory; + } + interface Building { + id: string; + name: string; + lnglat: LngLat; + floor: number; + floor_details: FloorDetails; + } + interface SearchSuccessResult { + id: string; + status: 0; + building: Building; + } + interface SearchErrorResult { + id: string; + status: 1; + error: Error; + } + type SearchResult = SearchSuccessResult | SearchErrorResult; + } + + class IndoorMap extends Layer { + constructor(options?: IndoorMap.Options); + showIndoorMap( + indoorId: string, + floor?: number, + shopId?: string, + noMove?: boolean, + callback?: (error: null | Error, result: IndoorMap.SearchResult) => void + ): void; + showIndoorMap( + indoorId: string, + floor?: number, + shopId?: string, + callback?: (error: null | Error, result: IndoorMap.SearchResult) => void + ): void; + showIndoorMap( + indoorId: string, + floor?: number, + callback?: (error: null | Error, result: IndoorMap.SearchResult) => void + ): void; + showIndoorMap( + indoorId: string, + callback?: (error: null | Error, result: IndoorMap.SearchResult) => void + ): void; + + showFloor(floor: number, noMove?: boolean): false | undefined; + showFloorBar(): void; + hideFloorBar(): void; + showLabels(): void; + hideLabels(): void; + getSelectedBuildingId(): string | null; + getSelectedBuilding(): IndoorMap.Building | null; + + // internal + getFloorBar(): void; + setSelectedBuildingId(id: string): void; + } +} diff --git a/types/amap-js-api-indoor-map/tsconfig.json b/types/amap-js-api-indoor-map/tsconfig.json new file mode 100644 index 0000000000..da736c3c7b --- /dev/null +++ b/types/amap-js-api-indoor-map/tsconfig.json @@ -0,0 +1,24 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6", + "dom" + ], + "noEmit": true, + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "amap-js-api-indoor-map-tests.ts" + ] +} diff --git a/types/amap-js-api-indoor-map/tslint.json b/types/amap-js-api-indoor-map/tslint.json new file mode 100644 index 0000000000..f93cf8562a --- /dev/null +++ b/types/amap-js-api-indoor-map/tslint.json @@ -0,0 +1,3 @@ +{ + "extends": "dtslint/dt.json" +} From 7b79531f48fb6a80eb811a458a3c4d42c8893da4 Mon Sep 17 00:00:00 2001 From: breeze9527 Date: Wed, 20 Mar 2019 17:58:41 +0800 Subject: [PATCH 2/2] [amap-js-api-indoor-map] reverse overloads order --- types/amap-js-api-indoor-map/index.d.ts | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/types/amap-js-api-indoor-map/index.d.ts b/types/amap-js-api-indoor-map/index.d.ts index b19082e926..03c2a6bb2f 100644 --- a/types/amap-js-api-indoor-map/index.d.ts +++ b/types/amap-js-api-indoor-map/index.d.ts @@ -73,29 +73,28 @@ declare namespace AMap { class IndoorMap extends Layer { constructor(options?: IndoorMap.Options); + showIndoorMap( + indoorId: string, + callback?: (error: null | Error, result: IndoorMap.SearchResult) => void + ): void; + showIndoorMap( + indoorId: string, + floor?: number, + callback?: (error: null | Error, result: IndoorMap.SearchResult) => void + ): void; showIndoorMap( indoorId: string, floor?: number, shopId?: string, - noMove?: boolean, callback?: (error: null | Error, result: IndoorMap.SearchResult) => void ): void; showIndoorMap( indoorId: string, floor?: number, shopId?: string, + noMove?: boolean, callback?: (error: null | Error, result: IndoorMap.SearchResult) => void ): void; - showIndoorMap( - indoorId: string, - floor?: number, - callback?: (error: null | Error, result: IndoorMap.SearchResult) => void - ): void; - showIndoorMap( - indoorId: string, - callback?: (error: null | Error, result: IndoorMap.SearchResult) => void - ): void; - showFloor(floor: number, noMove?: boolean): false | undefined; showFloorBar(): void; hideFloorBar(): void;