Skip to content

Commit 6e80fdc

Browse files
committed
feat: add types for isochrone service
1 parent 792d10a commit 6e80fdc

2 files changed

Lines changed: 121 additions & 0 deletions

File tree

types/mapbox__mapbox-sdk/index.d.ts

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1235,6 +1235,100 @@ declare module "@mapbox/mapbox-sdk/services/geocoding-v6" {
12351235
}
12361236
}
12371237

1238+
// eslint-disable-next-line @definitelytyped/no-declare-current-package
1239+
declare module "@mapbox/mapbox-sdk/services/isochrone" {
1240+
import * as GeoJSON from "geojson";
1241+
// eslint-disable-next-line @definitelytyped/no-self-import
1242+
import MapiClient, { SdkConfig } from "@mapbox/mapbox-sdk/lib/classes/mapi-client";
1243+
// eslint-disable-next-line @definitelytyped/no-self-import
1244+
import { MapiRequest } from "@mapbox/mapbox-sdk/lib/classes/mapi-request";
1245+
1246+
export default function Isochrone(config: SdkConfig | MapiClient): IsochroneService;
1247+
1248+
interface IsochroneService {
1249+
getContours(
1250+
request: IsochroneRequest<false | undefined>,
1251+
): MapiRequest<GeoJSON.FeatureCollection<GeoJSON.LineString>>;
1252+
getContours(
1253+
request: IsochroneRequest<true>,
1254+
): MapiRequest<GeoJSON.FeatureCollection<GeoJSON.Polygon>>;
1255+
}
1256+
1257+
interface IsochroneDistance {
1258+
/**
1259+
* The times in minutes to use for each isochrone contour. You can specify up to four contours.
1260+
* Times must be in increasing order. The maximum time that can be specified is 60 minutes.
1261+
* Setting minutes and meters in the same time is an error.
1262+
*/
1263+
minutes?: never;
1264+
/**
1265+
* The distances in meters to use for each isochrone contour. You can specify up to four contours.
1266+
* Distances must be in increasing order. The maximum distance that can be specified is
1267+
* 100000 meters. Setting minutes and meters in the same time is an error.
1268+
*/
1269+
meters: [number, number?, number?, number?];
1270+
}
1271+
1272+
interface IsochroneTime {
1273+
/**
1274+
* The times in minutes to use for each isochrone contour. You can specify up to four contours.
1275+
* Times must be in increasing order. The maximum time that can be specified is 60 minutes.
1276+
* Setting minutes and meters in the same time is an error.
1277+
*/
1278+
minutes: [number, number?, number?, number?];
1279+
/**
1280+
* The distances in meters to use for each isochrone contour. You can specify up to four contours.
1281+
* Distances must be in increasing order. The maximum distance that can be specified is
1282+
* 100000 meters. Setting minutes and meters in the same time is an error.
1283+
*/
1284+
meters?: never;
1285+
}
1286+
1287+
type IsochroneRequest<T extends boolean | undefined = false> = (IsochroneDistance | IsochroneTime) & {
1288+
/**
1289+
* The colors to use for each isochrone contour, specified as hex values without a leading
1290+
* `#`(for example, `ff0000` for red). If this parameter is used, there must be the same
1291+
* number of colors as there are entries in contours_minutes or contours_meters. If no
1292+
* colors are specified, the Isochrone API will assign a default rainbow color scheme to
1293+
* the output.
1294+
*/
1295+
colors?: [string?, string?, string?, string?];
1296+
/** A {longitude,latitude} coordinate pair around which to center the isochrone lines. */
1297+
coordinates: [number, number];
1298+
/**
1299+
* A floating point value from 0.0 to 1.0 that can be used to remove smaller contours. The
1300+
* default is 1.0. A value of 1.0 will only return the largest contour for a given time
1301+
* value. A value of 0.5 drops any contours that are less than half the area of the largest
1302+
* contour in the set of contours for that same time value.
1303+
*
1304+
* @default 1.0
1305+
*/
1306+
denoise?: number;
1307+
/**
1308+
* A positive floating point value in meters used as the tolerance for Douglas-Peucker
1309+
* generalization. There is no upper bound. If no value is specified in the request, the
1310+
* Isochrone API will choose the most optimized generalization to use for the request.
1311+
* Note that the generalization of contours can lead to self-intersections, as well as
1312+
* intersections of adjacent contours.
1313+
*/
1314+
generalize?: number;
1315+
/**
1316+
* Specify whether to return the contours as GeoJSON polygons (`true`) or linestrings
1317+
* (`false`, default). When polygons=`true`, any contour that forms a ring is returned as a
1318+
* polygon.
1319+
*
1320+
* @default false
1321+
*/
1322+
polygons?: T;
1323+
/**
1324+
* A Mapbox Directions routing profile ID.
1325+
*
1326+
* @default 'driving'
1327+
*/
1328+
profile?: "driving" | "driving-traffic" | "walking" | "cycling";
1329+
};
1330+
}
1331+
12381332
// eslint-disable-next-line @definitelytyped/no-declare-current-package
12391333
declare module "@mapbox/mapbox-sdk/services/geocoding" {
12401334
import { LngLatLike } from "mapbox-gl";

types/mapbox__mapbox-sdk/mapbox__mapbox-sdk-tests.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { MapiResponse } from "@mapbox/mapbox-sdk/lib/classes/mapi-response";
55
import Directions, { DirectionsResponse, DirectionsService } from "@mapbox/mapbox-sdk/services/directions";
66
import Geocoding, { GeocodeService } from "@mapbox/mapbox-sdk/services/geocoding";
77
import GeocodingV6, { GeocodeService as GeocodeServiceV6 } from "@mapbox/mapbox-sdk/services/geocoding-v6";
8+
import Isochrone, { IsochroneService } from "@mapbox/mapbox-sdk/services/isochrone";
89
import MapMatching, { MapMatchingResponse, MapMatchingService } from "@mapbox/mapbox-sdk/services/map-matching";
910
import Optimization, { OptimizationService } from "@mapbox/mapbox-sdk/services/optimization";
1011
import StaticMap, { StaticMapService } from "@mapbox/mapbox-sdk/services/static";
@@ -82,6 +83,32 @@ const drivingTrafficDirectionsRequest: MapiRequest = directionsService.getDirect
8283
drivingTrafficDirectionsRequest.send().then((response: MapiResponse) => {
8384
});
8485

86+
const isochroneService: IsochroneService = Isochrone(client);
87+
88+
const isochroneRequestLine = isochroneService.getContours({ coordinates: [-3.599431, 54.507913], minutes: [20, 40] });
89+
90+
const isochroneRequestPoly = isochroneService.getContours({
91+
coordinates: [-3.599431, 54.507913],
92+
minutes: [20, 40],
93+
polygons: true,
94+
});
95+
96+
isochroneRequestLine.send().then((response) => {
97+
const body = response.body;
98+
const features = body.features;
99+
features.map((feature) => {
100+
feature.geometry.type === "LineString";
101+
});
102+
});
103+
104+
isochroneRequestPoly.send().then((response) => {
105+
const body = response.body;
106+
const features = body.features;
107+
features.map((feature) => {
108+
feature.geometry.type === "Polygon";
109+
});
110+
});
111+
85112
const mapMatchingService: MapMatchingService = MapMatching(client);
86113

87114
const mapMatchingRequest: MapiRequest = mapMatchingService.getMatch({

0 commit comments

Comments
 (0)