首页 > 解决方案 > 使用从 angular-google-maps agmCircle 到打字稿文件的方法

问题描述

我想在改变时得到一个圆的边界。从这里https://angular-maps.com/api-docs/agm-core/directives/AgmCircle.html我可以看到它有一个“getBounds”方法,我如何从我的打字稿文件访问它来记录这些数据?目前我的 html 圆圈组件如下所示:

<agm-circle [latitude]="lat + 0.3" [longitude]="lng" 
      [radius]="10000"
      [fillColor]="'blue'"
      [circleDraggable]="true"
      [editable]="true"
      (dragEnd)="test($event)"
      >
  </agm-circle>

我希望有这样的功能:

test(m){
   // get bounds from circle in some way
}

标签: angulargoogle-maps

解决方案


只需将其作为 a 添加ViewChild到您的组件中

@ViewChild(AgmCircle) child;

test(m) {
    console.log(this.child.getBounds())
}

推荐阅读