react-bmap 安装于使用

react-bmap安装与使用

一、安装
1、

npm i react-bmapgl -S

2、引入js(public index.html)

<script type="text/javascript"
src="//api.map.baidu.com/api?type=webgl&v=1.0&ak=你的秘钥">
</script>

3、引入组件

import { Map, Marker, NavigationControl, InfoWindow, Polyline, Polygon, ZoomControl } from 'react-bmapgl';

二、Map
1、引入获取

ref={ref => { this.map = ref.map }}

2、地图中心

center={{ lng: center.lon, lat: center.lat }}

3、缩放层级

zoom="13"

4、鼠标滚动缩放

 enableScrollWheelZoom={true}

5、样式

style={{ height: 600 }}

三、Marker

position={{lng,lat}}
icon=“start”
onClick={this.showInfo}

四、绘线(Polyline)

  path={position_list.map(item => new window.BMapGL.Point(item.lon, item.lat))}
  strokeColor="#f00"
  strokeWeight={6}

五、多边形(Polygon)

 path={details.area.map(item => new window.BMapGL.Point(item.lon, item.lat))}
    strokeColor="#f00"
    strokeWeight={1}
    fillColor="#ff0"
    fillOpacity={0.1}
    onm ouseover={e => { console.log(e) }}
	//路径:线条颜色,线条粗细,填充颜色,填充透明度

六、缩放组件

<ZoomControl />

七、导航组件

<NavigationControl />

八、信息窗口(InfoWindow)
1、ref={ref => { this.infoWindow = ref.infoWindow }}
2、位置position={new window.BMapGL.Point(center.lon, center.lat)}
3、标题title="订单信息"
4、文本内容text={text}
5、打开信息窗口

this.map.openInfoWindow(this.infoWindow, this.map.getCenter());
上一篇:FL Studio最新20.9中文豪华顶配购买指南


下一篇:基数树RadixTree的golang实现