[OpenLayers-Commits] r7479 - in sandbox/vector-behavior: examples lib lib/OpenLayers lib/OpenLayers/Strategy

commits at openlayers.org commits at openlayers.org
Tue Jul 8 16:08:47 EDT 2008


Author: elemoine
Date: 2008-07-08 16:08:47 -0400 (Tue, 08 Jul 2008)
New Revision: 7479

Added:
   sandbox/vector-behavior/examples/strategy-grid.html
   sandbox/vector-behavior/lib/OpenLayers/Grid.js
   sandbox/vector-behavior/lib/OpenLayers/Strategy/Grid.js
Modified:
   sandbox/vector-behavior/lib/OpenLayers.js
Log:
Add Grid Strategy. With this strategy features are added and removed as the map moves. The grid-related code has been taken from Layer.Grid and isolated in a specific class (OpenLayers.Grid); ultimately Layer.Grid should rely on that class so that we share code. One current limitation of this strategy is that it doesn't support features spanning multiple grid cells.


Added: sandbox/vector-behavior/examples/strategy-grid.html
===================================================================
--- sandbox/vector-behavior/examples/strategy-grid.html	                        (rev 0)
+++ sandbox/vector-behavior/examples/strategy-grid.html	2008-07-08 20:08:47 UTC (rev 7479)
@@ -0,0 +1,71 @@
+<html xmlns="http://www.w3.org/1999/xhtml">
+    <head>
+        <title>OpenLayers Grid Strategy Example</title>
+        <link rel="stylesheet" href="../theme/default/style.css" type="text/css" />
+        <link rel="stylesheet" href="style.css" type="text/css" />
+        <style type="text/css">
+            #map {
+                width: 511px;
+                height: 256px;
+            }
+        </style>
+        <script src="../lib/OpenLayers.js"></script>
+        <script type="text/javascript">
+            var map;
+            OpenLayers.ProxyHost = (window.location.host == "localhost") ?
+                "/cgi-bin/proxy.cgi?url=" : "proxy?url=";
+
+            function init() {
+                map = new OpenLayers.Map('map', {
+                    maxExtent: new OpenLayers.Bounds(-180, -90, 180, 90),
+                    restrictedExtent: new OpenLayers.Bounds(-180, -90, 180, 90)
+                });
+
+                var base = new OpenLayers.Layer.WMS("OpenLayers WMS", 
+                    ["http://t3.labs.metacarta.com/wms-c/Basic.py",
+                     "http://t2.labs.metacarta.com/wms-c/Basic.py",
+                     "http://t1.labs.metacarta.com/wms-c/Basic.py"], 
+                    {layers: 'satellite', buffer: 0}
+                );
+
+                var layer = new OpenLayers.Layer.Vector("Owl Survey", {
+                    strategies: [
+                        new OpenLayers.Strategy.Grid({
+                            buffer: 0,
+                            tileSize: new OpenLayers.Size(256, 256)
+                        })
+                    ],
+                    protocol: new OpenLayers.Protocol.HTTP({
+                        url: "http://www.bsc-eoc.org/cgi-bin/bsc_ows.asp?",
+                        params: {
+                            format: "WFS",
+                            service: "WFS",
+                            version: "1.0.0",
+                            request: "GetFeature",
+                            srs: "EPSG:4326",
+                            maxfeatures: 10,
+                            typename: "OWLS"
+                        }
+                    }),
+                    format: new OpenLayers.Format.GML()
+                });
+
+                map.addLayers([base, layer]);
+                map.zoomToExtent(new OpenLayers.Bounds(
+                    -90.0244140625, 40.48828125, -67.5244140625, 51.73828125
+                ));
+            }
+        </script>
+    </head>
+    <body onload="init()">
+        <h1 id="title">Grid Strategy Example</h1>
+        <p id="shortdesc">
+            Uses a Grid strategy to add and remove feaures as the map is moved.
+        </p>
+        <div id="map" class="smallmap"></div>
+        <div id="docs">
+            <p>
+            </p>
+        </div>
+    </body>
+</html>

Added: sandbox/vector-behavior/lib/OpenLayers/Grid.js
===================================================================
--- sandbox/vector-behavior/lib/OpenLayers/Grid.js	                        (rev 0)
+++ sandbox/vector-behavior/lib/OpenLayers/Grid.js	2008-07-08 20:08:47 UTC (rev 7479)
@@ -0,0 +1,527 @@
+/* Copyright (c) 2006-2008 MetaCarta, Inc., published under the Clear BSD
+ * license.  See http://svn.openlayers.org/trunk/openlayers/license.txt for the
+ * full text of the license. */
+
+/**
+ * Class: OpenLayers.Grid
+ */
+OpenLayers.Grid = OpenLayers.Class({
+
+    /**
+     * APIProperty: map
+     * {<OpenLayers.map>}
+     */
+    map: null,
+
+    /**
+     * APIProperty: createTile
+     * {Function} Function returning a {<OpenLayers.Tile>} object.
+     */
+    createTile: null,
+
+    /**
+     * APIProperty: tileSize
+     * {<OpenLayers.Size>} Size object representing the tile size.
+     */
+    tileSize: null,
+    
+    /**
+     * APIProperty: buffer
+     * {Integer} Number of extra rows and columns of tiles on each side which
+     *      will surround the minimum grid tiles to cover the map.
+     */
+    buffer: 2,
+
+    /**
+     * APIProperty: maxExtent
+     * {<OpenLayers.Bounds>} The max extent used to calculate the grid.
+     */
+    maxExtent: null,
+
+    /**
+     * Property: grid
+     * {Array(Array(<OpenLayers.Tile>))} This is an array of rows, each row
+     *      is an array of tiles.
+     */
+    grid: null,
+
+    /**
+     * Constructor: OpenLayers.Grid
+     *      Create a new grid.
+     *
+     * Parameters:
+     * options - {Object} The API properties are set through this object.
+     */
+    initialize: function(options) {
+        this.grid = [];
+        OpenLayers.Util.extend(this, options);
+    },
+
+    /**
+     * APIMethod: destroy
+     *      Destroy the grid.
+     */
+    destroy: function() {
+        this.clearGrid();
+        this.map = null;
+        this.grid = null;
+        this.tileSize = null;
+    },
+
+    /**
+     * Method: clearGrid
+     *      Go through and remove all tiles from the grid, calling
+     *      destroy() on each of them.
+     */
+    clearGrid: function() {
+        if (this.grid) {
+            for(var i = 0; i < this.grid.length; i++) {
+                var row = this.grid[i];
+                for(var j = 0; j < row.length; j++) {
+                    var tile = row[j];
+                    //this.removeTileMonitoringHooks(tile); FIXME
+                    tile.destroy();
+                }
+            }
+            this.grid = [];
+        }
+    },
+
+    /**
+     * APIMethod: moveTo
+     *      Move the grid to the bounds passed as the first argument.
+     *
+     * Parameters:
+     * bounds - {<OpenLayers.Bounds>}
+     * force - {Boolean}
+     */
+    moveTo: function(bounds, force) {
+        bounds = bounds || this.map.getExtent();
+        if (bounds != null) {
+            var retile = force ||
+                         this.grid.length == 0 ||
+                         !this.getBounds().containsBounds(bounds, true);
+            if (retile) {
+                this.initGrid(bounds);
+            } else {
+                this.moveGrid(bounds);
+            }
+        }
+    },
+
+    /**
+     * Method: getBounds
+     *      Return the bounds of the tile grid.
+     *
+     * Returns:
+     * {<OpenLayers.Bounds>} A Bounds object representing the bounds of
+     *      the grid.
+     */
+    getBounds: function() {    
+        var bounds = null; 
+        if (this.grid.length > 0) {
+
+            var bottom = this.grid.length - 1;
+            var bottomLeftTile = this.grid[bottom][0];
+            var right = this.grid[0].length - 1; 
+            var topRightTile = this.grid[0][right];
+
+            bounds = new OpenLayers.Bounds(
+                bottomLeftTile.bounds.left, 
+                bottomLeftTile.bounds.bottom,
+                topRightTile.bounds.right, 
+                topRightTile.bounds.top
+            );
+        }   
+        return bounds;
+    },
+
+    /** 
+     * Method: calculateGridLayout
+     * Generate parameters for the grid layout. This  
+     *
+     * Parameters:
+     * bounds - {<OpenLayers.Bound>}
+     * extent - {<OpenLayers.Bounds>}
+     * resolution - {Number}
+     *
+     * Returns:
+     * Object containing properties tilelon, tilelat, tileoffsetlat,
+     * tileoffsetlat, tileoffsetx, tileoffsety
+     */
+    calculateGridLayout: function(bounds, extent, resolution) {
+        var tilelon = resolution * this.tileSize.w;
+        var tilelat = resolution * this.tileSize.h;
+        
+        var offsetlon = bounds.left - extent.left;
+        var tilecol = Math.floor(offsetlon/tilelon) - this.buffer;
+        var tilecolremain = offsetlon/tilelon - tilecol;
+        var tileoffsetx = -tilecolremain * this.tileSize.w;
+        var tileoffsetlon = extent.left + tilecol * tilelon;
+        
+        var offsetlat = bounds.top - (extent.bottom + tilelat);  
+        var tilerow = Math.ceil(offsetlat/tilelat) + this.buffer;
+        var tilerowremain = tilerow - offsetlat/tilelat;
+        var tileoffsety = -tilerowremain * this.tileSize.h;
+        var tileoffsetlat = extent.bottom + tilerow * tilelat;
+        
+        return { 
+          tilelon: tilelon,
+          tilelat: tilelat,
+          tileoffsetlon: tileoffsetlon,
+          tileoffsetlat: tileoffsetlat,
+          tileoffsetx: tileoffsetx,
+          tileoffsety: tileoffsety
+        };
+    },
+
+    /**
+     * Method: initGrid
+     * 
+     * Parameters:
+     * bounds - {<OpenLayers.Bounds>}
+     */
+    initGrid: function(bounds) {
+        
+        // work out mininum number of rows and columns; this is the number of
+        // tiles required to cover the viewport plus at least one for panning
+
+        var viewSize = this.map.getSize();
+        var minRows = Math.ceil(viewSize.h/this.tileSize.h) + 
+                      Math.max(1, 2 * this.buffer);
+        var minCols = Math.ceil(viewSize.w/this.tileSize.w) +
+                      Math.max(1, 2 * this.buffer);
+        
+        var extent = this.maxExtent;
+        var resolution = this.map.getResolution();
+        
+        var tileLayout = this.calculateGridLayout(bounds, extent, resolution);
+
+        var tileoffsetx = Math.round(tileLayout.tileoffsetx); // heaven help us
+        var tileoffsety = Math.round(tileLayout.tileoffsety);
+
+        var tileoffsetlon = tileLayout.tileoffsetlon;
+        var tileoffsetlat = tileLayout.tileoffsetlat;
+        
+        var tilelon = tileLayout.tilelon;
+        var tilelat = tileLayout.tilelat;
+
+        this.origin = new OpenLayers.Pixel(tileoffsetx, tileoffsety);
+
+        var startX = tileoffsetx; 
+        var startLon = tileoffsetlon;
+
+        var rowidx = 0;
+        
+        var layerContainerDivLeft = parseInt(this.map.layerContainerDiv.style.left);
+        var layerContainerDivTop = parseInt(this.map.layerContainerDiv.style.top);
+        
+        do {
+            var row = this.grid[rowidx++];
+            if (!row) {
+                row = [];
+                this.grid.push(row);
+            }
+
+            tileoffsetlon = startLon;
+            tileoffsetx = startX;
+            var colidx = 0;
+ 
+            do {
+                var tileBounds = 
+                    new OpenLayers.Bounds(tileoffsetlon, 
+                                          tileoffsetlat, 
+                                          tileoffsetlon + tilelon,
+                                          tileoffsetlat + tilelat);
+
+                var x = tileoffsetx;
+                x -= layerContainerDivLeft;
+
+                var y = tileoffsety;
+                y -= layerContainerDivTop;
+
+                var px = new OpenLayers.Pixel(x, y);
+                var tile = row[colidx++];
+                if (!tile) {
+                    tile = this.createTile(tileBounds, px);
+                    //this.addTileMonitoringHooks(tile); FIXME
+                    row.push(tile);
+                } else {
+                    tile.moveTo(tileBounds, px, false);
+                }
+     
+                tileoffsetlon += tilelon;       
+                tileoffsetx += this.tileSize.w;
+            } while ((tileoffsetlon <= bounds.right + tilelon * this.buffer)
+                     || colidx < minCols)  
+             
+            tileoffsetlat -= tilelat;
+            tileoffsety += this.tileSize.h;
+        } while((tileoffsetlat >= bounds.bottom - tilelat * this.buffer)
+                || rowidx < minRows)
+        
+        //shave off exceess rows and colums
+        this.removeExcessTiles(rowidx, colidx);
+
+        //now actually draw the tiles
+        this.spiralTileLoad();
+    },
+    
+    /**
+     * Method: spiralTileLoad
+     *   Starts at the top right corner of the grid and proceeds in a spiral 
+     *    towards the center, adding tiles one at a time to the beginning of a 
+     *    queue. 
+     * 
+     *   Once all the grid's tiles have been added to the queue, we go back 
+     *    and iterate through the queue (thus reversing the spiral order from 
+     *    outside-in to inside-out), calling draw() on each tile. 
+     */
+    spiralTileLoad: function() {
+        var tileQueue = [];
+ 
+        var directions = ["right", "down", "left", "up"];
+
+        var iRow = 0;
+        var iCell = -1;
+        var direction = OpenLayers.Util.indexOf(directions, "right");
+        var directionsTried = 0;
+        
+        while (directionsTried < directions.length) {
+
+            var testRow = iRow;
+            var testCell = iCell;
+
+            switch (directions[direction]) {
+                case "right":
+                    testCell++;
+                    break;
+                case "down":
+                    testRow++;
+                    break;
+                case "left":
+                    testCell--;
+                    break;
+                case "up":
+                    testRow--;
+                    break;
+            } 
+    
+            // if the test grid coordinates are within the bounds of the 
+            //  grid, get a reference to the tile.
+            var tile = null;
+            if ((testRow < this.grid.length) && (testRow >= 0) &&
+                (testCell < this.grid[0].length) && (testCell >= 0)) {
+                tile = this.grid[testRow][testCell];
+            }
+            
+            if ((tile != null) && (!tile.queued)) {
+                //add tile to beginning of queue, mark it as queued.
+                tileQueue.unshift(tile);
+                tile.queued = true;
+                
+                //restart the directions counter and take on the new coords
+                directionsTried = 0;
+                iRow = testRow;
+                iCell = testCell;
+            } else {
+                //need to try to load a tile in a different direction
+                direction = (direction + 1) % 4;
+                directionsTried++;
+            }
+        } 
+        
+        // now we go through and draw the tiles in forward order
+        for(var i = 0; i < tileQueue.length; i++) {
+            var tile = tileQueue[i];
+            tile.draw();
+            //mark tile as unqueued for the next time (since tiles are reused)
+            tile.queued = false;       
+        }
+    },
+    
+    /** 
+     * 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>}
+     */
+    /* FIXME
+    addTileMonitoringHooks: function(tile) {
+        
+        tile.onLoadStart = function() {
+            //if that was first tile then trigger a 'loadstart' on the layer
+            if (this.numLoadingTiles == 0) {
+                this.events.triggerEvent("loadstart");
+            }
+            this.numLoadingTiles++;
+        };
+        tile.events.register("loadstart", this, tile.onLoadStart);
+      
+        tile.onLoadEnd = function() {
+            this.numLoadingTiles--;
+            this.events.triggerEvent("tileloaded");
+            //if that was the last tile, then trigger a 'loadend' on the layer
+            if (this.numLoadingTiles == 0) {
+                this.events.triggerEvent("loadend");
+            }
+        };
+        tile.events.register("loadend", this, tile.onLoadEnd);
+        tile.events.register("unload", this, tile.onLoadEnd);
+    },
+    */
+
+    /** 
+     * Method: removeTileMonitoringHooks
+     * This function takes a tile as input and removes the tile hooks 
+     *     that were added in addTileMonitoringHooks()
+     * 
+     * Parameters: 
+     * tile - {<OpenLayers.Tile>}
+     */
+    /* FIXME
+    removeTileMonitoringHooks: function(tile) {
+        tile.unload();
+        tile.events.un({
+            "loadstart": tile.onLoadStart,
+            "loadend": tile.onLoadEnd,
+            "unload": tile.onLoadEnd,
+            scope: this
+        });
+    },
+    */
+    
+    /**
+     * Method: moveGrid
+     * 
+     * Parameters:
+     * bounds - {<OpenLayers.Bounds>}
+     */
+    moveGrid: function(bounds) {
+        var buffer = this.buffer || 1;
+        while (true) {
+            var tlLayer = this.grid[0][0].position;
+            var tlViewPort = 
+                this.map.getViewPortPxFromLayerPx(tlLayer);
+            if (tlViewPort.x > -this.tileSize.w * (buffer - 1)) {
+                this.shiftColumn(true);
+            } else if (tlViewPort.x < -this.tileSize.w * buffer) {
+                this.shiftColumn(false);
+            } else if (tlViewPort.y > -this.tileSize.h * (buffer - 1)) {
+                this.shiftRow(true);
+            } else if (tlViewPort.y < -this.tileSize.h * buffer) {
+                this.shiftRow(false);
+            } else {
+                break;
+            }
+        };
+    },
+
+    /**
+     * Method: shiftRow
+     * Shifty grid work
+     *
+     * Parameters:
+     * prepend - {Boolean} if true, prepend to beginning.
+     *                          if false, then append to end
+     */
+    shiftRow:function(prepend) {
+        var modelRowIndex = (prepend) ? 0 : (this.grid.length - 1);
+        var grid = this.grid;
+        var modelRow = grid[modelRowIndex];
+
+        var resolution = this.map.getResolution();
+        var deltaY = (prepend) ? -this.tileSize.h : this.tileSize.h;
+        var deltaLat = resolution * -deltaY;
+
+        var row = (prepend) ? grid.pop() : grid.shift();
+
+        for (var i=0; i < modelRow.length; i++) {
+            var modelTile = modelRow[i];
+            var bounds = modelTile.bounds.clone();
+            var position = modelTile.position.clone();
+            bounds.bottom = bounds.bottom + deltaLat;
+            bounds.top = bounds.top + deltaLat;
+            position.y = position.y + deltaY;
+            row[i].moveTo(bounds, position);
+        }
+
+        if (prepend) {
+            grid.unshift(row);
+        } else {
+            grid.push(row);
+        }
+    },
+
+    /**
+     * Method: shiftColumn
+     * Shift grid work in the other dimension
+     *
+     * Parameters:
+     * prepend - {Boolean} if true, prepend to beginning.
+     *                          if false, then append to end
+     */
+    shiftColumn: function(prepend) {
+        var deltaX = (prepend) ? -this.tileSize.w : this.tileSize.w;
+        var resolution = this.map.getResolution();
+        var deltaLon = resolution * deltaX;
+
+        for (var i=0; i<this.grid.length; i++) {
+            var row = this.grid[i];
+            var modelTileIndex = (prepend) ? 0 : (row.length - 1);
+            var modelTile = row[modelTileIndex];
+            
+            var bounds = modelTile.bounds.clone();
+            var position = modelTile.position.clone();
+            bounds.left = bounds.left + deltaLon;
+            bounds.right = bounds.right + deltaLon;
+            position.x = position.x + deltaX;
+
+            var tile = prepend ? this.grid[i].pop() : this.grid[i].shift();
+            tile.moveTo(bounds, position);
+            if (prepend) {
+                row.unshift(tile);
+            } else {
+                row.push(tile);
+            }
+        }
+    },
+    
+    /**
+     * Method: removeExcessTiles
+     * When the size of the map or the buffer changes, we may need to
+     *     remove some excess rows and columns.
+     *
+     *     FIXME need to figure this one out
+     * 
+     * Parameters:
+     * rows - {Integer} Maximum number of rows we want our grid to have.
+     * colums - {Integer} Maximum number of columns we want our grid to have.
+     */
+    removeExcessTiles: function(rows, columns) {
+        
+        // remove extra rows
+        while (this.grid.length > rows) {
+            var row = this.grid.pop();
+            for (var i = 0, l=row.length; i < l; i++) {
+                var tile = row[i];
+                //this.removeTileMonitoringHooks(tile); FIXME
+                tile.destroy();
+            }
+        }
+        
+        // remove extra columns
+        while (this.grid[0].length > columns) {
+            for (var i = 0, l=this.grid.length; i < l; i++) {
+                var row = this.grid[i];
+                var tile = row.pop();
+                //this.removeTileMonitoringHooks(tile); FIXME
+                tile.destroy();
+            }
+        }
+    },
+
+    CLASS_NAME: "OpenLayers.Grid"
+});

Added: sandbox/vector-behavior/lib/OpenLayers/Strategy/Grid.js
===================================================================
--- sandbox/vector-behavior/lib/OpenLayers/Strategy/Grid.js	                        (rev 0)
+++ sandbox/vector-behavior/lib/OpenLayers/Strategy/Grid.js	2008-07-08 20:08:47 UTC (rev 7479)
@@ -0,0 +1,212 @@
+/**
+ * @requires OpenLayers/Strategy.js
+ */
+
+/**
+ * Class: OpenLayers.Strategy.Grid
+ * This strategy works with a grid of features, adding and removing features
+ * as the map is moved.
+ *
+ * Inherits from:
+ *  - OpenLayers.Strategy
+ */
+OpenLayers.Strategy.Grid = new OpenLayers.Class(OpenLayers.Strategy, {
+
+    /**
+     * Property: grid
+     * {<OpenLayers.Grid>} Grid object.
+     */
+    grid: null,
+
+    /**
+     * Property: buffer
+     * {Integer}
+     */
+    buffer: null,
+
+    /**
+     * Property: tileSize
+     * {<OpenLayers.Size>}
+     */
+    tileSize: null,
+
+    /**
+     * Class: tileClass
+     * Inner class to represent tiles
+     */
+    tileClass: OpenLayers.Class({
+        /**
+         */
+        bounds: null,
+
+        /**
+         */
+        position: null,
+
+        /**
+         */
+        strategy: null,
+
+        /**
+         */
+        features: null,
+
+        /**
+         */
+        initialize: function(options) {
+            this.features = [];
+            OpenLayers.Util.extend(this, options);
+        },
+
+        /**
+         */
+        destroy: function() {
+            this.destroyFeatures();
+            this.bounds = null;
+            this.position = null;
+            this.strategy = null;
+            this.features = null;
+        },
+
+        /**
+         */
+        destroyFeatures: function() {
+            if (this.features.length > 0) {
+                this.strategy.layer.destroyFeatures(this.features);
+            }
+            this.features = [];
+        },
+
+        /**
+         */
+        moveTo: function(bounds, position) {
+            this.bounds = bounds;
+            this.position = position;
+            this.draw();
+        },
+
+        /**
+         */
+        draw: function() {
+            this.destroyFeatures();
+            this.requestFeatures(
+                this.createFilter(),
+                function(resp) {
+                    if (resp.code == OpenLayers.Protocol.Response.SUCCESS) {
+                        this.features = resp.features;
+                        this.strategy.layer.addFeatures(this.features);
+                    } else {
+                        // FIXME
+                    }
+                },
+                this
+            );
+        },
+
+        /**
+         */
+        createFilter: function() {
+            // create a BBOX spatial filter
+            var filter = new OpenLayers.Filter.Spatial({
+                type: OpenLayers.Filter.Spatial.BBOX,
+                value: new OpenLayers.Geometry.Rectangle(
+                    this.bounds.left,
+                    this.bounds.bottom,
+                    this.bounds.right - this.bounds.left,
+                    this.bounds.top - this.bounds.bottom
+                ),
+                projection: this.strategy.layer.projection
+            });
+            return filter;
+        },
+
+        /**
+         */
+        requestFeatures: function(filter, callback, scope) {
+            this.strategy.layer.protocol.read({
+                filter: filter,
+                callback: callback,
+                scope: scope
+            });
+        }
+    }),
+
+    /**
+     * Constructor: OpenLayers.Strategy.Grid
+     * Create a new Grid strategy.
+     *
+     * Parameters:
+     * options - {Object} Optional object whose properties will be set on the
+     *     instance.
+     */
+    initialize: function(options) {
+        OpenLayers.Strategy.prototype.initialize.apply(this, [options]);
+    },
+
+    /**
+     * Method: activate
+     * Set up strategy with regard to reading new batches of remote data.
+     */
+    activate: function() {
+        // define function for creating tiles
+        var createTile = OpenLayers.Function.bind(
+            function(bounds, position) {
+                return new this.tileClass({
+                    bounds: bounds,
+                    position: position,
+                    strategy: this
+                });
+            },
+            this
+        );
+        // define grid
+        this.grid = new OpenLayers.Grid({
+            map: this.layer.map,
+            maxExtent: this.layer.maxExtent,
+            buffer: this.buffer,
+            tileSize: this.tileSize,
+            createTile: createTile
+        });
+        // register event listeners
+        this.layer.map.events.on({
+            "moveend": this.refresh,
+            scope: this
+        });
+        this.layer.events.on({
+            "refresh": this.refresh,
+            scope: this
+        });
+    },
+    
+    /**
+     * Method: deactivate
+     * Tear down strategy with regard to reading new batches of remote data.
+     */
+    deactivate: function() {
+        // unregister event listeners
+        this.layer.map.events.un({
+            "moveend": this.updateListener,
+            scope: this
+        });
+        this.layer.events.un({
+            "refresh": this.updateListener,
+            scope: this
+        });
+        // destroy grid
+        this.grid.destroy();
+        this.grid = null;
+    },
+
+    /**
+     * Method: refresh
+     *
+     * Parameters:
+     * evt - {<OpenLayers.Event>} The event that caused this refresh.
+     */
+    refresh: function(evt) {
+        var bounds = this.layer.map.getExtent();
+        this.grid.moveTo(bounds, evt.force);
+    },
+   
+    CLASS_NAME: "OpenLayers.Strategy.Grid" 
+});

Modified: sandbox/vector-behavior/lib/OpenLayers.js
===================================================================
--- sandbox/vector-behavior/lib/OpenLayers.js	2008-07-08 14:58:43 UTC (rev 7478)
+++ sandbox/vector-behavior/lib/OpenLayers.js	2008-07-08 20:08:47 UTC (rev 7479)
@@ -96,6 +96,7 @@
             "OpenLayers/Marker.js",
             "OpenLayers/Marker/Box.js",
             "OpenLayers/Popup.js",
+            "OpenLayers/Grid.js",
             "OpenLayers/Tile.js",
             "OpenLayers/Tile/Image.js",
             "OpenLayers/Tile/WFS.js",
@@ -194,6 +195,7 @@
             "OpenLayers/Strategy/Autosave.js",
             "OpenLayers/Strategy/Cluster.js",
             "OpenLayers/Strategy/Paging.js",
+            "OpenLayers/Strategy/Grid.js",
             "OpenLayers/Protocol.js",
             "OpenLayers/Protocol/HTTP.js",
             "OpenLayers/Protocol/SQL.js",



More information about the Commits mailing list