├── .all-contributorsrc ├── .commitlintrc ├── .eslintignore ├── .eslintrc ├── .gitattributes ├── .github └── workflows │ ├── deploy-docs.yml │ └── test-deploy-docs.yml ├── .gitignore ├── .husky ├── commit-msg └── pre-commit ├── .prettierrc ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── babel.config.js ├── docs ├── .gitignore ├── README.md ├── babel.config.js ├── docs │ ├── examples │ │ ├── _category_.json │ │ ├── expo.md │ │ └── solito.md │ ├── extra-features │ │ ├── _category_.json │ │ └── clustering.md │ ├── getting-started.md │ ├── index.md │ ├── installation │ │ ├── _category_.json │ │ ├── expo-web.md │ │ ├── next-js.md │ │ └── webpack.md │ └── support │ │ ├── _category_.json │ │ ├── callout.md │ │ ├── circle.md │ │ ├── geojson.md │ │ ├── heat-map.md │ │ ├── map-view.md │ │ ├── marker.md │ │ ├── overlay.md │ │ ├── polygon.md │ │ └── polyline.md ├── docusaurus.config.js ├── package.json ├── sidebars.js ├── src │ └── css │ │ └── custom.css ├── static │ ├── .nojekyll │ └── img │ │ ├── docusaurus.png │ │ ├── favicon.ico │ │ ├── logo.svg │ │ ├── undraw_docusaurus_mountain.svg │ │ ├── undraw_docusaurus_react.svg │ │ └── undraw_docusaurus_tree.svg └── tsconfig.json ├── example ├── .expo-shared │ └── assets.json ├── .gitignore ├── App.tsx ├── app.d.ts ├── app.json ├── assets │ ├── adaptive-icon.png │ ├── favicon.png │ ├── icon.png │ └── splash.png ├── babel.config.js ├── index.js ├── metro.config.js ├── package.json ├── tsconfig.json └── webpack.config.js ├── package.json ├── packages └── react-native-web-maps │ ├── .eslintrc │ ├── README.md │ ├── babel.config.js │ ├── jest.config.js │ ├── jest.setup.js │ ├── package.json │ ├── src │ ├── __tests__ │ │ └── map-view.test.tsx │ ├── components │ │ ├── callout.tsx │ │ ├── circle.tsx │ │ ├── geojson.tsx │ │ ├── heat-map.tsx │ │ ├── map-view.tsx │ │ ├── marker-clusterer │ │ │ ├── cluster.tsx │ │ │ ├── index.ts │ │ │ ├── marker-clusterer.tsx │ │ │ └── types.ts │ │ ├── marker.tsx │ │ ├── marker.web.tsx │ │ ├── polygon.tsx │ │ ├── polyline.tsx │ │ └── user-location-marker.tsx │ ├── hooks │ │ └── use-user-location.tsx │ ├── index.tsx │ ├── index.web.tsx │ ├── override-types.ts │ └── utils │ │ ├── camera.ts │ │ ├── geojson.ts │ │ ├── log.ts │ │ ├── mouse-event.ts │ │ └── region.ts │ ├── tsconfig.build.json │ └── tsconfig.json └── turbo.json /.all-contributorsrc: -------------------------------------------------------------------------------- 1 | { 2 | "files": [ 3 | "README.md" 4 | ], 5 | "imageSize": 100, 6 | "commit": false, 7 | "contributors": [ 8 | { 9 | "login": "teovillanueva", 10 | "name": "Teodoro Villanueva", 11 | "avatar_url": "https://avatars.githubusercontent.com/u/41754896?v=4", 12 | "profile": "https://greener.bio", 13 | "contributions": [ 14 | "maintenance", 15 | "doc", 16 | "code" 17 | ] 18 | }, 19 | { 20 | "login": "artalat", 21 | "name": "Abdul Rehman Talat", 22 | "avatar_url": "https://avatars.githubusercontent.com/u/295630?v=4", 23 | "profile": "https://github.com/artalat", 24 | "contributions": [ 25 | "code" 26 | ] 27 | }, 28 | { 29 | "login": "tobysmith", 30 | "name": "Toby Smith", 31 | "avatar_url": "https://avatars.githubusercontent.com/u/1110053?v=4", 32 | "profile": "https://github.com/tobysmith", 33 | "contributions": [ 34 | "doc", 35 | "code" 36 | ] 37 | }, 38 | { 39 | "login": "YoussefHenna", 40 | "name": "Youssef Henna", 41 | "avatar_url": "https://avatars.githubusercontent.com/u/58384527?v=4", 42 | "profile": "https://github.com/YoussefHenna", 43 | "contributions": [ 44 | "doc", 45 | "code" 46 | ] 47 | }, 48 | { 49 | "login": "sreuter", 50 | "name": "Sascha Reuter", 51 | "avatar_url": "https://avatars.githubusercontent.com/u/550246?v=4", 52 | "profile": "https://github.com/sreuter", 53 | "contributions": [ 54 | "code" 55 | ] 56 | } 57 | ], 58 | "contributorsPerLine": 7, 59 | "projectName": "react-native-web-maps", 60 | "projectOwner": "teovillanueva", 61 | "repoType": "github", 62 | "repoHost": "https://github.com", 63 | "skipCi": true, 64 | "commitConvention": "angular", 65 | "commitType": "docs" 66 | } 67 | -------------------------------------------------------------------------------- /.commitlintrc: -------------------------------------------------------------------------------- 1 | { 2 | "extends": [ 3 | "@commitlint/config-conventional" 4 | ], 5 | "scope-enum": [ 6 | 2, 7 | "always", 8 | [ 9 | "docs", 10 | "lib", 11 | "example", 12 | "root" 13 | ] 14 | ] 15 | } 16 | -------------------------------------------------------------------------------- /.eslintignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | dist 3 | example 4 | *.config.js -------------------------------------------------------------------------------- /.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "root": true, 3 | "parser": "@babel/eslint-parser", 4 | "extends": ["prettier"], 5 | "plugins": ["prettier"], 6 | "rules": { 7 | "prettier/prettier": [ 8 | "error", 9 | { 10 | "quoteProps": "consistent", 11 | "singleQuote": true, 12 | "tabWidth": 2, 13 | "trailingComma": "es5", 14 | "useTabs": false 15 | } 16 | ] 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | *.pbxproj -text 2 | # specific for windows script files 3 | *.bat text eol=crlf -------------------------------------------------------------------------------- /.github/workflows/deploy-docs.yml: -------------------------------------------------------------------------------- 1 | name: Deploy to GitHub Pages 2 | 3 | defaults: 4 | run: 5 | working-directory: docs 6 | 7 | on: 8 | push: 9 | paths: 10 | - 'docs/**' 11 | branches: 12 | - main 13 | 14 | jobs: 15 | deploy: 16 | name: Deploy to GitHub Pages 17 | runs-on: ubuntu-latest 18 | steps: 19 | - uses: actions/checkout@v2 20 | - uses: actions/setup-node@v3 21 | with: 22 | node-version: 16.x 23 | cache: yarn 24 | 25 | - name: Install dependencies 26 | run: yarn install --frozen-lockfile 27 | - name: Build docs 28 | run: yarn build 29 | 30 | - name: Deploy to GitHub Pages 31 | uses: peaceiris/actions-gh-pages@v3 32 | with: 33 | github_token: ${{ secrets.GITHUB_TOKEN }} 34 | publish_dir: ./docs/build 35 | user_name: github-actions[bot] 36 | user_email: 41898282+github-actions[bot]@users.noreply.github.com 37 | -------------------------------------------------------------------------------- /.github/workflows/test-deploy-docs.yml: -------------------------------------------------------------------------------- 1 | name: Test deployment 2 | 3 | defaults: 4 | run: 5 | working-directory: docs 6 | 7 | on: 8 | pull_request: 9 | paths: 10 | - 'docs/**' 11 | branches: 12 | - main 13 | 14 | jobs: 15 | test-deploy: 16 | name: Test deployment 17 | runs-on: ubuntu-latest 18 | steps: 19 | - uses: actions/checkout@v2 20 | - uses: actions/setup-node@v3 21 | with: 22 | node-version: 16.x 23 | cache: yarn 24 | 25 | - name: Install dependencies 26 | run: yarn install --frozen-lockfile 27 | - name: Test build docs 28 | run: yarn build 29 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # OSX 2 | # 3 | .DS_Store 4 | 5 | # XDE 6 | .expo/ 7 | 8 | # VSCode 9 | .vscode/ 10 | jsconfig.json 11 | 12 | yarn.lock 13 | 14 | # Xcode 15 | # 16 | build/ 17 | *.pbxuser 18 | !default.pbxuser 19 | *.mode1v3 20 | !default.mode1v3 21 | *.mode2v3 22 | !default.mode2v3 23 | *.perspectivev3 24 | !default.perspectivev3 25 | xcuserdata 26 | *.xccheckout 27 | *.moved-aside 28 | DerivedData 29 | *.hmap 30 | *.ipa 31 | *.xcuserstate 32 | project.xcworkspace 33 | 34 | # Android/IJ 35 | # 36 | .classpath 37 | .cxx 38 | .gradle 39 | .idea 40 | .project 41 | .settings 42 | local.properties 43 | android.iml 44 | 45 | # Cocoapods 46 | # 47 | example/ios/Pods 48 | 49 | # node.js 50 | # 51 | node_modules/ 52 | npm-debug.log 53 | yarn-debug.log 54 | yarn-error.log 55 | 56 | # BUCK 57 | buck-out/ 58 | \.buckd/ 59 | android/app/libs 60 | android/keystores/debug.keystore 61 | 62 | # Expo 63 | .expo/* 64 | 65 | # generated by bob 66 | dist/ 67 | .turbo 68 | package-lock.json 69 | .env 70 | -------------------------------------------------------------------------------- /.husky/commit-msg: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | . "$(dirname "$0")/_/husky.sh" 3 | 4 | npx --no -- commitlint --edit "${1}" 5 | -------------------------------------------------------------------------------- /.husky/pre-commit: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | . "$(dirname -- "$0")/_/husky.sh" 3 | 4 | yarn lint-staged 5 | -------------------------------------------------------------------------------- /.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "quoteProps": "consistent", 3 | "singleQuote": true, 4 | "tabWidth": 2, 5 | "trailingComma": "es5", 6 | "useTabs": false 7 | } 8 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | We want this community to be friendly and respectful to each other. Please follow it in all your interactions with the project. 4 | 5 | ## Development workflow 6 | 7 | To get started with the project, run `yarn` in the root directory to install the required dependencies for each package: 8 | 9 | ```sh 10 | yarn 11 | ``` 12 | 13 | > While it's possible to use [`npm`](https://github.com/npm/cli), the tooling is built around [`yarn`](https://classic.yarnpkg.com/), so you'll have an easier time if you use `yarn` for development. 14 | 15 | While developing, you can run the [example app](/example/) to test your changes. Any changes you make in your library's JavaScript code will be reflected in the example app without a rebuild. If you change any native code, then you'll need to rebuild the example app. 16 | 17 | To start the packager: 18 | 19 | ```sh 20 | yarn example start 21 | ``` 22 | 23 | Make sure your code passes TypeScript and ESLint. Run the following to verify: 24 | 25 | ```sh 26 | yarn typescript 27 | yarn lint 28 | ``` 29 | 30 | To fix formatting errors, run the following: 31 | 32 | ```sh 33 | yarn lint --fix 34 | ``` 35 | 36 | Remember to add tests for your change if possible. Run the unit tests by: 37 | 38 | ```sh 39 | yarn test 40 | ``` 41 | 42 | ### Commit message convention 43 | 44 | We follow the [conventional commits specification](https://www.conventionalcommits.org/en) for our commit messages: 45 | 46 | - `fix`: bug fixes, e.g. fix crash due to deprecated method. 47 | - `feat`: new features, e.g. add new method to the module. 48 | - `refactor`: code refactor, e.g. migrate from class components to hooks. 49 | - `docs`: changes into documentation, e.g. add usage example for the module.. 50 | - `test`: adding or updating tests, e.g. add integration tests using detox. 51 | - `chore`: tooling changes, e.g. change CI config. 52 | 53 | Our pre-commit hooks verify that your commit message matches this format when committing. 54 | 55 | ### Linting and tests 56 | 57 | [ESLint](https://eslint.org/), [Prettier](https://prettier.io/), [TypeScript](https://www.typescriptlang.org/) 58 | 59 | We use [TypeScript](https://www.typescriptlang.org/) for type checking, [ESLint](https://eslint.org/) with [Prettier](https://prettier.io/) for linting and formatting the code, and [Jest](https://jestjs.io/) for testing. 60 | 61 | Our pre-commit hooks verify that the linter and tests pass when committing. 62 | 63 | ### Publishing to npm 64 | 65 | We use [release-it](https://github.com/release-it/release-it) to make it easier to publish new versions. It handles common tasks like bumping version based on semver, creating tags and releases etc. 66 | 67 | To publish new versions, run the following: 68 | 69 | ```sh 70 | yarn release 71 | ``` 72 | 73 | ### Scripts 74 | 75 | The `package.json` file contains various scripts for common tasks: 76 | 77 | - `yarn typescript`: type-check files with TypeScript. 78 | - `yarn lint`: lint files with ESLint. 79 | - `yarn test`: run unit tests with Jest. 80 | - `yarn example start`: start the Metro server for the example app. 81 | 82 | ### Sending a pull request 83 | 84 | > **Working on your first pull request?** You can learn how from this _free_ series: [How to Contribute to an Open Source Project on GitHub](https://app.egghead.io/playlists/how-to-contribute-to-an-open-source-project-on-github). 85 | 86 | When you're sending a pull request: 87 | 88 | - Prefer small pull requests focused on one change. 89 | - Verify that linters and tests are passing. 90 | - Review the documentation to make sure it looks good. 91 | - Follow the pull request template when opening a pull request. 92 | - For pull requests that change the API or implementation, discuss with maintainers first by opening an issue. 93 | 94 | ## Code of Conduct 95 | 96 | ### Our Pledge 97 | 98 | We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation. 99 | 100 | We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community. 101 | 102 | ### Our Standards 103 | 104 | Examples of behavior that contributes to a positive environment for our community include: 105 | 106 | - Demonstrating empathy and kindness toward other people 107 | - Being respectful of differing opinions, viewpoints, and experiences 108 | - Giving and gracefully accepting constructive feedback 109 | - Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience 110 | - Focusing on what is best not just for us as individuals, but for the overall community 111 | 112 | Examples of unacceptable behavior include: 113 | 114 | - The use of sexualized language or imagery, and sexual attention or 115 | advances of any kind 116 | - Trolling, insulting or derogatory comments, and personal or political attacks 117 | - Public or private harassment 118 | - Publishing others' private information, such as a physical or email 119 | address, without their explicit permission 120 | - Other conduct which could reasonably be considered inappropriate in a 121 | professional setting 122 | 123 | ### Enforcement Responsibilities 124 | 125 | Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful. 126 | 127 | Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate. 128 | 129 | ### Scope 130 | 131 | This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. 132 | 133 | ### Enforcement 134 | 135 | Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at [INSERT CONTACT METHOD]. All complaints will be reviewed and investigated promptly and fairly. 136 | 137 | All community leaders are obligated to respect the privacy and security of the reporter of any incident. 138 | 139 | ### Enforcement Guidelines 140 | 141 | Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct: 142 | 143 | #### 1. Correction 144 | 145 | **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community. 146 | 147 | **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested. 148 | 149 | #### 2. Warning 150 | 151 | **Community Impact**: A violation through a single incident or series of actions. 152 | 153 | **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban. 154 | 155 | #### 3. Temporary Ban 156 | 157 | **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior. 158 | 159 | **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban. 160 | 161 | #### 4. Permanent Ban 162 | 163 | **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals. 164 | 165 | **Consequence**: A permanent ban from any sort of public interaction within the community. 166 | 167 | ### Attribution 168 | 169 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0, 170 | available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html. 171 | 172 | Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity). 173 | 174 | [homepage]: https://www.contributor-covenant.org 175 | 176 | For answers to common questions about this code of conduct, see the FAQ at 177 | https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations. 178 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 Teodoro Villanueva 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all 12 | copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | SOFTWARE. 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # @teovilla/react-native-web-maps 2 | 3 | 4 | [![All Contributors](https://img.shields.io/badge/all_contributors-5-orange.svg?style=flat-square)](#contributors-) 5 | 6 | 7 | Cross platfrom maps for react & react-native 8 | 9 | ## Installation 10 | 11 | ```bash 12 | $ yarn add @teovilla/react-native-web-maps 13 | ``` 14 | 15 | ## Usage with Expo web / Webpack 16 | 17 | For this to work you must alias `react-native-maps` to `@teovilla/react-native-web-maps` in your webpack config. 18 | 19 | ### Example with Expo Web: 20 | 21 | ```js 22 | // webpack.config.js 23 | 24 | module.exports = async function (env, argv) { 25 | const config = await createExpoWebpackConfigAsync(env, argv); 26 | 27 | config.resolve.alias['react-native-maps'] = '@teovilla/react-native-web-maps'; 28 | 29 | return config; 30 | }; 31 | ``` 32 | 33 | ### Example with Next.js: 34 | 35 | ```js 36 | // next.config.js 37 | 38 | module.exports = { 39 | webpack: (config) => { 40 | config.resolve.alias = { 41 | ...(config.resolve.alias || {}), 42 | 'react-native-maps$': '@teovilla/react-native-web-maps', 43 | }; 44 | 45 | return config; 46 | }, 47 | }; 48 | ``` 49 | 50 | ## Documentation 51 | 52 | The docs for the project can be found [here](https://teovillanueva.github.io/react-native-web-maps/). 53 | 54 | ## Contributing 55 | 56 | See the [contributing guide](CONTRIBUTING.md) to learn how to contribute to the repository and the development workflow. 57 | 58 | ## License 59 | 60 | MIT 61 | 62 | --- 63 | 64 | Made with [create-react-native-library](https://github.com/callstack/react-native-builder-bob) 65 | 66 | ## Contributors ✨ 67 | 68 | Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)): 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 |
Teodoro Villanueva
Teodoro Villanueva

🚧 📖 💻
Abdul Rehman Talat
Abdul Rehman Talat

💻
Toby Smith
Toby Smith

📖 💻
Youssef Henna
Youssef Henna

📖 💻
Sascha Reuter
Sascha Reuter

💻
84 | 85 | 86 | 87 | 88 | 89 | 90 | This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome! 91 | -------------------------------------------------------------------------------- /babel.config.js: -------------------------------------------------------------------------------- 1 | module.exports = function(api) { 2 | api.cache(true); 3 | return { 4 | presets: ['babel-preset-expo'], 5 | }; 6 | }; 7 | -------------------------------------------------------------------------------- /docs/.gitignore: -------------------------------------------------------------------------------- 1 | # Dependencies 2 | /node_modules 3 | 4 | # Production 5 | /build 6 | 7 | # Generated files 8 | .docusaurus 9 | .cache-loader 10 | 11 | # Misc 12 | .DS_Store 13 | .env.local 14 | .env.development.local 15 | .env.test.local 16 | .env.production.local 17 | 18 | npm-debug.log* 19 | yarn-debug.log* 20 | yarn-error.log* 21 | -------------------------------------------------------------------------------- /docs/README.md: -------------------------------------------------------------------------------- 1 | # Website 2 | 3 | This website is built using [Docusaurus 2](https://docusaurus.io/), a modern static website generator. 4 | 5 | ### Installation 6 | 7 | ``` 8 | $ yarn 9 | ``` 10 | 11 | ### Local Development 12 | 13 | ``` 14 | $ yarn start 15 | ``` 16 | 17 | This command starts a local development server and opens up a browser window. Most changes are reflected live without having to restart the server. 18 | 19 | ### Build 20 | 21 | ``` 22 | $ yarn build 23 | ``` 24 | 25 | This command generates static content into the `build` directory and can be served using any static contents hosting service. 26 | 27 | ### Deployment 28 | 29 | Using SSH: 30 | 31 | ``` 32 | $ USE_SSH=true yarn deploy 33 | ``` 34 | 35 | Not using SSH: 36 | 37 | ``` 38 | $ GIT_USER= yarn deploy 39 | ``` 40 | 41 | If you are using GitHub pages for hosting, this command is a convenient way to build the website and push to the `gh-pages` branch. 42 | -------------------------------------------------------------------------------- /docs/babel.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | presets: [require.resolve('@docusaurus/core/lib/babel/preset')], 3 | }; 4 | -------------------------------------------------------------------------------- /docs/docs/examples/_category_.json: -------------------------------------------------------------------------------- 1 | { 2 | "label": "Examples", 3 | "position": 4 4 | } 5 | -------------------------------------------------------------------------------- /docs/docs/examples/expo.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Expo 3 | --- 4 | 5 | You can find the example using Expo [here](https://github.com/teovillanueva/react-native-web-maps/tree/main/example) 6 | -------------------------------------------------------------------------------- /docs/docs/examples/solito.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Solito 3 | --- 4 | 5 | You can find the example using Solito [here](https://github.com/teovillanueva/react-native-web-maps-solito-example) 6 | -------------------------------------------------------------------------------- /docs/docs/extra-features/_category_.json: -------------------------------------------------------------------------------- 1 | { 2 | "label": "Extra features", 3 | "position": 6 4 | } 5 | -------------------------------------------------------------------------------- /docs/docs/extra-features/clustering.md: -------------------------------------------------------------------------------- 1 | --- 2 | sidebar_position: 3 3 | title: Clustering 4 | --- 5 | 6 | This feature has not been fully tested. Therefore I wouldn't really recommend it for production use yet. But it does work pretty good 😅. It uses [Supercluster](https://github.com/mapbox/supercluster) under the hood. 7 | 8 | ## Props 9 | 10 | | Prop | Type | Notes | 11 | | --------------- | ------------------------------------------- | ------------------------------------------------------------------------------------------------------- | 12 | | `region` | `Region` | The region being displayed by the map | 13 | | `children` | `React.ReactElement[]` | All childs must be of type `` | 14 | | `renderCluster` | `(props: ClusterProps<{}>) => JSX.Element;` | This is optional, if you want you can leave it blank and the default cluster component will be rendered | 15 | 16 | ## Types 17 | 18 | ```ts 19 | // #ref: https://github.com/react-native-maps/react-native-maps/blob/master/index.d.ts#L24 20 | interface Region { 21 | latitude: number; 22 | longitude: number; 23 | latitudeDelta: number; 24 | longitudeDelta: number; 25 | } 26 | 27 | type ClusterProps

= { 28 | pointCount: number; 29 | pointCountAbbreviated: number | string; 30 | coordinate: LatLng; 31 | expansionZoom: number; 32 | } & P; 33 | ``` 34 | 35 | ## Example 36 | 37 | ```tsx 38 | import { ClusterProps, MarkerClusterer } from '@teovilla/react-native-web-maps'; 39 | 40 | const POINTS = [ 41 | { 42 | latitude: 59.33956246905637, 43 | longitude: 18.050015441134114, 44 | }, 45 | { 46 | latitude: 59.3442016958775, 47 | longitude: 18.038256636812825, 48 | }, 49 | ]; 50 | 51 | function MyClusterComponent(props: ClusterProps<{ onPress(): void }>) { 52 | return ( 53 | 58 | 59 | {props.pointCountAbbreviated} 60 | 61 | 62 | ); 63 | } 64 | 65 | export default function ClusteringExample() { 66 | const [region, setRegion] = useState(null); 67 | 68 | const mapRef = useRef(null); 69 | 70 | return ( 71 | 76 | ( 79 | 82 | mapRef.current?.animateCamera({ 83 | center: cluster.coordinate, 84 | zoom: cluster.expansionZoom + 3, 85 | }) 86 | } 87 | /> 88 | )} 89 | > 90 | {POINTS.map((point, idx) => ( 91 | 92 | ))} 93 | 94 | 95 | ); 96 | } 97 | 98 | const styles = StyleSheet.create({ 99 | cluster: { 100 | backgroundColor: 'salmon', 101 | alignItems: 'center', 102 | justifyContent: 'center', 103 | width: 20, 104 | height: 20, 105 | borderRadius: 999, 106 | }, 107 | clusterText: { 108 | fontWeight: '700', 109 | }, 110 | }); 111 | ``` 112 | -------------------------------------------------------------------------------- /docs/docs/getting-started.md: -------------------------------------------------------------------------------- 1 | --- 2 | sidebar_position: 2 3 | title: Getting started 4 | --- 5 | 6 | ## 1. Install the package 7 | 8 | ```bash 9 | yarn add @teovilla/react-native-web-maps 10 | ``` 11 | 12 | ## 2. Alias the package in your Webpack config 13 | 14 | You can find how to do this with the following guides 15 | 16 | - [With Expo web](/react-native-web-maps/installation/expo-web) 17 | - [With Next.js](/react-native-web-maps/installation/next-js) 18 | - [With plain webpack config](/react-native-web-maps/installation/webpack) 19 | 20 | ## 3. Actually using it 21 | 22 | There are some props that have been added to make this package work and give more customization options for web in some cases. So if you are using Typescript I recommend create a `app.d.ts` file in your project root and adding the following: 23 | 24 | ```ts 25 | /// 26 | ``` 27 | 28 | Now that everything is setup you can start using your maps on web! But there is something else you need to know. Google maps requires an API key for it work on web, so there is one prop that has been added to the `` component, it's the `googleMapsApiKey` prop. You should be passing your API key through that prop. There's also something important you should know, this only adds support for maps with `provider="google"` for now. So if you are trying to use Apple maps it will warn you about it. 29 | 30 | If you want to edit the loading state of the map you can pass JSX through the `loadingFallback` prop like [this](#quick-example). 31 | 32 | ## Quick example 33 | 34 | ```tsx 35 | 40 | Loading... 41 | 42 | } 43 | /> 44 | ``` 45 | -------------------------------------------------------------------------------- /docs/docs/index.md: -------------------------------------------------------------------------------- 1 | --- 2 | sidebar_position: 1 3 | title: Introduction 4 | --- 5 | 6 | Hey! Thanks for checking out this package 💪 7 | 8 | The goal of this package is adding web support to [react-native-maps](https://github.com/react-native-maps/react-native-maps). This package currently adds support for almost all of `react-native-maps` components. Most of the important methods and props are supported, and all of the methods marked as `deprecated` by `react-native-maps` are currently not supported. 9 | 10 | I have some ideas to bring some web apis to `react-native` but I still have to decide whether to create a new package and add these new APIs or re export them from `react-native-maps` through this package or trying to add them to `react-native-maps`. The last option I think it wont be possible. By these web APIs I mean for example marker clustering, drawing manager, editable polygons, etc. 11 | 12 | ## Trying it out 13 | 14 | If you want to try this out I recommend cloning the [example](https://github.com/teovillanueva/react-native-web-maps/tree/main/example) and running it ✨ 15 | -------------------------------------------------------------------------------- /docs/docs/installation/_category_.json: -------------------------------------------------------------------------------- 1 | { 2 | "label": "Installation", 3 | "position": 3 4 | } 5 | -------------------------------------------------------------------------------- /docs/docs/installation/expo-web.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Expo Web 3 | --- 4 | Generate a metro config file: 5 | `npx expo customize metro.config.js` 6 | 7 | ```js 8 | // webpack.config.js 9 | 10 | module.exports = async function (env, argv) { 11 | const config = await createExpoWebpackConfigAsync(env, argv); 12 | 13 | config.resolve.alias['react-native-maps'] = '@teovilla/react-native-web-maps'; 14 | 15 | return config; 16 | }; 17 | ``` 18 | **For Expo versions 50+** 19 | ``` 20 | const { getDefaultConfig } = require('expo/metro-config'); 21 | 22 | /** @type {import('expo/metro-config').MetroConfig} */ 23 | 24 | const config = getDefaultConfig(__dirname); 25 | 26 | const ALIASES = { 27 | "react-native-maps": "@teovilla/react-native-web-maps", 28 | }; 29 | 30 | config.resolver.resolveRequest = ( context, moduleName, platform ) => { 31 | 32 | // web 33 | if (platform === 'web') { 34 | // call default resolver 35 | return context.resolveRequest( 36 | context, 37 | // use alias, if alias exists 38 | ALIASES[moduleName] ?? moduleName, 39 | platform 40 | ); 41 | } 42 | 43 | // ios, android 44 | return context.resolveRequest(context, moduleName, platform); 45 | 46 | }; 47 | 48 | 49 | module.exports = config; 50 | ``` 51 | -------------------------------------------------------------------------------- /docs/docs/installation/next-js.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Next.js 3 | --- 4 | 5 | ```js 6 | // next.config.js 7 | 8 | module.exports = { 9 | webpack: (config) => { 10 | config.resolve.alias = { 11 | ...(config.resolve.alias || {}), 12 | 'react-native-maps': '@teovilla/react-native-web-maps', 13 | }; 14 | 15 | return config; 16 | }, 17 | }; 18 | ``` 19 | -------------------------------------------------------------------------------- /docs/docs/installation/webpack.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Webpack 3 | --- 4 | 5 | ```js 6 | const path = require('path'); 7 | 8 | module.exports = { 9 | //... 10 | resolve: { 11 | alias: { 12 | 'react-native-maps': '@teovilla/react-native-web-maps', 13 | }, 14 | }, 15 | }; 16 | ``` 17 | -------------------------------------------------------------------------------- /docs/docs/support/_category_.json: -------------------------------------------------------------------------------- 1 | { 2 | "label": "Support", 3 | "position": 5 4 | } 5 | -------------------------------------------------------------------------------- /docs/docs/support/callout.md: -------------------------------------------------------------------------------- 1 | --- 2 | sidebar_position: 3 3 | title: Callout ✅ 4 | --- 5 | 6 | ## Legend 7 | 8 | - Supported ✅ 9 | - Not supported ❌ 10 | - Needs investigation 🤔 11 | - Planned 🌲 12 | 13 | ## Props 14 | 15 | | Prop | Status | 16 | | -------------- | ------ | 17 | | `tooltip` | ✅ | 18 | | `alphaHitTest` | ❌ | 19 | 20 | ## Events 21 | 22 | To access event data, you will need to use `e.nativeEvent`. For example, `onPress={e => console.log(e.nativeEvent)}` will log the entire event object to your console. 23 | 24 | | Event Name | Status | 25 | | ---------- | ------ | 26 | | `onPress` | ✅ | 27 | -------------------------------------------------------------------------------- /docs/docs/support/circle.md: -------------------------------------------------------------------------------- 1 | --- 2 | sidebar_position: 6 3 | title: Circle ✅ 4 | --- 5 | 6 | ## Legend 7 | 8 | - Supported ✅ 9 | - Not supported ❌ 10 | - Needs investigation 🤔 11 | - Planned 🌲 12 | 13 | ## Props 14 | 15 | | Prop | Status | 16 | | ----------------- | ------ | 17 | | `center` | ✅ | 18 | | `radius` | ✅ | 19 | | `strokeWidth` | ✅ | 20 | | `strokeColor` | ✅ | 21 | | `fillColor` | ✅ | 22 | | `zIndex` | ✅ | 23 | | `lineCap` | ❌ | 24 | | `lineJoin` | ❌ | 25 | | `miterLimit` | ❌ | 26 | | `geodesic` | ✅ | 27 | | `lineDashPhase` | 🤔 | 28 | | `lineDashPattern` | 🤔 | 29 | -------------------------------------------------------------------------------- /docs/docs/support/geojson.md: -------------------------------------------------------------------------------- 1 | --- 2 | sidebar_position: 9 3 | title: Geojson ✅ 4 | --- 5 | 6 | ## Legend 7 | 8 | - Supported ✅ 9 | - Not supported ❌ 10 | - Needs investigation 🤔 11 | - Planned 🌲 12 | 13 | | Prop | Status | 14 | | ----------------- | ------ | 15 | | `geojson` | ✅ | 16 | | `strokeColor` | ✅ | 17 | | `fillColor` | ✅ | 18 | | `strokeWidth` | ✅ | 19 | | `color` | ✅ | 20 | | `lineDashPhase` | ❌ | 21 | | `lineDashPattern` | ❌ | 22 | | `lineCap` | ❌ | 23 | | `lineJoin` | ❌ | 24 | | `miterLimit` | ❌ | 25 | | `zIndex` | ✅ | 26 | | `onPress` | ✅ | 27 | | `markerComponent` | ✅ | 28 | | `title` | ✅ | 29 | -------------------------------------------------------------------------------- /docs/docs/support/heat-map.md: -------------------------------------------------------------------------------- 1 | --- 2 | sidebar_position: 8 3 | title: Heatmap ✅ 4 | --- 5 | 6 | ## Legend 7 | 8 | - Supported ✅ 9 | - Not supported ❌ 10 | - Needs investigation 🤔 11 | - Planned 🌲 12 | 13 | ## Props 14 | 15 | | Prop | Status | 16 | | ---------- | ------ | 17 | | `points` | ✅ | 18 | | `radius` | ✅ | 19 | | `opacity` | ✅ | 20 | | `gradient` | ✅ | 21 | 22 | ## Gradient Config 23 | 24 | [Android Doc](https://developers.google.com/maps/documentation/android-sdk/utility/heatmap#custom) | [iOS Doc](https://developers.google.com/maps/documentation/ios-sdk/utility/heatmap#customize) 25 | 26 | | Prop | Status | 27 | | -------------- | ------ | 28 | | `colors` | ✅ | 29 | | `startPoints` | ❌ | 30 | | `colorMapSize` | ❌ | 31 | -------------------------------------------------------------------------------- /docs/docs/support/map-view.md: -------------------------------------------------------------------------------- 1 | --- 2 | sidebar_position: 1 3 | title: MapView ✅ 4 | --- 5 | 6 | ## Legend 7 | 8 | - Supported ✅ 9 | - Not supported ❌ 10 | - Needs investigation 🤔 11 | - Planned 🌲 12 | 13 | ## Props 14 | 15 | | Prop | Status | Notes | 16 | | --------------------------------- | ------ | -------------------------------------------------------------- | 17 | | `provider` | ✅ | Only accepts `google` | 18 | | `region` | 🌲 | This is for controlling the map region | 19 | | `initialRegion` | ✅ | | 20 | | `initialCamera` | ✅ | | 21 | | `mapPadding` | 🤔 | | 22 | | `paddingAdjustmentBehavior` | 🤔 | | 23 | | `liteMode` | ❌ | | 24 | | `mapType` | ❌ | | 25 | | `customMapStyle` | ✅ | | 26 | | `userInterfaceStyle` | ❌ | | 27 | | `showsUserLocation` | ✅ | | 28 | | `userLocationPriority` | ❌ | | 29 | | `userLocationUpdateInterval` | 🌲 | | 30 | | `userLocationFastestInterval` | ❌ | | 31 | | `userLocationAnnotationTitle` | ❌ | | 32 | | `followsUserLocation` | ✅ | | 33 | | `userLocationCalloutEnabled` | ❌ | | 34 | | `showsMyLocationButton` | 🌲 | | 35 | | `showsPointsOfInterest` | ❌ | | 36 | | `showsCompass` | ❌ | | 37 | | `showsScale` | ✅ | | 38 | | `showsBuildings` | 🤔 | | 39 | | `showsTraffic` | ❌ | | 40 | | `showsIndoors` | ❌ | | 41 | | `showsIndoorLevelPicker` | ❌ | | 42 | | `zoomEnabled` | ✅ | | 43 | | `zoomTapEnabled` | ✅ | | 44 | | `zoomControlEnabled` | ✅ | | 45 | | `minZoomLevel` | ✅ | | 46 | | `maxZoomLevel` | ✅ | | 47 | | `rotateEnabled` | ✅ | | 48 | | `scrollEnabled` | 🤔 | | 49 | | `scrollDuringRotateOrZoomEnabled` | 🤔 | | 50 | | `pitchEnabled` | ✅ | | 51 | | `toolbarEnabled` | ❌ | | 52 | | `cacheEnabled` | ❌ | | 53 | | `loadingEnabled` | ❌ | | 54 | | `loadingIndicatorColor` | ❌ | | 55 | | `loadingBackgroundColor` | ❌ | | 56 | | `tintColor` | ❌ | | 57 | | `moveOnMarkerPress` | ❌ | | 58 | | `legalLabelInsets` | 🤔 | I don't think this will be possible but it would be fun to try | 59 | | `kmlSrc` | ❌ | | 60 | | `compassOffset` | ❌ | | 61 | | `isAccessibilityElement` | ❌ | | 62 | 63 | ## Events 64 | 65 | To access event data, you will need to use `e.nativeEvent`. For example, `onPress={e => console.log(e.nativeEvent)}` will log the entire event object to your console. 66 | 67 | | Event name | Status | 68 | | ------------------------- | ------ | 69 | | `onMapReady` | ✅ | 70 | | `onKmlReady` | ❌ | 71 | | `onRegionChange` | ✅ | 72 | | `onRegionChangeComplete` | ✅ | 73 | | `onUserLocationChange` | ✅ | 74 | | `onPress` | ✅ | 75 | | `onDoublePress` | ✅ | 76 | | `onPanDrag` | ✅ | 77 | | `onPoiClick` | 🤔 | 78 | | `onLongPress` | 🤔 | 79 | | `onMarkerPress` | ❌ | 80 | | `onMarkerSelect` | ❌ | 81 | | `onMarkerDeselect` | ❌ | 82 | | `onCalloutPress` | ❌ | 83 | | `onMarkerDragStart` | ❌ | 84 | | `onMarkerDrag` | ❌ | 85 | | `onMarkerDragEnd` | ❌ | 86 | | `onIndoorLevelActivated` | ❌ | 87 | | `onIndoorBuildingFocused` | ❌ | 88 | 89 | ## Methods 90 | 91 | | Method name | Status | 92 | | --------------------------- | ------ | 93 | | `getCamera` | ✅ | 94 | | `animateCamera` | ✅ | 95 | | `setCamera` | ✅ | 96 | | `animateToRegion` | ✅ | 97 | | `animateToNavigation` | ❌ | 98 | | `animateToCoordinate` | ❌ | 99 | | `animateToBearing` | ❌ | 100 | | `animateToViewingAngle` | ❌ | 101 | | `getMapBoundaries` | ✅ | 102 | | `setMapBoundaries` | ✅ | 103 | | `setIndoorActiveLevelIndex` | ❌ | 104 | | `fitToElements` | ❌ | 105 | | `fitToSuppliedMarkers` | ❌ | 106 | | `fitToCoordinates` | ✅ | 107 | | `addressForCoordinate` | ✅ | 108 | | `pointForCoordinate` | ✅ | 109 | | `coordinateForPoint` | ✅ | 110 | | `getMarkersFrames` | ❌ | 111 | -------------------------------------------------------------------------------- /docs/docs/support/marker.md: -------------------------------------------------------------------------------- 1 | --- 2 | sidebar_position: 2 3 | title: Marker ✅ 4 | --- 5 | 6 | ## Legend 7 | 8 | - Supported ✅ 9 | - Not supported ❌ 10 | - Needs investigation 🤔 11 | - Planned 🌲 12 | 13 | ## Props 14 | 15 | | Prop | Status | 16 | | ------------------------- | ------ | 17 | | `title` | ✅ | 18 | | `description` | ❌ | 19 | | `image` | 🌲 | 20 | | `icon` | 🌲 | 21 | | `pinColor` | 🤔 | 22 | | `coordinate` | ✅ | 23 | | `centerOffset` | 🤔 | 24 | | `calloutOffset` | 🤔 | 25 | | `anchor` | ✅ | 26 | | `calloutAnchor` | ✅ | 27 | | `flat` | ❌ | 28 | | `identifier` | ❌ | 29 | | `rotation` | ❌ | 30 | | `draggable` | ✅ | 31 | | `tappable` | ✅ | 32 | | `tracksViewChanges` | ❌ | 33 | | `tracksInfoWindowChanges` | ❌ | 34 | | `stopPropagation` | ❌ | 35 | | `opacity` | ✅ | 36 | | `isPreselected` | 🤔 | 37 | | `key` | ✅ | 38 | 39 | ## Events 40 | 41 | To access event data, you will need to use `e.nativeEvent`. For example, `onPress={e => console.log(e.nativeEvent)}` will log the entire event object to your console. 42 | 43 | | Event Name | Status | 44 | | ---------------- | ------ | 45 | | `onPress` | ✅ | 46 | | `onSelect` | 🤔 | 47 | | `onDeselect` | 🤔 | 48 | | `onCalloutPress` | 🤔 | 49 | | `onDragStart` | ✅ | 50 | | `onDrag` | ✅ | 51 | | `onDragEnd` | ✅ | 52 | 53 | ## Methods 54 | 55 | | Method Name | Status | 56 | | --------------------------- | ------ | 57 | | `showCallout` | ✅ | 58 | | `hideCallout` | ✅ | 59 | | `redrawCallout` | ❌ | 60 | | `animateMarkerToCoordinate` | ❌ | 61 | | `redraw` | ❌ | 62 | -------------------------------------------------------------------------------- /docs/docs/support/overlay.md: -------------------------------------------------------------------------------- 1 | --- 2 | sidebar_position: 7 3 | title: Overlay 🤔 4 | --- 5 | 6 | ## Legend 7 | 8 | - Supported ✅ 9 | - Not supported ❌ 10 | - Needs investigation 🤔 11 | - Planned 🌲 12 | 13 | This component is currently not supported, I still have to look at it since I've never used it before so I don't know really what's used for. 14 | -------------------------------------------------------------------------------- /docs/docs/support/polygon.md: -------------------------------------------------------------------------------- 1 | --- 2 | sidebar_position: 4 3 | title: Polygon ✅ 4 | --- 5 | 6 | ## Legend 7 | 8 | - Supported ✅ 9 | - Not supported ❌ 10 | - Needs investigation 🤔 11 | - Planned 🌲 12 | 13 | ## Props 14 | 15 | | Prop | Status | 16 | | ----------------- | ------ | 17 | | `miterLimit` | ❌ | 18 | | `geodesic` | ✅ | 19 | | `lineDashPhase` | 🤔 | 20 | | `lineDashPattern` | 🤔 | 21 | | `tappable` | ✅ | 22 | | `zIndex` | ✅ | 23 | 24 | ## Events 25 | 26 | | Event Name | Status | 27 | | ---------- | ------ | 28 | | `onPress` | ✅ | 29 | -------------------------------------------------------------------------------- /docs/docs/support/polyline.md: -------------------------------------------------------------------------------- 1 | --- 2 | sidebar_position: 5 3 | title: Polyline ✅ 4 | --- 5 | 6 | ## Legend 7 | 8 | - Supported ✅ 9 | - Not supported ❌ 10 | - Needs investigation 🤔 11 | - Planned 🌲 12 | 13 | ## Props 14 | 15 | | Prop | Status | 16 | | ----------------- | ------ | 17 | | `coordinates` | ✅ | 18 | | `strokeWidth` | ✅ | 19 | | `strokeColor` | ✅ | 20 | | `strokeColors` | ✅ | 21 | | `lineCap` | ❌ | 22 | | `lineJoin` | ❌ | 23 | | `miterLimit` | ❌ | 24 | | `geodesic` | ✅ | 25 | | `lineDashPhase` | 🤔 | 26 | | `lineDashPattern` | 🤔 | 27 | | `tappable` | ✅ | 28 | 29 | ## Events 30 | 31 | | Event Name | Status | 32 | | ---------- | ------ | 33 | | `onPress` | ✅ | 34 | -------------------------------------------------------------------------------- /docs/docusaurus.config.js: -------------------------------------------------------------------------------- 1 | // @ts-check 2 | // Note: type annotations allow type checking and IDEs autocompletion 3 | 4 | const lightCodeTheme = require('prism-react-renderer/themes/github'); 5 | const darkCodeTheme = require('prism-react-renderer/themes/dracula'); 6 | 7 | /** @type {import('@docusaurus/types').Config} */ 8 | const config = { 9 | title: 'react-native-web-maps', 10 | tagline: 'Cross platform maps for react & react-native', 11 | url: 'https://teovillanueva.github.io', 12 | baseUrl: '/react-native-web-maps/', 13 | trailingSlash: false, 14 | onBrokenLinks: 'throw', 15 | onBrokenMarkdownLinks: 'warn', 16 | favicon: 'img/favicon.ico', 17 | // GitHub pages deployment config. 18 | // If you aren't using GitHub pages, you don't need these. 19 | organizationName: 'teovillanueva', // Usually your GitHub org/user name. 20 | projectName: 'react-native-web-maps', // Usually your repo name. 21 | 22 | // Even if you don't use internalization, you can use this field to set useful 23 | // metadata like html lang. For example, if your site is Chinese, you may want 24 | // to replace "en" with "zh-Hans". 25 | i18n: { 26 | defaultLocale: 'en', 27 | locales: ['en'], 28 | }, 29 | 30 | presets: [ 31 | [ 32 | 'classic', 33 | /** @type {import('@docusaurus/preset-classic').Options} */ 34 | ({ 35 | docs: { 36 | routeBasePath: '/', 37 | sidebarPath: require.resolve('./sidebars.js'), 38 | // Please change this to your repo. 39 | // Remove this to remove the "edit this page" links. 40 | editUrl: 41 | 'https://github.com/teovillanueva/react-native-web-maps/tree/main/docs/', 42 | }, 43 | theme: { 44 | customCss: require.resolve('./src/css/custom.css'), 45 | }, 46 | }), 47 | ], 48 | ], 49 | 50 | themeConfig: 51 | /** @type {import('@docusaurus/preset-classic').ThemeConfig} */ 52 | ({ 53 | navbar: { 54 | title: '@teovilla/react-native-web-maps', 55 | logo: { 56 | alt: 'Logo', 57 | src: 'img/logo.svg', 58 | }, 59 | items: [ 60 | { 61 | type: 'doc', 62 | docId: 'index', 63 | position: 'left', 64 | label: 'Docs', 65 | }, 66 | { 67 | href: 'https://github.com/teovillanueva/react-native-web-maps', 68 | label: 'GitHub', 69 | position: 'right', 70 | }, 71 | ], 72 | }, 73 | footer: { 74 | style: 'dark', 75 | copyright: `Copyright © ${new Date().getFullYear()} Teodoro Villanueva. Built with Docusaurus.`, 76 | }, 77 | prism: { 78 | theme: lightCodeTheme, 79 | darkTheme: darkCodeTheme, 80 | }, 81 | }), 82 | }; 83 | 84 | module.exports = config; 85 | -------------------------------------------------------------------------------- /docs/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "docs", 3 | "version": "0.0.0", 4 | "private": true, 5 | "scripts": { 6 | "docusaurus": "docusaurus", 7 | "start": "docusaurus start", 8 | "build": "docusaurus build", 9 | "swizzle": "docusaurus swizzle", 10 | "deploy": "docusaurus deploy", 11 | "clear": "docusaurus clear", 12 | "serve": "docusaurus serve", 13 | "write-translations": "docusaurus write-translations", 14 | "write-heading-ids": "docusaurus write-heading-ids", 15 | "typecheck": "tsc" 16 | }, 17 | "dependencies": { 18 | "@docusaurus/core": "2.0.0-beta.21", 19 | "@docusaurus/preset-classic": "2.0.0-beta.21", 20 | "@mdx-js/react": "^1.6.22", 21 | "clsx": "^1.1.1", 22 | "prism-react-renderer": "^1.3.3", 23 | "react": "18.2.0", 24 | "react-dom": "18.2.0" 25 | }, 26 | "devDependencies": { 27 | "@docusaurus/module-type-aliases": "2.0.0-beta.21", 28 | "@tsconfig/docusaurus": "^1.0.5", 29 | "typescript": "^4.6.4" 30 | }, 31 | "browserslist": { 32 | "production": [ 33 | ">0.5%", 34 | "not dead", 35 | "not op_mini all" 36 | ], 37 | "development": [ 38 | "last 1 chrome version", 39 | "last 1 firefox version", 40 | "last 1 safari version" 41 | ] 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /docs/sidebars.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Creating a sidebar enables you to: 3 | - create an ordered group of docs 4 | - render a sidebar for each doc of that group 5 | - provide next/previous navigation 6 | 7 | The sidebars can be generated from the filesystem, or explicitly defined here. 8 | 9 | Create as many sidebars as you want. 10 | */ 11 | 12 | // @ts-check 13 | 14 | /** @type {import('@docusaurus/plugin-content-docs').SidebarsConfig} */ 15 | const sidebars = { 16 | // By default, Docusaurus generates a sidebar from the docs folder structure 17 | tutorialSidebar: [{type: 'autogenerated', dirName: '.'}], 18 | 19 | // But you can create a sidebar manually 20 | /* 21 | tutorialSidebar: [ 22 | { 23 | type: 'category', 24 | label: 'Tutorial', 25 | items: ['hello'], 26 | }, 27 | ], 28 | */ 29 | }; 30 | 31 | module.exports = sidebars; 32 | -------------------------------------------------------------------------------- /docs/src/css/custom.css: -------------------------------------------------------------------------------- 1 | /** 2 | * Any CSS included here will be global. The classic template 3 | * bundles Infima by default. Infima is a CSS framework designed to 4 | * work well for content-centric websites. 5 | */ 6 | 7 | /* You can override the default Infima variables here. */ 8 | :root { 9 | --ifm-color-primary: #2e8555; 10 | --ifm-color-primary-dark: #29784c; 11 | --ifm-color-primary-darker: #277148; 12 | --ifm-color-primary-darkest: #205d3b; 13 | --ifm-color-primary-light: #33925d; 14 | --ifm-color-primary-lighter: #359962; 15 | --ifm-color-primary-lightest: #3cad6e; 16 | --ifm-code-font-size: 95%; 17 | --docusaurus-highlighted-code-line-bg: rgba(0, 0, 0, 0.1); 18 | } 19 | 20 | /* For readability concerns, you should choose a lighter palette in dark mode. */ 21 | [data-theme='dark'] { 22 | --ifm-color-primary: #25c2a0; 23 | --ifm-color-primary-dark: #21af90; 24 | --ifm-color-primary-darker: #1fa588; 25 | --ifm-color-primary-darkest: #1a8870; 26 | --ifm-color-primary-light: #29d5b0; 27 | --ifm-color-primary-lighter: #32d8b4; 28 | --ifm-color-primary-lightest: #4fddbf; 29 | --docusaurus-highlighted-code-line-bg: rgba(0, 0, 0, 0.3); 30 | } 31 | -------------------------------------------------------------------------------- /docs/static/.nojekyll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teovillanueva/react-native-web-maps/bc0a56bc25aadfd2f57ef495999edf85a4c11bbb/docs/static/.nojekyll -------------------------------------------------------------------------------- /docs/static/img/docusaurus.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teovillanueva/react-native-web-maps/bc0a56bc25aadfd2f57ef495999edf85a4c11bbb/docs/static/img/docusaurus.png -------------------------------------------------------------------------------- /docs/static/img/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teovillanueva/react-native-web-maps/bc0a56bc25aadfd2f57ef495999edf85a4c11bbb/docs/static/img/favicon.ico -------------------------------------------------------------------------------- /docs/static/img/logo.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /docs/static/img/undraw_docusaurus_mountain.svg: -------------------------------------------------------------------------------- 1 | 2 | Easy to Use 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | -------------------------------------------------------------------------------- /docs/static/img/undraw_docusaurus_react.svg: -------------------------------------------------------------------------------- 1 | 2 | Powered by React 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | -------------------------------------------------------------------------------- /docs/static/img/undraw_docusaurus_tree.svg: -------------------------------------------------------------------------------- 1 | 2 | Focus on What Matters 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /docs/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | // This file is not used in compilation. It is here just for a nice editor experience. 3 | "extends": "@tsconfig/docusaurus/tsconfig.json", 4 | "compilerOptions": { 5 | "baseUrl": "." 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /example/.expo-shared/assets.json: -------------------------------------------------------------------------------- 1 | { 2 | "12bb71342c6255bbf50437ec8f4441c083f47cdb74bd89160c15e4f43e52a1cb": true, 3 | "40b842e832070c58deac6aa9e08fa459302ee3f9da492c7e77d93d2fbf4a56fd": true 4 | } 5 | -------------------------------------------------------------------------------- /example/.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | .expo/ 3 | dist/ 4 | npm-debug.* 5 | *.jks 6 | *.p8 7 | *.p12 8 | *.key 9 | *.mobileprovision 10 | *.orig.* 11 | web-build/ 12 | 13 | # macOS 14 | .DS_Store 15 | -------------------------------------------------------------------------------- /example/App.tsx: -------------------------------------------------------------------------------- 1 | import { useCallback, useMemo, useRef, useState } from 'react'; 2 | import { StyleSheet, View, Text } from 'react-native'; 3 | import MapView, { Marker } from 'react-native-maps'; 4 | import { ClusterProps, MarkerClusterer } from '@teovilla/react-native-web-maps'; 5 | import type { Region } from 'react-native-maps'; 6 | 7 | function MyClusterComponent(props: ClusterProps<{ onPress(): void }>) { 8 | return ( 9 | 14 | 15 | {props.pointCountAbbreviated} 16 | 17 | 18 | ); 19 | } 20 | 21 | export default function App() { 22 | const [region, setRegion] = useState(null); 23 | 24 | const mapRef = useRef(null); 25 | 26 | const loadingFallback = useMemo(() => { 27 | return ( 28 | 29 | Loading 30 | 31 | ); 32 | }, []); 33 | 34 | return ( 35 | 36 | 44 | ( 47 | 50 | mapRef.current?.animateCamera({ 51 | center: cluster.coordinate, 52 | zoom: cluster.expansionZoom + 3, 53 | }) 54 | } 55 | /> 56 | )} 57 | > 58 | 64 | 70 | 71 | {/* {SHOW_LOCATION_BUBBLE && position && ( 72 | <> 73 | 80 | 90 | 102 | You are here 103 | 104 | {Platform.select({ 105 | native: , 106 | })} 107 | 108 | 116 | 117 | )} */} 118 | 119 | 120 | ); 121 | } 122 | 123 | const styles = StyleSheet.create({ 124 | container: { 125 | flex: 1, 126 | }, 127 | cluster: { 128 | backgroundColor: 'salmon', 129 | width: 20, 130 | height: 20, 131 | borderRadius: 999, 132 | alignItems: 'center', 133 | justifyContent: 'center', 134 | }, 135 | clusterText: { 136 | fontWeight: '700', 137 | }, 138 | }); 139 | -------------------------------------------------------------------------------- /example/app.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | -------------------------------------------------------------------------------- /example/app.json: -------------------------------------------------------------------------------- 1 | { 2 | "expo": { 3 | "name": "example", 4 | "slug": "example", 5 | "version": "1.0.0", 6 | "orientation": "portrait", 7 | "icon": "./assets/icon.png", 8 | "userInterfaceStyle": "light", 9 | "splash": { 10 | "image": "./assets/splash.png", 11 | "resizeMode": "contain", 12 | "backgroundColor": "#ffffff" 13 | }, 14 | "updates": { 15 | "fallbackToCacheTimeout": 0 16 | }, 17 | "assetBundlePatterns": [ 18 | "**/*" 19 | ], 20 | "ios": { 21 | "supportsTablet": true 22 | }, 23 | "android": { 24 | "adaptiveIcon": { 25 | "foregroundImage": "./assets/adaptive-icon.png", 26 | "backgroundColor": "#FFFFFF" 27 | } 28 | }, 29 | "web": { 30 | "favicon": "./assets/favicon.png" 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /example/assets/adaptive-icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teovillanueva/react-native-web-maps/bc0a56bc25aadfd2f57ef495999edf85a4c11bbb/example/assets/adaptive-icon.png -------------------------------------------------------------------------------- /example/assets/favicon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teovillanueva/react-native-web-maps/bc0a56bc25aadfd2f57ef495999edf85a4c11bbb/example/assets/favicon.png -------------------------------------------------------------------------------- /example/assets/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teovillanueva/react-native-web-maps/bc0a56bc25aadfd2f57ef495999edf85a4c11bbb/example/assets/icon.png -------------------------------------------------------------------------------- /example/assets/splash.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/teovillanueva/react-native-web-maps/bc0a56bc25aadfd2f57ef495999edf85a4c11bbb/example/assets/splash.png -------------------------------------------------------------------------------- /example/babel.config.js: -------------------------------------------------------------------------------- 1 | module.exports = function (api) { 2 | api.cache(true); 3 | return { 4 | presets: ['babel-preset-expo'], 5 | plugins: ['inline-dotenv'], 6 | }; 7 | }; 8 | -------------------------------------------------------------------------------- /example/index.js: -------------------------------------------------------------------------------- 1 | import { registerRootComponent } from 'expo'; 2 | 3 | import App from './App'; 4 | 5 | // registerRootComponent calls AppRegistry.registerComponent('main', () => App); 6 | // It also ensures that whether you load the app in Expo Go or in a native build, 7 | // the environment is set up appropriately 8 | registerRootComponent(App); 9 | -------------------------------------------------------------------------------- /example/metro.config.js: -------------------------------------------------------------------------------- 1 | const { getDefaultConfig } = require('expo/metro-config'); 2 | const path = require('path'); 3 | 4 | const workspaceRoot = path.resolve(__dirname, '../'); 5 | const projectRoot = __dirname; 6 | 7 | const config = getDefaultConfig(projectRoot); 8 | 9 | config.watchFolders = [workspaceRoot]; 10 | 11 | config.resolver.nodeModulesPaths = [ 12 | path.resolve(projectRoot, 'node_modules'), 13 | path.resolve(workspaceRoot, 'node_modules'), 14 | ]; 15 | 16 | module.exports = config; 17 | -------------------------------------------------------------------------------- /example/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "example", 3 | "version": "1.0.0", 4 | "main": "index.js", 5 | "scripts": { 6 | "start": "expo start", 7 | "android": "expo start --android", 8 | "ios": "expo start --ios", 9 | "web": "expo start --web", 10 | "eject": "expo eject", 11 | "dev": "expo-yarn-workspaces postinstall && expo start --web --ios" 12 | }, 13 | "dependencies": { 14 | "expo": "^48.0.0", 15 | "expo-location": "~15.1.1", 16 | "expo-status-bar": "~1.4.4", 17 | "expo-yarn-workspaces": "^2.0.0", 18 | "react": "18.2.0", 19 | "react-dom": "18.2.0", 20 | "react-native": "0.71.7", 21 | "react-native-maps": "1.3.2", 22 | "react-native-web": "~0.18.11" 23 | }, 24 | "devDependencies": { 25 | "@babel/core": "^7.20.0", 26 | "@expo/webpack-config": "^18.0.1", 27 | "@types/react": "~18.0.27", 28 | "@types/react-native": "~0.70.6", 29 | "babel-plugin-inline-dotenv": "^1.7.0", 30 | "typescript": "^4.9.4" 31 | }, 32 | "private": true 33 | } 34 | -------------------------------------------------------------------------------- /example/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "expo/tsconfig.base", 3 | "compilerOptions": { 4 | "strict": true 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /example/webpack.config.js: -------------------------------------------------------------------------------- 1 | const { createWebpackConfigAsync } = require('expo-yarn-workspaces/webpack'); 2 | 3 | module.exports = async function (env, argv) { 4 | const config = await createWebpackConfigAsync(env, argv); 5 | 6 | config.resolve.alias['react-native-maps'] = '@teovilla/react-native-web-maps'; 7 | 8 | return config; 9 | }; 10 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@teovilla/react-native-web-maps-root", 3 | "version": "0.1.0", 4 | "description": "Cross platform maps for react & react-native", 5 | "main": "dist/commonjs/index", 6 | "module": "dist/module/index", 7 | "types": "dist/typescript/index.d.ts", 8 | "react-native": "src/index", 9 | "source": "src/index", 10 | "private": true, 11 | "workspaces": { 12 | "packages": [ 13 | "./packages/*", 14 | "./example", 15 | "./docs" 16 | ] 17 | }, 18 | "scripts": { 19 | "lint": "turbo run lint --filter @teovilla/*", 20 | "test": "turbo run test --filter @teovilla/*", 21 | "build": "turbo run build --filter @teovilla/*", 22 | "dev": "turbo run dev", 23 | "example": "yarn --cwd example", 24 | "lib": "yarn --cwd packages/react-native-web-maps", 25 | "docs": "yarn --cwd docs", 26 | "prepare": "husky install", 27 | "postinstall": "cd ./example && expo-yarn-workspaces postinstall", 28 | "clear": "npx rimraf ./**/node_modules ./**/yarn.lock ./**/package-lock.json ./**/.next ./**/.turbo ./**/.expo ./**/dist" 29 | }, 30 | "repository": "https://github.com/teovillanueva/react-native-web-maps", 31 | "author": "Teodoro Villanueva (https://github.com/teovillanueva)", 32 | "license": "MIT", 33 | "bugs": { 34 | "url": "https://github.com/teovillanueva/react-native-web-maps/issues" 35 | }, 36 | "homepage": "https://github.com/teovillanueva/react-native-web-maps#readme", 37 | "publishConfig": { 38 | "registry": "https://registry.npmjs.org/" 39 | }, 40 | "devDependencies": { 41 | "@babel/eslint-parser": "^7.18.2", 42 | "@commitlint/config-conventional": "^17.0.2", 43 | "@react-native-community/eslint-config": "^3.0.2", 44 | "@release-it/conventional-changelog": "^5.0.0", 45 | "@types/jest": "^28.1.2", 46 | "commitlint": "^17.0.2", 47 | "eslint": "^8.4.1", 48 | "eslint-config-prettier": "^8.5.0", 49 | "eslint-plugin-prettier": "^4.0.0", 50 | "husky": "^8.0.1", 51 | "lint-staged": "^13.0.3", 52 | "prettier": "^2.0.5", 53 | "turbo": "^1.3.1", 54 | "typescript": "^4.9.4" 55 | }, 56 | "resolutions": { 57 | "@types/react": "~18.0.27" 58 | }, 59 | "lint-staged": { 60 | "packages/*/src/**/*.+(ts|tsx)": [ 61 | "eslint --fix" 62 | ], 63 | "packages/*/src/**/*.{js,jsx,ts,tsx,json,css,scss,md}": [ 64 | "prettier --write" 65 | ], 66 | "*.js": "eslint --cache --fix" 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /packages/react-native-web-maps/.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "extends": ["../../.eslintrc"] 3 | } 4 | -------------------------------------------------------------------------------- /packages/react-native-web-maps/README.md: -------------------------------------------------------------------------------- 1 | # @teovilla/react-native-web-maps 2 | 3 | 4 | [![All Contributors](https://img.shields.io/badge/all_contributors-5-orange.svg?style=flat-square)](#contributors-) 5 | 6 | 7 | Cross platfrom maps for react & react-native 8 | 9 | ## Installation 10 | 11 | ```bash 12 | $ yarn add @teovilla/react-native-web-maps 13 | ``` 14 | 15 | ## Usage with Expo web / Webpack 16 | 17 | For this to work you must alias `react-native-maps` to `@teovilla/react-native-web-maps` in your webpack config. 18 | 19 | ### Example with Expo Web: 20 | 21 | ```js 22 | // webpack.config.js 23 | 24 | module.exports = async function (env, argv) { 25 | const config = await createExpoWebpackConfigAsync(env, argv); 26 | 27 | config.resolve.alias['react-native-maps'] = '@teovilla/react-native-web-maps'; 28 | 29 | return config; 30 | }; 31 | ``` 32 | 33 | ### Example with Next.js: 34 | 35 | ```js 36 | // next.config.js 37 | 38 | module.exports = { 39 | webpack: (config) => { 40 | config.resolve.alias = { 41 | ...(config.resolve.alias || {}), 42 | 'react-native-maps$': '@teovilla/react-native-web-maps', 43 | }; 44 | 45 | return config; 46 | }, 47 | }; 48 | ``` 49 | 50 | ## Documentation 51 | 52 | The docs for the project can be found [here](https://teovillanueva.github.io/react-native-web-maps/). 53 | 54 | ## Contributing 55 | 56 | See the [contributing guide](CONTRIBUTING.md) to learn how to contribute to the repository and the development workflow. 57 | 58 | ## License 59 | 60 | MIT 61 | 62 | --- 63 | 64 | Made with [create-react-native-library](https://github.com/callstack/react-native-builder-bob) 65 | 66 | ## Contributors ✨ 67 | 68 | Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)): 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 |
Teodoro Villanueva
Teodoro Villanueva

🚧 📖 💻
Abdul Rehman Talat
Abdul Rehman Talat

💻
Toby Smith
Toby Smith

📖 💻
Youssef Henna
Youssef Henna

📖 💻
Sascha Reuter
Sascha Reuter

💻
84 | 85 | 86 | 87 | 88 | 89 | 90 | This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome! 91 | -------------------------------------------------------------------------------- /packages/react-native-web-maps/babel.config.js: -------------------------------------------------------------------------------- 1 | module.exports = function(api) { 2 | api.cache(true); 3 | return { 4 | presets: ['babel-preset-expo'], 5 | }; 6 | }; 7 | -------------------------------------------------------------------------------- /packages/react-native-web-maps/jest.config.js: -------------------------------------------------------------------------------- 1 | const path = require('path'); 2 | 3 | module.exports = { 4 | preset: 'jest-expo', 5 | testEnvironment: 'jsdom', 6 | transformIgnorePatterns: [ 7 | 'node_modules/(?!((jest-)?react-native|@react-native(-community)?)|expo(nent)?|@expo(nent)?/.*|@expo-google-fonts/.*|react-navigation|@react-navigation/.*|@unimodules/.*|unimodules|sentry-expo|native-base|react-native-svg)', 8 | ], 9 | setupFiles: ['/jest.setup.js'], 10 | moduleDirectories: [ 11 | path.resolve(__dirname, '../../node_modules'), 12 | path.join(__dirname, 'node_modules'), 13 | __dirname, 14 | ], 15 | modulePathIgnorePatterns: ['/dist/'], 16 | }; 17 | -------------------------------------------------------------------------------- /packages/react-native-web-maps/jest.setup.js: -------------------------------------------------------------------------------- 1 | jest.mock('expo-location', () => ({})); 2 | -------------------------------------------------------------------------------- /packages/react-native-web-maps/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@teovilla/react-native-web-maps", 3 | "version": "0.9.5", 4 | "description": "Cross platform maps for react & react-native", 5 | "main": "dist/commonjs/index", 6 | "module": "dist/module/index", 7 | "types": "dist/typescript/index.d.ts", 8 | "react-native": "src/index", 9 | "source": "src/index", 10 | "files": [ 11 | "src", 12 | "dist", 13 | "!dist/typescript/example", 14 | "!**/__tests__", 15 | "!**/__fixtures__", 16 | "!**/__mocks__" 17 | ], 18 | "scripts": { 19 | "test": "jest", 20 | "typecheck": "tsc --noEmit", 21 | "lint": "eslint", 22 | "prepare": "yarn build", 23 | "build": "bob build", 24 | "release": "cp ../../README.md ./README.md && git add ./README.md && yarn build && release-it", 25 | "dev": "yarn nodemon --exec 'yarn bob build' --ignore dist --watch src -e ts,tsx" 26 | }, 27 | "keywords": [ 28 | "react-native", 29 | "react-native-web", 30 | "react-native-maps", 31 | "maps", 32 | "ios", 33 | "android" 34 | ], 35 | "repository": "https://github.com/teovillanueva/react-native-web-maps", 36 | "author": "Teodoro Villanueva (https://github.com/teovillanueva)", 37 | "license": "MIT", 38 | "bugs": { 39 | "url": "https://github.com/teovillanueva/react-native-web-maps/issues" 40 | }, 41 | "homepage": "https://github.com/teovillanueva/react-native-web-maps#readme", 42 | "publishConfig": { 43 | "registry": "https://registry.npmjs.org/", 44 | "access": "public" 45 | }, 46 | "devDependencies": { 47 | "@testing-library/jest-dom": "^5.16.4", 48 | "@testing-library/react": "12.1.5", 49 | "@types/geojson": "^7946.0.8", 50 | "@types/react": "~18.0.27", 51 | "@types/react-native": "~0.70.6", 52 | "@types/supercluster": "^7.1.0", 53 | "jest": "^29.2.1", 54 | "jest-environment-jsdom": "^28.1.2", 55 | "jest-expo": "^49.0.0", 56 | "nodemon": "^2.0.18", 57 | "react": "18.2.0", 58 | "react-dom": "18.2.0", 59 | "react-native": "0.71.7", 60 | "react-native-builder-bob": "^0.18.2", 61 | "react-native-maps": "1.3.2", 62 | "release-it": "^15.0.0", 63 | "typescript": "^4.9.4" 64 | }, 65 | "resolutions": { 66 | "@types/react": "~18.0.27" 67 | }, 68 | "peerDependencies": { 69 | "@react-google-maps/api": "*", 70 | "expo-location": "*", 71 | "react": "*", 72 | "react-native": "*", 73 | "react-native-maps": "*" 74 | }, 75 | "release-it": { 76 | "git": { 77 | "commitMessage": "chore: release ${version}", 78 | "tagName": "v${version}" 79 | }, 80 | "npm": { 81 | "publish": true 82 | }, 83 | "github": { 84 | "release": true 85 | }, 86 | "plugins": { 87 | "@release-it/conventional-changelog": { 88 | "preset": "angular" 89 | } 90 | } 91 | }, 92 | "react-native-builder-bob": { 93 | "source": "src", 94 | "output": "dist", 95 | "targets": [ 96 | "commonjs", 97 | "module", 98 | [ 99 | "typescript", 100 | { 101 | "project": "tsconfig.build.json" 102 | } 103 | ] 104 | ] 105 | }, 106 | "dependencies": { 107 | "@react-google-maps/api": "^2.12.0", 108 | "expo-location": "~15.1.1", 109 | "supercluster": "^7.1.5" 110 | } 111 | } 112 | -------------------------------------------------------------------------------- /packages/react-native-web-maps/src/__tests__/map-view.test.tsx: -------------------------------------------------------------------------------- 1 | import '@testing-library/jest-dom'; 2 | import React from 'react'; 3 | import { render } from '@testing-library/react'; 4 | import { MapView } from '../components/map-view'; 5 | 6 | describe(' props', () => { 7 | it('Returns null if provider is not `google`', () => { 8 | const { container } = render(); 9 | expect(container).toBeEmptyDOMElement(); 10 | }); 11 | }); 12 | -------------------------------------------------------------------------------- /packages/react-native-web-maps/src/components/callout.tsx: -------------------------------------------------------------------------------- 1 | import * as React from 'react'; 2 | import { 3 | InfoWindow as GMInfoWindow, 4 | OverlayView as GMOverlayView, 5 | useGoogleMap, 6 | } from '@react-google-maps/api'; 7 | import type { MapCalloutProps, LatLng, Point } from 'react-native-maps'; 8 | import { mapMouseEventToMapEvent } from '../utils/mouse-event'; 9 | 10 | export type CalloutContextType = { 11 | coordinate: LatLng; 12 | calloutVisible: boolean; 13 | toggleCalloutVisible: () => void; 14 | markerSize: { width: number; height: number }; 15 | anchor: Point; 16 | }; 17 | 18 | export const CalloutContext = React.createContext({ 19 | coordinate: { latitude: 0, longitude: 0 }, 20 | calloutVisible: false, 21 | toggleCalloutVisible: () => {}, 22 | markerSize: { width: 0, height: 0 }, 23 | anchor: { x: 0, y: 0 }, 24 | }); 25 | 26 | export function Callout(props: MapCalloutProps) { 27 | const map = useGoogleMap(); 28 | 29 | const { 30 | coordinate, 31 | calloutVisible, 32 | toggleCalloutVisible, 33 | markerSize, 34 | anchor, 35 | } = React.useContext(CalloutContext); 36 | 37 | //By default callout is positioned to bottom center 38 | //i.e. is at anchor: (0.5, 1) 39 | //This compensates to match expected result using the provided anchor prop 40 | const xOffset = -(markerSize.width * (0.5 - anchor.x)); 41 | const yOffset = -(markerSize.height * (1 - anchor.y)); 42 | 43 | return calloutVisible ? ( 44 |

{ 46 | props.onPress?.( 47 | mapMouseEventToMapEvent(null, coordinate, map, 'callout-press') 48 | ); 49 | e.stopPropagation(); //Prevent marker click handler from being called 50 | }} 51 | > 52 | {props.tooltip ? ( 53 | ({ 60 | x: xOffset, 61 | y: yOffset, 62 | })} 63 | > 64 | {/* Render on top of marker instead of inside */} 65 |
66 | {props.children} 67 |
68 |
69 | ) : ( 70 | toggleCalloutVisible()} 79 | > 80 | <>{props.children} 81 | 82 | )} 83 |
84 | ) : null; 85 | } 86 | -------------------------------------------------------------------------------- /packages/react-native-web-maps/src/components/circle.tsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import { Circle as GMCircle } from '@react-google-maps/api'; 3 | import type { MapCircleProps } from 'react-native-maps'; 4 | 5 | export function Circle(props: MapCircleProps) { 6 | return ( 7 | 16 | ); 17 | } 18 | -------------------------------------------------------------------------------- /packages/react-native-web-maps/src/components/geojson.tsx: -------------------------------------------------------------------------------- 1 | /** 2 | * This component is taken from `react-native-maps` 3 | * I just replaced the inner components with the web ones 4 | * I guess this has been tested by the creators lol 5 | * https://github.com/react-native-maps/react-native-maps/blob/master/src/Geojson.js 6 | */ 7 | 8 | import React from 'react'; 9 | import type { GeojsonProps } from 'react-native-maps'; 10 | import { getColor, getStrokeWidth, makeOverlays } from '../utils/geojson'; 11 | import { Marker } from './marker'; 12 | import { Polygon } from './polygon'; 13 | import { Polyline } from './polyline'; 14 | 15 | export function Geojson(props: GeojsonProps) { 16 | const { 17 | title, 18 | zIndex, 19 | onPress, 20 | lineCap, 21 | lineJoin, 22 | tappable, 23 | miterLimit, 24 | lineDashPhase, 25 | lineDashPattern, 26 | markerComponent, 27 | } = props; 28 | 29 | const overlays = makeOverlays(props.geojson.features); 30 | 31 | return ( 32 | <> 33 | {overlays.map((overlay, index) => { 34 | const fillColor = getColor(props, overlay, 'fill', 'fillColor'); 35 | const strokeColor = getColor(props, overlay, 'stroke', 'strokeColor'); 36 | const markerColor = getColor(props, overlay, 'marker-color', 'color'); 37 | const strokeWidth = getStrokeWidth(props, overlay); 38 | if (overlay.type === 'point') { 39 | return ( 40 | onPress && onPress(overlay as any)} 47 | > 48 | {markerComponent} 49 | 50 | ); 51 | } 52 | if (overlay.type === 'polygon') { 53 | return ( 54 | onPress && onPress(overlay as any)} 63 | zIndex={zIndex} 64 | /> 65 | ); 66 | } 67 | if (overlay.type === 'polyline') { 68 | return ( 69 | onPress && onPress(overlay as any)} 82 | /> 83 | ); 84 | } 85 | 86 | return null; 87 | })} 88 | 89 | ); 90 | } 91 | -------------------------------------------------------------------------------- /packages/react-native-web-maps/src/components/heat-map.tsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import { HeatmapLayer as GMHeatmap } from '@react-google-maps/api'; 3 | import type { MapHeatmapProps } from 'react-native-maps'; 4 | 5 | export function Heatmap(props: MapHeatmapProps) { 6 | return ( 7 | ({ 9 | location: new google.maps.LatLng({ 10 | lat: p.latitude, 11 | lng: p.longitude, 12 | }), 13 | weight: p.weight || 0, 14 | }))} 15 | options={{ 16 | radius: props.radius, 17 | gradient: props.gradient?.colors, 18 | opacity: props.opacity, 19 | }} 20 | /> 21 | ); 22 | } 23 | -------------------------------------------------------------------------------- /packages/react-native-web-maps/src/components/map-view.tsx: -------------------------------------------------------------------------------- 1 | import { GoogleMap, useJsApiLoader } from '@react-google-maps/api'; 2 | import type { ForwardedRef } from 'react'; 3 | import React, { 4 | forwardRef, 5 | memo, 6 | useCallback, 7 | useEffect, 8 | useImperativeHandle, 9 | useMemo, 10 | useState, 11 | } from 'react'; 12 | import type { 13 | Address, 14 | Camera, 15 | EdgePadding, 16 | LatLng, 17 | MapViewProps, 18 | Point, 19 | Region, 20 | SnapshotOptions, 21 | } from 'react-native-maps'; 22 | import type RNMapView from 'react-native-maps'; 23 | import { mapMouseEventToMapEvent } from '../utils/mouse-event'; 24 | import { transformRNCameraObject } from '../utils/camera'; 25 | import { 26 | logMethodNotImplementedWarning, 27 | logDeprecationWarning, 28 | } from '../utils/log'; 29 | import { useUserLocation } from '../hooks/use-user-location'; 30 | import { UserLocationMarker } from './user-location-marker'; 31 | import * as Location from 'expo-location'; 32 | 33 | function _MapView(props: MapViewProps, ref: ForwardedRef>) { 34 | // State 35 | 36 | const [map, setMap] = useState(null); 37 | const [isGesture, setIsGesture] = useState(false); 38 | 39 | const userLocation = useUserLocation({ 40 | showUserLocation: props.showsUserLocation || false, 41 | requestPermission: 42 | props.showsUserLocation || !!props.onUserLocationChange || false, 43 | onUserLocationChange: props.onUserLocationChange, 44 | followUserLocation: props.followsUserLocation || false, 45 | }); 46 | 47 | const { isLoaded } = useJsApiLoader({ 48 | googleMapsApiKey: props.googleMapsApiKey || '', 49 | }); 50 | 51 | // Callbacks 52 | 53 | const _onMapReady = useCallback( 54 | (_map: google.maps.Map) => { 55 | setMap(_map); 56 | props.onMapReady?.(); 57 | }, 58 | [map, props.onMapReady] 59 | ); 60 | 61 | const _onDragStart = useCallback(() => { 62 | setIsGesture(true); 63 | }, []); 64 | 65 | const _onRegionChange = useCallback(() => { 66 | const bounds = map?.getBounds(); 67 | if (bounds) { 68 | const northEast = bounds.getNorthEast(); 69 | const southWest = bounds.getSouthWest(); 70 | const longitudeDelta = Math.abs(northEast.lng() - southWest.lng()); 71 | const latitudeDelta = Math.abs(northEast.lat() - southWest.lat()); 72 | const center = bounds.getCenter(); 73 | props.onRegionChange?.( 74 | { 75 | latitude: center.lat(), 76 | longitude: center.lng(), 77 | latitudeDelta, 78 | longitudeDelta, 79 | }, 80 | { isGesture } 81 | ); 82 | } 83 | }, [map, props.onRegionChange, isGesture]); 84 | 85 | const _onRegionChangeComplete = useCallback(() => { 86 | const bounds = map?.getBounds(); 87 | if (bounds) { 88 | const northEast = bounds.getNorthEast(); 89 | const southWest = bounds.getSouthWest(); 90 | const longitudeDelta = Math.abs(northEast.lng() - southWest.lng()); 91 | const latitudeDelta = Math.abs(northEast.lat() - southWest.lat()); 92 | const center = bounds.getCenter(); 93 | props.onRegionChangeComplete?.( 94 | { 95 | latitude: center.lat(), 96 | longitude: center.lng(), 97 | latitudeDelta, 98 | longitudeDelta, 99 | }, 100 | { isGesture } 101 | ); 102 | } 103 | setIsGesture(false); 104 | }, [map, props.onRegionChange, isGesture]); 105 | 106 | // Ref handle 107 | 108 | useImperativeHandle( 109 | ref, 110 | () => ({ 111 | async getCamera(): Promise { 112 | const center = map?.getCenter(); 113 | return { 114 | altitude: 0, 115 | heading: map?.getHeading() || 0, 116 | pitch: map?.getTilt() || 0, // TODO: Review this 117 | zoom: map?.getZoom() || 0, // TODO: Normalize value 118 | center: { 119 | latitude: center?.lat() || 0, 120 | longitude: center?.lng() || 0, 121 | }, 122 | }; 123 | }, 124 | setCamera(camera: Partial): void { 125 | map?.moveCamera(transformRNCameraObject(camera)); 126 | }, 127 | animateCamera( 128 | camera: Partial, 129 | _opts?: { duration?: number } 130 | ): void { 131 | map?.moveCamera(transformRNCameraObject(camera)); 132 | }, 133 | async getMapBoundaries(): Promise<{ 134 | northEast: LatLng; 135 | southWest: LatLng; 136 | }> { 137 | const bounds = map?.getBounds(); 138 | 139 | const northEast = bounds?.getNorthEast(); 140 | const southWest = bounds?.getSouthWest(); 141 | 142 | return { 143 | northEast: { 144 | latitude: northEast?.lat() || 0, 145 | longitude: northEast?.lng() || 0, 146 | }, 147 | southWest: { 148 | latitude: southWest?.lat() || 0, 149 | longitude: southWest?.lng() || 0, 150 | }, 151 | }; 152 | }, 153 | animateToRegion(region: Region, _duration?: number): void { 154 | const bounds = new google.maps.LatLngBounds(); 155 | 156 | // Source: https://github.com/react-native-maps/react-native-maps/blob/master/android/src/main/java/com/airbnb/android/react/maps/AirMapView.java#L503 157 | 158 | // southWest 159 | bounds.extend({ 160 | lat: region.latitude - region.latitudeDelta / 2, 161 | lng: region.longitude - region.longitudeDelta / 2, 162 | }); 163 | 164 | // northEast 165 | bounds.extend({ 166 | lat: region.latitude + region.latitudeDelta / 2, 167 | lng: region.longitude + region.longitudeDelta / 2, 168 | }); 169 | 170 | // panToBounds not working?? 171 | // map?.panToBounds(bounds); 172 | map?.fitBounds(bounds); 173 | }, 174 | fitToCoordinates( 175 | coordinates?: LatLng[], 176 | options?: { edgePadding?: EdgePadding; animated?: boolean } 177 | ): void { 178 | const bounds = new google.maps.LatLngBounds(); 179 | 180 | if (coordinates) { 181 | coordinates?.forEach((c) => 182 | bounds.extend({ 183 | lat: c.latitude, 184 | lng: c.longitude, 185 | }) 186 | ); 187 | } 188 | 189 | map?.fitBounds(bounds, options?.edgePadding as google.maps.Padding); 190 | }, 191 | setMapBoundaries(northEast: LatLng, southWest: LatLng): void { 192 | const bounds = new google.maps.LatLngBounds(); 193 | 194 | bounds.extend({ lat: northEast.latitude, lng: northEast.longitude }); 195 | bounds.extend({ lat: southWest.latitude, lng: southWest.longitude }); 196 | 197 | map?.fitBounds(bounds); 198 | }, 199 | async pointForCoordinate(coordinate: LatLng): Promise { 200 | const point = map?.getProjection()?.fromLatLngToPoint({ 201 | lat: coordinate.latitude, 202 | lng: coordinate.longitude, 203 | }); 204 | return point || { x: 0, y: 0 }; 205 | }, 206 | async coordinateForPoint(point: Point): Promise { 207 | const coord = map 208 | ?.getProjection() 209 | ?.fromPointToLatLng(new google.maps.Point(point.x, point.y)); 210 | 211 | return { latitude: coord?.lat() || 0, longitude: coord?.lng() || 0 }; 212 | }, 213 | async takeSnapshot(_options?: SnapshotOptions): Promise { 214 | logMethodNotImplementedWarning('takeSnapshot'); 215 | return ''; 216 | }, 217 | async addressForCoordinate(_coordinate: LatLng): Promise
{ 218 | Location.setGoogleApiKey(props.googleMapsApiKey || ''); 219 | const [address] = await Location.reverseGeocodeAsync(_coordinate, { 220 | useGoogleMaps: true, 221 | }); 222 | 223 | return address 224 | ? { 225 | administrativeArea: address.region || '', 226 | country: address.country || '', 227 | countryCode: address.isoCountryCode || '', 228 | locality: address.city || '', 229 | postalCode: address.postalCode || '', 230 | name: address.name || '', 231 | subAdministrativeArea: address.subregion || '', 232 | subLocality: address.city || '', 233 | thoroughfare: '', 234 | } 235 | : (null as unknown as Address); 236 | }, 237 | animateToNavigation( 238 | _location: LatLng, 239 | _bearing: number, 240 | _angle: number, 241 | _duration?: number 242 | ): void { 243 | logDeprecationWarning('animateToNavigation'); 244 | }, 245 | animateToCoordinate(_latLng: LatLng, _duration?: number): void { 246 | logDeprecationWarning('animateToCoordinate'); 247 | }, 248 | animateToBearing(_bearing: number, _duration?: number): void { 249 | logDeprecationWarning('animateToBearing'); 250 | }, 251 | animateToViewingAngle(_angle: number, _duration?: number): void { 252 | logDeprecationWarning('animateToViewingAngle'); 253 | }, 254 | fitToElements(_options?: { 255 | edgePadding?: EdgePadding; 256 | animated?: boolean; 257 | }): void { 258 | logMethodNotImplementedWarning('fitToElements'); 259 | }, 260 | fitToSuppliedMarkers( 261 | _markers: string[], 262 | _options?: { edgePadding?: EdgePadding; animated?: boolean } 263 | ): void { 264 | logMethodNotImplementedWarning('fitToSuppliedMarkers'); 265 | }, 266 | setIndoorActiveLevelIndex(_index: number): void { 267 | logMethodNotImplementedWarning('setIndoorActiveLevelIndex'); 268 | }, 269 | }), 270 | [map] 271 | ); 272 | 273 | // Side effects 274 | 275 | useEffect(() => { 276 | if (props.followsUserLocation && userLocation) { 277 | map?.panTo({ 278 | lat: userLocation.coords.latitude, 279 | lng: userLocation.coords.longitude, 280 | }); 281 | } 282 | }, [props.followsUserLocation, userLocation]); 283 | 284 | const mapNode = useMemo( 285 | () => ( 286 | { 296 | const center = map?.getCenter(); 297 | 298 | props.onPanDrag?.( 299 | mapMouseEventToMapEvent( 300 | null, 301 | center && { latitude: center.lat(), longitude: center.lng() }, 302 | map, 303 | undefined 304 | ) 305 | ); 306 | }} 307 | onClick={(e) => 308 | props.onPress?.(mapMouseEventToMapEvent(e, null, map, 'press')) 309 | } 310 | onDblClick={(e) => 311 | props.onDoublePress?.(mapMouseEventToMapEvent(e, null, map, 'press')) 312 | } 313 | center={ 314 | map 315 | ? map.getCenter() 316 | : { 317 | lat: 318 | props.initialCamera?.center.latitude || 319 | props.initialRegion?.latitude || 320 | 0, 321 | lng: 322 | props.initialCamera?.center.longitude || 323 | props.initialRegion?.longitude || 324 | 0, 325 | } 326 | } 327 | options={{ 328 | scrollwheel: props.zoomEnabled, 329 | disableDoubleClickZoom: !props.zoomTapEnabled, 330 | zoomControl: props.zoomControlEnabled, 331 | rotateControl: props.rotateEnabled, 332 | minZoom: props.minZoomLevel, // TODO: Normalize value 333 | maxZoom: props.maxZoomLevel, // TODO: Normalize value 334 | scaleControl: props.showsScale, 335 | styles: props.customMapStyle, 336 | ...(props.options || {}), 337 | }} 338 | > 339 | {props.showsUserLocation && userLocation && ( 340 | 341 | )} 342 | {props.children} 343 | 344 | ), 345 | [ 346 | _onRegionChange, 347 | _onMapReady, 348 | userLocation, 349 | props.initialCamera, 350 | props.initialRegion, 351 | props.showsUserLocation, 352 | props.onPanDrag, 353 | props.onPress, 354 | props.onDoublePress, 355 | props.zoomEnabled, 356 | props.zoomTapEnabled, 357 | props.zoomControlEnabled, 358 | props.rotateEnabled, 359 | props.minZoomLevel, 360 | props.maxZoomLevel, 361 | props.showsScale, 362 | props.customMapStyle, 363 | props.options, 364 | ] 365 | ); 366 | 367 | if (props.provider !== 'google') { 368 | console.warn( 369 | '[WARNING] `react-native-web-maps` only suppots google for now. Please pass "google" as provider in props' 370 | ); 371 | 372 | return null; 373 | } 374 | 375 | return isLoaded ? ( 376 | React.cloneElement(mapNode) 377 | ) : ( 378 | <>{props.loadingFallback || null} 379 | ); 380 | } 381 | 382 | export const MapView = memo(forwardRef(_MapView)); 383 | -------------------------------------------------------------------------------- /packages/react-native-web-maps/src/components/marker-clusterer/cluster.tsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import { StyleSheet, View, Text } from 'react-native'; 3 | import { Marker } from '../marker'; 4 | import type { ClusterProps } from './types'; 5 | 6 | export function Cluster(props: ClusterProps) { 7 | return ( 8 | 9 | 10 | {props.pointCountAbbreviated} 11 | 12 | 13 | ); 14 | } 15 | 16 | export const styles = StyleSheet.create({ 17 | container: { 18 | width: 30, 19 | height: 30, 20 | borderRadius: 9999, 21 | backgroundColor: '#1380FF', 22 | alignItems: 'center', 23 | justifyContent: 'center', 24 | }, 25 | text: { 26 | textAlign: 'center', 27 | fontWeight: '500', 28 | }, 29 | }); 30 | -------------------------------------------------------------------------------- /packages/react-native-web-maps/src/components/marker-clusterer/index.ts: -------------------------------------------------------------------------------- 1 | export * from './marker-clusterer'; 2 | export * from './types'; 3 | -------------------------------------------------------------------------------- /packages/react-native-web-maps/src/components/marker-clusterer/marker-clusterer.tsx: -------------------------------------------------------------------------------- 1 | import type { ClusterProps, MarkerClustererProps } from './types'; 2 | import type { ReactElement } from 'react'; 3 | import React, { memo, useMemo, useState } from 'react'; 4 | import { getBoundByRegion } from '../../utils/region'; 5 | import type { MapMarkerProps } from 'react-native-maps'; 6 | import { Cluster } from './cluster'; 7 | import Supercluster from 'supercluster'; 8 | import { Marker } from '../marker'; 9 | 10 | function _MarkerClusterer(props: MarkerClustererProps) { 11 | const [supercluster, _setSupercluster] = useState< 12 | Supercluster<{ node: JSX.Element; cluster: boolean }> 13 | >(new Supercluster()); 14 | 15 | const markers = useMemo( 16 | () => 17 | (React.Children.toArray(props.children).filter((child) => { 18 | return (child as ReactElement).type === Marker; 19 | }) as ReactElement[]) || [], 20 | [props.children] 21 | ); 22 | 23 | const points = useMemo< 24 | Supercluster.PointFeature<{ node: JSX.Element; cluster: boolean }>[] 25 | >( 26 | () => 27 | markers.map((node) => ({ 28 | type: 'Feature', 29 | properties: { cluster: false, node }, 30 | geometry: { 31 | type: 'Point', 32 | coordinates: [ 33 | Number(node.props.coordinate.longitude), 34 | Number(node.props.coordinate.latitude), 35 | ], 36 | }, 37 | })), 38 | [markers] 39 | ); 40 | 41 | const clusters = useMemo(() => { 42 | if (!props.region) return []; 43 | 44 | const bbox = getBoundByRegion(props.region); 45 | 46 | supercluster.load(points); 47 | 48 | return supercluster.getClusters( 49 | bbox, 50 | Math.round(Math.log(360 / props.region.longitudeDelta) / Math.LN2) 51 | ); 52 | }, [props.region, points]); 53 | 54 | return ( 55 | <> 56 | {clusters.map((feature, idx) => { 57 | const clusterProperties = 58 | feature.properties as Supercluster.ClusterProperties; 59 | 60 | const clusterProps: ClusterProps = { 61 | expansionZoom: supercluster.getClusterExpansionZoom( 62 | clusterProperties.cluster_id 63 | ), 64 | pointCount: clusterProperties.point_count, 65 | pointCountAbbreviated: clusterProperties.point_count_abbreviated, 66 | coordinate: { 67 | longitude: feature.geometry.coordinates[0]!, 68 | latitude: feature.geometry.coordinates[1]!, 69 | }, 70 | }; 71 | 72 | return ( 73 | 74 | {feature.properties.cluster === true 75 | ? props.renderCluster?.(clusterProps) || ( 76 | 77 | ) 78 | : feature.properties.node} 79 | 80 | ); 81 | })} 82 | 83 | ); 84 | } 85 | 86 | export const MarkerClusterer = memo(_MarkerClusterer); 87 | -------------------------------------------------------------------------------- /packages/react-native-web-maps/src/components/marker-clusterer/types.ts: -------------------------------------------------------------------------------- 1 | import type React from 'react'; 2 | import type { LatLng, Region } from 'react-native-maps'; 3 | 4 | export type ClusterProps

= { 5 | pointCount: number; 6 | pointCountAbbreviated: number | string; 7 | coordinate: LatLng; 8 | expansionZoom: number; 9 | } & P; 10 | 11 | export type MarkerClustererProps = { 12 | children?: React.ReactElement[]; 13 | region: Region | null; 14 | renderCluster?(props: ClusterProps<{}>): JSX.Element; 15 | }; 16 | 17 | export type MarkerClustererHandle = { 18 | handleRegionChange(region: Region): void; 19 | }; 20 | -------------------------------------------------------------------------------- /packages/react-native-web-maps/src/components/marker.tsx: -------------------------------------------------------------------------------- 1 | export { Marker } from 'react-native-maps'; 2 | -------------------------------------------------------------------------------- /packages/react-native-web-maps/src/components/marker.web.tsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import type { ReactElement, Ref } from 'react'; 3 | import { 4 | Marker as GMMarker, 5 | OverlayViewF as GMOverlayView, 6 | useGoogleMap, 7 | } from '@react-google-maps/api'; 8 | import type { MapMarkerProps, Point } from 'react-native-maps'; 9 | import { mapMouseEventToMapEvent } from '../utils/mouse-event'; 10 | import { Callout, CalloutContext } from './callout'; 11 | import type { CalloutContextType } from './callout'; 12 | 13 | interface MarkerState { 14 | calloutVisible: boolean; 15 | } 16 | 17 | //Wrapped in class component to provide methods 18 | //forwardRef + useImperativeHandle not sufficient because it returns a ForwardRefExoticComponent which does not seem to render in the MapView 19 | export class Marker extends React.Component { 20 | constructor(props: MapMarkerProps) { 21 | super(props); 22 | this.state = { calloutVisible: false }; 23 | } 24 | 25 | showCallout() { 26 | this.setState({ calloutVisible: true }); 27 | } 28 | 29 | hideCallout() { 30 | this.setState({ calloutVisible: false }); 31 | } 32 | 33 | render(): React.ReactNode { 34 | return ( 35 | 39 | this.setState({ calloutVisible: !this.state.calloutVisible }) 40 | } 41 | /> 42 | ); 43 | } 44 | } 45 | 46 | interface MarkerFProps extends MapMarkerProps { 47 | calloutVisible: boolean; 48 | toggleCalloutVisible: () => void; 49 | } 50 | 51 | function MarkerF(props: MarkerFProps) { 52 | const map = useGoogleMap(); 53 | 54 | const customMarkerContainerRef = React.useRef(); 55 | const [markerSize, setMarkerSize] = React.useState<{ 56 | width: number; 57 | height: number; 58 | }>({ width: 22, height: 40 }); //22 x 40 is the default google maps marker size 59 | 60 | React.useEffect(() => { 61 | if (customMarkerContainerRef.current) { 62 | setMarkerSize({ 63 | width: customMarkerContainerRef.current.clientWidth, 64 | height: customMarkerContainerRef.current.clientHeight, 65 | }); 66 | } 67 | }, [customMarkerContainerRef.current]); 68 | 69 | const onMarkerPress = (e?: google.maps.MapMouseEvent) => { 70 | props.onPress?.( 71 | mapMouseEventToMapEvent(e, props.coordinate, map, 'marker-press') 72 | ); 73 | props.toggleCalloutVisible(); 74 | }; 75 | 76 | const hasNonCalloutChildren = React.useMemo( 77 | () => 78 | !!React.Children.toArray(props.children).find((child) => { 79 | return (child as ReactElement).type !== Callout; 80 | }), 81 | [props.children] 82 | ); 83 | 84 | //Default anchor values to react-native-maps values (https://github.com/react-native-maps/react-native-maps/blob/master/docs/marker.md) 85 | const anchor: Point = props.anchor || { x: 0.5, y: 1 }; 86 | const calloutAnchor: Point = props.calloutAnchor || { x: 0.5, y: 0 }; 87 | 88 | const calloutContextValue: CalloutContextType = { 89 | calloutVisible: props.calloutVisible, 90 | toggleCalloutVisible: props.toggleCalloutVisible, 91 | coordinate: props.coordinate, 92 | markerSize, 93 | anchor: calloutAnchor, 94 | }; 95 | 96 | return ( 97 | 98 | <> 99 | {hasNonCalloutChildren ? ( 100 | ({ 107 | x: -(w * anchor!.x), 108 | y: -(h * anchor!.y), 109 | })} 110 | > 111 |

} 113 | onClick={() => onMarkerPress()} 114 | > 115 | {props.children} 116 |
117 | 118 | ) : ( 119 | onMarkerPress(e)} 123 | onDrag={(e) => 124 | props.onDrag?.( 125 | mapMouseEventToMapEvent(e, props.coordinate, map, '') 126 | ) 127 | } 128 | onDragStart={(e) => 129 | props.onDragStart?.( 130 | mapMouseEventToMapEvent(e, props.coordinate, map, '') 131 | ) 132 | } 133 | onDragEnd={(e) => 134 | props.onDragEnd?.( 135 | mapMouseEventToMapEvent(e, props.coordinate, map, '') 136 | ) 137 | } 138 | options={{ 139 | clickable: props.tappable, 140 | opacity: props.opacity, 141 | draggable: props.draggable, 142 | anchorPoint: props.anchor 143 | ? new google.maps.Point(props.anchor?.x, props.anchor?.y) 144 | : null, 145 | }} 146 | position={{ 147 | lat: Number(props.coordinate.latitude), 148 | lng: Number(props.coordinate.longitude), 149 | }} 150 | children={props.children} 151 | /> 152 | )} 153 | 154 | 155 | ); 156 | } 157 | -------------------------------------------------------------------------------- /packages/react-native-web-maps/src/components/polygon.tsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import { Polygon as GMPolygon, useGoogleMap } from '@react-google-maps/api'; 3 | import type { MapPolygonProps } from 'react-native-maps'; 4 | import { mapMouseEventToMapEvent } from '../utils/mouse-event'; 5 | 6 | export function Polygon(props: MapPolygonProps) { 7 | const map = useGoogleMap(); 8 | return ( 9 | ({ 11 | lat: c.latitude, 12 | lng: c.longitude, 13 | }))} 14 | onClick={(e) => mapMouseEventToMapEvent(e, null, map, 'polygon-press')} 15 | options={{ 16 | geodesic: props.geodesic, 17 | clickable: props.tappable, 18 | fillColor: props.fillColor, 19 | strokeColor: props.strokeColor, 20 | strokeWeight: props.strokeWidth, 21 | }} 22 | /> 23 | ); 24 | } 25 | -------------------------------------------------------------------------------- /packages/react-native-web-maps/src/components/polyline.tsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import { Polyline as GMPolyline, useGoogleMap } from '@react-google-maps/api'; 3 | import type { MapPolylineProps } from 'react-native-maps'; 4 | import { mapMouseEventToMapEvent } from '../utils/mouse-event'; 5 | 6 | export function Polyline(props: MapPolylineProps) { 7 | const map = useGoogleMap(); 8 | 9 | return ( 10 | ({ 12 | lat: c.latitude, 13 | lng: c.longitude, 14 | }))} 15 | onClick={(e) => 16 | props.onPress?.(mapMouseEventToMapEvent(e, null, map, 'polyline-press')) 17 | } 18 | options={{ 19 | geodesic: props.geodesic, 20 | clickable: props.tappable, 21 | strokeColor: props.strokeColor, 22 | strokeWeight: props.strokeWidth, 23 | }} 24 | /> 25 | ); 26 | } 27 | -------------------------------------------------------------------------------- /packages/react-native-web-maps/src/components/user-location-marker.tsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import { StyleSheet, View } from 'react-native'; 3 | import { Marker } from './marker'; 4 | import type { LocationObjectCoords } from 'expo-location'; 5 | 6 | interface UserLocationMarkerProps { 7 | coordinates: LocationObjectCoords; 8 | } 9 | 10 | export function UserLocationMarker(props: UserLocationMarkerProps) { 11 | return ( 12 | 13 | 14 | 15 | ); 16 | } 17 | 18 | const styles = StyleSheet.create({ 19 | container: { 20 | backgroundColor: '#1380FF', 21 | width: 18, 22 | height: 18, 23 | borderRadius: 999, 24 | borderWidth: 2, 25 | borderColor: 'white', 26 | shadowColor: '#000', 27 | shadowOpacity: 0.36, 28 | shadowRadius: 6.68, 29 | shadowOffset: { 30 | width: 0, 31 | height: 5, 32 | }, 33 | }, 34 | }); 35 | -------------------------------------------------------------------------------- /packages/react-native-web-maps/src/hooks/use-user-location.tsx: -------------------------------------------------------------------------------- 1 | import * as Location from 'expo-location'; 2 | import { useCallback, useEffect, useState } from 'react'; 3 | import type { UserLocationChangeEvent } from 'react-native-maps'; 4 | 5 | interface UseUserLocationOptions { 6 | requestPermission: boolean; 7 | onUserLocationChange?(e: UserLocationChangeEvent): void; 8 | followUserLocation: boolean; 9 | showUserLocation: boolean; 10 | } 11 | 12 | export function useUserLocation(options: UseUserLocationOptions) { 13 | const [location, setLocation] = useState(); 14 | 15 | const [watchPositionSubscription, setWatchPositionSubscription] = 16 | useState(); 17 | 18 | const [permission] = Location.useForegroundPermissions({ 19 | request: options.requestPermission, 20 | get: options.showUserLocation, 21 | }); 22 | 23 | const handleLocationChange = useCallback( 24 | function (e: Location.LocationObject) { 25 | setLocation(e); 26 | options.onUserLocationChange?.({ 27 | nativeEvent: { 28 | coordinate: { 29 | ...e.coords, 30 | timestamp: Date.now(), 31 | altitude: e.coords.altitude || 0, 32 | heading: e.coords.heading || 0, 33 | accuracy: e.coords.accuracy || Location.Accuracy.Balanced, 34 | isFromMockProvider: e.mocked || false, 35 | speed: e.coords.speed || 0, 36 | }, 37 | }, 38 | } as unknown as UserLocationChangeEvent); 39 | }, 40 | [options.onUserLocationChange] 41 | ); 42 | 43 | useEffect(() => { 44 | if (permission?.granted && options.followUserLocation) { 45 | Location.getCurrentPositionAsync().then(handleLocationChange); 46 | // Watch position 47 | Location.watchPositionAsync( 48 | { accuracy: Location.Accuracy.Balanced }, 49 | handleLocationChange 50 | ).then(setWatchPositionSubscription); 51 | } 52 | 53 | return () => watchPositionSubscription?.remove(); 54 | }, [permission, options.followUserLocation]); 55 | 56 | return location; 57 | } 58 | -------------------------------------------------------------------------------- /packages/react-native-web-maps/src/index.tsx: -------------------------------------------------------------------------------- 1 | export * from './components/marker-clusterer'; 2 | -------------------------------------------------------------------------------- /packages/react-native-web-maps/src/index.web.tsx: -------------------------------------------------------------------------------- 1 | export { MapView as default } from './components/map-view'; 2 | export { Polygon } from './components/polygon'; 3 | export { Marker } from './components/marker'; 4 | export { Callout } from './components/callout'; 5 | export { Polyline } from './components/polyline'; 6 | export { Circle } from './components/circle'; 7 | export { Geojson } from './components/geojson'; 8 | 9 | export * from './components/marker-clusterer'; 10 | -------------------------------------------------------------------------------- /packages/react-native-web-maps/src/override-types.ts: -------------------------------------------------------------------------------- 1 | import type { MapViewProps as RNMapViewProps } from 'react-native-maps/lib/MapView'; 2 | 3 | /** 4 | * Overrides MapView props to include additional web-specific props 5 | * 6 | * Add '/// ' 7 | * in the app.d.ts file of the app to get overriden types 8 | */ 9 | 10 | declare module 'react-native-maps' { 11 | //@ts-ignore gets rid of 'Duplicate indetfier' error 12 | export interface MapViewProps extends RNMapViewProps { 13 | googleMapsApiKey?: string; 14 | googleMapsMapId?: string; 15 | loadingFallback?: JSX.Element; 16 | options?: google.maps.MapOptions; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /packages/react-native-web-maps/src/utils/camera.ts: -------------------------------------------------------------------------------- 1 | import type { Camera } from 'react-native-maps'; 2 | 3 | export function transformRNCameraObject( 4 | camera: Partial 5 | ): google.maps.CameraOptions { 6 | return { 7 | tilt: camera.pitch, 8 | heading: camera.heading, 9 | zoom: camera.zoom, 10 | center: camera.center 11 | ? { 12 | lat: camera.center?.latitude, 13 | lng: camera.center?.longitude, 14 | } 15 | : undefined, 16 | }; 17 | } 18 | -------------------------------------------------------------------------------- /packages/react-native-web-maps/src/utils/geojson.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * This file is taken from `react-native-maps` 3 | * I guess this has been tested by the creators lol 4 | * Tried to type it but it's a pain 5 | * TODO: Type this bs 6 | * https://github.com/react-native-maps/react-native-maps/blob/master/src/Geojson.js 7 | */ 8 | 9 | export const makeOverlays = (features: GeoJSON.Feature[]) => { 10 | const points = features 11 | .filter( 12 | (f) => 13 | f.geometry && 14 | (f.geometry.type === 'Point' || f.geometry.type === 'MultiPoint') 15 | ) 16 | .map((feature) => 17 | makeCoordinates(feature).map((coordinates) => 18 | makeOverlay(coordinates as any, feature) 19 | ) 20 | ) 21 | .reduce(flatten as any, []) 22 | .map((overlay) => ({ ...overlay, type: 'point' })); 23 | 24 | const lines = features 25 | .filter( 26 | (f) => 27 | f.geometry && 28 | (f.geometry.type === 'LineString' || 29 | f.geometry.type === 'MultiLineString') 30 | ) 31 | .map((feature) => 32 | makeCoordinates(feature).map((coordinates) => 33 | makeOverlay(coordinates as any, feature) 34 | ) 35 | ) 36 | .reduce(flatten as any, []) 37 | .map((overlay) => ({ ...overlay, type: 'polyline' })); 38 | 39 | const multipolygons = features 40 | .filter((f) => f.geometry && f.geometry.type === 'MultiPolygon') 41 | .map((feature) => 42 | makeCoordinates(feature).map((coordinates) => 43 | makeOverlay(coordinates as any, feature) 44 | ) 45 | ) 46 | .reduce(flatten as any, []); 47 | 48 | const polygons = features 49 | .filter((f) => f.geometry && f.geometry.type === 'Polygon') 50 | .map((feature) => makeOverlay(makeCoordinates(feature) as any, feature)) 51 | .reduce(flatten as any, []) 52 | .concat(multipolygons as any) 53 | .map((overlay) => ({ ...(overlay as any), type: 'polygon' })); 54 | 55 | return points.concat(lines).concat(polygons); 56 | }; 57 | 58 | export const flatten = (prev: T, curr: T) => prev.concat(curr); 59 | 60 | export const makeOverlay = ( 61 | coordinates: GeoJSON.Position, 62 | feature: GeoJSON.Feature 63 | ) => { 64 | let overlay: { 65 | feature: GeoJSON.Feature; 66 | coordinates: number | undefined | GeoJSON.Position; 67 | holes: any; 68 | } = { 69 | feature, 70 | } as any; 71 | if ( 72 | feature.geometry.type === 'Polygon' || 73 | feature.geometry.type === 'MultiPolygon' 74 | ) { 75 | overlay.coordinates = coordinates[0]; 76 | if (coordinates.length > 1) { 77 | overlay.holes = coordinates.slice(1); 78 | } 79 | } else { 80 | overlay.coordinates = coordinates; 81 | } 82 | return overlay; 83 | }; 84 | 85 | export const makePoint = (c: GeoJSON.Position) => ({ 86 | latitude: c[1], 87 | longitude: c[0], 88 | }); 89 | 90 | export const makeLine = (l: GeoJSON.Position[]) => l.map(makePoint); 91 | 92 | export const makeCoordinates = (feature: GeoJSON.Feature) => { 93 | const g = feature.geometry; 94 | if (g.type === 'Point') { 95 | return [makePoint(g.coordinates)]; 96 | } else if (g.type === 'MultiPoint') { 97 | return g.coordinates.map(makePoint); 98 | } else if (g.type === 'LineString') { 99 | return [makeLine(g.coordinates)]; 100 | } else if (g.type === 'MultiLineString') { 101 | return g.coordinates.map(makeLine); 102 | } else if (g.type === 'Polygon') { 103 | return g.coordinates.map(makeLine); 104 | } else if (g.type === 'MultiPolygon') { 105 | return g.coordinates.map((p) => p.map(makeLine)); 106 | } else { 107 | return []; 108 | } 109 | }; 110 | 111 | export const doesOverlayContainProperty = (overlay: any, property: any) => { 112 | // Geojson may have 0 for the opacity when intention is to not specify the 113 | // opacity. Therefore, we evaluate the truthiness of the propery where 0 114 | // would return false. 115 | return ( 116 | overlay.feature && 117 | overlay.feature.properties && 118 | overlay.feature.properties[property] 119 | ); 120 | }; 121 | 122 | export const getRgbaFromHex = (hex: string, alpha = 1) => { 123 | const [r, g, b] = hex.match(/\w\w/g)?.map((x) => parseInt(x, 16)) || [ 124 | 0, 0, 0, 125 | ]; 126 | return `rgba(${r},${g},${b},${alpha})`; 127 | }; 128 | 129 | export const getColor = ( 130 | props: any, 131 | overlay: any, 132 | colorType: any, 133 | overrideColorProp: any 134 | ) => { 135 | if (props.hasOwnProperty(overrideColorProp)) { 136 | return props[overrideColorProp]; 137 | } 138 | if (doesOverlayContainProperty(overlay, colorType)) { 139 | let color = overlay.feature.properties[colorType]; 140 | const opacityProperty = colorType + '-opacity'; 141 | if ( 142 | doesOverlayContainProperty(overlay, opacityProperty) && 143 | color[0] === '#' 144 | ) { 145 | color = getRgbaFromHex( 146 | color, 147 | overlay.feature.properties[opacityProperty] 148 | ); 149 | } 150 | return color; 151 | } 152 | return; 153 | }; 154 | 155 | export const getStrokeWidth = (props: any, overlay: any) => { 156 | if (props.hasOwnProperty('strokeWidth')) { 157 | return props.strokeWidth; 158 | } 159 | if (doesOverlayContainProperty(overlay, 'stroke-width')) { 160 | return overlay.feature.properties['stroke-width']; 161 | } 162 | return; 163 | }; 164 | -------------------------------------------------------------------------------- /packages/react-native-web-maps/src/utils/log.ts: -------------------------------------------------------------------------------- 1 | export function logDeprecationWarning(methodName: string) { 2 | console.warn( 3 | `[WARNING] Method ${methodName} is deprecated therefore not implemented. Check https://github.com/react-native-maps/react-native-maps/blob/master/docs/mapview.md#types` 4 | ); 5 | } 6 | 7 | export function logMethodNotImplementedWarning(methodName: string) { 8 | console.warn(`[WARNING] Method ${methodName} is not implemented on web`); 9 | } 10 | -------------------------------------------------------------------------------- /packages/react-native-web-maps/src/utils/mouse-event.ts: -------------------------------------------------------------------------------- 1 | import type { AnimatedRegion, LatLng } from 'react-native-maps'; 2 | 3 | export function mapMouseEventToMapEvent( 4 | e?: google.maps.MapMouseEvent | null, 5 | defaultCoordinate?: LatLng | AnimatedRegion | null, 6 | map?: google.maps.Map | null, 7 | action?: string 8 | ) { 9 | return { 10 | preventDefault: e?.stop, 11 | stopPropagation: e?.stop, 12 | nativeEvent: { 13 | action, 14 | coordinate: { 15 | latitude: e?.latLng?.lat() || defaultCoordinate?.latitude || 0, 16 | longitude: e?.latLng?.lng() || defaultCoordinate?.longitude || 0, 17 | }, 18 | position: map?.getProjection()?.fromLatLngToPoint({ 19 | lat: e?.latLng?.lat() || Number(defaultCoordinate?.latitude) || 0, 20 | lng: e?.latLng?.lng() || Number(defaultCoordinate?.longitude) || 0, 21 | }) || { x: 0, y: 0 }, 22 | }, 23 | } as T; 24 | } 25 | -------------------------------------------------------------------------------- /packages/react-native-web-maps/src/utils/region.ts: -------------------------------------------------------------------------------- 1 | import type { BBox } from 'geojson'; 2 | import type { Region } from 'react-native-maps'; 3 | 4 | /** 5 | * Code taken from https://github.com/react-native-maps/react-native-maps/issues/356 6 | * Solution by https://github.com/MatsMaker 7 | */ 8 | 9 | export const getBoundByRegion = (region: Region, scale = 1): BBox => { 10 | /* 11 | * Latitude : max/min +90 to -90 12 | * Longitude : max/min +180 to -180 13 | */ 14 | // Of course we can do it mo compact but it wait is more obvious 15 | const calcMinLatByOffset = (lng: number, offset: number) => { 16 | const factValue = lng - offset; 17 | if (factValue < -90) { 18 | return (90 + offset) * -1; 19 | } 20 | return factValue; 21 | }; 22 | 23 | const calcMaxLatByOffset = (lng: number, offset: number) => { 24 | const factValue = lng + offset; 25 | if (90 < factValue) { 26 | return (90 - offset) * -1; 27 | } 28 | return factValue; 29 | }; 30 | 31 | const calcMinLngByOffset = (lng: number, offset: number) => { 32 | const factValue = lng - offset; 33 | if (factValue < -180) { 34 | return (180 + offset) * -1; 35 | } 36 | return factValue; 37 | }; 38 | 39 | const calcMaxLngByOffset = (lng: number, offset: number) => { 40 | const factValue = lng + offset; 41 | if (180 < factValue) { 42 | return (180 - offset) * -1; 43 | } 44 | return factValue; 45 | }; 46 | 47 | const latOffset = (region.latitudeDelta / 2) * scale; 48 | const lngD = 49 | region.longitudeDelta < -180 50 | ? 360 + region.longitudeDelta 51 | : region.longitudeDelta; 52 | const lngOffset = (lngD / 2) * scale; 53 | 54 | // bounds.nw.lng, 55 | // bounds.se.lat, 56 | // bounds.se.lng, 57 | // bounds.nw.lat 58 | 59 | return [ 60 | calcMinLngByOffset(region.longitude, lngOffset), // westLng - min lng 61 | calcMinLatByOffset(region.latitude, latOffset), // southLat - min lat 62 | calcMaxLngByOffset(region.longitude, lngOffset), // eastLng - max lng 63 | calcMaxLatByOffset(region.latitude, latOffset), // northLat - max lat 64 | ]; 65 | }; 66 | -------------------------------------------------------------------------------- /packages/react-native-web-maps/tsconfig.build.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig", 3 | "exclude": ["example", "docs"] 4 | } 5 | -------------------------------------------------------------------------------- /packages/react-native-web-maps/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "allowUnreachableCode": false, 4 | "allowUnusedLabels": false, 5 | "esModuleInterop": true, 6 | "importsNotUsedAsValues": "error", 7 | "forceConsistentCasingInFileNames": true, 8 | "jsx": "react", 9 | "lib": ["esnext", "DOM"], 10 | "module": "esnext", 11 | "moduleResolution": "node", 12 | "noFallthroughCasesInSwitch": true, 13 | "noImplicitReturns": true, 14 | "noImplicitUseStrict": false, 15 | "noStrictGenericChecks": false, 16 | "noUncheckedIndexedAccess": true, 17 | "noUnusedLocals": true, 18 | "noUnusedParameters": true, 19 | "resolveJsonModule": true, 20 | "skipLibCheck": true, 21 | "strict": true, 22 | "target": "esnext" 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /turbo.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://turborepo.org/schema.json", 3 | "baseBranch": "origin/main", 4 | "pipeline": { 5 | "build": { 6 | "dependsOn": ["^build"], 7 | "outputs": ["dist/**"] 8 | }, 9 | "dev": { 10 | "dependsOn": ["^dev"], 11 | "outputs": ["dist/**", ".expo/**", ".next/**"] 12 | }, 13 | "test": { 14 | "dependsOn": ["build"], 15 | "outputs": [], 16 | "inputs": ["src/**/*.tsx", "src/**/*.ts", "test/**/*.ts", "test/**/*.tsx"] 17 | }, 18 | 19 | "lint": { 20 | "outputs": [] 21 | } 22 | } 23 | } 24 | --------------------------------------------------------------------------------