react-百度地图

安装

npm i reacat-bmapgl -S  //安装react组件库

引入js

public/index.html

<script src="https://api.map.baidu.com/apiv=1.0&&type=webgl&ak=你的ak"></script>

引入组件

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

Map

如果你在业务中需要操作map对象,需要BMapGL.Map实例的话,可以通过组件实例的map属性访问到它。

<Map
 ref={ref => {this.map = ref.map}}   //获取map实例
 center = {lng:center.lng,lat:center.lat}}    //地图中心
 zoom=“13”   //缩放层级
 enableScrollWheelZoom={true}    //鼠标滚动
 style={{height:600}}    //样式
 />

Marker点标注

<Marker
 position={{lng,lat}}    //标注点的坐标
 icon="start"    //图标
 onClick={this.showInfo}    //单机事件
>
 <ZoomControl />    //缩放控件
 <NavigationControl />    //3D控件
</Marker>

Polyline绘线

<Polyline
 path={new window.BMapGL.Point(lng, lat))}    //路径
 strokeColor="#f00"    //折线的颜色
 strokeWeight={6}      //折线的宽度
/>

polygon多边形

<polygon
 path={ details.area.map(item=> new window.BMapGL.Point(item.lon, item.lat))}      //路径
 strokeColor="#f00"    //折线的颜色
 strokeWeight={1}      //折线的宽度
 fillColor="#ff0"      //面填充颜色
 fillOpacity={0.1}    //面填充的透明度
 onMouseover={e => {console.log(e)}}    //鼠标指针移入覆盖物事件的回调函数
/>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值