@remaply/maps 0.0.0-stage → 0.2.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/LICENSE +202 -0
- package/NOTICE +8 -0
- package/README.md +240 -2
- package/dist/client.d.ts +31 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +208 -0
- package/dist/client.js.map +1 -0
- package/dist/config.d.ts +62 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +65 -0
- package/dist/config.js.map +1 -0
- package/dist/directions.d.ts +68 -0
- package/dist/directions.d.ts.map +1 -0
- package/dist/directions.js +114 -0
- package/dist/directions.js.map +1 -0
- package/dist/errors.d.ts +26 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +85 -0
- package/dist/errors.js.map +1 -0
- package/dist/geo.d.ts +17 -0
- package/dist/geo.d.ts.map +1 -0
- package/dist/geo.js +43 -0
- package/dist/geo.js.map +1 -0
- package/dist/index.d.ts +21 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +23 -0
- package/dist/index.js.map +1 -0
- package/dist/map.d.ts +117 -0
- package/dist/map.d.ts.map +1 -0
- package/dist/map.js +357 -0
- package/dist/map.js.map +1 -0
- package/dist/routePreview.d.ts +84 -0
- package/dist/routePreview.d.ts.map +1 -0
- package/dist/routePreview.js +206 -0
- package/dist/routePreview.js.map +1 -0
- package/dist/search.d.ts +70 -0
- package/dist/search.d.ts.map +1 -0
- package/dist/search.js +60 -0
- package/dist/search.js.map +1 -0
- package/dist/security.d.ts +20 -0
- package/dist/security.d.ts.map +1 -0
- package/dist/security.js +53 -0
- package/dist/security.js.map +1 -0
- package/dist/style.d.ts +45 -0
- package/dist/style.d.ts.map +1 -0
- package/dist/style.js +173 -0
- package/dist/style.js.map +1 -0
- package/dist/version.d.ts +3 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +5 -0
- package/dist/version.js.map +1 -0
- package/package.json +56 -4
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
// Copyright 2026 Remaply
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
import { boundsOf, unwrapLongitudes } from "./geo.js";
|
|
4
|
+
import { firstFont } from "./style.js";
|
|
5
|
+
/** The route colours, as in the Android and iOS SDKs: the chosen route blue, alternatives grey. */
|
|
6
|
+
export const ROUTE_COLORS = {
|
|
7
|
+
line: "#1A73E8",
|
|
8
|
+
casing: "#0B57D0",
|
|
9
|
+
alternativeLine: "#C5D2E6",
|
|
10
|
+
alternativeCasing: "#8F9DB3",
|
|
11
|
+
from: "#0B57D0",
|
|
12
|
+
to: "#D93025",
|
|
13
|
+
};
|
|
14
|
+
const SOURCE = "remaply-sdk-route-preview";
|
|
15
|
+
/** Layer ids, bottom to top. Routes go under the map's labels, the ends on top of everything. */
|
|
16
|
+
export const ROUTE_PREVIEW_LAYERS = {
|
|
17
|
+
casing: "remaply-sdk-route-casing",
|
|
18
|
+
line: "remaply-sdk-route-line",
|
|
19
|
+
links: "remaply-sdk-route-end-links",
|
|
20
|
+
ends: "remaply-sdk-route-ends",
|
|
21
|
+
labels: "remaply-sdk-route-end-labels",
|
|
22
|
+
};
|
|
23
|
+
const EMPTY = { routes: [] };
|
|
24
|
+
/**
|
|
25
|
+
* The route preview, as GeoJSON: each route (longitudes unwrapped across the antimeridian), the
|
|
26
|
+
* From and To points with their labels, and a dotted link from each to where the route line begins
|
|
27
|
+
* or ends (a router starts and ends on the nearest road, which can be a little way off).
|
|
28
|
+
* Exported for tests and for maps drawn another way.
|
|
29
|
+
*/
|
|
30
|
+
export function routePreviewGeoJson(data) {
|
|
31
|
+
const features = [];
|
|
32
|
+
const lines = data.routes.filter((r) => r.points.length >= 2);
|
|
33
|
+
for (const r of lines) {
|
|
34
|
+
features.push({
|
|
35
|
+
type: "Feature",
|
|
36
|
+
geometry: { type: "LineString", coordinates: unwrapLongitudes(r.points).map((p) => [p.lon, p.lat]) },
|
|
37
|
+
properties: { kind: "route", id: r.id, active: r.active ?? false },
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
const main = lines.find((r) => r.active) ?? lines[0];
|
|
41
|
+
const ends = [
|
|
42
|
+
["from", data.from, main?.points[0]],
|
|
43
|
+
["to", data.to, main?.points[main.points.length - 1]],
|
|
44
|
+
];
|
|
45
|
+
for (const [kind, end, onRoute] of ends) {
|
|
46
|
+
if (!end)
|
|
47
|
+
continue;
|
|
48
|
+
const at = [end.location.lon, end.location.lat];
|
|
49
|
+
if (onRoute) {
|
|
50
|
+
features.push({ type: "Feature", geometry: { type: "LineString", coordinates: [at, [onRoute.lon, onRoute.lat]] }, properties: { kind: "link" } });
|
|
51
|
+
}
|
|
52
|
+
features.push({
|
|
53
|
+
type: "Feature",
|
|
54
|
+
geometry: { type: "Point", coordinates: at },
|
|
55
|
+
properties: { kind, label: end.label ? `${kind === "from" ? "From" : "To"}: ${end.label}` : "" },
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
return { type: "FeatureCollection", features };
|
|
59
|
+
}
|
|
60
|
+
const isKind = (kind) => ["==", ["get", "kind"], kind];
|
|
61
|
+
/**
|
|
62
|
+
* Routes and their From and To on a MapLibre map showing the Remaply style (from `loadStyle`):
|
|
63
|
+
* the chosen route blue, alternatives grey, the ends labelled. Survives style changes.
|
|
64
|
+
* `RemaplyMap` uses it; use it directly on your own MapLibre map.
|
|
65
|
+
*
|
|
66
|
+
* ```ts
|
|
67
|
+
* const preview = new RoutePreview(map);
|
|
68
|
+
* const routes = await route([from, to], { alternatives: 2 });
|
|
69
|
+
* preview.set({
|
|
70
|
+
* routes: routes.map((r, i) => ({ id: `r${i}`, points: routePoints(r), active: i === 0 })),
|
|
71
|
+
* from: { location: from, label: "Your location" },
|
|
72
|
+
* to: { location: to, label: "CWM Hospital" },
|
|
73
|
+
* });
|
|
74
|
+
* preview.fit();
|
|
75
|
+
* ```
|
|
76
|
+
*/
|
|
77
|
+
export class RoutePreview {
|
|
78
|
+
constructor(map) {
|
|
79
|
+
this.map = map;
|
|
80
|
+
this.data = EMPTY;
|
|
81
|
+
this.onStyleLoad = () => this.add();
|
|
82
|
+
map.on("style.load", this.onStyleLoad);
|
|
83
|
+
if (map.isStyleLoaded())
|
|
84
|
+
this.add();
|
|
85
|
+
}
|
|
86
|
+
/** Show these routes and ends (replacing what was shown). */
|
|
87
|
+
set(data) {
|
|
88
|
+
this.data = data;
|
|
89
|
+
const source = this.map.getSource(SOURCE);
|
|
90
|
+
if (source) {
|
|
91
|
+
source.setData(routePreviewGeoJson(data));
|
|
92
|
+
this.bringEndsToFront();
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
this.add();
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
/** Remove the routes and ends from view. */
|
|
99
|
+
clear() {
|
|
100
|
+
this.set(EMPTY);
|
|
101
|
+
}
|
|
102
|
+
/** Fit the routes and ends on screen. [padding] in pixels, a number or per side. */
|
|
103
|
+
fit(padding = 64, maxZoom = 16) {
|
|
104
|
+
const ends = [this.data.from, this.data.to].filter((e) => !!e).map((e) => e.location);
|
|
105
|
+
const box = boundsOf([...this.data.routes.map((r) => r.points), ends].filter((l) => l.length > 0));
|
|
106
|
+
if (!box)
|
|
107
|
+
return;
|
|
108
|
+
const [west, south, east, north] = box;
|
|
109
|
+
this.map.fitBounds([[west, south], [east, north]], { padding, maxZoom, duration: 800 });
|
|
110
|
+
}
|
|
111
|
+
/** Remove the layers and stop following style changes. */
|
|
112
|
+
remove() {
|
|
113
|
+
this.map.off("style.load", this.onStyleLoad);
|
|
114
|
+
for (const id of Object.values(ROUTE_PREVIEW_LAYERS).reverse())
|
|
115
|
+
if (this.map.getLayer(id))
|
|
116
|
+
this.map.removeLayer(id);
|
|
117
|
+
if (this.map.getSource(SOURCE))
|
|
118
|
+
this.map.removeSource(SOURCE);
|
|
119
|
+
}
|
|
120
|
+
add() {
|
|
121
|
+
const map = this.map;
|
|
122
|
+
if (!map.isStyleLoaded() || map.getSource(SOURCE))
|
|
123
|
+
return;
|
|
124
|
+
const style = map.getStyle();
|
|
125
|
+
const font = firstFont(style);
|
|
126
|
+
// Routes under the first label layer, so road names stay readable over them.
|
|
127
|
+
const firstSymbol = style.layers?.find((l) => l.type === "symbol")?.id;
|
|
128
|
+
map.addSource(SOURCE, { type: "geojson", data: routePreviewGeoJson(this.data) });
|
|
129
|
+
const active = ["get", "active"];
|
|
130
|
+
const lineLayout = { "line-cap": "round", "line-join": "round", "line-sort-key": ["case", active, 1, 0] };
|
|
131
|
+
map.addLayer({
|
|
132
|
+
id: ROUTE_PREVIEW_LAYERS.casing,
|
|
133
|
+
type: "line",
|
|
134
|
+
source: SOURCE,
|
|
135
|
+
filter: isKind("route"),
|
|
136
|
+
layout: lineLayout,
|
|
137
|
+
paint: {
|
|
138
|
+
"line-color": ["case", active, ROUTE_COLORS.casing, ROUTE_COLORS.alternativeCasing],
|
|
139
|
+
"line-width": ["interpolate", ["linear"], ["zoom"], 8, 5, 12, 8, 16, 14],
|
|
140
|
+
},
|
|
141
|
+
}, firstSymbol);
|
|
142
|
+
map.addLayer({
|
|
143
|
+
id: ROUTE_PREVIEW_LAYERS.line,
|
|
144
|
+
type: "line",
|
|
145
|
+
source: SOURCE,
|
|
146
|
+
filter: isKind("route"),
|
|
147
|
+
layout: lineLayout,
|
|
148
|
+
paint: {
|
|
149
|
+
"line-color": ["case", active, ROUTE_COLORS.line, ROUTE_COLORS.alternativeLine],
|
|
150
|
+
"line-width": ["interpolate", ["linear"], ["zoom"], 8, 3, 12, 5.5, 16, 10],
|
|
151
|
+
},
|
|
152
|
+
}, firstSymbol);
|
|
153
|
+
map.addLayer({
|
|
154
|
+
id: ROUTE_PREVIEW_LAYERS.links,
|
|
155
|
+
type: "line",
|
|
156
|
+
source: SOURCE,
|
|
157
|
+
filter: isKind("link"),
|
|
158
|
+
layout: { "line-cap": "round" },
|
|
159
|
+
paint: { "line-color": ROUTE_COLORS.casing, "line-width": 3, "line-dasharray": [0.1, 2], "line-opacity": 0.8 },
|
|
160
|
+
});
|
|
161
|
+
const isTo = isKind("to");
|
|
162
|
+
map.addLayer({
|
|
163
|
+
id: ROUTE_PREVIEW_LAYERS.ends,
|
|
164
|
+
type: "circle",
|
|
165
|
+
source: SOURCE,
|
|
166
|
+
filter: ["any", isKind("from"), isTo],
|
|
167
|
+
paint: {
|
|
168
|
+
"circle-radius": ["case", isTo, 8, 7],
|
|
169
|
+
"circle-color": ["case", isTo, ROUTE_COLORS.to, "#FFFFFF"],
|
|
170
|
+
"circle-stroke-width": 3,
|
|
171
|
+
"circle-stroke-color": ["case", isTo, "#FFFFFF", ROUTE_COLORS.from],
|
|
172
|
+
},
|
|
173
|
+
});
|
|
174
|
+
if (font) {
|
|
175
|
+
map.addLayer({
|
|
176
|
+
id: ROUTE_PREVIEW_LAYERS.labels,
|
|
177
|
+
type: "symbol",
|
|
178
|
+
source: SOURCE,
|
|
179
|
+
filter: ["all", ["any", isKind("from"), isTo], ["!=", ["get", "label"], ""]],
|
|
180
|
+
layout: {
|
|
181
|
+
"text-field": ["get", "label"],
|
|
182
|
+
"text-font": [font],
|
|
183
|
+
"text-size": 13,
|
|
184
|
+
"text-anchor": "bottom",
|
|
185
|
+
"text-offset": [0, -1],
|
|
186
|
+
"text-max-width": 14,
|
|
187
|
+
"text-allow-overlap": true,
|
|
188
|
+
"text-ignore-placement": true,
|
|
189
|
+
},
|
|
190
|
+
paint: {
|
|
191
|
+
"text-color": ["case", isTo, "#B3261E", ROUTE_COLORS.casing],
|
|
192
|
+
"text-halo-color": "#FFFFFF",
|
|
193
|
+
"text-halo-width": 2,
|
|
194
|
+
},
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
/** Keep the ends above layers added after the preview (an app's own pins), so they're never hidden. */
|
|
199
|
+
bringEndsToFront() {
|
|
200
|
+
for (const id of [ROUTE_PREVIEW_LAYERS.links, ROUTE_PREVIEW_LAYERS.ends, ROUTE_PREVIEW_LAYERS.labels]) {
|
|
201
|
+
if (this.map.getLayer(id))
|
|
202
|
+
this.map.moveLayer(id);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
//# sourceMappingURL=routePreview.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"routePreview.js","sourceRoot":"","sources":["../src/routePreview.ts"],"names":[],"mappings":"AAAA,yBAAyB;AACzB,sCAAsC;AAGtC,OAAO,EAAE,QAAQ,EAAe,gBAAgB,EAAE,MAAM,UAAU,CAAC;AACnE,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAwBvC,mGAAmG;AACnG,MAAM,CAAC,MAAM,YAAY,GAAG;IAC1B,IAAI,EAAE,SAAS;IACf,MAAM,EAAE,SAAS;IACjB,eAAe,EAAE,SAAS;IAC1B,iBAAiB,EAAE,SAAS;IAC5B,IAAI,EAAE,SAAS;IACf,EAAE,EAAE,SAAS;CACL,CAAC;AAEX,MAAM,MAAM,GAAG,2BAA2B,CAAC;AAC3C,iGAAiG;AACjG,MAAM,CAAC,MAAM,oBAAoB,GAAG;IAClC,MAAM,EAAE,0BAA0B;IAClC,IAAI,EAAE,wBAAwB;IAC9B,KAAK,EAAE,6BAA6B;IACpC,IAAI,EAAE,wBAAwB;IAC9B,MAAM,EAAE,8BAA8B;CAC9B,CAAC;AAEX,MAAM,KAAK,GAAqB,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC;AAE/C;;;;;GAKG;AACH,MAAM,UAAU,mBAAmB,CAAC,IAAsB;IACxD,MAAM,QAAQ,GAAsB,EAAE,CAAC;IACvC,MAAM,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,IAAI,CAAC,CAAC,CAAC;IAC9D,KAAK,MAAM,CAAC,IAAI,KAAK,EAAE,CAAC;QACtB,QAAQ,CAAC,IAAI,CAAC;YACZ,IAAI,EAAE,SAAS;YACf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C1B,uBAAuB,EAAE,IAAI;iBAC9B;gBACD,KAAK,EAAE;oBACL,YAAY,EAAE,CAAC,MAAM,EAAE,IAAI,EAAE,SAAS,EAAE,YAAY,CAAC,MAAM,CAAC;oBAC5D,iBAAiB,EAAE,SAAS;oBAC5B,iBAAiB,EAAE,CAAC;iBACrB;aACF,CAAC,CAAC;QACL,CAAC;IACH,CAAC;IAED,uGAAuG;IACvG,gBAAgB;QACd,KAAK,MAAM,EAAE,IAAI,CAAC,oBAAoB,CAAC,KAAK,EAAE,oBAAoB,CAAC,IAAI,EAAE,oBAAoB,CAAC,MAAM,CAAC,EAAE,CAAC;YACtG,IAAI,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE,CAAC;gBAAE,IAAI,CAAC,GAAG,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC;QACpD,CAAC;IACH,CAAC;CACF"}
|
package/dist/search.d.ts
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import type { LatLon } from "./geo.js";
|
|
2
|
+
export interface Address {
|
|
3
|
+
road_name?: string | null;
|
|
4
|
+
building_number?: string | null;
|
|
5
|
+
settlement?: string | null;
|
|
6
|
+
province?: string | null;
|
|
7
|
+
country_code?: string | null;
|
|
8
|
+
country?: string | null;
|
|
9
|
+
}
|
|
10
|
+
export interface Place {
|
|
11
|
+
id: string;
|
|
12
|
+
name: string;
|
|
13
|
+
/** `poi`, `building`, `administrative_area`... A string so that new values do not break your code. */
|
|
14
|
+
type: string;
|
|
15
|
+
category: string;
|
|
16
|
+
categories: string[];
|
|
17
|
+
address: Address;
|
|
18
|
+
virtual_address_code?: string | null;
|
|
19
|
+
location: LatLon;
|
|
20
|
+
/** Metres from the point the search was biased to; null when none was sent. */
|
|
21
|
+
distance_m?: number | null;
|
|
22
|
+
is_verified: boolean;
|
|
23
|
+
phone?: string | null;
|
|
24
|
+
website?: string | null;
|
|
25
|
+
brand?: string | null;
|
|
26
|
+
}
|
|
27
|
+
export interface SearchOptions {
|
|
28
|
+
/** Nearest to this point first, e.g. the map centre. */
|
|
29
|
+
near?: LatLon;
|
|
30
|
+
/** At most this many results. Default 10. */
|
|
31
|
+
limit?: number;
|
|
32
|
+
/** Cancel the request, e.g. when the user types again. */
|
|
33
|
+
signal?: AbortSignal;
|
|
34
|
+
}
|
|
35
|
+
export interface NearbyOptions {
|
|
36
|
+
/** Overture category codes, which also match their children (`restaurant`, `atm`...). Empty: any place. */
|
|
37
|
+
categories?: readonly string[];
|
|
38
|
+
/** Search radius in metres, at most 5000. Default 5000. */
|
|
39
|
+
radiusM?: number;
|
|
40
|
+
/** At most this many results, at most 20. Default 20. */
|
|
41
|
+
limit?: number;
|
|
42
|
+
signal?: AbortSignal;
|
|
43
|
+
}
|
|
44
|
+
/** A category for "search nearby". */
|
|
45
|
+
export interface NearbyCategory {
|
|
46
|
+
id: string;
|
|
47
|
+
label: string;
|
|
48
|
+
categories: readonly string[];
|
|
49
|
+
}
|
|
50
|
+
/** The categories the Remaply apps offer for "search nearby". */
|
|
51
|
+
export declare const NEARBY_CATEGORIES: readonly NearbyCategory[];
|
|
52
|
+
/** Limits of /v1/reverse. */
|
|
53
|
+
export declare const NEARBY_RADIUS_M = 5000;
|
|
54
|
+
export declare const NEARBY_LIMIT = 20;
|
|
55
|
+
/**
|
|
56
|
+
* Places and addresses matching [query], nearest to `near` first when given. The key needs the
|
|
57
|
+
* `search` scope.
|
|
58
|
+
*
|
|
59
|
+
* ```ts
|
|
60
|
+
* const places = await search("hospital", { near: { lat: -18.1416, lon: 178.4419 } });
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
63
|
+
export declare function search(query: string, options?: SearchOptions): Promise<Place[]>;
|
|
64
|
+
/** Places nearest to a point, nearest first. The key needs the `geocode` scope. */
|
|
65
|
+
export declare function nearby(near: LatLon, options?: NearbyOptions): Promise<Place[]>;
|
|
66
|
+
/** `12 Victoria Parade, Suva, Fiji`. */
|
|
67
|
+
export declare function formatAddress(place: Pick<Place, "address">): string;
|
|
68
|
+
/** `fast_food` → `Fast food`. */
|
|
69
|
+
export declare function formatCategory(category: string): string;
|
|
70
|
+
//# sourceMappingURL=search.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"search.d.ts","sourceRoot":"","sources":["../src/search.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAKvC,MAAM,WAAW,OAAO;IACtB,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,eAAe,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAChC,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,YAAY,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CACzB;AAED,MAAM,WAAW,KAAK;IACpB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,sGAAsG;IACtG,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,OAAO,EAAE,OAAO,CAAC;IACjB,oBAAoB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACrC,QAAQ,EAAE,MAAM,CAAC;IACjB,+EAA+E;IAC/E,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,WAAW,EAAE,OAAO,CAAC;IACrB,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CACvB;AAED,MAAM,WAAW,aAAa;IAC5B,wDAAwD;IACxD,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,6CAA6C;IAC7C,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,0DAA0D;IAC1D,MAAM,CAAC,EAAE,WAAW,CAAC;CACtB;AAED,MAAM,WAAW,aAAa;IAC5B,2GAA2G;IAC3G,UAAU,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAC/B,2DAA2D;IAC3D,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,yDAAyD;IACzD,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,WAAW,CAAC;CACtB;AAED,sCAAsC;AACtC,MAAM,WAAW,cAAc;IAC7B,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,EAAE,SAAS,MAAM,EAAE,CAAC;CAC/B;AAED,iEAAiE;AACjE,eAAO,MAAM,iBAAiB,EAAE,SAAS,cAAc,EAQtD,CAAC;AAEF,6BAA6B;AAC7B,eAAO,MAAM,eAAe,OAAO,CAAC;AACpC,eAAO,MAAM,YAAY,KAAK,CAAC;AAoB/B;;;;;;;GAOG;AACH,wBAAsB,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,GAAE,aAAkB,GAAG,OAAO,CAAC,KAAK,EAAE,CAAC,CAQzF;AAED,mFAAmF;AACnF,wBAAsB,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,GAAE,aAAkB,GAAG,OAAO,CAAC,KAAK,EAAE,CAAC,CAQxF;AAED,wCAAwC;AACxC,wBAAgB,aAAa,CAAC,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,SAAS,CAAC,GAAG,MAAM,CAMnE;AAED,iCAAiC;AACjC,wBAAgB,cAAc,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAGvD"}
|
package/dist/search.js
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
// Copyright 2026 Remaply
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
import { apiGet } from "./client.js";
|
|
4
|
+
/** The categories the Remaply apps offer for "search nearby". */
|
|
5
|
+
export const NEARBY_CATEGORIES = [
|
|
6
|
+
{ id: "restaurant", label: "Restaurants", categories: ["restaurant"] },
|
|
7
|
+
{ id: "cafe", label: "Cafes", categories: ["cafe"] },
|
|
8
|
+
{ id: "hotel", label: "Hotels", categories: ["hotel"] },
|
|
9
|
+
{ id: "atm", label: "ATMs", categories: ["atm"] },
|
|
10
|
+
{ id: "gas_station", label: "Gas stations", categories: ["gas_station"] },
|
|
11
|
+
{ id: "pharmacy", label: "Pharmacies", categories: ["pharmacy"] },
|
|
12
|
+
{ id: "hospital", label: "Health", categories: ["hospital"] },
|
|
13
|
+
];
|
|
14
|
+
/** Limits of /v1/reverse. */
|
|
15
|
+
export const NEARBY_RADIUS_M = 5000;
|
|
16
|
+
export const NEARBY_LIMIT = 20;
|
|
17
|
+
/** Fills in what the API may leave out, so `Place` fields are always there. */
|
|
18
|
+
function normalize(raw) {
|
|
19
|
+
return {
|
|
20
|
+
...raw,
|
|
21
|
+
type: raw.type ?? "",
|
|
22
|
+
category: raw.category ?? "",
|
|
23
|
+
categories: raw.categories ?? [],
|
|
24
|
+
address: raw.address ?? {},
|
|
25
|
+
is_verified: raw.is_verified ?? false,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Places and addresses matching [query], nearest to `near` first when given. The key needs the
|
|
30
|
+
* `search` scope.
|
|
31
|
+
*
|
|
32
|
+
* ```ts
|
|
33
|
+
* const places = await search("hospital", { near: { lat: -18.1416, lon: 178.4419 } });
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
export async function search(query, options = {}) {
|
|
37
|
+
const { near, limit = 10, signal } = options;
|
|
38
|
+
const body = await apiGet("/v1/search", { q: query.trim(), lat: near?.lat, lon: near?.lon, limit }, signal);
|
|
39
|
+
return body.results.map(normalize);
|
|
40
|
+
}
|
|
41
|
+
/** Places nearest to a point, nearest first. The key needs the `geocode` scope. */
|
|
42
|
+
export async function nearby(near, options = {}) {
|
|
43
|
+
const { categories = [], radiusM = NEARBY_RADIUS_M, limit = NEARBY_LIMIT, signal } = options;
|
|
44
|
+
const body = await apiGet("/v1/reverse", { lat: near.lat, lon: near.lon, category: categories, radius_m: radiusM, limit }, signal);
|
|
45
|
+
return body.results.map(normalize);
|
|
46
|
+
}
|
|
47
|
+
/** `12 Victoria Parade, Suva, Fiji`. */
|
|
48
|
+
export function formatAddress(place) {
|
|
49
|
+
const a = place.address;
|
|
50
|
+
const street = [a.building_number, a.road_name].filter((s) => !!s && s.trim() !== "").join(" ");
|
|
51
|
+
// Many records have no settlement yet; province is the fallback.
|
|
52
|
+
const area = a.settlement ?? a.province;
|
|
53
|
+
return [street, area, a.country ?? a.country_code].filter((s) => !!s && s.trim() !== "").join(", ");
|
|
54
|
+
}
|
|
55
|
+
/** `fast_food` → `Fast food`. */
|
|
56
|
+
export function formatCategory(category) {
|
|
57
|
+
const text = category.replace(/_/g, " ");
|
|
58
|
+
return text.charAt(0).toUpperCase() + text.slice(1);
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=search.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"search.js","sourceRoot":"","sources":["../src/search.ts"],"names":[],"mappings":"AAAA,yBAAyB;AACzB,sCAAsC;AAEtC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AA2DrC,iEAAiE;AACjE,MAAM,CAAC,MAAM,iBAAiB,GAA8B;IAC1D,EAAE,EAAE,EAAE,YAAY,EAAE,KAAK,EAAE,aAAa,EAAE,UAAU,EAAE,CAAC,YAAY,CAAC,EAAE;IACtE,EAAE,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,UAAU,EAAE,CAAC,MAAM,CAAC,EAAE;IACpD,EAAE,EAAE,EAAE,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,UAAU,EAAE,CAAC,OAAO,CAAC,EAAE;IACvD,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE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cAAc,CAAC,QAAgB;IAC7C,MAAM,IAAI,GAAG,QAAQ,CAAC,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;IACzC,OAAO,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AACtD,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/** Prefix of secret keys. They must never reach a browser, so the SDK never sends them. */
|
|
2
|
+
export declare const SECRET_KEY_PREFIX = "rmp_sk_";
|
|
3
|
+
/**
|
|
4
|
+
* Largest response the SDK reads, in bytes. Styles, TileJSON and search or route answers are far
|
|
5
|
+
* smaller; the cap keeps a broken or hostile `mapStyleUrl` from exhausting memory.
|
|
6
|
+
*/
|
|
7
|
+
export declare const MAX_RESPONSE_BYTES: number;
|
|
8
|
+
export declare function isSecretKey(key: string): boolean;
|
|
9
|
+
/**
|
|
10
|
+
* [baseUrl] trimmed and without a trailing slash, when it is an `https://` URL (or `http://` on a
|
|
11
|
+
* local host). Throws otherwise: over plain HTTP the API key would travel in clear text.
|
|
12
|
+
*/
|
|
13
|
+
export declare function validatedApiBaseUrl(baseUrl: string): string;
|
|
14
|
+
/**
|
|
15
|
+
* True when [url] is on the same origin as [apiBaseUrl] (scheme, host and port), the only requests
|
|
16
|
+
* that get the API key. Comparing the host alone would also send the key to `http://` or another
|
|
17
|
+
* port of the same host. An `http://` origin only counts on a local host.
|
|
18
|
+
*/
|
|
19
|
+
export declare function isSameApiOrigin(apiBaseUrl: string, url: string): boolean;
|
|
20
|
+
//# sourceMappingURL=security.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"security.d.ts","sourceRoot":"","sources":["../src/security.ts"],"names":[],"mappings":"AAGA,2FAA2F;AAC3F,eAAO,MAAM,iBAAiB,YAAY,CAAC;AAE3C;;;GAGG;AACH,eAAO,MAAM,kBAAkB,QAAkB,CAAC;AAKlD,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAEhD;AAUD;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAY3D;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,UAAU,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAOxE"}
|
package/dist/security.js
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
// Copyright 2026 Remaply
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
/** Prefix of secret keys. They must never reach a browser, so the SDK never sends them. */
|
|
4
|
+
export const SECRET_KEY_PREFIX = "rmp_sk_";
|
|
5
|
+
/**
|
|
6
|
+
* Largest response the SDK reads, in bytes. Styles, TileJSON and search or route answers are far
|
|
7
|
+
* smaller; the cap keeps a broken or hostile `mapStyleUrl` from exhausting memory.
|
|
8
|
+
*/
|
|
9
|
+
export const MAX_RESPONSE_BYTES = 8 * 1024 * 1024;
|
|
10
|
+
/** Hosts where an `http://` API is allowed, for an API running on the developer's machine. */
|
|
11
|
+
const LOCAL_HOSTS = new Set(["localhost", "127.0.0.1", "[::1]"]);
|
|
12
|
+
export function isSecretKey(key) {
|
|
13
|
+
return key.startsWith(SECRET_KEY_PREFIX);
|
|
14
|
+
}
|
|
15
|
+
function parse(url) {
|
|
16
|
+
try {
|
|
17
|
+
return new URL(url);
|
|
18
|
+
}
|
|
19
|
+
catch {
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* [baseUrl] trimmed and without a trailing slash, when it is an `https://` URL (or `http://` on a
|
|
25
|
+
* local host). Throws otherwise: over plain HTTP the API key would travel in clear text.
|
|
26
|
+
*/
|
|
27
|
+
export function validatedApiBaseUrl(baseUrl) {
|
|
28
|
+
const trimmed = baseUrl.trim().replace(/\/+$/, "");
|
|
29
|
+
const url = parse(trimmed);
|
|
30
|
+
const host = url?.hostname.toLowerCase() ?? "";
|
|
31
|
+
const ok = url !== null &&
|
|
32
|
+
host !== "" &&
|
|
33
|
+
(url.protocol === "https:" || (url.protocol === "http:" && LOCAL_HOSTS.has(host)));
|
|
34
|
+
if (!ok) {
|
|
35
|
+
throw new Error(`Remaply apiBaseUrl must be an https:// URL (http:// only for localhost), not "${trimmed}".`);
|
|
36
|
+
}
|
|
37
|
+
return trimmed;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* True when [url] is on the same origin as [apiBaseUrl] (scheme, host and port), the only requests
|
|
41
|
+
* that get the API key. Comparing the host alone would also send the key to `http://` or another
|
|
42
|
+
* port of the same host. An `http://` origin only counts on a local host.
|
|
43
|
+
*/
|
|
44
|
+
export function isSameApiOrigin(apiBaseUrl, url) {
|
|
45
|
+
const api = parse(apiBaseUrl);
|
|
46
|
+
const target = parse(url);
|
|
47
|
+
if (!api || !target || api.hostname === "")
|
|
48
|
+
return false;
|
|
49
|
+
const secure = api.protocol === "https:" || LOCAL_HOSTS.has(api.hostname.toLowerCase());
|
|
50
|
+
// URL.origin normalises case and default ports (https://x:443 is https://x).
|
|
51
|
+
return secure && api.origin === target.origin;
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=security.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"security.js","sourceRoot":"","sources":["../src/security.ts"],"names":[],"mappings":"AAAA,yBAAyB;AACzB,sCAAsC;AAEtC,2FAA2F;AAC3F,MAAM,CAAC,MAAM,iBAAiB,GAAG,SAAS,CAAC;AAE3C;;;GAGG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,GAAG,IAAI,GAAG,IAAI,CAAC;AAElD,8FAA8F;AAC9F,MAAM,WAAW,GAAG,IAAI,GAAG,CAAC,CAAC,WAAW,EAAE,WAAW,EAAE,OAAO,CAAC,CAAC,CAAC;AAEjE,MAAM,UAAU,WAAW,CAAC,GAAW;IACrC,OAAO,GAAG,CAAC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AAQ,CAAC,WAAW,EAAE,CAAC,CAAC;IACxF,6EAA6E;IAC7E,OAAO,MAAM,IAAI,GAAG,CAAC,MAAM,KAAK,MAAM,CAAC,MAAM,CAAC;AAChD,CAAC"}
|
package/dist/style.d.ts
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { StyleSpecification } from "maplibre-gl";
|
|
2
|
+
/** Id of the vector tile source in the style. Its URL is replaced with the tiles of the API in use. */
|
|
3
|
+
export declare const REMAPLY_SOURCE = "remaply";
|
|
4
|
+
/** Label fonts for styles whose `glyphs` cannot be loaded (Remaply's default style may name `mapbox://fonts/...`). */
|
|
5
|
+
export declare const FALLBACK_GLYPHS = "https://tiles.openfreemap.org/fonts/{fontstack}/{range}.pbf";
|
|
6
|
+
/** Copy of the GET /v1/tiles/{tileset}.json contract (app/features/tiles/schemas.py in the API). */
|
|
7
|
+
export interface TileJson {
|
|
8
|
+
tiles: string[];
|
|
9
|
+
minzoom?: number;
|
|
10
|
+
maxzoom?: number;
|
|
11
|
+
bounds?: number[] | null;
|
|
12
|
+
attribution?: string | null;
|
|
13
|
+
}
|
|
14
|
+
/** The style is not a MapLibre style with a `remaply` source. */
|
|
15
|
+
export declare class MapStyleError extends Error {
|
|
16
|
+
readonly name = "MapStyleError";
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* The Remaply map style, ready for `new maplibregl.Map({ style })`: the style from the API (or
|
|
20
|
+
* `mapStyleUrl`), with its `remaply` source pointed at the tiles of the API in use, the sprite on that
|
|
21
|
+
* API, reachable fonts, and buildings and building numbers from `buildingMinZoom` /
|
|
22
|
+
* `addressNumberMinZoom`.
|
|
23
|
+
*
|
|
24
|
+
* The key is not written into the style: pass {@link transformRequest} to the map, which adds it to
|
|
25
|
+
* requests for the API's origin only. `RemaplyMap` does both for you.
|
|
26
|
+
*/
|
|
27
|
+
export declare function loadStyle(options?: {
|
|
28
|
+
signal?: AbortSignal;
|
|
29
|
+
}): Promise<StyleSpecification>;
|
|
30
|
+
/** The first font named literally in a symbol layer, for the glyph check and for marker labels. */
|
|
31
|
+
export declare function firstFont(style: Pick<StyleSpecification, "layers">): string | null;
|
|
32
|
+
export interface PrepareStyleOptions {
|
|
33
|
+
tileset: string;
|
|
34
|
+
buildingMinZoom: number | null;
|
|
35
|
+
addressNumberMinZoom: number | null;
|
|
36
|
+
}
|
|
37
|
+
/** Exported for tests. See {@link loadStyle}. */
|
|
38
|
+
export declare function prepareStyle(styleText: string, tileJson: TileJson, options: PrepareStyleOptions): StyleSpecification;
|
|
39
|
+
/**
|
|
40
|
+
* Tile URL template on the API in use. Keeps the query of the TileJSON URL (`?v=`, the tileset
|
|
41
|
+
* version): without it a rebuilt tileset would show a mix of old and new cached tiles. A `key` in
|
|
42
|
+
* that query is dropped: {@link transformRequest} adds the current one.
|
|
43
|
+
*/
|
|
44
|
+
export declare function tileUrl(tileset: string, tileJson: TileJson): string;
|
|
45
|
+
//# sourceMappingURL=style.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"style.d.ts","sourceRoot":"","sources":["../src/style.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAMtD,uGAAuG;AACvG,eAAO,MAAM,cAAc,YAAY,CAAC;AAExC,sHAAsH;AACtH,eAAO,MAAM,eAAe,gEAAgE,CAAC;AAM7F,oGAAoG;AACpG,MAAM,WAAW,QAAQ;IACvB,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC;IACzB,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAC7B;AAED,iEAAiE;AACjE,qBAAa,aAAc,SAAQ,KAAK;IACtC,SAAkB,IAAI,mBAAmB;CAC1C;AASD;;;;;;;;GAQG;AACH,wBAAsB,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