OpenLayers 3捕获tile加载的事件

kli*_*.ch 5 gis events event-handling openlayers openlayers-3

如何在OpenLayers 3中捕获tile加载的事件?在OpenLayers 2中,这可以通过从地图的底层捕获"loadend"事件来完成:

map.baseLayer.events.register('loadend' , false, function(){  });
Run Code Online (Sandbox Code Playgroud)

Joh*_*bos 6

tileloadstarttileloadendtileloaderror事件可以订阅以来的OpenLayers V3.3瓦来源。

您可以使用类似于以下内容的东西:

var tilesLoading = 0,
    tilesLoaded = 0;

tileLayer.getSource().on('tileloadend', function () {
    tilesLoaded++;
    if (tilesLoading === tilesLoaded) {
        console.log(tilesLoaded + ' tiles finished loading');
        tilesLoading = 0;
        tilesLoaded = 0;
        //trigger another event, do something etc...
    }
});

tileLayer.getSource().on('tileloadstart', function () {
    this.tilesLoading++;
});
Run Code Online (Sandbox Code Playgroud)


Pou*_*sen 1

您现在可以通过以下方式将其连接起来,直到将某些内容添加到核心中为止。

tileSource.setTileLoadFunction(( function(){
        var numLoadingTiles = 0;
        var tileLoadFn = tileSource.getTileLoadFunction();
        return (tile, src) => {
            console.log(src);
            if (numLoadingTiles === 0) {
                console.log('loading');
            }
            ++numLoadingTiles;
            var image = tile.getImage();

            image.onload = image.onerror =  function(){
                --numLoadingTiles;
                if (numLoadingTiles === 0) {
                    console.log('idle');
                }
            };
            tileLoadFn(tile, src);
        };
    })()); 
Run Code Online (Sandbox Code Playgroud)

您可以在此处查看可用于此的所有图块源类: http://openlayers.org/en/v3.4.0/apidoc/ol.source.TileImage.html ?unstable=true#setTileLoadFunction