Giter VIP home page Giter VIP logo

Comments (4)

JserWang avatar JserWang commented on June 19, 2024

首先:
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.

codepandy avatar codepandy commented on June 19, 2024

非常感谢您的回答,我知道我的为什么没出来了,我一个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.

JserWang avatar JserWang commented on June 19, 2024

这是使用时的问题。

我修改了示例中的代码:
https://codesandbox.io/s/ymv7n67wrz

上面产生的原因是由于在组件中的getInstance中,route后者覆盖了前者,这个searchComplete是通过route.search触发的,所以,在示例中,我用了更明确的名字来标识当前组件。看眼示例,您就都明白了。

from rc-bmap.

codepandy avatar codepandy commented on June 19, 2024

嗯,明白了,厉害厉害

from rc-bmap.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.