├── .releaserc ├── .eslintignore ├── .github ├── bundlewatch.config.json ├── CODEOWNERS ├── dependabot.yml ├── workflows │ ├── package.yml │ ├── test.yml │ ├── dependabot.yml │ ├── bundlewatch.yml │ ├── docs.yml │ ├── release.yml │ └── codeql.yml └── sync-repo-settings.yaml ├── .babelrc ├── tsconfig.json ├── SECURITY.md ├── jest.config.js ├── typedoc.js ├── CONTRIBUTING.md ├── src ├── __snapshots__ │ └── index.test.ts.snap ├── index.test.ts └── index.ts ├── .eslintrc.json ├── package.json ├── README.md ├── rollup.config.js ├── .gitignore └── LICENSE /.releaserc: -------------------------------------------------------------------------------- 1 | extends: "@googlemaps/semantic-release-config" 2 | -------------------------------------------------------------------------------- /.eslintignore: -------------------------------------------------------------------------------- 1 | bazel-* 2 | coverage/ 3 | dist/ 4 | docs/ 5 | lib/ 6 | node_modules/ 7 | public/ -------------------------------------------------------------------------------- /.github/bundlewatch.config.json: -------------------------------------------------------------------------------- 1 | { 2 | "files": [ 3 | { 4 | "path": "dist/index.*.js" 5 | } 6 | ], 7 | "ci": { 8 | "trackBranches": ["main"], 9 | "repoBranchBase": "main" 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": [ 3 | [ 4 | "@babel/env", 5 | { 6 | "targets": { 7 | "browsers": "ie>=11, > 0.25%, not dead" 8 | }, 9 | "corejs": "3.6", 10 | "useBuiltIns": "usage" 11 | } 12 | ] 13 | ] 14 | } 15 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "declaration": true, 4 | "declarationDir": "./dist", 5 | "noImplicitAny": true, 6 | "outDir": "./dist", 7 | "sourceMap": true, 8 | "esModuleInterop": true, 9 | "lib": ["ESNext", "DOM"] 10 | }, 11 | "include": ["src/**/*"], 12 | "exclude": ["**/*.test.ts", "node_modules"] 13 | } 14 | -------------------------------------------------------------------------------- /SECURITY.md: -------------------------------------------------------------------------------- 1 | # Report a security issue 2 | 3 | To report a security issue, please use https://g.co/vulnz. We use 4 | https://g.co/vulnz for our intake, and do coordination and disclosure here on 5 | GitHub (including using GitHub Security Advisory). The Google Security Team will 6 | respond within 5 working days of your report on g.co/vulnz. 7 | 8 | To contact us about other bugs, please open an issue on GitHub. 9 | 10 | > **Note**: This file is synchronized from the https://github.com/googlemaps/.github repository. 11 | -------------------------------------------------------------------------------- /.github/CODEOWNERS: -------------------------------------------------------------------------------- 1 | # Copyright 2021 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | # https://help.github.com/en/github/creating-cloning-and-archiving-repositories/about-code-owners 16 | 17 | .github/ @googlemaps/admin 18 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | # Copyright 2021 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | version: 2 16 | updates: 17 | - package-ecosystem: "npm" 18 | directory: "/" 19 | schedule: 20 | interval: "weekly" 21 | -------------------------------------------------------------------------------- /jest.config.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2020 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | module.exports = { 18 | transform: { 19 | "^.+\\.tsx?$": "ts-jest", 20 | }, 21 | collectCoverage: true, 22 | testPathIgnorePatterns: ["/dist/"], 23 | }; 24 | -------------------------------------------------------------------------------- /typedoc.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2020 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | module.exports = { 18 | out: "docs", 19 | exclude: ["**/node_modules/**", "**/*.spec.ts", "**/*.test.ts"], 20 | name: "", 21 | excludePrivate: true, 22 | excludeExternals: true, 23 | }; 24 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # How to become a contributor and submit your own code 2 | 3 | 1. Submit an issue describing your proposed change to the repo in question. 4 | 1. The repo owner will respond to your issue promptly. 5 | 1. Fork the desired repo, develop and test your code changes. 6 | 1. Ensure that your code adheres to the existing style in the code to which 7 | you are contributing. 8 | 1. Ensure that your code has an appropriate set of tests which all pass. 9 | 1. Title your pull request following [Conventional Commits](https://www.conventionalcommits.org/) styling. 10 | 1. Submit a pull request. 11 | 12 | ## Running the tests 13 | 14 | 1. Install dependencies: 15 | 16 | npm i 17 | 18 | 1. Run lint 19 | 20 | npm run lint 21 | npm run format # will fix some issues 22 | 23 | 1. Run the tests: 24 | 25 | # Run unit tests. 26 | npm test 27 | -------------------------------------------------------------------------------- /.github/workflows/package.yml: -------------------------------------------------------------------------------- 1 | # Copyright 2021 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | name: Package 16 | on: 17 | - push 18 | - pull_request 19 | jobs: 20 | package: 21 | runs-on: ubuntu-latest 22 | steps: 23 | - uses: actions/checkout@v2 24 | - run: npm i 25 | - uses: jpoehnelt/verify-npm-files-action@main 26 | with: 27 | keys: | 28 | types 29 | main 30 | module 31 | -------------------------------------------------------------------------------- /.github/workflows/test.yml: -------------------------------------------------------------------------------- 1 | # Copyright 2021 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | name: Test 16 | on: [push, pull_request] 17 | jobs: 18 | test: 19 | runs-on: ubuntu-latest 20 | steps: 21 | - uses: actions/checkout@v2 22 | - uses: actions/cache@v2 23 | with: 24 | path: ~/.npm 25 | key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} 26 | restore-keys: | 27 | ${{ runner.os }}-node- 28 | - run: npm i 29 | - run: npm run lint 30 | - run: npm test 31 | - uses: codecov/codecov-action@v1 32 | -------------------------------------------------------------------------------- /.github/workflows/dependabot.yml: -------------------------------------------------------------------------------- 1 | # Copyright 2022 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | name: Dependabot 16 | on: pull_request 17 | 18 | permissions: 19 | contents: write 20 | 21 | jobs: 22 | dependabot: 23 | runs-on: ubuntu-latest 24 | if: ${{ github.actor == 'dependabot[bot]' }} 25 | env: 26 | PR_URL: ${{github.event.pull_request.html_url}} 27 | GITHUB_TOKEN: ${{secrets.SYNCED_GITHUB_TOKEN_REPO}} 28 | steps: 29 | - name: approve 30 | run: gh pr review --approve "$PR_URL" 31 | - name: merge 32 | run: gh pr merge --auto --squash --delete-branch "$PR_URL" 33 | -------------------------------------------------------------------------------- /src/__snapshots__/index.test.ts.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`roundtrip roundrip 1`] = ` 4 | Array [ 5 | Array [ 6 | 53.48932, 7 | -104.16777, 8 | ], 9 | Array [ 10 | 53.49014, 11 | -104.16833, 12 | ], 13 | Array [ 14 | 53.4907, 15 | -104.16936, 16 | ], 17 | Array [ 18 | 53.49065, 19 | -104.17142, 20 | ], 21 | Array [ 22 | 53.49011, 23 | -104.17288, 24 | ], 25 | Array [ 26 | 53.48876, 27 | -104.17305, 28 | ], 29 | Array [ 30 | 53.48715, 31 | -104.17219, 32 | ], 33 | Array [ 34 | 53.48542, 35 | -104.17022, 36 | ], 37 | Array [ 38 | 53.48345, 39 | -104.1679, 40 | ], 41 | Array [ 42 | 53.48554, 43 | -104.16442, 44 | ], 45 | Array [ 46 | 53.4871, 47 | -104.16279, 48 | ], 49 | Array [ 50 | 53.48863, 51 | -104.16236, 52 | ], 53 | Array [ 54 | 53.49004, 55 | -104.16249, 56 | ], 57 | Array [ 58 | 53.49055, 59 | -104.16361, 60 | ], 61 | Array [ 62 | 53.49083, 63 | -104.16477, 64 | ], 65 | Array [ 66 | 53.49045, 67 | -104.16648, 68 | ], 69 | Array [ 70 | 53.48935, 71 | -104.16773, 72 | ], 73 | ] 74 | `; 75 | -------------------------------------------------------------------------------- /.github/workflows/bundlewatch.yml: -------------------------------------------------------------------------------- 1 | # Copyright 2021 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | name: Bundlewatch 16 | 17 | on: 18 | push: 19 | branches: 20 | - main 21 | pull_request: 22 | types: [synchronize, opened] 23 | 24 | jobs: 25 | bundlewatch: 26 | runs-on: ubuntu-latest 27 | env: 28 | CI_BRANCH_BASE: main 29 | steps: 30 | - uses: actions/checkout@v2 31 | - uses: jackyef/bundlewatch-gh-action@b9753bc9b3ea458ff21069eaf6206e01e046f0b5 32 | with: 33 | build-script: npm i 34 | bundlewatch-github-token: ${{ secrets.BUNDLEWATCH_GITHUB_TOKEN }} 35 | bundlewatch-config: .github/bundlewatch.config.json 36 | -------------------------------------------------------------------------------- /.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": ["eslint:recommended", "plugin:prettier/recommended"], 3 | "parserOptions": { 4 | "ecmaVersion": 12, 5 | "sourceType": "module", 6 | "ecmaFeatures": { 7 | "jsx": true 8 | } 9 | }, 10 | "plugins": ["jest"], 11 | "rules": { 12 | "no-var": 2, 13 | "prefer-arrow-callback": 2 14 | }, 15 | "overrides": [ 16 | { 17 | "files": ["*.ts", "*.tsx"], 18 | "parser": "@typescript-eslint/parser", 19 | "plugins": ["@typescript-eslint"], 20 | "extends": ["plugin:@typescript-eslint/recommended"], 21 | "rules": { 22 | "@typescript-eslint/ban-ts-comment": 0, 23 | "@typescript-eslint/ban-types": 1, 24 | "@typescript-eslint/no-empty-function": 1, 25 | "@typescript-eslint/member-ordering": 1, 26 | "@typescript-eslint/explicit-member-accessibility": [ 27 | 1, 28 | { 29 | "accessibility": "explicit", 30 | "overrides": { 31 | "accessors": "explicit", 32 | "constructors": "no-public", 33 | "methods": "explicit", 34 | "properties": "explicit", 35 | "parameterProperties": "explicit" 36 | } 37 | } 38 | ] 39 | } 40 | } 41 | ], 42 | "env": { 43 | "browser": true, 44 | "node": true, 45 | "es6": true, 46 | "jest/globals": true 47 | }, 48 | "globals": { "google": "readonly" } 49 | } 50 | -------------------------------------------------------------------------------- /.github/workflows/docs.yml: -------------------------------------------------------------------------------- 1 | # Copyright 2021 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | name: Docs 16 | on: [push, pull_request] 17 | jobs: 18 | test: 19 | runs-on: ubuntu-latest 20 | steps: 21 | - uses: actions/checkout@v2 22 | - uses: actions/cache@v2 23 | with: 24 | path: ~/.npm 25 | key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} 26 | restore-keys: | 27 | ${{ runner.os }}-node- 28 | - run: | 29 | npm i 30 | npm run docs 31 | - uses: peaceiris/actions-gh-pages@v3 32 | if: github.ref == 'refs/heads/main' 33 | with: 34 | github_token: ${{ secrets.GITHUB_TOKEN }} 35 | publish_dir: ./docs 36 | user_name: 'googlemaps-bot' 37 | user_email: 'googlemaps-bot@users.noreply.github.com' 38 | commit_message: ${{ github.event.head_commit.message }} 39 | -------------------------------------------------------------------------------- /.github/sync-repo-settings.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2022 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | # https://github.com/googleapis/repo-automation-bots/tree/main/packages/sync-repo-settings 16 | 17 | rebaseMergeAllowed: true 18 | squashMergeAllowed: true 19 | mergeCommitAllowed: false 20 | deleteBranchOnMerge: true 21 | branchProtectionRules: 22 | - pattern: main 23 | isAdminEnforced: false 24 | requiresStrictStatusChecks: false 25 | requiredStatusCheckContexts: 26 | - 'cla/google' 27 | - 'test' 28 | - 'snippet-bot check' 29 | - 'header-check' 30 | requiredApprovingReviewCount: 1 31 | requiresCodeOwnerReviews: true 32 | - pattern: master 33 | isAdminEnforced: false 34 | requiresStrictStatusChecks: false 35 | requiredStatusCheckContexts: 36 | - 'cla/google' 37 | - 'test' 38 | - 'snippet-bot check' 39 | - 'header-check' 40 | requiredApprovingReviewCount: 1 41 | requiresCodeOwnerReviews: true 42 | permissionRules: 43 | - team: admin 44 | permission: admin 45 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@googlemaps/polyline-codec", 3 | "version": "1.0.29", 4 | "description": "Encode and decode polyines in Nodejs or the browser using this package.", 5 | "keywords": [ 6 | "google", 7 | "maps", 8 | "polyline" 9 | ], 10 | "homepage": "https://github.com/googlemaps/js-polyline-codec", 11 | "bugs": { 12 | "url": "https://github.com/googlemaps/js-polyline-codec/issues" 13 | }, 14 | "repository": { 15 | "type": "git", 16 | "url": "https://github.com/googlemaps/js-polyline-codec.git" 17 | }, 18 | "license": "Apache-2.0", 19 | "author": "Justin Poehnelt", 20 | "main": "dist/index.umd.js", 21 | "unpkg": "dist/index.min.js", 22 | "module": "dist/index.esm.js", 23 | "types": "dist/index.d.ts", 24 | "files": [ 25 | "dist/**", 26 | "src/**" 27 | ], 28 | "scripts": { 29 | "docs": "typedoc src/index.ts", 30 | "format": "eslint . --fix", 31 | "lint": "eslint .", 32 | "prepare": "rm -rf dist && rollup -c", 33 | "test": "jest src/*" 34 | }, 35 | "devDependencies": { 36 | "@babel/preset-env": "^7.12.1", 37 | "@rollup/plugin-babel": "^5.3.0", 38 | "@rollup/plugin-commonjs": "^25.0.0", 39 | "@rollup/plugin-typescript": "^8.3.0", 40 | "@types/google.maps": "^3.43.0", 41 | "@types/jest": "^27.0.1", 42 | "@typescript-eslint/eslint-plugin": ">=4.1.0", 43 | "@typescript-eslint/parser": ">=4.1.0", 44 | "babel": "^6.23.0", 45 | "core-js": "^3.6.5", 46 | "eslint": "^7.8.1", 47 | "eslint-config-prettier": "^8.3.0", 48 | "eslint-plugin-jest": "^26.0.0", 49 | "eslint-plugin-prettier": "^4.0.0", 50 | "jest": "^26.4.2", 51 | "prettier": "^2.1.1", 52 | "rollup": "^2.26.11", 53 | "rollup-plugin-terser": "^7.0.2", 54 | "ts-jest": "^26.4.1", 55 | "typedoc": "^0.22.3", 56 | "typescript": "^4.0.2" 57 | }, 58 | "publishConfig": { 59 | "access": "public", 60 | "registry": "https://wombat-dressing-room.appspot.com" 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /.github/workflows/release.yml: -------------------------------------------------------------------------------- 1 | # Copyright 2021 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | name: Release 16 | on: 17 | push: 18 | branches: 19 | - main 20 | concurrency: release 21 | jobs: 22 | build: 23 | runs-on: ubuntu-latest 24 | steps: 25 | - uses: actions/setup-node@v2 26 | with: 27 | node-version: '14' 28 | - name: Checkout 29 | uses: actions/checkout@v3 30 | with: 31 | token: ${{ secrets.SYNCED_GITHUB_TOKEN_REPO }} 32 | - uses: actions/cache@v2 33 | with: 34 | path: ~/.npm 35 | key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} 36 | restore-keys: | 37 | ${{ runner.os }}-node- 38 | - name: Test 39 | run: | 40 | npm i 41 | npm run lint 42 | npm test 43 | - name: Release 44 | uses: cycjimmy/semantic-release-action@v2 45 | with: 46 | extra_plugins: | 47 | @semantic-release/commit-analyzer 48 | semantic-release-interval 49 | @semantic-release/release-notes-generator 50 | @semantic-release/git 51 | @semantic-release/github 52 | @semantic-release/npm 53 | @googlemaps/semantic-release-config 54 | semantic-release-npm-deprecate 55 | env: 56 | GH_TOKEN: ${{ secrets.SYNCED_GITHUB_TOKEN_REPO }} 57 | NPM_TOKEN: ${{ secrets.NPM_WOMBAT_TOKEN }} 58 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Google Maps JavaScript Polyline Encoding 2 | 3 | [![npm](https://img.shields.io/npm/v/@googlemaps/polyline-codec)](https://www.npmjs.com/package/@googlemaps/polyline-codec) 4 | ![Build](https://github.com/googlemaps/js-polyline-codec/workflows/Build/badge.svg) 5 | ![Release](https://github.com/googlemaps/js-polyline-codec/workflows/Release/badge.svg) 6 | [![codecov](https://codecov.io/gh/googlemaps/js-polyline-codec/branch/main/graph/badge.svg)](https://codecov.io/gh/googlemaps/js-polyline-codec) 7 | ![GitHub contributors](https://img.shields.io/github/contributors/googlemaps/js-polyline-codec?color=green) 8 | [![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release) 9 | [![](https://github.com/jpoehnelt/in-solidarity-bot/raw/main/static//badge-flat.png)](https://github.com/apps/in-solidarity) 10 | 11 | ## Description 12 | 13 | Encode and decode polyines in Nodejs or the browser using this package. 14 | 15 | 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. 16 | 17 | Read more at https://developers.google.com/maps/documentation/utilities/polylinealgorithm. 18 | 19 | ## Install 20 | 21 | Available via npm as the package [@googlemaps/polyline-codec](https://www.npmjs.com/package/@googlemaps/polyline-codec). 22 | 23 | `npm i @googlemaps/polyline-codec` 24 | 25 | ## Documentation 26 | 27 | The reference documentation can be found at this [link](https://googlemaps.github.io/js-polyline-codec/index.html). 28 | 29 | ## Example 30 | 31 | ```js 32 | import { decode, encode } from "@googlemaps/polyline-codec"; 33 | 34 | const encoded = "_p~iF~ps|U_ulLnnqC_mqNvxq`@"; 35 | console.log(decode(encoded, 5)); 36 | // [ 37 | // [38.5, -120.2], 38 | // [40.7, -120.95], 39 | // [43.252, -126.453], 40 | // ] 41 | 42 | const path = [ 43 | [38.5, -120.2], 44 | [40.7, -120.95], 45 | [43.252, -126.453], 46 | ]; 47 | console.log(encode(path, 5)); 48 | // "_p~iF~ps|U_ulLnnqC_mqNvxq`@" 49 | ``` 50 | -------------------------------------------------------------------------------- /rollup.config.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2020 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | import { babel } from "@rollup/plugin-babel"; 18 | import commonjs from "@rollup/plugin-commonjs"; 19 | import { terser } from "rollup-plugin-terser"; 20 | import typescript from "@rollup/plugin-typescript"; 21 | 22 | const babelOptions = { 23 | extensions: [".js", ".ts"], 24 | }; 25 | 26 | const terserOptions = { output: { comments: "" } }; 27 | export default [ 28 | { 29 | input: "src/index.ts", 30 | plugins: [ 31 | typescript({ tsconfig: "./tsconfig.json", declarationDir: "./" }), 32 | 33 | commonjs(), 34 | babel(babelOptions), 35 | terser(terserOptions), 36 | ], 37 | output: [ 38 | { 39 | file: "dist/index.umd.js", 40 | format: "umd", 41 | name: "polyline", 42 | }, 43 | { 44 | file: "dist/index.min.js", 45 | format: "iife", 46 | name: "polyline", 47 | }, 48 | ], 49 | }, 50 | { 51 | input: "src/index.ts", 52 | plugins: [ 53 | typescript({ tsconfig: "./tsconfig.json", declarationDir: "./" }), 54 | 55 | commonjs(), 56 | babel(babelOptions), 57 | ], 58 | output: { 59 | file: "dist/index.dev.js", 60 | format: "iife", 61 | name: "polyline", 62 | }, 63 | }, 64 | { 65 | input: "src/index.ts", 66 | plugins: [ 67 | typescript({ tsconfig: "./tsconfig.json", declarationDir: "./" }), 68 | ], 69 | output: { 70 | file: "dist/index.esm.js", 71 | format: "esm", 72 | sourcemap: true, 73 | }, 74 | }, 75 | ]; 76 | -------------------------------------------------------------------------------- /.github/workflows/codeql.yml: -------------------------------------------------------------------------------- 1 | # Copyright 2021 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | # For most projects, this workflow file will not need changing; you simply need 16 | # to commit it to your repository. 17 | # 18 | # You may wish to alter this file to override the set of languages analyzed, 19 | # or to provide custom queries or build logic. 20 | # 21 | # ******** NOTE ******** 22 | # We have attempted to detect the languages in your repository. Please check 23 | # the `language` matrix defined below to confirm you have the correct set of 24 | # supported CodeQL languages. 25 | # 26 | name: "CodeQL" 27 | 28 | on: 29 | push: 30 | branches: [main] 31 | pull_request: 32 | # The branches below must be a subset of the branches above 33 | branches: [main] 34 | schedule: 35 | - cron: "0 13 * * *" 36 | 37 | jobs: 38 | analyze: 39 | name: Analyze 40 | runs-on: ubuntu-latest 41 | permissions: 42 | actions: read 43 | contents: read 44 | security-events: write 45 | 46 | strategy: 47 | fail-fast: false 48 | matrix: 49 | language: ["javascript"] 50 | # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python' ] 51 | # Learn more: 52 | # https://docs.github.com/en/free-pro-team@latest/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#changing-the-languages-that-are-analyzed 53 | 54 | steps: 55 | - name: Checkout repository 56 | uses: actions/checkout@v2 57 | 58 | # Initializes the CodeQL tools for scanning. 59 | - name: Initialize CodeQL 60 | uses: github/codeql-action/init@v1 61 | with: 62 | languages: ${{ matrix.language }} 63 | # If you wish to specify custom queries, you can do so here or in a config file. 64 | # By default, queries listed here will override any specified in a config file. 65 | # Prefix the list here with "+" to use these queries and those in the config file. 66 | # queries: ./path/to/local/query, your-org/your-repo/queries@main 67 | 68 | # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). 69 | # If this step fails, then you should remove it and run the build manually (see below) 70 | - name: Autobuild 71 | uses: github/codeql-action/autobuild@v1 72 | 73 | # ℹ️ Command-line programs to run using the OS shell. 74 | # 📚 https://git.io/JvXDl 75 | 76 | # ✏️ If the Autobuild fails above, remove it and uncomment the following three lines 77 | # and modify them (or add more) to build your code if your project 78 | # uses a compiled language 79 | 80 | #- run: | 81 | # make bootstrap 82 | # make release 83 | 84 | - name: Perform CodeQL Analysis 85 | uses: github/codeql-action/analyze@v1 86 | -------------------------------------------------------------------------------- /src/index.test.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2020 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | import { decode, encode } from "./index"; 18 | 19 | const CASES = { 20 | DEFAULT: [ 21 | [38.5, -120.2], 22 | [40.7, -120.95], 23 | [43.252, -126.453], 24 | ], 25 | DEFAULT_MIXED: [ 26 | [38.5, -120.2], 27 | { lat: 40.7, lng: -120.95 }, 28 | [43.252, -126.453], 29 | ], 30 | DEFAULT_ROUNDED: [ 31 | [39, -120], 32 | [41, -121], 33 | [43, -126], 34 | ], 35 | SLASHES: [ 36 | [35.6, -82.55], 37 | [35.59985, -82.55015], 38 | [35.6, -82.55], 39 | ], 40 | FLIPPED: [ 41 | [-120.2, 38.5], 42 | [-120.95, 40.7], 43 | [-126.453, 43.252], 44 | ], 45 | ROUNDING: [ 46 | [0, 0.000006], 47 | [0, 0.000002], 48 | ], 49 | NEGATIVE: [ 50 | [36.05322, -112.084004], 51 | [36.053573, -112.083914], 52 | [36.053845, -112.083965], 53 | ], 54 | }; 55 | 56 | describe("decode", () => { 57 | test("decodes to an empty array", () => { 58 | expect(decode("")).toEqual([]); 59 | }); 60 | 61 | test("decodes a string into an array of lat lng pairs", () => { 62 | expect(decode("_p~iF~ps|U_ulLnnqC_mqNvxq`@")).toEqual(CASES.DEFAULT); 63 | }); 64 | 65 | test("decodes with a custom precision", () => { 66 | expect(decode("_izlhA~rlgdF_{geC~ywl@_kwzCn`{nI", 6)).toEqual( 67 | CASES.DEFAULT 68 | ); 69 | }); 70 | 71 | test("decodes with precision 0", () => { 72 | expect(decode("mAnFC@CH", 0)).toEqual(CASES.DEFAULT_ROUNDED); 73 | }); 74 | }); 75 | 76 | describe("roundtrip", () => { 77 | test("roundrip", () => { 78 | const encoded = 79 | "gcneIpgxzRcDnBoBlEHzKjBbHlG`@`IkDxIiKhKoMaLwTwHeIqHuAyGXeB~Ew@fFjAtIzExF"; 80 | const decoded = decode(encoded, 5); 81 | 82 | expect(decoded).toMatchSnapshot(); 83 | expect(encode(decoded, 5)).toEqual(encoded); 84 | }); 85 | 86 | test("feed encode into decode and check if the result is the same as the input", () => { 87 | expect(decode(encode(CASES.SLASHES))).toEqual(CASES.SLASHES); 88 | }); 89 | 90 | test("feed decode into encode and check if the result is the same as the input", () => { 91 | expect(encode(decode("_chxEn`zvN\\\\]]"))).toEqual("_chxEn`zvN\\\\]]"); 92 | }); 93 | }); 94 | 95 | describe("encode", () => { 96 | test("encodes an empty Array", () => { 97 | expect(encode([])).toEqual(""); 98 | }); 99 | 100 | test("encodes an Array of lat/lon pairs into a String", () => { 101 | expect(encode(CASES.DEFAULT)).toEqual("_p~iF~ps|U_ulLnnqC_mqNvxq`@"); 102 | }); 103 | 104 | test("encodes with proper rounding", () => { 105 | expect(encode(CASES.ROUNDING)).toEqual("?A?@"); 106 | }); 107 | 108 | test("encodes array having lat lng objects", () => { 109 | expect(encode(CASES.DEFAULT_MIXED)).toEqual("_p~iF~ps|U_ulLnnqC_mqNvxq`@"); 110 | }); 111 | 112 | test("encodes with proper negative rounding", () => { 113 | expect(encode(CASES.NEGATIVE)).toEqual("ss`{E~kbkTeAQw@J"); 114 | }); 115 | 116 | test("encodes with a custom precision", () => { 117 | expect(encode(CASES.DEFAULT, 6)).toEqual( 118 | "_izlhA~rlgdF_{geC~ywl@_kwzCn`{nI" 119 | ); 120 | }); 121 | 122 | test("encodes with precision 0", () => { 123 | expect(encode(CASES.DEFAULT, 0)).toEqual("mAnFC@CH"); 124 | }); 125 | 126 | test("encodes negative values correctly", () => { 127 | expect( 128 | decode(encode([{ lng: -107.3741825, lat: 0 }], 7), 7)[0][1] 129 | ).toBeLessThan(0); 130 | }); 131 | }); 132 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | dist/ 3 | .npmrc 4 | **/docs 5 | 6 | # Logs 7 | logs 8 | *.log 9 | npm-debug.log* 10 | yarn-debug.log* 11 | yarn-error.log* 12 | lerna-debug.log* 13 | 14 | # Diagnostic reports (https://nodejs.org/api/report.html) 15 | report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json 16 | 17 | # Runtime data 18 | pids 19 | *.pid 20 | *.seed 21 | *.pid.lock 22 | 23 | # Directory for instrumented libs generated by jscoverage/JSCover 24 | lib-cov 25 | 26 | # Coverage directory used by tools like istanbul 27 | coverage 28 | *.lcov 29 | 30 | # nyc test coverage 31 | .nyc_output 32 | 33 | # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) 34 | .grunt 35 | 36 | # Bower dependency directory (https://bower.io/) 37 | bower_components 38 | 39 | # node-waf configuration 40 | .lock-wscript 41 | 42 | # Compiled binary addons (https://nodejs.org/api/addons.html) 43 | build/Release 44 | 45 | # Dependency directories 46 | node_modules/ 47 | jspm_packages/ 48 | 49 | # TypeScript v1 declaration files 50 | typings/ 51 | 52 | # TypeScript cache 53 | *.tsbuildinfo 54 | 55 | # Optional npm cache directory 56 | .npm 57 | 58 | # Optional eslint cache 59 | .eslintcache 60 | 61 | # Microbundle cache 62 | .rpt2_cache/ 63 | .rts2_cache_cjs/ 64 | .rts2_cache_es/ 65 | .rts2_cache_umd/ 66 | 67 | # Optional REPL history 68 | .node_repl_history 69 | 70 | # Output of 'npm pack' 71 | *.tgz 72 | 73 | # Yarn Integrity file 74 | .yarn-integrity 75 | 76 | # dotenv environment variables file 77 | .env 78 | .env.test 79 | 80 | # parcel-bundler cache (https://parceljs.org/) 81 | .cache 82 | 83 | # next.js build output 84 | .next 85 | 86 | # nuxt.js build output 87 | .nuxt 88 | 89 | # gatsby files 90 | .cache/ 91 | public 92 | 93 | # vuepress build output 94 | .vuepress/dist 95 | 96 | # Serverless directories 97 | .serverless/ 98 | 99 | # FuseBox cache 100 | .fusebox/ 101 | 102 | # DynamoDB Local files 103 | .dynamodb/ 104 | 105 | # TernJS port file 106 | .tern-port 107 | 108 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm 109 | # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 110 | 111 | # User-specific stuff 112 | .idea/**/workspace.xml 113 | .idea/**/tasks.xml 114 | .idea/**/usage.statistics.xml 115 | .idea/**/dictionaries 116 | .idea/**/shelf 117 | 118 | # Generated files 119 | .idea/**/contentModel.xml 120 | 121 | # Sensitive or high-churn files 122 | .idea/**/dataSources/ 123 | .idea/**/dataSources.ids 124 | .idea/**/dataSources.local.xml 125 | .idea/**/sqlDataSources.xml 126 | .idea/**/dynamic.xml 127 | .idea/**/uiDesigner.xml 128 | .idea/**/dbnavigator.xml 129 | 130 | # Gradle 131 | .idea/**/gradle.xml 132 | .idea/**/libraries 133 | 134 | # Gradle and Maven with auto-import 135 | # When using Gradle or Maven with auto-import, you should exclude module files, 136 | # since they will be recreated, and may cause churn. Uncomment if using 137 | # auto-import. 138 | # .idea/modules.xml 139 | # .idea/*.iml 140 | # .idea/modules 141 | # *.iml 142 | # *.ipr 143 | 144 | # CMake 145 | cmake-build-*/ 146 | 147 | # Mongo Explorer plugin 148 | .idea/**/mongoSettings.xml 149 | 150 | # File-based project format 151 | *.iws 152 | 153 | # IntelliJ 154 | out/ 155 | 156 | # mpeltonen/sbt-idea plugin 157 | .idea_modules/ 158 | 159 | # JIRA plugin 160 | atlassian-ide-plugin.xml 161 | 162 | # Cursive Clojure plugin 163 | .idea/replstate.xml 164 | 165 | # Crashlytics plugin (for Android Studio and IntelliJ) 166 | com_crashlytics_export_strings.xml 167 | crashlytics.properties 168 | crashlytics-build.properties 169 | fabric.properties 170 | 171 | # Editor-based Rest Client 172 | .idea/httpRequests 173 | 174 | # Android studio 3.1+ serialized cache file 175 | .idea/caches/build_file_checksums.ser 176 | 177 | # General 178 | .DS_Store 179 | .AppleDouble 180 | .LSOverride 181 | 182 | # Icon must end with two \r 183 | Icon 184 | 185 | 186 | # Thumbnails 187 | ._* 188 | 189 | # Files that might appear in the root of a volume 190 | .DocumentRevisions-V100 191 | .fseventsd 192 | .Spotlight-V100 193 | .TemporaryItems 194 | .Trashes 195 | .VolumeIcon.icns 196 | .com.apple.timemachine.donotpresent 197 | 198 | # Directories potentially created on remote AFP share 199 | .AppleDB 200 | .AppleDesktop 201 | Network Trash Folder 202 | Temporary Items 203 | .apdisk 204 | 205 | # Windows thumbnail cache files 206 | Thumbs.db 207 | Thumbs.db:encryptable 208 | ehthumbs.db 209 | ehthumbs_vista.db 210 | 211 | # Dump file 212 | *.stackdump 213 | 214 | # Folder config file 215 | [Dd]esktop.ini 216 | 217 | # Recycle Bin used on file shares 218 | $RECYCLE.BIN/ 219 | 220 | # Windows Installer files 221 | *.cab 222 | *.msi 223 | *.msix 224 | *.msm 225 | *.msp 226 | 227 | # Windows shortcuts 228 | *.lnk 229 | -------------------------------------------------------------------------------- /src/index.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2020 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /** Object with lat and lng properties. */ 18 | export interface LatLng { 19 | lat: number; 20 | lng: number; 21 | } 22 | 23 | /** 24 | * Array with lat and lng elements. 25 | */ 26 | export type LatLngTuple = [number, number]; 27 | 28 | /** 29 | * Decodes an encoded path string into a sequence of LatLngs. 30 | * 31 | * See {@link https://developers.google.com/maps/documentation/utilities/polylinealgorithm} 32 | * 33 | * #### Example 34 | * 35 | * ```js 36 | * import { decode } from "@googlemaps/polyline-codec"; 37 | * 38 | * const encoded = "_p~iF~ps|U_ulLnnqC_mqNvxq`@"; 39 | * console.log(decode(encoded, 5)); 40 | * // [ 41 | * // [38.5, -120.2], 42 | * // [40.7, -120.95], 43 | * // [43.252, -126.453], 44 | * // ] 45 | * ``` 46 | */ 47 | export const decode = function ( 48 | encodedPath: string, 49 | precision = 5 50 | ): LatLngTuple[] { 51 | const factor = Math.pow(10, precision); 52 | 53 | const len = encodedPath.length; 54 | 55 | // For speed we preallocate to an upper bound on the final length, then 56 | // truncate the array before returning. 57 | const path = new Array(Math.floor(encodedPath.length / 2)); 58 | let index = 0; 59 | let lat = 0; 60 | let lng = 0; 61 | let pointIndex = 0; 62 | 63 | // This code has been profiled and optimized, so don't modify it without 64 | // measuring its performance. 65 | for (; index < len; ++pointIndex) { 66 | // Fully unrolling the following loops speeds things up about 5%. 67 | let result = 1; 68 | let shift = 0; 69 | let b: number; 70 | do { 71 | // Invariant: "result" is current partial result plus (1 << shift). 72 | // The following line effectively clears this bit by decrementing "b". 73 | b = encodedPath.charCodeAt(index++) - 63 - 1; 74 | result += b << shift; 75 | shift += 5; 76 | } while (b >= 0x1f); // See note above. 77 | lat += result & 1 ? ~(result >> 1) : result >> 1; 78 | 79 | result = 1; 80 | shift = 0; 81 | do { 82 | b = encodedPath.charCodeAt(index++) - 63 - 1; 83 | result += b << shift; 84 | shift += 5; 85 | } while (b >= 0x1f); 86 | lng += result & 1 ? ~(result >> 1) : result >> 1; 87 | 88 | path[pointIndex] = [lat / factor, lng / factor]; 89 | } 90 | // truncate array 91 | path.length = pointIndex; 92 | 93 | return path; 94 | }; 95 | 96 | /** 97 | * Polyline encodes an array of objects having lat and lng properties. 98 | * 99 | * See {@link https://developers.google.com/maps/documentation/utilities/polylinealgorithm} 100 | * 101 | * #### Example 102 | * 103 | * ```js 104 | * import { encode } from "@googlemaps/polyline-codec"; 105 | * 106 | * const path = [ 107 | * [38.5, -120.2], 108 | * [40.7, -120.95], 109 | * [43.252, -126.453], 110 | * ]; 111 | * console.log(encode(path, 5)); 112 | * // "_p~iF~ps|U_ulLnnqC_mqNvxq`@" 113 | * ``` 114 | */ 115 | export const encode = function ( 116 | path: (number[] | LatLng | LatLngTuple)[], 117 | precision = 5 118 | ): string { 119 | const factor = Math.pow(10, precision); 120 | 121 | const transform = function latLngToFixed( 122 | latLng: LatLng | LatLngTuple 123 | ): [number, number] { 124 | if (!Array.isArray(latLng)) { 125 | latLng = [latLng.lat, latLng.lng]; 126 | } 127 | 128 | return [round(latLng[0] * factor), round(latLng[1] * factor)]; 129 | }; 130 | 131 | return polylineEncodeLine(path, transform); 132 | }; 133 | 134 | /** 135 | * Encodes a generic polyline; optionally performing a transform on each point 136 | * before encoding it. 137 | * 138 | * @ignore 139 | */ 140 | export const polylineEncodeLine = function ( 141 | array: (number[] | LatLng | LatLngTuple)[], 142 | transform: (latLng: number[] | LatLng | LatLngTuple) => [number, number] 143 | ): string { 144 | const v: string[] = []; 145 | let start = [0, 0]; 146 | let end; 147 | for (let i = 0, I = array.length; i < I; ++i) { 148 | // In order to prevent drift (from quantizing deltas), we explicitly convert 149 | // coordinates to fixed-precision to obtain integer deltas. 150 | end = transform(array[i]); 151 | 152 | // Push the next edge 153 | polylineEncodeSigned(round(end[0]) - round(start[0]), v); // lat 154 | polylineEncodeSigned(round(end[1]) - round(start[1]), v); // lng 155 | start = end; 156 | } 157 | 158 | return v.join(""); 159 | }; 160 | 161 | /** 162 | * Encodes the given value in our compact polyline format, appending the 163 | * encoded value to the given array of strings. 164 | * 165 | * @ignore 166 | */ 167 | const polylineEncodeSigned = function ( 168 | value: number, 169 | array: string[] 170 | ): string[] { 171 | return polylineEncodeUnsigned(value < 0 ? ~(value << 1) : value << 1, array); 172 | }; 173 | 174 | /** 175 | * Helper function for encodeSigned. 176 | * 177 | * @ignore 178 | */ 179 | const polylineEncodeUnsigned = function ( 180 | value: number, 181 | array: string[] 182 | ): string[] { 183 | while (value >= 0x20) { 184 | array.push(String.fromCharCode((0x20 | (value & 0x1f)) + 63)); 185 | value >>= 5; 186 | } 187 | array.push(String.fromCharCode(value + 63)); 188 | return array; 189 | }; 190 | 191 | /** 192 | * @ignore 193 | */ 194 | const round = (v: number) => { 195 | return Math.floor(Math.abs(v) + 0.5) * (v >= 0 ? 1 : -1); 196 | }; 197 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS 178 | 179 | APPENDIX: How to apply the Apache License to your work. 180 | 181 | To apply the Apache License to your work, attach the following 182 | boilerplate notice, with the fields enclosed by brackets "[]" 183 | replaced with your own identifying information. (Don't include 184 | the brackets!) The text should be enclosed in the appropriate 185 | comment syntax for the file format. We also recommend that a 186 | file or class name and description of purpose be included on the 187 | same "printed page" as the copyright notice for easier 188 | identification within third-party archives. 189 | 190 | Copyright [yyyy] [name of copyright owner] 191 | 192 | Licensed under the Apache License, Version 2.0 (the "License"); 193 | you may not use this file except in compliance with the License. 194 | You may obtain a copy of the License at 195 | 196 | http://www.apache.org/licenses/LICENSE-2.0 197 | 198 | Unless required by applicable law or agreed to in writing, software 199 | distributed under the License is distributed on an "AS IS" BASIS, 200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 201 | See the License for the specific language governing permissions and 202 | limitations under the License. 203 | --------------------------------------------------------------------------------