[OpenLayers-Commits] r3605 - in sandbox/euzuro/untiled3: examples lib/OpenLayers/Layer
commits at openlayers.org
commits at openlayers.org
Thu Jul 5 18:55:02 EDT 2007
Author: euzuro
Date: 2007-07-05 18:55:01 -0400 (Thu, 05 Jul 2007)
New Revision: 3605
Added:
sandbox/euzuro/untiled3/examples/layerLoadMonitoring.html
Modified:
sandbox/euzuro/untiled3/lib/OpenLayers/Layer/Grid.js
Log:
use the tile events to register when a grid layer starts and stops loading
Added: sandbox/euzuro/untiled3/examples/layerLoadMonitoring.html
===================================================================
--- sandbox/euzuro/untiled3/examples/layerLoadMonitoring.html (rev 0)
+++ sandbox/euzuro/untiled3/examples/layerLoadMonitoring.html 2007-07-05 22:55:01 UTC (rev 3605)
@@ -0,0 +1,45 @@
+<html xmlns="http://www.w3.org/1999/xhtml">
+ <head>
+ <style type="text/css">
+ #map {
+ width: 800px;
+ height: 475px;
+ border: 1px solid black;
+ }
+ </style>
+ <script src="../lib/Firebug/firebug.js"></script>
+ <script src="../lib/OpenLayers.js"></script>
+ <script type="text/javascript">
+ <!--
+ var lon = 5;
+ var lat = 40;
+ var zoom = 5;
+ var map, layer;
+
+ function init(){
+ map = new OpenLayers.Map( 'map' );
+ layer = new OpenLayers.Layer.WMS( "OpenLayers WMS",
+ "http://labs.metacarta.com/wms/vmap0",
+ {layers: 'basic'} ,
+ { singleTile: false, buffer:0}
+ );
+
+ layer.events.register("loadstart", this, function() {
+ OpenLayers.Console.log("loadstart!");
+ });
+
+ layer.events.register("loadend", this, function() {
+ OpenLayers.Console.log("loadend!");
+ });
+
+
+ map.addLayer(layer);
+ map.setCenter(new OpenLayers.LonLat(lon, lat), zoom);
+ }
+ // -->
+ </script>
+ </head>
+ <body onload="init()">
+ <div id="map"></div>
+ </body>
+</html>
Modified: sandbox/euzuro/untiled3/lib/OpenLayers/Layer/Grid.js
===================================================================
--- sandbox/euzuro/untiled3/lib/OpenLayers/Layer/Grid.js 2007-07-05 22:34:02 UTC (rev 3604)
+++ sandbox/euzuro/untiled3/lib/OpenLayers/Layer/Grid.js 2007-07-05 22:55:01 UTC (rev 3605)
@@ -44,6 +44,12 @@
buffer: 2,
/**
+ * APIProperty: numLoadingTiles
+ * {Integer} How many tiles are still loading?
+ */
+ numLoadingTiles: 0,
+
+ /**
* Constructor: OpenLayers.Layer.Grid
* Create a new grid layer
*
@@ -251,12 +257,63 @@
var tile = this.grid[0][0];
if (!tile) {
tile = this.addTile(tileBounds, px);
+
+ this.addTileMonitoringHooks(tile);
tile.draw();
this.grid[0][0] = tile;
} else {
tile.moveTo(tileBounds, px);
}
},
+
+ /**
+ * Method: addTileMonitoringHooks
+ * This function takes a tile as input and adds the appropriate hooks to
+ * the tile so that the layer can keep track of the loading tiles.
+ *
+ * Parameters:
+ * tile - {<OpenLayers.Tile>}
+ */
+ addTileMonitoringHooks: function(tile) {
+
+ var onLoadStart = function() {
+
+ if (!tile.reloading) {
+
+ //if there are no tiles loading then trigger a 'loadstart'
+ // event on the layer
+ if (this.numLoadingTiles == 0) {
+ this.events.triggerEvent("loadstart");
+ }
+
+ this.numLoadingTiles++;
+ }
+ };
+ tile.events.register("loadstart",
+ this,
+ onLoadStart.bindAsEventListener(this));
+
+
+ var onReload = function() {
+ //mark the tile as reloading. This is a flag that is checked for
+ // in the 'loadstart' handler.
+ tile.reloading = true;
+ };
+ tile.events.register("reload",
+ this,
+ onReload.bindAsEventListener(this));
+
+ var onLoadEnd = function() {
+ this.numLoadingTiles--;
+ if (this.numLoadingTiles == 0) {
+ this.events.triggerEvent("loadend");
+ }
+ };
+ tile.events.register("loadend",
+ this,
+ onLoadEnd.bindAsEventListener(this));
+ },
+
/**
* Method: initGriddedTiles
@@ -327,6 +384,7 @@
var tile = row[colidx++];
if (!tile) {
tile = this.addTile(tileBounds, px);
+ this.addTileMonitoringHooks(tile);
row.push(tile);
} else {
tile.moveTo(tileBounds, px, false);
More information about the Commits
mailing list