Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

bmap-libs

Package Overview
Dependencies
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bmap-libs

百度地图插件

  • 1.5.0
  • latest
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

bmap-libs

百度地图插件

使用说明

安装

npm install bmap-libs
# OR
yarn add bmap-libs

使用

import bmapLibs from 'bmap-libs';

// 百度地图库加载完毕后初始化
bmapLibs();

// 绘制多段线
const multiPolyline = new BMapGLLib.MultiPolyline(points, options);

// 添加marker
const marker = new BMapGLLib.Marker(point, content, options);

// 添加popup
const popup = new BMapGLLib.Popup(content, options);
// 直接使用
popup.setPoint(point);
// 或者绑定到marker
marker.bindPopup(popup);

注意

不要通过直接调用 overlay.remove() 来移除图层!!!正确的移除方法如下:

// 移除单个图层
map.removeOverlay(overlay);
// 移除全部图层
map.clearOverlays();

MultiPolyline

示例

let multiPoints = [
  [
    '116.27961508447355,40.049453414029834',
    '116.2801675423622,40.04985729053617',
    '116.2798172032133,40.050264616535344',
    '116.28072000025082,40.050461374825595',
    '116.2815823735404,40.05003679043139',
    '116.28114220384052,40.04954661651461',
  ],
  ['116.27966898280415,40.04863529781763', '116.28142067854861,40.04870778952721'],
];
multiPoints = multiPoints.map((points) => points.map((point) => new BMapGL.Point(...point.split(','))));

const multiPolyline = new BMapGLLib.MultiPolyline(multiPoints, { strokeColor: 'red' });
map.addOverlay(multiPolyline);

参数

参数类型描述
pointsArray多段线的 Point 二维数组
optionsObject多段线的配置
options
属性类型默认值描述
zIndexNumber1层级
strokeColorString'blue'多段线颜色
strokeWeightNumber2多段线的宽度,以像素为单位
strokeOpacityNumber1多段线的透明度,取值范围 0 - 1
delayNumber100防抖延迟,单位毫秒,值为 0 则不开启防抖
paneString'markerPane'添加到的面板(可选值见 map.getPanes()返回值)

方法

名称返回值备注
on(<String>type, <Function>listener)绑定事件
off(<String>type, <Function>listener)解绑事件
isVisible()Boolean查看多段线图层可见性
show()显示多段线图层
hide()隐藏多段线图层
getZIndex()Number获取 zIndex
setZIndex(<Number>zIndex)设置 zIndex

Marker

示例

const point = new BMapGL.Point(116.27961508447355, 40.049453414029834);
const div = document.createElement('div');
div.style.width = '40px';
div.style.height = '40px';
div.style.background = 'rgba(0, 0, 255, .5)';

const marker = new BMapGLLib.Marker(point, div, { zIndex: 2, offset: new BMapGL.Size(0, 0) });
marker.on('click', () => {
  console.log('marker click');
});
map.addOverlay(marker);

参数

参数类型描述
pointObject坐标点
contentString|HTMLElementdom 字符串或者 dom 元素
optionsObject配置
options
属性类型默认值描述
zIndexNumber1层级
offsetSizeSize(0, 0)偏移量
classNameString''css 类名
paneString'markerPane'添加到的面板

方法

名称返回值备注
on(<String>type, <Function>listener)绑定事件
off(<String>type, <Function>listener)解绑事件
isVisible()Boolean查看 marker 可见性
show()显示 marker
hide()隐藏 marker
update()更新 marker
getZIndex()Number获取 zIndex
setZIndex(<Number>zIndex)设置 zIndex
getPosition()返回标注的地理坐标
bindPopup(<Popup>popup)绑定 popup
unbindPopup()解绑 popup
getPopup()Popup获取 popup
openPopup()打开 popup
closePopup()关闭 popup
isPopupOpen()Boolean查看 popup 是否打开

Popup

示例

const point = new BMapGL.Point(116.27961508447355, 40.049453414029834);
const popupEl = document.createElement('div');
popupEl.style.width = '200px';
popupEl.style.height = '120px';
popupEl.style.border = '1px solid black';
popupEl.style.background = 'rgba(255, 255, 255, .5)';

const popup = new BMapGLLib.Popup(popupEl, { offset: new BMapGL.Size(0, -10), visible: true });

// 直接使用
popup.setPoint(point);
map.addOverlay(popup);

// 或者绑定到marker使用
marker.bindPopup(popup);
map.addOverlay(marker);

参数

参数类型描述
contentString|HTMLElementdom 字符串或者 dom 元素
optionsObject配置
options
属性类型默认值描述
zIndexNumber1层级
offsetSizeSize(0, 0)偏移量
classNameString''css 类名
visibleBooleantrue初始可见性
paneString'labelPane'添加到的面板

方法

名称返回值备注
on(<String>type, <Function>listener)绑定事件
off(<String>type, <Function>listener)解绑事件
isVisible()Boolean查看 popup 可见性
show()显示 popup
hide()隐藏 popup
update()更新 popup
setPoint(<Point>point)设置坐标点
getZIndex()Number获取 zIndex
setZIndex(<Number>zIndex)设置 zIndex

Keywords

FAQs

Package last updated on 06 Nov 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc