react-百度地图


引入

  1. 在public的index.html中引入
  <script type="text/javascript" src="//api.map.baidu.com/api?type=webgl&v=1.0&ak=你的Ak"></script>
npm install react-bmapgl --save
import { Map, Marker, NavigationControl, InfoWindow } from 'react-bmapgl';
 render() {
        const details=this.state.details;
        return (<div>
            <h1>订单详情</h1>
            {details.order_sn?
                <Map center={{ lng: 116.402544, lat: 39.928216 }} zoom="11">
                    <Marker position={{ lng: 116.402544, lat: 39.928216 }} />
                    <NavigationControl />
                    <InfoWindow position={{ lng: 116.402544, lat: 39.928216 }} text="内容" title="标题" />
                </Map>:'数据加载中'
            }
        </div>);
    }

Map

引用获取
ref={ref => { this.map = ref.map }}
地图中心
center={{ lng: center.lon, lat: center.lat }}
缩放层级
zoom=“11”
鼠标滚动缩放
enableScrollWheelZoom={true}
样式
style={{ height: 500 }}>

Maker

position={{ lng: position_list[0].lon, lat: position_list[0].lat }}
icon=“start”
icon=“end”
onClick={this.showInfo}

Polyline绘线

	<Polyline
    path={
        position_list.map(item => new window.BMapGL.Point(item.lon, item.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) }}
/>

缩放组件ZoomControl

导航组件 <NavigationControl />

信息窗口<InfoWindow></InfoWindow>

ref={ref => { this.infoWindow = ref.infoWindow }}
	位置
position={new window.BMapGL.Point(116.40, 39.91)}
	标题
title="订单信息"
	内容
text={text}
	onClickclose={e => { console.log(e) }}
	打开信息窗口 
this.map.openInfoWindow(this.infoWindow, this.map.getCenter());

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值