├── .babelrc ├── .eslintignore ├── .eslintrc.json ├── .github ├── CODEOWNERS ├── bundlewatch.config.json ├── dependabot.yml ├── sync-repo-settings.yaml └── workflows │ ├── bundlewatch.yml │ ├── codeql.yml │ ├── dependabot.yml │ ├── docs.yml │ ├── e2e.yml │ ├── package.yml │ ├── release.yml │ └── test.yml ├── .gitignore ├── .releaserc ├── CHANGELOG.md ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── SECURITY.md ├── examples ├── google_northamerica_offices.html ├── google_northamerica_offices.js ├── images │ ├── ca.png │ ├── flag-shadow.png │ ├── headquarters-shadow.png │ ├── headquarters.png │ ├── house-shadow.png │ ├── house.png │ ├── rain-shadow.png │ ├── rain.png │ ├── snow-shadow.png │ ├── snow.png │ ├── storm-shadow.png │ ├── storm.png │ ├── sun-shadow.png │ ├── sun.png │ └── us.png └── weather_map.html ├── jest.config.js ├── package-lock.json ├── package.json ├── rollup.config.js ├── src ├── gridbounds.ts ├── index.ts ├── markermanager.test.ts ├── markermanager.ts └── utils.ts ├── tsconfig.json └── typedoc.js /.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 | -------------------------------------------------------------------------------- /.eslintignore: -------------------------------------------------------------------------------- 1 | bazel-* 2 | coverage/ 3 | dist/ 4 | docs/ 5 | lib/ 6 | node_modules/ 7 | public/ -------------------------------------------------------------------------------- /.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/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/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 | -------------------------------------------------------------------------------- /.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 | -------------------------------------------------------------------------------- /.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 | -------------------------------------------------------------------------------- /.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 | -------------------------------------------------------------------------------- /.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 | -------------------------------------------------------------------------------- /.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 | -------------------------------------------------------------------------------- /.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/workflows/e2e.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: e2e 16 | on: 17 | push: 18 | schedule: 19 | - cron: "0 12 * * *" 20 | jobs: 21 | chrome: 22 | runs-on: ubuntu-latest 23 | services: 24 | hub: 25 | image: selenium/standalone-chrome 26 | volumes: 27 | - ${{ github.workspace }}:${{ github.workspace }} 28 | ports: 29 | - 4444:4444 30 | steps: 31 | - uses: actions/checkout@v2 32 | - run: npm i 33 | - run: npm run test:e2e 34 | firefox: 35 | runs-on: ubuntu-latest 36 | services: 37 | hub: 38 | image: selenium/standalone-firefox 39 | volumes: 40 | - ${{ github.workspace }}:${{ github.workspace }} 41 | ports: 42 | - 4444:4444 43 | steps: 44 | - uses: actions/checkout@v2 45 | - run: npm i 46 | - run: npm run test:e2e 47 | env: 48 | BROWSER: firefox 49 | -------------------------------------------------------------------------------- /.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/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 | -------------------------------------------------------------------------------- /.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 | -------------------------------------------------------------------------------- /.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 | .vscode 230 | -------------------------------------------------------------------------------- /.releaserc: -------------------------------------------------------------------------------- 1 | extends: "@googlemaps/semantic-release-config" 2 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Change Log 2 | 3 | All notable changes to this project will be documented in this file. 4 | See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. 5 | 6 | # [0.1.0](https://github.com/googlemaps/v3-utility-library/compare/@googlemaps/markermanager@0.0.8...@googlemaps/markermanager@0.1.0) (2021-06-17) 7 | 8 | 9 | ### Features 10 | 11 | * Support for @types/google.maps ([#694](https://github.com/googlemaps/v3-utility-library/issues/694)) ([e78e58c](https://github.com/googlemaps/v3-utility-library/commit/e78e58c0c5a0dcf6675e671e2d54dcc46779744d)), closes [#690](https://github.com/googlemaps/v3-utility-library/issues/690) 12 | 13 | 14 | 15 | 16 | 17 | ## [0.0.8](https://github.com/googlemaps/v3-utility-library/compare/@googlemaps/markermanager@0.0.7...@googlemaps/markermanager@0.0.8) (2021-03-08) 18 | 19 | **Note:** Version bump only for package @googlemaps/markermanager 20 | 21 | 22 | 23 | 24 | 25 | ## [0.0.7](https://github.com/googlemaps/v3-utility-library/compare/@googlemaps/markermanager@0.0.6...@googlemaps/markermanager@0.0.7) (2020-09-11) 26 | 27 | **Note:** Version bump only for package @googlemaps/markermanager 28 | 29 | 30 | 31 | 32 | 33 | ## [0.0.6](https://github.com/googlemaps/v3-utility-library/compare/@googlemaps/markermanager@0.0.5...@googlemaps/markermanager@0.0.6) (2020-03-12) 34 | 35 | 36 | ### Bug Fixes 37 | 38 | * add polyfills via core-js ([#634](https://github.com/googlemaps/v3-utility-library/issues/634)) ([4699c9a](https://github.com/googlemaps/v3-utility-library/commit/4699c9abf69307829a8782c917f1eb0108ac941b)) 39 | 40 | 41 | 42 | 43 | 44 | ## [0.0.5](https://github.com/googlemaps/v3-utility-library/compare/@googlemaps/markermanager@0.0.4...@googlemaps/markermanager@0.0.5) (2020-03-12) 45 | 46 | 47 | ### Bug Fixes 48 | 49 | * set browserslist setting for babel ([#632](https://github.com/googlemaps/v3-utility-library/issues/632)) ([a57b68e](https://github.com/googlemaps/v3-utility-library/commit/a57b68e86bef5bea54e35c9fc4cd66b10ef8dafe)) 50 | 51 | 52 | 53 | 54 | 55 | ## [0.0.4](https://github.com/googlemaps/v3-utility-library/compare/@googlemaps/markermanager@0.0.3...@googlemaps/markermanager@0.0.4) (2019-12-23) 56 | 57 | **Note:** Version bump only for package @googlemaps/markermanager 58 | 59 | 60 | 61 | 62 | 63 | ## [0.0.3](https://github.com/googlemaps/v3-utility-library/compare/@googlemaps/markermanager@0.0.2...@googlemaps/markermanager@0.0.3) (2019-12-09) 64 | 65 | 66 | ### Bug Fixes 67 | 68 | * remove old documentation links ([#574](https://github.com/googlemaps/v3-utility-library/issues/574)) ([0bfb640](https://github.com/googlemaps/v3-utility-library/commit/0bfb6400b555f46e2fbc4fab002673b084931c09)) 69 | * transpile code for iife and umd outputs ([#586](https://github.com/googlemaps/v3-utility-library/issues/586)) ([fb9ad06](https://github.com/googlemaps/v3-utility-library/commit/fb9ad066cbf5d87cffcda2c435196ad20fed56f1)) 70 | -------------------------------------------------------------------------------- /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 | 1. Run lint 18 | 19 | npm run lint 20 | npm run format # will fix some issues 21 | 22 | 1. Run the tests: 23 | 24 | # Run unit tests. 25 | npm test 26 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # MarkerManager 2 | 3 | [![npm](https://img.shields.io/npm/v/@googlemaps/markermanager)](https://www.npmjs.com/package/@googlemaps/markermanager) 4 | ![Build](https://github.com/googlemaps/js-markermanager/workflows/Test/badge.svg) 5 | ![Release](https://github.com/googlemaps/js-markermanager/workflows/Release/badge.svg) 6 | [![codecov](https://codecov.io/gh/googlemaps/js-markermanager/branch/main/graph/badge.svg)](https://codecov.io/gh/googlemaps/js-markermanager) 7 | ![GitHub contributors](https://img.shields.io/github/contributors/googlemaps/js-markermanager?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 | [![Discord](https://img.shields.io/discord/676948200904589322?color=6A7EC2&logo=discord&logoColor=ffffff)](https://discord.gg/jRteCzP) 11 | 12 | ## Description 13 | 14 | Marker manager is an interface between the map and the user, designed to manage adding and removing many points when the viewport changes. 15 | 16 | > **Note**: This package was previously located at https://github.com/googlemaps/v3-utility-library. 17 | 18 | ### How it Works 19 | 20 | The MarkerManager places its markers onto a grid, similar to the map tiles. When the user moves the viewport, it computes which grid cells have entered or left the viewport, and shows or hides all the markers in those cells. (If the users scrolls the viewport beyond the markers that are loaded, no markers will be visible until the EVENT_moveend triggers an update.) In practical consequences, this allows 10,000 markers to be distributed over a large area, and as long as only 100-200 are visible in any given viewport, the user will see good performance corresponding to the 100 visible markers, rather than poor performance corresponding to the total 10,000 markers. Note that some code is optimized for speed over space, with the goal of accommodating thousands of markers. 21 | 22 | ## Documentation 23 | 24 | The reference documentation can be found at this [link](https://googlemaps.github.io/js-markermanager). 25 | 26 | ## Examples 27 | 28 | - [Weather Map](https://googlemaps.github.io/js-markermanager/examples/weather_map.html) 29 | - [Google North America Offices](https://googlemaps.github.io/js-markermanager/examples/google_northamerica_offices.html) 30 | 31 | ## Support 32 | 33 | This library is community supported. We're comfortable enough with the stability and features of 34 | the library that we want you to build real production applications on it. 35 | 36 | If you find a bug, or have a feature suggestion, please [log an issue][issues]. If you'd like to 37 | contribute, please read [How to Contribute][contrib]. 38 | 39 | [issues]: https://github.com/googlemaps/js-markermanager/issues 40 | [contrib]: https://github.com/googlemaps/js-markermanager/blob/master/packages/markermanager/CONTRIB.md 41 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /examples/google_northamerica_offices.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Google Maps API Example - Google North America Offices 6 | 10 | 11 | 12 | 13 | 156 | 162 | 163 | 164 | 165 |  | 170 | | 171 | | 176 | | 177 | 178 | 179 |
180 |
181 |
182 | 183 | 184 | -------------------------------------------------------------------------------- /examples/google_northamerica_offices.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable no-unused-vars */ 2 | let iconData = { 3 | us: { width: 24, height: 14 }, 4 | ca: { width: 24, height: 14 }, 5 | "flag-shadow": { width: 40, height: 30 }, 6 | house: { width: 32, height: 32 }, 7 | "house-shadow": { width: 59, height: 32 }, 8 | headquarters: { width: 32, height: 32 }, 9 | "headquarters-shadow": { width: 59, height: 32 }, 10 | }; 11 | 12 | let officeLayer = [ 13 | { 14 | zoom: [0, 3], 15 | places: [ 16 | { 17 | name: "USA Offices", 18 | icon: ["us", "flag-shadow"], 19 | position: [40, -97], 20 | }, 21 | { 22 | name: "Canadian Offices", 23 | icon: ["ca", "flag-shadow"], 24 | position: [58, -101], 25 | }, 26 | ], 27 | }, 28 | { 29 | zoom: [4, 6], 30 | places: [ 31 | { 32 | name: "Headquarters", 33 | icon: ["headquarters", "headquarters-shadow"], 34 | position: [37.423021, -122.083739], 35 | }, 36 | { 37 | name: "New York Sales & Engineering Office", 38 | icon: ["house", "house-shadow"], 39 | position: [40.754606, -73.986794], 40 | }, 41 | { 42 | name: "Atlanta Sales & Engineering Office", 43 | icon: ["house", "house-shadow"], 44 | position: [33.781506, -84.387422], 45 | }, 46 | { 47 | name: "Dallas Sales Office", 48 | icon: ["house", "house-shadow"], 49 | position: [36.4724385, -101.044637], 50 | }, 51 | { 52 | name: "Cambridge Sales & Engineering Office", 53 | icon: ["house", "house-shadow"], 54 | position: [42.362331, -71.083661], 55 | }, 56 | { 57 | name: "Chicago Sales Office", 58 | icon: ["house", "house-shadow"], 59 | position: [41.889232, -87.628767], 60 | }, 61 | { 62 | name: "Denver & Boulder Offices", 63 | icon: ["house", "house-shadow"], 64 | position: [39.563011, -104.868962], 65 | }, 66 | { 67 | name: "Detroit Sales Office", 68 | icon: ["house", "house-shadow"], 69 | position: [42.475482, -83.244587], 70 | }, 71 | { 72 | name: "Santa Monica & Irvine Offices", 73 | icon: ["house", "house-shadow"], 74 | position: [33.715585, -118.177435], 75 | }, 76 | { 77 | name: "Phoenix Sales & Engineering Office", 78 | icon: ["house", "house-shadow"], 79 | position: [33.411782, -111.926247], 80 | }, 81 | { 82 | name: "Pittsburgh Engineering Office", 83 | icon: ["house", "house-shadow"], 84 | position: [40.444541, -79.946254], 85 | }, 86 | { 87 | name: "Seattle Engineering & Sales Offices", 88 | icon: ["house", "house-shadow"], 89 | position: [47.664261, -122.274308], 90 | }, 91 | { 92 | name: "Canada Sales Office", 93 | icon: ["house", "house-shadow"], 94 | position: [43.645478, -79.378843], 95 | }, 96 | ], 97 | }, 98 | { 99 | zoom: [7, 17], 100 | places: [ 101 | { 102 | name: "Headquarters", 103 | position: [37.423021, -122.083739], 104 | }, 105 | { 106 | name: "New York Sales & Engineering Office", 107 | position: [40.754606, -73.986794], 108 | }, 109 | { 110 | name: "Atlanta Sales & Engineering Office", 111 | position: [33.781506, -84.387422], 112 | }, 113 | { 114 | name: "Boulder Sales & Engineering Office", 115 | position: [40.01852, -105.276882], 116 | }, 117 | { 118 | name: "Cambridge Sales & Engineering Office", 119 | position: [42.362331, -71.083661], 120 | }, 121 | { 122 | name: "Chicago Sales Office", 123 | position: [41.889232, -87.628767], 124 | }, 125 | { 126 | name: "Dallas Sales Office", 127 | position: [32.925355, -96.816087], 128 | }, 129 | { 130 | name: "Denver Sales Office", 131 | position: [39.563011, -104.868962], 132 | }, 133 | { 134 | name: "Detroit Sales Office", 135 | position: [42.475482, -83.244587], 136 | }, 137 | { 138 | name: "Irvine Sales & Engineering Office", 139 | position: [33.660021, -117.860142], 140 | }, 141 | { 142 | name: "Phoenix Sales & Engineering Office", 143 | position: [33.411782, -111.926247], 144 | }, 145 | { 146 | name: "Pittsburgh Engineering Office", 147 | position: [40.444541, -79.946254], 148 | }, 149 | { 150 | name: "Santa Monica Sales & Engineering Office", 151 | position: [34.019388, -118.494728], 152 | }, 153 | { 154 | name: "Seattle Engineering Office", 155 | position: [47.678415, -122.195713], 156 | }, 157 | { 158 | name: "Seattle Sales Office", 159 | position: [47.650106, -122.352903], 160 | }, 161 | { 162 | name: "Toronto Sales Office", 163 | position: [43.645478, -79.378843], 164 | }, 165 | ], 166 | }, 167 | ]; 168 | -------------------------------------------------------------------------------- /examples/images/ca.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlemaps/js-markermanager/463788837d1670ea191dbb909c1dbe51bd5b5ca2/examples/images/ca.png -------------------------------------------------------------------------------- /examples/images/flag-shadow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlemaps/js-markermanager/463788837d1670ea191dbb909c1dbe51bd5b5ca2/examples/images/flag-shadow.png -------------------------------------------------------------------------------- /examples/images/headquarters-shadow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlemaps/js-markermanager/463788837d1670ea191dbb909c1dbe51bd5b5ca2/examples/images/headquarters-shadow.png -------------------------------------------------------------------------------- /examples/images/headquarters.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlemaps/js-markermanager/463788837d1670ea191dbb909c1dbe51bd5b5ca2/examples/images/headquarters.png -------------------------------------------------------------------------------- /examples/images/house-shadow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlemaps/js-markermanager/463788837d1670ea191dbb909c1dbe51bd5b5ca2/examples/images/house-shadow.png -------------------------------------------------------------------------------- /examples/images/house.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlemaps/js-markermanager/463788837d1670ea191dbb909c1dbe51bd5b5ca2/examples/images/house.png -------------------------------------------------------------------------------- /examples/images/rain-shadow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlemaps/js-markermanager/463788837d1670ea191dbb909c1dbe51bd5b5ca2/examples/images/rain-shadow.png -------------------------------------------------------------------------------- /examples/images/rain.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlemaps/js-markermanager/463788837d1670ea191dbb909c1dbe51bd5b5ca2/examples/images/rain.png -------------------------------------------------------------------------------- /examples/images/snow-shadow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlemaps/js-markermanager/463788837d1670ea191dbb909c1dbe51bd5b5ca2/examples/images/snow-shadow.png -------------------------------------------------------------------------------- /examples/images/snow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlemaps/js-markermanager/463788837d1670ea191dbb909c1dbe51bd5b5ca2/examples/images/snow.png -------------------------------------------------------------------------------- /examples/images/storm-shadow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlemaps/js-markermanager/463788837d1670ea191dbb909c1dbe51bd5b5ca2/examples/images/storm-shadow.png -------------------------------------------------------------------------------- /examples/images/storm.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlemaps/js-markermanager/463788837d1670ea191dbb909c1dbe51bd5b5ca2/examples/images/storm.png -------------------------------------------------------------------------------- /examples/images/sun-shadow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlemaps/js-markermanager/463788837d1670ea191dbb909c1dbe51bd5b5ca2/examples/images/sun-shadow.png -------------------------------------------------------------------------------- /examples/images/sun.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlemaps/js-markermanager/463788837d1670ea191dbb909c1dbe51bd5b5ca2/examples/images/sun.png -------------------------------------------------------------------------------- /examples/images/us.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googlemaps/js-markermanager/463788837d1670ea191dbb909c1dbe51bd5b5ca2/examples/images/us.png -------------------------------------------------------------------------------- /examples/weather_map.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Google Maps API Example - Random Weather Map 6 | 7 | 8 | 96 | 102 | 103 | 104 | 105 |
106 |
107 | Random Weather Map 108 |
109 | 110 | 111 | -------------------------------------------------------------------------------- /jest.config.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2021 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 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@googlemaps/markermanager", 3 | "version": "1.0.34", 4 | "keywords": [ 5 | "google", 6 | "maps", 7 | "marker" 8 | ], 9 | "homepage": "https://github.com/googlemaps/js-markermanager", 10 | "bugs": { 11 | "url": "https://github.com/googlemaps/js-markermanager/issues" 12 | }, 13 | "repository": { 14 | "type": "git", 15 | "url": "https://github.com/googlemaps/js-markermanager.git" 16 | }, 17 | "license": "Apache-2.0", 18 | "author": "Justin Poehnelt", 19 | "main": "dist/index.umd.js", 20 | "unpkg": "dist/index.min.js", 21 | "module": "dist/index.esm.js", 22 | "types": "dist/index.d.ts", 23 | "files": [ 24 | "dist/*" 25 | ], 26 | "scripts": { 27 | "docs": "typedoc src/index.ts && cp -r dist docs/dist && cp -r examples docs/examples", 28 | "format": "eslint . --fix", 29 | "lint": "eslint .", 30 | "prepare": "rm -rf dist && rollup -c", 31 | "test": "jest src/*", 32 | "test:e2e": "jest --passWithNoTests e2e/*" 33 | }, 34 | "dependencies": {}, 35 | "devDependencies": { 36 | "@babel/preset-env": "^7.26.0", 37 | "@babel/runtime-corejs3": "^7.25.6", 38 | "@googlemaps/jest-mocks": "^2.19.0", 39 | "@rollup/plugin-babel": "^6.0.4", 40 | "@rollup/plugin-commonjs": "^26.0.1", 41 | "@rollup/plugin-html": "^1.0.4", 42 | "@rollup/plugin-json": "^6.1.0", 43 | "@rollup/plugin-node-resolve": "^15.3.0", 44 | "@rollup/plugin-typescript": "^11.1.6", 45 | "@types/google.maps": "^3.58.1", 46 | "@types/jest": "^27.4.1", 47 | "@types/selenium-webdriver": "^4.1.26", 48 | "@typescript-eslint/eslint-plugin": ">=4.33.0", 49 | "@typescript-eslint/parser": ">=4.33.0", 50 | "chromedriver": "^131.0.1", 51 | "core-js": "^3.39.0", 52 | "eslint": "^7.32.0", 53 | "eslint-config-prettier": "^9.1.0", 54 | "eslint-plugin-jest": "^28.2.0", 55 | "eslint-plugin-prettier": "^4.2.1", 56 | "geckodriver": "^5.0.0", 57 | "jest": "^27.5.1", 58 | "prettier": "^2.8.8", 59 | "rollup": "^2.79.2", 60 | "rollup-plugin-terser": "^7.0.2", 61 | "selenium-webdriver": "^4.25.0", 62 | "ts-jest": "^27.1.4", 63 | "typedoc": "^0.26.11", 64 | "typescript": "^4.9.5" 65 | }, 66 | "publishConfig": { 67 | "access": "public", 68 | "registry": "https://wombat-dressing-room.appspot.com" 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /rollup.config.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2021 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 | 28 | export default [ 29 | { 30 | input: "src/index.ts", 31 | plugins: [ 32 | typescript({ tsconfig: "./tsconfig.json", declarationDir: "./" }), 33 | 34 | commonjs(), 35 | babel(babelOptions), 36 | terser(terserOptions), 37 | ], 38 | output: [ 39 | { 40 | file: "dist/index.umd.js", 41 | format: "umd", 42 | sourcemap: false, 43 | name: "google.maps.plugins.markermanager", 44 | }, 45 | { 46 | file: "dist/index.min.js", 47 | format: "iife", 48 | sourcemap: false, 49 | name: "google.maps.plugins.markermanager", 50 | }, 51 | ], 52 | }, 53 | { 54 | input: "src/index.ts", 55 | plugins: [ 56 | typescript({ tsconfig: "./tsconfig.json", declarationDir: "./" }), 57 | 58 | commonjs(), 59 | babel(babelOptions), 60 | terser(terserOptions), 61 | ], 62 | output: { 63 | file: "dist/index.dev.js", 64 | format: "iife", 65 | sourcemap: true, 66 | name: "google.maps.plugins.markermanager", 67 | }, 68 | }, 69 | { 70 | input: "src/index.ts", 71 | plugins: [ 72 | typescript({ tsconfig: "./tsconfig.json", declarationDir: "./" }), 73 | ], 74 | output: { 75 | file: "dist/index.esm.js", 76 | format: "esm", 77 | }, 78 | }, 79 | ]; 80 | -------------------------------------------------------------------------------- /src/gridbounds.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2019 Google LLC. All Rights Reserved. 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 | /** 18 | * Helper class to create a bounds of INT ranges. 19 | * @ignore 20 | */ 21 | export class GridBounds { 22 | public z: number; 23 | public minX: number; 24 | public maxX: number; 25 | public minY: number; 26 | public maxY: number; 27 | 28 | /** 29 | * 30 | * @param bounds 31 | * @param z 32 | */ 33 | constructor(bounds: google.maps.Point[], z: number) { 34 | // [sw, ne] 35 | this.z = z; 36 | this.minX = Math.min(bounds[0].x, bounds[1].x); 37 | this.maxX = Math.max(bounds[0].x, bounds[1].x); 38 | this.minY = Math.min(bounds[0].y, bounds[1].y); 39 | this.maxY = Math.max(bounds[0].y, bounds[1].y); 40 | } 41 | 42 | /** 43 | * Returns true if this bounds equal the given bounds. 44 | * @param {GridBounds} gridBounds GridBounds The bounds to test. 45 | * @return {Boolean} This Bounds equals the given GridBounds. 46 | */ 47 | equals(gridBounds: GridBounds): boolean { 48 | if ( 49 | this.maxX === gridBounds.maxX && 50 | this.maxY === gridBounds.maxY && 51 | this.minX === gridBounds.minX && 52 | this.minY === gridBounds.minY 53 | ) { 54 | return true; 55 | } else { 56 | return false; 57 | } 58 | } 59 | 60 | /** 61 | * Returns true if this bounds (inclusively) contains the given point. 62 | * @param {Point} point The point to test. 63 | * @return {Boolean} This Bounds contains the given Point. 64 | */ 65 | containsPoint(point: google.maps.Point): boolean { 66 | return ( 67 | this.minX <= point.x && 68 | this.maxX >= point.x && 69 | this.minY <= point.y && 70 | this.maxY >= point.y 71 | ); 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /src/index.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2019 Google LLC. All Rights Reserved. 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 | export { MarkerManager } from "./markermanager"; 18 | -------------------------------------------------------------------------------- /src/markermanager.test.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2019 Google LLC. All Rights Reserved. 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 | /// 18 | /// 19 | /* eslint-disable @typescript-eslint/no-explicit-any */ 20 | 21 | import { MarkerManager } from "./markermanager"; 22 | import { initialize } from "@googlemaps/jest-mocks"; 23 | import { GridBounds } from "./gridbounds"; 24 | 25 | beforeEach(() => { 26 | initialize(); 27 | }); 28 | 29 | test("can construct MarkerManager", () => { 30 | const zoom = 10; 31 | const map = new google.maps.Map(null); 32 | (map.getZoom as jest.Mock).mockReturnValueOnce(zoom); 33 | 34 | const mm = new MarkerManager(map, {}); 35 | 36 | expect(map.getZoom).toHaveBeenCalledTimes(1); 37 | expect(mm["_mapZoom"]).toBe(zoom); 38 | }); 39 | 40 | test("can add and remove markers", () => { 41 | const map = new google.maps.Map(null); 42 | const mm = new MarkerManager(map, {}); 43 | const marker = new google.maps.Marker(); 44 | marker.setPosition({ lat: 0, lng: 0 }); 45 | mm["_shownBounds"] = new GridBounds( 46 | [new google.maps.Point(-10, -10), new google.maps.Point(10, 10)], 47 | 6 48 | ); 49 | mm.addMarker(marker, 0, 10); 50 | 51 | expect(mm.shownMarkers).toBe(1); 52 | expect(mm.getMarker(0, 0, 0)).toBe(marker); 53 | 54 | mm.removeMarker(marker); 55 | }); 56 | -------------------------------------------------------------------------------- /src/markermanager.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2019 Google LLC. All Rights Reserved. 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 | /// 18 | 19 | import { latLngToPixel } from "./utils"; 20 | import { GridBounds } from "./gridbounds"; 21 | 22 | interface Options { 23 | maxZoom?: number; 24 | shown?: boolean; 25 | trackMarkers?: boolean; 26 | borderPadding?: number; 27 | } 28 | 29 | /** 30 | * Creates a new MarkerManager that will show/hide markers on a map. 31 | */ 32 | class MarkerManager { 33 | public shown: boolean; 34 | public shownMarkers: number; 35 | 36 | private _map: google.maps.Map; 37 | private _mapZoom: number; 38 | private _maxZoom: number; 39 | private _tileSize = 1024; 40 | private _trackMarkers: boolean; 41 | private _swPadding: google.maps.Size; 42 | private _nePadding: google.maps.Size; 43 | private _gridWidth: { [k: string]: number }; 44 | private _grid: google.maps.Marker[][][][]; 45 | private _numMarkers: { [k: string]: number }; 46 | private _shownBounds: GridBounds; 47 | 48 | /** 49 | * @constructor 50 | * @param map The map to manage. 51 | * @param {Options} options 52 | */ 53 | constructor( 54 | map: google.maps.Map, 55 | { maxZoom = 19, trackMarkers, shown = true, borderPadding = 100 }: Options 56 | ) { 57 | this._map = map; 58 | this._mapZoom = map.getZoom(); 59 | this._maxZoom = maxZoom; 60 | this._trackMarkers = trackMarkers; 61 | 62 | // The padding in pixels beyond the viewport, where we will pre-load markers. 63 | this._swPadding = new google.maps.Size(-borderPadding, borderPadding); 64 | this._nePadding = new google.maps.Size(borderPadding, -borderPadding); 65 | 66 | this._gridWidth = {}; 67 | this._grid = []; 68 | this._grid[this._maxZoom] = []; 69 | this._numMarkers = {}; 70 | this._numMarkers[this._maxZoom] = 0; 71 | 72 | this.shownMarkers = 0; 73 | this.shown = shown; 74 | 75 | google.maps.event.addListenerOnce(map, "idle", () => { 76 | this._initialize(); 77 | }); 78 | } 79 | 80 | private _initialize(): void { 81 | const mapTypes = this._map.mapTypes; 82 | 83 | // Find max zoom level 84 | let mapMaxZoom = 1; 85 | for (const sType in mapTypes) { 86 | if ( 87 | sType in mapTypes && 88 | mapTypes.get(sType) && 89 | mapTypes.get(sType).maxZoom === "number" 90 | ) { 91 | const mapTypeMaxZoom = this._map.mapTypes.get(sType).maxZoom; 92 | if (mapTypeMaxZoom > mapMaxZoom) { 93 | mapMaxZoom = mapTypeMaxZoom; 94 | } 95 | } 96 | } 97 | 98 | google.maps.event.addListener( 99 | this._map, 100 | "dragend", 101 | this._onMapMoveEnd.bind(this) 102 | ); 103 | 104 | google.maps.event.addListener( 105 | this._map, 106 | "idle", 107 | this._onMapMoveEnd.bind(this) 108 | ); 109 | 110 | google.maps.event.addListener( 111 | this._map, 112 | "zoom_changed", 113 | this._onMapMoveEnd.bind(this) 114 | ); 115 | 116 | this.resetManager(); 117 | 118 | this._shownBounds = this._getMapGridBounds(); 119 | 120 | google.maps.event.trigger(this, "loaded"); 121 | } 122 | /** 123 | * This closure provide easy access to the map. 124 | * They are used as callbacks, not as methods. 125 | * @param marker Marker to be removed from the map 126 | */ 127 | private _removeOverlay(marker: google.maps.Marker): void { 128 | marker.setMap(null); 129 | this.shownMarkers--; 130 | } 131 | 132 | /** 133 | * This closure provide easy access to the map. 134 | * They are used as callbacks, not as methods. 135 | * @param marker Marker to be added to the map 136 | */ 137 | private _addOverlay(marker: google.maps.Marker): void { 138 | if (this.shown) { 139 | marker.setMap(this._map); 140 | this.shownMarkers++; 141 | } 142 | } 143 | 144 | /** 145 | * Initializes MarkerManager arrays for all zoom levels 146 | * Called by constructor and by clearAllMarkers 147 | */ 148 | public resetManager(): void { 149 | let mapWidth = 256; 150 | for (let zoom = 0; zoom <= this._maxZoom; ++zoom) { 151 | this._grid[zoom] = []; 152 | this._numMarkers[zoom] = 0; 153 | this._gridWidth[zoom] = Math.ceil(mapWidth / this._tileSize); 154 | mapWidth <<= 1; 155 | } 156 | } 157 | 158 | /** 159 | * Removes all markers in the manager, and 160 | * removes any visible markers from the map. 161 | */ 162 | public clearMarkers(): void { 163 | this._processAll(this._shownBounds, this._removeOverlay.bind(this)); 164 | this.resetManager(); 165 | } 166 | 167 | /** 168 | * Gets the tile coordinate for a given latlng point. 169 | * 170 | * @param {LatLng} latlng The geographical point. 171 | * @param {Number} zoom The zoom level. 172 | * @param {google.maps.Size} padding The padding used to shift the pixel coordinate. 173 | * Used for expanding a bounds to include an extra padding 174 | * of pixels surrounding the bounds. 175 | * @return {GPoint} The point in tile coordinates. 176 | * 177 | */ 178 | private _getTilePoint( 179 | latlng: google.maps.LatLng, 180 | zoom: number, 181 | padding: google.maps.Size 182 | ): google.maps.Point { 183 | const pixelPoint = latLngToPixel(latlng, zoom); 184 | 185 | const point = new google.maps.Point( 186 | Math.floor((pixelPoint.x + padding.width) / this._tileSize), 187 | Math.floor((pixelPoint.y + padding.height) / this._tileSize) 188 | ); 189 | 190 | return point; 191 | } 192 | 193 | /** 194 | * Finds the appropriate place to add the marker to the grid. 195 | * Optimized for speed; does not actually add the marker to the map. 196 | * Designed for batch-_processing thousands of markers. 197 | * 198 | * @param {Marker} marker The marker to add. 199 | * @param {Number} minZoom The minimum zoom for displaying the marker. 200 | * @param {Number} maxZoom The maximum zoom for displaying the marker. 201 | */ 202 | private _addMarkerBatch( 203 | marker: google.maps.Marker, 204 | minZoom: number, 205 | maxZoom: number 206 | ): void { 207 | const mPoint = marker.getPosition(); 208 | marker.set("__minZoom", minZoom); 209 | 210 | // Tracking markers is expensive, so we do this only if the 211 | // user explicitly requested it when creating marker manager. 212 | if (this._trackMarkers) { 213 | google.maps.event.addListener( 214 | marker, 215 | "changed", 216 | ( 217 | marker: google.maps.Marker, 218 | oldPoint: google.maps.LatLng, 219 | newPoint: google.maps.LatLng 220 | ) => { 221 | this._onMarkerMoved(marker, oldPoint, newPoint); 222 | } 223 | ); 224 | } 225 | 226 | const gridPoint = this._getTilePoint( 227 | mPoint, 228 | maxZoom, 229 | new google.maps.Size(0, 0) 230 | ); 231 | 232 | for (let zoom = maxZoom; zoom >= minZoom; zoom--) { 233 | const cell = this._getGridCellCreate(gridPoint.x, gridPoint.y, zoom); 234 | cell.push(marker); 235 | 236 | gridPoint.x = gridPoint.x >> 1; 237 | gridPoint.y = gridPoint.y >> 1; 238 | } 239 | } 240 | 241 | /** 242 | * Returns whether or not the given point is visible in the shown bounds. This 243 | * is a helper method that takes care of the corner case, when shownBounds have 244 | * negative minX value. 245 | * 246 | * @param {Point} point a point on a grid. 247 | * @return {Boolean} Whether or not the given point is visible in the currently 248 | * shown bounds. 249 | */ 250 | private _isGridPointVisible(point: google.maps.Point): boolean { 251 | const vertical = 252 | this._shownBounds.minY <= point.y && point.y <= this._shownBounds.maxY; 253 | const minX = this._shownBounds.minX; 254 | let horizontal = minX <= point.x && point.x <= this._shownBounds.maxX; 255 | if (!horizontal && minX < 0) { 256 | // Shifts the negative part of the rectangle. As point.x is always less 257 | // than grid width, only test shifted minX .. 0 part of the shown bounds. 258 | const width = this._gridWidth[this._shownBounds.z]; 259 | horizontal = minX + width <= point.x && point.x <= width - 1; 260 | } 261 | return vertical && horizontal; 262 | } 263 | 264 | /** 265 | * Reacts to a notification from a marker that it has moved to a new location. 266 | * It scans the grid all all zoom levels and moves the marker from the old grid 267 | * location to a new grid location. 268 | * 269 | * @param {Marker} marker The marker that moved. 270 | * @param {LatLng} oldPoint The old position of the marker. 271 | * @param {LatLng} newPoint The new position of the marker. 272 | */ 273 | private _onMarkerMoved( 274 | marker: google.maps.Marker, 275 | oldPoint: google.maps.LatLng, 276 | newPoint: google.maps.LatLng 277 | ): void { 278 | // NOTE: We do not know the minimum or maximum zoom the marker was 279 | // added at, so we start at the absolute maximum. Whenever we successfully 280 | // remove a marker at a given zoom, we add it at the new grid coordinates. 281 | let zoom = this._maxZoom; 282 | let changed = false; 283 | const oldGrid = this._getTilePoint( 284 | oldPoint, 285 | zoom, 286 | new google.maps.Size(0, 0) 287 | ); 288 | const newGrid = this._getTilePoint( 289 | newPoint, 290 | zoom, 291 | new google.maps.Size(0, 0) 292 | ); 293 | while (zoom >= 0 && (oldGrid.x !== newGrid.x || oldGrid.y !== newGrid.y)) { 294 | const cell = this._getGridCellNoCreate(oldGrid.x, oldGrid.y, zoom); 295 | if (cell) { 296 | if (this._removeMarkerFromCell(cell, marker)) { 297 | this._getGridCellCreate(newGrid.x, newGrid.y, zoom).push(marker); 298 | } 299 | } 300 | // For the current zoom we also need to update the map. Markers that no 301 | // longer are visible are removed from the map. Markers that moved into 302 | // the shown bounds are added to the map. This also lets us keep the count 303 | // of visible markers up to date. 304 | if (zoom === this._mapZoom) { 305 | if (this._isGridPointVisible(oldGrid)) { 306 | if (!this._isGridPointVisible(newGrid)) { 307 | this._removeOverlay(marker); 308 | changed = true; 309 | } 310 | } else { 311 | if (this._isGridPointVisible(newGrid)) { 312 | this._addOverlay(marker); 313 | changed = true; 314 | } 315 | } 316 | } 317 | oldGrid.x = oldGrid.x >> 1; 318 | oldGrid.y = oldGrid.y >> 1; 319 | newGrid.x = newGrid.x >> 1; 320 | newGrid.y = newGrid.y >> 1; 321 | --zoom; 322 | } 323 | if (changed) { 324 | this._notifyListeners(); 325 | } 326 | } 327 | 328 | /** 329 | * Removes marker from the manager and from the map 330 | * (if it's currently visible). 331 | * @param {GMarker} marker The marker to delete. 332 | */ 333 | public removeMarker(marker: google.maps.Marker): void { 334 | let zoom = this._maxZoom; 335 | let changed = false; 336 | const point = marker.getPosition(); 337 | const grid = this._getTilePoint(point, zoom, new google.maps.Size(0, 0)); 338 | while (zoom >= 0) { 339 | const cell = this._getGridCellNoCreate(grid.x, grid.y, zoom); 340 | 341 | if (cell) { 342 | this._removeMarkerFromCell(cell, marker); 343 | } 344 | // For the current zoom we also need to update the map. Markers that no 345 | // longer are visible are removed from the map. This also lets us keep the count 346 | // of visible markers up to date. 347 | if (zoom === this._mapZoom) { 348 | if (this._isGridPointVisible(grid)) { 349 | this._removeOverlay(marker); 350 | changed = true; 351 | } 352 | } 353 | grid.x = grid.x >> 1; 354 | grid.y = grid.y >> 1; 355 | --zoom; 356 | } 357 | if (changed) { 358 | this._notifyListeners(); 359 | } 360 | this._numMarkers[marker.get("__minZoom")]--; 361 | } 362 | 363 | /** 364 | * Add many markers at once. 365 | * Does not actually update the map, just the internal grid. 366 | * 367 | * @param {Array of Marker} markers The markers to add. 368 | * @param {Number} minZoom The minimum zoom level to display the markers. 369 | * @param {Number} maxZoom The maximum zoom level to display the markers. 370 | */ 371 | public addMarkers( 372 | markers: google.maps.Marker[], 373 | minZoom: number, 374 | maxZoom: number 375 | ): void { 376 | maxZoom = this._getOptmaxZoom(maxZoom); 377 | for (let i = markers.length - 1; i >= 0; i--) { 378 | this._addMarkerBatch(markers[i], minZoom, maxZoom); 379 | } 380 | 381 | this._numMarkers[minZoom] += markers.length; 382 | } 383 | 384 | /** 385 | * Returns the value of the optional maximum zoom. This method is defined so 386 | * that we have just one place where optional maximum zoom is calculated. 387 | * 388 | * @param {Number} maxZoom The optinal maximum zoom. 389 | * @return The maximum zoom. 390 | */ 391 | private _getOptmaxZoom(maxZoom: number): number { 392 | return maxZoom || this._maxZoom; 393 | } 394 | 395 | /** 396 | * Calculates the total number of markers potentially visible at a given 397 | * zoom level. 398 | * 399 | * @param {Number} zoom The zoom level to check. 400 | */ 401 | public getMarkerCount(zoom: number): number { 402 | let total = 0; 403 | for (let z = 0; z <= zoom; z++) { 404 | total += this._numMarkers[z]; 405 | } 406 | return total; 407 | } 408 | 409 | /** 410 | * Returns a marker given latitude, longitude and zoom. If the marker does not 411 | * exist, the method will return a new marker. If a new marker is created, 412 | * it will NOT be added to the manager. 413 | * 414 | * @param {Number} lat - the latitude of a marker. 415 | * @param {Number} lng - the longitude of a marker. 416 | * @param {Number} zoom - the zoom level 417 | * @return {GMarker} marker - the marker found at lat and lng 418 | */ 419 | public getMarker(lat: number, lng: number, zoom: number): google.maps.Marker { 420 | const mPoint = new google.maps.LatLng(lat, lng); 421 | const gridPoint = this._getTilePoint( 422 | mPoint, 423 | zoom, 424 | new google.maps.Size(0, 0) 425 | ); 426 | 427 | let marker = new google.maps.Marker({ position: mPoint }); 428 | 429 | const cell = this._getGridCellNoCreate(gridPoint.x, gridPoint.y, zoom); 430 | if (cell !== undefined) { 431 | for (let i = 0; i < cell.length; i++) { 432 | if ( 433 | lat === cell[i].getPosition().lat() && 434 | lng === cell[i].getPosition().lng() 435 | ) { 436 | marker = cell[i]; 437 | } 438 | } 439 | } 440 | return marker; 441 | } 442 | 443 | /** 444 | * Add a single marker to the map. 445 | * 446 | * @param {Marker} marker The marker to add. 447 | * @param {Number} minZoom The minimum zoom level to display the marker. 448 | * @param {Number} maxZoom The maximum zoom level to display the marker. 449 | */ 450 | public addMarker( 451 | marker: google.maps.Marker, 452 | minZoom: number, 453 | maxZoom: number 454 | ): void { 455 | maxZoom = this._getOptmaxZoom(maxZoom); 456 | this._addMarkerBatch(marker, minZoom, maxZoom); 457 | const gridPoint = this._getTilePoint( 458 | marker.getPosition(), 459 | this._mapZoom, 460 | new google.maps.Size(0, 0) 461 | ); 462 | if ( 463 | this._isGridPointVisible(gridPoint) && 464 | minZoom <= this._shownBounds.z && 465 | this._shownBounds.z <= maxZoom 466 | ) { 467 | this._addOverlay(marker); 468 | this._notifyListeners(); 469 | } 470 | this._numMarkers[minZoom]++; 471 | } 472 | 473 | /** 474 | * Get a cell in the grid, creating it first if necessary. 475 | * 476 | * Optimization candidate 477 | * 478 | * @param {Number} x The x coordinate of the cell. 479 | * @param {Number} y The y coordinate of the cell. 480 | * @param {Number} z The z coordinate of the cell. 481 | * @return {Array} The cell in the array. 482 | */ 483 | private _getGridCellCreate( 484 | x: number, 485 | y: number, 486 | z: number 487 | ): google.maps.Marker[] { 488 | // TODO document this 489 | if (x < 0) { 490 | x += this._gridWidth[z]; 491 | } 492 | 493 | if (!this._grid[z]) { 494 | this._grid[z] = []; 495 | } 496 | if (!this._grid[z][x]) { 497 | this._grid[z][x] = []; 498 | } 499 | if (!this._grid[z][x][y]) { 500 | this._grid[z][x][y] = []; 501 | } 502 | return this._grid[z][x][y]; 503 | } 504 | 505 | /** 506 | * Get a cell in the grid, returning undefined if it does not exist. 507 | * 508 | * NOTE: Optimized for speed -- otherwise could combine with _getGridCellCreate. 509 | * 510 | * @param {Number} x The x coordinate of the cell. 511 | * @param {Number} y The y coordinate of the cell. 512 | * @param {Number} z The z coordinate of the cell. 513 | * @return {Array} The cell in the array. 514 | */ 515 | private _getGridCellNoCreate( 516 | x: number, 517 | y: number, 518 | z: number 519 | ): google.maps.Marker[] | null { 520 | if (x < 0) { 521 | x += this._gridWidth[z]; 522 | } 523 | 524 | if (!this._grid[z]) { 525 | return null; 526 | } 527 | if (!this._grid[z][x]) { 528 | return null; 529 | } 530 | if (!this._grid[z][x][y]) { 531 | return null; 532 | } 533 | return this._grid[z][x][y]; 534 | } 535 | 536 | /** 537 | * Turns at geographical bounds into a grid-space bounds. 538 | * 539 | * @param {LatLngBounds} bounds The geographical bounds. 540 | * @param {Number} zoom The zoom level of the bounds. 541 | * @param {google.maps.Size} swPadding The padding in pixels to extend beyond the 542 | * given bounds. 543 | * @param {google.maps.Size} nePadding The padding in pixels to extend beyond the 544 | * given bounds. 545 | * @return {GridBounds} The bounds in grid space. 546 | */ 547 | private _getGridBounds( 548 | bounds: google.maps.LatLngBounds, 549 | zoom: number, 550 | swPadding: google.maps.Size, 551 | nePadding: google.maps.Size 552 | ): GridBounds { 553 | zoom = Math.min(zoom, this._maxZoom); 554 | 555 | const bl = bounds.getSouthWest(); 556 | const tr = bounds.getNorthEast(); 557 | const sw = this._getTilePoint(bl, zoom, swPadding); 558 | 559 | const ne = this._getTilePoint(tr, zoom, nePadding); 560 | const gw = this._gridWidth[zoom]; 561 | 562 | // Crossing the prime meridian requires correction of bounds. 563 | if (tr.lng() < bl.lng() || ne.x < sw.x) { 564 | sw.x -= gw; 565 | } 566 | if (ne.x - sw.x + 1 >= gw) { 567 | // Computed grid bounds are larger than the world; truncate. 568 | sw.x = 0; 569 | ne.x = gw - 1; 570 | } 571 | 572 | const gridBounds = new GridBounds([sw, ne], zoom); 573 | gridBounds.z = zoom; 574 | 575 | return gridBounds; 576 | } 577 | 578 | /** 579 | * Gets the grid-space bounds for the current map viewport. 580 | * 581 | * @return {Bounds} The bounds in grid space. 582 | */ 583 | private _getMapGridBounds(): GridBounds { 584 | return this._getGridBounds( 585 | this._map.getBounds(), 586 | this._mapZoom, 587 | this._swPadding, 588 | this._nePadding 589 | ); 590 | } 591 | 592 | /** 593 | * Event listener for map:movend. 594 | * NOTE: Use a timeout so that the user is not blocked 595 | * from moving the map. 596 | * 597 | * Removed this because a a lack of a scopy override/callback function on events. 598 | */ 599 | private _onMapMoveEnd(): void { 600 | window.setTimeout(this._updateMarkers.bind(this), 0); 601 | } 602 | 603 | /** 604 | * Is this layer visible? 605 | * 606 | * Returns visibility setting 607 | * 608 | * @return {Boolean} Visible 609 | */ 610 | public visible(): boolean { 611 | return this.shown ? true : false; 612 | } 613 | 614 | /** 615 | * Returns true if the manager is hidden. 616 | * Otherwise returns false. 617 | * @return {Boolean} Hidden 618 | */ 619 | public isHidden(): boolean { 620 | return !this.shown; 621 | } 622 | 623 | /** 624 | * Shows the manager if it's currently hidden. 625 | */ 626 | public show(): void { 627 | this.shown = true; 628 | this.refresh(); 629 | } 630 | 631 | /** 632 | * Hides the manager if it's currently visible 633 | */ 634 | public hide(): void { 635 | this.shown = false; 636 | this.refresh(); 637 | } 638 | 639 | /** 640 | * Toggles the visibility of the manager. 641 | */ 642 | public toggle(): void { 643 | this.shown = !this.shown; 644 | this.refresh(); 645 | } 646 | 647 | /** 648 | * Refresh forces the marker-manager into a good state. 649 | *
    650 | *
  1. If never before initialized, shows all the markers.
  2. 651 | *
  3. If previously initialized, removes and re-adds all markers.
  4. 652 | *
653 | */ 654 | public refresh(): void { 655 | if (this.shownMarkers > 0) { 656 | this._processAll(this._shownBounds, this._removeOverlay.bind(this)); 657 | } 658 | // An extra check on this.show to increase performance (no need to _processAll_) 659 | if (this.show) { 660 | this._processAll(this._shownBounds, this._addOverlay.bind(this)); 661 | } 662 | this._notifyListeners(); 663 | } 664 | 665 | /** 666 | * After the viewport may have changed, add or remove markers as needed. 667 | */ 668 | private _updateMarkers(): void { 669 | this._mapZoom = this._map.getZoom(); 670 | const newBounds = this._getMapGridBounds(); 671 | 672 | // If the move does not include new grid sections, 673 | // we have no work to do: 674 | if ( 675 | newBounds.equals(this._shownBounds) && 676 | newBounds.z === this._shownBounds.z 677 | ) { 678 | return; 679 | } 680 | 681 | if (newBounds.z !== this._shownBounds.z) { 682 | this._processAll(this._shownBounds, this._removeOverlay.bind(this)); 683 | if (this.show) { 684 | // performance 685 | this._processAll(newBounds, this._addOverlay.bind(this)); 686 | } 687 | } else { 688 | // Remove markers: 689 | this._rectangleDiff( 690 | this._shownBounds, 691 | newBounds, 692 | this._removeCellMarkers.bind(this) 693 | ); 694 | 695 | // Add markers: 696 | if (this.show) { 697 | // performance 698 | this._rectangleDiff( 699 | newBounds, 700 | this._shownBounds, 701 | this._addCellMarkers.bind(this) 702 | ); 703 | } 704 | } 705 | this._shownBounds = newBounds; 706 | 707 | this._notifyListeners(); 708 | } 709 | 710 | /** 711 | * Notify listeners when the state of what is displayed changes. 712 | */ 713 | private _notifyListeners(): void { 714 | google.maps.event.trigger( 715 | this, 716 | "changed", 717 | this._shownBounds, 718 | this.shownMarkers 719 | ); 720 | } 721 | 722 | /** 723 | * Process all markers in the bounds provided, using a callback. 724 | * 725 | * @param {Bounds} bounds The bounds in grid space. 726 | * @param {Function} callback The function to call for each marker. 727 | */ 728 | private _processAll( 729 | bounds: GridBounds, 730 | callback: (marker: google.maps.Marker) => void 731 | ): void { 732 | for (let x = bounds.minX; x <= bounds.maxX; x++) { 733 | for (let y = bounds.minY; y <= bounds.maxY; y++) { 734 | this._processCellMarkers(x, y, bounds.z, callback); 735 | } 736 | } 737 | } 738 | 739 | /** 740 | * Process all markers in the grid cell, using a callback. 741 | * 742 | * @param {Number} x The x coordinate of the cell. 743 | * @param {Number} y The y coordinate of the cell. 744 | * @param {Number} z The z coordinate of the cell. 745 | * @param {Function} callback The function to call for each marker. 746 | */ 747 | private _processCellMarkers( 748 | x: number, 749 | y: number, 750 | z: number, 751 | callback: (marker: google.maps.Marker) => void 752 | ): void { 753 | const cell = this._getGridCellNoCreate(x, y, z); 754 | if (cell) { 755 | for (let i = cell.length - 1; i >= 0; i--) { 756 | callback(cell[i]); 757 | } 758 | } 759 | } 760 | 761 | /** 762 | * Remove all markers in a grid cell. 763 | * 764 | * @param {Number} x The x coordinate of the cell. 765 | * @param {Number} y The y coordinate of the cell. 766 | * @param {Number} z The z coordinate of the cell. 767 | */ 768 | private _removeCellMarkers(x: number, y: number, z: number): void { 769 | this._processCellMarkers(x, y, z, this._removeOverlay.bind(this)); 770 | } 771 | 772 | /** 773 | * Add all markers in a grid cell. 774 | * 775 | * @param {Number} x The x coordinate of the cell. 776 | * @param {Number} y The y coordinate of the cell. 777 | * @param {Number} z The z coordinate of the cell. 778 | */ 779 | private _addCellMarkers(x: number, y: number, z: number): void { 780 | this._processCellMarkers(x, y, z, this._addOverlay.bind(this)); 781 | } 782 | 783 | /** 784 | * Use the _rectangleDiffCoords function to process all grid cells 785 | * that are in bounds1 but not bounds2, using a callback, and using 786 | * the current MarkerManager object as the instance. 787 | * 788 | * Pass the z parameter to the callback in addition to x and y. 789 | * 790 | * @param {Bounds} bounds1 The bounds of all points we may _process. 791 | * @param {Bounds} bounds2 The bounds of points to exclude. 792 | * @param {Function} callback The callback function to call 793 | * for each grid coordinate (x, y, z). 794 | */ 795 | private _rectangleDiff( 796 | bounds1: GridBounds, 797 | bounds2: GridBounds, 798 | callback: (x: number, y: number, z: number) => void 799 | ): void { 800 | this._rectangleDiffCoords(bounds1, bounds2, (x, y) => { 801 | callback(x, y, bounds1.z); 802 | }); 803 | } 804 | 805 | /** 806 | * Calls the function for all points in bounds1, not in bounds2 807 | * 808 | * @param {Bounds} bounds1 The bounds of all points we may process. 809 | * @param {Bounds} bounds2 The bounds of points to exclude. 810 | * @param {Function} callback The callback function to call 811 | * for each grid coordinate. 812 | */ 813 | private _rectangleDiffCoords( 814 | bounds1: GridBounds, 815 | bounds2: GridBounds, 816 | callback: (x: number, y: number) => void 817 | ): void { 818 | const minX1 = bounds1.minX; 819 | const minY1 = bounds1.minY; 820 | const maxX1 = bounds1.maxX; 821 | const maxY1 = bounds1.maxY; 822 | const minX2 = bounds2.minX; 823 | const minY2 = bounds2.minY; 824 | const maxX2 = bounds2.maxX; 825 | const maxY2 = bounds2.maxY; 826 | 827 | let x, y; 828 | for (x = minX1; x <= maxX1; x++) { 829 | // All x in R1 830 | // All above: 831 | for (y = minY1; y <= maxY1 && y < minY2; y++) { 832 | // y in R1 above R2 833 | callback(x, y); 834 | } 835 | // All below: 836 | for ( 837 | y = Math.max(maxY2 + 1, minY1); // y in R1 below R2 838 | y <= maxY1; 839 | y++ 840 | ) { 841 | callback(x, y); 842 | } 843 | } 844 | 845 | for (y = Math.max(minY1, minY2); y <= Math.min(maxY1, maxY2); y++) { 846 | // All y in R2 and in R1 847 | // Strictly left: 848 | for (x = Math.min(maxX1 + 1, minX2) - 1; x >= minX1; x--) { 849 | // x in R1 left of R2 850 | callback(x, y); 851 | } 852 | // Strictly right: 853 | for ( 854 | x = Math.max(minX1, maxX2 + 1); // x in R1 right of R2 855 | x <= maxX1; 856 | x++ 857 | ) { 858 | callback(x, y); 859 | } 860 | } 861 | } 862 | 863 | /** 864 | * Removes marker from cell. O(N). 865 | */ 866 | private _removeMarkerFromCell( 867 | cell: google.maps.Marker[], 868 | marker: google.maps.Marker 869 | ): number { 870 | let shift = 0; 871 | for (let i = 0; i < cell.length; ++i) { 872 | if (cell[i] === marker) { 873 | cell.splice(i--, 1); 874 | shift++; 875 | } 876 | } 877 | return shift; 878 | } 879 | } 880 | 881 | export { MarkerManager }; 882 | -------------------------------------------------------------------------------- /src/utils.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2019 Google LLC. All Rights Reserved. 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 | /** 18 | * @ignore 19 | * 20 | * @param lng 21 | */ 22 | function lngToX(lng: number): number { 23 | return 1 + lng / 180; 24 | } 25 | /** 26 | * @ignore 27 | * 28 | * @param {number} lat 29 | * @returns {number} 30 | */ 31 | function latToY(lat: number): number { 32 | const sinofphi = Math.sin((lat * Math.PI) / 180); 33 | return 1 - (0.5 / Math.PI) * Math.log((1 + sinofphi) / (1 - sinofphi)); 34 | } 35 | 36 | /** 37 | * @ignore 38 | * 39 | * @param latlng 40 | * @param zoom 41 | */ 42 | export function latLngToPixel( 43 | latlng: google.maps.LatLng, 44 | zoom: number 45 | ): google.maps.Point { 46 | return new google.maps.Point( 47 | ~~(0.5 + lngToX(latlng.lng()) * (2 << (zoom + 6))), 48 | ~~(0.5 + latToY(latlng.lat()) * (2 << (zoom + 6))) 49 | ); 50 | } 51 | -------------------------------------------------------------------------------- /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": ["DOM", "ESNext", "ES2019"], 10 | "target": "ES6", 11 | "moduleResolution": "node", 12 | "skipLibCheck": true, 13 | "resolveJsonModule": true 14 | }, 15 | "include": ["src/**/*"], 16 | "exclude": ["node_modules", "./dist"] 17 | } 18 | -------------------------------------------------------------------------------- /typedoc.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2021 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: "@googlemaps/markermanager", 21 | excludePrivate: true, 22 | }; 23 | --------------------------------------------------------------------------------