简体   繁体   English

地图花费过多时间在使用角和AGM进行首次加载时进行渲染

[英]Map takes too much time to render on first load with angular and AGM

I am using Angualr 5 with AGM Angular Google Maps and using *ngFor to update the maps pins when datasource updated The problem is the screen freezes once the data is loaded (420 point) and stays for 30 seconds then works with the points rendered 我将Angualr 5与AGM Angular Google Maps一起使用,并使用* ngFor在数据源更新时更新地图图钉。问题是,一旦加载数据(420点)并冻结30秒,屏幕就会冻结,然后处理渲染的点

HTML: HTML:

<agm-marker  *ngFor="let point of points; trackBy: trackByFn" class="point"  [latitude]="point.lat" [longitude] ="point.long" >
            <agm-info-window>Name: {{point.Title}} <br/> Address: {{point.Desc}} </agm-info-window>
    </agm-marker>

as: 如:

trackByFn(index, point)  {
    console.log(point);
    return point ? point.title : undefined;
  }

updatePoints(newPoints:Array<mapDto>)
{
    this.points = new Array<mapDto>();
    this.points = newPoints;
}

I'm not sure if this is causing this problem, maybe not, but trackByFn should return something unique. 我不确定这是否会导致此问题,但trackByFn应该返回唯一的东西。 So unless you can be sure that all items have a unique title, don't use it. 因此,除非您可以确定所有项目都具有唯一标题,否则请不要使用它。 Or maybe try some composite of lat+long+title? 或者尝试使用经纬度+标题+标题组合?

One possible bottleneck is an agm-info-window inside every marker. 每个标记内的agm-info-window可能是瓶颈。 It also works standalone, try taking it out and having just one of those. 它也可以独立运行,尝试将其取出并仅使用其中之一。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM