Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for standalone Places, Routes SDKs #40

Merged
merged 34 commits into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
302db92
Bump micromatch from 4.0.5 to 4.0.8
dependabot[bot] Sep 11, 2024
c839d41
Merge pull request #1 from aws-geospatial/dependabot/npm_and_yarn/mic…
cgalvan Sep 11, 2024
f2762d5
Bump fast-xml-parser and @aws-sdk/client-location
dependabot[bot] Sep 11, 2024
0551edf
Merge pull request #2 from aws-geospatial/dependabot/npm_and_yarn/mul…
juaneslucero Sep 11, 2024
e316a63
Added V2 Place API support to place-converter.
mbalfour-amzn Sep 18, 2024
1480b3e
Merge remote-tracking branch 'staging/main' into mbalfour/v2-support
mbalfour-amzn Sep 18, 2024
7813f98
Removed unused import.
mbalfour-amzn Sep 19, 2024
db56b30
Removed partialFlattenList.
mbalfour-amzn Sep 20, 2024
63cc9e0
Moved GeoPlaces APIs into separate files and APIs.
mbalfour-amzn Sep 20, 2024
954f606
Merge pull request #3 from aws-geospatial/mbalfour/v2-support
mbalfour-amzn Sep 24, 2024
50c31fe
Bump rollup from 3.22.0 to 3.29.5
dependabot[bot] Sep 24, 2024
9fe5160
Fixed id handling to be more MapLibre-friendly.
mbalfour-amzn Sep 24, 2024
31e2144
Merge pull request #4 from aws-geospatial/dependabot/npm_and_yarn/rol…
mbalfour-amzn Sep 24, 2024
62e2004
Merge pull request #5 from aws-geospatial/mbalfour/v2-support
mbalfour-amzn Sep 25, 2024
87c3f8f
Adds converter for V2 CalculateRoutesResponse.
mbalfour-amzn Sep 26, 2024
4cf31be
Updated to the newest geoplaces-client.
mbalfour-amzn Sep 26, 2024
c86555a
Fixed PR feedback.
mbalfour-amzn Sep 27, 2024
fb7ca55
Merge pull request #6 from aws-geospatial/mbalfour/v2-support
mbalfour-amzn Sep 30, 2024
c15deb4
Fixed some README method name typos
cgalvan Oct 10, 2024
40cbb6c
Merge pull request #8 from cgalvan/WHATNEXT
cgalvan Oct 10, 2024
604ae5d
Added remaining V2 API support (#7)
mbalfour-amzn Oct 17, 2024
ef4a60e
Specify browser artifacts
mojodna Oct 25, 2024
b4b2235
Simplify unpkg URLs
mojodna Oct 25, 2024
ced7560
Switch to jsdelivr
mojodna Oct 25, 2024
efc2d82
Merge pull request #9 from aws-geospatial/browser-artifacts
mojodna Oct 25, 2024
65a559a
Update to the latest clients (#10)
mojodna Oct 26, 2024
9546c0f
Switched to public polyline release (#11)
mbalfour-amzn Oct 29, 2024
e129961
Use new public packages.
mbalfour-amzn Oct 30, 2024
0bbb533
Merge pull request #12 from aws-geospatial/mbalfour/use-public-packages
mbalfour-amzn Oct 30, 2024
25fa181
Bump rollup from 3.22.0 to 3.29.5
dependabot[bot] Sep 26, 2024
cbee68e
Fixed package-lock merge conflict.
mbalfour-amzn Oct 30, 2024
a6e46ac
Deleted package-lock.json temporarily.
mbalfour-amzn Oct 30, 2024
944299b
Merge branch 'main' into staging_changes
mbalfour-amzn Oct 30, 2024
e1d5f7a
Fixed up package-lock.json again
mbalfour-amzn Oct 30, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# 1.1.0

### ✨ Features and improvements

- Added support for new standalone Places and Routes SDKs
187 changes: 181 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ npm install @aws/amazon-location-utilities-datatypes
Importing in an HTML file for usage directly in the browser.

```html
<script src="https://www.unpkg.com/@aws/amazon-location-utilities-datatypes@1.x/dist/amazonLocationDataConverter.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@aws/amazon-location-utilities-datatypes@1"></script>
```

# Usage
Expand Down Expand Up @@ -48,10 +48,10 @@ This example uses the Amazon Location Client. The Amazon Location Client is base
Utility functions will be within `amazonLocationDataConverter`.

```html
<!-- Importing Amazon Location Client -->
<script src="https://www.unpkg.com/@aws/amazon-location-client@1.x/dist/amazonLocationClient.js"></script>
<!-- Importing the utility library from an HTML file -->
<script src="https://www.unpkg.com/@aws/amazon-location-utilities-datatypes@1.x/dist/amazonLocationDataConverter.js"></script>
<!-- Import the Amazon Location Client -->
<script src="https://cdn.jsdelivr.net/npm/@aws/amazon-location-client@1"></script>
<!-- Import the utility library -->
<script src="https://cdn.jsdelivr.net/npm/@aws/amazon-location-utilities-datatypes@1"></script>
```

```javascript
Expand Down Expand Up @@ -145,11 +145,184 @@ const featureCollection = routeToFeatureCollection(response)

```javascript
const response = { ... };
const featureCollection = placeToFeatureCollection(response, {
const featureCollection = routeToFeatureCollection(response, {
flattenProperties: true
});
```

## Amazon Location GeoPlaces Data Types to GeoJSON

### geocodeResponseToFeatureCollection

Converts a Geocode response from the standalone Places SDK to a FeatureCollection with Point
Features. Only result items with location information will appear in the FeatureCollection.
The `flattenProperties` option will flatten the nested response data into a flat properties list.
This option is enabled by default, as it makes the data easier to use from within MapLibre expressions.

```javascript
const response = { ... };
const featureCollection = geocodeResponseToFeatureCollection(response)
```

### getPlaceResponseToFeatureCollection

Converts a GetPlace response from the standalone Places SDK to a FeatureCollection with a Point
Feature. If the response has no location information, an empty FeatureCollection will be returned.
The `flattenProperties` option will flatten the nested response data into a flat properties list.
This option is enabled by default, as it makes the data easier to use from within MapLibre expressions.

```javascript
const response = { ... };
const featureCollection = getPlaceResponseToFeatureCollection(response)
```

### reverseGeocodeResponseToFeatureCollection

Converts a ReverseGeocode response from the standalone Places SDK to a FeatureCollection with Point
Features. Only result items with location information will appear in the FeatureCollection.
The `flattenProperties` option will flatten the nested response data into a flat properties list.
This option is enabled by default, as it makes the data easier to use from within MapLibre expressions.

```javascript
const response = { ... };
const featureCollection = reverseGeocodeResponseToFeatureCollection(response)
```

### searchNearbyResponseToFeatureCollection

Converts a SearchNearby response from the standalone Places SDK to a FeatureCollection with Point
Features. Only result items with location information will appear in the FeatureCollection.
The `flattenProperties` option will flatten the nested response data into a flat properties list.
This option is enabled by default, as it makes the data easier to use from within MapLibre expressions.

```javascript
const response = { ... };
const featureCollection = searchNearbyResponseToFeatureCollection(response)
```

### searchTextResponseToFeatureCollection

Converts a SearchText response from the standalone Places SDK to a FeatureCollection with Point
Features. Only result items with location information will appear in the FeatureCollection.
The `flattenProperties` option will flatten the nested response data into a flat properties list.
This option is enabled by default, as it makes the data easier to use from within MapLibre expressions.

```javascript
const response = { ... };
const featureCollection = searchTextResponseToFeatureCollection(response)
```

### suggestResponseToFeatureCollection

Converts a Suggest response from the standalone Places SDK to a FeatureCollection with Point
Features. Only result items with location information will appear in the FeatureCollection.
The `flattenProperties` option will flatten the nested response data into a flat properties list.
This option is enabled by default, as it makes the data easier to use from within MapLibre expressions.

```javascript
const response = { ... };
const featureCollection = suggestResponseToFeatureCollection(response)
```

## Amazon Location GeoRoutes Data Types to GeoJSON

### calculateRoutesResponseToFeatureCollection

This converts a CalculateRoutesResponse from the standalone Routes SDK to an array of GeoJSON FeatureCollections, one for each route in the
response. Route responses contain multiple different types of geometry in the response, so the conversion is
configurable to choose which features should be in the resulting GeoJSON. Each GeoJSON Feature contains properties
from that portion of the response along with any child arrays/structures. It will not contain properties from any
parent structures. So for example, with Route->Leg->TravelSteps, a converted Leg feature will contain properties for
everything on Leg and everything in TravelSteps, but it won't contain any properties from Route.

Each Feature contains a `FeatureType` property that can be used to distinguish between the types of features if
multiple are requested during the conversion:

- `Leg`: A travel leg of the route. (LineString)
- `Span`: A span within a travel leg. (LineString)
- `TravelStepGeometry`: A travel step line within a travel leg. (LineString)
- `TravelStepStartPosition`: The start position of a travel step within a travel leg. (Point)
- `Arrival`: The arrival position of a travel leg. (Point)
- `Departure`: The departure position of a travel leg. (Point)

Each FeatureCollection may contain a mixture of LineString and Point features, depending on the conversion options
provided.

Any feature that is missing its geometry in the response or has invalid geometry will throw an Error().

The API optionally accepts the following conversion flags:

- `flattenProperties`: flatten nested properties in the response (default: true)
- `includeLegs`: include the Leg features (default: true)
- `includeSpans`: include the Span features (default: false)
- `includeTravelStepGeometry`: include the TravelStepGeometry features (default: false)
- `includeTravelStepStartPositions`: include the TravelStepStartPosition features (default: false)
- `includeLegArrivalDeparturePositions`: include the Arrival and Departure features (default: false)

```javascript
const response = { ... };
const featureCollections = calculateRoutesResponseToFeatureCollections(response)
```

### calculateIsolinesResponseToFeatureCollection

This converts a CalculateIsolineResponse from the standalone Routes SDK to a GeoJSON FeatureCollection which contains one Feature for each isoline
in the response. Isolines can contain both polygons for isoline regions and lines for connectors between regions
(such as ferry travel), so each Feature is a GeometryCollection that can contain a mix of Polygons and LineStrings.
The `flattenProperties` option will flatten the nested response data into a flat properties list.
This option is enabled by default, as it makes the data easier to use from within MapLibre expressions.

Any feature that is missing its geometry in the response or has invalid geometry will throw an Error().

```javascript
const response = { ... };
const featureCollection = calculateIsolinesResponseToFeatureCollection(response)
```

### optimizeWaypointsResponseToFeatureCollection

This converts an OptimizeWaypointsResponse from the standalone Routes SDK to a GeoJSON FeatureCollection which contains one Feature for each
waypoint in the response. The response can contain either impeding waypoints or optimized waypoints.
The `flattenProperties` option will flatten the nested response data into a flat properties list.
This option is enabled by default, as it makes the data easier to use from within MapLibre expressions.

Each Feature contains a `FeatureType` property that can be used to distinguish between the types of features:

- `ImpedingWaypoint`: A waypoint that impedes the optimization request.
- `OptimizedWaypoint`: An optimized waypoint in a successful optimization request.

```javascript
const response = { ... };
const featureCollection = optimizeWaypointsResponseToFeatureCollection(response)
```

### snapToRoadsResponseToFeatureCollection

This converts a SnapToRoadsResponse from the standalone Routes SDK to a GeoJSON FeatureCollection. The FeatureCollection may optionally contain any
combination of the snapped route geometry, the original trace points, the snapped trace points, and lines that
connect the original trace points to their snapped trace points.

Each Feature contains a `FeatureType` property that can be used to distinguish between the types of features if
multiple are requested during the conversion:

- `SnappedGeometry`: The snapped route geometry. (LineString)
- `SnappedTracePointOriginalPosition`: The original submitted trace point. (Point)
- `SnappedTracePointSnappedPosition`: The snapped trace point. (Point)
- `OriginalToSnappedPositionLine`: A line from the original trace point to the corresponding snapped trace point. (LineString)

The API optionally accepts the following conversion flags:

- `flattenProperties`: flatten nested properties in the response (default: true)
- `includeSnappedGeometry`: include the snapped route geometry features (default: true)
- `includeSnappedTracePointOriginalPositions`: include the original trace point features (default: false)
- `includeSnappedTracePointSnappedPositions`: include the snapped trace point features (default: false)
- `includeOriginalToSnappedPositionLines`: include the trace point connector line features (default: false)

```javascript
const response = { ... };
const featureCollection = snapToRoadsResponseToFeatureCollection(response)
```

## Error Handling

If the data provided to the utility functions are invalid, the entries in the data will be skipped.
Expand All @@ -159,6 +332,8 @@ Examples:
- A FeatureCollection containing a Feature of a non-polygon type when calling `featureCollectionToGeofence` will result in a set of geofence entries that do not contain that Feature.
- An input to `devicePositionsToFeatureCollection` with an device position entry that does not contain the coordinates of the device will result in a FeatureCollection with that device position entry skipped.

The GeoRoutes converters will additionally throw an Error() if the geometry in the passed-in response is invalid.

# Getting Help

The best way to interact with our team is through GitHub.
Expand Down
Loading
Loading