javascript - 当位置(纬度/经度)更改时,缓慢更新 HereMaps DomIcon,重新渲染

标签 javascript reactjs performance here-api

使用 renderToStaticMarkup 将 html 渲染到 HereMaps 中的 DomIcon。当没有那么多标记和更新时,这是有效且快速的。然而,100 个标记频繁更新和重新渲染导致页面打开速度缓慢。它甚至减慢了 map 渲染速度。

我调查过best practices around re-using a DomIcon 。我有also been looking into clustering -- 但不确定更新如何进行。集群是进一步发展的唯一方法吗?好奇是否有任何其他性能最佳实践

最佳答案

聚类解决了潜在的性能问题,但是 H.map.Group 用于将标记关联在一起,并使用 group.getBounds() 方法来查找包含所有组内容的最小边界框。然后可以更新map.viewBounds()。

function addMarkersAndSetViewBounds() {
  // create map objects
  var toronto = new H.map.Marker({lat:43.7,  lng:-79.4}),
      boston = new H.map.Marker({lat:42.35805, lng:-71.0636}),
      washington = new H.map.Marker({lat:38.8951, lng:-77.0366}),
      group = new H.map.Group();

  // add markers to the group
  group.addObjects([toronto, boston, washington]);
  map.addObject(group);

  // get geo bounding box for the group and set it to the map
  map.getViewModel().setLookAtData({
    bounds: group.getBoundingBox()
  });
}

forEachDataPoint(回调)

此方法为给定集群中的每个数据点调用指定的回调,该回调可用于更新数据点。

A clustering algorithm groups data points by collapsing two or more points positioned close to one another on the screen into a single cluster point. All other (not collapsed) points are still visible on map as noise points.

如果这确实适合用例,请选择集群。它有助于提升性能问题。欲了解更多详情,请参阅: developer.here.com/documentation/maps/topics/clustering.html

关于javascript - 当位置(纬度/经度)更改时,缓慢更新 HereMaps DomIcon,重新渲染,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58454206/

相关文章:

javascript - 使用 Vue js 进行 geocomplete -- 位置被删除

javascript - 在 IE 中本地保存 Canvas

javascript - React 中动态创建的元素 - 如何进行控制?

c# - 使用 C# 将数据存储在数据库中的最快方法

javascript - Ng 重复不在 li 内工作弹出窗口

javascript - Angular 中的动态更新无需使用 ng-repeat。可能的? (使用 Firebase)

c++ - 为什么这个 C++ 程序如此之快?

javascript - 加速优化 JavaScript 函数

javascript - 如何从 ANTD.DESIGN 的 RangePicker 获取 startDate 和 endDate

reactjs - Material UI 选择 onChange 在 react 测试库中不起作用