New definition for non npm-package amap-js-api-driving (#35747)

* [amap-js-api] update to v1.4.14

* Add definition for non npm package: amap-js-api-district-search

* Add type definition for non npm-package amap-js-api-line-search

* Add type definition of non npm package amap-js-api-arrival-range

* New definition for non npm-package amap-js-api-driving
This commit is contained in:
breeze9527 2019-05-29 04:30:00 +08:00 committed by Sheetal Nandi
parent 9f60c235c4
commit 46b4037bf0
4 changed files with 696 additions and 0 deletions

View File

@ -0,0 +1,254 @@
declare const map: AMap.Map;
declare const lnglat: AMap.LngLat;
declare const lnglatTuple: [number, number];
// $ExpectType Driving
new AMap.Driving();
// $ExpectType Driving
new AMap.Driving({});
// $ExpectType Driving
const driving = new AMap.Driving({
policy: AMap.DrivingPolicy.LEAST_DISTANCE,
extensions: 'all',
ferry: true,
map,
panel: 'result',
hideMarkers: false,
showTraffic: true,
province: '粤',
number: 'NH1N11',
isOutline: true,
outlineColor: 'blue',
autoFitView: true
});
// $ExpectType void
driving.search(lnglat, lnglat);
// $ExpectType void
driving.search(lnglatTuple, lnglatTuple);
// $ExpectType void
driving.search(lnglat, lnglat, { waypoints: [lnglat] });
driving.search(lnglat, lnglat, { waypoints: [lnglat] }, (status, result) => {
const temp: 'error' | 'complete' | 'no_data' = status;
if (typeof result !== 'string') {
// $ExpectType LngLat
result.destination;
// $ExpectType Poi
result.end;
{
const poi = result.end;
// $ExpectType LngLat
poi.location;
// $ExpectType string
poi.name;
// $ExpectType "start" | "end" | "waypoint"
poi.type;
}
// $ExpectType string
result.info;
// $ExpectType LngLat
result.origin;
// $ExpectType DriveRoute[]
result.routes;
{
const route = result.routes[0];
// $ExpectType number
route.distance;
// $ExpectType string
route.policy;
// $ExpectType 0 | 1
route.restriction;
// $ExpectType DriveStep[]
route.steps;
{
const step = route.steps[0];
// $ExpectType string
step.action;
// $ExpectType string
step.assistant_action;
// $ExpectType number
step.distance;
// $ExpectType LngLat
step.end_location;
// $ExpectType string
step.instruction;
// $ExpectType string
step.orientation;
// $ExpectType LngLat[]
step.path;
// $ExpectType string
step.road;
// $ExpectType LngLat
step.start_location;
// $ExpectType number
step.time;
// $ExpectType number
step.toll_distance;
// $ExpectType string
step.toll_road;
// $ExpectType number
step.tolls;
// $ExpectType ViaCity[] | undefined
step.cities;
if (step.cities) {
const city = step.cities[0];
// $ExpectType string
city.adcode;
// $ExpectType string
city.citycode;
// $ExpectType District[]
city.districts;
{
const district = city.districts[0];
// $ExpectType string
district.adcode;
// $ExpectType string
district.name;
}
// $ExpectType string
city.name;
}
// $ExpectType TMC[] | undefined
step.tmcs;
if (step.tmcs) {
const tmc = step.tmcs[0];
// $ExpectType number
tmc.distance;
// $ExpectType string | never[]
tmc.lcode;
// $ExpectType LngLat[]
tmc.path;
// $ExpectType string
tmc.polyline;
// $ExpectType string
tmc.status;
}
// $ExpectType TMCsPath[] | undefined
step.tmcsPaths;
if (step.tmcsPaths) {
const tmcsPath = step.tmcsPaths[0];
// $ExpectType LngLat[]
tmcsPath.path;
// $ExpectType string
tmcsPath.status;
}
}
// $ExpectType number
route.time;
// $ExpectType number
route.tolls;
// $ExpectType number
route.tolls_distance;
}
// $ExpectType Poi
result.start;
// $ExpectType number | undefined
result.taxi_cost;
// $ExpectType (Poi & { isWaypoint: boolean; })[]
result.waypoints;
} else {
// $ExpectType string
result;
}
});
driving.search([{ keyword: 'start' }, { keyword: 'end' }], (status, result) => {
const temp: 'error' | 'complete' | 'no_data' = status;
if (typeof result !== 'string') {
// $ExpectType SearchResultExt
result;
// $ExpectType string
result.destinationName;
// $ExpectType PoiExt
result.end;
// $ExpectType string
result.originName;
// $ExpectType PoiExt
result.start;
// (PoiExt & {isWaypoint: boolean})[]
result.waypoints;
} else {
// $ExpectType string
result;
}
});
driving.search([
{ keyword: 'start', city: 'startCity' },
{ keyword: 'end', city: 'endCity' }
]);
// $ExpectType void
driving.setPolicy();
// $ExpectType void
driving.setPolicy(AMap.DrivingPolicy.LEAST_DISTANCE);
// $ExpectType void
driving.setAvoidPolygons([[lnglat, lnglat, lnglat, lnglat]]);
// $ExpectType void
driving.setAvoidPolygons([[lnglatTuple, lnglatTuple, lnglatTuple, lnglatTuple]]);
// $ExpectType void
driving.setAvoidRoad('roadName');
// $ExpectType void
driving.clearAvoidRoad();
// $ExpectType void
driving.clearAvoidPolygons();
// $ExpectType LngLat[]
driving.getAvoidPolygons();
// $ExpectType string | undefined
driving.getAvoidRoad();
// $ExpectType void
driving.clear();
// $ExpectType void
driving.searchOnAMAP({
origin: lnglat,
destination: lnglat
});
// $ExpectType void
driving.searchOnAMAP({
origin: lnglatTuple,
destination: lnglatTuple
});
// $ExpectType void
driving.searchOnAMAP({
origin: lnglatTuple,
originName: 'originName',
destination: lnglatTuple,
destinationName: 'destinationName'
});
// $ExpectType void
driving.setProvinceAndNumber('province', 'number');
driving.on('complete', (event: AMap.Driving.EventMap['complete']) => {
// $ExpectType "complete"
event.type;
// $ExpectType string
event.info;
if ('start' in event) {
// $ExpectType LngLat
event.destination;
if ('destinationName' in event) {
// $ExpectType string
event.destinationName;
// $ExpectType string
event.originName;
}
event.end;
// $ExpectType LngLat
event.origin;
// $ExpectType DriveRoute[]
event.routes;
event.start;
// $ExpectType number | undefined
event.taxi_cost;
event.waypoints;
}
});

415
types/amap-js-api-driving/index.d.ts vendored Normal file
View File

@ -0,0 +1,415 @@
// Type definitions for non-npm package amap-js-api-driving 1.4
// Project: https://lbs.amap.com/api/javascript-api/reference/route-search#m_AMap.Driving
// Definitions by: breeze9527 <https://github.com/breeze9527>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.8
/// <reference types="amap-js-api" />
/// <reference types="amap-js-api-place-search" />
declare namespace AMap {
enum DrivingPolicy {
/**
*
*/
LEAST_TIME = 0,
/**
*
*/
LEAST_FEE = 1,
/**
*
*/
LEAST_DISTANCE = 2,
/**
*
*/
REAL_TRAFFIC = 4,
// form DragRoute
MULTI_POLICIES = 5,
HIGHWAY = 6,
FEE_HIGHWAY = 7,
FEE_TRAFFIC = 8,
TRAFFIC_HIGHWAY = 9
}
namespace Driving {
interface EventMap {
complete: Event<'complete', SearchResult | { info: string }>;
error: Event<'error', { info: string }>;
}
interface Options {
/**
* 线
*/
policy?: DrivingPolicy;
/**
*
* base
* allDriveStep基本信息+DriveStep详细信息
*/
extensions?: 'base' | 'all';
/**
* 0使1使
*/
ferry?: boolean;
/**
* AMap.Map对象
* 线
*/
map?: Map;
/**
* HTML容器id或容器元素
*/
panel?: string | HTMLElement;
/**
*
*/
hideMarkers?: boolean;
/**
* true
* 绿
*/
showTraffic?: boolean;
/**
* number属性组合使用
*/
province?: string;
/**
* province属性组合使用
*/
number?: string;
/**
* 使map属性时线true
*/
isOutline?: boolean;
/**
* 使map属性时线'white'
*/
outlineColor?: string;
/**
* 使线
*/
autoFitView?: boolean;
// internal
showDir?: boolean;
}
interface SearchOptions {
/**
*
*/
waypoints?: LocationValue[];
}
interface SearchPoint {
/**
*
*/
keyword: string;
/**
*
*/
city?: string;
}
interface TMCsPath {
path: LngLat[];
status: string;
}
interface DriveStep {
/**
*
*/
start_location: LngLat;
/**
*
*/
end_location: LngLat;
/**
*
*/
instruction: string;
/**
*
*/
action: string;
/**
*
*/
assistant_action: string;
/**
*
*/
orientation: string;
/**
*
*/
road: string;
/**
*
*/
distance: number;
/**
*
*/
tolls: number;
/**
*
*/
toll_distance: number;
/**
*
*/
toll_road: string;
/**
* 使
*/
time: number;
/**
*
*/
path: LngLat[];
/**
*
*/
cities?: ViaCity[];
/**
*
*/
tmcs?: TMC[];
tmcsPaths?: TMCsPath[];
}
interface District {
/**
*
*/
name: string;
/**
*
*/
adcode: string;
}
interface ViaCity {
/**
*
*/
name: string;
/**
*
*/
citycode: string;
/**
*
*/
adcode: string;
/**
*
*/
districts: District[];
}
interface TMC {
/**
*
* direction是正向 lcode返回值大于0lcode0
* 0lcode
*/
lcode: string | never[];
/**
* lcode对应的路段长度单位:
*/
distance: number;
/**
*
*/
status: string;
path: LngLat[];
polyline: string;
}
interface DriveRoute {
/**
*
*/
distance: number;
/**
*
*/
time: number;
/**
*
*/
policy: string;
/**
* 线
*/
tolls: number;
/**
*
*/
tolls_distance: number;
/**
* DriveStep集合
*/
steps: DriveStep[];
/**
*
* 0 线
* 1 线
*/
restriction: 0 | 1;
}
interface Poi {
location: LngLat;
name: string;
type: 'start' | 'end' | 'waypoint';
}
interface SearchResultCommon {
/**
*
*/
info: string;
/**
*
*/
origin: LngLat;
/**
*
*/
destination: LngLat;
/**
* 线
*/
routes: DriveRoute[];
/**
* extensions为all
*
*/
taxi_cost?: number;
}
interface SearchResultBase extends SearchResultCommon {
/**
*
*/
start: Poi;
/**
*
*/
end: Poi;
/**
*
*/
waypoints: Array<Poi & { isWaypoint: boolean }>;
}
interface SearchResultExt extends SearchResultCommon {
/**
*
*/
start: PlaceSearch.PoiExt;
/**
*
*/
end: PlaceSearch.PoiExt;
/**
*
*/
originName: string;
/**
*
*/
destinationName: string;
/**
*
*/
waypoints: Array<PlaceSearch.PoiExt & { isWaypoint: boolean }>;
}
type SearchResult = SearchResultBase | SearchResultExt;
type SearchStatus = 'error' | 'no_data' | 'complete';
}
class Driving extends EventEmitter {
/**
* 线
* @param options
*/
constructor(options?: Driving.Options);
/**
* 线
* @param points
* @param callback
*/
search(
points: Driving.SearchPoint[],
callback?: (status: Driving.SearchStatus, result: string | Driving.SearchResultExt) => void
): void;
/**
* 线
* @param origin
* @param destination
* @param callback
*/
search(
origin: LocationValue,
destination: LocationValue,
callback?: (status: Driving.SearchStatus, result: string | Driving.SearchResultBase) => void
): void;
/**
* 线
* @param origin
* @param destination
* @param opts
* @param callback
*/
search(
origin: LocationValue,
destination: LocationValue,
opts?: Driving.SearchOptions,
callback?: (status: Driving.SearchStatus, result: string | Driving.SearchResultBase) => void
): void;
/**
* 线
* @param policy 线
*/
setPolicy(policy?: DrivingPolicy): void;
/**
* 使
* @param path
*/
setAvoidPolygons(path: LocationValue[][]): void;
/**
* 使
* @param road
*/
setAvoidRoad(road: string): void;
/**
*
*/
clearAvoidRoad(): void;
/**
*
*/
clearAvoidPolygons(): void;
/**
*
*/
getAvoidPolygons(): LngLat[];
/**
*
*/
getAvoidRoad(): string | undefined;
/**
*
*/
clear(): void;
/**
*
* @param obj
*/
searchOnAMAP(obj: { origin: LocationValue, originName?: string, destination: LocationValue, destinationName?: string }): void;
/**
*
* 线
* @param province
* @param number
*/
setProvinceAndNumber(province: string, number: string): void;
// internal
open(): void;
close(): void;
}
}

View File

@ -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-driving-tests.ts"
]
}

View File

@ -0,0 +1,3 @@
{
"extends": "dtslint/dt.json"
}