ElemeFE / react-amap

基于 React 封装的高德地图组件。AMap Component Based On React.
https://elemefe.github.io/react-amap/articles/start
MIT License
1.03k stars 151 forks source link

使用驾车路线规划的api设置途径点,不能成功。 #94

Closed Jamesxiehailong closed 6 years ago

Jamesxiehailong commented 6 years ago

我打算使用驾车路线的路径规划api,设置多个途径点,不能成功, 这是我的map中子组件的写法

 componentWillMount(){
        const map = this.props.__map__;
        var truckOptions = {
            map: map,
            policy:0,
            size:1,
            city:'beijing',
            panel:'panel'

         };
        let AMap =  window.AMap;
        new AMap.plugin(['AMap.Driving'],function(){

           var driving= new AMap.Driving(truckOptions);

           driving.search(new AMap.LngLat(116.379028, 39.865042), new AMap.LngLat(116.427281, 39.903719),new AMap.LngLat(116.379028, 38.865042),);
        });
    }

父组件:

  <Map plugins={['ToolBar','MapType','Scale','OverView']}  center={this.center} zoom={9} useAMapUI={true} amapkey='mykey' >

                    <PlanDriving></PlanDriving> 
                     {/* {dirvingArr.length && <PlanDriving dirvingArr = {this.state.dirvingArr}></PlanDriving>}            */}
                    <Markers 
                      events={this.markersEvents}
                      markers={markersCon}
                      useCluster={useCluster}
                    />
                     <InfoWindow
                      position={this.state.infoPosition}
                      visible={this.state.infoVisible}
                      isCustom={false}
                      events={this.windowEvents}
                      autoMove = {true}
                      size={this.state.size}                      
                    >
                     {infoContent.length === 0 ? null : <Card title='用户信息'  style={{ width: 300,border:"none" }}>
                            <p>姓名:{infoContent.name}</p>  
                            <p>电话:{infoContent.phone}</p>  
                            <p>地址:{infoContent.contactAddress}</p>  
                            <p>负责人姓名:{infoContent.responsibleName}</p>  
                            <p>负责人电话:{infoContent.recommendPhone}</p>  
                            <p>配送时间:{`${infoContent.receivingTime[0]}至${infoContent.receivingTime[1]}`}</p>  
                         </Card>}
                    </InfoWindow>    
                  </Map>   
ioslh commented 6 years ago

试了下没有问题啊。

你再检查下代码,是否有报错之类的。不能成功的表现是什么?最好有个复现的在线示例。

Jamesxiehailong commented 6 years ago

你的示例里面,设置了 3 点,但是途径点并没有显示出来,我从你的那个示例去掉了最后一个坐标点,地图呈现的规划路径没有变化,这个地方是默认取前两个坐标进行规划么?我在想对应完成的功能和下面这个例子很相似this

Jamesxiehailong commented 6 years ago

对了当前我使用的组件库版本是 "react-amap": "^1.2.3",我去加载货车规划路劲的插件,进入不了回调。所以才打算用普通驾车的api,这个和版本有关系么?谢谢啦!(≧▽≦)/

ioslh commented 6 years ago

image

AMap.TruckDriving 是高德 JSSDK 1.4.4 版本添加的功能。react-amap 默认使用 1.4.0,可以使用 version 来指定版本。

<Map version="1.4.4">
    ....
</Map>
Jamesxiehailong commented 6 years ago

这相当于我之前写的方式this,控制台有一个报错,我这样写,在那个回调中我打了debugger,不能进入

Jamesxiehailong commented 6 years ago

恩恩,好的。我明白了。谢谢啦。O(∩_∩)O!

superlbr commented 6 years ago

请教如何clear driving.search的显示结果,传入新的参数后发现原先的路径还在

superlbr commented 6 years ago

发现可以直接调用 map.clearMap() 。。。