-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.d.ts
305 lines (270 loc) · 8.57 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
declare namespace Baato {
// Common Types
type CommonConstructorProps = {
key: string;
baseUrl?: string;
apiVersion?: string;
};
abstract class Common<T> {
setKey(key: string): T;
setBaseUrl(url: string): T;
setApiVersion(version: string): T;
}
// Places API
interface PlacesProps extends CommonConstructorProps {}
class Places extends Common<Places> {
constructor(props: PlacesProps);
setPlaceId(placeId: string): Places;
doRequest: () => Promise<any> | null;
}
// Reverse Search API
interface ReverseProps extends CommonConstructorProps {
radius: number;
limit: number;
}
type ReverseResponseItem = {
address: string;
centroid: GeoJSON.LatLon;
geometry: GeoJSON.GeoJSON;
name: string;
osmId: number;
placeId: number;
score: string;
tags: Array<string>;
type: string;
};
type ReverseResponse = {
data: Array<ReverseResponseItem>;
message: string;
status: number;
};
class Reverse extends Common<Reverse> {
constructor(props?: ReverseProps);
setCoordinates(coordinates: [number, number]): Reverse;
setCoordinate(coordinate: GeoJSON.Position): Reverse;
setRadius(radius: number): Reverse;
setLimit(limit: number): Reverse;
doRequest: () => Promise<any> | null;
}
// Routing API
interface RoutingProps extends CommonConstructorProps {}
type RoutingResponse = {
distanceInMeters: number;
geojson: GeoJSON.GeoJSON;
instructionList: Array<any> | null;
timeInMs: number;
};
class Routing extends Common<Routing> {
constructor(props: RoutingProps);
setVehicle(vehicle: string): Routing;
addPoint(point: GeoJSON.LatLon): Routing;
getAlternatives(alternatives: boolean): Routing;
addPoints(point: Array<string>): Routing;
getBaseUrl(): string;
getKey(): string;
includeAlternativeRoutes(): Routing;
getElevation(elevation:boolean):Routing;
getBest(): Routing;
hasInstructions(instructions: boolean): Routing;
doRequest(): Promise<Array<RoutingResponse>> | null;
}
// Search API
interface SearchProps extends CommonConstructorProps {
query?: string;
}
type SearchResultItem = {
address: string;
name: string;
placeId: number;
radialDistanceInKm: number;
score: number;
type: string;
};
type SearchResult = {
data: Array<SearchResultItem>;
message: string;
status: number;
};
class Search extends Common<Search> {
constructor(props?: SearchProps);
setLimit(limit: number): Reverse;
setQuery(query: string): Search;
setCoordinates(coordinate: GeoJSON.Position, radius: number): Search;
doRequest: () => Promise<SearchResult> | null;
}
// Utils API
class Utils {
decodePath(encoded: string, is3D: boolean): Array<GeoJSON.Position>;
getGeoJsonFromEncodedPolyLine(encoded: string): GeoJSON.LineString;
getGeoJsonFromSearchResults(searchResults): GeoJSON.FeatureCollection;
}
}
/**
* GeoJSON types according to the GeoJSON specs
*/
declare namespace GeoJSON {
export type LatLon = {
lat: number;
lon: number;
};
/**
* The valid values for the "type" property of GeoJSON geometry objects.
* https://tools.ietf.org/html/rfc7946#section-1.4
*/
export type GeoJsonGeometryTypes = Geometry["type"];
/**
* The value values for the "type" property of GeoJSON Objects.
* https://tools.ietf.org/html/rfc7946#section-1.4
*/
export type GeoJsonTypes = GeoJSON["type"];
/**
* Bounding box
* https://tools.ietf.org/html/rfc7946#section-5
*/
export type BBox =
| [number, number, number, number]
| [number, number, number, number, number, number];
/**
* A Position is an array of coordinates.
* https://tools.ietf.org/html/rfc7946#section-3.1.1
* Array should contain between two and three elements.
* The previous GeoJSON specification allowed more elements (e.g., which could be used to represent M values),
* but the current specification only allows X, Y, and (optionally) Z to be defined.
*/
export type Position = number[]; // [number, number] | [number, number, number];
/**
* The base GeoJSON object.
* https://tools.ietf.org/html/rfc7946#section-3
* The GeoJSON specification also allows foreign members
* (https://tools.ietf.org/html/rfc7946#section-6.1)
* Developers should use "&" type in TypeScript or extend the interface
* to add these foreign members.
*/
export interface GeoJsonObject {
// Don't include foreign members directly into this type def.
// in order to preserve type safety.
// [key: string]: any;
/**
* Specifies the type of GeoJSON object.
*/
type: GeoJsonTypes;
/**
* Bounding box of the coordinate range of the object's Geometries, Features, or Feature Collections.
* The value of the bbox member is an array of length 2*n where n is the number of dimensions
* represented in the contained geometries, with all axes of the most southwesterly point
* followed by all axes of the more northeasterly point.
* The axes order of a bbox follows the axes order of geometries.
* https://tools.ietf.org/html/rfc7946#section-5
*/
bbox?: BBox | undefined;
}
/**
* Union of GeoJSON objects.
*/
export type GeoJSON = Geometry | Feature | FeatureCollection;
/**
* Geometry object.
* https://tools.ietf.org/html/rfc7946#section-3
*/
export type Geometry =
| Point
| MultiPoint
| LineString
| MultiLineString
| Polygon
| MultiPolygon
| GeometryCollection;
export type GeometryObject = Geometry;
/**
* Point geometry object.
* https://tools.ietf.org/html/rfc7946#section-3.1.2
*/
export interface Point extends GeoJsonObject {
type: "Point";
coordinates: Position;
}
/**
* MultiPoint geometry object.
* https://tools.ietf.org/html/rfc7946#section-3.1.3
*/
export interface MultiPoint extends GeoJsonObject {
type: "MultiPoint";
coordinates: Position[];
}
/**
* LineString geometry object.
* https://tools.ietf.org/html/rfc7946#section-3.1.4
*/
export interface LineString extends GeoJsonObject {
type: "LineString";
coordinates: Position[];
}
/**
* MultiLineString geometry object.
* https://tools.ietf.org/html/rfc7946#section-3.1.5
*/
export interface MultiLineString extends GeoJsonObject {
type: "MultiLineString";
coordinates: Position[][];
}
/**
* Polygon geometry object.
* https://tools.ietf.org/html/rfc7946#section-3.1.6
*/
export interface Polygon extends GeoJsonObject {
type: "Polygon";
coordinates: Position[][];
}
/**
* MultiPolygon geometry object.
* https://tools.ietf.org/html/rfc7946#section-3.1.7
*/
export interface MultiPolygon extends GeoJsonObject {
type: "MultiPolygon";
coordinates: Position[][][];
}
/**
* Geometry Collection
* https://tools.ietf.org/html/rfc7946#section-3.1.8
*/
export interface GeometryCollection extends GeoJsonObject {
type: "GeometryCollection";
geometries: Geometry[];
}
export type GeoJsonProperties = { [name: string]: any } | null;
/**
* A feature object which contains a geometry and associated properties.
* https://tools.ietf.org/html/rfc7946#section-3.2
*/
export interface Feature<
G extends Geometry | null = Geometry,
P = GeoJsonProperties
> extends GeoJsonObject {
type: "Feature";
/**
* The feature's geometry
*/
geometry: G;
/**
* A value that uniquely identifies this feature in a
* https://tools.ietf.org/html/rfc7946#section-3.2.
*/
id?: string | number | undefined;
/**
* Properties associated with this feature.
*/
properties: P;
}
/**
* A collection of feature objects.
* https://tools.ietf.org/html/rfc7946#section-3.3
*/
export interface FeatureCollection<
G extends Geometry | null = Geometry,
P = GeoJsonProperties
> extends GeoJsonObject {
type: "FeatureCollection";
features: Array<Feature<G, P>>;
}
}
export default Baato;