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

Fixed up for packaging and added Swift demo app. #12

Merged
merged 2 commits into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
129 changes: 18 additions & 111 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,127 +1,34 @@
# @aws-geospatial/polyline
# @aws/polyline

This library is used to simplify the process of using compressed geometry with [maplibre-gl-js](https://github.com/maplibre/maplibre-gl-js) in JavaScript Applications.
This library simplifies the process of using compressed geometry with [maplibre-gl-js](https://github.com/maplibre/maplibre-gl-js) in JavaScript applications
and with [maplibre-native](https://github.com/maplibre/maplibre-native) in Kotlin and Swift applications.

Location-based service providers sometimes use variations of the [Encoded Polyline Algorithm Format](https://developers.google.com/maps/documentation/utilities/polylinealgorithm)
to reduce the response size for APIs that return potentially large arrays of coordinates, such as routing and isoline APIs.
to reduce the response size for APIs that can return large arrays of coordinates, such as routing and isoline APIs.
The utility methods in this library compresses the data and decompresses into GeoJSON that can be directly rendered in MapLibre.

## Installation

Install this library from NPM for usage with modules:

```console
npm install @aws-geospatial/polyline
```

You can also import the Javascript file for usage directly in the browser.

```html
<script src="https://www.unpkg.com/@aws-geospatial/polyline/dist/polyline.js"></script>
```

## Usage

Import the library and call the utility functions in the top-level namespace as needed.
You can find more details about these functions in the [Documentation](#documentation) section.

### Usage with Modules

```javascript
import { decodeToLineStringFeature } from "@aws-geospatial/polyline";

var decodedGeoJSON = decodeToLineStringFeature(response.EncodedPolyline);
map.addLayer({
id: "route",
type: "line",
source: {
type: "geojson",
data: decodedGeoJSON,
},
layout: {
"line-join": "round",
"line-cap": "round",
},
paint: {
"line-color": "#3887be",
"line-width": 5,
"line-opacity": 0.75,
},
});
```

### Usage with a browser

```html
<!-- Import the Maplibre Polyline library -->
<script src="https://www.unpkg.com/@aws-geospatial/polyline"></script>
```

```javascript
var decodedGeoJSON = polyline.decodeToLineStringFeature(
response.EncodedPolyline,
);
map.addLayer({
id: "route",
type: "line",
source: {
type: "geojson",
data: decodedGeoJSON,
},
layout: {
"line-join": "round",
"line-cap": "round",
},
paint: {
"line-color": "#3887be",
"line-width": 5,
"line-opacity": 0.75,
},
});
```

## Documentation

Detailed documentation can be found under `/docs/index.html` after generating it by running:

```console
npm run typedoc
```

### encodeFromLngLatArray

This encodes an array of coordinates in longitude, latitude order into compressed polyline data.
While this isn't needed for MapLibre rendering, you might need it to compress data for a request
to a Location Service Provider when requesting route-related data.

### decodeToLineStringFeature

This is the most common method to use. It decodes compressed polyline data into a GeoJSON
Feature containing a LineString that can directly be used as a MapLibre source for rendering.

### decodeToPolygonFeature

Similar to `decodeToLineStringFeature` it decodes an array of compressed polyline rings into a GeoJSON
Feature containing a Polygon that can directly be used as a MapLibre source for rendering.
This should be used when the compressed data is meant to represent polygon rings, as it will
also generate the correct winding order of the rings for use with GeoJSON.
Documentation for each supported language can be found here:
* [JavaScript](./javascript/README.md)
* [Kotlin](./kotlin/README.md)
* [Swift](./swift/README.md)

### decodeToLineString
## Security

This decodes a compressed polyline into a GeoJSON LineString. This can't directly be used
as a MapLibre source for rendering, but it is useful when trying to work directly with LineString
data.
See [CONTRIBUTING](CONTRIBUTING.md#security-issue-notifications) for more information.

### decodeToPolygon
## Getting Help

This decodes an array of compressed polyline rings into a GeoJSON Polygon. This can't directly be used
as a MapLibre source for rendering, but it is useful when trying to work directly with Polygon
data.
The best way to interact with our team is through GitHub.
You can [open an issue](https://github.com/aws-geospatial/polyline/issues/new/choose) and choose from one of our templates for
[bug reports](https://github.com/aws-geospatial/polyline/issues/new?assignees=&labels=bug%2C+needs-triage&template=---bug-report.md&title=) or
[feature requests](https://github.com/aws-geospatial/polyline/issues/new?assignees=&labels=feature-request&template=---feature-request.md&title=).
If you have a support plan with [AWS Support](https://aws.amazon.com/premiumsupport/), you can also create a new support case.

### decodeToLngLatArray
## Contributing

This decodes compressed polyline data into an array of coordinates in longitude, latitude order.
This method is helpful when you need to directly work with the coordinate data.
We welcome community contributions and pull requests. See [CONTRIBUTING.md](https://github.com/aws-geospatial/amazon-location-mobile-auth-sdk-android/blob/master/CONTRIBUTING.md) for information on how to set up a development environment and submit code.

mbalfour-amzn marked this conversation as resolved.
Show resolved Hide resolved
## License

Expand Down
5 changes: 5 additions & 0 deletions javascript/CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
## Code of Conduct

This project has adopted the [Amazon Open Source Code of Conduct](https://aws.github.io/code-of-conduct).
For more information see the [Code of Conduct FAQ](https://aws.github.io/code-of-conduct-faq) or contact
[email protected] with any additional questions or comments.
57 changes: 57 additions & 0 deletions javascript/CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Contributing Guidelines

Thank you for your interest in contributing to our project. Whether it's a bug report, new feature, correction, or additional
documentation, we greatly value feedback and contributions from our community.

Please read through this document before submitting any issues or pull requests to ensure we have all the necessary
information to effectively respond to your bug report or contribution.

## Reporting Bugs/Feature Requests

We welcome you to use the GitHub issue tracker to report bugs or suggest features.

When filing an issue, please check existing open, or recently closed, issues to make sure somebody else hasn't already
reported the issue. Please try to include as much information as you can. Details like these are incredibly useful:

- A reproducible test case or series of steps
- The version of our code being used
- Any modifications you've made relevant to the bug
- Anything unusual about your environment or deployment

## Contributing via Pull Requests

Contributions via pull requests are much appreciated. Before sending us a pull request, please ensure that:

1. You are working against the latest source on the _main_ branch.
2. You check existing open, and recently merged, pull requests to make sure someone else hasn't addressed the problem already.
3. You open an issue to discuss any significant work - we would hate for your time to be wasted.

To send us a pull request, please:

1. Fork the repository.
2. Modify the source; please focus on the specific change you are contributing. If you also reformat all the code, it will be hard for us to focus on your change.
3. Ensure local tests pass.
4. Commit to your fork using clear commit messages.
5. Send us a pull request, answering any default questions in the pull request interface.
6. Pay attention to any automated CI failures reported in the pull request, and stay involved in the conversation.

GitHub provides additional document on [forking a repository](https://help.github.com/articles/fork-a-repo/) and
[creating a pull request](https://help.github.com/articles/creating-a-pull-request/).

## Finding contributions to work on

Looking at the existing issues is a great way to find something to contribute on. As our projects, by default, use the default GitHub issue labels (enhancement/bug/duplicate/help wanted/invalid/question/wontfix), looking at any 'help wanted' issues is a great place to start.

## Code of Conduct

This project has adopted the [Amazon Open Source Code of Conduct](https://aws.github.io/code-of-conduct).
For more information see the [Code of Conduct FAQ](https://aws.github.io/code-of-conduct-faq) or contact
[email protected] with any additional questions or comments.

## Security issue notifications

If you discover a potential security issue in this project we ask that you notify AWS/Amazon Security via our [vulnerability reporting page](http://aws.amazon.com/security/vulnerability-reporting/). Please do **not** create a public github issue.

## Licensing

See the [LICENSE](LICENSE) file for our project's licensing. We will ask you to confirm the licensing of your contribution.
17 changes: 17 additions & 0 deletions javascript/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
MIT No Attribution

Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Loading
Loading