@unmap/geocoding 0.27.0 → 0.29.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -916,8 +916,10 @@ interface Place {
916
916
  postcode?: string;
917
917
  country?: string;
918
918
  };
919
- /** Metres from the anchor. Only on `nearby()`. */
919
+ /** Metres from the anchor on `nearby()`; metres off the route on `along()`. */
920
920
  distance?: number;
921
+ /** Metres from the start of the route to the nearest point on it. Only on `along()`. */
922
+ along?: number;
921
923
  /** Registry id of the dataset, for provenance. */
922
924
  source: string;
923
925
  }
@@ -973,6 +975,19 @@ interface PlaceNearbyOptions {
973
975
  lang?: string;
974
976
  signal?: AbortSignal;
975
977
  }
978
+ interface PlaceAlongOptions {
979
+ /** Metres either side of the route, clamped server-side to 10..500. Default 50. */
980
+ radius?: number;
981
+ /** 1..200, default 50. Out of range is status 400. */
982
+ limit?: number;
983
+ lang?: string;
984
+ signal?: AbortSignal;
985
+ }
986
+ /** A GeoJSON LineString, the shape `/route` returns as `geometry`. */
987
+ interface RouteLine {
988
+ type: "LineString";
989
+ coordinates: number[][];
990
+ }
976
991
  /**
977
992
  * A places failure.
978
993
  *
@@ -1020,6 +1035,18 @@ declare class Places {
1020
1035
  * outside WGS84, including a bbox corner, rejects with status 400 and code `bad_request`.
1021
1036
  */
1022
1037
  nearby(category: string | readonly string[], opts?: PlaceNearbyOptions): Promise<PlacesResponse<Place[]>>;
1038
+ /**
1039
+ * Places of a category along a route, in the order the route reaches them.
1040
+ *
1041
+ * Pass the `geometry` a route response carries; each place comes back with `distance` (metres
1042
+ * off the route) and `along` (metres from the start), sorted by `along`. The line is capped at
1043
+ * 2,000 coordinates and 100 km (status 400 beyond either), and every coordinate must be in
1044
+ * Canada (status 422, code `outside_coverage`). `category` resolves aliases as `nearby()` does.
1045
+ *
1046
+ * const route = await router.route(from, to, { mode: "pedestrian" });
1047
+ * const { data } = await places.along(route.geometry, "cafe");
1048
+ */
1049
+ along(route: RouteLine, category: string | readonly string[], opts?: PlaceAlongOptions): Promise<PlacesResponse<Place[]>>;
1023
1050
  /**
1024
1051
  * One place by its unmap id.
1025
1052
  *
@@ -1101,8 +1128,10 @@ interface GeocodeResult {
1101
1128
  match_reasons?: GeocodeMatchReason[];
1102
1129
  /** Canonical category id (e.g. "health.pharmacy") when the feature carries one. */
1103
1130
  category?: string;
1104
- /** Spheroidal metres from the query anchor; only `/geocode/nearby` results carry it. */
1131
+ /** Spheroidal metres from the query anchor (`/geocode/nearby`), or off the route (`/places/along`). */
1105
1132
  distance?: number;
1133
+ /** Metres from the start of the route; only the geocode container's `/along` sets it. */
1134
+ along?: number;
1106
1135
  names?: Record<string, string>;
1107
1136
  address?: {
1108
1137
  housenumber?: string;
@@ -1254,4 +1283,4 @@ declare class Geocoder {
1254
1283
  private query;
1255
1284
  }
1256
1285
 
1257
- export { AMBIGUOUS_SCORE_RATIO, type AcknowledgementContext, type AcknowledgementResource, CIVIC_SEARCH_LAYERS, COMMUNITY_INCLUDE_VALUES, type CivicSearchLayer, type CommunityIncludeValue, type CommunityStatus, CsvParser, type CsvProblem, type CsvRecord, DEFAULT_IDENTIFY_LAYERS, DEFAULT_QUERY_LIMIT, ENERGY_IDENTIFY_LAYER_IDS, ENERGY_SEARCH_LAYERS, type EnergyDetails, type EnergyQuery, type EnergyQueryKind, type EnergySearchLayer, type FocusParse, GEOCODE_BATCH_MAX, type GeocodeLayer, type GeocodeMatchReason, type GeocodeMatchType, type GeocodePrecision, type GeocodeResult, type GeocodeSource, Geocoder, GeocoderError, type GeocoderOptions, IDENTIFY_LAYER_IDS, INCLUDE_VALUES, type IdentifyLayerId, type IdentifyOptions, type IdentifyResponse, type IdentifyResult, type IncludeParse, type IncludeValue, LAND_IDENTIFY_LAYER_IDS, type LegalLandComponents, type LegalLandDetails, type LegalLandLayerSystem, type LegalLandParse, type LegalLandSystem, type LegalLandUnit, MAX_QUERY_LIMIT, MINING_IDENTIFY_LAYER_IDS, type NearbyOptions, OUTPUT_COLUMNS, OUTPUT_PREFIX, type OutputColumn, type ParcelQuery, type Place, type PlaceNearbyOptions, type PlaceSearchOptions, Places, PlacesError, type PlacesOptions, type PlacesResponse, QUERY_LAYER_IDS, type QueryBbox, type QueryLayerId, type QueryOptions, type QueryResponse, REGIONS, REGION_CODES, REGION_KEYS, type ReverseOptions, type ReviewReason, type RowStatus, type RuralRouteKind, type RuralRouteQuery, STRUCTURED_FIELDS, type SearchLayersParse, type SearchOptions, type StructuredOptions, type StructuredParseResult, type StructuredQuery, type TerritoryContext, type TerritoryMatch, type TreatyCategory, type TreatyContext, type TreatyGeographyKind, type TreatyLang, type TreatyLookupClient, type TreatyMapLike, type TreatyMatch, type TreatyOptions, type TreatyOverlayController, type TreatyOverlayOptions, type TreatyPointBasis, type TreatyRepresentation, type TreatySelection, alignRow, classify, createTreatyOverlay, emptyAcknowledgementContext, emptyTerritoryContext, encodeField, encodeRow, energySearchRequested, escapeForSpreadsheet, isEnergyIdentifyLayer, isEnergySearchSource, isIdentifyLayer, isLandIdentifyLayer, isTreatiesVersion, knownIdentifyLayers, knownQueryLayers, knownSearchLayers, looksLikeEnergyQuery, looksLikeFormula, looksLikeLegalLand, looksLikeParcel, looksLikeRuralRoute, orderTreatyMatches, outputValues, parseAcknowledgementContext, parseEnergyQuery, parseEnergySearchLayers, parseFocus, parseIdentifyAt, parseIdentifyLayers, parseInclude, parseLegalLand, parseParcel, parseQueryBbox, parseQueryLayer, parseQueryLimit, parseRegion, parseRuralRoute, parseSearchLayers, parseStructuredQuery, parseTerritoryContext, parseTreatiesVersion, parseTreatyContext, pickCommunityName, pickTreatyLabel, regionForms, resolveOutputHeader, toLegalLandDetails, treatyLayerIds, unavailableTreatyContext };
1286
+ export { AMBIGUOUS_SCORE_RATIO, type AcknowledgementContext, type AcknowledgementResource, CIVIC_SEARCH_LAYERS, COMMUNITY_INCLUDE_VALUES, type CivicSearchLayer, type CommunityIncludeValue, type CommunityStatus, CsvParser, type CsvProblem, type CsvRecord, DEFAULT_IDENTIFY_LAYERS, DEFAULT_QUERY_LIMIT, ENERGY_IDENTIFY_LAYER_IDS, ENERGY_SEARCH_LAYERS, type EnergyDetails, type EnergyQuery, type EnergyQueryKind, type EnergySearchLayer, type FocusParse, GEOCODE_BATCH_MAX, type GeocodeLayer, type GeocodeMatchReason, type GeocodeMatchType, type GeocodePrecision, type GeocodeResult, type GeocodeSource, Geocoder, GeocoderError, type GeocoderOptions, IDENTIFY_LAYER_IDS, INCLUDE_VALUES, type IdentifyLayerId, type IdentifyOptions, type IdentifyResponse, type IdentifyResult, type IncludeParse, type IncludeValue, LAND_IDENTIFY_LAYER_IDS, type LegalLandComponents, type LegalLandDetails, type LegalLandLayerSystem, type LegalLandParse, type LegalLandSystem, type LegalLandUnit, MAX_QUERY_LIMIT, MINING_IDENTIFY_LAYER_IDS, type NearbyOptions, OUTPUT_COLUMNS, OUTPUT_PREFIX, type OutputColumn, type ParcelQuery, type Place, type PlaceAlongOptions, type PlaceNearbyOptions, type PlaceSearchOptions, Places, PlacesError, type PlacesOptions, type PlacesResponse, QUERY_LAYER_IDS, type QueryBbox, type QueryLayerId, type QueryOptions, type QueryResponse, REGIONS, REGION_CODES, REGION_KEYS, type ReverseOptions, type ReviewReason, type RouteLine, type RowStatus, type RuralRouteKind, type RuralRouteQuery, STRUCTURED_FIELDS, type SearchLayersParse, type SearchOptions, type StructuredOptions, type StructuredParseResult, type StructuredQuery, type TerritoryContext, type TerritoryMatch, type TreatyCategory, type TreatyContext, type TreatyGeographyKind, type TreatyLang, type TreatyLookupClient, type TreatyMapLike, type TreatyMatch, type TreatyOptions, type TreatyOverlayController, type TreatyOverlayOptions, type TreatyPointBasis, type TreatyRepresentation, type TreatySelection, alignRow, classify, createTreatyOverlay, emptyAcknowledgementContext, emptyTerritoryContext, encodeField, encodeRow, energySearchRequested, escapeForSpreadsheet, isEnergyIdentifyLayer, isEnergySearchSource, isIdentifyLayer, isLandIdentifyLayer, isTreatiesVersion, knownIdentifyLayers, knownQueryLayers, knownSearchLayers, looksLikeEnergyQuery, looksLikeFormula, looksLikeLegalLand, looksLikeParcel, looksLikeRuralRoute, orderTreatyMatches, outputValues, parseAcknowledgementContext, parseEnergyQuery, parseEnergySearchLayers, parseFocus, parseIdentifyAt, parseIdentifyLayers, parseInclude, parseLegalLand, parseParcel, parseQueryBbox, parseQueryLayer, parseQueryLimit, parseRegion, parseRuralRoute, parseSearchLayers, parseStructuredQuery, parseTerritoryContext, parseTreatiesVersion, parseTreatyContext, pickCommunityName, pickTreatyLabel, regionForms, resolveOutputHeader, toLegalLandDetails, treatyLayerIds, unavailableTreatyContext };
package/dist/index.js CHANGED
@@ -1222,6 +1222,27 @@ var Places = class {
1222
1222
  lang: opts.lang
1223
1223
  }, opts.signal);
1224
1224
  }
1225
+ /**
1226
+ * Places of a category along a route, in the order the route reaches them.
1227
+ *
1228
+ * Pass the `geometry` a route response carries; each place comes back with `distance` (metres
1229
+ * off the route) and `along` (metres from the start), sorted by `along`. The line is capped at
1230
+ * 2,000 coordinates and 100 km (status 400 beyond either), and every coordinate must be in
1231
+ * Canada (status 422, code `outside_coverage`). `category` resolves aliases as `nearby()` does.
1232
+ *
1233
+ * const route = await router.route(from, to, { mode: "pedestrian" });
1234
+ * const { data } = await places.along(route.geometry, "cafe");
1235
+ */
1236
+ along(route, category, opts = {}) {
1237
+ const body = {
1238
+ route,
1239
+ category: Array.isArray(category) ? category.join(",") : String(category),
1240
+ ...opts.radius != null ? { radius: opts.radius } : {},
1241
+ ...opts.limit != null ? { limit: opts.limit } : {},
1242
+ ...opts.lang ? { lang: opts.lang } : {}
1243
+ };
1244
+ return this.request("/places/along", {}, opts.signal, body);
1245
+ }
1225
1246
  /**
1226
1247
  * One place by its unmap id.
1227
1248
  *
@@ -1232,15 +1253,11 @@ var Places = class {
1232
1253
  get(id, opts = {}) {
1233
1254
  return this.request(`/places/${encodeURIComponent(id)}`, { lang: opts.lang }, opts.signal);
1234
1255
  }
1235
- async request(path, params, signal) {
1256
+ async request(path, params, signal, body) {
1236
1257
  const q = new URLSearchParams({ key: this.key });
1237
1258
  for (const [k, v] of Object.entries(params)) if (v != null && v !== "") q.set(k, v);
1238
- const res = await fetchWithRetry(
1239
- this.fetchImpl,
1240
- `${this.base}${path}?${q}`,
1241
- { signal, headers: { accept: "application/json" } },
1242
- this.retry
1243
- );
1259
+ const init = body === void 0 ? { signal, headers: { accept: "application/json" } } : { method: "POST", signal, headers: { accept: "application/json", "content-type": "application/json" }, body: JSON.stringify(body) };
1260
+ const res = await fetchWithRetry(this.fetchImpl, `${this.base}${path}?${q}`, init, this.retry);
1244
1261
  if (!res.ok) throw await errorFrom(res, path);
1245
1262
  return await res.json();
1246
1263
  }