7

How to check if the map tiles are loaded?

I need to know whether all map tiles are loaded on to the OpenLayers map as html contents.... Is there any method to find out or function in openlayers to find out for how much percentage the map tiles are loaded.......

7

see the Layer Load Monitoring sample for some ideas.

layer.events.register("loadend", layer, function() {
  this.logEvent("Load End. Grid:" + this.grid.length + "x" + this.grid[0].length);
});
  • is there a call that would check every layer on the map rather than just one single layer? or do we basically have to monitor each one separately? – Manuel Arredondo Dec 3 '12 at 21:15
  • @ManuelArredondo I can't see any map-level events at dev.openlayers.org/docs/files/OpenLayers/… so I believe you'll need to monitor each layer separately. – Stephen Lead Dec 4 '12 at 0:33
3

In case you see this answer and you were looking for the same thing just in open layers 3 so here is the code you need:

var source = new ol.source.TileJSON({
  url: 'http://api.tiles.mapbox.com/v3/mapbox.world-bright.jsonp',
  crossOrigin: 'anonymous'
});

source.on('tileloadstart', function(event) {
  // do some stuff start loading tiles...
});

source.on('tileloadend', function(event) {
  // do some stuff tiles were loaded...
});
source.on('tileloaderror', function(event) {
  // eject :(
});

var map = new ol.Map({
  logo: false,
  layers: [
    new ol.layer.Tile({source: source})
  ],
  renderer: exampleNS.getRendererFromQueryString(),
  target: 'map',
  view: new ol.View({
    center: [0, 0],
    zoom: 2
  })
});

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.