Giter VIP home page Giter VIP logo

js-polyline-codec's Introduction

Google Maps JavaScript Polyline Encoding

npm Build Release codecov GitHub contributors semantic-release

Description

Encode and decode polyines in Nodejs or the browser using this package.

Polyline encoding is a lossy compression algorithm that allows you to store a series of coordinates as a single string. Point coordinates are encoded using signed values.

Read more at https://developers.google.com/maps/documentation/utilities/polylinealgorithm.

Install

Available via npm as the package @googlemaps/polyline-codec.

npm i @googlemaps/polyline-codec

Documentation

The reference documentation can be found at this link.

Example

import { decode, encode } from "@googlemaps/polyline-codec";

const encoded = "_p~iF~ps|U_ulLnnqC_mqNvxq`@";
console.log(decode(encoded, 5));
// [
//   [38.5, -120.2],
//   [40.7, -120.95],
//   [43.252, -126.453],
// ]

const path = [
  [38.5, -120.2],
  [40.7, -120.95],
  [43.252, -126.453],
];
console.log(encode(path, 5));
// "_p~iF~ps|U_ulLnnqC_mqNvxq`@"

js-polyline-codec's People

Contributors

debkanchan avatar dependabot[bot] avatar googlemaps-bot avatar jpoehnelt avatar semantic-release-bot avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

js-polyline-codec's Issues

Issue with source maps

Environment details

OS: MacOS
Node: v14.17.0
Version: 1.0.16

Issue

I use js-polyline-codec with create-react-app, and currently I'm getting a warning:

WARNING in ./node_modules/@googlemaps/polyline-codec/dist/index.esm.js
Module Warning (from ./node_modules/source-map-loader/dist/cjs.js):
Failed to parse source map from '/Users/stiaje/Projects/admin/node_modules/@googlemaps/polyline-codec/src/index.ts' file: Error: ENOENT: no such file or directory, open '/Users/stiaje/Projects/admin/node_modules/@googlemaps/polyline-codec/src/index.ts'

Looks like the published index.esm.js.map contains a reference the src/index.ts, which is not part of the published files.

Maybe the sourcemap should not be published, or it should be corrected to only reference available files.

Make LatLngTuple a Tuple instead of an Array

Is your feature request related to a problem? Please describe.
LatLngTuple is an alias for number[] which can have n number of values in it instead of being [number, number] tuple with only 2 numbers. Hence it can be used with ... spread operator but cannot be used in places where only 2 positional values of Lat and Long are required.

Example:
Using it with firestore GeoPoint like this

class GeoPoint {
//...
constructor(latitude: number, longitude: number);
//...


const location: LatLngTuple = [0, 0];
new GeoPoint(...location); //invalid

will cause the following error
error TS2556: A spread argument must either have a tuple type or be passed to a rest parameter

Describe the solution you'd like
Make LatLngTuple a proper [number: number] tuple and in encode function let the union type be (number[] | LatLng | LatLngTuple) to keep the fliexibility

Describe alternatives you've considered

const location: LatLngTuple = [0, 0];
new GeoPoint(location[0], location[1]);

Can we have a selection choice for setEditable regarding adding new vertices or try to disabled it

Thanks for stopping by to let us know something could be better!


PLEASE READ

If you have a support contract with Google, please create an issue in the support console. This will ensure a timely response.

Discover additional support services for the Google Maps Platform, including developer communities, technical guidance, and expert support at the Google Maps Platform support resources page.

If your bug or feature request is not related to this particular library, please visit the Google Maps Platform issue trackers.

Check for answers on StackOverflow with the google-maps tag.


Is your feature request related to a problem? Please describe.
I have a problem regarding polygon API whenever I tried to use setEditable method. since when we try to use this method especially for polygon area marker, the library will give a solution to edit any predefined vertex and automatically show a transparent vertex in the middle of the line between each vertex which is good, but I have stumbled at some of condition where user can only edit a predefined vertex without add any new vertex from any transparent vertex, currently I can use roundabout ways to not store any new vertex and stick to the predefined vertex that I got from our API response, but User experience itself is not good since I can't hide the transparent vertex and user can still add vertex but will not be store to our database, that's why if possible can you add any choice if we want to edit our marker but leave out options to add any new vertex in between the line of each vertex that connected?

image

Describe the solution you'd like
maybe some params like this would be nice:
setEditable({ editable: true, options: { addNewVertex: false, resizeVertex: true, rotateVertext: true } })

while editable itself from the current polygon params so if we want to have editable feature we set it to true and if not we can set it to false, meanwhile options in here have several feature that can help to customize the polygon area or polyline that we already create. addNewVertex: Boolean will give us choice if we want to have editable transparent vertex in the middle of each vertex or not like the image above, resizeVertex: true can help user to edit our polygon with scale approach for example to keep the ratio of the original polygon when we move or click the vertex and drag it to upscale the polygon area, and rotateVertex: Boolean will help the user to get a shorthand to rotate our predefined vertex without developer need to calculate it manually every time we want to rotate our polygon area

Describe alternatives you've considered
for now I use roundabout way to not store any new vertex that user add after click and drag the transparent vertex and only store the predefined value that we got from API response, but with this approach, the user experience will not be good since we got a lot of question as why the system give a new transparent vertex but cannot be add after save

Additional context
image

encode Z Dimension

I seen that this library in encoding skipping the third dimension if present in the coordinates. [lon, lat, z]
is it possible to somehow include it in encoding?

The automated release is failing 🚨

🚨 The automated release from the main branch failed. 🚨

I recommend you give this issue a high priority, so other packages depending on you could benefit from your bug fixes and new features.

You can find below the list of errors reported by semantic-release. Each one of them has to be resolved in order to automatically publish your package. I’m sure you can resolve this πŸ’ͺ.

Errors are usually caused by a misconfiguration or an authentication problem. With each error reported below you will find explanation and guidance to help you to resolve it.

Once all the errors are resolved, semantic-release will release your package the next time you push a commit to the main branch. You can also manually restart the failed CI job that runs semantic-release.

If you are not sure how to resolve this, here is some links that can help you:

If those don’t help, or if this issue is reporting something you think isn’t right, you can always ask the humans behind semantic-release.


No npm token specified.

An npm token must be created and set in the NPM_TOKEN environment variable on your CI environment.

Please make sure to create an npm token and to set it in the NPM_TOKEN environment variable on your CI environment. The token must allow to publish to the registry https://wombat-dressing-room.appspot.com.


Good luck with your project ✨

Your semantic-release bot πŸ“¦πŸš€

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.