Comments (4)
首先:
onSearchComplete写在render中,是可用的,可直接参考示例中代码。
https://codesandbox.io/s/ymv7n67wrz
其中L21-L29
onSearchComplete = result => {
console.log(result);
const plan = result.getPlan(0); // 取第一条方案
console.log(plan.getDistance()); // 取当前方案距离
console.log(plan.getDuration()); // 取当前方案耗时
const route = plan.getRoute(0); // 取当前路线
console.log(route);
const path = route.getPath(); // 当前路线坐标集合
console.log(path);
};
这个path,就是最终您想要的当前展现路线中的坐标集合。
from rc-bmap.
非常感谢您的回答,我知道我的为什么没出来了,我一个walkingRoute,下面还有一个RidingRoute,我只是写了上面一个的事件,下面的没写,所以就没执行
<WalkingRoute
getInstance={this.getRoute}
showInMap
location="北京"
onSearchComplete={this.onSearchComplete}
// 这里还有更多属性,可参考文档
/>
<RidingRoute
getInstance={this.getRoute}
showInMap
/>
下一个组件的onSearchComplete会覆盖上面的一个,按说两个应该互不影响才对吧。这算不算个bug?
下面是我的验证,下面的果然会覆盖上面的。
<WalkingRoute
getInstance={this.getRoute}
showInMap
location="北京"
onSearchComplete={this.onSearchComplete}
// 这里还有更多属性,可参考文档
/>
<RidingRoute
getInstance={this.getRoute}
showInMap
onSearchComplete={this.onSearchComplete1}
/>
onSearchComplete = result => {
console.log('aaaaaaaaaa');
console.log(result);
};
onSearchComplete1 = result => {
console.log('bbbb');
console.log(result);
};
结果只输出了bbb和下面的对象,没有aaaa。
from rc-bmap.
这是使用时的问题。
我修改了示例中的代码:
https://codesandbox.io/s/ymv7n67wrz
上面产生的原因是由于在组件中的getInstance
中,route
后者覆盖了前者,这个searchComplete
是通过route.search
触发的,所以,在示例中,我用了更明确的名字来标识当前组件。看眼示例,您就都明白了。
from rc-bmap.
嗯,明白了,厉害厉害
from rc-bmap.
Related Issues (20)
- 自定义组件不全面啊,能不能直接继承BaseOverLay?
- 1.0.5版本,经纬度-3.74922 40.46367报错 HOT 1
- MarkerClusterer 如何引入使用 HOT 1
- Size 设置 offset 时无法使用负数,内部判断是否为Size时漏掉偏移量场景。 HOT 4
- Label组件中的Content中为HTML添加点击事件,不生效
- [BUG] 在移动端上 Polygon 再次渲染时会消失
- 请求补充typescript声明
- Marker执行点击事件时如何屏蔽Map的点击事件呢?
- Cannot read property 'Geolocation' of undefined
- 无法获取百度原生对象呢? HOT 1
- 没有这个AutoComplete 例子demo吗?
- 如何获取到BMapLib这个类
- BMapUtil.search 搜索结果参数不固定
- 为什么1.0版本后MarkerClusterer点聚合功能没有呢?
- setCenter方法不管用
- BMapUtil.search 这个方法是不是有点问题 HOT 1
- ie10报错
- DrivingRoute的search方法设置途经点waypoints不起作用
- 示例地址以及api地址打不开了
- Why can't I open the document address???
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rc-bmap.