Skip to content

Commit 45d63b5

Browse files
authored
🤖 Merge PR DefinitelyTyped#72659 feat(mapbox__mapbox-sdk): refine TileQueryService.listFeatures() return by @hkleungai
1 parent 233a197 commit 45d63b5

File tree

2 files changed

+107
-3
lines changed

2 files changed

+107
-3
lines changed

‎types/mapbox__mapbox-sdk/index.d.ts‎

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ declare module "@mapbox/mapbox-sdk/lib/classes/mapi-error" {
198198

199199
// eslint-disable-next-line @definitelytyped/no-declare-current-package
200200
declare module "@mapbox/mapbox-sdk/services/datasets" {
201+
import * as GeoJSON from "geojson";
201202
// eslint-disable-next-line @definitelytyped/no-self-import
202203
import { MapiRequest } from "@mapbox/mapbox-sdk/lib/classes/mapi-request";
203204
// eslint-disable-next-line @definitelytyped/no-self-import
@@ -1844,6 +1845,7 @@ declare module "@mapbox/mapbox-sdk/services/optimization" {
18441845

18451846
// eslint-disable-next-line @definitelytyped/no-declare-current-package
18461847
declare module "@mapbox/mapbox-sdk/services/static" {
1848+
import * as GeoJSON from "geojson";
18471849
import { AnyLayer, LngLatBoundsLike, LngLatLike } from "mapbox-gl";
18481850
// eslint-disable-next-line @definitelytyped/no-self-import
18491851
import { MapiRequest } from "@mapbox/mapbox-sdk/lib/classes/mapi-request";
@@ -2107,6 +2109,7 @@ declare module "@mapbox/mapbox-sdk/services/styles" {
21072109

21082110
// eslint-disable-next-line @definitelytyped/no-declare-current-package
21092111
declare module "@mapbox/mapbox-sdk/services/tilequery" {
2112+
import * as GeoJSON from "geojson";
21102113
// eslint-disable-next-line @definitelytyped/no-self-import
21112114
import { Coordinates, MapiRequest } from "@mapbox/mapbox-sdk/lib/classes/mapi-request";
21122115
// eslint-disable-next-line @definitelytyped/no-self-import
@@ -2122,7 +2125,9 @@ declare module "@mapbox/mapbox-sdk/services/tilequery" {
21222125
* Get a static map image..
21232126
* @param request
21242127
*/
2125-
listFeatures(request: TileQueryRequest): MapiRequest;
2128+
listFeatures(
2129+
request: TileQueryRequest,
2130+
): MapiRequest<GeoJSON.FeatureCollection<GeoJSON.Point, TileQueryResponseProperty>>;
21262131
}
21272132

21282133
interface TileQueryRequest {
@@ -2150,7 +2155,27 @@ declare module "@mapbox/mapbox-sdk/services/tilequery" {
21502155
* Queries for a specific geometry type.
21512156
*/
21522157
geometry?: GeometryType | undefined;
2153-
layers?: string[] | undefined;
2158+
/**
2159+
* A comma-separated list of bands to query, rather than querying all bands.
2160+
* If a specified layer does not exist, it is skipped.
2161+
* If no bands exist, returns an empty `FeatureCollection`.
2162+
*/
2163+
bands?: string | undefined;
2164+
/**
2165+
* A comma-separated list of layers to query, rather than querying all layers.
2166+
* If a specified layer does not exist, it is skipped.
2167+
* If no layers exist, returns an empty `FeatureCollection`.
2168+
*/
2169+
layers?: string | undefined;
2170+
}
2171+
2172+
interface TileQueryResponseProperty {
2173+
tilequery: {
2174+
distance: number;
2175+
geometry: GeometryType;
2176+
layer: string;
2177+
};
2178+
[name: string]: any;
21542179
}
21552180

21562181
type GeometryType = "polygon" | "linestring" | "point";

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

Lines changed: 80 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import mbxClient from "@mapbox/mapbox-sdk";
2-
import { SdkConfig } from "@mapbox/mapbox-sdk/lib/classes/mapi-client";
2+
import MapiClient, { SdkConfig } from "@mapbox/mapbox-sdk/lib/classes/mapi-client";
33
import { MapiRequest } from "@mapbox/mapbox-sdk/lib/classes/mapi-request";
44
import { MapiResponse } from "@mapbox/mapbox-sdk/lib/classes/mapi-response";
55
import Directions, { DirectionsService } from "@mapbox/mapbox-sdk/services/directions";
@@ -10,6 +10,12 @@ import MapMatching, { MapMatchingResponse, MapMatchingService } from "@mapbox/ma
1010
import Optimization, { OptimizationService } from "@mapbox/mapbox-sdk/services/optimization";
1111
import StaticMap, { StaticMapService } from "@mapbox/mapbox-sdk/services/static";
1212
import Styles, { StylesService } from "@mapbox/mapbox-sdk/services/styles";
13+
import TileQuery, {
14+
GeometryType,
15+
TileQueryRequest,
16+
TileQueryResponseProperty,
17+
TileQueryService,
18+
} from "@mapbox/mapbox-sdk/services/tilequery";
1319
import { LineString } from "geojson";
1420

1521
const config: SdkConfig = {
@@ -332,3 +338,76 @@ optimizationService.getOptimization({
332338
roundtrip: true,
333339
steps: true,
334340
});
341+
342+
{
343+
let tileQueryService: TileQueryService;
344+
tileQueryService = TileQuery({ accessToken: "" } satisfies SdkConfig);
345+
tileQueryService = TileQuery(new MapiClient({ accessToken: "" }));
346+
347+
// Required request params
348+
let mapiRequest = tileQueryService.listFeatures(
349+
{
350+
mapIds: ["id"],
351+
coordinates: [2, 3],
352+
} satisfies TileQueryRequest,
353+
);
354+
355+
// Optional request params
356+
mapiRequest = tileQueryService.listFeatures(
357+
{
358+
mapIds: ["id"],
359+
coordinates: [2, 3],
360+
radius: 0,
361+
limit: 5,
362+
dedupe: true,
363+
bands: "band1,band2",
364+
layers: "layer1,layer2",
365+
} satisfies TileQueryRequest,
366+
);
367+
368+
// Optional Geometry params
369+
mapiRequest = tileQueryService.listFeatures(
370+
{
371+
mapIds: ["id"],
372+
coordinates: [2, 3],
373+
geometry: "linestring" satisfies GeometryType,
374+
} satisfies TileQueryRequest,
375+
);
376+
mapiRequest = tileQueryService.listFeatures(
377+
{
378+
mapIds: ["id"],
379+
coordinates: [2, 3],
380+
geometry: "point" satisfies GeometryType,
381+
} satisfies TileQueryRequest,
382+
);
383+
mapiRequest = tileQueryService.listFeatures(
384+
{
385+
mapIds: ["id"],
386+
coordinates: [2, 3],
387+
geometry: "polygon" satisfies GeometryType,
388+
} satisfies TileQueryRequest,
389+
);
390+
391+
const featureCollection = mapiRequest.response!.body;
392+
// $ExpectType "FeatureCollection"
393+
featureCollection.type;
394+
395+
const [feature] = featureCollection.features;
396+
// $ExpectType "Feature"
397+
feature.type;
398+
// $ExpectType string | number | undefined
399+
feature.id;
400+
401+
// $ExpectType "Point"
402+
feature.geometry.type;
403+
// $ExpectType Position
404+
feature.geometry.coordinates;
405+
406+
feature.properties satisfies TileQueryResponseProperty;
407+
// $ExpectType number
408+
feature.properties.tilequery.distance;
409+
// $ExpectType GeometryType
410+
feature.properties.tilequery.geometry;
411+
// $ExpectType string
412+
feature.properties.tilequery.layer;
413+
}

0 commit comments

Comments
 (0)