HERE Maps JS API v3.x - 收听`clusteringend`活动

时间:2015-07-23 21:25:27

标签: javascript maps here-api

有没有方便的方法来判断群集过程是否已完成/结束?我似乎没有看到the clustering provider中我可以收听的任何原生clusteringend事件。

一直是bangin'自从这个问题上的最后几天以来,我的脑袋再次出现。 =(

1 个答案:

答案 0 :(得分:0)

是的,无论如何。我没有等待一些HERE Maps新秀的一些令人失望的回答,而是试图解决我的问题并做出类似的事情(没有彻底测试过,但到目前为止它一直运作得很好):

var
/*
 * Work "listen-to-clusteringend-event-issue" around.
 */
processedNoisePointCounter   = 0,
incrementProcessedNoisePoint = function () {
    processedNoisePointCounter++;

    if (processedNoisePointCounter === dataPoints.length) {
        map.dispatchEvent('clusteringend');
    }
},
clusteredDataProvider        = new H.clustering.Provider([]),
defaultTheme                 = clusteredDataProvider.getTheme(),
customTheme                  = {

    /**
     *
     * @implements {H.clustering.ITheme.getClusterPresentation}
     */
    getClusterPresentation: function (cluster) {
        var clusterMarker = defaultTheme.getClusterPresentation.call(defaultTheme, cluster);

        cluster.forEachEntry(function (entry) {

            if (!entry.isCluster()) {
                incrementProcessedNoisePoint();
            }
        });

        return clusterMarker;
    },

    /**
     *
     * @implements {H.clustering.ITheme.getNoisePresentation}
     */
    getNoisePresentation: function (noisePoint) {
        var noiseMarker = defaultTheme.getNoisePresentation.call(defaultTheme, noisePoint);

        incrementProcessedNoisePoint();

        return noiseMarker;
    }
};

clusteredDataProvider.setTheme(customTheme);
clusteredDataProvider.setDataPoints(dataPoints);

var layer = new H.map.layer.ObjectLayer(clusteredDataProvider);
map.addLayer(layer);

map.addEventListener('clusteringend', function () {
    var message = 'Clustering allegedly ends. ;)';

    console.log(message);
    window.alert(message);
});

JSFiddle可用here