Installations
npm install @uiw/react-baidu-map-info-window
Developer Guide
Typescript
Yes
Module System
CommonJS
Node Version
20.14.0
NPM Version
8.19.4
Score
71.1
Supply Chain
94.4
Quality
79.1
Maintenance
100
Vulnerability
100
License
Releases
Contributors
Unable to fetch Contributors
Languages
TypeScript (98.85%)
HTML (0.99%)
Less (0.14%)
Shell (0.03%)
Love this project? Help keep it running — sponsor us today! 🚀
Developer
Download Statistics
Total Downloads
135,565
Last Day
563
Last Week
3,499
Last Month
11,028
Last Year
108,749
GitHub Statistics
226 Stars
520 Commits
22 Forks
7 Watching
8 Branches
12 Contributors
Bundle Size
3.83 kB
Minified
1.56 kB
Minified + Gzipped
Sponsor this package
Package Meta Information
Latest Version
2.7.2
Package Id
@uiw/react-baidu-map-info-window@2.7.2
Unpacked Size
23.60 kB
Size
5.91 kB
File Count
12
NPM Version
8.19.4
Node Version
20.14.0
Publised On
24 Jun 2024
Total Downloads
Cumulative downloads
Total Downloads
135,565
Last day
-24.9%
563
Compared to previous day
Last week
37.2%
3,499
Compared to previous week
Last month
63.7%
11,028
Compared to previous month
Last year
526.5%
108,749
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
InfoWindow 信息窗口
表示地图上包含信息的窗口。
1import { InfoWindow, useInfoWindow } from '@uiw/react-baidu-map'; 2// 或者单独安装使用 3import InfoWindow, { useInfoWindow } from '@uiw/react-baidu-map-info-window';
基本用法
1import React, { useState } from 'react'; 2import { Map, InfoWindow, APILoader } from '@uiw/react-baidu-map'; 3 4const Example = () => { 5 const [visiable, setVisiable] = useState(true); 6 const [ isOpen, setIsOpen ] = useState(true); 7 const [ content, setContent ] = useState('上海市 <del>青浦区</del> 徐泾镇盈港东路'); 8 9 function infoWindowRef(props) { 10 if (props && props.infoWindow) { 11 console.log('infoWindow:', props.infoWindow, props.map, props.BMap); 12 } 13 } 14 return ( 15 <> 16 <button onClick={() => setIsOpen(!isOpen)}>{isOpen ? '关闭' : '打开'} isOpen={String(isOpen)}</button> 17 <button onClick={() => setVisiable(!visiable)}>{visiable ? '隐藏' : '显示'}visiable={String(visiable)}</button> 18 <input value={content} onChange={(e) => setContent(e.target.value)} /> 19 <Map zoom={13} center={{ lng: 121.460977, lat: 31.227906 }}> 20 <InfoWindow 21 ref={infoWindowRef} 22 visiable={visiable} 23 isOpen={isOpen} 24 onClose={() => { 25 console.log(':onClose'); 26 }} 27 position={{ lng: 121.501365, lat: 31.224942 }} 28 content={content} 29 title="地址信息一" 30 /> 31 </Map> 32 </> 33 ); 34} 35 36const Demo = () => ( 37 <div style={{ width: '100%', height: '350px' }}> 38 <APILoader akay="eYpCTECSntZmw0WyoQ7zFpCRR9cpgHFG"> 39 <Example /> 40 </APILoader> 41 </div> 42); 43export default Demo;
content
-> children
支持 JSX.Element
content
通过 children
支持 JSX.Element
的方式展现内容,因为窗口信息内容通过 content
展示内容,它支持 string/HTMLElement
添加事件并不方便。
🚧 如果同时设置了
content
属性且有children
,content
将失效被忽略。
1import React, { useState } from 'react'; 2import { Map, InfoWindow, APILoader } from '@uiw/react-baidu-map'; 3 4const Example = () => { 5 const [visiable, setVisiable] = useState(true); 6 const [ isOpen, setIsOpen ] = useState(true); 7 const [ count, setCount ] = useState(0); 8 return ( 9 <> 10 <button onClick={() => setIsOpen(!isOpen)}>{isOpen ? '关闭' : '打开'} isOpen={String(isOpen)}</button> 11 <button onClick={() => setVisiable(!visiable)}>{visiable ? '隐藏' : '显示'}visiable={String(visiable)}</button> 12 <Map zoom={13} center={{ lng: 121.460977, lat: 31.227906 }}> 13 <InfoWindow 14 visiable={visiable} 15 isOpen={isOpen} 16 onClose={() => { 17 console.log(':onClose'); 18 }} 19 position={{ lng: 121.501365, lat: 31.224942 }} 20 title={<div>地址信息二</div>} 21 content="test" 22 > 23 <div> 24 上海市 <del>青浦区</del> 徐泾镇盈港东路 Good! 25 <br/> 26 <button onClick={() => setCount(count+1)}>{count} Count={String(count)}</button> 27 </div> 28 </InfoWindow> 29 </Map> 30 </> 31 ); 32} 33 34const Demo = () => ( 35 <div style={{ width: '100%', height: '350px' }}> 36 <APILoader akay="eYpCTECSntZmw0WyoQ7zFpCRR9cpgHFG"> 37 <Example /> 38 </APILoader> 39 </div> 40); 41export default Demo;
使用 hooks
infoWindow
, setInfoWindow
, isOpen
, setIsOpen
1import React, { useRef, useState, useEffect } from 'react'; 2import { Map, Provider, useMap, InfoWindow, useInfoWindow, APILoader } from '@uiw/react-baidu-map'; 3 4const Example = () => { 5 const divElm = useRef(null); 6 const { setContainer, map } = useMap({ 7 zoom: 13, center: { lng: 121.460977, lat: 31.227906 }, 8 widget: ['GeolocationControl', 'NavigationControl'] 9 }); 10 11 const [title, setTitle] = useState('地址信息二'); 12 const position = { lng: 121.501365, lat: 31.224942 }; 13 const { infoWindow, isOpen, setIsOpen, Portal, PortalTitle } = useInfoWindow({ 14 position, enableCloseOnClick: false, isOpen: true, 15 // content: '上海市 <del>青浦区</del> 徐泾镇盈港东路', 16 // title, 17 onClose: () => { 18 console.log('onClose:'); 19 } 20 }); 21 useEffect(() => { 22 if (divElm.current) { 23 setContainer(divElm.current); 24 } 25 }); 26 return ( 27 <> 28 <button onClick={() => setIsOpen(!isOpen)}>{isOpen ? '显示' : '隐藏'}</button> 29 <input value={title} onChange={(e) => setTitle(e.target.value)} /> 30 <div ref={divElm} style={{ height: 350 }} /> 31 <Portal>上海市 <del>青浦区</del> 徐泾镇盈港东路</Portal> 32 <PortalTitle> {title} </PortalTitle> 33 </> 34 ) 35} 36 37const Demo = () => { 38 return ( 39 <div style={{ width: '100%' }}> 40 <APILoader akay="eYpCTECSntZmw0WyoQ7zFpCRR9cpgHFG"> 41 <Provider> 42 <Example /> 43 </Provider> 44 </APILoader> 45 </div> 46 ) 47}; 48export default Demo;
Props
参数 | 说明 | 类型 | 默认值 |
---|---|---|---|
position | 必填 指定的经度和纬度创建一个地理点坐标 | Point | - |
content | 展示文本内容,支持 HTML 内容字符串 | string | - |
children | 展示文本内容,🚧 添加 children 的时候 content 将失效。 | JSX.Element | - |
isOpen | 窗口是否打开 | Point | - |
visiable | 覆盖物是否可见。此属性来自继承 Overlay 实例对象。 | boolean | - |
width | 信息窗宽度,单位像素。取值范围:0 , 220 - 730 。如果您指定宽度为 0 ,则信息窗口的宽度将按照其内容自动调整 | number | true |
height | 信息窗高度,单位像素。取值范围:0 , 60 - 650 。如果您指定宽度为 0 ,则信息窗口的宽度将按照其内容自动调整 | number | - |
maxWidth | 信息窗最大化时的宽度,单位像素。取值范围:220 - 730 | number | - |
offset | 信息窗位置偏移值。默认情况下在地图上打开的信息窗底端的尖角将指向其地理坐标,在标注上打开的信息窗底端尖角的位置取决于标注所用图标的 infoWindowOffset 属性值,您可以为信息窗添加偏移量来改变默认位置 | Size | - |
maxContent | 信息窗口最大化时所显示内容,支持HTML内容 | string | - |
title | 信息窗标题文字,支持 HTML 内容 | string | - |
message | 自定义部分的短信内容,可选项。完整的短信内容包括:自定义部分+位置链接,不设置时,显示默认短信内容。短信内容最长为140个字 | string | - |
enableAutoPan | 是否开启信息窗口打开时地图自动移动(默认开启) | boolean | - |
enableCloseOnClick | 是否开启点击地图关闭信息窗口(默认开启) | boolean | - |
enableMaximize | 启用窗口最大化功能。需要设置最大化后信息窗口里的内容,该接口才生效 | boolean | - |
事件
参数 | 说明 | 类型 |
---|---|---|
onClose | 信息窗口被关闭时触发此事件 | (event: { type: string, target: any, point: Point }) => void; |
onOpen | 信息窗口被打开时触发此事件 | (event: { type: string, target: any, point: Point }) => void; |
onMaximize | 信息窗口最大化后触发此事件 | (event: { type: string, target: any }) => void; |
onRestore | 信息窗口还原时触发此事件 | (event: { type: string, target: any }) => void; |
onClickclose | 点击信息窗口的关闭按钮时触发此事件 | (event: { type: string, target: any }) => void; |
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
packaging workflow detected
Details
- Info: Project packages its releases by way of GitHub Actions.: .github/workflows/ci.yml:29
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
Found 0/24 approved changesets -- score normalized to 0
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci.yml:14: update your workflow using https://app.stepsecurity.io/secureworkflow/uiwjs/react-baidu-map/ci.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci.yml:15: update your workflow using https://app.stepsecurity.io/secureworkflow/uiwjs/react-baidu-map/ci.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci.yml:35: update your workflow using https://app.stepsecurity.io/secureworkflow/uiwjs/react-baidu-map/ci.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci.yml:36: update your workflow using https://app.stepsecurity.io/secureworkflow/uiwjs/react-baidu-map/ci.yml/master?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/ci.yml:56: update your workflow using https://app.stepsecurity.io/secureworkflow/uiwjs/react-baidu-map/ci.yml/master?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/ci.yml:61: update your workflow using https://app.stepsecurity.io/secureworkflow/uiwjs/react-baidu-map/ci.yml/master?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/ci.yml:236: update your workflow using https://app.stepsecurity.io/secureworkflow/uiwjs/react-baidu-map/ci.yml/master?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/ci.yml:242: update your workflow using https://app.stepsecurity.io/secureworkflow/uiwjs/react-baidu-map/ci.yml/master?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/ci.yml:245: update your workflow using https://app.stepsecurity.io/secureworkflow/uiwjs/react-baidu-map/ci.yml/master?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/ci.yml:255: update your workflow using https://app.stepsecurity.io/secureworkflow/uiwjs/react-baidu-map/ci.yml/master?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/ci.yml:263: update your workflow using https://app.stepsecurity.io/secureworkflow/uiwjs/react-baidu-map/ci.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/pull_request.yml:9: update your workflow using https://app.stepsecurity.io/secureworkflow/uiwjs/react-baidu-map/pull_request.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/pull_request.yml:10: update your workflow using https://app.stepsecurity.io/secureworkflow/uiwjs/react-baidu-map/pull_request.yml/master?enable=pin
- Warn: npmCommand not pinned by hash: .github/workflows/ci.yml:43
- Warn: npmCommand not pinned by hash: .github/workflows/ci.yml:45
- Warn: npmCommand not pinned by hash: .github/workflows/ci.yml:46
- Warn: npmCommand not pinned by hash: .github/workflows/pull_request.yml:17
- Warn: npmCommand not pinned by hash: .github/workflows/pull_request.yml:19
- Warn: npmCommand not pinned by hash: .github/workflows/pull_request.yml:20
- Info: 0 out of 6 GitHub-owned GitHubAction dependencies pinned
- Info: 0 out of 7 third-party GitHubAction dependencies pinned
- Info: 0 out of 6 npmCommand dependencies pinned
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
detected GitHub workflow tokens with excessive permissions
Details
- Warn: no topLevel permission defined: .github/workflows/ci.yml:1
- Warn: no topLevel permission defined: .github/workflows/pull_request.yml:1
- Info: no jobLevel write permissions found
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 6 are checked with a SAST tool
Score
4.2
/10
Last Scanned on 2025-01-27
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More