首页 > 解决方案 > 在这里返回活动

问题描述

我正在转换为 HERE 地图 API 3.1,但无法在 HERE 中找到与 Google 和 Bing 中存在的相同功能来返回事件。

必应:返回 Microsoft.Maps.Events.addThrottledHandler (_map, 'viewchangeend', callBack, 100); 谷歌:返回 google.maps.event.addListener(_map, 'bounds_changed', callBack);

HERE 中的等价物是什么?

标签: javascripteventshere-api

解决方案


如果您正在寻找 mapviewchange 或 mapviewchangeend 以下事件是信息:

在改变视口状态的过程中,每个动画步骤都会调用 Mapviewchange。在很多情况下,这种操作是过度的。例如,每次用户双击地图时,多次使用当前缩放级别更新 UI 元素是低效的。

// Displays current zoom level to the end user:
function displayZoomLevel() {...}

// A listener updates the map zoom level on each map view change
// -- this occurs more than 20 times on a double-click on the map, 
// inefficient and to be avoided:
map.addEventListener('mapviewchange', function () {
    var zoom = map.getZoom();

    // This function is called more than 20 times on a double-click on the map!
    displayZoomLevel(zoom);
});

另一方面,mapviewchangeend 仅在视口更改完成时调用一次,因此,我们建议使用此事件来更新地图视口:

/

* 
    Displays current zoom level to the end user 
 */
function displayZoomLevel() {...}

// A listener updates the map zoom level -- it is called once when the map 
// view change is complete.
map.addEventListener('mapviewchangeend', function () {
    var zoom = map.getZoom();

    // The function that displays the zoom level is called only once, 
    // after zoom level changed
    displayZoomLevel(zoom);
});

mapviewchangeend 事件是 mapviewchange 的“去抖动”版本,因此,作为一项规则,使用 mapviewchangeend 更有效


推荐阅读