├── .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 | [![Buy me a coffee](https://img.shields.io/badge/Buy%20me%20a%20coffee-048754?logo=buymeacoffee)](https://jaywcjlove.github.io/#/sponsor) 5 | [![npm version](https://img.shields.io/npm/v/@uiw/react-baidu-map-api-loader.svg)](https://www.npmjs.com/package/@uiw/react-baidu-map-api-loader) 6 | [![Downloads](https://img.shields.io/npm/dm/@uiw/react-baidu-map-api-loader.svg?style=flat)](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 |
43 | 44 | 45 | 46 |
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 | [![Buy me a coffee](https://img.shields.io/badge/Buy%20me%20a%20coffee-048754?logo=buymeacoffee)](https://jaywcjlove.github.io/#/sponsor) 5 | [![npm version](https://img.shields.io/npm/v/@uiw/react-baidu-map-copyright-control.svg)](https://www.npmjs.com/package/@uiw/react-baidu-map-copyright-control) 6 | [![Downloads](https://img.shields.io/npm/dm/@uiw/react-baidu-map-copyright-control.svg?style=flat)](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 | 33 | 34 | 35 | 自定义版权只在上海地区可见 36 | 37 | {show && ( 38 | 在任何区域都可见 39 | )} 40 | 41 | 44 | 在任何区域都可见 45 | 46 | 47 | 48 | {show && ( 49 | 50 | 自定义版权只在上海地区可见 51 | 52 | )} 53 | 在任何区域都可见 54 | 55 | 56 | 57 | ); 58 | } 59 | 60 | const Demo = () => ( 61 |
62 | 63 | 64 | 65 |
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('