├── .github
├── FUNDING.yml
└── workflows
│ ├── ci.yml
│ └── pull_request.yml
├── .gitignore
├── .husky
└── pre-commit
├── .prettierignore
├── .prettierrc
├── LICENSE
├── README.md
├── lerna.json
├── package.json
├── packages
├── api-loader
│ ├── README.md
│ ├── package.json
│ ├── src
│ │ └── index.tsx
│ └── tsconfig.json
├── baidu-map
│ ├── .kktrc.ts
│ ├── README.md
│ ├── __tests__
│ │ └── index.test.tsx
│ ├── package.json
│ ├── src
│ │ └── index.tsx
│ └── tsconfig.json
├── canvas-layer
│ ├── README.md
│ ├── __tests__
│ │ └── index.test.tsx
│ ├── package.json
│ ├── src
│ │ ├── index.tsx
│ │ └── useCanvasLayer.tsx
│ └── tsconfig.json
├── circle
│ ├── README.md
│ ├── __tests__
│ │ └── index.test.tsx
│ ├── package.json
│ ├── src
│ │ ├── index.tsx
│ │ └── useCircle.tsx
│ └── tsconfig.json
├── control
│ ├── README.md
│ ├── __tests__
│ │ └── index.test.tsx
│ ├── package.json
│ ├── src
│ │ ├── getControl.ts
│ │ ├── index.tsx
│ │ └── useControl.tsx
│ └── tsconfig.json
├── copyright-control
│ ├── README.md
│ ├── __tests__
│ │ └── index.test.tsx
│ ├── package.json
│ ├── src
│ │ ├── Item.tsx
│ │ ├── index.tsx
│ │ └── useCopyrightControl.tsx
│ └── tsconfig.json
├── curve-line
│ ├── README.md
│ ├── __tests__
│ │ └── index.test.tsx
│ ├── package.json
│ ├── src
│ │ ├── index.tsx
│ │ └── useCurveLine.tsx
│ └── tsconfig.json
├── custom-overlay
│ ├── README.md
│ ├── __tests__
│ │ └── index.test.tsx
│ ├── package.json
│ ├── src
│ │ ├── index.tsx
│ │ └── useCustomOverlay.tsx
│ └── tsconfig.json
├── drawing-manager
│ ├── README.md
│ ├── __tests__
│ │ └── index.test.tsx
│ ├── package.json
│ ├── src
│ │ ├── index.tsx
│ │ └── useDrawingManager.tsx
│ └── tsconfig.json
├── geolocation-control
│ ├── README.md
│ ├── __tests__
│ │ └── index.test.tsx
│ ├── package.json
│ ├── src
│ │ ├── index.tsx
│ │ └── useGeolocationControl.tsx
│ └── tsconfig.json
├── ground-overlay
│ ├── README.md
│ ├── __tests__
│ │ └── index.test.tsx
│ ├── package.json
│ ├── src
│ │ ├── index.tsx
│ │ └── useGroundOverlay.ts
│ └── tsconfig.json
├── info-window
│ ├── README.md
│ ├── __tests__
│ │ └── index.test.tsx
│ ├── package.json
│ ├── src
│ │ ├── index.tsx
│ │ └── useInfoWindow.ts
│ └── tsconfig.json
├── label
│ ├── README.md
│ ├── __tests__
│ │ └── index.test.tsx
│ ├── package.json
│ ├── src
│ │ ├── index.tsx
│ │ └── useLabel.ts
│ └── tsconfig.json
├── map
│ ├── README.md
│ ├── __tests__
│ │ └── index.test.tsx
│ ├── package.json
│ ├── src
│ │ ├── context.ts
│ │ ├── index.tsx
│ │ └── useMap.tsx
│ └── tsconfig.json
├── marker
│ ├── README.md
│ ├── __tests__
│ │ └── index.test.tsx
│ ├── package.json
│ ├── src
│ │ ├── index.tsx
│ │ ├── markers.png
│ │ ├── markers.ts
│ │ └── useMarker.tsx
│ └── tsconfig.json
├── navigation-control
│ ├── README.md
│ ├── __tests__
│ │ └── index.test.tsx
│ ├── package.json
│ ├── src
│ │ ├── index.tsx
│ │ └── useNavigationControl.tsx
│ └── tsconfig.json
├── overview-map-control
│ ├── README.md
│ ├── __tests__
│ │ └── index.test.tsx
│ ├── package.json
│ ├── src
│ │ ├── index.tsx
│ │ └── useOverviewMapControl.tsx
│ └── tsconfig.json
├── panorama-control
│ ├── README.md
│ ├── __tests__
│ │ └── index.test.tsx
│ ├── package.json
│ ├── src
│ │ ├── index.tsx
│ │ └── usePanoramaControl.tsx
│ └── tsconfig.json
├── point-collection
│ ├── README.md
│ ├── __tests__
│ │ └── index.test.tsx
│ ├── package.json
│ ├── src
│ │ ├── index.tsx
│ │ └── usePointCollection.ts
│ └── tsconfig.json
├── polygon
│ ├── README.md
│ ├── __tests__
│ │ └── index.test.tsx
│ ├── package.json
│ ├── src
│ │ ├── index.tsx
│ │ └── usePolygon.tsx
│ └── tsconfig.json
├── polyline
│ ├── README.md
│ ├── __tests__
│ │ └── index.test.tsx
│ ├── package.json
│ ├── src
│ │ ├── index.tsx
│ │ └── usePolyline.tsx
│ └── tsconfig.json
├── require-script
│ ├── README.md
│ ├── package.json
│ ├── src
│ │ └── index.tsx
│ └── tsconfig.json
├── scale-control
│ ├── README.md
│ ├── __tests__
│ │ └── index.test.tsx
│ ├── package.json
│ ├── src
│ │ ├── index.tsx
│ │ └── useScaleControl.tsx
│ └── tsconfig.json
├── tile-layer
│ ├── README.md
│ ├── __tests__
│ │ └── index.test.tsx
│ ├── package.json
│ ├── src
│ │ ├── index.tsx
│ │ └── useTileLayer.ts
│ └── tsconfig.json
├── type-control
│ ├── README.md
│ ├── __tests__
│ │ └── index.test.tsx
│ ├── package.json
│ ├── src
│ │ ├── index.tsx
│ │ └── useMapTypeControl.tsx
│ └── tsconfig.json
├── types
│ ├── README.md
│ ├── index.d.ts
│ ├── package.json
│ ├── src
│ │ ├── base.d.ts
│ │ ├── bmapgl.d.ts
│ │ ├── bmaplib.d.ts
│ │ ├── control.d.ts
│ │ ├── core.d.ts
│ │ ├── declare.d.ts
│ │ ├── index.d.ts
│ │ ├── maplayer.d.ts
│ │ ├── maptype.d.ts
│ │ ├── overlay.d.ts
│ │ ├── panorama.d.ts
│ │ ├── rightmenu.d.ts
│ │ ├── service.d.ts
│ │ └── tools.d.ts
│ └── tsconfig.json
├── utils
│ ├── README.md
│ ├── package.json
│ ├── src
│ │ ├── hooks.tsx
│ │ ├── index.ts
│ │ ├── noop.ts
│ │ ├── requireScript.ts
│ │ └── usePortal.tsx
│ └── tsconfig.json
└── with-map
│ ├── README.md
│ ├── __tests__
│ └── index.test.tsx
│ ├── package.json
│ ├── src
│ └── index.tsx
│ └── tsconfig.json
├── renovate.json
├── tsconfig.json
└── website
├── .kktrc.ts
├── README.md
├── package.json
├── public
├── bundle.html
├── favicon.ico
├── index.html
└── logo.svg
├── src
├── Layout.tsx
├── components
│ ├── Footer
│ │ └── index.tsx
│ ├── Preview
│ │ ├── Hyperlink.tsx
│ │ └── index.tsx
│ └── SideMenu
│ │ └── index.tsx
├── data.tsx
├── index.less
├── index.tsx
└── react-app-env.d.ts
└── tsconfig.json
/.github/FUNDING.yml:
--------------------------------------------------------------------------------
1 | ko_fi: jaywcjlove
2 | buy_me_a_coffee: jaywcjlove
3 | custom: ["https://www.paypal.me/kennyiseeyou", "https://jaywcjlove.github.io/#/sponsor"]
4 |
--------------------------------------------------------------------------------
/.github/workflows/pull_request.yml:
--------------------------------------------------------------------------------
1 | name: Pull Request Build
2 | on:
3 | pull_request:
4 |
5 | jobs:
6 | build-deploy:
7 | runs-on: ubuntu-latest
8 | steps:
9 | - uses: actions/checkout@v3
10 | - uses: actions/setup-node@v3
11 | with:
12 | node-version: 16
13 | registry-url: 'https://registry.npmjs.org'
14 |
15 | - run: npm -v
16 | - run: npm install -g npm@7
17 | - run: npm -v
18 | - run: npm install
19 | - run: npm install --workspaces
20 | - run: npm run build
21 | - run: npm run doc
22 | - run: npm run coverage
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Created by https://www.gitignore.io/api/node
2 | # Edit at https://www.gitignore.io/?templates=node
3 |
4 | lib
5 | cjs
6 | esm
7 | dist
8 | build
9 | doc
10 | package-lock.json
11 | __snapshots__
12 |
13 | ### Node ###
14 | # Logs
15 | logs
16 | *.log
17 | npm-debug.log*
18 | yarn-debug.log*
19 | yarn-error.log*
20 | lerna-debug.log*
21 |
22 | # Diagnostic reports (https://nodejs.org/api/report.html)
23 | report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
24 |
25 | # Runtime data
26 | pids
27 | *.pid
28 | *.seed
29 | *.pid.lock
30 |
31 | # Directory for instrumented libs generated by jscoverage/JSCover
32 | lib-cov
33 |
34 | # Coverage directory used by tools like istanbul
35 | coverage
36 |
37 | # nyc test coverage
38 | .nyc_output
39 |
40 | # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
41 | .grunt
42 |
43 | # Bower dependency directory (https://bower.io/)
44 | bower_components
45 |
46 | # node-waf configuration
47 | .lock-wscript
48 |
49 | # Compiled binary addons (https://nodejs.org/api/addons.html)
50 | build/Release
51 |
52 | # Dependency directories
53 | node_modules/
54 | jspm_packages/
55 |
56 | # TypeScript v1 declaration files
57 | typings/
58 |
59 | # Optional npm cache directory
60 | .npm
61 |
62 | # Optional eslint cache
63 | .eslintcache
64 |
65 | # Optional REPL history
66 | .node_repl_history
67 |
68 | # Output of 'npm pack'
69 | *.tgz
70 |
71 | # Yarn Integrity file
72 | .yarn-integrity
73 |
74 | # dotenv environment variables file
75 | .env
76 | .env.test
77 |
78 | # parcel-bundler cache (https://parceljs.org/)
79 | .cache
80 |
81 | # next.js build output
82 | .next
83 |
84 | # nuxt.js build output
85 | .nuxt
86 |
87 | # vuepress build output
88 | .vuepress/dist
89 |
90 | # Serverless directories
91 | .serverless/
92 |
93 | # FuseBox cache
94 | .fusebox/
95 |
96 | # DynamoDB Local files
97 | .dynamodb/
98 |
99 | # End of https://www.gitignore.io/api/node
100 |
101 | .DS_Store
102 | .cache
103 | .vscode
104 | .idea
105 | .env
106 |
107 | *.bak
108 | *.tem
109 | *.temp
110 | #.swp
111 | *.*~
112 | ~*.*
113 |
114 | # IDEA
115 | *.iml
116 | *.ipr
117 | *.iws
118 | .idea/
119 |
120 | .history/
--------------------------------------------------------------------------------
/.husky/pre-commit:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | . "$(dirname "$0")/_/husky.sh"
3 |
4 | npx lint-staged
5 |
--------------------------------------------------------------------------------
/.prettierignore:
--------------------------------------------------------------------------------
1 | **/*.md
2 | **/*.svg
3 | **/*.ejs
4 | **/*.html
5 | **/*.yml
6 | package.json
7 | node_modules
8 | build
9 | coverage
10 | dist
11 | esm
12 | lib
13 | test
14 |
--------------------------------------------------------------------------------
/.prettierrc:
--------------------------------------------------------------------------------
1 | {
2 | "singleQuote": true,
3 | "trailingComma": "all",
4 | "printWidth": 120,
5 | "overrides": [
6 | {
7 | "files": ".prettierrc",
8 | "options": { "parser": "json" }
9 | }
10 | ]
11 | }
12 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2019 uiw
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | packages/baidu-map/README.md
--------------------------------------------------------------------------------
/lerna.json:
--------------------------------------------------------------------------------
1 | {
2 | "version": "2.7.3",
3 | "packages": ["packages/*", "website"]
4 | }
5 |
--------------------------------------------------------------------------------
/packages/api-loader/README.md:
--------------------------------------------------------------------------------
1 | APILoader
2 | ===
3 |
4 | [](https://jaywcjlove.github.io/#/sponsor)
5 | [](https://www.npmjs.com/package/@uiw/react-baidu-map-api-loader)
6 | [](https://www.npmjs.com/package/@uiw/react-baidu-map-api-loader)
7 |
8 | 用于加载百度地图 SDK 依赖,加载完成,全局将会有 **`window.BMap`** 对象。
9 |
10 | - [x] 自动加载百度地图 SDK 依赖
11 | - [x] 避免重复加载 SDK 依赖
12 |
13 | ```jsx
14 | import { APILoader } from '@uiw/react-baidu-map';
15 | // 或者单独安装使用
16 | import APILoader from '@uiw/react-baidu-map-api-loader';
17 | ```
18 |
19 | ### 基本用法
20 |
21 | Map 的父组件必须具有宽度和高度;
22 |
23 |
24 | > 🚧 注意:如果你不使用 `APILoader` 组件,需要手动将 SDK 引入到 HTML 中。
25 |
26 |
27 |
28 | ```html
29 |
34 | ```
35 |
36 |
37 | ```jsx mdx:preview
38 | import React from 'react';
39 | import { Map, APILoader } from '@uiw/react-baidu-map';
40 |
41 | const Demo = () => (
42 |
47 | );
48 |
49 | export default Demo;
50 | ```
51 |
52 | ### 禁用 SDK 加载
53 |
54 | 收到一个需求,希望自己在 `html` 中引入 SDK,不需要自动加载,可以使用 `disableScripts` 禁用,在 html 中自己手动添加
55 |
56 | ```jsx
57 |
58 |
59 |
60 | ```
61 |
62 | ```html
63 |
64 | ```
65 |
66 | ### Props
67 |
68 | | 参数 | 说明 | 类型 | 默认值 |
69 | |--------- |-------- |--------- |-------- |
70 | | akay | **`必填`** `disableScripts=true` 时**选填** 您需先[申请密钥(ak)](http://lbs.baidu.com/apiconsole/key?application=key)才可使用该服务,接口无使用次数限制,请开发者放心使用。 | string | - |
71 | | version | SDK 版本 | string | `3.0` |
72 | | protocol | 协议,默认是根据当前网站协议的 | `http`/`https` | `window.location.protocol` |
73 | | hostAndPath | 请求 `SDK` 的前半部分 | string | `api.map.baidu.com/api` |
74 | | type | 可选使用百度的 `webgl` 地图 | `webgl` | - |
75 | | `disableScripts` | 禁用 `SDK` 加载 | boolean | `-` |
--------------------------------------------------------------------------------
/packages/api-loader/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "@uiw/react-baidu-map-api-loader",
3 | "version": "2.7.3",
4 | "description": "Baidu Map api-loader Components for React.",
5 | "funding": "https://jaywcjlove.github.io/#/sponsor",
6 | "homepage": "https://uiwjs.github.io/react-baidu-map/#/api-loader",
7 | "main": "cjs/index.js",
8 | "module": "esm/index.js",
9 | "repository": {
10 | "type": "git",
11 | "url": "https://github.com/uiwjs/react-baidu-map.git"
12 | },
13 | "scripts": {
14 | "build": "tsbb build \"src/*.{tsx,ts}\" --use-babel --cjs cjs --bail",
15 | "watch": "tsbb watch \"src/*.{tsx,ts}\" --use-babel --cjs cjs"
16 | },
17 | "author": "Kenny Wong ",
18 | "license": "MIT",
19 | "files": [
20 | "src",
21 | "esm",
22 | "cjs"
23 | ],
24 | "keywords": [
25 | "react-baidu-map",
26 | "baidu",
27 | "baidu-map",
28 | "baidu-map-utils",
29 | "utils",
30 | "map",
31 | "react",
32 | "bdmap",
33 | "types",
34 | "百度",
35 | "地图",
36 | "百度地图"
37 | ],
38 | "peerDependencies": {
39 | "react": ">=16.14.0",
40 | "react-dom": ">=16.14.0"
41 | },
42 | "dependencies": {
43 | "@babel/runtime": "^7.18.0",
44 | "@uiw/react-baidu-map-utils": "2.7.3"
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/packages/api-loader/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "../../tsconfig",
3 | "include": ["src"],
4 | "compilerOptions": {
5 | "baseUrl": ".",
6 | "outDir": "cjs",
7 | "noEmit": false
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/packages/baidu-map/.kktrc.ts:
--------------------------------------------------------------------------------
1 | import { LoaderConfOptions, WebpackConfiguration } from 'kkt';
2 |
3 | export default (conf: WebpackConfiguration, env: 'production' | 'development', options: LoaderConfOptions) => {
4 | if (options.bundle) {
5 | conf.output!.library = '@uiw/react-baidu-map';
6 | conf.externals = {
7 | react: {
8 | root: 'React',
9 | commonjs2: 'react',
10 | commonjs: 'react',
11 | amd: 'react',
12 | },
13 | 'react-dom': {
14 | root: 'ReactDOM',
15 | commonjs2: 'react-dom',
16 | commonjs: 'react-dom',
17 | amd: 'react-dom',
18 | },
19 | };
20 | }
21 | return conf;
22 | };
23 |
--------------------------------------------------------------------------------
/packages/baidu-map/__tests__/index.test.tsx:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import TestRenderer from 'react-test-renderer';
3 | import { Map, useMap } from '../src';
4 |
5 | describe('', () => {
6 | it('Map test case', () => {
7 | expect(typeof Map).toEqual('object');
8 | expect(typeof useMap).toEqual('function');
9 | const component = TestRenderer.create();
10 | let tree = component.toJSON();
11 | expect(tree).toMatchObject({
12 | type: 'div',
13 | props: { className: undefined, style: { fontSize: 1, height: '100%' } },
14 | children: null,
15 | });
16 | });
17 | });
18 |
--------------------------------------------------------------------------------
/packages/baidu-map/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "@uiw/react-baidu-map",
3 | "version": "2.7.3",
4 | "description": "Baidu Map Components for React.",
5 | "funding": "https://jaywcjlove.github.io/#/sponsor",
6 | "homepage": "https://uiwjs.github.io/react-baidu-map/#/map",
7 | "main": "cjs/index.js",
8 | "module": "esm/index.js",
9 | "repository": {
10 | "type": "git",
11 | "url": "https://github.com/uiwjs/react-baidu-map.git"
12 | },
13 | "scripts": {
14 | "build": "tsbb build \"src/*.{tsx,ts}\" --use-babel --cjs cjs --bail",
15 | "watch": "tsbb watch \"src/*.{tsx,ts}\" --use-babel --cjs cjs"
16 | },
17 | "author": "Kenny Wong ",
18 | "license": "MIT",
19 | "files": [
20 | "dist",
21 | "src",
22 | "esm",
23 | "cjs"
24 | ],
25 | "keywords": [
26 | "react-baidu-map",
27 | "baidu",
28 | "baidu-map",
29 | "map",
30 | "react",
31 | "bdmap",
32 | "types",
33 | "百度",
34 | "地图",
35 | "百度地图"
36 | ],
37 | "peerDependencies": {
38 | "react": ">=16.14.0",
39 | "react-dom": ">=16.14.0"
40 | },
41 | "dependencies": {
42 | "@babel/runtime": "^7.18.0",
43 | "@uiw/react-baidu-map-api-loader": "2.7.3",
44 | "@uiw/react-baidu-map-circle": "2.7.3",
45 | "@uiw/react-baidu-map-control": "2.7.3",
46 | "@uiw/react-baidu-map-copyright-control": "2.7.3",
47 | "@uiw/react-baidu-map-curve-line": "2.7.3",
48 | "@uiw/react-baidu-map-custom-overlay": "2.7.3",
49 | "@uiw/react-baidu-map-drawing-manager": "2.7.3",
50 | "@uiw/react-baidu-map-geolocation-control": "2.7.3",
51 | "@uiw/react-baidu-map-ground-overlay": "2.7.3",
52 | "@uiw/react-baidu-map-info-window": "2.7.3",
53 | "@uiw/react-baidu-map-label": "2.7.3",
54 | "@uiw/react-baidu-map-map": "2.7.3",
55 | "@uiw/react-baidu-map-marker": "2.7.3",
56 | "@uiw/react-baidu-map-navigation-control": "2.7.3",
57 | "@uiw/react-baidu-map-overview-map-control": "2.7.3",
58 | "@uiw/react-baidu-map-panorama-control": "2.7.3",
59 | "@uiw/react-baidu-map-point-collection": "2.7.3",
60 | "@uiw/react-baidu-map-polygon": "2.7.3",
61 | "@uiw/react-baidu-map-polyline": "2.7.3",
62 | "@uiw/react-baidu-map-require-script": "2.7.3",
63 | "@uiw/react-baidu-map-scale-control": "2.7.3",
64 | "@uiw/react-baidu-map-tile-layer": "2.7.3",
65 | "@uiw/react-baidu-map-type-control": "2.7.3",
66 | "@uiw/react-baidu-map-types": "2.7.3",
67 | "@uiw/react-baidu-map-utils": "2.7.3",
68 | "@uiw/react-baidu-map-with-map": "2.7.3"
69 | },
70 | "devDependencies": {
71 | "@types/react": "~18.2.0",
72 | "@types/react-dom": "~18.2.0"
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/packages/baidu-map/src/index.tsx:
--------------------------------------------------------------------------------
1 | export * from '@uiw/react-baidu-map-utils';
2 | export { default as APILoader } from '@uiw/react-baidu-map-api-loader';
3 | export * from '@uiw/react-baidu-map-api-loader';
4 | export { default as Map } from '@uiw/react-baidu-map-map';
5 | export * from '@uiw/react-baidu-map-map';
6 | export { default as Circle } from '@uiw/react-baidu-map-circle';
7 | export * from '@uiw/react-baidu-map-circle';
8 | export { default as CurveLine } from '@uiw/react-baidu-map-curve-line';
9 | export * from '@uiw/react-baidu-map-curve-line';
10 | export { default as CustomOverlay } from '@uiw/react-baidu-map-custom-overlay';
11 | export * from '@uiw/react-baidu-map-custom-overlay';
12 | export { default as Marker } from '@uiw/react-baidu-map-marker';
13 | export * from '@uiw/react-baidu-map-marker';
14 | export { default as Label } from '@uiw/react-baidu-map-label';
15 | export * from '@uiw/react-baidu-map-label';
16 | export { default as TileLayer } from '@uiw/react-baidu-map-tile-layer';
17 | export * from '@uiw/react-baidu-map-tile-layer';
18 | export { default as InfoWindow } from '@uiw/react-baidu-map-info-window';
19 | export * from '@uiw/react-baidu-map-info-window';
20 | export { default as PointCollection } from '@uiw/react-baidu-map-point-collection';
21 | export * from '@uiw/react-baidu-map-point-collection';
22 | export { default as DrawingManager } from '@uiw/react-baidu-map-drawing-manager';
23 | export * from '@uiw/react-baidu-map-drawing-manager';
24 | export { default as Polyline } from '@uiw/react-baidu-map-polyline';
25 | export * from '@uiw/react-baidu-map-polyline';
26 | export { default as Polygon } from '@uiw/react-baidu-map-polygon';
27 | export * from '@uiw/react-baidu-map-polygon';
28 | export { default as withMap } from '@uiw/react-baidu-map-with-map';
29 | export * from '@uiw/react-baidu-map-with-map';
30 | export { default as RequireScript } from '@uiw/react-baidu-map-require-script';
31 |
32 | export { default as Control } from '@uiw/react-baidu-map-control';
33 | export * from '@uiw/react-baidu-map-control';
34 | export { default as CopyrightControl } from '@uiw/react-baidu-map-copyright-control';
35 | export * from '@uiw/react-baidu-map-copyright-control';
36 | export { default as NavigationControl } from '@uiw/react-baidu-map-navigation-control';
37 | export * from '@uiw/react-baidu-map-navigation-control';
38 | export { default as GeolocationControl } from '@uiw/react-baidu-map-geolocation-control';
39 | export * from '@uiw/react-baidu-map-geolocation-control';
40 | export { default as OverviewMapControl } from '@uiw/react-baidu-map-overview-map-control';
41 | export * from '@uiw/react-baidu-map-overview-map-control';
42 | export { default as ScaleControl } from '@uiw/react-baidu-map-scale-control';
43 | export * from '@uiw/react-baidu-map-scale-control';
44 | export { default as MapTypeControl } from '@uiw/react-baidu-map-type-control';
45 | export * from '@uiw/react-baidu-map-type-control';
46 | export { default as PanoramaControl } from '@uiw/react-baidu-map-panorama-control';
47 | export * from '@uiw/react-baidu-map-panorama-control';
48 | export { default as GroundOverlay } from '@uiw/react-baidu-map-ground-overlay';
49 | export * from '@uiw/react-baidu-map-ground-overlay';
50 |
--------------------------------------------------------------------------------
/packages/baidu-map/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "../../tsconfig",
3 | "include": ["src"],
4 | "compilerOptions": {
5 | "baseUrl": ".",
6 | "outDir": "cjs",
7 | "noEmit": false
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/packages/canvas-layer/__tests__/index.test.tsx:
--------------------------------------------------------------------------------
1 | /**
2 | * @jest-environment jsdom
3 | */
4 | import React from 'react';
5 | import TestRenderer from 'react-test-renderer';
6 | import CanvasLayer, { useCanvasLayer } from '../src';
7 |
8 | describe('', () => {
9 | it('CanvasLayer test case', () => {
10 | expect(typeof CanvasLayer).toEqual('object');
11 | expect(typeof useCanvasLayer).toEqual('function');
12 | const component = TestRenderer.create();
13 | let tree = component.toJSON();
14 | expect(tree).toBeNull();
15 | });
16 | });
17 |
--------------------------------------------------------------------------------
/packages/canvas-layer/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "@uiw/react-baidu-map-canvas-layer",
3 | "version": "2.7.3",
4 | "private": true,
5 | "description": "Baidu Map canvas-layer Components for React.",
6 | "funding": "https://jaywcjlove.github.io/#/sponsor",
7 | "homepage": "https://uiwjs.github.io/react-baidu-map/#/canvas-layer",
8 | "main": "cjs/index.js",
9 | "module": "esm/index.js",
10 | "repository": {
11 | "type": "git",
12 | "url": "https://github.com/uiwjs/react-baidu-map.git"
13 | },
14 | "scripts": {
15 | "build": "tsbb build \"src/*.{tsx,ts}\" --use-babel --cjs cjs --bail",
16 | "watch": "tsbb watch \"src/*.{tsx,ts}\" --use-babel --cjs cjs"
17 | },
18 | "author": "Kenny Wong ",
19 | "license": "MIT",
20 | "files": [
21 | "src",
22 | "esm",
23 | "cjs"
24 | ],
25 | "keywords": [
26 | "react-baidu-map",
27 | "baidu",
28 | "baidu-map",
29 | "baidu-map-utils",
30 | "utils",
31 | "map",
32 | "react",
33 | "bdmap",
34 | "types",
35 | "百度",
36 | "地图",
37 | "百度地图"
38 | ],
39 | "peerDependencies": {
40 | "react": ">=16.14.0",
41 | "react-dom": ">=16.14.0"
42 | },
43 | "dependencies": {
44 | "@babel/runtime": "^7.18.0",
45 | "@uiw/react-baidu-map-map": "2.7.3",
46 | "@uiw/react-baidu-map-utils": "2.7.3"
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/packages/canvas-layer/src/index.tsx:
--------------------------------------------------------------------------------
1 | ///
2 |
3 | import React, { useImperativeHandle } from 'react';
4 | import { OverlayProps } from '@uiw/react-baidu-map-map';
5 | import { useCanvasLayer, CanvasLayerResult } from './useCanvasLayer';
6 |
7 | export * from './useCanvasLayer';
8 | export interface CanvasLayerProps extends Omit, OverlayProps {
9 | update?(argument: CanvasLayerResult): void;
10 | }
11 |
12 | export default React.forwardRef(
13 | (props, ref) => {
14 | const { canvasLayer } = useCanvasLayer(props);
15 | useImperativeHandle(ref, () => ({ ...props, canvasLayer }));
16 | return null;
17 | },
18 | );
19 |
--------------------------------------------------------------------------------
/packages/canvas-layer/src/useCanvasLayer.tsx:
--------------------------------------------------------------------------------
1 | import { useState, useMemo } from 'react';
2 | import { useMapContext } from '@uiw/react-baidu-map-map';
3 | import { useVisiable } from '@uiw/react-baidu-map-utils';
4 | import { CanvasLayerProps } from '.';
5 |
6 | export interface UseCanvasLayer extends CanvasLayerProps {}
7 |
8 | export interface CanvasLayerResult {
9 | canvas: React.HTMLAttributes;
10 | ba: React.HTMLAttributes;
11 | options: BMap.CanvasLayerOptions;
12 | zIndex: number;
13 | map: UseCanvasLayer['map'];
14 | BMap: UseCanvasLayer['BMap'];
15 | }
16 |
17 | export function useCanvasLayer(props = {} as UseCanvasLayer) {
18 | const { zIndex, paneName } = props;
19 | const { map } = useMapContext();
20 | const [canvasLayer, setCanvasLayer] = useState();
21 | useMemo(() => {
22 | if (map && BMap && !canvasLayer) {
23 | const update = function (this: CanvasLayerResult) {
24 | const self = this;
25 | props.update && props.update({ ...self, BMap, map });
26 | };
27 | const instance = new BMap.CanvasLayer({ zIndex, paneName, update });
28 | map.addOverlay(instance);
29 | setCanvasLayer(instance);
30 | }
31 | // eslint-disable-next-line react-hooks/exhaustive-deps
32 | }, [map, canvasLayer]);
33 |
34 | useVisiable(canvasLayer!, props);
35 |
36 | return {
37 | canvasLayer,
38 | setCanvasLayer,
39 | };
40 | }
41 |
--------------------------------------------------------------------------------
/packages/canvas-layer/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "../../tsconfig",
3 | "include": ["src"],
4 | "compilerOptions": {
5 | "baseUrl": ".",
6 | "outDir": "cjs",
7 | "noEmit": false
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/packages/circle/__tests__/index.test.tsx:
--------------------------------------------------------------------------------
1 | /**
2 | * @jest-environment jsdom
3 | */
4 | import React from 'react';
5 | import TestRenderer from 'react-test-renderer';
6 | import Circle, { useCircle } from '../src';
7 |
8 | describe('', () => {
9 | it('Circle test case', () => {
10 | expect(typeof Circle).toEqual('object');
11 | expect(typeof useCircle).toEqual('function');
12 | const component = TestRenderer.create();
13 | let tree = component.toJSON();
14 | expect(tree).toBeNull();
15 | });
16 | });
17 |
--------------------------------------------------------------------------------
/packages/circle/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "@uiw/react-baidu-map-circle",
3 | "version": "2.7.3",
4 | "description": "Baidu Map circle Components for React.",
5 | "funding": "https://jaywcjlove.github.io/#/sponsor",
6 | "homepage": "https://uiwjs.github.io/react-baidu-map/#/circle",
7 | "main": "cjs/index.js",
8 | "module": "esm/index.js",
9 | "repository": {
10 | "type": "git",
11 | "url": "https://github.com/uiwjs/react-baidu-map.git"
12 | },
13 | "scripts": {
14 | "build": "tsbb build \"src/*.{tsx,ts}\" --use-babel --cjs cjs --bail",
15 | "watch": "tsbb watch \"src/*.{tsx,ts}\" --use-babel --cjs cjs"
16 | },
17 | "author": "Kenny Wong ",
18 | "license": "MIT",
19 | "files": [
20 | "src",
21 | "esm",
22 | "cjs"
23 | ],
24 | "keywords": [
25 | "react-baidu-map",
26 | "baidu",
27 | "baidu-map",
28 | "baidu-map-circle",
29 | "circle",
30 | "map",
31 | "react",
32 | "bdmap",
33 | "types",
34 | "百度",
35 | "地图",
36 | "百度地图"
37 | ],
38 | "peerDependencies": {
39 | "react": ">=16.14.0",
40 | "react-dom": ">=16.14.0"
41 | },
42 | "dependencies": {
43 | "@babel/runtime": "^7.18.0",
44 | "@uiw/react-baidu-map-map": "2.7.3",
45 | "@uiw/react-baidu-map-utils": "2.7.3"
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/packages/circle/src/index.tsx:
--------------------------------------------------------------------------------
1 | ///
2 |
3 | import React, { useImperativeHandle } from 'react';
4 | import { OverlayProps } from '@uiw/react-baidu-map-map';
5 | import { useCircle } from './useCircle';
6 | export * from './useCircle';
7 |
8 | export interface CircleProps extends OverlayProps, BMap.CircleOptions, BMap.CircleEvents {
9 | /**
10 | * 设置折线的点数组
11 | */
12 | center: BMap.Point;
13 | /**
14 | * 设置圆形的半径,单位为米
15 | */
16 | radius: number;
17 | }
18 |
19 | export default React.forwardRef((props, ref) => {
20 | const { circle } = useCircle(props);
21 | useImperativeHandle(ref, () => ({ ...props, circle }));
22 | return null;
23 | });
24 |
--------------------------------------------------------------------------------
/packages/circle/src/useCircle.tsx:
--------------------------------------------------------------------------------
1 | import { useState, useMemo } from 'react';
2 | import { useMapContext } from '@uiw/react-baidu-map-map';
3 | import { useEnableProperties, useProperties, useVisiable, useEventProperties } from '@uiw/react-baidu-map-utils';
4 | import { CircleProps } from './';
5 |
6 | export interface UseCircle extends CircleProps {}
7 |
8 | export function useCircle(props = {} as UseCircle) {
9 | const {
10 | center,
11 | radius,
12 | strokeColor,
13 | fillColor,
14 | strokeWeight,
15 | strokeOpacity,
16 | fillOpacity,
17 | strokeStyle,
18 | enableMassClear,
19 | enableEditing,
20 | enableClicking,
21 | } = props;
22 | const { map } = useMapContext();
23 | const [circle, setCircle] = useState();
24 |
25 | useMemo(() => {
26 | if (map && !circle) {
27 | let point = center;
28 | if (center && center.lng && center.lat) {
29 | point = new BMap.Point(center.lng, center.lat);
30 | }
31 | const opts = {
32 | strokeColor,
33 | fillColor,
34 | strokeWeight,
35 | strokeOpacity,
36 | fillOpacity,
37 | strokeStyle,
38 | enableMassClear,
39 | enableEditing,
40 | enableClicking,
41 | };
42 | const instance = new BMap.Circle(point, radius, opts);
43 | map.addOverlay(instance);
44 | setCircle(instance);
45 | }
46 | // eslint-disable-next-line react-hooks/exhaustive-deps
47 | }, [map, circle]);
48 |
49 | useVisiable(circle!, props);
50 | useEventProperties(circle!, props, [
51 | 'Click',
52 | 'DblClick',
53 | 'MouseDown',
54 | 'MouseUp',
55 | 'MouseOut',
56 | 'MouseOver',
57 | 'Remove',
58 | 'LineUpdate',
59 | ]);
60 | useEnableProperties(circle!, props, ['Editing', 'MassClear']);
61 | useProperties(circle!, props, [
62 | 'Center',
63 | 'Radius',
64 | 'StrokeColor',
65 | 'FillColor',
66 | 'StrokeOpacity',
67 | 'FillOpacity',
68 | 'StrokeWeight',
69 | 'StrokeStyle',
70 | ]);
71 |
72 | return {
73 | circle,
74 | setCircle,
75 | };
76 | }
77 |
--------------------------------------------------------------------------------
/packages/circle/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "../../tsconfig",
3 | "include": ["src"],
4 | "compilerOptions": {
5 | "baseUrl": ".",
6 | "outDir": "cjs",
7 | "noEmit": false
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/packages/control/__tests__/index.test.tsx:
--------------------------------------------------------------------------------
1 | /**
2 | * @jest-environment jsdom
3 | */
4 | import React from 'react';
5 | import TestRenderer from 'react-test-renderer';
6 | import Control, { useControl } from '../src';
7 |
8 | describe('', () => {
9 | it('Control test case', () => {
10 | expect(typeof Control).toEqual('object');
11 | expect(typeof useControl).toEqual('function');
12 | const component = TestRenderer.create();
13 | let tree = component.toJSON();
14 | expect(tree).toBeNull();
15 | });
16 | });
17 |
--------------------------------------------------------------------------------
/packages/control/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "@uiw/react-baidu-map-control",
3 | "version": "2.7.3",
4 | "description": "Baidu Map control Components for React.",
5 | "funding": "https://jaywcjlove.github.io/#/sponsor",
6 | "homepage": "https://uiwjs.github.io/react-baidu-map/#/control",
7 | "main": "cjs/index.js",
8 | "module": "esm/index.js",
9 | "repository": {
10 | "type": "git",
11 | "url": "https://github.com/uiwjs/react-baidu-map.git"
12 | },
13 | "scripts": {
14 | "build": "tsbb build \"src/*.{tsx,ts}\" --use-babel --cjs cjs --bail",
15 | "watch": "tsbb watch \"src/*.{tsx,ts}\" --use-babel --cjs cjs"
16 | },
17 | "author": "Kenny Wong ",
18 | "license": "MIT",
19 | "files": [
20 | "src",
21 | "esm",
22 | "cjs"
23 | ],
24 | "keywords": [
25 | "react-baidu-map",
26 | "baidu",
27 | "baidu-map",
28 | "baidu-map-control",
29 | "control",
30 | "map",
31 | "react",
32 | "bdmap",
33 | "types",
34 | "百度",
35 | "地图",
36 | "百度地图"
37 | ],
38 | "peerDependencies": {
39 | "react": ">=16.14.0",
40 | "react-dom": ">=16.14.0"
41 | },
42 | "dependencies": {
43 | "@babel/runtime": "^7.18.0",
44 | "@uiw/react-baidu-map-map": "2.7.3",
45 | "@uiw/react-baidu-map-utils": "2.7.3"
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/packages/control/src/getControl.ts:
--------------------------------------------------------------------------------
1 | export default function getCustomOverlay() {
2 | return class extends BMap.Control {
3 | public container: HTMLDivElement;
4 | public map!: BMap.Map;
5 | constructor(elm: HTMLDivElement, defaultAnchor?: BMap.ControlAnchor, defaultOffset?: BMap.Size) {
6 | super();
7 | this.container = elm;
8 | this.defaultAnchor = defaultAnchor || BMAP_ANCHOR_TOP_LEFT;
9 | this.defaultOffset = defaultOffset || new BMap.Size(10, 10);
10 | }
11 | public initialize: (map: BMap.Map) => HTMLElement = (map) => {
12 | this.map = map;
13 | // 添加DOM元素到地图中
14 | map.getContainer().appendChild(this.container);
15 | return this.container;
16 | };
17 | public draw = () => {};
18 | };
19 | }
20 |
--------------------------------------------------------------------------------
/packages/control/src/index.tsx:
--------------------------------------------------------------------------------
1 | ///
2 |
3 | import React, { useImperativeHandle } from 'react';
4 | import { OverlayProps } from '@uiw/react-baidu-map-map';
5 | import { useControl } from './useControl';
6 | export * from './useControl';
7 |
8 | export interface ControlProps extends OverlayProps {
9 | /**
10 | * 控件默认的停靠位置。自定义控件时需要提供此属性,作为控件的默认停靠位置
11 | */
12 | anchor?: BMap.ControlAnchor;
13 | /**
14 | * 控件默认的位置偏移值。自定义控件时需要提供此属性,作为控件的默认偏移位置
15 | */
16 | offset?: BMap.Size;
17 | /**
18 | * 自定义 DOM 元素。
19 | */
20 | children?: React.ReactNode;
21 | }
22 |
23 | export default React.forwardRef((props, ref) => {
24 | const { control, ControlPortal } = useControl(props);
25 | useImperativeHandle(ref, () => ({ ...props, control }), [control, props]);
26 | return {props.children};
27 | });
28 |
--------------------------------------------------------------------------------
/packages/control/src/useControl.tsx:
--------------------------------------------------------------------------------
1 | import { useState, useEffect } from 'react';
2 | import { useMapContext } from '@uiw/react-baidu-map-map';
3 | import { useProperties, useVisiable, usePortal } from '@uiw/react-baidu-map-utils';
4 | import getControl from './getControl';
5 | import { ControlProps } from './';
6 |
7 | export interface UseControl extends ControlProps {}
8 |
9 | export function useControl(props = {} as UseControl) {
10 | const { container, Portal } = usePortal();
11 | const [control, setControl] = useState();
12 | const { offset, anchor } = props;
13 | const { map } = useMapContext();
14 |
15 | useEffect(() => {
16 | if (map && !control && container) {
17 | const Control = getControl();
18 | const instance = new Control(container, anchor, offset);
19 | setControl(instance);
20 | map.addOverlay(instance);
21 | }
22 | return () => {
23 | if (map && control) {
24 | map.removeControl(control);
25 | }
26 | };
27 | }, [map, control, anchor, offset, container]);
28 |
29 | useVisiable(control!, props);
30 | useProperties(control!, props, ['Anchor', 'Offset']);
31 | return {
32 | control,
33 | ControlPortal: Portal,
34 | setControl,
35 | };
36 | }
37 |
--------------------------------------------------------------------------------
/packages/control/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "../../tsconfig",
3 | "include": ["src"],
4 | "compilerOptions": {
5 | "baseUrl": ".",
6 | "outDir": "cjs",
7 | "noEmit": false
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/packages/copyright-control/README.md:
--------------------------------------------------------------------------------
1 | CopyrightControl 版权控件
2 | ===
3 |
4 | [](https://jaywcjlove.github.io/#/sponsor)
5 | [](https://www.npmjs.com/package/@uiw/react-baidu-map-copyright-control)
6 | [](https://www.npmjs.com/package/@uiw/react-baidu-map-copyright-control)
7 |
8 | 版权控件,您可以在地图上添加自己的版权信息。你也可以使用 `Map` 组件 `widget` 属性来设置控件更方便。
9 |
10 | ```jsx
11 | import { CopyrightControl, useCopyrightControl } from '@uiw/react-baidu-map';
12 | // 或者单独安装使用
13 | import CopyrightControl, { useCopyrightControl } from '@uiw/react-baidu-map-copyright-control';
14 | ```
15 |
16 | ### 基本用法
17 |
18 | ```jsx mdx:preview
19 | import React, { useState, useRef } from 'react';
20 | import { Map, APILoader, CopyrightControl } from '@uiw/react-baidu-map';
21 |
22 | const Example = () => {
23 | const [show, setShow] = useState(true);
24 | const [count, setCount] = useState(0);
25 | const map = useRef(null);
26 | const bounds = new BMap.Bounds(new BMap.Point(121.412972,31.245691), new BMap.Point(121.53083,31.185407));
27 | return (
28 | <>
29 |
32 |
56 | >
57 | );
58 | }
59 |
60 | const Demo = () => (
61 |
66 | );
67 | export default Demo;
68 | ```
69 |
70 | ### CopyrightControl
71 |
72 | | 参数 | 说明 | 类型 | 默认值 |
73 | | ----- | ----- | ----- | ----- |
74 | | visiable | 覆盖物是否可见。 | `boolean` | - |
75 | | anchor | 控件的位置偏移值。| `ControlAnchor` | `BMAP_ANCHOR_TOP_RIGHT` |
76 | | offset | 控件的水平偏移值。 | `BMap.Size` | - |
77 |
78 | ### CopyrightControl.Item
79 |
80 | | 参数 | 说明 | 类型 | 默认值 |
81 | | ----- | ----- | ----- | ----- |
82 | | bounds | 该版权信息所适用的地理区域 | `BMap.Bounds(sw: Point, ne: Point)` | - |
83 | | children | 该版权的文本信息,用于显示在地图上,支持HTML内容。 | `React.ReactNode` | - |
84 |
85 | ```js
86 | const bounds = new BMap.Bounds(
87 | new BMap.Point(121.412972,31.245691),
88 | new BMap.Point(121.53083,31.185407)
89 | );
90 | ```
--------------------------------------------------------------------------------
/packages/copyright-control/__tests__/index.test.tsx:
--------------------------------------------------------------------------------
1 | /**
2 | * @jest-environment jsdom
3 | */
4 | import React from 'react';
5 | import TestRenderer from 'react-test-renderer';
6 | import CopyrightControl, { useCopyrightControl } from '../src';
7 |
8 | describe('', () => {
9 | it('CopyrightControl test case', () => {
10 | expect(typeof CopyrightControl).toEqual('object');
11 | expect(typeof useCopyrightControl).toEqual('function');
12 | const component = TestRenderer.create();
13 | let tree = component.toJSON();
14 | expect(tree).toBeNull();
15 | });
16 | });
17 |
--------------------------------------------------------------------------------
/packages/copyright-control/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "@uiw/react-baidu-map-copyright-control",
3 | "version": "2.7.3",
4 | "description": "Baidu Map copyright-control Components for React.",
5 | "funding": "https://jaywcjlove.github.io/#/sponsor",
6 | "homepage": "https://uiwjs.github.io/react-baidu-map/#/copyright-control",
7 | "main": "cjs/index.js",
8 | "module": "esm/index.js",
9 | "repository": {
10 | "type": "git",
11 | "url": "https://github.com/uiwjs/react-baidu-map.git"
12 | },
13 | "scripts": {
14 | "build": "tsbb build \"src/*.{tsx,ts}\" --use-babel --cjs cjs --bail",
15 | "watch": "tsbb watch \"src/*.{tsx,ts}\" --use-babel --cjs cjs"
16 | },
17 | "author": "Kenny Wong ",
18 | "license": "MIT",
19 | "files": [
20 | "src",
21 | "esm",
22 | "cjs"
23 | ],
24 | "keywords": [
25 | "react-baidu-map",
26 | "baidu",
27 | "baidu-map",
28 | "baidu-map-copyright-control",
29 | "copyright-control",
30 | "map",
31 | "react",
32 | "bdmap",
33 | "types",
34 | "百度",
35 | "地图",
36 | "百度地图"
37 | ],
38 | "peerDependencies": {
39 | "react": ">=16.14.0",
40 | "react-dom": ">=16.14.0"
41 | },
42 | "dependencies": {
43 | "@babel/runtime": "^7.18.0",
44 | "@uiw/react-baidu-map-map": "2.7.3",
45 | "@uiw/react-baidu-map-utils": "2.7.3"
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/packages/copyright-control/src/Item.tsx:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import { useEffect, useState } from 'react';
3 | import { usePrevious, usePortal } from '@uiw/react-baidu-map-utils';
4 |
5 | let uid: number = 1;
6 |
7 | export interface CopyrightControlItemProps {
8 | /**
9 | * 自定义 DOM 元素。
10 | */
11 | children?: React.ReactNode;
12 | /**
13 | * 该版权信息所适用的地理区域
14 | */
15 | bounds?: BMap.Bounds;
16 | /**
17 | * 表示版权控件实例,`CopyrightControl` 给子组件注入的一个版权控件实例属性。
18 | */
19 | control?: BMap.CopyrightControl;
20 | }
21 |
22 | export function CopyrightControlItem(props: CopyrightControlItemProps = {}) {
23 | const { children, control, bounds } = props;
24 | const [id] = useState(uid++);
25 | const { container, Portal } = usePortal();
26 | const prevId = usePrevious(id);
27 | useEffect(() => {
28 | if (control) {
29 | control.addCopyright({
30 | id,
31 | bounds,
32 | content: container!.innerHTML,
33 | });
34 | }
35 | return function () {
36 | if (prevId && control) {
37 | control.removeCopyright(prevId);
38 | }
39 | };
40 | }, [bounds, children, container, control, id, prevId]);
41 |
42 | return {children};
43 | }
44 |
--------------------------------------------------------------------------------
/packages/copyright-control/src/index.tsx:
--------------------------------------------------------------------------------
1 | ///
2 | import React, { useImperativeHandle, Fragment } from 'react';
3 | import { OverlayProps } from '@uiw/react-baidu-map-map';
4 | import { useCopyrightControl } from './useCopyrightControl';
5 | import { CopyrightControlItem } from './Item';
6 |
7 | export * from './Item';
8 | export * from './useCopyrightControl';
9 |
10 | export interface CopyrightControlProps extends OverlayProps, BMap.CopyrightControlOptions {
11 | /**
12 | * 自定义 DOM 元素。
13 | */
14 | children?: React.ReactNode;
15 | }
16 |
17 | type RefCopyrightControl = React.ForwardRefExoticComponent<
18 | CopyrightControlProps & React.RefAttributes
19 | > & { Item: typeof CopyrightControlItem };
20 |
21 | const CopyrightControl: RefCopyrightControl = React.forwardRef<
22 | CopyrightControlProps & { copyrightControl?: BMap.CopyrightControl },
23 | CopyrightControlProps
24 | >((props, ref) => {
25 | const { copyrightControl } = useCopyrightControl(props);
26 | useImperativeHandle(ref, () => ({ ...props, copyrightControl }), [copyrightControl, props]);
27 | return (
28 |
29 | {React.Children.toArray(props.children).map((child, index) => {
30 | if (React.isValidElement(child)) {
31 | return React.cloneElement(
32 | child as React.ReactElement<
33 | { control: BMap.CopyrightControl; id: number },
34 | string | React.JSXElementConstructor
35 | >,
36 | {
37 | control: copyrightControl,
38 | id: index + 1,
39 | },
40 | );
41 | }
42 | return child;
43 | })}
44 |
45 | );
46 | }) as unknown as RefCopyrightControl;
47 |
48 | CopyrightControl.Item = CopyrightControlItem;
49 |
50 | export default CopyrightControl;
51 |
--------------------------------------------------------------------------------
/packages/copyright-control/src/useCopyrightControl.tsx:
--------------------------------------------------------------------------------
1 | import { useEffect, useState } from 'react';
2 | import { useMapContext } from '@uiw/react-baidu-map-map';
3 | import { useProperties, useVisiable } from '@uiw/react-baidu-map-utils';
4 | import { CopyrightControlProps } from './';
5 |
6 | export interface UseCopyrightControl extends CopyrightControlProps {}
7 |
8 | export function useCopyrightControl(props = {} as UseCopyrightControl) {
9 | const [copyrightControl, setCopyrightControl] = useState();
10 |
11 | const { anchor, offset } = props;
12 | const { map } = useMapContext();
13 | useEffect(() => {
14 | if (map && !copyrightControl) {
15 | const instance = new BMap.CopyrightControl({
16 | anchor: anchor || BMAP_ANCHOR_TOP_RIGHT,
17 | offset,
18 | });
19 | map.addControl(instance);
20 | setCopyrightControl(instance);
21 | }
22 | return () => {
23 | if (map && copyrightControl) {
24 | map.removeControl(copyrightControl);
25 | }
26 | };
27 | }, [map, copyrightControl, anchor, offset]);
28 |
29 | useVisiable(copyrightControl!, props);
30 | useProperties(copyrightControl!, props, ['Anchor', 'Offset']);
31 |
32 | return {
33 | copyrightControl,
34 | setCopyrightControl,
35 | };
36 | }
37 |
--------------------------------------------------------------------------------
/packages/copyright-control/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "../../tsconfig",
3 | "include": ["src"],
4 | "compilerOptions": {
5 | "baseUrl": ".",
6 | "outDir": "cjs",
7 | "noEmit": false
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/packages/curve-line/__tests__/index.test.tsx:
--------------------------------------------------------------------------------
1 | /**
2 | * @jest-environment jsdom
3 | */
4 | import React from 'react';
5 | import TestRenderer from 'react-test-renderer';
6 | import CurveLine, { useCurveLine } from '../src';
7 |
8 | describe('', () => {
9 | it('CurveLine test case', () => {
10 | expect(typeof CurveLine).toEqual('object');
11 | expect(typeof useCurveLine).toEqual('function');
12 | const component = TestRenderer.create();
13 | let tree = component.toJSON();
14 | expect(tree).toBeNull();
15 | });
16 | });
17 |
--------------------------------------------------------------------------------
/packages/curve-line/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "@uiw/react-baidu-map-curve-line",
3 | "version": "2.7.3",
4 | "description": "Baidu Map Components for React.",
5 | "funding": "https://jaywcjlove.github.io/#/sponsor",
6 | "homepage": "https://uiwjs.github.io/react-baidu-map/#/curve-line",
7 | "main": "cjs/index.js",
8 | "module": "esm/index.js",
9 | "repository": {
10 | "type": "git",
11 | "url": "https://github.com/uiwjs/react-baidu-map.git"
12 | },
13 | "scripts": {
14 | "build": "tsbb build \"src/*.{tsx,ts}\" --use-babel --cjs cjs --bail",
15 | "watch": "tsbb watch \"src/*.{tsx,ts}\" --use-babel --cjs cjs"
16 | },
17 | "author": "Kenny Wong ",
18 | "license": "MIT",
19 | "files": [
20 | "src",
21 | "esm",
22 | "cjs"
23 | ],
24 | "keywords": [
25 | "react-baidu-map",
26 | "baidu",
27 | "baidu-map",
28 | "baidu-map-curve-line",
29 | "curve-line",
30 | "map",
31 | "react",
32 | "bdmap",
33 | "types",
34 | "百度",
35 | "地图",
36 | "百度地图"
37 | ],
38 | "peerDependencies": {
39 | "react": ">=16.14.0",
40 | "react-dom": ">=16.14.0"
41 | },
42 | "dependencies": {
43 | "@babel/runtime": "^7.18.0",
44 | "@uiw/react-baidu-map-map": "2.7.3",
45 | "@uiw/react-baidu-map-utils": "2.7.3"
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/packages/curve-line/src/index.tsx:
--------------------------------------------------------------------------------
1 | ///
2 | import React, { useEffect, useImperativeHandle } from 'react';
3 | import { OverlayProps } from '@uiw/react-baidu-map-map';
4 | import { useCurveLine } from './useCurveLine';
5 |
6 | export * from './useCurveLine';
7 |
8 | export interface CurveLineProps extends BMapLib.CurveLineOptions, BMapLib.CurveLineEvents, OverlayProps {
9 | /**
10 | * 设置弧线的点数组
11 | */
12 | path: BMap.Point[];
13 | }
14 |
15 | export default React.forwardRef((props, ref) => {
16 | const { curveLine, BMapLib, setPath } = useCurveLine(props);
17 | // eslint-disable-next-line react-hooks/exhaustive-deps
18 | useEffect(() => setPath(props.path), [props.path]);
19 | useImperativeHandle(ref, () => ({ ...props, curveLine, BMapLib }));
20 | return null;
21 | });
22 |
--------------------------------------------------------------------------------
/packages/curve-line/src/useCurveLine.tsx:
--------------------------------------------------------------------------------
1 | import { useState, useEffect, useMemo } from 'react';
2 | import { useMapContext } from '@uiw/react-baidu-map-map';
3 | import { requireScript } from '@uiw/react-baidu-map-utils';
4 | import { useEnableProperties, useProperties, useVisiable, useEventProperties } from '@uiw/react-baidu-map-utils';
5 | import { CurveLineProps } from '.';
6 |
7 | export interface UseCurveLine extends CurveLineProps {}
8 |
9 | export function useCurveLine(props = {} as UseCurveLine) {
10 | const {
11 | strokeColor,
12 | strokeWeight,
13 | strokeOpacity,
14 | strokeStyle,
15 | enableMassClear,
16 | enableEditing = false,
17 | enableClicking,
18 | icons,
19 | } = props;
20 | const { map } = useMapContext();
21 | const [curveLine, setCurveLine] = useState();
22 | const libSDK = window.BMapLib;
23 | const [bMapLib, setBMapLib] = useState(libSDK);
24 | const [loadMapLib, setLoadBMapLib] = useState(false || !!libSDK);
25 | // eslint-disable-next-line react-hooks/exhaustive-deps
26 | const opts = {
27 | strokeColor,
28 | strokeWeight,
29 | strokeOpacity,
30 | strokeStyle,
31 | enableMassClear,
32 | enableEditing,
33 | enableClicking,
34 | icons,
35 | };
36 | useMemo(() => {
37 | // 如果第一次加载,会执行下面的
38 | if (map && bMapLib && !curveLine) {
39 | if (bMapLib.CurveLine) {
40 | const points = (props.path || []).map((item) => new BMap.Point(item.lng, item.lat));
41 | const instance = new BMapLib.CurveLine(points, opts);
42 | map.addOverlay(instance);
43 | setCurveLine(instance);
44 | }
45 | }
46 |
47 | // 如果 bMapLib 已经加载过,会执行下面的
48 | if (map && bMapLib && !bMapLib.CurveLine) {
49 | requireScript('//api.map.baidu.com/library/CurveLine/1.5/src/CurveLine.min.js')
50 | .then(() => {
51 | if (window.BMapLib) {
52 | const newMapLib = Object.assign(window.BMapLib, bMapLib);
53 | setBMapLib(newMapLib);
54 |
55 | const points = (props.path || []).map((item) => new BMap.Point(item.lng, item.lat));
56 | const instance = new BMapLib.CurveLine(points, opts);
57 | map.addOverlay(instance);
58 | setCurveLine(instance);
59 | }
60 | })
61 | .catch(() => {});
62 | }
63 |
64 | // 如果第一次加载,会执行下面的
65 | if (!bMapLib && !loadMapLib) {
66 | setLoadBMapLib(true);
67 | requireScript('//api.map.baidu.com/library/CurveLine/1.5/src/CurveLine.min.js')
68 | .then(() => {
69 | if (window.BMapLib) {
70 | setBMapLib(window.BMapLib);
71 | }
72 | })
73 | .catch(() => {});
74 | }
75 | }, [map, bMapLib, curveLine, loadMapLib, props.path, opts]);
76 |
77 | const [path, setPath] = useState(props.path || []);
78 | useEffect(() => {
79 | if (curveLine && props.path && path && JSON.stringify(path) !== JSON.stringify(props.path)) {
80 | const points = path.map((item) => new BMap.Point(item.lng, item.lat));
81 | curveLine.setPath(points);
82 | }
83 | }, [curveLine, path, props.path]);
84 |
85 | useVisiable(curveLine!, props);
86 | useEventProperties(curveLine!, props, [
87 | 'Click',
88 | 'DblClick',
89 | 'MouseDown',
90 | 'MouseUp',
91 | 'MouseOut',
92 | 'MouseOver',
93 | 'Remove',
94 | 'LineUpdate',
95 | ]);
96 | useEnableProperties(curveLine!, props, ['Editing', 'MassClear']);
97 | // PositionAt
98 | useProperties(curveLine!, props, [
99 | 'StrokeColor',
100 | 'StrokeOpacity',
101 | 'StrokeWeight',
102 | 'StrokeStyle',
103 | ]);
104 |
105 | return {
106 | curveLine,
107 | setCurveLine,
108 | BMapLib: bMapLib,
109 | path,
110 | setPath,
111 | };
112 | }
113 |
--------------------------------------------------------------------------------
/packages/curve-line/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "../../tsconfig",
3 | "include": ["src"],
4 | "compilerOptions": {
5 | "baseUrl": ".",
6 | "outDir": "cjs",
7 | "noEmit": false
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/packages/custom-overlay/__tests__/index.test.tsx:
--------------------------------------------------------------------------------
1 | /**
2 | * @jest-environment jsdom
3 | */
4 | import React from 'react';
5 | import TestRenderer from 'react-test-renderer';
6 | import CustomOverlay, { useCustomOverlay } from '../src';
7 |
8 | describe('', () => {
9 | it('CustomOverlay test case', () => {
10 | expect(typeof CustomOverlay).toEqual('object');
11 | expect(typeof useCustomOverlay).toEqual('function');
12 | const component = TestRenderer.create();
13 | let tree = component.toJSON();
14 | expect(tree).toBeNull();
15 | });
16 | });
17 |
--------------------------------------------------------------------------------
/packages/custom-overlay/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "@uiw/react-baidu-map-custom-overlay",
3 | "version": "2.7.3",
4 | "description": "Baidu Map custom-overlay Components for React.",
5 | "funding": "https://jaywcjlove.github.io/#/sponsor",
6 | "homepage": "https://uiwjs.github.io/react-baidu-map/#/custom-overlay",
7 | "main": "cjs/index.js",
8 | "module": "esm/index.js",
9 | "repository": {
10 | "type": "git",
11 | "url": "https://github.com/uiwjs/react-baidu-map.git"
12 | },
13 | "scripts": {
14 | "build": "tsbb build \"src/*.{tsx,ts}\" --use-babel --cjs cjs --bail",
15 | "watch": "tsbb watch \"src/*.{tsx,ts}\" --use-babel --cjs cjs"
16 | },
17 | "author": "Kenny Wong ",
18 | "license": "MIT",
19 | "files": [
20 | "src",
21 | "esm",
22 | "cjs"
23 | ],
24 | "keywords": [
25 | "react-baidu-map",
26 | "baidu",
27 | "baidu-map",
28 | "baidu-map-custom-overlay",
29 | "custom-overlay",
30 | "map",
31 | "react",
32 | "bdmap",
33 | "types",
34 | "百度",
35 | "地图",
36 | "百度地图"
37 | ],
38 | "peerDependencies": {
39 | "react": ">=16.14.0",
40 | "react-dom": ">=16.14.0"
41 | },
42 | "dependencies": {
43 | "@babel/runtime": "^7.18.0",
44 | "@uiw/react-baidu-map-map": "2.7.3",
45 | "@uiw/react-baidu-map-utils": "2.7.3"
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/packages/custom-overlay/src/index.tsx:
--------------------------------------------------------------------------------
1 | ///
2 |
3 | import React, { useImperativeHandle } from 'react';
4 | import { OverlayProps } from '@uiw/react-baidu-map-map';
5 | import { useCustomOverlay } from './useCustomOverlay';
6 |
7 | export * from './useCustomOverlay';
8 |
9 | export interface CustomOverlayProps extends OverlayProps {
10 | /**
11 | * 设置标注的地理坐标。
12 | */
13 | position?: BMap.Point;
14 | /**
15 | * 对应 css z-index 属性,当添加了多个 CustomOverlay 时,可以用于设置层叠顺序
16 | */
17 | zIndex?: number;
18 | /**
19 | *
20 | * 覆盖物层级
21 | * JSAPI 把地图覆盖物分为了8个层级,顶层为 `floatPane`,
22 | * 低层为 `vertexPane`。可以通过Map实例的 `getPanes()` 方法,获取到8个层级的名称
23 | */
24 | paneName?: keyof BMap.MapPanes;
25 | /**
26 | * 覆盖物是否可见。
27 | */
28 | visiable?: boolean;
29 | /**
30 | * 自定义 DOM 元素。
31 | */
32 | children?: React.ReactNode;
33 | }
34 |
35 | export default React.forwardRef((props, ref) => {
36 | const { customOverlay, portal } = useCustomOverlay(props);
37 | // eslint-disable-next-line react-hooks/exhaustive-deps
38 | useImperativeHandle(ref, () => ({ ...props, customOverlay }), [customOverlay]);
39 | if (portal) {
40 | return portal;
41 | }
42 | return null;
43 | });
44 |
--------------------------------------------------------------------------------
/packages/custom-overlay/src/useCustomOverlay.tsx:
--------------------------------------------------------------------------------
1 | import { useState, useMemo, useEffect } from 'react';
2 | import { createPortal } from 'react-dom';
3 | import { useMapContext } from '@uiw/react-baidu-map-map';
4 | import { useProperties, usePrevious } from '@uiw/react-baidu-map-utils';
5 | import { CustomOverlayProps } from './';
6 |
7 | function getCustomOverlay() {
8 | return class extends BMap.Overlay {
9 | public container: HTMLDivElement;
10 | public map!: BMap.Map;
11 | public paneName: keyof BMap.MapPanes;
12 | public position?: BMap.Point;
13 | public offset?: BMap.Size;
14 | constructor(elm: HTMLDivElement, position?: BMap.Point, paneName?: CustomOverlayProps['paneName']) {
15 | super();
16 | this.container = elm;
17 | this.paneName = paneName || 'markerPane';
18 | this.position = position;
19 | }
20 | public initialize: (map: BMap.Map) => HTMLElement = (map) => {
21 | const panes = map.getPanes();
22 | this.container.style.position = 'absolute';
23 | this.map = map;
24 | panes[this.paneName]!.appendChild(this.container);
25 | return this.container;
26 | };
27 | public draw = () => {
28 | if (this.position == null || this.map == null) {
29 | return;
30 | }
31 | const position = this.map.pointToOverlayPixel(this.position);
32 | const { width = 0, height = 0 } = this.offset || {};
33 |
34 | this.container.style.left = `${position.x + width}px`;
35 | this.container.style.top = `${position.y + height}px`;
36 | };
37 | public setOffset = (offset: BMap.Size) => {
38 | this.offset = offset;
39 | this.draw();
40 | };
41 | public setPosition = (position: BMap.Point) => {
42 | this.position = position;
43 | this.draw();
44 | };
45 | public setVisiable = (visiable: boolean) => {
46 | this.container.style.display = visiable ? 'block' : 'none';
47 | };
48 |
49 | public getPosition = () => {
50 | return this.position;
51 | };
52 |
53 | public setZIndex = (index: number) => {
54 | this.container.style.zIndex = index.toString();
55 | };
56 | };
57 | }
58 |
59 | export interface UseCustomOverlay extends CustomOverlayProps {}
60 |
61 | export function useCustomOverlay(props = {} as UseCustomOverlay) {
62 | const { children, paneName, position } = props;
63 | const { map } = useMapContext();
64 | const [customOverlay, setCustomOverlay] = useState();
65 | const [div, setDiv] = useState();
66 | const [portal, setPortal] = useState();
67 | const [count, setCount] = useState(0);
68 | useEffect(() => {
69 | return () => {
70 | if (map && customOverlay) {
71 | map.removeOverlay(customOverlay);
72 | }
73 | };
74 | }, [customOverlay, map]);
75 | useMemo(() => {
76 | if (map && !portal && document) {
77 | const elm = document.createElement('div');
78 | const CustomOverlay = getCustomOverlay();
79 | const portalInstance = createPortal(children, elm);
80 | const CompOverlay = new CustomOverlay(elm, position, paneName);
81 | setCount(count + 1);
82 | setDiv(elm);
83 | map.addOverlay(CompOverlay);
84 | setPortal(portalInstance);
85 | setCustomOverlay(CompOverlay);
86 | }
87 | }, [children, count, map, paneName, portal, position]);
88 |
89 | const prevCount = usePrevious(count);
90 | useMemo(() => {
91 | if (map && div && children && count === prevCount) {
92 | const portalInstance = createPortal(children, div);
93 | setPortal(portalInstance);
94 | setCount(count + 1);
95 | }
96 | // eslint-disable-next-line react-hooks/exhaustive-deps
97 | }, [children, customOverlay]);
98 |
99 | useProperties(customOverlay!, props, ['ZIndex', 'Offset', 'Position', 'Visiable']);
100 | return {
101 | portal,
102 | setPortal,
103 | customOverlay,
104 | setCustomOverlay,
105 | };
106 | }
107 |
--------------------------------------------------------------------------------
/packages/custom-overlay/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "../../tsconfig",
3 | "include": ["src"],
4 | "compilerOptions": {
5 | "baseUrl": ".",
6 | "outDir": "cjs",
7 | "noEmit": false
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/packages/drawing-manager/__tests__/index.test.tsx:
--------------------------------------------------------------------------------
1 | /**
2 | * @jest-environment jsdom
3 | */
4 | import React from 'react';
5 | import TestRenderer from 'react-test-renderer';
6 | import DrawingManager, { useDrawingManager } from '../src';
7 |
8 | describe('', () => {
9 | it('DrawingManager test case', () => {
10 | expect(typeof DrawingManager).toEqual('object');
11 | expect(typeof useDrawingManager).toEqual('function');
12 | const component = TestRenderer.create();
13 | let tree = component.toJSON();
14 | expect(tree).toBeNull();
15 | });
16 | });
17 |
--------------------------------------------------------------------------------
/packages/drawing-manager/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "@uiw/react-baidu-map-drawing-manager",
3 | "version": "2.7.3",
4 | "description": "Baidu Map drawing-manager Components for React.",
5 | "funding": "https://jaywcjlove.github.io/#/sponsor",
6 | "homepage": "https://uiwjs.github.io/react-baidu-map/#/drawing-manager",
7 | "main": "cjs/index.js",
8 | "module": "esm/index.js",
9 | "repository": {
10 | "type": "git",
11 | "url": "https://github.com/uiwjs/react-baidu-map.git"
12 | },
13 | "scripts": {
14 | "build": "tsbb build \"src/*.{tsx,ts}\" --use-babel --cjs cjs --bail",
15 | "watch": "tsbb watch \"src/*.{tsx,ts}\" --use-babel --cjs cjs"
16 | },
17 | "author": "Kenny Wong ",
18 | "license": "MIT",
19 | "files": [
20 | "src",
21 | "esm",
22 | "cjs"
23 | ],
24 | "keywords": [
25 | "react-baidu-map",
26 | "baidu",
27 | "baidu-map",
28 | "baidu-map-drawing-manager",
29 | "drawing-manager",
30 | "map",
31 | "react",
32 | "bdmap",
33 | "types",
34 | "百度",
35 | "地图",
36 | "百度地图"
37 | ],
38 | "peerDependencies": {
39 | "react": ">=16.14.0",
40 | "react-dom": ">=16.14.0"
41 | },
42 | "dependencies": {
43 | "@babel/runtime": "^7.18.0",
44 | "@uiw/react-baidu-map-map": "2.7.3",
45 | "@uiw/react-baidu-map-utils": "2.7.3"
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/packages/drawing-manager/src/index.tsx:
--------------------------------------------------------------------------------
1 | ///
2 | import React, { useImperativeHandle } from 'react';
3 | import { MapChildProps } from '@uiw/react-baidu-map-map';
4 | import { useDrawingManager } from './useDrawingManager';
5 |
6 | export * from './useDrawingManager';
7 | export interface DrawingManagerProps
8 | extends BMapLib.DrawingManagerOptions,
9 | BMapLib.DrawingManagerEvents,
10 | MapChildProps {}
11 |
12 | export default React.forwardRef(
13 | (props, ref) => {
14 | const { drawingManager } = useDrawingManager(props);
15 | useImperativeHandle(ref, () => ({ ...props, drawingManager, BMapLib: window.BMapLib }));
16 | return null;
17 | },
18 | );
19 |
--------------------------------------------------------------------------------
/packages/drawing-manager/src/useDrawingManager.tsx:
--------------------------------------------------------------------------------
1 | import { useState, useMemo } from 'react';
2 | import { useMapContext } from '@uiw/react-baidu-map-map';
3 | import { requireScript, requireCss, useEventProperties } from '@uiw/react-baidu-map-utils';
4 | import { DrawingManagerProps } from '.';
5 |
6 | export interface UseDrawingManager extends DrawingManagerProps {}
7 |
8 | export function useDrawingManager(props = {} as UseDrawingManager) {
9 | const {
10 | isOpen,
11 | drawingMode,
12 | enableDrawingTool,
13 | enableCalculate,
14 | drawingToolOptions,
15 | markerOptions,
16 | circleOptions,
17 | polylineOptions,
18 | polygonOptions,
19 | rectangleOptions,
20 | } = props;
21 | const { map } = useMapContext();
22 |
23 | const [drawingManager, setDrawingManager] = useState();
24 | const libSDK = window.BMapLib;
25 | const [bMapLib, setBMapLib] = useState(libSDK);
26 | const [loadMapLib, setLoadBMapLib] = useState(false || !!libSDK);
27 | const opts = {
28 | isOpen,
29 | drawingMode,
30 | enableDrawingTool,
31 | enableCalculate,
32 | drawingToolOptions,
33 | markerOptions,
34 | circleOptions,
35 | polylineOptions,
36 | polygonOptions,
37 | rectangleOptions,
38 | } as BMapLib.DrawingManagerOptions;
39 |
40 | useMemo(() => {
41 | // 如果第一次加载,会执行下面的
42 | if (map && bMapLib && !drawingManager) {
43 | if (bMapLib.DrawingManager) {
44 | const instance = new BMapLib.DrawingManager(map, opts);
45 | setDrawingManager(instance);
46 | }
47 | }
48 |
49 | // 如果 bMapLib 已经加载过,会执行下面的
50 | if (map && bMapLib && !bMapLib.DrawingManager) {
51 | requireCss('//api.map.baidu.com/library/DrawingManager/1.4/src/DrawingManager_min.css').then(() => {});
52 |
53 | requireScript('//api.map.baidu.com/library/DrawingManager/1.4/src/DrawingManager_min.js')
54 | .then(() => {
55 | if (window.BMapLib) {
56 | const newMapLib = Object.assign(window.BMapLib, bMapLib);
57 | setBMapLib(newMapLib);
58 |
59 | const instance = new BMapLib.DrawingManager(map, opts);
60 | setDrawingManager(instance);
61 | }
62 | })
63 | .catch(() => {});
64 | }
65 |
66 | // 如果第一次加载,会执行下面的
67 | if (!bMapLib && !loadMapLib) {
68 | setLoadBMapLib(true);
69 | requireCss('//api.map.baidu.com/library/DrawingManager/1.4/src/DrawingManager_min.css').then(() => {});
70 | requireScript('//api.map.baidu.com/library/DrawingManager/1.4/src/DrawingManager_min.js')
71 | .then(() => {
72 | if (window.BMapLib) {
73 | setBMapLib(window.BMapLib);
74 | }
75 | })
76 | .catch(() => {});
77 | }
78 | // eslint-disable-next-line react-hooks/exhaustive-deps
79 | }, [map, loadMapLib, bMapLib, drawingManager]);
80 |
81 | useEventProperties(drawingManager!, props, [
82 | 'CircleComplete',
83 | 'MarkerComplete',
84 | 'OverlayComplete',
85 | 'PolygonComplete',
86 | 'PolylineComplete',
87 | 'RectangleComplete',
88 | ]);
89 |
90 | return {
91 | drawingManager,
92 | setDrawingManager,
93 | BMapLib: bMapLib,
94 | };
95 | }
96 |
--------------------------------------------------------------------------------
/packages/drawing-manager/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "../../tsconfig",
3 | "include": ["src"],
4 | "compilerOptions": {
5 | "baseUrl": ".",
6 | "outDir": "cjs",
7 | "noEmit": false
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/packages/geolocation-control/__tests__/index.test.tsx:
--------------------------------------------------------------------------------
1 | /**
2 | * @jest-environment jsdom
3 | */
4 | import React from 'react';
5 | import TestRenderer from 'react-test-renderer';
6 | import GeolocationControl, { useGeolocationControl } from '../src';
7 |
8 | describe('', () => {
9 | it('GeolocationControl test case', () => {
10 | expect(typeof GeolocationControl).toEqual('object');
11 | expect(typeof useGeolocationControl).toEqual('function');
12 | const component = TestRenderer.create();
13 | let tree = component.toJSON();
14 | expect(tree).toBeNull();
15 | });
16 | });
17 |
--------------------------------------------------------------------------------
/packages/geolocation-control/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "@uiw/react-baidu-map-geolocation-control",
3 | "version": "2.7.3",
4 | "description": "Baidu Map geolocation-control Components for React.",
5 | "funding": "https://jaywcjlove.github.io/#/sponsor",
6 | "homepage": "https://uiwjs.github.io/react-baidu-map/#/geolocation-control",
7 | "main": "cjs/index.js",
8 | "module": "esm/index.js",
9 | "repository": {
10 | "type": "git",
11 | "url": "https://github.com/uiwjs/react-baidu-map.git"
12 | },
13 | "scripts": {
14 | "build": "tsbb build \"src/*.{tsx,ts}\" --use-babel --cjs cjs --bail",
15 | "watch": "tsbb watch \"src/*.{tsx,ts}\" --use-babel --cjs cjs"
16 | },
17 | "author": "Kenny Wong ",
18 | "license": "MIT",
19 | "files": [
20 | "src",
21 | "esm",
22 | "cjs"
23 | ],
24 | "keywords": [
25 | "react-baidu-map",
26 | "baidu",
27 | "baidu-map",
28 | "baidu-map-geolocation-control",
29 | "geolocation-control",
30 | "map",
31 | "react",
32 | "bdmap",
33 | "types",
34 | "百度",
35 | "地图",
36 | "百度地图"
37 | ],
38 | "peerDependencies": {
39 | "react": ">=16.14.0",
40 | "react-dom": ">=16.14.0"
41 | },
42 | "dependencies": {
43 | "@babel/runtime": "^7.18.0",
44 | "@uiw/react-baidu-map-map": "2.7.3",
45 | "@uiw/react-baidu-map-utils": "2.7.3"
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/packages/geolocation-control/src/index.tsx:
--------------------------------------------------------------------------------
1 | ///
2 | import React, { useImperativeHandle } from 'react';
3 | import { OverlayProps } from '@uiw/react-baidu-map-map';
4 | import { useGeolocationControl } from './useGeolocationControl';
5 |
6 | export * from './useGeolocationControl';
7 | export interface GeolocationControlProps extends OverlayProps, BMap.GeolocationControlOptions {
8 | /**
9 | * 定位成功后触发此事件
10 | */
11 | onLocationSuccess?(result: { point: BMap.Point; addressComponent: BMap.AddressComponent }): void;
12 | /**
13 | * 定位失败后触发此事件
14 | */
15 | onLocationError?(error: { statusCode: BMap.StatusCode }): void;
16 | }
17 |
18 | export default React.forwardRef((props, ref) => {
19 | const { geolocationControl } = useGeolocationControl(props);
20 | useImperativeHandle(ref, () => ({ ...props, geolocationControl }), [geolocationControl, props]);
21 | return null;
22 | });
23 |
--------------------------------------------------------------------------------
/packages/geolocation-control/src/useGeolocationControl.tsx:
--------------------------------------------------------------------------------
1 | import { useEffect, useState } from 'react';
2 | import { useMapContext } from '@uiw/react-baidu-map-map';
3 | import { useProperties, useVisiable, useEventProperties } from '@uiw/react-baidu-map-utils';
4 | import { GeolocationControlProps } from './';
5 |
6 | export interface UseGeolocationControl extends GeolocationControlProps {}
7 |
8 | export function useGeolocationControl(props = {} as UseGeolocationControl) {
9 | const [geolocationControl, setGeolocationControl] = useState();
10 | const { anchor, offset, showAddressBar, enableAutoLocation, locationIcon } = props;
11 | const { map } = useMapContext();
12 | useEffect(() => {
13 | if (map && !geolocationControl) {
14 | const instance = new BMap.GeolocationControl({
15 | anchor: anchor || BMAP_ANCHOR_TOP_LEFT,
16 | offset,
17 | showAddressBar,
18 | enableAutoLocation,
19 | locationIcon,
20 | });
21 | map.addControl(instance);
22 | setGeolocationControl(instance);
23 | }
24 | return () => {
25 | if (map && geolocationControl) {
26 | try {
27 | map.removeControl(geolocationControl);
28 | } catch (error) {}
29 | }
30 | };
31 | // eslint-disable-next-line react-hooks/exhaustive-deps
32 | }, [map, geolocationControl]);
33 |
34 | useVisiable(geolocationControl!, props);
35 | useEventProperties(
36 | geolocationControl!,
37 | props,
38 | ['LocationSuccess', 'LocationError'],
39 | 'CamelCase',
40 | );
41 | useProperties(geolocationControl!, props, ['Anchor', 'Offset']);
42 | return {
43 | geolocationControl,
44 | setGeolocationControl,
45 | };
46 | }
47 |
--------------------------------------------------------------------------------
/packages/geolocation-control/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "../../tsconfig",
3 | "include": ["src"],
4 | "compilerOptions": {
5 | "baseUrl": ".",
6 | "outDir": "cjs",
7 | "noEmit": false
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/packages/ground-overlay/__tests__/index.test.tsx:
--------------------------------------------------------------------------------
1 | /**
2 | * @jest-environment jsdom
3 | */
4 | import React from 'react';
5 | import TestRenderer from 'react-test-renderer';
6 | import GroundOverlay, { useGroundOverlay } from '../src';
7 |
8 | describe('', () => {
9 | it('GroundOverlay test case', () => {
10 | expect(typeof GroundOverlay).toEqual('object');
11 | expect(typeof useGroundOverlay).toEqual('function');
12 | const component = TestRenderer.create();
13 | let tree = component.toJSON();
14 | expect(tree).toBeNull();
15 | });
16 | });
17 |
--------------------------------------------------------------------------------
/packages/ground-overlay/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "@uiw/react-baidu-map-ground-overlay",
3 | "version": "2.7.3",
4 | "description": "Baidu Map ground-overlay Components for React.",
5 | "funding": "https://jaywcjlove.github.io/#/sponsor",
6 | "homepage": "https://uiwjs.github.io/react-baidu-map/#/ground-overlay",
7 | "main": "cjs/index.js",
8 | "module": "esm/index.js",
9 | "repository": {
10 | "type": "git",
11 | "url": "https://github.com/uiwjs/react-baidu-map.git"
12 | },
13 | "scripts": {
14 | "build": "tsbb build \"src/*.{tsx,ts}\" --use-babel --cjs cjs --bail",
15 | "watch": "tsbb watch \"src/*.{tsx,ts}\" --use-babel --cjs cjs"
16 | },
17 | "author": "Kenny Wong ",
18 | "license": "MIT",
19 | "files": [
20 | "src",
21 | "esm",
22 | "cjs"
23 | ],
24 | "keywords": [
25 | "react-baidu-map",
26 | "baidu",
27 | "baidu-map",
28 | "baidu-map-ground-overlay",
29 | "ground-overlay",
30 | "map",
31 | "react",
32 | "bdmap",
33 | "types",
34 | "百度",
35 | "地图",
36 | "百度地图"
37 | ],
38 | "peerDependencies": {
39 | "react": ">=16.14.0",
40 | "react-dom": ">=16.14.0"
41 | },
42 | "dependencies": {
43 | "@babel/runtime": "^7.18.0",
44 | "@uiw/react-baidu-map-map": "2.7.3",
45 | "@uiw/react-baidu-map-utils": "2.7.3"
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/packages/ground-overlay/src/index.tsx:
--------------------------------------------------------------------------------
1 | ///
2 | import React, { useImperativeHandle } from 'react';
3 | import { OverlayProps } from '@uiw/react-baidu-map-map';
4 | import { useGroundOverlay } from './useGroundOverlay';
5 |
6 | export * from './useGroundOverlay';
7 |
8 | export interface GroundOverlayProps extends OverlayProps, BMap.GroundOverlayOptions, BMap.GroundOverlayEvents {
9 | /**
10 | * 设置矩形区域
11 | */
12 | bounds?: BMap.Bounds;
13 | }
14 |
15 | export default React.forwardRef((props, ref) => {
16 | const { groundOverlay } = useGroundOverlay(props);
17 | // eslint-disable-next-line react-hooks/exhaustive-deps
18 | useImperativeHandle(ref, () => ({ ...props, groundOverlay }), [groundOverlay]);
19 | return null;
20 | });
21 |
--------------------------------------------------------------------------------
/packages/ground-overlay/src/useGroundOverlay.ts:
--------------------------------------------------------------------------------
1 | import { useEffect, useState } from 'react';
2 | import { useMapContext } from '@uiw/react-baidu-map-map';
3 | import { useProperties, useVisiable, useEventProperties } from '@uiw/react-baidu-map-utils';
4 | import { GroundOverlayProps } from './';
5 |
6 | export interface UseGroundOverlay extends GroundOverlayProps {}
7 |
8 | export function useGroundOverlay(props = {} as UseGroundOverlay) {
9 | const [groundOverlay, setGroundOverlay] = useState();
10 | const { bounds, opacity, imageURL, displayOnMinLevel, displayOnMaxLevel } = props;
11 | const { map } = useMapContext();
12 | useEffect(() => {
13 | if (!groundOverlay && bounds && map) {
14 | const instance = new BMap.GroundOverlay(bounds, {
15 | opacity,
16 | imageURL,
17 | displayOnMinLevel,
18 | displayOnMaxLevel,
19 | });
20 | map.addOverlay(instance);
21 | setGroundOverlay(instance);
22 | return () => {
23 | if (map && instance) {
24 | map.removeOverlay(instance);
25 | }
26 | };
27 | }
28 | // eslint-disable-next-line react-hooks/exhaustive-deps
29 | }, [map]);
30 |
31 | useVisiable(groundOverlay!, props);
32 | useEventProperties(groundOverlay!, props, ['Click', 'DblClick']);
33 | useProperties(groundOverlay!, props, [
34 | 'Bounds',
35 | 'Opacity',
36 | 'ImageURL',
37 | 'DisplayOnMinLevel',
38 | 'DispalyOnMaxLevel',
39 | ]);
40 |
41 | return {
42 | groundOverlay,
43 | setGroundOverlay,
44 | };
45 | }
46 |
--------------------------------------------------------------------------------
/packages/ground-overlay/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "../../tsconfig",
3 | "include": ["src"],
4 | "compilerOptions": {
5 | "baseUrl": ".",
6 | "outDir": "cjs",
7 | "noEmit": false
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/packages/info-window/__tests__/index.test.tsx:
--------------------------------------------------------------------------------
1 | /**
2 | * @jest-environment jsdom
3 | */
4 | import React from 'react';
5 | import TestRenderer from 'react-test-renderer';
6 | import InfoWindow, { useInfoWindow } from '../src';
7 |
8 | describe('', () => {
9 | it('InfoWindow test case', () => {
10 | expect(typeof InfoWindow).toEqual('object');
11 | expect(typeof useInfoWindow).toEqual('function');
12 | const component = TestRenderer.create(
13 | xxx} position={{ lng: 121.501365, lat: 31.224942 }} />,
14 | );
15 | let tree = component.toJSON();
16 | expect(tree).toBeNull();
17 | });
18 | });
19 |
--------------------------------------------------------------------------------
/packages/info-window/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "@uiw/react-baidu-map-info-window",
3 | "version": "2.7.3",
4 | "description": "Baidu Map info-window Components for React.",
5 | "funding": "https://jaywcjlove.github.io/#/sponsor",
6 | "homepage": "https://uiwjs.github.io/react-baidu-map/#/info-window",
7 | "main": "cjs/index.js",
8 | "module": "esm/index.js",
9 | "repository": {
10 | "type": "git",
11 | "url": "https://github.com/uiwjs/react-baidu-map.git"
12 | },
13 | "scripts": {
14 | "build": "tsbb build \"src/*.{tsx,ts}\" --use-babel --cjs cjs --bail",
15 | "watch": "tsbb watch \"src/*.{tsx,ts}\" --use-babel --cjs cjs"
16 | },
17 | "author": "Kenny Wong ",
18 | "license": "MIT",
19 | "files": [
20 | "src",
21 | "esm",
22 | "cjs"
23 | ],
24 | "keywords": [
25 | "react-baidu-map",
26 | "baidu",
27 | "baidu-map",
28 | "baidu-map-info-window",
29 | "info-window",
30 | "map",
31 | "react",
32 | "bdmap",
33 | "types",
34 | "百度",
35 | "地图",
36 | "百度地图"
37 | ],
38 | "peerDependencies": {
39 | "react": ">=16.14.0",
40 | "react-dom": ">=16.14.0"
41 | },
42 | "dependencies": {
43 | "@babel/runtime": "^7.18.0",
44 | "@uiw/react-baidu-map-map": "2.7.3",
45 | "@uiw/react-baidu-map-utils": "2.7.3"
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/packages/info-window/src/index.tsx:
--------------------------------------------------------------------------------
1 | ///
2 | import React, { Fragment, useEffect, useImperativeHandle } from 'react';
3 | import { OverlayProps } from '@uiw/react-baidu-map-map';
4 | import { useInfoWindow } from './useInfoWindow';
5 |
6 | export * from './useInfoWindow';
7 |
8 | export interface InfoWindowProps extends OverlayProps, Omit, BMap.InfoWindowEvent {
9 | /**
10 | * 窗口是否打开
11 | * @default true
12 | */
13 | isOpen?: boolean;
14 | /** 窗口位置经纬度 */
15 | position: BMap.Point;
16 | /** 展示文本内容,支持 HTML 内容字符串 */
17 | content?: string | HTMLElement;
18 | /** 信息窗标题文字 */
19 | title?: string | HTMLElement | JSX.Element;
20 | /**
21 | * 信息窗口最大化时所显示内容,支持HTML内容
22 | */
23 | maxContent?: string;
24 | /**
25 | * 展示文本内容,类似于 content
26 | */
27 | children?: JSX.Element;
28 | }
29 |
30 | export default React.forwardRef((props, ref) => {
31 | const { infoWindow, setIsOpen, Portal, PortalTitle } = useInfoWindow(props);
32 |
33 | useEffect(() => setIsOpen(props.isOpen!), [props.isOpen, setIsOpen]);
34 | useImperativeHandle(ref, () => ({ ...props, infoWindow }));
35 | return (
36 |
37 | {props.children}
38 | {props.title as any}
39 |
40 | );
41 | });
42 |
--------------------------------------------------------------------------------
/packages/info-window/src/useInfoWindow.ts:
--------------------------------------------------------------------------------
1 | import { useState, useEffect, useMemo, PropsWithChildren } from 'react';
2 | import { useMapContext } from '@uiw/react-baidu-map-map';
3 | import {
4 | useEnableProperties,
5 | useProperties,
6 | useVisiable,
7 | useEventProperties,
8 | usePortal,
9 | } from '@uiw/react-baidu-map-utils';
10 | import { InfoWindowProps } from '.';
11 |
12 | export interface UseInfoWindow extends PropsWithChildren {}
13 |
14 | export function useInfoWindow(props = {} as UseInfoWindow) {
15 | const { position, ...opts } = props;
16 | const { container, Portal } = usePortal();
17 | const { container: title, Portal: PortalTitle } = usePortal();
18 | const { map } = useMapContext();
19 | const [infoWindow, setInfoWindow] = useState();
20 | useMemo(() => {
21 | if (!infoWindow && map) {
22 | opts.title = title;
23 | const win = new BMap.InfoWindow(props.children ? container : opts.content || '', {
24 | ...(opts as BMap.InfoWindowOptions),
25 | });
26 | setInfoWindow(win);
27 | }
28 | return () => {
29 | if (infoWindow) {
30 | infoWindow.restore();
31 | }
32 | };
33 | // eslint-disable-next-line react-hooks/exhaustive-deps
34 | }, [map]);
35 |
36 | const [isOpen, setIsOpen] = useState(opts.isOpen === undefined ? true : opts.isOpen);
37 | useEffect(() => {
38 | if (map && BMap && infoWindow) {
39 | if (!isOpen) {
40 | map.closeInfoWindow();
41 | } else if (position) {
42 | const point = new BMap.Point(position.lng, position.lat);
43 | map.openInfoWindow(infoWindow, point);
44 | }
45 | }
46 | // eslint-disable-next-line react-hooks/exhaustive-deps
47 | }, [isOpen, infoWindow]);
48 |
49 | useEffect(() => {
50 | if (infoWindow) {
51 | infoWindow.setContent(props.children ? container : opts.content || '');
52 | }
53 | }, [props.content, props.children, infoWindow, container, opts.content]);
54 |
55 | useEffect(() => {
56 | if (infoWindow) {
57 | infoWindow.setTitle(title);
58 | }
59 | }, [infoWindow, props.content, title]);
60 |
61 | useVisiable(infoWindow!, props);
62 | useEventProperties(infoWindow!, props, [
63 | 'Close',
64 | 'Open',
65 | 'Maximize',
66 | 'Restore',
67 | 'ClickClose',
68 | ]);
69 | useProperties(infoWindow!, props, [
70 | 'Width',
71 | 'Height',
72 | // 'Title',
73 | // 'Content',
74 | 'MaxContent',
75 | ]);
76 | useEnableProperties(infoWindow!, props, ['CloseOnClick', 'Maximize', 'AutoPan']);
77 |
78 | return {
79 | /**
80 | * 信息窗口实例对象
81 | */
82 | infoWindow,
83 | /**
84 | * 更新 信息窗口实例对象
85 | */
86 | setInfoWindow,
87 | isOpen,
88 | setIsOpen,
89 | Portal,
90 | PortalTitle,
91 | };
92 | }
93 |
--------------------------------------------------------------------------------
/packages/info-window/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "../../tsconfig",
3 | "include": ["src"],
4 | "compilerOptions": {
5 | "baseUrl": ".",
6 | "outDir": "cjs",
7 | "noEmit": false
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/packages/label/__tests__/index.test.tsx:
--------------------------------------------------------------------------------
1 | /**
2 | * @jest-environment jsdom
3 | */
4 | import React from 'react';
5 | import TestRenderer from 'react-test-renderer';
6 | import Label, { useLabel } from '../src';
7 |
8 | describe('', () => {
9 | it('Label test case', () => {
10 | expect(typeof Label).toEqual('object');
11 | expect(typeof useLabel).toEqual('function');
12 | const component = TestRenderer.create();
13 | let tree = component.toJSON();
14 | expect(tree).toBeNull();
15 | });
16 | });
17 |
--------------------------------------------------------------------------------
/packages/label/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "@uiw/react-baidu-map-label",
3 | "version": "2.7.3",
4 | "description": "Baidu Map label Components for React.",
5 | "funding": "https://jaywcjlove.github.io/#/sponsor",
6 | "homepage": "https://uiwjs.github.io/react-baidu-map/#/label",
7 | "main": "cjs/index.js",
8 | "module": "esm/index.js",
9 | "repository": {
10 | "type": "git",
11 | "url": "https://github.com/uiwjs/react-baidu-map.git"
12 | },
13 | "scripts": {
14 | "build": "tsbb build \"src/*.{tsx,ts}\" --use-babel --cjs cjs --bail",
15 | "watch": "tsbb watch \"src/*.{tsx,ts}\" --use-babel --cjs cjs"
16 | },
17 | "author": "Kenny Wong ",
18 | "license": "MIT",
19 | "files": [
20 | "src",
21 | "esm",
22 | "cjs"
23 | ],
24 | "keywords": [
25 | "react-baidu-map",
26 | "baidu",
27 | "baidu-map",
28 | "baidu-map-label",
29 | "label",
30 | "map",
31 | "react",
32 | "bdmap",
33 | "types",
34 | "百度",
35 | "地图",
36 | "百度地图"
37 | ],
38 | "peerDependencies": {
39 | "react": ">=16.14.0",
40 | "react-dom": ">=16.14.0"
41 | },
42 | "dependencies": {
43 | "@babel/runtime": "^7.18.0",
44 | "@uiw/react-baidu-map-map": "2.7.3",
45 | "@uiw/react-baidu-map-utils": "2.7.3"
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/packages/label/src/index.tsx:
--------------------------------------------------------------------------------
1 | ///
2 | import React, { CSSProperties, useImperativeHandle } from 'react';
3 | import { OverlayProps } from '@uiw/react-baidu-map-map';
4 | import { useLabel } from './useLabel';
5 |
6 | export * from './useLabel';
7 |
8 | export interface LabelProps extends OverlayProps, BMap.LabelOptions, BMap.LabelEvents {
9 | /**
10 | * 文本标注内容
11 | */
12 | content?: string;
13 | /**
14 | * 文本标注样式,该样式将作用于文本标注的容器元素上。
15 | * 其中styles为JavaScript对象常量,比如: setStyle({ color : "red", fontSize : "12px" })
16 | * 注意:如果css的属性名中包含连字符,需要将连字符去掉并将其后的字母进行大写处理,
17 | * 例如:背景色属性要写成:backgroundColor
18 | */
19 | style?: CSSProperties;
20 | children?: JSX.Element;
21 | }
22 |
23 | export default React.forwardRef((props, ref) => {
24 | const { label, Portal } = useLabel({ ...props });
25 | useImperativeHandle(ref, () => ({ ...props, label }), [label, props]);
26 | return {props.children};
27 | });
28 |
--------------------------------------------------------------------------------
/packages/label/src/useLabel.ts:
--------------------------------------------------------------------------------
1 | import { useEffect, useState } from 'react';
2 | import {
3 | usePortal,
4 | useEnableProperties,
5 | useProperties,
6 | useVisiable,
7 | useEventProperties,
8 | } from '@uiw/react-baidu-map-utils';
9 | import { useMapContext } from '@uiw/react-baidu-map-map';
10 | import { LabelProps } from './';
11 |
12 | export interface UseLabel extends LabelProps {}
13 |
14 | export function useLabel(props = {} as UseLabel) {
15 | const [label, setLabel] = useState();
16 | const { offset, style, content = '', position, enableMassClear } = props;
17 | const { container, Portal } = usePortal();
18 | // const { container } = useRenderDom({ children: props.children });
19 | const { map } = useMapContext();
20 |
21 | useEffect(() => {
22 | if (!BMap || !map) return;
23 | if (!label) {
24 | const opts = { offset, position, enableMassClear };
25 | const instance = new BMap.Label(props.children ? container.innerHTML : content, opts);
26 | instance.setStyle({ ...style });
27 | map.addOverlay(instance);
28 | setLabel(instance);
29 | }
30 | return () => {
31 | if (map && label) {
32 | map.removeOverlay(label);
33 | }
34 | };
35 | // eslint-disable-next-line react-hooks/exhaustive-deps
36 | }, [map]);
37 |
38 | useEffect(() => {
39 | if (label) {
40 | label.setContent(props.children ? container.innerHTML : content);
41 | }
42 | // eslint-disable-next-line react-hooks/exhaustive-deps
43 | }, [props.children, container, label]);
44 |
45 | useVisiable(label!, props);
46 | useEventProperties(label!, props, [
47 | 'Click',
48 | 'DblClick',
49 | 'MouseDo',
50 | 'MouseUp',
51 | 'MouseOout',
52 | 'MouseO',
53 | 'Remove',
54 | 'RightClick',
55 | ]);
56 | useProperties(label!, props, ['Style', 'Position', 'Offset', 'Title', 'ZIndex']);
57 | useEnableProperties(label!, props, ['MassClear']);
58 |
59 | return {
60 | label,
61 | setLabel,
62 | Portal,
63 | };
64 | }
65 |
--------------------------------------------------------------------------------
/packages/label/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "../../tsconfig",
3 | "include": ["src"],
4 | "compilerOptions": {
5 | "baseUrl": ".",
6 | "outDir": "cjs",
7 | "noEmit": false
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/packages/map/__tests__/index.test.tsx:
--------------------------------------------------------------------------------
1 | /* eslint-disable jest/no-conditional-expect */
2 | /**
3 | * @jest-environment jsdom
4 | */
5 | import React from 'react';
6 | import TestRenderer from 'react-test-renderer';
7 | import Map from '../src';
8 |
9 | describe('', () => {
10 | it('Should output a Map', () => {
11 | const component = TestRenderer.create();
12 | let tree = component.toJSON();
13 | if (tree && !Array.isArray(tree)) {
14 | expect(tree.type).toBe('div');
15 | expect(tree.props).toEqual({
16 | className: undefined,
17 | style: { fontSize: 1, height: '100%' },
18 | });
19 | }
20 | });
21 | });
22 |
--------------------------------------------------------------------------------
/packages/map/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "@uiw/react-baidu-map-map",
3 | "version": "2.7.3",
4 | "description": "Baidu Map Components for React.",
5 | "funding": "https://jaywcjlove.github.io/#/sponsor",
6 | "homepage": "https://uiwjs.github.io/react-baidu-map/#/map",
7 | "main": "cjs/index.js",
8 | "module": "esm/index.js",
9 | "repository": {
10 | "type": "git",
11 | "url": "https://github.com/uiwjs/react-baidu-map.git"
12 | },
13 | "scripts": {
14 | "build": "tsbb build \"src/*.{tsx,ts}\" --use-babel --cjs cjs --bail",
15 | "watch": "tsbb watch \"src/*.{tsx,ts}\" --use-babel --cjs cjs"
16 | },
17 | "author": "Kenny Wong ",
18 | "license": "MIT",
19 | "files": [
20 | "src",
21 | "esm",
22 | "cjs"
23 | ],
24 | "keywords": [
25 | "react-baidu-map",
26 | "baidu",
27 | "baidu-map",
28 | "baidu-map-utils",
29 | "utils",
30 | "map",
31 | "react",
32 | "bdmap",
33 | "types",
34 | "百度",
35 | "地图",
36 | "百度地图"
37 | ],
38 | "peerDependencies": {
39 | "react": ">=16.14.0",
40 | "react-dom": ">=16.14.0"
41 | },
42 | "dependencies": {
43 | "@babel/runtime": "^7.18.0",
44 | "@uiw/react-baidu-map-api-loader": "2.7.3",
45 | "@uiw/react-baidu-map-types": "2.7.3",
46 | "@uiw/react-baidu-map-utils": "2.7.3"
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/packages/map/src/context.ts:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import { useContext } from 'react';
3 |
4 | type InitialState = {
5 | BMap?: typeof BMap;
6 | map?: BMap.Map;
7 | container?: HTMLDivElement | null;
8 | };
9 |
10 | export const initialState: Partial = {
11 | map: undefined,
12 | BMap: undefined,
13 | container: undefined,
14 | };
15 |
16 | export const reducer = (state: InitialState, action: InitialState) => {
17 | return {
18 | ...state,
19 | ...action,
20 | };
21 | };
22 |
23 | export interface ContextState {
24 | state: Partial;
25 | dispatch: React.Dispatch;
26 | }
27 |
28 | export const Context = React.createContext({
29 | state: initialState,
30 | dispatch: () => null,
31 | });
32 |
33 | export function useMapContext() {
34 | const { state, dispatch } = useContext(Context);
35 | return { ...state, state, dispatch };
36 | }
37 |
--------------------------------------------------------------------------------
/packages/map/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "../../tsconfig",
3 | "include": ["src"],
4 | "compilerOptions": {
5 | "baseUrl": ".",
6 | "outDir": "cjs",
7 | "noEmit": false
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/packages/marker/__tests__/index.test.tsx:
--------------------------------------------------------------------------------
1 | /**
2 | * @jest-environment jsdom
3 | */
4 | import React from 'react';
5 | import TestRenderer from 'react-test-renderer';
6 | import Marker, { useMarker } from '../src';
7 |
8 | describe('', () => {
9 | it('Marker test case', () => {
10 | expect(typeof Marker).toEqual('object');
11 | expect(typeof useMarker).toEqual('function');
12 | const component = TestRenderer.create();
13 | let tree = component.toJSON();
14 | expect(tree).toBeNull();
15 | });
16 | });
17 |
--------------------------------------------------------------------------------
/packages/marker/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "@uiw/react-baidu-map-marker",
3 | "version": "2.7.3",
4 | "description": "Baidu Map map-marker Components for React.",
5 | "funding": "https://jaywcjlove.github.io/#/sponsor",
6 | "homepage": "https://uiwjs.github.io/react-baidu-map/#/marker",
7 | "main": "cjs/index.js",
8 | "module": "esm/index.js",
9 | "repository": {
10 | "type": "git",
11 | "url": "https://github.com/uiwjs/react-baidu-map.git"
12 | },
13 | "scripts": {
14 | "build": "tsbb build \"src/*.{tsx,ts}\" --use-babel --cjs cjs --bail",
15 | "watch": "tsbb watch \"src/*.{tsx,ts}\" --use-babel --cjs cjs"
16 | },
17 | "author": "Kenny Wong ",
18 | "license": "MIT",
19 | "files": [
20 | "src",
21 | "esm",
22 | "cjs"
23 | ],
24 | "keywords": [
25 | "react-baidu-map",
26 | "baidu",
27 | "baidu-map",
28 | "baidu-map-marker",
29 | "map-marker",
30 | "map",
31 | "react",
32 | "bdmap",
33 | "types",
34 | "百度",
35 | "地图",
36 | "百度地图"
37 | ],
38 | "peerDependencies": {
39 | "react": ">=16.14.0",
40 | "react-dom": ">=16.14.0"
41 | },
42 | "dependencies": {
43 | "@babel/runtime": "^7.18.0",
44 | "@uiw/react-baidu-map-map": "2.7.3",
45 | "@uiw/react-baidu-map-utils": "2.7.3"
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/packages/marker/src/index.tsx:
--------------------------------------------------------------------------------
1 | ///
2 | import React, { useEffect, useImperativeHandle } from 'react';
3 | import { OverlayProps } from '@uiw/react-baidu-map-map';
4 | import { useMarker } from './useMarker';
5 |
6 | export * from './useMarker';
7 | export interface MarkerProps extends OverlayProps, BMap.MarkerEvents, BMap.MarkerOptions {
8 | /**
9 | * **`必填`** 设置标注的地理坐标。
10 | */
11 | position: BMap.Point;
12 | /**
13 | * 此常量表示标注的动画效果。
14 | */
15 | animation?: BMap.Animation;
16 | /**
17 | * 标点类型
18 | */
19 | type?:
20 | | 'location'
21 | | 'end'
22 | | 'start'
23 | | 'simple_red'
24 | | 'simple_blue'
25 | | 'loc_blue'
26 | | 'loc_red'
27 | | 'dot_red'
28 | | 'dot_blue'
29 | | 'red1'
30 | | 'red2'
31 | | 'red3'
32 | | 'red4'
33 | | 'red5'
34 | | 'red6'
35 | | 'red7'
36 | | 'red8'
37 | | 'red9'
38 | | 'blue1'
39 | | 'blue2'
40 | | 'blue3'
41 | | 'blue4'
42 | | 'blue5'
43 | | 'blue6'
44 | | 'blue7'
45 | | 'blue8'
46 | | 'blue9';
47 | }
48 |
49 | export default React.forwardRef((props, ref) => {
50 | const { marker, setType } = useMarker(props);
51 | // eslint-disable-next-line react-hooks/exhaustive-deps
52 | useEffect(() => props.type && setType(props.type), [props.type]);
53 | useImperativeHandle(ref, () => ({ ...props, marker }));
54 | return null;
55 | });
56 |
--------------------------------------------------------------------------------
/packages/marker/src/markers.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/uiwjs/react-baidu-map/ca628f0261310de4b1da0acf98703803b8f9b7d3/packages/marker/src/markers.png
--------------------------------------------------------------------------------
/packages/marker/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "../../tsconfig",
3 | "include": ["src"],
4 | "compilerOptions": {
5 | "baseUrl": ".",
6 | "outDir": "cjs",
7 | "noEmit": false
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/packages/navigation-control/__tests__/index.test.tsx:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import TestRenderer from 'react-test-renderer';
3 | import NavigationControl, { useNavigationControl } from '../src';
4 |
5 | describe('', () => {
6 | it('NavigationControl test case', () => {
7 | expect(typeof NavigationControl).toEqual('object');
8 | expect(typeof useNavigationControl).toEqual('function');
9 | const component = TestRenderer.create();
10 | let tree = component.toJSON();
11 | expect(tree).toBeNull();
12 | });
13 | });
14 |
--------------------------------------------------------------------------------
/packages/navigation-control/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "@uiw/react-baidu-map-navigation-control",
3 | "version": "2.7.3",
4 | "description": "Baidu Map map-navigation-control Components for React.",
5 | "funding": "https://jaywcjlove.github.io/#/sponsor",
6 | "homepage": "https://uiwjs.github.io/react-baidu-map/#/navigation-control",
7 | "main": "cjs/index.js",
8 | "module": "esm/index.js",
9 | "repository": {
10 | "type": "git",
11 | "url": "https://github.com/uiwjs/react-baidu-map.git"
12 | },
13 | "scripts": {
14 | "build": "tsbb build \"src/*.{tsx,ts}\" --use-babel --cjs cjs --bail",
15 | "watch": "tsbb watch \"src/*.{tsx,ts}\" --use-babel --cjs cjs"
16 | },
17 | "author": "Kenny Wong ",
18 | "license": "MIT",
19 | "files": [
20 | "src",
21 | "esm",
22 | "cjs"
23 | ],
24 | "keywords": [
25 | "react-baidu-map",
26 | "baidu",
27 | "baidu-map",
28 | "baidu-map-navigation-control",
29 | "map-navigation-control",
30 | "map",
31 | "react",
32 | "bdmap",
33 | "types",
34 | "百度",
35 | "地图",
36 | "百度地图"
37 | ],
38 | "peerDependencies": {
39 | "react": ">=16.14.0",
40 | "react-dom": ">=16.14.0"
41 | },
42 | "dependencies": {
43 | "@babel/runtime": "^7.18.0",
44 | "@uiw/react-baidu-map-map": "2.7.3",
45 | "@uiw/react-baidu-map-utils": "2.7.3"
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/packages/navigation-control/src/index.tsx:
--------------------------------------------------------------------------------
1 | ///
2 | import React, { useImperativeHandle } from 'react';
3 | import { OverlayProps } from '@uiw/react-baidu-map-map';
4 | import { useNavigationControl } from './useNavigationControl';
5 |
6 | export * from './useNavigationControl';
7 | export interface NavigationControlProps extends OverlayProps, BMap.NavigationControlOptions {}
8 |
9 | export default React.forwardRef((props, ref) => {
10 | const { navigationControl } = useNavigationControl(props);
11 | // eslint-disable-next-line react-hooks/exhaustive-deps
12 | useImperativeHandle(ref, () => ({ ...props, navigationControl }), [navigationControl]);
13 | return null;
14 | });
15 |
--------------------------------------------------------------------------------
/packages/navigation-control/src/useNavigationControl.tsx:
--------------------------------------------------------------------------------
1 | import { useEffect, useState } from 'react';
2 | import { useMapContext } from '@uiw/react-baidu-map-map';
3 | import { useProperties, useVisiable } from '@uiw/react-baidu-map-utils';
4 | import { NavigationControlProps } from './';
5 |
6 | export interface UseNavigationControl extends NavigationControlProps {}
7 |
8 | export function useNavigationControl(props = {} as UseNavigationControl) {
9 | const [navigationControl, setNavigationControl] = useState();
10 | const { anchor, offset, type, showZoomInfo, enableGeolocation } = props;
11 | const { map } = useMapContext();
12 | useEffect(() => {
13 | if (!map || navigationControl) return;
14 | const instance = new BMap.NavigationControl({
15 | anchor: anchor || BMAP_ANCHOR_TOP_LEFT,
16 | offset,
17 | type,
18 | showZoomInfo,
19 | enableGeolocation,
20 | });
21 | map.addControl(instance);
22 | setNavigationControl(instance);
23 | return () => {
24 | if (map && instance) {
25 | map.removeControl(instance);
26 | }
27 | };
28 | // eslint-disable-next-line react-hooks/exhaustive-deps
29 | }, [map]);
30 |
31 | useVisiable(navigationControl!, props);
32 | useProperties(navigationControl!, props, ['Anchor', 'Offset', 'Type']);
33 | return {
34 | navigationControl,
35 | setNavigationControl,
36 | };
37 | }
38 |
--------------------------------------------------------------------------------
/packages/navigation-control/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "../../tsconfig",
3 | "include": ["src"],
4 | "compilerOptions": {
5 | "baseUrl": ".",
6 | "outDir": "cjs",
7 | "noEmit": false
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/packages/overview-map-control/README.md:
--------------------------------------------------------------------------------
1 | OverviewMapControl 缩略地图控件
2 | ===
3 |
4 | [](https://jaywcjlove.github.io/#/sponsor)
5 | [](https://www.npmjs.com/package/@uiw/react-baidu-map-overview-map-control)
6 | [](https://www.npmjs.com/package/@uiw/react-baidu-map-overview-map-control)
7 |
8 | 缩略地图控件。你也可以使用 `Map` 组件 `widget` 属性来设置控件更方便。
9 |
10 | ```jsx
11 | import { OverviewMapControl, useOverviewMapControl } from '@uiw/react-baidu-map';
12 | // 或者单独安装使用
13 | import OverviewMapControl, { useOverviewMapControl } from '@uiw/react-baidu-map-overview-map-control';
14 | ```
15 |
16 | ### 基本用法
17 |
18 | ```jsx mdx:preview
19 | import React, { useState, useRef } from 'react';
20 | import { Map, APILoader, OverviewMapControl } from '@uiw/react-baidu-map';
21 |
22 | const Example = () => {
23 | const [show, setShow] = useState(true);
24 | return (
25 |
26 |
29 |
43 |
44 | );
45 | }
46 |
47 | const Demo = () => (
48 |
53 | );
54 |
55 | export default Demo;
56 | ```
57 |
58 |
59 | ### 使用 hooks
60 |
61 | `overviewMapControl`, `setGeolocationControl`
62 |
63 | ```jsx mdx:preview
64 | import React from 'react';
65 | import { useRef, useEffect, useState } from 'react';
66 | import { Map, APILoader, Provider, useMap, useOverviewMapControl } from '@uiw/react-baidu-map';
67 |
68 | const Example = () => {
69 | const divElm = useRef(null);
70 | const [show, setShow] = useState(true);
71 | const { setContainer, map } = useMap();
72 | const { overviewMapControl } = useOverviewMapControl({
73 | map, anchor: BMAP_NAVIGATION_CONTROL_LARGE, visiable: show, isOpen: true,
74 | });
75 |
76 | useEffect(() => {
77 | if (divElm.current && !map) {
78 | setContainer(divElm.current);
79 | }
80 | }, [map]);
81 | return (
82 | <>
83 |
86 |
87 | >
88 | );
89 | }
90 |
91 | const Demo = () => (
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 | );
100 | export default Demo;
101 | ```
102 |
103 | ### Props
104 |
105 | | 参数 | 说明 | 类型 | 默认值 |
106 | | ----- | ----- | ----- | ----- |
107 | | visiable | 覆盖物是否可见。 | `boolean` | - |
108 | | anchor | 控件的位置偏移值。| `ControlAnchor` | `BMAP_ANCHOR_TOP_RIGHT` |
109 | | offset | 控件的水平偏移值。 | `BMap.Size` | - |
110 | | size | 缩略地图控件的大小 | `BMap.Size` | - |
111 | | isOpen | 缩略地图添加到地图后的开合状态,默认为关闭。 | `boolean` | - |
112 |
113 | ### 事件
114 |
115 | | 参数 | 说明 | 类型 |
116 | | ----- | ----- | ----- |
117 | | onViewChanged | 缩略地图开合状态发生变化后触发此事件 | (event: { type: any, target: any, isOpen: boolean }) => void; |
118 | | onViewChanging | 缩略地图开合状态发生变化过程中触发此事件 | (event: { type: any, target: any }) => void; |
119 |
--------------------------------------------------------------------------------
/packages/overview-map-control/__tests__/index.test.tsx:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import TestRenderer from 'react-test-renderer';
3 | import OverviewMapControl, { useOverviewMapControl } from '../src';
4 |
5 | describe('', () => {
6 | it('OverviewMapControl test case', () => {
7 | expect(typeof OverviewMapControl).toEqual('object');
8 | expect(typeof useOverviewMapControl).toEqual('function');
9 | const component = TestRenderer.create();
10 | let tree = component.toJSON();
11 | expect(tree).toBeNull();
12 | });
13 | });
14 |
--------------------------------------------------------------------------------
/packages/overview-map-control/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "@uiw/react-baidu-map-overview-map-control",
3 | "version": "2.7.3",
4 | "description": "Baidu Map map-overview-map-control Components for React.",
5 | "funding": "https://jaywcjlove.github.io/#/sponsor",
6 | "homepage": "https://uiwjs.github.io/react-baidu-map/#/overview-map-control",
7 | "main": "cjs/index.js",
8 | "module": "esm/index.js",
9 | "repository": {
10 | "type": "git",
11 | "url": "https://github.com/uiwjs/react-baidu-map.git"
12 | },
13 | "scripts": {
14 | "build": "tsbb build \"src/*.{tsx,ts}\" --use-babel --cjs cjs --bail",
15 | "watch": "tsbb watch \"src/*.{tsx,ts}\" --use-babel --cjs cjs"
16 | },
17 | "author": "Kenny Wong ",
18 | "license": "MIT",
19 | "files": [
20 | "src",
21 | "esm",
22 | "cjs"
23 | ],
24 | "keywords": [
25 | "react-baidu-map",
26 | "baidu",
27 | "baidu-map",
28 | "baidu-map-overview-map-control",
29 | "map-overview-map-control",
30 | "map",
31 | "react",
32 | "bdmap",
33 | "types",
34 | "百度",
35 | "地图",
36 | "百度地图"
37 | ],
38 | "peerDependencies": {
39 | "react": ">=16.14.0",
40 | "react-dom": ">=16.14.0"
41 | },
42 | "dependencies": {
43 | "@babel/runtime": "^7.18.0",
44 | "@uiw/react-baidu-map-map": "2.7.3",
45 | "@uiw/react-baidu-map-utils": "2.7.3"
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/packages/overview-map-control/src/index.tsx:
--------------------------------------------------------------------------------
1 | ///
2 | import React, { useImperativeHandle } from 'react';
3 | import { OverlayProps } from '@uiw/react-baidu-map-map';
4 | import { useOverviewMapControl } from './useOverviewMapControl';
5 |
6 | export * from './useOverviewMapControl';
7 | export interface OverviewMapControlProps extends OverlayProps, BMap.OverviewMapControlOptions {
8 | /**
9 | * 缩略地图开合状态发生变化后触发此事件
10 | */
11 | onViewChanged?(event: { type: any; target: any; isOpen: boolean }): void;
12 | /**
13 | * 缩略地图开合状态发生变化过程中触发此事件
14 | */
15 | onViewChanging?(event: { type: any; target: any }): void;
16 | }
17 |
18 | export default React.forwardRef((props, ref) => {
19 | const { overviewMapControl } = useOverviewMapControl(props);
20 | // eslint-disable-next-line react-hooks/exhaustive-deps
21 | useImperativeHandle(ref, () => ({ ...props, overviewMapControl }), [overviewMapControl]);
22 | return null;
23 | });
24 |
--------------------------------------------------------------------------------
/packages/overview-map-control/src/useOverviewMapControl.tsx:
--------------------------------------------------------------------------------
1 | import { useEffect, useState } from 'react';
2 | import { useMapContext } from '@uiw/react-baidu-map-map';
3 | import { useProperties, useVisiable, useEventProperties } from '@uiw/react-baidu-map-utils';
4 | import { OverviewMapControlProps } from './';
5 |
6 | export interface UseOverviewMapControl extends OverviewMapControlProps {}
7 |
8 | export function useOverviewMapControl(props = {} as UseOverviewMapControl) {
9 | const [overviewMapControl, setOverviewMapControl] = useState();
10 | const { anchor, offset, size, isOpen } = props;
11 | const { map } = useMapContext();
12 | useEffect(() => {
13 | if (map && !overviewMapControl) {
14 | const instance = new BMap.OverviewMapControl({
15 | anchor: anchor || BMAP_ANCHOR_TOP_LEFT,
16 | offset,
17 | size,
18 | isOpen,
19 | });
20 | map.addControl(instance);
21 | setOverviewMapControl(instance);
22 | return () => {
23 | map.removeControl(instance);
24 | };
25 | }
26 | // eslint-disable-next-line react-hooks/exhaustive-deps
27 | }, [map]);
28 |
29 | useVisiable(overviewMapControl!, props);
30 | useEventProperties(overviewMapControl!, props, [
31 | 'ViewChanged',
32 | 'ViewChanging',
33 | ]);
34 | useProperties(overviewMapControl!, props, [
35 | 'Anchor',
36 | 'Offset',
37 | 'Size',
38 | ]);
39 | return {
40 | overviewMapControl,
41 | setOverviewMapControl,
42 | };
43 | }
44 |
--------------------------------------------------------------------------------
/packages/overview-map-control/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "../../tsconfig",
3 | "include": ["src"],
4 | "compilerOptions": {
5 | "baseUrl": ".",
6 | "outDir": "cjs",
7 | "noEmit": false
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/packages/panorama-control/README.md:
--------------------------------------------------------------------------------
1 | PanoramaControl 全景地图控件
2 | ===
3 |
4 | [](https://jaywcjlove.github.io/#/sponsor)
5 | [](https://www.npmjs.com/package/@uiw/react-baidu-map-panorama-control)
6 | [](https://www.npmjs.com/package/@uiw/react-baidu-map-panorama-control)
7 |
8 | 全景地图控件。
9 |
10 | ```jsx
11 | import { PanoramaControl, usePanoramaControl } from '@uiw/react-baidu-map';
12 | // 或者单独安装使用
13 | import PanoramaControl, { usePanoramaControl } from '@uiw/react-baidu-map-panorama-control';
14 | ```
15 |
16 | ### 基本用法
17 |
18 | ```jsx mdx:preview
19 | import React, { useState } from 'react';
20 | import { Map, APILoader, PanoramaControl } from '@uiw/react-baidu-map';
21 |
22 | const Example = () => {
23 | const [show, setShow] = useState(true);
24 | return (
25 | <>
26 |
29 |
35 | >
36 | );
37 | }
38 |
39 | const Demo = () => (
40 |
45 | );
46 |
47 | export default Demo;
48 | ```
49 |
50 |
51 | ### 使用 hooks
52 |
53 | `panoramaControl`, `setPanoramaControl`
54 |
55 | ```jsx mdx:preview
56 | import React from 'react';
57 | import { useRef, useEffect, useState } from 'react';
58 | import { Map, APILoader, Provider, useMap, usePanoramaControl } from '@uiw/react-baidu-map';
59 |
60 | const Example = () => {
61 | const divElm = useRef(null);
62 | const [show, setShow] = useState(true);
63 | const { setContainer, map } = useMap();
64 | const { panoramaControl } = usePanoramaControl({
65 | map, anchor: BMAP_NAVIGATION_CONTROL_LARGE, visiable: show,
66 | });
67 |
68 | useEffect(() => {
69 | if (divElm.current && !map) {
70 | setContainer(divElm.current);
71 | }
72 | }, [map]);
73 | return (
74 | <>
75 |
78 |
79 | >
80 | );
81 | }
82 |
83 | const Demo = () => (
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 | );
92 | export default Demo;
93 | ```
94 |
95 | ### Props
96 |
97 | | 参数 | 说明 | 类型 | 默认值 |
98 | | ----- | ----- | ----- | ----- |
99 | | visiable | 覆盖物是否可见。 | `boolean` | - |
100 | | ~~anchor~~ | **`无效`** 控件的位置偏移值。| `ControlAnchor` | `BMAP_ANCHOR_TOP_RIGHT` |
101 | | ~~offset~~ | **`无效`** 控件的水平偏移值。 | `BMap.Size` | - |
102 |
--------------------------------------------------------------------------------
/packages/panorama-control/__tests__/index.test.tsx:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import TestRenderer from 'react-test-renderer';
3 | import PanoramaControl, { usePanoramaControl } from '../src';
4 |
5 | describe('', () => {
6 | it('PanoramaControl test case', () => {
7 | expect(typeof PanoramaControl).toEqual('object');
8 | expect(typeof usePanoramaControl).toEqual('function');
9 | const component = TestRenderer.create();
10 | let tree = component.toJSON();
11 | expect(tree).toBeNull();
12 | });
13 | });
14 |
--------------------------------------------------------------------------------
/packages/panorama-control/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "@uiw/react-baidu-map-panorama-control",
3 | "version": "2.7.3",
4 | "description": "Baidu Map map-panorama-control Components for React.",
5 | "funding": "https://jaywcjlove.github.io/#/sponsor",
6 | "homepage": "https://uiwjs.github.io/react-baidu-map/#/panorama-control",
7 | "main": "cjs/index.js",
8 | "module": "esm/index.js",
9 | "repository": {
10 | "type": "git",
11 | "url": "https://github.com/uiwjs/react-baidu-map.git"
12 | },
13 | "scripts": {
14 | "build": "tsbb build \"src/*.{tsx,ts}\" --use-babel --cjs cjs --bail",
15 | "watch": "tsbb watch \"src/*.{tsx,ts}\" --use-babel --cjs cjs"
16 | },
17 | "author": "Kenny Wong ",
18 | "license": "MIT",
19 | "files": [
20 | "src",
21 | "esm",
22 | "cjs"
23 | ],
24 | "keywords": [
25 | "react-baidu-map",
26 | "baidu",
27 | "baidu-map",
28 | "baidu-map-panorama-control",
29 | "map-panorama-control",
30 | "panorama-control",
31 | "map",
32 | "react",
33 | "bdmap",
34 | "types",
35 | "百度",
36 | "地图",
37 | "百度地图"
38 | ],
39 | "peerDependencies": {
40 | "react": ">=16.14.0",
41 | "react-dom": ">=16.14.0"
42 | },
43 | "dependencies": {
44 | "@babel/runtime": "^7.18.0",
45 | "@uiw/react-baidu-map-map": "2.7.3",
46 | "@uiw/react-baidu-map-utils": "2.7.3"
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/packages/panorama-control/src/index.tsx:
--------------------------------------------------------------------------------
1 | ///
2 | import React, { useImperativeHandle } from 'react';
3 | import { OverlayProps } from '@uiw/react-baidu-map-map';
4 | import { usePanoramaControl } from './usePanoramaControl';
5 |
6 | export * from './usePanoramaControl';
7 | export interface PanoramaControlProps extends OverlayProps {}
8 |
9 | export default React.forwardRef((props, ref) => {
10 | const { panoramaControl } = usePanoramaControl(props);
11 | // eslint-disable-next-line react-hooks/exhaustive-deps
12 | useImperativeHandle(ref, () => ({ ...props, panoramaControl }), [panoramaControl]);
13 | return null;
14 | });
15 |
--------------------------------------------------------------------------------
/packages/panorama-control/src/usePanoramaControl.tsx:
--------------------------------------------------------------------------------
1 | import { useEffect, useState } from 'react';
2 | import { useMapContext } from '@uiw/react-baidu-map-map';
3 | import { useVisiable } from '@uiw/react-baidu-map-utils';
4 | import { PanoramaControlProps } from './';
5 |
6 | export interface UsePanoramaControl extends PanoramaControlProps {}
7 |
8 | export function usePanoramaControl(props = {} as UsePanoramaControl) {
9 | const [panoramaControl, setPanoramaControl] = useState();
10 | const { map } = useMapContext();
11 | useEffect(() => {
12 | if (map && !panoramaControl) {
13 | const instance = new BMap.PanoramaControl();
14 | map.addControl(instance);
15 | setPanoramaControl(instance);
16 | return () => {
17 | map.removeControl(instance);
18 | };
19 | }
20 | // eslint-disable-next-line react-hooks/exhaustive-deps
21 | }, [map]);
22 |
23 | useVisiable(panoramaControl!, props);
24 | return {
25 | panoramaControl,
26 | setPanoramaControl,
27 | };
28 | }
29 |
--------------------------------------------------------------------------------
/packages/panorama-control/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "../../tsconfig",
3 | "include": ["src"],
4 | "compilerOptions": {
5 | "baseUrl": ".",
6 | "outDir": "cjs",
7 | "noEmit": false
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/packages/point-collection/__tests__/index.test.tsx:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import TestRenderer from 'react-test-renderer';
3 | import PointCollection, { usePointCollection } from '../src';
4 |
5 | describe('', () => {
6 | it('PointCollection test case', () => {
7 | expect(typeof PointCollection).toEqual('object');
8 | expect(typeof usePointCollection).toEqual('function');
9 | const component = TestRenderer.create();
10 | let tree = component.toJSON();
11 | expect(tree).toBeNull();
12 | });
13 | });
14 |
--------------------------------------------------------------------------------
/packages/point-collection/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "@uiw/react-baidu-map-point-collection",
3 | "version": "2.7.3",
4 | "description": "Baidu Map map-point-collection Components for React.",
5 | "funding": "https://jaywcjlove.github.io/#/sponsor",
6 | "homepage": "https://uiwjs.github.io/react-baidu-map/#/point-collection",
7 | "main": "cjs/index.js",
8 | "module": "esm/index.js",
9 | "repository": {
10 | "type": "git",
11 | "url": "https://github.com/uiwjs/react-baidu-map.git"
12 | },
13 | "scripts": {
14 | "build": "tsbb build \"src/*.{tsx,ts}\" --use-babel --cjs cjs --bail",
15 | "watch": "tsbb watch \"src/*.{tsx,ts}\" --use-babel --cjs cjs"
16 | },
17 | "author": "Kenny Wong ",
18 | "license": "MIT",
19 | "files": [
20 | "src",
21 | "esm",
22 | "cjs"
23 | ],
24 | "keywords": [
25 | "react-baidu-map",
26 | "baidu",
27 | "baidu-map",
28 | "baidu-map-point-collection",
29 | "map-point-collection",
30 | "point-collection",
31 | "map",
32 | "react",
33 | "bdmap",
34 | "types",
35 | "百度",
36 | "地图",
37 | "百度地图"
38 | ],
39 | "peerDependencies": {
40 | "react": ">=16.14.0",
41 | "react-dom": ">=16.14.0"
42 | },
43 | "dependencies": {
44 | "@babel/runtime": "^7.18.0",
45 | "@uiw/react-baidu-map-map": "2.7.3",
46 | "@uiw/react-baidu-map-utils": "2.7.3"
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/packages/point-collection/src/index.tsx:
--------------------------------------------------------------------------------
1 | ///
2 | import React, { useEffect, useImperativeHandle } from 'react';
3 | import { OverlayProps } from '@uiw/react-baidu-map-map';
4 | import { usePointCollection } from './usePointCollection';
5 |
6 | export * from './usePointCollection';
7 | export interface PointCollectionProps extends OverlayProps, BMap.PointCollectionOption, BMap.PointCollectionEvents {
8 | points?: [number, number][];
9 | }
10 |
11 | export default React.forwardRef<
12 | PointCollectionProps & { pointCollection?: BMap.PointCollection },
13 | PointCollectionProps
14 | >((props, ref) => {
15 | const { pointCollection, setPoints } = usePointCollection(props);
16 | // eslint-disable-next-line react-hooks/exhaustive-deps
17 | useEffect(() => setPoints(props.points), [props.points]);
18 | // eslint-disable-next-line react-hooks/exhaustive-deps
19 | useImperativeHandle(ref, () => ({ ...props, pointCollection }), [pointCollection]);
20 | return null;
21 | });
22 |
--------------------------------------------------------------------------------
/packages/point-collection/src/usePointCollection.ts:
--------------------------------------------------------------------------------
1 | import { useState, useEffect } from 'react';
2 | import { useMapContext } from '@uiw/react-baidu-map-map';
3 | import { useProperties, useVisiable, useEventProperties } from '@uiw/react-baidu-map-utils';
4 | import { PointCollectionProps } from './';
5 |
6 | const EVENTS = ['onClick', 'onMouseOver', 'onMouseOut'];
7 |
8 | export interface UsePointCollection extends PointCollectionProps {}
9 |
10 | export function usePointCollection(props = {} as UsePointCollection) {
11 | const { shape, color, size } = props;
12 | const { map } = useMapContext();
13 | const [points, setPoints] = useState(props.points);
14 | const [pointCollection, setPointCollection] = useState();
15 |
16 | const getPoints = (data: [number, number][] = []) => {
17 | const result: BMap.Point[] = [];
18 | data.forEach((item) => {
19 | result.push(new BMap.Point(item[0], item[1]));
20 | });
21 | return result;
22 | };
23 | useEffect(() => {
24 | if (!BMap || !map) return;
25 | // 判断当前浏览器是否支持绘制海量点
26 | if (document && !document.createElement('canvas').getContext) return;
27 | const opts = { shape, color, size };
28 | if (!pointCollection) {
29 | if (!opts.size) opts.size = BMAP_POINT_SIZE_SMALL;
30 | if (!opts.shape) opts.shape = BMAP_POINT_SHAPE_WATERDROP;
31 | if (!opts.color) opts.color = '#d340c3';
32 | const pointCollection = new BMap.PointCollection(getPoints(points), opts);
33 | // pointCollection.clear();
34 | map.addOverlay(pointCollection);
35 | setPointCollection(pointCollection);
36 | EVENTS.forEach((evnetName) => {
37 | if ((props as any)[evnetName]) {
38 | const name = evnetName.replace(/^on/, '').toLowerCase();
39 | pointCollection.addEventListener(name, (props as any)[evnetName]);
40 | }
41 | });
42 | }
43 | // eslint-disable-next-line react-hooks/exhaustive-deps
44 | }, [map]);
45 |
46 | useEffect(() => {
47 | if (pointCollection && points) {
48 | // pointCollection.clear();
49 | pointCollection.setPoints(getPoints(points));
50 | }
51 | }, [points, pointCollection]);
52 |
53 | useVisiable(pointCollection!, props);
54 | useEventProperties(pointCollection!, props, [
55 | 'onClick',
56 | 'onMouseOver',
57 | 'onMouseOut',
58 | ]);
59 | useProperties(pointCollection!, props, ['Styles']);
60 |
61 | return {
62 | pointCollection,
63 | setPointCollection,
64 | points,
65 | setPoints,
66 | };
67 | }
68 |
--------------------------------------------------------------------------------
/packages/point-collection/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "../../tsconfig",
3 | "include": ["src"],
4 | "compilerOptions": {
5 | "baseUrl": ".",
6 | "outDir": "cjs",
7 | "noEmit": false
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/packages/polygon/__tests__/index.test.tsx:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import TestRenderer from 'react-test-renderer';
3 | import Polygon, { usePolygon } from '../src';
4 |
5 | describe('', () => {
6 | it('Polygon test case', () => {
7 | expect(typeof Polygon).toEqual('object');
8 | expect(typeof usePolygon).toEqual('function');
9 | const component = TestRenderer.create(
10 | ,
17 | );
18 | let tree = component.toJSON();
19 | expect(tree).toBeNull();
20 | });
21 | });
22 |
--------------------------------------------------------------------------------
/packages/polygon/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "@uiw/react-baidu-map-polygon",
3 | "version": "2.7.3",
4 | "description": "Baidu Map map-polygon Components for React.",
5 | "funding": "https://jaywcjlove.github.io/#/sponsor",
6 | "homepage": "https://uiwjs.github.io/react-baidu-map/#/polygon",
7 | "main": "cjs/index.js",
8 | "module": "esm/index.js",
9 | "repository": {
10 | "type": "git",
11 | "url": "https://github.com/uiwjs/react-baidu-map.git"
12 | },
13 | "scripts": {
14 | "build": "tsbb build \"src/*.{tsx,ts}\" --use-babel --cjs cjs --bail",
15 | "watch": "tsbb watch \"src/*.{tsx,ts}\" --use-babel --cjs cjs"
16 | },
17 | "author": "Kenny Wong ",
18 | "license": "MIT",
19 | "files": [
20 | "src",
21 | "esm",
22 | "cjs"
23 | ],
24 | "keywords": [
25 | "react-baidu-map",
26 | "baidu",
27 | "baidu-map",
28 | "baidu-map-polygon",
29 | "map-polygon",
30 | "polygon",
31 | "map",
32 | "react",
33 | "bdmap",
34 | "types",
35 | "百度",
36 | "地图",
37 | "百度地图"
38 | ],
39 | "peerDependencies": {
40 | "react": ">=16.14.0",
41 | "react-dom": ">=16.14.0"
42 | },
43 | "dependencies": {
44 | "@babel/runtime": "^7.18.0",
45 | "@uiw/react-baidu-map-map": "2.7.3",
46 | "@uiw/react-baidu-map-utils": "2.7.3"
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/packages/polygon/src/index.tsx:
--------------------------------------------------------------------------------
1 | ///
2 | import React, { useEffect, useImperativeHandle } from 'react';
3 | import { OverlayProps } from '@uiw/react-baidu-map-map';
4 | import { usePolygon } from './usePolygon';
5 |
6 | export * from './usePolygon';
7 | export interface PolygonProps extends BMap.PolygonOptions, BMap.PolygonEvents, OverlayProps {
8 | /**
9 | * 设置折线的点数组
10 | */
11 | path: BMap.Point[];
12 | }
13 |
14 | export default React.forwardRef((props, ref) => {
15 | const { polygon, setPath } = usePolygon(props);
16 | // eslint-disable-next-line react-hooks/exhaustive-deps
17 | useEffect(() => setPath(props.path), [props.path]);
18 | // eslint-disable-next-line react-hooks/exhaustive-deps
19 | useImperativeHandle(ref, () => ({ ...props, polygon }), [polygon, props]);
20 | return null;
21 | });
22 |
--------------------------------------------------------------------------------
/packages/polygon/src/usePolygon.tsx:
--------------------------------------------------------------------------------
1 | import { useState, useEffect } from 'react';
2 | import { useMapContext } from '@uiw/react-baidu-map-map';
3 | import { noop, useEnableProperties, useProperties, useVisiable, useEventProperties } from '@uiw/react-baidu-map-utils';
4 | import { PolygonProps } from './';
5 |
6 | export interface UsePolygon extends PolygonProps {}
7 |
8 | export function usePolygon(props = {} as UsePolygon) {
9 | const {
10 | strokeColor,
11 | fillColor,
12 | strokeWeight,
13 | strokeOpacity,
14 | fillOpacity,
15 | strokeStyle,
16 | enableMassClear,
17 | enableEditing,
18 | enableClicking,
19 | } = props;
20 | const { map } = useMapContext();
21 | const [polygon, setPolygon] = useState();
22 | const [path, setPath] = useState(props.path || []);
23 |
24 | const opts = {
25 | strokeColor,
26 | fillColor,
27 | strokeWeight,
28 | strokeOpacity,
29 | fillOpacity,
30 | strokeStyle,
31 | enableMassClear,
32 | enableEditing,
33 | enableClicking,
34 | };
35 |
36 | useEffect(() => {
37 | if (!BMap || !map) return noop;
38 | const points = (path || []).map((item) => new BMap.Point(item.lng, item.lat));
39 | const instance = new BMap.Polygon(points, opts);
40 | map.addOverlay(instance);
41 | setPolygon(instance);
42 | return function () {
43 | map.removeOverlay(instance);
44 | };
45 | // eslint-disable-next-line react-hooks/exhaustive-deps
46 | }, [map]);
47 |
48 | useEffect(() => {
49 | if (path && polygon) {
50 | const points = path.map((item) => new BMap.Point(item.lng, item.lat));
51 | polygon.setPath(points);
52 | }
53 | }, [polygon, path]);
54 |
55 | useVisiable(polygon!, props);
56 | useEventProperties(polygon!, props, [
57 | 'Click',
58 | 'DoubleClick',
59 | 'MouseDown',
60 | 'MouseUp',
61 | 'MouseOut',
62 | 'MouseOver',
63 | 'Remove',
64 | 'LineUpdate',
65 | ]);
66 | useEnableProperties(polygon!, props, ['Editing', 'MassClear']);
67 | // PositionAt
68 | useProperties(polygon!, props, [
69 | 'StrokeColor',
70 | 'StrokeOpacity',
71 | 'FillColor',
72 | 'FillOpacity',
73 | 'StrokeWeight',
74 | 'StrokeStyle',
75 | ]);
76 |
77 | return {
78 | polygon,
79 | setPolygon,
80 | path,
81 | setPath,
82 | };
83 | }
84 |
--------------------------------------------------------------------------------
/packages/polygon/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "../../tsconfig",
3 | "include": ["src"],
4 | "compilerOptions": {
5 | "baseUrl": ".",
6 | "outDir": "cjs",
7 | "noEmit": false
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/packages/polyline/__tests__/index.test.tsx:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import TestRenderer from 'react-test-renderer';
3 | import Polyline, { usePolyline } from '../src';
4 |
5 | describe('', () => {
6 | it('Polyline test case', () => {
7 | expect(typeof Polyline).toEqual('object');
8 | expect(typeof usePolyline).toEqual('function');
9 | const component = TestRenderer.create(
10 | ,
17 | );
18 | let tree = component.toJSON();
19 | expect(tree).toBeNull();
20 | });
21 | });
22 |
--------------------------------------------------------------------------------
/packages/polyline/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "@uiw/react-baidu-map-polyline",
3 | "version": "2.7.3",
4 | "description": "Baidu Map map-polyline Components for React.",
5 | "funding": "https://jaywcjlove.github.io/#/sponsor",
6 | "homepage": "https://uiwjs.github.io/react-baidu-map/#/polyline",
7 | "main": "cjs/index.js",
8 | "module": "esm/index.js",
9 | "repository": {
10 | "type": "git",
11 | "url": "https://github.com/uiwjs/react-baidu-map.git"
12 | },
13 | "scripts": {
14 | "build": "tsbb build \"src/*.{tsx,ts}\" --use-babel --cjs cjs --bail",
15 | "watch": "tsbb watch \"src/*.{tsx,ts}\" --use-babel --cjs cjs"
16 | },
17 | "author": "Kenny Wong ",
18 | "license": "MIT",
19 | "files": [
20 | "src",
21 | "esm",
22 | "cjs"
23 | ],
24 | "keywords": [
25 | "react-baidu-map",
26 | "baidu",
27 | "baidu-map",
28 | "baidu-map-polyline",
29 | "map-polyline",
30 | "polyline",
31 | "map",
32 | "react",
33 | "bdmap",
34 | "types",
35 | "百度",
36 | "地图",
37 | "百度地图"
38 | ],
39 | "peerDependencies": {
40 | "react": ">=16.14.0",
41 | "react-dom": ">=16.14.0"
42 | },
43 | "dependencies": {
44 | "@babel/runtime": "^7.18.0",
45 | "@uiw/react-baidu-map-map": "2.7.3",
46 | "@uiw/react-baidu-map-utils": "2.7.3"
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/packages/polyline/src/index.tsx:
--------------------------------------------------------------------------------
1 | ///
2 | import React, { useEffect, useImperativeHandle } from 'react';
3 | import { OverlayProps } from '@uiw/react-baidu-map-map';
4 | import { usePolyline } from './usePolyline';
5 |
6 | export * from './usePolyline';
7 | export interface PolylineProps extends BMap.PolylineOptions, BMap.PolylineEvents, OverlayProps {
8 | /**
9 | * 设置折线的点数组
10 | */
11 | path: BMap.Point[];
12 | }
13 |
14 | export default React.forwardRef((props, ref) => {
15 | const { polyline, setPath } = usePolyline(props);
16 | // eslint-disable-next-line react-hooks/exhaustive-deps
17 | useEffect(() => setPath(props.path), [props.path]);
18 | useImperativeHandle(ref, () => ({ ...props, polyline }), [polyline, props]);
19 | return null;
20 | });
21 |
--------------------------------------------------------------------------------
/packages/polyline/src/usePolyline.tsx:
--------------------------------------------------------------------------------
1 | import { useState, useEffect, useMemo } from 'react';
2 | import { useMapContext } from '@uiw/react-baidu-map-map';
3 | import { useEnableProperties, useProperties, useVisiable, useEventProperties } from '@uiw/react-baidu-map-utils';
4 | import { PolylineProps } from './';
5 |
6 | export interface UsePolyline extends PolylineProps {}
7 |
8 | export function usePolyline(props = {} as UsePolyline) {
9 | const {
10 | strokeColor,
11 | strokeWeight,
12 | strokeOpacity,
13 | strokeStyle,
14 | enableMassClear,
15 | enableEditing,
16 | enableClicking,
17 | icons,
18 | } = props;
19 | const { map } = useMapContext();
20 | const [polyline, setPolyline] = useState();
21 | const [path, setPath] = useState(props.path || []);
22 |
23 | // eslint-disable-next-line react-hooks/exhaustive-deps
24 | const opts = {
25 | strokeColor,
26 | strokeWeight,
27 | strokeOpacity,
28 | strokeStyle,
29 | enableMassClear,
30 | enableEditing,
31 | enableClicking,
32 | icons,
33 | };
34 | useEffect(() => {
35 | return () => {
36 | if (polyline && map) {
37 | map.removeOverlay(polyline);
38 | }
39 | };
40 | // eslint-disable-next-line react-hooks/exhaustive-deps
41 | }, [map]);
42 | useMemo(() => {
43 | if (map && !polyline) {
44 | const points = (props.path || []).map((item) => new BMap.Point(item.lng, item.lat));
45 | const instance = new BMap.Polyline(points, opts);
46 | map.addOverlay(instance);
47 | setPolyline(instance);
48 | }
49 | }, [map, opts, polyline, props.path]);
50 |
51 | useEffect(() => {
52 | if (path && polyline) {
53 | const points = path.map((item) => new BMap.Point(item.lng, item.lat));
54 | polyline.setPath(points);
55 | }
56 | }, [polyline, path]);
57 |
58 | useVisiable(polyline!, props);
59 | useEventProperties(polyline!, props, [
60 | 'Click',
61 | 'DblClick',
62 | 'MouseDown',
63 | 'MouseUp',
64 | 'MouseOut',
65 | 'MouseOver',
66 | 'Remove',
67 | 'LineUpdate',
68 | ]);
69 | useEnableProperties(polyline!, props, ['Editing', 'MassClear']);
70 | // PositionAt
71 | useProperties(polyline!, props, [
72 | 'StrokeColor',
73 | 'StrokeOpacity',
74 | 'StrokeWeight',
75 | 'StrokeStyle',
76 | ]);
77 |
78 | return {
79 | polyline,
80 | setPolyline,
81 | path,
82 | setPath,
83 | };
84 | }
85 |
--------------------------------------------------------------------------------
/packages/polyline/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "../../tsconfig",
3 | "include": ["src"],
4 | "compilerOptions": {
5 | "baseUrl": ".",
6 | "outDir": "cjs",
7 | "noEmit": false
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/packages/require-script/README.md:
--------------------------------------------------------------------------------
1 | RequireScript 加载第三方包
2 | ===
3 |
4 | [](https://jaywcjlove.github.io/#/sponsor)
5 | [](https://www.npmjs.com/package/@uiw/react-baidu-map-require-script)
6 | [](https://www.npmjs.com/package/@uiw/react-baidu-map-require-script)
7 |
8 | 提供一个组件加载第三方包,也提供了一个 `requireScript` 方法加载第三方包。
9 |
10 | ```jsx
11 | import { RequireScript, requireScript } from '@uiw/react-baidu-map';
12 | // 或者单独安装使用
13 | import RequireScript, { requireScript } from '@uiw/react-baidu-map-require-script';
14 | ```
15 |
16 | > ⚠️ 注意:预览当前页面需要刷新页面。
17 |
18 |
19 | ### 基本用法
20 |
21 | 下面实例来自高德官方: https://lbsyun.baidu.com/jsdemo.htm#gl_tool_1
22 |
23 | ```jsx mdx:preview
24 | import React from 'react';
25 | import { useRef } from 'react';
26 | import { Map, APILoader, RequireScript } from '@uiw/react-baidu-map';
27 |
28 | const Example = () => {
29 | const myDis = useRef();
30 | const openHandle = () => {
31 | myDis.current.open();
32 | }
33 | const closeHandle = () => {
34 | myDis.current.close();
35 | }
36 | return (
37 | <>
38 |
39 |
40 |
41 |
42 |
68 | >
69 | );
70 | };
71 |
72 | const Demo = () => (
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 | );
81 |
82 | export default Demo;
83 | ```
84 |
85 | ### Props
86 |
87 | | 参数 | 说明 | 类型 | 默认值 |
88 | | ----- | ----- | ----- | ----- |
89 | | src | 第三方包的 URL 地址 | `string` | - |
90 |
91 | ### 事件
92 |
93 | | 参数 | 说明 | 类型 | 默认值 |
94 | | ----- | ----- | ----- | ----- |
95 | | onCompleted | 加载完成 | () => void; | - |
96 | | onFailed | 加载失败 | () => void; | - |
--------------------------------------------------------------------------------
/packages/require-script/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "@uiw/react-baidu-map-require-script",
3 | "version": "2.7.3",
4 | "description": "Baidu Map require-script Components for React.",
5 | "funding": "https://jaywcjlove.github.io/#/sponsor",
6 | "homepage": "https://uiwjs.github.io/react-baidu-map/#/require-script",
7 | "main": "cjs/index.js",
8 | "module": "esm/index.js",
9 | "repository": {
10 | "type": "git",
11 | "url": "https://github.com/uiwjs/react-baidu-map.git"
12 | },
13 | "scripts": {
14 | "build": "tsbb build \"src/*.{tsx,ts}\" --use-babel --cjs cjs --bail",
15 | "watch": "tsbb watch \"src/*.{tsx,ts}\" --use-babel --cjs cjs"
16 | },
17 | "author": "Kenny Wong ",
18 | "license": "MIT",
19 | "files": [
20 | "src",
21 | "esm",
22 | "cjs"
23 | ],
24 | "keywords": [
25 | "react-baidu-map",
26 | "baidu",
27 | "baidu-map",
28 | "baidu-map-require-script",
29 | "require-script",
30 | "map",
31 | "react",
32 | "bdmap",
33 | "types",
34 | "百度",
35 | "地图",
36 | "百度地图"
37 | ],
38 | "peerDependencies": {
39 | "react": ">=16.14.0",
40 | "react-dom": ">=16.14.0"
41 | },
42 | "dependencies": {
43 | "@babel/runtime": "^7.18.0",
44 | "@uiw/react-baidu-map-map": "2.7.3",
45 | "@uiw/react-baidu-map-utils": "2.7.3"
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/packages/require-script/src/index.tsx:
--------------------------------------------------------------------------------
1 | ///
2 | import React, { Fragment, useEffect, useState } from 'react';
3 | import { requireScript } from '@uiw/react-baidu-map-utils';
4 | import { RenderProps } from '@uiw/react-baidu-map-map';
5 |
6 | export type RequireScriptProps = {
7 | src?: string;
8 | /** ✅ 加载完成 */
9 | onCompleted?: () => void;
10 | /** ❌ 加载失败 */
11 | onFailed?: (error: any) => void;
12 | } & RenderProps;
13 |
14 | export default React.forwardRef<
15 | RequireScriptProps,
16 | RequireScriptProps & {
17 | map: BMap.Map;
18 | container?: HTMLDivElement | null;
19 | }
20 | >((props, ref) => {
21 | const { children, map, container } = props || {};
22 | const [completed, setCompleted] = useState(false);
23 | useEffect(() => {
24 | if (props.src) {
25 | requireScript(props.src)
26 | .then(() => {
27 | setCompleted(true);
28 | props.onCompleted && props.onCompleted();
29 | })
30 | .catch((err) => {
31 | props.onFailed && props.onFailed(err);
32 | });
33 | }
34 | // eslint-disable-next-line react-hooks/exhaustive-deps
35 | }, []);
36 | const chields = typeof children === 'function' ? [children] : React.Children.toArray(children);
37 | if (completed) {
38 | return (
39 |
40 | {typeof children === 'function' && children({ BMap, map, container })}
41 | {chields.map((child) => {
42 | if (!React.isValidElement(child)) return null;
43 | return React.cloneElement(child, {
44 | ...child.props,
45 | BMap,
46 | map,
47 | container,
48 | });
49 | })}
50 |
51 | );
52 | }
53 |
54 | return null;
55 | });
56 |
--------------------------------------------------------------------------------
/packages/require-script/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "../../tsconfig",
3 | "include": ["src"],
4 | "compilerOptions": {
5 | "baseUrl": ".",
6 | "outDir": "cjs",
7 | "noEmit": false
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/packages/scale-control/README.md:
--------------------------------------------------------------------------------
1 | ScaleControl 比例尺控件
2 | ===
3 |
4 | [](https://jaywcjlove.github.io/#/sponsor)
5 | [](https://www.npmjs.com/package/@uiw/react-baidu-map-scale-control)
6 | [](https://www.npmjs.com/package/@uiw/react-baidu-map-scale-control)
7 |
8 | 比例尺控件。你也可以使用 `Map` 组件 `widget` 属性来设置控件更方便。
9 |
10 | ```jsx
11 | import { ScaleControl, useScaleControl } from '@uiw/react-baidu-map';
12 | // 或者单独安装使用
13 | import ScaleControl, { useScaleControl } from '@uiw/react-baidu-map-scale-control';
14 | ```
15 |
16 | ### 基本用法
17 |
18 | ```jsx mdx:preview
19 | import React, { useState, useRef } from 'react';
20 | import { Map, APILoader, ScaleControl } from '@uiw/react-baidu-map';
21 |
22 | const Example = () => {
23 | const [show, setShow] = useState(true);
24 | return (
25 | <>
26 |
29 |
35 | >
36 | );
37 | }
38 |
39 | const Demo = () => (
40 |
45 | );
46 |
47 | export default Demo;
48 | ```
49 |
50 |
51 | ### 使用 hooks
52 |
53 | `scaleControl`, `setScaleControl`
54 |
55 | ```jsx mdx:preview
56 | import React from 'react';
57 | import { useRef, useEffect, useState } from 'react';
58 | import { Map, APILoader, Provider, useMap, useScaleControl } from '@uiw/react-baidu-map';
59 |
60 | const Example = () => {
61 | const divElm = useRef(null);
62 | const [show, setShow] = useState(true);
63 | const { setContainer, map } = useMap();
64 | const { scaleControl } = useScaleControl({
65 | map, anchor: BMAP_NAVIGATION_CONTROL_LARGE, visiable: show,
66 | });
67 |
68 | useEffect(() => {
69 | if (divElm.current && !map) {
70 | setContainer(divElm.current);
71 | }
72 | }, [map]);
73 | return (
74 | <>
75 |
78 |
79 | >
80 | );
81 | }
82 |
83 | const Demo = () => (
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 | );
92 |
93 | export default Demo;
94 | ```
95 |
96 | ### Props
97 |
98 | | 参数 | 说明 | 类型 | 默认值 |
99 | | ----- | ----- | ----- | ----- |
100 | | visiable | 覆盖物是否可见。 | `boolean` | - |
101 | | anchor | 控件的位置偏移值。| `ControlAnchor` | `BMAP_ANCHOR_TOP_RIGHT` |
102 | | offset | 控件的水平偏移值。 | `BMap.Size` | - |
103 | | unit | 设置比例尺单位制 | `BMap.LengthUnit` | - |
104 |
105 | ### LengthUnit
106 |
107 | 常量表示长度单位制。
108 |
109 | | 常量 | 值 | 描述 |
110 | | ----- | ----- | ----- |
111 | | BMAP_UNIT_METRIC | `0` | 公制单位 |
112 | | BMAP_UNIT_IMPERIAL | `1` | 英制单位 |
113 |
--------------------------------------------------------------------------------
/packages/scale-control/__tests__/index.test.tsx:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import TestRenderer from 'react-test-renderer';
3 | import ScaleControl, { useScaleControl } from '../src';
4 |
5 | describe('', () => {
6 | it('ScaleControl test case', () => {
7 | expect(typeof ScaleControl).toEqual('object');
8 | expect(typeof useScaleControl).toEqual('function');
9 | const component = TestRenderer.create();
10 | let tree = component.toJSON();
11 | expect(tree).toBeNull();
12 | });
13 | });
14 |
--------------------------------------------------------------------------------
/packages/scale-control/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "@uiw/react-baidu-map-scale-control",
3 | "version": "2.7.3",
4 | "description": "Baidu Map scale-control Components for React.",
5 | "funding": "https://jaywcjlove.github.io/#/sponsor",
6 | "homepage": "https://uiwjs.github.io/react-baidu-map/#/scale-control",
7 | "main": "cjs/index.js",
8 | "module": "esm/index.js",
9 | "repository": {
10 | "type": "git",
11 | "url": "https://github.com/uiwjs/react-baidu-map.git"
12 | },
13 | "scripts": {
14 | "build": "tsbb build \"src/*.{tsx,ts}\" --use-babel --cjs cjs --bail",
15 | "watch": "tsbb watch \"src/*.{tsx,ts}\" --use-babel --cjs cjs"
16 | },
17 | "author": "Kenny Wong ",
18 | "license": "MIT",
19 | "files": [
20 | "src",
21 | "esm",
22 | "cjs"
23 | ],
24 | "keywords": [
25 | "react-baidu-map",
26 | "baidu",
27 | "baidu-map",
28 | "baidu-map-scale-control",
29 | "scale-control",
30 | "map",
31 | "react",
32 | "bdmap",
33 | "types",
34 | "百度",
35 | "地图",
36 | "百度地图"
37 | ],
38 | "peerDependencies": {
39 | "react": ">=16.14.0",
40 | "react-dom": ">=16.14.0"
41 | },
42 | "dependencies": {
43 | "@babel/runtime": "^7.18.0",
44 | "@uiw/react-baidu-map-map": "2.7.3",
45 | "@uiw/react-baidu-map-utils": "2.7.3"
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/packages/scale-control/src/index.tsx:
--------------------------------------------------------------------------------
1 | ///
2 | import React, { useImperativeHandle } from 'react';
3 | import { OverlayProps } from '@uiw/react-baidu-map-map';
4 | import { useScaleControl } from './useScaleControl';
5 |
6 | export * from './useScaleControl';
7 | export interface ScaleControlProps extends OverlayProps, BMap.ScaleControlOptions {}
8 |
9 | export default React.forwardRef((props, ref) => {
10 | const { scaleControl } = useScaleControl(props);
11 | // eslint-disable-next-line react-hooks/exhaustive-deps
12 | useImperativeHandle(ref, () => ({ ...props, scaleControl }), [scaleControl]);
13 | return null;
14 | });
15 |
--------------------------------------------------------------------------------
/packages/scale-control/src/useScaleControl.tsx:
--------------------------------------------------------------------------------
1 | import { useEffect, useState } from 'react';
2 | import { useMapContext } from '@uiw/react-baidu-map-map';
3 | import { useProperties, useVisiable } from '@uiw/react-baidu-map-utils';
4 | import { ScaleControlProps } from './';
5 |
6 | export interface UseScaleControl extends ScaleControlProps {}
7 |
8 | export function useScaleControl(props = {} as UseScaleControl) {
9 | const [scaleControl, setScaleControl] = useState();
10 | const { anchor, offset } = props;
11 | const { map } = useMapContext();
12 | useEffect(() => {
13 | if (map && !scaleControl) {
14 | const instance = new BMap.ScaleControl({
15 | anchor: anchor || BMAP_ANCHOR_TOP_LEFT,
16 | offset,
17 | });
18 | map.addControl(instance);
19 | setScaleControl(instance);
20 | }
21 |
22 | return () => {
23 | if (map && scaleControl) {
24 | try {
25 | map.removeControl(scaleControl);
26 | } catch (error) {}
27 | }
28 | };
29 | // eslint-disable-next-line react-hooks/exhaustive-deps
30 | }, [map, scaleControl]);
31 |
32 | useVisiable(scaleControl!, props);
33 | useProperties(scaleControl!, props, ['Anchor', 'Offset', 'Unit']);
34 | return {
35 | scaleControl,
36 | setScaleControl,
37 | };
38 | }
39 |
--------------------------------------------------------------------------------
/packages/scale-control/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "../../tsconfig",
3 | "include": ["src"],
4 | "compilerOptions": {
5 | "baseUrl": ".",
6 | "outDir": "cjs",
7 | "noEmit": false
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/packages/tile-layer/README.md:
--------------------------------------------------------------------------------
1 | TileLayer 地图图层
2 | ===
3 |
4 | [](https://jaywcjlove.github.io/#/sponsor)
5 | [](https://www.npmjs.com/package/@uiw/react-baidu-map-tile-layer)
6 | [](https://www.npmjs.com/package/@uiw/react-baidu-map-tile-layer)
7 |
8 | 此类表示一个地图图层,您可以向地图中添加自定义图层,官方原生实例:https://lbsyun.baidu.com/jsdemo.htm#g0_2。
9 |
10 | ```jsx
11 | import { TileLayer, useTileLayer } from '@uiw/react-baidu-map';
12 | // 或者单独安装使用
13 | import TileLayer, { useTileLayer } from '@uiw/react-baidu-map-tile-layer';
14 | ```
15 |
16 | ### 基本用法
17 |
18 | ```jsx mdx:preview
19 | import React from 'react';
20 | import { useState, useRef } from 'react';
21 | import { Map, APILoader, TileLayer } from '@uiw/react-baidu-map';
22 |
23 | const Example = () => {
24 | const [show, setShow] = useState(true);
25 | return (
26 | <>
27 |
30 |
40 | >
41 | );
42 | }
43 |
44 | const Demo = () => (
45 |
50 | );
51 |
52 | export default Demo;
53 | ```
54 |
55 | ### 使用 hooks
56 |
57 | `tileLayer`, `setTileLayer`, `visiable`, `setVisiable`
58 |
59 | ```jsx mdx:preview
60 | import React from 'react';
61 | import { useRef, useEffect, useState } from 'react';
62 | import { Map, APILoader, Provider, useMap, useTileLayer } from '@uiw/react-baidu-map';
63 |
64 | const Example = () => {
65 | const divElm = useRef(null);
66 | const [show, setShow] = useState(true);
67 | const { setContainer, map } = useMap({
68 | zoom: 16, center: { lng: 116.332782, lat: 40.007978 },
69 | widget: ['NavigationControl']
70 | });
71 |
72 | const { setVisiable } = useTileLayer({
73 | visiable: show,
74 | map, getTilesUrl: (tileCoord, zoom) => {
75 | const { x, y } = tileCoord;
76 | // 根据当前坐标,选取合适的瓦片图
77 | return `http://lbsyun.baidu.com/jsdemo/demo/tiles/${zoom}/tile${x}_${y}.png`;
78 | }
79 | });
80 |
81 | useEffect(() => {
82 | if (divElm.current && !map) {
83 | setContainer(divElm.current);
84 | }
85 | }, [map]);
86 | return (
87 | <>
88 |
94 |
95 | >
96 | );
97 | }
98 |
99 | const Demo = () => (
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 | );
108 | export default Demo;
109 | ```
110 |
111 | ### Props
112 |
113 | | 参数 | 说明 | 类型 | 默认值 |
114 | | ----- | ----- | ----- | ----- |
115 | | visiable | 地图图层是否可见 | `Boolean` | - |
116 | | transparentPng | 是否使用了带有透明信息的PNG。由于IE6不支持PNG透明,因此需要特殊处理。 | `Boolean` | - |
117 | | tileUrlTemplate | 指定图块网址模板,该模板可以针对每个图块请求而展开,以根据现有的图块坐标系引用唯一的图块。模板的格式应该为:`http://yourhost/tile?x={X}&y={Y}&z={Z}.png` 其中X和Y分别指纬度和经度图块坐标,Z指缩放级别,比如: `http://yourhost/tile?x=3&y=27&z=5.png` 如果您没有提供图块网址模板,您需要实现`TileLayer.getTileUrl()` 抽象方法。 | `string` | - |
118 | | getTilesUrl | 抽象。向地图返回地图图块的网址,图块索引由 `tileCoord` 的 `x` 和 `y` 属性在指定的缩放级别 `zoom` 提供。如果您在 `TileLayerOptions` 中提供了tileUrlTemplate参数,则可不实现此接口。| `(tileCoord: Pixel, zoom: number): string;` | - |
119 | | getCopyright | 返回地图图层数据的版权对象 | `(): Copyright` | - |
120 | | copyright | 地图图层的版权信息 | `Copyright` | - |
121 | | zIndex | 图层的 `zIndex` | `number` | - |
122 |
--------------------------------------------------------------------------------
/packages/tile-layer/__tests__/index.test.tsx:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import TestRenderer from 'react-test-renderer';
3 | import TileLayer, { useTileLayer } from '../src';
4 |
5 | describe('', () => {
6 | it('TileLayer test case', () => {
7 | expect(typeof TileLayer).toEqual('object');
8 | expect(typeof useTileLayer).toEqual('function');
9 | const component = TestRenderer.create();
10 | let tree = component.toJSON();
11 | expect(tree).toBeNull();
12 | });
13 | });
14 |
--------------------------------------------------------------------------------
/packages/tile-layer/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "@uiw/react-baidu-map-tile-layer",
3 | "version": "2.7.3",
4 | "description": "Baidu Map tile-layer Components for React.",
5 | "funding": "https://jaywcjlove.github.io/#/sponsor",
6 | "homepage": "https://uiwjs.github.io/react-baidu-map/#/tile-layer",
7 | "main": "cjs/index.js",
8 | "module": "esm/index.js",
9 | "repository": {
10 | "type": "git",
11 | "url": "https://github.com/uiwjs/react-baidu-map.git"
12 | },
13 | "scripts": {
14 | "build": "tsbb build \"src/*.{tsx,ts}\" --use-babel --cjs cjs --bail",
15 | "watch": "tsbb watch \"src/*.{tsx,ts}\" --use-babel --cjs cjs"
16 | },
17 | "author": "Kenny Wong ",
18 | "license": "MIT",
19 | "files": [
20 | "src",
21 | "esm",
22 | "cjs"
23 | ],
24 | "keywords": [
25 | "react-baidu-map",
26 | "baidu",
27 | "baidu-map",
28 | "baidu-map-tile-layer",
29 | "tile-layer",
30 | "map",
31 | "react",
32 | "bdmap",
33 | "types",
34 | "百度",
35 | "地图",
36 | "百度地图"
37 | ],
38 | "peerDependencies": {
39 | "react": ">=16.14.0",
40 | "react-dom": ">=16.14.0"
41 | },
42 | "dependencies": {
43 | "@babel/runtime": "^7.18.0",
44 | "@uiw/react-baidu-map-map": "2.7.3",
45 | "@uiw/react-baidu-map-utils": "2.7.3"
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/packages/tile-layer/src/index.tsx:
--------------------------------------------------------------------------------
1 | ///
2 | import React, { useImperativeHandle, useEffect } from 'react';
3 | import { OverlayProps } from '@uiw/react-baidu-map-map';
4 | import { useTileLayer } from './useTileLayer';
5 |
6 | export * from './useTileLayer';
7 |
8 | export interface TileLayerProps extends OverlayProps, BMap.TileLayerOptions, BMap.TileLayer {
9 | visiable?: boolean;
10 | }
11 |
12 | export default React.forwardRef((props, ref) => {
13 | const { tileLayer, setVisiable } = useTileLayer(props);
14 | // eslint-disable-next-line react-hooks/exhaustive-deps
15 | useImperativeHandle(ref, () => ({ ...props, tileLayer }), [tileLayer]);
16 | // eslint-disable-next-line react-hooks/exhaustive-deps
17 | useEffect(() => setVisiable(props.visiable!), [props.visiable]);
18 | return null;
19 | });
20 |
--------------------------------------------------------------------------------
/packages/tile-layer/src/useTileLayer.ts:
--------------------------------------------------------------------------------
1 | import { useEffect, useState } from 'react';
2 | import { useMapContext } from '@uiw/react-baidu-map-map';
3 | import { TileLayerProps } from './';
4 |
5 | export interface UseTileLayer extends TileLayerProps {}
6 | /**
7 | * https://lbsyun.baidu.com/jsdemo.htm#g0_2
8 | */
9 | export function useTileLayer(props = {} as UseTileLayer) {
10 | const [tileLayer, setTileLayer] = useState();
11 | const { transparentPng = true, tileUrlTemplate, copyright, zIndex } = props;
12 | const { map } = useMapContext();
13 |
14 | useEffect(() => {
15 | if (map && !tileLayer) {
16 | const instance = new BMap.TileLayer({
17 | transparentPng,
18 | tileUrlTemplate,
19 | copyright,
20 | zIndex,
21 | });
22 | if (!!props.getTilesUrl) {
23 | instance.getTilesUrl = props.getTilesUrl;
24 | }
25 | if (!!props.getCopyright) {
26 | instance.getCopyright = props.getCopyright;
27 | }
28 | map.addTileLayer(instance);
29 | setTileLayer(instance);
30 | return () => {
31 | if (instance) {
32 | map.removeTileLayer(instance);
33 | }
34 | };
35 | }
36 | // eslint-disable-next-line react-hooks/exhaustive-deps
37 | }, [map]);
38 |
39 | const [visiable, setVisiable] = useState(props.visiable);
40 | useEffect(() => {
41 | if (map && tileLayer) {
42 | visiable ? map.addTileLayer(tileLayer) : map.removeTileLayer(tileLayer);
43 | }
44 | // eslint-disable-next-line react-hooks/exhaustive-deps
45 | }, [visiable, map]);
46 |
47 | return {
48 | tileLayer,
49 | setTileLayer,
50 | visiable,
51 | setVisiable,
52 | };
53 | }
54 |
--------------------------------------------------------------------------------
/packages/tile-layer/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "../../tsconfig",
3 | "include": ["src"],
4 | "compilerOptions": {
5 | "baseUrl": ".",
6 | "outDir": "cjs",
7 | "noEmit": false
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/packages/type-control/__tests__/index.test.tsx:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import TestRenderer from 'react-test-renderer';
3 | import MapTypeControl, { useMapTypeControl } from '../src';
4 |
5 | describe('', () => {
6 | it('MapTypeControl test case', () => {
7 | expect(typeof MapTypeControl).toEqual('object');
8 | expect(typeof useMapTypeControl).toEqual('function');
9 | const component = TestRenderer.create();
10 | let tree = component.toJSON();
11 | expect(tree).toBeNull();
12 | });
13 | });
14 |
--------------------------------------------------------------------------------
/packages/type-control/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "@uiw/react-baidu-map-type-control",
3 | "version": "2.7.3",
4 | "description": "Baidu Map map-type-control Components for React.",
5 | "funding": "https://jaywcjlove.github.io/#/sponsor",
6 | "homepage": "https://uiwjs.github.io/react-baidu-map/#/map-type-control",
7 | "main": "cjs/index.js",
8 | "module": "esm/index.js",
9 | "repository": {
10 | "type": "git",
11 | "url": "https://github.com/uiwjs/react-baidu-map.git"
12 | },
13 | "scripts": {
14 | "build": "tsbb build \"src/*.{tsx,ts}\" --use-babel --cjs cjs --bail",
15 | "watch": "tsbb watch \"src/*.{tsx,ts}\" --use-babel --cjs cjs"
16 | },
17 | "author": "Kenny Wong ",
18 | "license": "MIT",
19 | "files": [
20 | "src",
21 | "esm",
22 | "cjs"
23 | ],
24 | "keywords": [
25 | "react-baidu-map",
26 | "baidu",
27 | "baidu-map",
28 | "baidu-map-type-control",
29 | "map-type-control",
30 | "map",
31 | "react",
32 | "bdmap",
33 | "types",
34 | "百度",
35 | "地图",
36 | "百度地图"
37 | ],
38 | "peerDependencies": {
39 | "react": ">=16.14.0",
40 | "react-dom": ">=16.14.0"
41 | },
42 | "dependencies": {
43 | "@babel/runtime": "^7.18.0",
44 | "@uiw/react-baidu-map-map": "2.7.3",
45 | "@uiw/react-baidu-map-utils": "2.7.3"
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/packages/type-control/src/index.tsx:
--------------------------------------------------------------------------------
1 | ///
2 | import React, { useImperativeHandle } from 'react';
3 | import { OverlayProps } from '@uiw/react-baidu-map-map';
4 | import { useMapTypeControl } from './useMapTypeControl';
5 |
6 | export * from './useMapTypeControl';
7 | export interface MapTypeControlProps extends OverlayProps, BMap.MapTypeControlOptions {}
8 |
9 | export default React.forwardRef((props, ref) => {
10 | const { mapTypeControl } = useMapTypeControl(props);
11 | useImperativeHandle(ref, () => ({ ...props, mapTypeControl }), [mapTypeControl, props]);
12 | return null;
13 | });
14 |
--------------------------------------------------------------------------------
/packages/type-control/src/useMapTypeControl.tsx:
--------------------------------------------------------------------------------
1 | import { useEffect, useState } from 'react';
2 | import { useMapContext } from '@uiw/react-baidu-map-map';
3 | import { useProperties, useVisiable } from '@uiw/react-baidu-map-utils';
4 | import { MapTypeControlProps } from './';
5 |
6 | export interface UseMapTypeControl extends MapTypeControlProps {}
7 |
8 | export function useMapTypeControl(props = {} as UseMapTypeControl) {
9 | const [mapTypeControl, setMapTypeControl] = useState();
10 | const { anchor, offset, type, mapTypes } = props;
11 | const { map } = useMapContext();
12 | useEffect(() => {
13 | if (map && !mapTypeControl) {
14 | const instance = new BMap.MapTypeControl({
15 | anchor: anchor || BMAP_ANCHOR_TOP_LEFT,
16 | offset,
17 | type,
18 | mapTypes,
19 | });
20 | map.addControl(instance);
21 | setMapTypeControl(instance);
22 | }
23 | return () => {
24 | if (map && mapTypeControl) {
25 | try {
26 | map.removeControl(mapTypeControl);
27 | } catch (error) {}
28 | }
29 | };
30 | // eslint-disable-next-line react-hooks/exhaustive-deps
31 | }, [map, mapTypeControl]);
32 |
33 | useVisiable(mapTypeControl!, props);
34 | useProperties(mapTypeControl!, props, ['Anchor', 'Offset', 'Unit']);
35 | return {
36 | mapTypeControl,
37 | setMapTypeControl,
38 | };
39 | }
40 |
--------------------------------------------------------------------------------
/packages/type-control/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "../../tsconfig",
3 | "include": ["src"],
4 | "compilerOptions": {
5 | "baseUrl": ".",
6 | "outDir": "cjs",
7 | "noEmit": false
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/packages/types/README.md:
--------------------------------------------------------------------------------
1 | Support TypeScript
2 | ===
3 |
4 | [](https://jaywcjlove.github.io/#/sponsor)
5 | [](https://www.npmjs.com/package/@uiw/react-baidu-map-types)
6 | [](https://www.npmjs.com/package/@uiw/react-baidu-map-types)
7 |
8 | 此包包含百度地图 [API](https://lbsyun.baidu.com/cms/jsapi/reference/jsapi_reference_3_0.html) 的类型定义。
9 |
10 | ```shell
11 | $ npm i @uiw/react-baidu-map-types
12 | ```
13 |
14 | ### 基本用法
15 |
16 | ```tsx
17 | ///
18 | ```
19 |
--------------------------------------------------------------------------------
/packages/types/index.d.ts:
--------------------------------------------------------------------------------
1 | /**
2 | * 高德地图 SDK
3 | */
4 |
5 | ///
6 | ///
7 | ///
8 | ///
9 | ///
10 | ///
11 | ///
12 | ///
13 | ///
14 | ///
15 | ///
16 | ///
17 | ///
18 | ///
19 |
--------------------------------------------------------------------------------
/packages/types/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "@uiw/react-baidu-map-types",
3 | "version": "2.7.3",
4 | "description": "Baidu Map Components for React.",
5 | "funding": "https://jaywcjlove.github.io/#/sponsor",
6 | "homepage": "https://uiwjs.github.io/react-baidu-map/#/map-types",
7 | "types": "index.d.ts",
8 | "repository": {
9 | "type": "git",
10 | "url": "https://github.com/uiwjs/react-baidu-map.git"
11 | },
12 | "scripts": {},
13 | "author": "Kenny Wong ",
14 | "license": "MIT",
15 | "files": [
16 | "index.d.ts",
17 | "src"
18 | ],
19 | "keywords": [
20 | "react-baidu-map",
21 | "baidu-map",
22 | "map",
23 | "react",
24 | "bdmap",
25 | "types",
26 | "百度",
27 | "地图",
28 | "百度地图"
29 | ],
30 | "peerDependencies": {
31 | "react": ">=16.8.0",
32 | "react-dom": ">=16.8.0"
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/packages/types/src/base.d.ts:
--------------------------------------------------------------------------------
1 | declare global {
2 | interface Window {
3 | BMap: typeof BMap;
4 | }
5 | }
6 |
7 | declare namespace BMap {
8 | type Callback = (...args: any[]) => void;
9 | /**
10 | * 此类表示一个地理坐标点。
11 | */
12 | class Point {
13 | /**
14 | * 以指定的经度和纬度创建一个地理点坐标
15 | * @param lng 地理经度
16 | * @param lat 地理纬度
17 | */
18 | constructor(lng: number, lat: number);
19 | lng: number;
20 | lat: number;
21 | /**
22 | * 判断坐标点是否相等,当且仅当两点的经度和纬度均相等时返回true
23 | * @param other
24 | */
25 | equals?(other: Point): boolean;
26 | }
27 | /**
28 | * 此类表示地图上的一点,单位为像素。
29 | * 创建像素点对象实例。像素坐标的坐标原点为地图区域的左上角
30 | */
31 | class Pixel {
32 | constructor(x: number, y: number);
33 | /**
34 | * x坐标
35 | */
36 | x: number;
37 | /**
38 | * y坐标
39 | */
40 | y: number;
41 | equals?(other: Pixel): boolean;
42 | }
43 | /**
44 | * 此类以像素表示一个矩形区域的大小。
45 | */
46 | class Size {
47 | /**
48 | * 以指定的宽度和高度创建一个矩形区域大小对象
49 | * @param width
50 | * @param height
51 | */
52 | constructor(width: number, height: number);
53 | /**
54 | * 以指定的宽度和高度创建一个矩形区域大小对象
55 | */
56 | width: number;
57 | /**
58 | * 竖直方向的数值
59 | */
60 | height: number;
61 | /**
62 | * 当且仅当此矩形中的宽度和高度都等于其他矩形的宽度和高度时,返回true
63 | */
64 | equals?(other: Size): boolean;
65 | }
66 | class Bounds {
67 | constructor(sw: Point, ne: Point);
68 | /**
69 | * 当且仅当此矩形中的两点参数都等于其他矩形的两点参数时,返回true
70 | */
71 | equals?(other: Bounds): Boolean;
72 | /**
73 | * 如果点的地理坐标位于此矩形内,则返回true
74 | */
75 | containsPoint?(point: Point): Boolean;
76 | /**
77 | * 传入的矩形区域完全包含于此矩形区域中,则返回true
78 | */
79 | containsBounds?(bounds: Bounds): Boolean;
80 | /**
81 | * 计算与另一矩形的交集区域
82 | */
83 | intersects?(other: Bounds): Bounds;
84 | /**
85 | * 放大此矩形,使其包含给定的点
86 | */
87 | extend?(point: Point): void;
88 | /**
89 | * 返回矩形的中心点
90 | */
91 | getCenter?(): Point;
92 | /**
93 | * 如果矩形为空,则返回true
94 | */
95 | isEmpty?(): Boolean;
96 | /**
97 | * 返回矩形区域的西南角
98 | */
99 | getSouthWest?(): Point;
100 | /**
101 | * 返回矩形区域的东北角
102 | */
103 | getNorthEast?(): Point;
104 | /**
105 | * 返回矩形区域的跨度
106 | */
107 | toSpan?(): Point;
108 | }
109 | }
110 |
--------------------------------------------------------------------------------
/packages/types/src/bmapgl.d.ts:
--------------------------------------------------------------------------------
1 | declare global {
2 | interface Window {
3 | BMapGL: typeof BMapGL;
4 | }
5 | }
6 |
7 | declare namespace BMapGL {
8 | class Map extends BMap.Map {}
9 | }
10 |
--------------------------------------------------------------------------------
/packages/types/src/bmaplib.d.ts:
--------------------------------------------------------------------------------
1 | declare global {
2 | interface Window {
3 | BMapLib: typeof BMapLib;
4 | }
5 | }
6 |
7 | declare namespace BMapLib {
8 | type Callback = (...args: any[]) => void;
9 |
10 | type Callback = (e: any, overlay: T) => void;
11 |
12 | /**
13 | * 弧线
14 | */
15 | class CurveLine {
16 | constructor(points: BMap.Point[], opts?: CurveLineOptions);
17 | }
18 | interface CurveLineOptions extends BMap.PolylineOptions {}
19 | interface CurveLine extends BMap.Polyline {}
20 | interface CurveLineEvents extends BMap.PolylineEvents {}
21 |
22 | interface DrawingManagerOptions {
23 | /**
24 | * 是否开启绘制模式
25 | */
26 | isOpen?: boolean;
27 |
28 | /**
29 | * 当前的绘制模式, 默认是绘制点
30 | */
31 | drawingMode?: BMap.DrawingType;
32 |
33 | /**
34 | * 是否添加绘制工具栏控件,默认不添加
35 | */
36 | enableDrawingTool?: boolean;
37 |
38 | /**
39 | * 绘制是否进行测距(画线时候)、测面(画圆、多边形、矩形)
40 | */
41 | enableCalculate?: boolean;
42 |
43 | drawingToolOptions?: BMap.DrawingToolOptions;
44 |
45 | markerOptions?: BMap.CircleOptions;
46 | circleOptions?: BMap.CircleOptions;
47 | polylineOptions?: BMap.PolylineOptions;
48 | polygonOptions?: BMap.PolygonOptions;
49 | rectangleOptions?: BMap.PolygonOptions;
50 | }
51 |
52 | interface DrawingToolOptions {
53 | anchor?: BMap.ControlAnchor;
54 | offset?: BMap.Size;
55 | scale?: number;
56 | drawingModes?: BMap.DrawingType[];
57 | }
58 | interface DrawingManagerEvents {
59 | /**
60 | * 绘制圆完成后,派发的事件接口
61 | * @param {BMap.Circle} overlay
62 | */
63 | onCircleComplete?: (overlay: BMap.Circle) => void;
64 | /**
65 | * 绘制点完成后,派发的事件接口
66 | * @param {BMap.Marker} overlay
67 | */
68 | onMarkerComplete?: (overlay: BMap.Marker) => void;
69 | /**
70 | * {Event Object} 鼠标绘制完成后,派发总事件的接口
71 | * @param e
72 | */
73 | onOverlayComplete?: (e: any) => void;
74 | /**
75 | * 绘制多边形完成后,派发的事件接口
76 | * @param {BMap.Polygon} overlay
77 | */
78 | onPolygonComplete?: (overlay: BMap.Polygon) => void;
79 | /**
80 | * 绘制线完成后,派发的事件接口
81 | * @param {BMap.Polyline} overlay
82 | */
83 | onPolylineComplete?: (overlay: BMap.Polyline) => void;
84 | /**
85 | * 绘制矩形完成后,派发的事件接口
86 | * @param {BMap.Polygon} overlay
87 | */
88 | onRectangleComplete?: (overlay: BMap.Polygon) => void;
89 | }
90 | /**
91 | * 鼠标绘制管理
92 | */
93 | class DrawingManager {
94 | constructor(map: BMap.Map, opts?: BMap.DrawingManagerOptions);
95 |
96 | /**
97 | * 开启地图的绘制状态
98 | */
99 | open(): void;
100 |
101 | /**
102 | * 关闭地图的绘制状态
103 | */
104 | close(): void;
105 |
106 | /**
107 | * 打开距离或面积计算
108 | */
109 | enableCalculate(): void;
110 |
111 | /**
112 | * 关闭距离或面积计算
113 | */
114 | disableCalculate(): void;
115 |
116 | /**
117 | * 获取当前的绘制模式
118 | */
119 | getDrawingMode(): BMap.DrawingType;
120 |
121 | /**
122 | * 设置当前的绘制模式
123 | * BMAP_DRAWING_MARKER 画点
124 | * BMAP_DRAWING_CIRCLE 画圆
125 | * BMAP_DRAWING_POLYLINE 画线
126 | * BMAP_DRAWING_POLYGON 画多边形
127 | * BMAP_DRAWING_RECTANGLE 画矩形
128 | * @param drawingType 绘制模式
129 | */
130 | setDrawingMode(drawingType: BMap.DrawingType): void;
131 |
132 | /**
133 | * 添加事件监听函数
134 | * @param event
135 | * @param handler
136 | */
137 | addEventListener(event: string, handler: Callback): void;
138 |
139 | /**
140 | * 添加事件监听函数
141 | * @param event
142 | * @param handler
143 | */
144 | addEventListener(event: string, handler: Callback): void;
145 |
146 | /**
147 | * 移除事件监听函数
148 | * @param event
149 | * @param handler
150 | */
151 | removeEventListener(event: string, handler: Callback): void;
152 | }
153 | }
154 |
--------------------------------------------------------------------------------
/packages/types/src/declare.d.ts:
--------------------------------------------------------------------------------
1 | declare module '*.png' {
2 | const src: string;
3 | export default src;
4 | }
5 |
--------------------------------------------------------------------------------
/packages/types/src/index.d.ts:
--------------------------------------------------------------------------------
1 | /**
2 | * 百度地图 SDK
3 | * API v3.0类参考 http://lbsyun.baidu.com/cms/jsapi/reference/jsapi_reference_3_0.html#a3b3
4 | */
5 |
6 | ///
7 | ///
8 | ///
9 | ///
10 | ///
11 | ///
12 | ///
13 | ///
14 | ///
15 | ///
16 | ///
17 |
--------------------------------------------------------------------------------
/packages/types/src/maplayer.d.ts:
--------------------------------------------------------------------------------
1 | ///
2 | ///
3 | declare namespace BMap {
4 | /**
5 | * 此类表示一个地图图层,您可以向地图中添加自定义图层。
6 | */
7 | class TileLayer {
8 | constructor(opts?: TileLayerOptions);
9 | /**
10 | * 抽象。向地图返回地图图块的网址,图块索引由 tileCoord 的 x 和 y 属性在指定的缩放级别 zoom 提供。
11 | * 如果您在 TileLayerOptions 中提供了 tileUrlTemplate 参数,则可不实现此接口
12 | */
13 | getTilesUrl?: (tileCoord: Pixel, zoom: number) => string;
14 | /**
15 | * 返回地图图层数据的版权对象
16 | */
17 | getCopyright?: () => Copyright | null;
18 | /**
19 | * 如果图层所用的图片为PNG格式并且包含透明信息,则返回true
20 | */
21 | isTransparentPng?: () => boolean;
22 | }
23 | interface TileLayerOptions {
24 | /**
25 | * 是否使用了带有透明信息的PNG。由于IE6不支持PNG透明,因此需要特殊处理
26 | */
27 | transparentPng?: boolean;
28 | /**
29 | * 指定图块网址模板,该模板可以针对每个图块请求而展开,以根据现有的图块坐标系引用唯一的图块。
30 | * 模板的格式应该为:http://yourhost/tile?x={X}&y={Y}&z={Z}.png 其中X和Y分别指纬度和经度图块坐标,Z指缩放级别,
31 | * 比如: http://yourhost/tile?x=3&y=27&z=5.png 如果您没有提供图块网址模板,您需要实现TileLayer.getTileUrl()抽象方法
32 | */
33 | tileUrlTemplate?: string;
34 | /**
35 | * 地图图层的版权信息
36 | */
37 | copyright?: Copyright;
38 | /**
39 | * 图层的zIndex
40 | */
41 | zIndex?: number;
42 | }
43 | class TrafficLayer extends TileLayer {
44 | constructor(opts?: TrafficLayerOptions);
45 | }
46 | interface TrafficLayerOptions {
47 | predictDate?: PredictDate;
48 | }
49 | interface PredictDate {
50 | weekday: number;
51 | hour: number;
52 | }
53 | class CustomLayer extends TileLayer {
54 | constructor(opts: CustomLayerOptions);
55 | onhotspotclick: (event: { type: string; target: any; content: any }) => void;
56 | }
57 | interface Custompoi {
58 | poiId: string;
59 | databoxId: string;
60 | title: string;
61 | address: string;
62 | phoneNumber: string;
63 | postcode: string;
64 | provinceCode: number;
65 | province: string;
66 | cityCode: number;
67 | city: string;
68 | districtCode: number;
69 | district: string;
70 | point: Point;
71 | tags: string[];
72 | typeId: number;
73 | extendedData: any;
74 | }
75 | /**
76 | * 此图层用来展示全景覆盖的区域。
77 | * 创建全景覆盖区域图层的实例
78 | */
79 | class PanoramaCoverageLayer extends TileLayer {
80 | constructor();
81 | }
82 | interface CustomLayerOptions {
83 | databoxId?: string;
84 | geotableId?: string;
85 | q?: string;
86 | tags?: string;
87 | filter?: string;
88 | pointDensityType?: PointDensityType;
89 | }
90 | type PointDensityType = number;
91 | }
92 |
93 | declare const BMAP_POINT_DENSITY_HIGH: BMap.PointDensityType;
94 | declare const BMAP_POINT_DENSITY_MEDIUM: BMap.PointDensityType;
95 | declare const BMAP_POINT_DENSITY_LOW: BMap.PointDensityType;
96 |
--------------------------------------------------------------------------------
/packages/types/src/maptype.d.ts:
--------------------------------------------------------------------------------
1 | ///
2 | ///
3 |
4 | declare namespace BMap {
5 | class MapType {
6 | /**
7 | * 创建 MapType 对象实例
8 | * @param name
9 | * @param layers
10 | * @param opts
11 | */
12 | constructor(name: string, layers: TileLayer | TileLayer[], opts?: MapTypeOptions);
13 | /**
14 | * 返回地图类型名称
15 | */
16 | getName(): string;
17 | /**
18 | * 返回地图类型对应的图层
19 | */
20 | getTileLayer(): TileLayer;
21 | /**
22 | * 返回地图类型允许的最小级别
23 | */
24 | getMinZoom(): number;
25 | /**
26 | * 返回地图类型允许的最大级别
27 | */
28 | getMaxZoom(): number;
29 | /**
30 | * 返回地图类型所使用的投影实例
31 | */
32 | getProjection(): Projection;
33 | /**
34 | * 返回地图类型对应的前景色
35 | */
36 | getTextColor(): string;
37 | /**
38 | * 返回地图类型的提示说明,用于在地图类型控件中提示
39 | */
40 | getTips(): string;
41 | }
42 | interface MapTypeOptions {
43 | /**
44 | * 该类型地图的最小级别
45 | */
46 | minZoom: Number;
47 | /**
48 | * 该类型地图的最大级别
49 | */
50 | maxZoom: Number;
51 | /**
52 | * 当没有图块时所显示的错误图片地址。默认为透明图
53 | */
54 | errorImageUrl: String;
55 | /**
56 | * 地图类型对应的前景色
57 | */
58 | textColor: Number;
59 | /**
60 | * 提示说明信息,用于在地图类型控件中进行提示
61 | */
62 | tips: String;
63 | }
64 | /**
65 | * 此类表示地图投影抽象基类,不可实例化,但可通过MapType的getProjection方法获得。
66 | */
67 | interface Projection {
68 | /**
69 | * 抽象,根据球面坐标获得平面坐标
70 | * @param lngLat
71 | */
72 | lngLatToPoint(lngLat: Point): Pixel;
73 | /**
74 | * 抽象,根据平面坐标获得球面坐标
75 | * @param point
76 | */
77 | pointToLngLat(point: Pixel): Point;
78 | }
79 | /**
80 | * 此类表示街道地图投影类,一般通过 MapType 的getProjection方法获得实例。
81 | */
82 | type MercatorProjection = Projection;
83 | /**
84 | * 此类表示透视地图投影类,一般通过 MapType 的getProjection方法获得实例
85 | */
86 | type PerspectiveProjection = Projection;
87 | }
88 | declare const BMAP_NORMAL_MAP: BMap.MapType;
89 | declare const BMAP_PERSPECTIVE_MAP: BMap.MapType;
90 | declare const BMAP_SATELLITE_MAP: BMap.MapType;
91 | declare const BMAP_HYBRID_MAP: BMap.MapType;
92 |
--------------------------------------------------------------------------------
/packages/types/src/rightmenu.d.ts:
--------------------------------------------------------------------------------
1 | ///
2 |
3 | declare namespace BMap {
4 | type ContextMenuIcon = string;
5 | interface MenuItemOptions {
6 | /**
7 | * 指定此菜单项的宽度,菜单以最长的菜单项宽度为准
8 | */
9 | width: Number;
10 | /**
11 | * 指定此菜单项dom的id
12 | */
13 | id: string;
14 | /**
15 | * 指定此菜单项的icon URL(大小为17px*17px)
16 | */
17 | iconUrl: string | ContextMenuIcon;
18 | }
19 | class MenuItem {
20 | constructor(text: string, callback: (point: Point) => void, opts?: MenuItemOptions);
21 | /**
22 | * 设置菜单项显示的文本
23 | */
24 | setText: (text: string) => void;
25 | /**
26 | * 设置菜单项的icon
27 | */
28 | setIcon: (iconUrl: string) => void;
29 | /**
30 | * 启用菜单项
31 | */
32 | enable: () => void;
33 | /**
34 | * 禁用菜单项
35 | */
36 | disable: () => void;
37 | }
38 |
39 | /**
40 | * 此类表示右键菜单。您可以在地图上添加自定义内容的右键菜单。
41 | */
42 | class ContextMenu {
43 | constructor();
44 | /**
45 | * 添加菜单项
46 | */
47 | addItem: (item: MenuItem) => void;
48 | /**
49 | * 返回指定索引位置的菜单项,第一个菜单项的索引为0
50 | */
51 | getItem: (index: Number) => MenuItem;
52 | /**
53 | * 移除菜单项
54 | */
55 | removeItem: (item: MenuItem) => void;
56 | /**
57 | * 添加分隔符
58 | */
59 | addSeparator: () => void;
60 | /**
61 | * 移除指定索引位置的分隔符,第一个分隔符的索引为0
62 | */
63 | removeSeparator: (index: number) => void;
64 | onopen: (event: { type: string; target: any; point: Point; pixel: Pixel }) => void;
65 | onclose: (event: { type: string; target: any; point: Point; pixel: Pixel }) => void;
66 | }
67 | }
68 | declare const BMAP_CONTEXT_MENU_ICON_ZOOMIN: string;
69 | declare const BMAP_CONTEXT_MENU_ICON_ZOOMOUT: string;
70 |
--------------------------------------------------------------------------------
/packages/types/src/tools.d.ts:
--------------------------------------------------------------------------------
1 | ///
2 | ///
3 | ///
4 |
5 | declare namespace BMap {
6 | class PushpinTool {
7 | constructor(map: Map, opts?: PushpinToolOptions);
8 | open(): boolean;
9 | close(): boolean;
10 | setIcon(icon: Icon): Icon;
11 | getIcon(): Icon;
12 | setCursor(cursor: string): string;
13 | getCursor(): string;
14 | toString(): string;
15 | onmarkend: (event: { type: string; target: any; marker: Marker }) => void;
16 | }
17 | interface PushpinToolOptions {
18 | icon?: Icon;
19 | cursor?: string;
20 | followText?: string;
21 | }
22 | class DistanceTool {
23 | constructor(map: Map);
24 | open(): boolean;
25 | close(): void;
26 | toString(): string;
27 | ondrawend: (event: { type: string; target: any; points: Point[]; polylines: Polyline[]; distance: number }) => void;
28 | }
29 | class DragAndZoomTool {
30 | constructor(map: Map, opts?: DragAndZoomToolOptions);
31 | open(): boolean;
32 | close(): void;
33 | toString(): string;
34 | ondrawend: (event: { type: string; target: any; bounds: Bounds[] }) => void;
35 | }
36 | interface DragAndZoomToolOptions {
37 | zoomType?: ZoomType;
38 | autoClose?: boolean;
39 | followText?: string;
40 | }
41 | type ZoomType = number;
42 | }
43 | declare const BMAP_ZOOM_IN: BMap.ZoomType;
44 | declare const BMAP_ZOOM_OUT: BMap.ZoomType;
45 |
--------------------------------------------------------------------------------
/packages/types/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "../../tsconfig",
3 | "include": ["src"],
4 | "compilerOptions": {
5 | "baseUrl": ".",
6 | "outDir": "cjs",
7 | "noEmit": false
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/packages/utils/README.md:
--------------------------------------------------------------------------------
1 | @uiw/react-baidu-map-utils
2 | ===
3 |
4 | [](https://jaywcjlove.github.io/#/sponsor)
5 | [](https://www.npmjs.com/package/@uiw/react-baidu-map-utils)
6 | [](https://www.npmjs.com/package/@uiw/react-baidu-map-utils)
7 |
8 | ```shell
9 | $ npm i @uiw/react-baidu-map-utils
10 | ```
11 |
12 | ```jsx
13 | import { noop, requireCss, requireScript, useRenderDom, usePrevious } from '@uiw/react-baidu-map-utils';
14 | ```
15 |
--------------------------------------------------------------------------------
/packages/utils/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "@uiw/react-baidu-map-utils",
3 | "version": "2.7.3",
4 | "description": "Baidu Map utils Components for React.",
5 | "funding": "https://jaywcjlove.github.io/#/sponsor",
6 | "homepage": "https://uiwjs.github.io/react-baidu-map/",
7 | "main": "cjs/index.js",
8 | "module": "esm/index.js",
9 | "repository": {
10 | "type": "git",
11 | "url": "https://github.com/uiwjs/react-baidu-map.git"
12 | },
13 | "scripts": {
14 | "build": "tsbb build \"src/*.{tsx,ts}\" --use-babel --cjs cjs --bail",
15 | "watch": "tsbb watch \"src/*.{tsx,ts}\" --use-babel --cjs cjs"
16 | },
17 | "author": "Kenny Wong ",
18 | "license": "MIT",
19 | "files": [
20 | "src",
21 | "esm",
22 | "cjs"
23 | ],
24 | "keywords": [
25 | "react-baidu-map",
26 | "baidu",
27 | "baidu-map",
28 | "baidu-map-utils",
29 | "utils",
30 | "map",
31 | "react",
32 | "bdmap",
33 | "types",
34 | "百度",
35 | "地图",
36 | "百度地图"
37 | ],
38 | "peerDependencies": {
39 | "react": ">=16.14.0",
40 | "react-dom": ">=16.14.0"
41 | },
42 | "dependencies": {
43 | "@babel/runtime": "^7.18.0",
44 | "@uiw/react-baidu-map-types": "2.7.3"
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/packages/utils/src/index.ts:
--------------------------------------------------------------------------------
1 | export * from './noop';
2 | export * from './hooks';
3 | export * from './requireScript';
4 | export * from './usePortal';
5 |
--------------------------------------------------------------------------------
/packages/utils/src/noop.ts:
--------------------------------------------------------------------------------
1 | export function noop() {}
2 |
--------------------------------------------------------------------------------
/packages/utils/src/requireScript.ts:
--------------------------------------------------------------------------------
1 | const _importedScript: { [src: string]: true } = {};
2 |
3 | /**
4 | * load dependency by css tag
5 | */
6 | export function requireCss(src: string): Promise {
7 | const headElement = document && (document.head || document.getElementsByTagName('head')[0]);
8 |
9 | return new Promise((resolve, reject) => {
10 | if (!document || src in _importedScript) {
11 | resolve();
12 | return;
13 | }
14 | const script = document.createElement('link');
15 | script.type = 'text/css';
16 | script.rel = 'stylesheet';
17 | script.href = src;
18 | script.onerror = (err) => {
19 | headElement!.removeChild(script);
20 | reject(new URIError(`The css ${src} is no accessible.`));
21 | };
22 | script.onload = () => {
23 | _importedScript[src] = true;
24 | resolve();
25 | };
26 | headElement!.appendChild(script);
27 | });
28 | }
29 |
30 | /**
31 | * load dependency by script tag
32 | */
33 | export function requireScript(src: string): Promise {
34 | const headElement = document && (document.head || document.getElementsByTagName('head')[0]);
35 |
36 | return new Promise((resolve, reject) => {
37 | if (!document || src in _importedScript) {
38 | resolve();
39 | return;
40 | }
41 | const script = document.createElement('script');
42 | script.type = 'text/javascript';
43 | script.id = '_react_baidu_map';
44 | script.src = src;
45 | script.async = true;
46 | script.defer = true;
47 | script.onerror = (err) => {
48 | headElement!.removeChild(script);
49 | reject(new URIError(`The Script ${src} is no accessible.`));
50 | };
51 | script.onload = () => {
52 | _importedScript[src] = true;
53 | resolve();
54 | };
55 | headElement!.appendChild(script);
56 | });
57 | }
58 |
--------------------------------------------------------------------------------
/packages/utils/src/usePortal.tsx:
--------------------------------------------------------------------------------
1 | import React, { useState, useEffect, ReactPortal } from 'react';
2 | import { createPortal, unmountComponentAtNode } from 'react-dom';
3 |
4 | interface State {
5 | render: (props: { children?: React.ReactNode }) => ReactPortal | null;
6 | remove: (elm?: HTMLElement) => void;
7 | }
8 |
9 | export const usePortal = () => {
10 | const [container] = React.useState(() => {
11 | const el = document.createElement('div');
12 | return el;
13 | });
14 | const [portal, setPortal] = useState({
15 | render: () => null,
16 | remove: () => null,
17 | });
18 |
19 | const ReactCreatePortal = React.useCallback<(elmm: HTMLDivElement) => State>((elmm) => {
20 | const Portal: State['render'] = ({ children }) => {
21 | if (!children) return null;
22 | return createPortal(children, elmm);
23 | };
24 | const remove: State['remove'] = (elm) => {
25 | elm && unmountComponentAtNode(elm);
26 | };
27 | return { render: Portal, remove };
28 | }, []);
29 |
30 | useEffect(() => {
31 | if (container) portal.remove();
32 | const newPortal = ReactCreatePortal(container);
33 | setPortal(newPortal);
34 | return () => {
35 | newPortal.remove(container);
36 | };
37 | }, [container]);
38 |
39 | return { Portal: portal.render, container };
40 | };
41 |
--------------------------------------------------------------------------------
/packages/utils/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "../../tsconfig",
3 | "include": ["src"],
4 | "compilerOptions": {
5 | "baseUrl": ".",
6 | "outDir": "cjs",
7 | "noEmit": false
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/packages/with-map/README.md:
--------------------------------------------------------------------------------
1 | withMap
2 | ===
3 |
4 | [](https://jaywcjlove.github.io/#/sponsor)
5 | [](https://www.npmjs.com/package/@uiw/react-baidu-map-with-map)
6 | [](https://www.npmjs.com/package/@uiw/react-baidu-map-with-map)
7 |
8 | 一个高阶组件,用于将当前上下文的 `BMap.Map` 实例注入到目标组件中,主要用于实现对地图组件的自定义控制。
9 |
10 | ```jsx
11 | import { withMap, APILoader } from '@uiw/react-baidu-map';
12 | // 或者单独安装使用
13 | import withMap from '@uiw/react-baidu-map-with-map';
14 | ```
15 |
16 | ### 基本用法
17 |
18 | ```jsx mdx:preview
19 | import React from 'react';
20 | import { withMap, APILoader } from '@uiw/react-baidu-map';
21 |
22 | class ExampleMap extends React.Component {
23 | componentDidMount() {
24 | const { BMap, map, container } = this.props;
25 | // 启用滚轮放大缩小,默认禁用
26 | // map.enableScrollWheelZoom();
27 | // 添加地图类型控件
28 | map.addControl(new BMap.MapTypeControl({
29 | mapTypes:[
30 | BMAP_NORMAL_MAP,
31 | BMAP_HYBRID_MAP
32 | ]
33 | }));
34 | const point = new BMap.Point(121.458965, 31.238775);
35 | const marker = new BMap.Marker(point); // 创建标注
36 | map.addOverlay(marker); // 将标注添加到地图中
37 | marker.setAnimation(BMAP_ANIMATION_BOUNCE); // 跳动的动画
38 |
39 | // 添加自定义菜单
40 | const menu = new BMap.ContextMenu()
41 | const menuItem = [
42 | { text: '放大', callback: () => map.zoomIn() },
43 | { text: '缩小', callback: () => map.zoomOut() },
44 | ]
45 | for (let i = 0; i < menuItem.length; i++) {
46 | menu.addItem(new BMap.MenuItem(menuItem[i].text, menuItem[i].callback, 100));
47 | }
48 | map.addContextMenu(menu);
49 | }
50 | render() {
51 | return null;
52 | }
53 | }
54 |
55 | const CustomWithMap = withMap(ExampleMap);
56 |
57 | const Demo = () => {
58 | return (
59 |
60 |
61 | {
65 | console.log('instance>', instance);
66 | }}
67 | />
68 |
69 |
70 | )
71 | };
72 |
73 | export default Demo;
74 | ```
75 |
76 |
77 | 高阶组件 `withMap` 可以作为 `Map` 组件来使用,继承 `Map` 可以默认传递 `Map` 的属性,相关属性参考 [`