Document createTile async mode

This commit is contained in:
Iván Sánchez Ortega 2015-08-11 10:04:21 +02:00
parent 2290aa317c
commit 485c1987f0

View File

@ -3373,9 +3373,10 @@ map.fitBounds(bounds);</code></pre>
<h3>Asyncronous usage example</h3> <h3>Asyncronous usage example</h3>
<p>Tile creation can also be asyncronous, this is useful when using a third-party drawing library. Once the tile is finsihed drawing it can be passed to the <code>done()</code> callback.</p> <p>Tile creation can also be asyncronous, this is useful when using a third-party drawing library. Once the tile has finished drawing it must be passed to the <code>done()</code> callback.</p>
<pre><code class="javascript">var CanvasLayer = L.GridLayer.extend({ <pre><code class="javascript">var CanvasLayer = L.GridLayer.extend({
// createTile has a 'done' parameter when on async mode
createTile: function(coords, done){ createTile: function(coords, done){
var error; var error;
@ -3387,8 +3388,14 @@ map.fitBounds(bounds);</code></pre>
tile.width = size.x; tile.width = size.x;
tile.height = size.y; tile.height = size.y;
// draw something and pass the tile to the done() callback // For this example simply wait one second before tile is ready
done(error, tile); window.setTimeout(function(){
// draw something and pass the tile to the done() callback
done(error, tile);
}, 1000);
// return the tile so its progress can be tracked
return tile;
} }
});</code></pre> });</code></pre>