【问题标题】:Add dynamic line using angular2 google maps使用 angular2 谷歌地图添加动态线
【发布时间】:2017-12-02 16:05:44
【问题描述】:

我目前正在使用 https://github.com/SebastianM/angular2-google-maps Angular Google Maps 链接,我的要求是当用户单击按钮时使用 agm-polyline 绘制动态线它放置一个点在具有纬度和经度的地图上,现在我想使用相同的 linee 绘制路径: 我的样本是

app.html

        <button (click)="add()">Add Line</button>
<agm-map [latitude]="lat" [longitude]="lng" [panControl]="true" [usePanning]="true" [rotateControl]="true">
        <agm-marker [latitude]="lat" [longitude]="lng">
        </agm-marker>
      </agm-marker>
              <agm-polyline *ngFor="let data of lines" [editable]="true">
                            <agm-polyline-point
                              [latitude]="data.lat"
                              [longitude]="data.lng">
                            </agm-polyline-point>
              </agm-polyline>
    </agm-map>

app.component.ts

 add() {
console.log('on shape')
this.lines.push({lat: 51.79, lng: 7.8});//creates a point now want to add draw path 

}

它现在使用这个点创建一个点我想画一条线任何帮助将不胜感激

【问题讨论】:

    标签: google-maps angular-google-maps angular2-google-maps


    【解决方案1】:

    您需要将 *ngFor="let data of lines" 放在 agm-polyline-point 中。像这样:-

    <agm-polyline [editable]="true">
        <agm-polyline-point *ngFor="let data of lines" 
            [latitude]="data.lat"
            [longitude]="data.lng">
        </agm-polyline-point>
    </agm-polyline>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-09-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多