@apexara/map 1.1.0 → 1.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/README.md +315 -6
- package/fesm2022/apexara-map-geo.mjs +340 -0
- package/fesm2022/apexara-map-geo.mjs.map +1 -0
- package/fesm2022/apexara-map-search.mjs +93 -0
- package/fesm2022/apexara-map-search.mjs.map +1 -0
- package/fesm2022/apexara-map.mjs +309 -64
- package/fesm2022/apexara-map.mjs.map +1 -1
- package/package.json +9 -1
- package/types/apexara-map-geo.d.ts +217 -0
- package/types/apexara-map-search.d.ts +39 -0
- package/types/apexara-map.d.ts +160 -24
|
@@ -0,0 +1,340 @@
|
|
|
1
|
+
/** Every Mapbox web address the package calls or builds. */
|
|
2
|
+
class MapApiConfig {
|
|
3
|
+
/** Search Box API: `/suggest` and `/retrieve/<mapbox_id>`. */
|
|
4
|
+
static { this.SEARCH_BOX_URL = 'https://api.mapbox.com/search/searchbox/v1'; }
|
|
5
|
+
/** Styles API: `/<owner>/<id>/static/...` serves a style as a still image. */
|
|
6
|
+
static { this.STYLES_URL = 'https://api.mapbox.com/styles/v1'; }
|
|
7
|
+
/** What a hosted style URL starts with, as in `MapStyles`. */
|
|
8
|
+
static { this.STYLE_URL_PREFIX = 'mapbox://styles/'; }
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/** CSS colours in the form mapbox's style parser accepts, e.g. for a paint value read from a CSS custom property. */
|
|
12
|
+
class MapColorUtil {
|
|
13
|
+
static { this.HASH_CODE = 35; }
|
|
14
|
+
/** `#rrggbbaa` and `#rgba`, which mapbox rejects, as `rgba(r, g, b, a)` with the alpha to three places; else as it is. */
|
|
15
|
+
static toMapboxColor(cssColor) {
|
|
16
|
+
if (cssColor.charCodeAt(0) !== this.HASH_CODE || !this.isHexAfterHash(cssColor)) {
|
|
17
|
+
return cssColor;
|
|
18
|
+
}
|
|
19
|
+
if (cssColor.length === 9) {
|
|
20
|
+
return this.rgbaOf(cssColor.slice(1, 3), cssColor.slice(3, 5), cssColor.slice(5, 7), cssColor.slice(7, 9));
|
|
21
|
+
}
|
|
22
|
+
if (cssColor.length === 5) {
|
|
23
|
+
return this.rgbaOf(cssColor[1] + cssColor[1], cssColor[2] + cssColor[2], cssColor[3] + cssColor[3], cssColor[4] + cssColor[4]);
|
|
24
|
+
}
|
|
25
|
+
return cssColor;
|
|
26
|
+
}
|
|
27
|
+
static rgbaOf(red, green, blue, alpha) {
|
|
28
|
+
return `rgba(${parseInt(red, 16)}, ${parseInt(green, 16)}, ${parseInt(blue, 16)}, ${(parseInt(alpha, 16) / 255).toFixed(3)})`;
|
|
29
|
+
}
|
|
30
|
+
static isHexAfterHash(cssColor) {
|
|
31
|
+
for (let index = 1; index < cssColor.length; index++) {
|
|
32
|
+
if (!this.isHexDigit(cssColor.charCodeAt(index))) {
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return true;
|
|
37
|
+
}
|
|
38
|
+
// 0-9, A-F, a-f.
|
|
39
|
+
static isHexDigit(code) {
|
|
40
|
+
return (code >= 48 && code <= 57) || (code >= 65 && code <= 70) || (code >= 97 && code <= 102);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** One read of the browser's location, as a promise that always resolves. */
|
|
45
|
+
class MapGeolocationUtil {
|
|
46
|
+
/** The reader's position as `[lng, lat]`, or why there is none. `unavailable` at once where there is no geolocation. */
|
|
47
|
+
static locate(options) {
|
|
48
|
+
const geolocation = typeof navigator === 'undefined' ? undefined : navigator.geolocation;
|
|
49
|
+
if (!geolocation) {
|
|
50
|
+
return Promise.resolve({ status: 'unavailable' });
|
|
51
|
+
}
|
|
52
|
+
return new Promise((resolve) => geolocation.getCurrentPosition((position) => resolve({ status: 'located', position: [position.coords.longitude, position.coords.latitude] }), (error) => resolve({ status: error.code === error.PERMISSION_DENIED ? 'denied' : 'unavailable' }), options));
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** Plain geometry for maps: distances, boxes, circles, bounds and the camera framing them. Every point is `[lng, lat]`. */
|
|
57
|
+
class MapGeometryUtil {
|
|
58
|
+
/** Metres in a statute mile. */
|
|
59
|
+
static { this.METRES_PER_MILE = 1609.344; }
|
|
60
|
+
/** Mapbox's deepest zoom: where `cameraForBounds` holds a box with no area. */
|
|
61
|
+
static { this.MAX_ZOOM = 22; }
|
|
62
|
+
// Mean earth radius, for haversine distances.
|
|
63
|
+
static { this.EARTH_RADIUS_MILES = 3958.8; }
|
|
64
|
+
// Ground metres in one degree, for circles and boxes: a longitude degree at the equator, near enough for latitude.
|
|
65
|
+
static { this.METRES_PER_DEGREE = 111_320; }
|
|
66
|
+
// A longitude degree narrows with cos(latitude); the floor keeps a point at a pole from dividing by zero.
|
|
67
|
+
static { this.MIN_LATITUDE_COSINE = 0.01; }
|
|
68
|
+
// Mapbox draws the world this many pixels wide at zoom 0, doubling with each zoom level.
|
|
69
|
+
static { this.WORLD_WIDTH_AT_ZOOM_ZERO_PX = 512; }
|
|
70
|
+
// Smooth at every search radius, light enough to send as a query shape.
|
|
71
|
+
static { this.CIRCLE_SEGMENTS = 64; }
|
|
72
|
+
/** Great-circle (haversine) miles between two points, rounded to `decimals` when given. */
|
|
73
|
+
static milesBetween(from, to, decimals) {
|
|
74
|
+
const deltaLat = this.toRadians(to[1] - from[1]);
|
|
75
|
+
const deltaLng = this.toRadians(to[0] - from[0]);
|
|
76
|
+
const haversine = Math.sin(deltaLat / 2) ** 2 + Math.cos(this.toRadians(from[1])) * Math.cos(this.toRadians(to[1])) * Math.sin(deltaLng / 2) ** 2;
|
|
77
|
+
const miles = 2 * this.EARTH_RADIUS_MILES * Math.asin(Math.sqrt(haversine));
|
|
78
|
+
if (decimals === undefined) {
|
|
79
|
+
return miles;
|
|
80
|
+
}
|
|
81
|
+
const scale = 10 ** decimals;
|
|
82
|
+
return Math.round(miles * scale) / scale;
|
|
83
|
+
}
|
|
84
|
+
/** Whether a point can go on a map: both finite, and not the 0, 0 a record with no location tends to arrive as. */
|
|
85
|
+
static hasLocation(lng, lat) {
|
|
86
|
+
return Number.isFinite(lng) && Number.isFinite(lat) && !(lng === 0 && lat === 0);
|
|
87
|
+
}
|
|
88
|
+
/** The bounds of a square reaching `metres` from `center` on every side, e.g. to frame a circle of that radius. */
|
|
89
|
+
static boundsAround(center, metres) {
|
|
90
|
+
const [lng, lat] = center;
|
|
91
|
+
const latDelta = metres / this.METRES_PER_DEGREE;
|
|
92
|
+
const lngDelta = this.lngDeltaAt(lat, metres);
|
|
93
|
+
return [[lng - lngDelta, lat - latDelta], [lng + lngDelta, lat + latDelta]];
|
|
94
|
+
}
|
|
95
|
+
/** The closed ring (last point equals the first) of a ground circle `metres` in radius, for a GeoJSON polygon. */
|
|
96
|
+
static circleRing(center, metres, segments = this.CIRCLE_SEGMENTS) {
|
|
97
|
+
const [lng, lat] = center;
|
|
98
|
+
const latDelta = metres / this.METRES_PER_DEGREE;
|
|
99
|
+
const lngDelta = this.lngDeltaAt(lat, metres);
|
|
100
|
+
const ring = [];
|
|
101
|
+
for (let index = 0; index < segments; index++) {
|
|
102
|
+
const angle = (index / segments) * 2 * Math.PI;
|
|
103
|
+
ring.push([lng + lngDelta * Math.cos(angle), lat + latDelta * Math.sin(angle)]);
|
|
104
|
+
}
|
|
105
|
+
ring.push([ring[0][0], ring[0][1]]);
|
|
106
|
+
return ring;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* The Web Mercator centre and zoom fitting `bounds` in a `size` frame with `padding` on every side, before any map
|
|
110
|
+
* exists (mapbox's own `cameraForBounds` needs one). Null when the padding leaves no room. Zoom is capped at `maxZoom`.
|
|
111
|
+
*/
|
|
112
|
+
static cameraForBounds(bounds, size, padding = 0, maxZoom = this.MAX_ZOOM) {
|
|
113
|
+
const [[west, south], [east, north]] = bounds;
|
|
114
|
+
const innerWidth = size.width - 2 * padding;
|
|
115
|
+
const innerHeight = size.height - 2 * padding;
|
|
116
|
+
if (innerWidth <= 0 || innerHeight <= 0) {
|
|
117
|
+
return null;
|
|
118
|
+
}
|
|
119
|
+
const northY = this.mercatorY(north);
|
|
120
|
+
const southY = this.mercatorY(south);
|
|
121
|
+
const spanX = (east - west) / 360;
|
|
122
|
+
const spanY = (northY - southY) / (2 * Math.PI);
|
|
123
|
+
const widthZoom = Math.log2(innerWidth / (this.WORLD_WIDTH_AT_ZOOM_ZERO_PX * spanX));
|
|
124
|
+
const heightZoom = Math.log2(innerHeight / (this.WORLD_WIDTH_AT_ZOOM_ZERO_PX * spanY));
|
|
125
|
+
const centerLat = (Math.atan(Math.sinh((northY + southY) / 2)) * 180) / Math.PI;
|
|
126
|
+
return { center: [(west + east) / 2, centerLat], zoom: Math.min(widthZoom, heightZoom, maxZoom) };
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* The bounds of every position in any GeoJSON (collection, feature, geometry), walked in place: no flat copy, so a
|
|
130
|
+
* state's hundreds of thousands of points cost no allocation. Null when it holds no position.
|
|
131
|
+
*/
|
|
132
|
+
static boundsOf(geoJson, options) {
|
|
133
|
+
const extent = { west: Infinity, south: Infinity, east: -Infinity, north: -Infinity, wrappedWest: Infinity, wrappedEast: -Infinity };
|
|
134
|
+
this.extendByGeoJson(extent, geoJson);
|
|
135
|
+
return this.boundsOfExtent(extent, options?.wrapAntimeridian === true);
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Whether `outer` covers all of `inner`, edges included. `tolerance` forgives a miss up to that share of `inner`'s span
|
|
139
|
+
* per axis, e.g. 0.001 where `outer` was framed to `inner`'s edge and rounding can leave it a hair short.
|
|
140
|
+
*/
|
|
141
|
+
static containsBounds(outer, inner, tolerance = 0) {
|
|
142
|
+
const [[west, south], [east, north]] = outer;
|
|
143
|
+
const [[innerWest, innerSouth], [innerEast, innerNorth]] = inner;
|
|
144
|
+
const lngSlack = (innerEast - innerWest) * tolerance;
|
|
145
|
+
const latSlack = (innerNorth - innerSouth) * tolerance;
|
|
146
|
+
return innerWest >= west - lngSlack
|
|
147
|
+
&& innerEast <= east + lngSlack
|
|
148
|
+
&& innerSouth >= south - latSlack
|
|
149
|
+
&& innerNorth <= north + latSlack;
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Whether two polygons' outer rings match point for point (holes are not compared), e.g. as the `equal` of a signal
|
|
153
|
+
* holding `getViewportPolygon()`, so an unmoved camera is no change.
|
|
154
|
+
*/
|
|
155
|
+
static sameOuterRing(first, second) {
|
|
156
|
+
if (first === second) {
|
|
157
|
+
return true;
|
|
158
|
+
}
|
|
159
|
+
if (!first || !second) {
|
|
160
|
+
return false;
|
|
161
|
+
}
|
|
162
|
+
const firstRing = first[0] ?? [];
|
|
163
|
+
const secondRing = second[0] ?? [];
|
|
164
|
+
if (firstRing.length !== secondRing.length) {
|
|
165
|
+
return false;
|
|
166
|
+
}
|
|
167
|
+
for (let index = 0; index < firstRing.length; index++) {
|
|
168
|
+
if (firstRing[index][0] !== secondRing[index][0] || firstRing[index][1] !== secondRing[index][1]) {
|
|
169
|
+
return false;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
return true;
|
|
173
|
+
}
|
|
174
|
+
/** Calls `visit` with every position in GeoJSON coordinates at any nesting, in order, as the arrays they are. */
|
|
175
|
+
static forEachPosition(coordinates, visit) {
|
|
176
|
+
if (!Array.isArray(coordinates)) {
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
if (typeof coordinates[0] === 'number' && typeof coordinates[1] === 'number') {
|
|
180
|
+
visit(coordinates);
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
for (let index = 0; index < coordinates.length; index++) {
|
|
184
|
+
this.forEachPosition(coordinates[index], visit);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
static extendByGeoJson(extent, geoJson) {
|
|
188
|
+
if (geoJson.type === 'FeatureCollection') {
|
|
189
|
+
for (const feature of geoJson.features) {
|
|
190
|
+
this.extendByGeoJson(extent, feature);
|
|
191
|
+
}
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
194
|
+
if (geoJson.type === 'Feature') {
|
|
195
|
+
if (geoJson.geometry) {
|
|
196
|
+
this.extendByGeoJson(extent, geoJson.geometry);
|
|
197
|
+
}
|
|
198
|
+
return;
|
|
199
|
+
}
|
|
200
|
+
if (geoJson.type === 'GeometryCollection') {
|
|
201
|
+
for (const geometry of geoJson.geometries) {
|
|
202
|
+
this.extendByGeoJson(extent, geometry);
|
|
203
|
+
}
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
206
|
+
this.forEachPosition(geoJson.coordinates, (position) => this.extend(extent, position));
|
|
207
|
+
}
|
|
208
|
+
static extend(extent, position) {
|
|
209
|
+
const lng = position[0];
|
|
210
|
+
const lat = position[1];
|
|
211
|
+
const wrappedLng = lng < 0 ? lng + 360 : lng;
|
|
212
|
+
if (lng < extent.west) {
|
|
213
|
+
extent.west = lng;
|
|
214
|
+
}
|
|
215
|
+
if (lng > extent.east) {
|
|
216
|
+
extent.east = lng;
|
|
217
|
+
}
|
|
218
|
+
if (lat < extent.south) {
|
|
219
|
+
extent.south = lat;
|
|
220
|
+
}
|
|
221
|
+
if (lat > extent.north) {
|
|
222
|
+
extent.north = lat;
|
|
223
|
+
}
|
|
224
|
+
if (wrappedLng < extent.wrappedWest) {
|
|
225
|
+
extent.wrappedWest = wrappedLng;
|
|
226
|
+
}
|
|
227
|
+
if (wrappedLng > extent.wrappedEast) {
|
|
228
|
+
extent.wrappedEast = wrappedLng;
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
static boundsOfExtent(extent, wrapAntimeridian) {
|
|
232
|
+
if (!(extent.west <= extent.east) || !(extent.south <= extent.north)) {
|
|
233
|
+
return null;
|
|
234
|
+
}
|
|
235
|
+
if (wrapAntimeridian && extent.wrappedEast - extent.wrappedWest < extent.east - extent.west) {
|
|
236
|
+
return [[extent.wrappedWest, extent.south], [extent.wrappedEast, extent.north]];
|
|
237
|
+
}
|
|
238
|
+
return [[extent.west, extent.south], [extent.east, extent.north]];
|
|
239
|
+
}
|
|
240
|
+
static lngDeltaAt(lat, metres) {
|
|
241
|
+
return metres / (this.METRES_PER_DEGREE * Math.max(Math.cos(this.toRadians(lat)), this.MIN_LATITUDE_COSINE));
|
|
242
|
+
}
|
|
243
|
+
static mercatorY(lat) {
|
|
244
|
+
return Math.log(Math.tan(Math.PI / 4 + (lat * Math.PI) / 360));
|
|
245
|
+
}
|
|
246
|
+
static toRadians(degrees) {
|
|
247
|
+
return (degrees * Math.PI) / 180;
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
/** Reads Mapbox Search responses into results. `localityOf` also reads a Geocoding v6 feature's context. */
|
|
252
|
+
class MapSearchResponseUtil {
|
|
253
|
+
/** City, region code and postcode from a result's `context`; an empty string for what it lacks. */
|
|
254
|
+
static localityOf(context) {
|
|
255
|
+
return {
|
|
256
|
+
city: context?.place?.name ?? '',
|
|
257
|
+
region: context?.region?.region_code ?? '',
|
|
258
|
+
postcode: context?.postcode?.name ?? '',
|
|
259
|
+
};
|
|
260
|
+
}
|
|
261
|
+
/** A `suggest` item as a result, with no position: `retrieve` gives that. */
|
|
262
|
+
static resultOf(suggestion) {
|
|
263
|
+
return {
|
|
264
|
+
mapboxId: suggestion.mapbox_id ?? '',
|
|
265
|
+
...this.namesOf(suggestion),
|
|
266
|
+
...this.localityOf(suggestion.context),
|
|
267
|
+
lat: null,
|
|
268
|
+
lon: null,
|
|
269
|
+
};
|
|
270
|
+
}
|
|
271
|
+
/** A `retrieve` feature as a result, with its position. */
|
|
272
|
+
static placeOf(mapboxId, feature) {
|
|
273
|
+
const properties = feature.properties ?? {};
|
|
274
|
+
const lon = feature.geometry?.coordinates?.[0];
|
|
275
|
+
const lat = feature.geometry?.coordinates?.[1];
|
|
276
|
+
return {
|
|
277
|
+
mapboxId,
|
|
278
|
+
...this.namesOf(properties),
|
|
279
|
+
...this.localityOf(properties.context),
|
|
280
|
+
lat: typeof lat === 'number' ? lat : null,
|
|
281
|
+
lon: typeof lon === 'number' ? lon : null,
|
|
282
|
+
};
|
|
283
|
+
}
|
|
284
|
+
// Mapbox's full address when it sent one, else the name and the place line joined.
|
|
285
|
+
static namesOf(named) {
|
|
286
|
+
return {
|
|
287
|
+
name: named.name ?? '',
|
|
288
|
+
fullAddress: named.full_address ?? this.joinedAddress(named),
|
|
289
|
+
};
|
|
290
|
+
}
|
|
291
|
+
static joinedAddress(named) {
|
|
292
|
+
if (named.name && named.place_formatted) {
|
|
293
|
+
return `${named.name}, ${named.place_formatted}`;
|
|
294
|
+
}
|
|
295
|
+
return named.name || named.place_formatted || '';
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
/** Mapbox Static Images: a style rendered as one still, e.g. a placeholder while the live map is held back. */
|
|
300
|
+
class MapStaticImageUtil {
|
|
301
|
+
/** The image's URL. Options left out take mapbox's defaults (bearing and pitch 0, attribution and logo shown). */
|
|
302
|
+
static url(options) {
|
|
303
|
+
const size = `${options.width}x${options.height}${options.retina ? '@2x' : ''}`;
|
|
304
|
+
return `${MapApiConfig.STYLES_URL}/${this.stylePathOf(options.style)}/static/${this.cameraOf(options)}/${size}?${this.queryOf(options)}`;
|
|
305
|
+
}
|
|
306
|
+
// `mapbox://styles/<owner>/<id>` → `<owner>/<id>`; a bare `<owner>/<id>` as it is.
|
|
307
|
+
static stylePathOf(style) {
|
|
308
|
+
return style.startsWith(MapApiConfig.STYLE_URL_PREFIX) ? style.slice(MapApiConfig.STYLE_URL_PREFIX.length) : style;
|
|
309
|
+
}
|
|
310
|
+
// `lng,lat,zoom[,bearing[,pitch]]`: mapbox reads them by position, so a pitch needs the bearing before it.
|
|
311
|
+
static cameraOf(options) {
|
|
312
|
+
const camera = `${options.center[0]},${options.center[1]},${options.zoom}`;
|
|
313
|
+
if (options.pitch !== undefined) {
|
|
314
|
+
return `${camera},${options.bearing ?? 0},${options.pitch}`;
|
|
315
|
+
}
|
|
316
|
+
if (options.bearing !== undefined) {
|
|
317
|
+
return `${camera},${options.bearing}`;
|
|
318
|
+
}
|
|
319
|
+
return camera;
|
|
320
|
+
}
|
|
321
|
+
static queryOf(options) {
|
|
322
|
+
let query = `access_token=${encodeURIComponent(options.accessToken)}`;
|
|
323
|
+
if (options.attribution !== undefined) {
|
|
324
|
+
query += `&attribution=${options.attribution}`;
|
|
325
|
+
}
|
|
326
|
+
if (options.logo !== undefined) {
|
|
327
|
+
query += `&logo=${options.logo}`;
|
|
328
|
+
}
|
|
329
|
+
return query;
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
// No runtime import at all: neither Angular nor mapbox-gl, so a server, a worker or a page without a map can use it.
|
|
334
|
+
|
|
335
|
+
/**
|
|
336
|
+
* Generated bundle index. Do not edit.
|
|
337
|
+
*/
|
|
338
|
+
|
|
339
|
+
export { MapApiConfig, MapColorUtil, MapGeolocationUtil, MapGeometryUtil, MapSearchResponseUtil, MapStaticImageUtil };
|
|
340
|
+
//# sourceMappingURL=apexara-map-geo.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"apexara-map-geo.mjs","sources":["../../../../projects/apexara/map/geo/src/map-api.config.ts","../../../../projects/apexara/map/geo/src/map-color.util.ts","../../../../projects/apexara/map/geo/src/map-geolocation.util.ts","../../../../projects/apexara/map/geo/src/map-geometry.util.ts","../../../../projects/apexara/map/geo/src/map-search-response.util.ts","../../../../projects/apexara/map/geo/src/map-static-image.util.ts","../../../../projects/apexara/map/geo/public-api.ts","../../../../projects/apexara/map/geo/apexara-map-geo.ts"],"sourcesContent":["/** Every Mapbox web address the package calls or builds. */\nexport class MapApiConfig {\n\n /** Search Box API: `/suggest` and `/retrieve/<mapbox_id>`. */\n public static readonly SEARCH_BOX_URL = 'https://api.mapbox.com/search/searchbox/v1';\n\n /** Styles API: `/<owner>/<id>/static/...` serves a style as a still image. */\n public static readonly STYLES_URL = 'https://api.mapbox.com/styles/v1';\n\n /** What a hosted style URL starts with, as in `MapStyles`. */\n public static readonly STYLE_URL_PREFIX = 'mapbox://styles/';\n\n}\n","/** CSS colours in the form mapbox's style parser accepts, e.g. for a paint value read from a CSS custom property. */\nexport class MapColorUtil {\n\n private static readonly HASH_CODE = 35;\n\n /** `#rrggbbaa` and `#rgba`, which mapbox rejects, as `rgba(r, g, b, a)` with the alpha to three places; else as it is. */\n public static toMapboxColor(cssColor: string): string {\n if (cssColor.charCodeAt(0) !== this.HASH_CODE || !this.isHexAfterHash(cssColor)) {\n return cssColor;\n }\n\n if (cssColor.length === 9) {\n return this.rgbaOf(cssColor.slice(1, 3), cssColor.slice(3, 5), cssColor.slice(5, 7), cssColor.slice(7, 9));\n }\n\n if (cssColor.length === 5) {\n return this.rgbaOf(cssColor[1] + cssColor[1], cssColor[2] + cssColor[2], cssColor[3] + cssColor[3], cssColor[4] + cssColor[4]);\n }\n\n return cssColor;\n }\n\n private static rgbaOf(red: string, green: string, blue: string, alpha: string): string {\n return `rgba(${parseInt(red, 16)}, ${parseInt(green, 16)}, ${parseInt(blue, 16)}, ${(parseInt(alpha, 16) / 255).toFixed(3)})`;\n }\n\n private static isHexAfterHash(cssColor: string): boolean {\n for (let index = 1; index < cssColor.length; index++) {\n if (!this.isHexDigit(cssColor.charCodeAt(index))) {\n return false;\n }\n }\n\n return true;\n }\n\n // 0-9, A-F, a-f.\n private static isHexDigit(code: number): boolean {\n return (code >= 48 && code <= 57) || (code >= 65 && code <= 70) || (code >= 97 && code <= 102);\n }\n\n}\n","import { MapLocateOptions, MapLocateResult } from './map-geo.types';\n\n/** One read of the browser's location, as a promise that always resolves. */\nexport class MapGeolocationUtil {\n\n /** The reader's position as `[lng, lat]`, or why there is none. `unavailable` at once where there is no geolocation. */\n public static locate(options?: MapLocateOptions): Promise<MapLocateResult> {\n const geolocation = typeof navigator === 'undefined' ? undefined : navigator.geolocation;\n\n if (!geolocation) {\n return Promise.resolve({ status: 'unavailable' });\n }\n\n return new Promise((resolve) => geolocation.getCurrentPosition(\n (position) => resolve({ status: 'located', position: [position.coords.longitude, position.coords.latitude] }),\n (error) => resolve({ status: error.code === error.PERMISSION_DENIED ? 'denied' : 'unavailable' }),\n options,\n ));\n }\n\n}\n","import type * as GeoJSON from 'geojson';\n\nimport { MapBounds, MapBoundsExtent, MapBoundsOptions, MapCamera, MapCoordinates, MapLngLat, MapSize } from './map-geo.types';\n\n/** Plain geometry for maps: distances, boxes, circles, bounds and the camera framing them. Every point is `[lng, lat]`. */\nexport class MapGeometryUtil {\n\n /** Metres in a statute mile. */\n public static readonly METRES_PER_MILE = 1609.344;\n\n /** Mapbox's deepest zoom: where `cameraForBounds` holds a box with no area. */\n public static readonly MAX_ZOOM = 22;\n\n // Mean earth radius, for haversine distances.\n private static readonly EARTH_RADIUS_MILES = 3958.8;\n\n // Ground metres in one degree, for circles and boxes: a longitude degree at the equator, near enough for latitude.\n private static readonly METRES_PER_DEGREE = 111_320;\n\n // A longitude degree narrows with cos(latitude); the floor keeps a point at a pole from dividing by zero.\n private static readonly MIN_LATITUDE_COSINE = 0.01;\n\n // Mapbox draws the world this many pixels wide at zoom 0, doubling with each zoom level.\n private static readonly WORLD_WIDTH_AT_ZOOM_ZERO_PX = 512;\n\n // Smooth at every search radius, light enough to send as a query shape.\n private static readonly CIRCLE_SEGMENTS = 64;\n\n /** Great-circle (haversine) miles between two points, rounded to `decimals` when given. */\n public static milesBetween(from: MapLngLat, to: MapLngLat, decimals?: number): number {\n const deltaLat = this.toRadians(to[1] - from[1]);\n const deltaLng = this.toRadians(to[0] - from[0]);\n const haversine = Math.sin(deltaLat / 2) ** 2 + Math.cos(this.toRadians(from[1])) * Math.cos(this.toRadians(to[1])) * Math.sin(deltaLng / 2) ** 2;\n const miles = 2 * this.EARTH_RADIUS_MILES * Math.asin(Math.sqrt(haversine));\n\n if (decimals === undefined) {\n return miles;\n }\n\n const scale = 10 ** decimals;\n\n return Math.round(miles * scale) / scale;\n }\n\n /** Whether a point can go on a map: both finite, and not the 0, 0 a record with no location tends to arrive as. */\n public static hasLocation(lng: number | null | undefined, lat: number | null | undefined): boolean {\n return Number.isFinite(lng) && Number.isFinite(lat) && !(lng === 0 && lat === 0);\n }\n\n /** The bounds of a square reaching `metres` from `center` on every side, e.g. to frame a circle of that radius. */\n public static boundsAround(center: MapLngLat, metres: number): MapBounds {\n const [lng, lat] = center;\n const latDelta = metres / this.METRES_PER_DEGREE;\n const lngDelta = this.lngDeltaAt(lat, metres);\n\n return [[lng - lngDelta, lat - latDelta], [lng + lngDelta, lat + latDelta]];\n }\n\n /** The closed ring (last point equals the first) of a ground circle `metres` in radius, for a GeoJSON polygon. */\n public static circleRing(center: MapLngLat, metres: number, segments = this.CIRCLE_SEGMENTS): MapLngLat[] {\n const [lng, lat] = center;\n const latDelta = metres / this.METRES_PER_DEGREE;\n const lngDelta = this.lngDeltaAt(lat, metres);\n const ring: MapLngLat[] = [];\n\n for (let index = 0; index < segments; index++) {\n const angle = (index / segments) * 2 * Math.PI;\n\n ring.push([lng + lngDelta * Math.cos(angle), lat + latDelta * Math.sin(angle)]);\n }\n\n ring.push([ring[0][0], ring[0][1]]);\n\n return ring;\n }\n\n /**\n * The Web Mercator centre and zoom fitting `bounds` in a `size` frame with `padding` on every side, before any map\n * exists (mapbox's own `cameraForBounds` needs one). Null when the padding leaves no room. Zoom is capped at `maxZoom`.\n */\n public static cameraForBounds(bounds: MapBounds, size: MapSize, padding = 0, maxZoom = this.MAX_ZOOM): MapCamera | null {\n const [[west, south], [east, north]] = bounds;\n const innerWidth = size.width - 2 * padding;\n const innerHeight = size.height - 2 * padding;\n\n if (innerWidth <= 0 || innerHeight <= 0) {\n return null;\n }\n\n const northY = this.mercatorY(north);\n const southY = this.mercatorY(south);\n const spanX = (east - west) / 360;\n const spanY = (northY - southY) / (2 * Math.PI);\n const widthZoom = Math.log2(innerWidth / (this.WORLD_WIDTH_AT_ZOOM_ZERO_PX * spanX));\n const heightZoom = Math.log2(innerHeight / (this.WORLD_WIDTH_AT_ZOOM_ZERO_PX * spanY));\n const centerLat = (Math.atan(Math.sinh((northY + southY) / 2)) * 180) / Math.PI;\n\n return { center: [(west + east) / 2, centerLat], zoom: Math.min(widthZoom, heightZoom, maxZoom) };\n }\n\n /**\n * The bounds of every position in any GeoJSON (collection, feature, geometry), walked in place: no flat copy, so a\n * state's hundreds of thousands of points cost no allocation. Null when it holds no position.\n */\n public static boundsOf(geoJson: GeoJSON.GeoJSON, options?: MapBoundsOptions): MapBounds | null {\n const extent: MapBoundsExtent = { west: Infinity, south: Infinity, east: -Infinity, north: -Infinity, wrappedWest: Infinity, wrappedEast: -Infinity };\n\n this.extendByGeoJson(extent, geoJson);\n\n return this.boundsOfExtent(extent, options?.wrapAntimeridian === true);\n }\n\n /**\n * Whether `outer` covers all of `inner`, edges included. `tolerance` forgives a miss up to that share of `inner`'s span\n * per axis, e.g. 0.001 where `outer` was framed to `inner`'s edge and rounding can leave it a hair short.\n */\n public static containsBounds(outer: MapBounds, inner: MapBounds, tolerance = 0): boolean {\n const [[west, south], [east, north]] = outer;\n const [[innerWest, innerSouth], [innerEast, innerNorth]] = inner;\n const lngSlack = (innerEast - innerWest) * tolerance;\n const latSlack = (innerNorth - innerSouth) * tolerance;\n\n return innerWest >= west - lngSlack\n && innerEast <= east + lngSlack\n && innerSouth >= south - latSlack\n && innerNorth <= north + latSlack;\n }\n\n /**\n * Whether two polygons' outer rings match point for point (holes are not compared), e.g. as the `equal` of a signal\n * holding `getViewportPolygon()`, so an unmoved camera is no change.\n */\n public static sameOuterRing(first: GeoJSON.Position[][] | null, second: GeoJSON.Position[][] | null): boolean {\n if (first === second) {\n return true;\n }\n\n if (!first || !second) {\n return false;\n }\n\n const firstRing = first[0] ?? [];\n const secondRing = second[0] ?? [];\n\n if (firstRing.length !== secondRing.length) {\n return false;\n }\n\n for (let index = 0; index < firstRing.length; index++) {\n if (firstRing[index][0] !== secondRing[index][0] || firstRing[index][1] !== secondRing[index][1]) {\n return false;\n }\n }\n\n return true;\n }\n\n /** Calls `visit` with every position in GeoJSON coordinates at any nesting, in order, as the arrays they are. */\n public static forEachPosition(coordinates: MapCoordinates, visit: (position: GeoJSON.Position) => void): void {\n if (!Array.isArray(coordinates)) {\n return;\n }\n\n if (typeof coordinates[0] === 'number' && typeof coordinates[1] === 'number') {\n visit(coordinates as GeoJSON.Position);\n\n return;\n }\n\n for (let index = 0; index < coordinates.length; index++) {\n this.forEachPosition(coordinates[index] as MapCoordinates, visit);\n }\n }\n\n private static extendByGeoJson(extent: MapBoundsExtent, geoJson: GeoJSON.GeoJSON): void {\n if (geoJson.type === 'FeatureCollection') {\n for (const feature of geoJson.features) {\n this.extendByGeoJson(extent, feature);\n }\n\n return;\n }\n\n if (geoJson.type === 'Feature') {\n if (geoJson.geometry) {\n this.extendByGeoJson(extent, geoJson.geometry);\n }\n\n return;\n }\n\n if (geoJson.type === 'GeometryCollection') {\n for (const geometry of geoJson.geometries) {\n this.extendByGeoJson(extent, geometry);\n }\n\n return;\n }\n\n this.forEachPosition(geoJson.coordinates, (position) => this.extend(extent, position));\n }\n\n private static extend(extent: MapBoundsExtent, position: GeoJSON.Position): void {\n const lng = position[0];\n const lat = position[1];\n const wrappedLng = lng < 0 ? lng + 360 : lng;\n\n if (lng < extent.west) {\n extent.west = lng;\n }\n\n if (lng > extent.east) {\n extent.east = lng;\n }\n\n if (lat < extent.south) {\n extent.south = lat;\n }\n\n if (lat > extent.north) {\n extent.north = lat;\n }\n\n if (wrappedLng < extent.wrappedWest) {\n extent.wrappedWest = wrappedLng;\n }\n\n if (wrappedLng > extent.wrappedEast) {\n extent.wrappedEast = wrappedLng;\n }\n }\n\n private static boundsOfExtent(extent: MapBoundsExtent, wrapAntimeridian: boolean): MapBounds | null {\n if (!(extent.west <= extent.east) || !(extent.south <= extent.north)) {\n return null;\n }\n\n if (wrapAntimeridian && extent.wrappedEast - extent.wrappedWest < extent.east - extent.west) {\n return [[extent.wrappedWest, extent.south], [extent.wrappedEast, extent.north]];\n }\n\n return [[extent.west, extent.south], [extent.east, extent.north]];\n }\n\n private static lngDeltaAt(lat: number, metres: number): number {\n return metres / (this.METRES_PER_DEGREE * Math.max(Math.cos(this.toRadians(lat)), this.MIN_LATITUDE_COSINE));\n }\n\n private static mercatorY(lat: number): number {\n return Math.log(Math.tan(Math.PI / 4 + (lat * Math.PI) / 360));\n }\n\n private static toRadians(degrees: number): number {\n return (degrees * Math.PI) / 180;\n }\n\n}\n","import { MapSearchApiContext, MapSearchApiFeature, MapSearchApiNamed, MapSearchApiSuggestion, MapSearchLocality, MapSearchResult } from './map-geo.types';\n\n/** Reads Mapbox Search responses into results. `localityOf` also reads a Geocoding v6 feature's context. */\nexport class MapSearchResponseUtil {\n\n /** City, region code and postcode from a result's `context`; an empty string for what it lacks. */\n public static localityOf(context: MapSearchApiContext | undefined): MapSearchLocality {\n return {\n city: context?.place?.name ?? '',\n region: context?.region?.region_code ?? '',\n postcode: context?.postcode?.name ?? '',\n };\n }\n\n /** A `suggest` item as a result, with no position: `retrieve` gives that. */\n public static resultOf(suggestion: MapSearchApiSuggestion): MapSearchResult {\n return {\n mapboxId: suggestion.mapbox_id ?? '',\n ...this.namesOf(suggestion),\n ...this.localityOf(suggestion.context),\n lat: null,\n lon: null,\n };\n }\n\n /** A `retrieve` feature as a result, with its position. */\n public static placeOf(mapboxId: string, feature: MapSearchApiFeature): MapSearchResult {\n const properties = feature.properties ?? {};\n const lon = feature.geometry?.coordinates?.[0];\n const lat = feature.geometry?.coordinates?.[1];\n\n return {\n mapboxId,\n ...this.namesOf(properties),\n ...this.localityOf(properties.context),\n lat: typeof lat === 'number' ? lat : null,\n lon: typeof lon === 'number' ? lon : null,\n };\n }\n\n // Mapbox's full address when it sent one, else the name and the place line joined.\n private static namesOf(named: MapSearchApiNamed): Pick<MapSearchResult, 'name' | 'fullAddress'> {\n return {\n name: named.name ?? '',\n fullAddress: named.full_address ?? this.joinedAddress(named),\n };\n }\n\n private static joinedAddress(named: MapSearchApiNamed): string {\n if (named.name && named.place_formatted) {\n return `${named.name}, ${named.place_formatted}`;\n }\n\n return named.name || named.place_formatted || '';\n }\n\n}\n","import { MapApiConfig } from './map-api.config';\nimport { MapStaticImageOptions } from './map-geo.types';\n\n/** Mapbox Static Images: a style rendered as one still, e.g. a placeholder while the live map is held back. */\nexport class MapStaticImageUtil {\n\n /** The image's URL. Options left out take mapbox's defaults (bearing and pitch 0, attribution and logo shown). */\n public static url(options: MapStaticImageOptions): string {\n const size = `${options.width}x${options.height}${options.retina ? '@2x' : ''}`;\n\n return `${MapApiConfig.STYLES_URL}/${this.stylePathOf(options.style)}/static/${this.cameraOf(options)}/${size}?${this.queryOf(options)}`;\n }\n\n // `mapbox://styles/<owner>/<id>` → `<owner>/<id>`; a bare `<owner>/<id>` as it is.\n private static stylePathOf(style: string): string {\n return style.startsWith(MapApiConfig.STYLE_URL_PREFIX) ? style.slice(MapApiConfig.STYLE_URL_PREFIX.length) : style;\n }\n\n // `lng,lat,zoom[,bearing[,pitch]]`: mapbox reads them by position, so a pitch needs the bearing before it.\n private static cameraOf(options: MapStaticImageOptions): string {\n const camera = `${options.center[0]},${options.center[1]},${options.zoom}`;\n\n if (options.pitch !== undefined) {\n return `${camera},${options.bearing ?? 0},${options.pitch}`;\n }\n\n if (options.bearing !== undefined) {\n return `${camera},${options.bearing}`;\n }\n\n return camera;\n }\n\n private static queryOf(options: MapStaticImageOptions): string {\n let query = `access_token=${encodeURIComponent(options.accessToken)}`;\n\n if (options.attribution !== undefined) {\n query += `&attribution=${options.attribution}`;\n }\n\n if (options.logo !== undefined) {\n query += `&logo=${options.logo}`;\n }\n\n return query;\n }\n\n}\n","// No runtime import at all: neither Angular nor mapbox-gl, so a server, a worker or a page without a map can use it.\nexport { MapApiConfig } from './src/map-api.config';\nexport { MapColorUtil } from './src/map-color.util';\nexport { MapGeolocationUtil } from './src/map-geolocation.util';\nexport { MapGeometryUtil } from './src/map-geometry.util';\nexport { MapSearchResponseUtil } from './src/map-search-response.util';\nexport { MapStaticImageUtil } from './src/map-static-image.util';\nexport type {\n MapBounds,\n MapBoundsOptions,\n MapCamera,\n MapCoordinates,\n MapLngLat,\n MapLocateOptions,\n MapLocateResult,\n MapLocateStatus,\n MapSearchApiContext,\n MapSearchApiContextEntry,\n MapSearchApiFeature,\n MapSearchApiNamed,\n MapSearchApiRetrieveResponse,\n MapSearchApiSuggestResponse,\n MapSearchApiSuggestion,\n MapSearchLocality,\n MapSearchResult,\n MapSize,\n MapStaticImageOptions,\n} from './src/map-geo.types';\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":"AAAA;MACa,YAAY,CAAA;;aAGA,IAAA,CAAA,cAAc,GAAG,4CAA4C,CAAC;;aAG9D,IAAA,CAAA,UAAU,GAAG,kCAAkC,CAAC;;aAGhD,IAAA,CAAA,gBAAgB,GAAG,kBAAkB,CAAC;;;ACV/D;MACa,YAAY,CAAA;aAEC,IAAA,CAAA,SAAS,GAAG,EAAE,CAAC;;IAGhC,OAAO,aAAa,CAAC,QAAgB,EAAA;AAC1C,QAAA,IAAI,QAAQ,CAAC,UAAU,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,SAAS,IAAI,CAAC,IAAI,CAAC,cAAc,CAAC,QAAQ,CAAC,EAAE;AAC/E,YAAA,OAAO,QAAQ;QACjB;AAEA,QAAA,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC,EAAE;AACzB,YAAA,OAAO,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,QAAQ,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,QAAQ,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,QAAQ,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;QAC5G;AAEA,QAAA,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC,EAAE;YACzB,OAAO,IAAI,CAAC,MA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,MAAM,CAAC,CAAC,CAAC,IAAI,OAAO,CAAC,IAAI,CAAA,CAAE;AAE1E,QAAA,IAAI,OAAO,CAAC,KAAK,KAAK,SAAS,EAAE;AAC/B,YAAA,OAAO,CAAA,EAAG,MAAM,CAAA,CAAA,EAAI,OAAO,CAAC,OAAO,IAAI,CAAC,CAAA,CAAA,EAAI,OAAO,CAAC,KAAK,EAAE;QAC7D;AAEA,QAAA,IAAI,OAAO,CAAC,OAAO,KAAK,SAAS,EAAE;AACjC,YAAA,OAAO,GAAG,MAAM,CAAA,CAAA,EAAI,OAAO,CAAC,OAAO,EAAE;QACvC;AAEA,QAAA,OAAO,MAAM;IACf;IAEQ,OAAO,OAAO,CAAC,OAA8B,EAAA;QACnD,IAAI,KAAK,GAAG,CAAA,aAAA,EAAgB,kBAAkB,CAAC,OAAO,CAAC,WAAW,CAAC,CAAA,CAAE;AAErE,QAAA,IAAI,OAAO,CAAC,WAAW,KAAK,SAAS,EAAE;AACrC,YAAA,KAAK,IAAI,CAAA,aAAA,EAAgB,OAAO,CAAC,WAAW,EAAE;QAChD;AAEA,QAAA,IAAI,OAAO,CAAC,IAAI,KAAK,SAAS,EAAE;AAC9B,YAAA,KAAK,IAAI,CAAA,MAAA,EAAS,OAAO,CAAC,IAAI,EAAE;QAClC;AAEA,QAAA,OAAO,KAAK;IACd;AAED;;AC/CD;;ACAA;;AAEG;;;;"}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { isPlatformBrowser } from '@angular/common';
|
|
2
|
+
import * as i0 from '@angular/core';
|
|
3
|
+
import { inject, PLATFORM_ID, Injectable } from '@angular/core';
|
|
4
|
+
import { MAP_CONFIG } from '@apexara/map/config';
|
|
5
|
+
import { MapApiConfig, MapSearchResponseUtil } from '@apexara/map/geo';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Mapbox Search Box: `suggest` while the reader types, `retrieve` on a pick, billed per session (the session token
|
|
9
|
+
* rotates after a retrieve). Quiet on failure ([] or null, 5 s timeout). Uses `fetch`, never HttpClient, whose
|
|
10
|
+
* interceptors could send an app's own credentials to api.mapbox.com.
|
|
11
|
+
*/
|
|
12
|
+
class MapboxSearchService {
|
|
13
|
+
constructor() {
|
|
14
|
+
this.config = inject(MAP_CONFIG);
|
|
15
|
+
this.platformId = inject(PLATFORM_ID);
|
|
16
|
+
this.requestTimeoutMs = 5000;
|
|
17
|
+
// The billed session `suggest` and `retrieve` share: '' until the next call starts one.
|
|
18
|
+
this.sessionToken = '';
|
|
19
|
+
}
|
|
20
|
+
/** Whether a search can run: a token is configured and this is a browser. */
|
|
21
|
+
get isAvailable() {
|
|
22
|
+
return !!this.config.accessToken && isPlatformBrowser(this.platformId);
|
|
23
|
+
}
|
|
24
|
+
/** Suggestions for `query`, with no position yet. [] when unavailable or on any failure. */
|
|
25
|
+
async suggest(query, options) {
|
|
26
|
+
if (!this.isAvailable) {
|
|
27
|
+
return [];
|
|
28
|
+
}
|
|
29
|
+
const response = await this.get(`${MapApiConfig.SEARCH_BOX_URL}/suggest?${this.suggestParams(query, options)}`);
|
|
30
|
+
const results = [];
|
|
31
|
+
for (const suggestion of response?.suggestions ?? []) {
|
|
32
|
+
if (suggestion.mapbox_id) {
|
|
33
|
+
results.push(MapSearchResponseUtil.resultOf(suggestion));
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return results;
|
|
37
|
+
}
|
|
38
|
+
/** A suggestion's full record, the only call with a position; it ends the session. Null when unavailable or none. */
|
|
39
|
+
async retrieve(mapboxId) {
|
|
40
|
+
if (!this.isAvailable) {
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
const params = new URLSearchParams({ access_token: this.config.accessToken, session_token: this.session() });
|
|
44
|
+
const response = await this.get(`${MapApiConfig.SEARCH_BOX_URL}/retrieve/${encodeURIComponent(mapboxId)}?${params}`);
|
|
45
|
+
this.sessionToken = '';
|
|
46
|
+
const feature = response?.features?.[0];
|
|
47
|
+
return feature ? MapSearchResponseUtil.placeOf(mapboxId, feature) : null;
|
|
48
|
+
}
|
|
49
|
+
suggestParams(query, options) {
|
|
50
|
+
const params = new URLSearchParams({ q: query, access_token: this.config.accessToken, session_token: this.session() });
|
|
51
|
+
if (options?.types !== undefined) {
|
|
52
|
+
params.set('types', options.types);
|
|
53
|
+
}
|
|
54
|
+
if (options?.country !== undefined) {
|
|
55
|
+
params.set('country', options.country);
|
|
56
|
+
}
|
|
57
|
+
if (options?.limit !== undefined) {
|
|
58
|
+
params.set('limit', `${options.limit}`);
|
|
59
|
+
}
|
|
60
|
+
return params;
|
|
61
|
+
}
|
|
62
|
+
session() {
|
|
63
|
+
if (!this.sessionToken) {
|
|
64
|
+
this.sessionToken = crypto.randomUUID();
|
|
65
|
+
}
|
|
66
|
+
return this.sessionToken;
|
|
67
|
+
}
|
|
68
|
+
// Null on an error status, a network failure or the timeout, so a hung api.mapbox.com never holds the caller.
|
|
69
|
+
async get(url) {
|
|
70
|
+
try {
|
|
71
|
+
const response = await fetch(url, { signal: AbortSignal.timeout(this.requestTimeoutMs) });
|
|
72
|
+
return response.ok ? await response.json() : null;
|
|
73
|
+
}
|
|
74
|
+
catch {
|
|
75
|
+
return null;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.1", ngImport: i0, type: MapboxSearchService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
79
|
+
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.2.1", ngImport: i0, type: MapboxSearchService, providedIn: 'root' }); }
|
|
80
|
+
}
|
|
81
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.1", ngImport: i0, type: MapboxSearchService, decorators: [{
|
|
82
|
+
type: Injectable,
|
|
83
|
+
args: [{ providedIn: 'root' }]
|
|
84
|
+
}] });
|
|
85
|
+
|
|
86
|
+
// No mapbox-gl here: an address field can search without loading the map.
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Generated bundle index. Do not edit.
|
|
90
|
+
*/
|
|
91
|
+
|
|
92
|
+
export { MapboxSearchService };
|
|
93
|
+
//# sourceMappingURL=apexara-map-search.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"apexara-map-search.mjs","sources":["../../../../projects/apexara/map/search/src/mapbox-search.service.ts","../../../../projects/apexara/map/search/public-api.ts","../../../../projects/apexara/map/search/apexara-map-search.ts"],"sourcesContent":["import { isPlatformBrowser } from '@angular/common';\nimport { Injectable, PLATFORM_ID, inject } from '@angular/core';\n\nimport { MAP_CONFIG } from '@apexara/map/config';\nimport {\n MapApiConfig,\n MapSearchResponseUtil,\n type MapSearchApiRetrieveResponse,\n type MapSearchApiSuggestResponse,\n type MapSearchResult,\n} from '@apexara/map/geo';\n\nimport { MapSearchSuggestOptions } from './map-search.types';\n\n/**\n * Mapbox Search Box: `suggest` while the reader types, `retrieve` on a pick, billed per session (the session token\n * rotates after a retrieve). Quiet on failure ([] or null, 5 s timeout). Uses `fetch`, never HttpClient, whose\n * interceptors could send an app's own credentials to api.mapbox.com.\n */\n@Injectable({ providedIn: 'root' })\nexport class MapboxSearchService {\n\n private readonly config = inject(MAP_CONFIG);\n private readonly platformId = inject(PLATFORM_ID);\n private readonly requestTimeoutMs = 5000;\n\n // The billed session `suggest` and `retrieve` share: '' until the next call starts one.\n private sessionToken = '';\n\n /** Whether a search can run: a token is configured and this is a browser. */\n public get isAvailable(): boolean {\n return !!this.config.accessToken && isPlatformBrowser(this.platformId);\n }\n\n /** Suggestions for `query`, with no position yet. [] when unavailable or on any failure. */\n public async suggest(query: string, options?: MapSearchSuggestOptions): Promise<MapSearchResult[]> {\n if (!this.isAvailable) {\n return [];\n }\n\n const response = await this.get<MapSearchApiSuggestResponse>(`${MapApiConfig.SEARCH_BOX_URL}/suggest?${this.suggestParams(query, options)}`);\n const results: MapSearchResult[] = [];\n\n for (const suggestion of response?.suggestions ?? []) {\n if (suggestion.mapbox_id) {\n results.push(MapSearchResponseUtil.resultOf(suggestion));\n }\n }\n\n return results;\n }\n\n /** A suggestion's full record, the only call with a position; it ends the session. Null when unavailable or none. */\n public async retrieve(mapboxId: string): Promise<MapSearchResult | null> {\n if (!this.isAvailable) {\n return null;\n }\n\n const params = new URLSearchParams({ access_token: this.config.accessToken, session_token: this.session() });\n const response = await this.get<MapSearchApiRetrieveResponse>(`${MapApiConfig.SEARCH_BOX_URL}/retrieve/${encodeURIComponent(mapboxId)}?${params}`);\n\n this.sessionToken = '';\n\n const feature = response?.features?.[0];\n\n return feature ? MapSearchResponseUtil.placeOf(mapboxId, feature) : null;\n }\n\n private suggestParams(query: string, options: MapSearchSuggestOptions | undefined): URLSearchParams {\n const params = new URLSearchParams({ q: query, access_token: this.config.accessToken, session_token: this.session() });\n\n if (options?.types !== undefined) {\n params.set('types', options.types);\n }\n\n if (options?.country !== undefined) {\n params.set('country', options.country);\n }\n\n if (options?.limit !== undefined) {\n params.set('limit', `${options.limit}`);\n }\n\n return params;\n }\n\n private session(): string {\n if (!this.sessionToken) {\n this.sessionToken = crypto.randomUUID();\n }\n\n return this.sessionToken;\n }\n\n // Null on an error status, a network failure or the timeout, so a hung api.mapbox.com never holds the caller.\n private async get<T>(url: string): Promise<T | null> {\n try {\n const response = await fetch(url, { signal: AbortSignal.timeout(this.requestTimeoutMs) });\n\n return response.ok ? (await response.json() as T) : null;\n } catch {\n return null;\n }\n }\n\n}\n","// No mapbox-gl here: an address field can search without loading the map.\nexport { MapboxSearchService } from './src/mapbox-search.service';\nexport type { MapSearchSuggestOptions } from './src/map-search.types';\nexport type { MapSearchResult } from '@apexara/map/geo';\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;;;;;AAcA;;;;AAIG;MAEU,mBAAmB,CAAA;AADhC,IAAA,WAAA,GAAA;AAGmB,QAAA,IAAA,CAAA,MAAM,GAAG,MAAM,CAAC,UAAU,CA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