我是Angular和Openlayers的新手(3)。所以基本上我想做的是使用存储在数组中的对象显示路由。但是问题出在我从数组中删除对象之后,它会触发错误
ERROR TypeError:无法读取未定义的属性'forEach'
如果我在aol功能之外单独显示对象,则没有错误,因此我确定在openlayers中所做的操作有问题。
this.xx = this.broadCastService.events.subscribe((ev) =>{
this.configService.getConfig3(ev[0],ev[1]).subscribe((e: LineVariantTrack) =>{
if(ev[2]==true){
this.line.push(e);
console.log(this.line);
}
else{
this.line.splice(this.line.findIndex(el => el.lineVariantNumber==e.lineVariantNumber),1);
console.log(this.line);
}
});
});
<div *ngFor="let l of line">
ERROR HERE<aol-feature *ngFor="let s of l?.segments ;let i=index" [id]="i">
<aol-geometry-linestring>
<aol-collection-coordinates [coordinates]="[[s?.from?.position?.longitude || s?.to?.position?.longitude, s?.from?.position?.latitude || s?.to?.position?.latitude],[s?.to?.position?.longitude || s?.from?.position?.longitude, s?.to?.position?.latitude || s?.from?.position?.latitude]]"
[srid]="'EPSG:4326'">
</aol-collection-coordinates>
</aol-geometry-linestring>
<aol-style>
<aol-style-stroke [width]="5" [color]="'blue'"></aol-style-stroke>
</aol-style>
</aol-feature>
</div>