自封装的react引入使用二维地图组件(内含GPS坐标转换高德地图左边的近似方法)

自封装的react引入使用二维地图组件

废话少说,直接干货

AMap(高德地图)

内含GPS坐标转换高德地图左边的近似方法

class AMap extends Component {
  constructor(){
    super();
    this.state = {
      mapCenter: {longitude: 113.77, latitude: 34.75},
      status: {
        zoomEnable: true,
        scrollWheel:false,
        doubleClickZoom:false
      },
      zoom:11,
      startPoints:[],
      endPoints:[],
      rfids:[],
      faces:[],
      loading:[]
    }
  }
  componentWillMount=()=>{
    let timer=setTimeout(()=>{
      if(this.state.init){
        clearTimeout()
      }else{
        this.init()
      }
    },1000)
  }

  state={
      show:null,
      gpsType:"gps"
  }
  init=()=>{
    if(this.props.dataSource){
      this.setState({init:true})
    }else{
      this.setState({init:false})
      return
    }

    // let navigationLine=this.props.dataSource.navigationLine
    // let driverTrip=this.props.dataSource.driverTrip
    // let carTrip=this.props.dataSource.carTrip
    let startPoints=[]
    let endPoints=[]
    let rfids=[]
    let faces=[]
    let loading=[]
    let car

this.props.dataSource.timelineInfos&&this.props.dataSource.timelineInfos.map(item=>{
.....
if(this.props.dataSource.carTrip.length>0){
  let pointcar=this.props.dataSource.carTrip[this.props.dataSource.carTrip.length-1]
  car={longitude:pointcar.longitude+0.00603,latitude:pointcar.latitude+0.001275}
}
})
this.setState({startPoints,endPoints,rfids,faces,loading,mapCenter:car, zoom:9})

  }



  resetBigZoom=()=>{
    if(this.state.zoom<18){
      this.setState({zoom:this.state.zoom+1})
    }
  }
  resetSmallZoom=()=>{
    if(this.state.zoom>3) {
      this.setState({zoom: this.state.zoom - 1})
    }
  }

  render() {
    console.log(this )
    let car=null
    if(this.props.dataSource.carTrip.length>0){
      let pointcar=this.props.dataSource.carTrip[this.props.dataSource.carTrip.length-1]
      car=this.state.gpsType=="gps"?{longitude:pointcar.longitude+0.00603,latitude:pointcar.latitude+0.001275}:pointcar
    }
    return (
      <div className={"w_amap"}>
        <Map amapkey={"2d3828d880fad65924524f0384369550"}
             center={this.state.mapCenter}
             status={this.state.status}

           zoom={this.state.zoom}>

      {this.state.show=="car"&&this.props.dataSource.carTrip.length>0&&<Polyline zIndex="100" visible
         path={this.state.gpsType=="gps"?this.props.dataSource.carTrip.map(item=>({longitude:item.longitude+0.00603,latitude:item.latitude+0.001275})):this.props.dataSource.carTrip } style={{lineJoin:"round",strokeColor:"#21CA25",strokeWeight:8,isOutline:true,outlineColor:"#137F16"}}/>}
    </Map>
    <div className={style.mapmenu2}>
      <div className={style.menu2}>
        <span><img src={Big} onClick={()=>this.resetBigZoom()}/></span>
        <span><img src={Small} onClick={()=>this.resetSmallZoom()}/></span>
        {/*<span><img src={FullScreen} onClick={()=>this.resetBigZoom()}/></span>*/}
      </div>
    </div>
  </div>
)
  }
}

export default connect(({amap})=>({amap}))(Amap);

BMap(百度地图)

忘了写了

声明

以上内容均来源于实用中的网络和官方查找,若有批漏或侵权请告知。

生命的成长,需要吃饭,还需要吃苦,吃亏。

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

悟天特斯

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值