我当前正在使用 https://github.com/sebastianm/angular2-google-maps angular Google Map链接,我的要求是绘制动态线使用 AGM-POLYLINE 当用户单击按钮时,它在地图上放置了纬度和经度的点,现在我想使用相同的行绘制路径:我的样本是
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
}
现在使用这一点创造了一个点,我想绘制一行任何帮助,将不胜感激
您需要在AGM-Polyline点内放置 *ngfor =" LET LINE的数据"。这样: -
<agm-polyline [editable]="true">
<agm-polyline-point *ngFor="let data of lines"
[latitude]="data.lat"
[longitude]="data.lng">
</agm-polyline-point>
</agm-polyline>