@aws-amplify/geo 1.3.4 → 1.3.6-geo.14
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/CHANGELOG.md +8 -0
- package/dist/aws-amplify-geo.js +185 -48
- package/dist/aws-amplify-geo.js.map +1 -1
- package/dist/aws-amplify-geo.min.js +6 -6
- package/dist/aws-amplify-geo.min.js.map +1 -1
- package/lib/Geo.d.ts +8 -1
- package/lib/Geo.js +48 -20
- package/lib/Geo.js.map +1 -1
- package/lib/Providers/AmazonLocationServiceProvider.d.ts +8 -1
- package/lib/Providers/AmazonLocationServiceProvider.js +93 -28
- package/lib/Providers/AmazonLocationServiceProvider.js.map +1 -1
- package/lib/types/Geo.d.ts +1 -0
- package/lib/types/Provider.d.ts +2 -1
- package/lib-esm/Geo.d.ts +8 -1
- package/lib-esm/Geo.js +48 -20
- package/lib-esm/Geo.js.map +1 -1
- package/lib-esm/Providers/AmazonLocationServiceProvider.d.ts +8 -1
- package/lib-esm/Providers/AmazonLocationServiceProvider.js +94 -29
- package/lib-esm/Providers/AmazonLocationServiceProvider.js.map +1 -1
- package/lib-esm/types/Geo.d.ts +1 -0
- package/lib-esm/types/Provider.d.ts +2 -1
- package/package.json +3 -3
- package/src/Geo.ts +22 -0
- package/src/Providers/AmazonLocationServiceProvider.ts +80 -1
- package/src/types/Geo.ts +3 -0
- package/src/types/Provider.ts +7 -0
|
@@ -19,9 +19,11 @@ import {
|
|
|
19
19
|
} from '@aws-amplify/core';
|
|
20
20
|
import {
|
|
21
21
|
Place as PlaceResult,
|
|
22
|
-
SearchPlaceIndexForTextCommandInput,
|
|
23
22
|
LocationClient,
|
|
24
23
|
SearchPlaceIndexForTextCommand,
|
|
24
|
+
SearchPlaceIndexForTextCommandInput,
|
|
25
|
+
SearchPlaceIndexForSuggestionsCommand,
|
|
26
|
+
SearchPlaceIndexForSuggestionsCommandInput,
|
|
25
27
|
SearchPlaceIndexForPositionCommand,
|
|
26
28
|
SearchPlaceIndexForPositionCommandInput,
|
|
27
29
|
BatchPutGeofenceCommand,
|
|
@@ -45,6 +47,7 @@ import {
|
|
|
45
47
|
GeoConfig,
|
|
46
48
|
SearchByTextOptions,
|
|
47
49
|
SearchByCoordinatesOptions,
|
|
50
|
+
SearchForSuggestionsResults,
|
|
48
51
|
GeoProvider,
|
|
49
52
|
Place,
|
|
50
53
|
AmazonLocationServiceMapStyle,
|
|
@@ -221,6 +224,82 @@ export class AmazonLocationServiceProvider implements GeoProvider {
|
|
|
221
224
|
return results;
|
|
222
225
|
}
|
|
223
226
|
|
|
227
|
+
/**
|
|
228
|
+
* Search for suggestions based on the input text
|
|
229
|
+
* @param {string} text - The text string that is to be searched for
|
|
230
|
+
* @param {SearchByTextOptions} options? - Optional parameters to the search
|
|
231
|
+
* @returns {Promise<SearchForSuggestionsResults>} - Resolves to an array of search suggestion strings
|
|
232
|
+
*/
|
|
233
|
+
|
|
234
|
+
public async searchForSuggestions(
|
|
235
|
+
text: string,
|
|
236
|
+
options?: SearchByTextOptions
|
|
237
|
+
): Promise<SearchForSuggestionsResults> {
|
|
238
|
+
const credentialsOK = await this._ensureCredentials();
|
|
239
|
+
if (!credentialsOK) {
|
|
240
|
+
throw new Error('No credentials');
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
this._verifySearchIndex(options?.searchIndexName);
|
|
244
|
+
|
|
245
|
+
/**
|
|
246
|
+
* Setup the searchInput
|
|
247
|
+
*/
|
|
248
|
+
const locationServiceInput: SearchPlaceIndexForSuggestionsCommandInput = {
|
|
249
|
+
Text: text,
|
|
250
|
+
IndexName: this._config.search_indices.default,
|
|
251
|
+
};
|
|
252
|
+
|
|
253
|
+
/**
|
|
254
|
+
* Map search options to Amazon Location Service input object
|
|
255
|
+
*/
|
|
256
|
+
if (options) {
|
|
257
|
+
locationServiceInput.FilterCountries = options.countries;
|
|
258
|
+
locationServiceInput.MaxResults = options.maxResults;
|
|
259
|
+
|
|
260
|
+
if (options.searchIndexName) {
|
|
261
|
+
locationServiceInput.IndexName = options.searchIndexName;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
if (options['biasPosition'] && options['searchAreaConstraints']) {
|
|
265
|
+
throw new Error(
|
|
266
|
+
'BiasPosition and SearchAreaConstraints are mutually exclusive, please remove one or the other from the options object'
|
|
267
|
+
);
|
|
268
|
+
}
|
|
269
|
+
if (options['biasPosition']) {
|
|
270
|
+
locationServiceInput.BiasPosition = options['biasPosition'];
|
|
271
|
+
}
|
|
272
|
+
if (options['searchAreaConstraints']) {
|
|
273
|
+
locationServiceInput.FilterBBox = options['searchAreaConstraints'];
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
const client = new LocationClient({
|
|
278
|
+
credentials: this._config.credentials,
|
|
279
|
+
region: this._config.region,
|
|
280
|
+
customUserAgent: getAmplifyUserAgent(),
|
|
281
|
+
});
|
|
282
|
+
const command = new SearchPlaceIndexForSuggestionsCommand(
|
|
283
|
+
locationServiceInput
|
|
284
|
+
);
|
|
285
|
+
|
|
286
|
+
let response;
|
|
287
|
+
try {
|
|
288
|
+
response = await client.send(command);
|
|
289
|
+
} catch (error) {
|
|
290
|
+
logger.debug(error);
|
|
291
|
+
throw error;
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
/**
|
|
295
|
+
* The response from Amazon Location Service is a "Results" array of objects with a single `Text` item.
|
|
296
|
+
* Here we want to flatten that to an array of just the strings from those `Text` items.
|
|
297
|
+
*/
|
|
298
|
+
const results = response.Results.map(result => result.Text);
|
|
299
|
+
|
|
300
|
+
return results;
|
|
301
|
+
}
|
|
302
|
+
|
|
224
303
|
/**
|
|
225
304
|
* Reverse geocoding search via a coordinate point on the map
|
|
226
305
|
* @param coordinates - Coordinates array for the search input
|
package/src/types/Geo.ts
CHANGED
|
@@ -84,6 +84,9 @@ export type SearchByCoordinatesOptions = {
|
|
|
84
84
|
providerName?: string;
|
|
85
85
|
};
|
|
86
86
|
|
|
87
|
+
// Return type for searchForSuggestions
|
|
88
|
+
export type SearchForSuggestionsResults = string[];
|
|
89
|
+
|
|
87
90
|
// Geometry object for Place points
|
|
88
91
|
export type PlaceGeometry = {
|
|
89
92
|
point: Coordinates;
|
package/src/types/Provider.ts
CHANGED
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
import {
|
|
14
14
|
SearchByTextOptions,
|
|
15
15
|
SearchByCoordinatesOptions,
|
|
16
|
+
SearchForSuggestionsResults,
|
|
16
17
|
Coordinates,
|
|
17
18
|
Place,
|
|
18
19
|
MapStyle,
|
|
@@ -51,6 +52,12 @@ export interface GeoProvider {
|
|
|
51
52
|
options?: SearchByCoordinatesOptions
|
|
52
53
|
): Promise<Place>;
|
|
53
54
|
|
|
55
|
+
// search for suggestions based on a text string
|
|
56
|
+
searchForSuggestions(
|
|
57
|
+
text: string,
|
|
58
|
+
options?: SearchByTextOptions
|
|
59
|
+
): Promise<SearchForSuggestionsResults>;
|
|
60
|
+
|
|
54
61
|
// create geofences
|
|
55
62
|
saveGeofences(
|
|
56
63
|
geofences: GeofenceInput[],
|