[OpenLayers-Commits] r12394 - in sandbox/jsdoc/jsd/OpenLayers: .
Layer
commits-20090109 at openlayers.org
commits-20090109 at openlayers.org
Sat Sep 17 16:24:03 EDT 2011
Author: mpriour
Date: 2011-09-17 13:24:02 -0700 (Sat, 17 Sep 2011)
New Revision: 12394
Added:
sandbox/jsdoc/jsd/OpenLayers/Layer.js
sandbox/jsdoc/jsd/OpenLayers/Layer/Grid.js
sandbox/jsdoc/jsd/OpenLayers/Layer/HTTPRequest.js
Log:
Add Grid, HTTPRequest Layer & Layer with autoconverrted doc tags
Added: sandbox/jsdoc/jsd/OpenLayers/Layer/Grid.js
===================================================================
--- sandbox/jsdoc/jsd/OpenLayers/Layer/Grid.js (rev 0)
+++ sandbox/jsdoc/jsd/OpenLayers/Layer/Grid.js 2011-09-17 20:24:02 UTC (rev 12394)
@@ -0,0 +1,870 @@
+/* Copyright (c) 2006-2011 by OpenLayers Contributors (see authors.txt for
+ * full list of contributors). Published under the Clear BSD license.
+ * See http://svn.openlayers.org/trunk/openlayers/license.txt for the
+ * full text of the license. */
+
+
+/**
+ * @requires OpenLayers/Layer/HTTPRequest.js
+ * @requires OpenLayers/Console.js
+ */
+
+/**
+ * Class: OpenLayers.Layer.Grid
+ * Base class for layers that use a lattice of tiles. Create a new grid
+ * layer with the <OpenLayers.Layer.Grid> constructor.
+ *
+ * Inherits from:
+ * @extends OpenLayers.Layer.HTTPRequest
+ */
+OpenLayers.Layer.Grid = OpenLayers.Class(OpenLayers.Layer.HTTPRequest, {
+
+ /**
+ * APIProperty: tileSize
+ * @type {OpenLayers.Size}
+ */
+ tileSize: null,
+
+ /**
+ * Property: tileOriginCorner
+ * @type {string} If the <tileOrigin> property is not provided, the tile origin
+ * will be derived from the layer's <maxExtent>. The corner of the
+ * <maxExtent> used is determined by this property. Acceptable values
+ * are "tl" (top left), "tr" (top right), "bl" (bottom left), and "br"
+ * (bottom right). Default is "bl".
+ */
+ tileOriginCorner: "bl",
+
+ /**
+ * APIProperty: tileOrigin
+ * @type {OpenLayers.LonLat} Optional origin for aligning the grid of tiles.
+ * If provided, requests for tiles at all resolutions will be aligned
+ * with this location (no tiles shall overlap this location). If
+ * not provided, the grid of tiles will be aligned with the layer's
+ * <maxExtent>. Default is ``null``.
+ */
+ tileOrigin: null,
+
+ /** APIProperty: tileOptions
+ * @type {Object} optional configuration options for <OpenLayers.Tile> instances
+ * created by this Layer, if supported by the tile class.
+ */
+ tileOptions: null,
+
+ /**
+ * Property: grid
+ * @type {Array.<Array.<OpenLayers.Tile>>} This is an array of rows, each row is
+ * an array of tiles.
+ */
+ grid: null,
+
+ /**
+ * APIProperty: singleTile
+ * @type {boolean} Moves the layer into single-tile mode, meaning that one tile
+ * will be loaded. The tile's size will be determined by the 'ratio'
+ * property. When the tile is dragged such that it does not cover the
+ * entire viewport, it is reloaded.
+ */
+ singleTile: false,
+
+ /** APIProperty: ratio
+ * @type {number} Used only when in single-tile mode, this specifies the
+ * ratio of the size of the single tile to the size of the map.
+ */
+ ratio: 1.5,
+
+ /**
+ * APIProperty: buffer
+ * @type {number} Used only when in gridded mode, this specifies the number of
+ * extra rows and colums of tiles on each side which will
+ * surround the minimum grid tiles to cover the map.
+ * For very slow loading layers, a larger value may increase
+ * performance somewhat when dragging, but will increase bandwidth
+ * use significantly.
+ */
+ buffer: 0,
+
+ /**
+ * APIProperty: numLoadingTiles
+ * @type {number} How many tiles are still loading?
+ */
+ numLoadingTiles: 0,
+
+ /**
+ * APIProperty: tileLoadingDelay
+ * @type {number} - Number of milliseconds before we shift and load
+ * tiles. Default is 100.
+ */
+ tileLoadingDelay: 100,
+
+ /**
+ * Property: timerId
+ * @type {number} - The id of the tileLoadingDelay timer.
+ */
+ timerId: null,
+
+ /**
+ * @constructor Constructor: OpenLayers.Layer.Grid
+ * Create a new grid layer
+ *
+ * Parameters:
+ * @param {string} name
+ * @param {string} url
+ * @param {Object} params
+ * @param {Object=} options options - {Object} Hashtable of extra options to tag onto the layer
+ */
+ initialize: function(name, url, params, options) {
+ OpenLayers.Layer.HTTPRequest.prototype.initialize.apply(this,
+ arguments);
+
+ //grid layers will trigger 'tileloaded' when each new tile is
+ // loaded, as a means of progress update to listeners.
+ // listeners can access 'numLoadingTiles' if they wish to keep track
+ // of the loading progress
+ //
+ this.events.addEventType("tileloaded");
+
+ this.grid = [];
+
+ this._moveGriddedTiles = OpenLayers.Function.bind(
+ this.moveGriddedTiles, this
+ );
+ },
+
+ /**
+ * Method: removeMap
+ * Called when the layer is removed from the map.
+ *
+ * Parameters:
+ * @param {OpenLayers.Map} map The map.
+ */
+ removeMap: function(map) {
+ if(this.timerId != null) {
+ window.clearTimeout(this.timerId);
+ this.timerId = null;
+ }
+ },
+
+ /**
+ * APIMethod: destroy
+ * Deconstruct the layer and clear the grid.
+ */
+ destroy: function() {
+ this.clearGrid();
+ this.grid = null;
+ this.tileSize = null;
+ OpenLayers.Layer.HTTPRequest.prototype.destroy.apply(this, arguments);
+ },
+
+ /**
+ * Method: clearGrid
+ * Go through and remove all tiles from the grid, calling
+ * destroy() on each of them to kill circular references
+ */
+ clearGrid:function() {
+ if (this.grid) {
+ for(var iRow=0, len=this.grid.length; iRow<len; iRow++) {
+ var row = this.grid[iRow];
+ for(var iCol=0, clen=row.length; iCol<clen; iCol++) {
+ var tile = row[iCol];
+ this.removeTileMonitoringHooks(tile);
+ tile.destroy();
+ }
+ }
+ this.grid = [];
+ }
+ },
+
+ /**
+ * APIMethod: clone
+ * Create a clone of this layer
+ *
+ * Parameters:
+ * @param {Object} obj Is this ever used?
+ *
+ * Returns:
+ * @return {OpenLayers.Layer.Grid} An exact clone of this OpenLayers.Layer.Grid
+ */
+ clone: function (obj) {
+
+ if (obj == null) {
+ obj = new OpenLayers.Layer.Grid(this.name,
+ this.url,
+ this.params,
+ this.getOptions());
+ }
+
+ //get all additions from superclasses
+ obj = OpenLayers.Layer.HTTPRequest.prototype.clone.apply(this, [obj]);
+
+ // copy/set any non-init, non-simple values here
+ if (this.tileSize != null) {
+ obj.tileSize = this.tileSize.clone();
+ }
+
+ // we do not want to copy reference to grid, so we make a new array
+ obj.grid = [];
+
+ return obj;
+ },
+
+ /**
+ * Method: moveTo
+ * This function is called whenever the map is moved. All the moving
+ * of actual 'tiles' is done by the map, but moveTo's role is to accept
+ * a bounds and make sure the data that that bounds requires is pre-loaded.
+ *
+ * Parameters:
+ * @param {OpenLayers.Bounds} bounds
+ * @param {boolean} zoomChanged
+ * @param {boolean} dragging
+ */
+ moveTo:function(bounds, zoomChanged, dragging) {
+ OpenLayers.Layer.HTTPRequest.prototype.moveTo.apply(this, arguments);
+
+ bounds = bounds || this.map.getExtent();
+
+ if (bounds != null) {
+
+ // if grid is empty or zoom has changed, we *must* re-tile
+ var forceReTile = !this.grid.length || zoomChanged;
+
+ // total bounds of the tiles
+ var tilesBounds = this.getTilesBounds();
+
+ if (this.singleTile) {
+
+ // We want to redraw whenever even the slightest part of the
+ // current bounds is not contained by our tile.
+ // (thus, we do not specify partial -- its default is false)
+ if ( forceReTile ||
+ (!dragging && !tilesBounds.containsBounds(bounds))) {
+ this.initSingleTile(bounds);
+ }
+ } else {
+
+ // if the bounds have changed such that they are not even
+ // *partially* contained by our tiles (IE user has
+ // programmatically panned to the other side of the earth)
+ // then we want to reTile (thus, partial true).
+ //
+ if (forceReTile || !tilesBounds.containsBounds(bounds, true)) {
+ this.initGriddedTiles(bounds);
+ } else {
+ this.scheduleMoveGriddedTiles();
+ }
+ }
+ }
+ },
+
+ /**
+ * Method: moveByPx
+ * Move the layer based on pixel vector.
+ *
+ * Parameters:
+ * @param {number} dx
+ * @param {number} dy
+ */
+ moveByPx: function(dx, dy) {
+ if (!this.singleTile) {
+ this.scheduleMoveGriddedTiles();
+ }
+ },
+
+ /**
+ * Method: scheduleMoveGriddedTiles
+ * Schedule the move of tiles.
+ */
+ scheduleMoveGriddedTiles: function() {
+ if (this.timerId != null) {
+ window.clearTimeout(this.timerId);
+ }
+ this.timerId = window.setTimeout(
+ this._moveGriddedTiles,
+ this.tileLoadingDelay
+ );
+ },
+
+ /**
+ * APIMethod: setTileSize
+ * Check if we are in singleTile mode and if so, set the size as a ratio
+ * of the map size (as specified by the layer's 'ratio' property).
+ *
+ * Parameters:
+ * @param {OpenLayers.Size} size
+ */
+ setTileSize: function(size) {
+ if (this.singleTile) {
+ size = this.map.getSize();
+ size.h = parseInt(size.h * this.ratio);
+ size.w = parseInt(size.w * this.ratio);
+ }
+ OpenLayers.Layer.HTTPRequest.prototype.setTileSize.apply(this, [size]);
+ },
+
+ /**
+ * Method: getGridBounds
+ * Deprecated. This function will be removed in 3.0. Please use
+ * getTilesBounds() instead.
+ *
+ * Returns:
+ * @return {OpenLayers.Bounds} A Bounds object representing the bounds of all the
+ * currently loaded tiles (including those partially or not at all seen
+ * onscreen)
+ */
+ getGridBounds: function() {
+ var msg = "The getGridBounds() function is deprecated. It will be " +
+ "removed in 3.0. Please use getTilesBounds() instead.";
+ OpenLayers.Console.warn(msg);
+ return this.getTilesBounds();
+ },
+
+ /**
+ * APIMethod: getTilesBounds
+ * Return the bounds of the tile grid.
+ *
+ * Returns:
+ * @return {OpenLayers.Bounds} A Bounds object representing the bounds of all the
+ * currently loaded tiles (including those partially or not at all seen
+ * onscreen).
+ */
+ getTilesBounds: function() {
+ var bounds = null;
+
+ if (this.grid.length) {
+ 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: initSingleTile
+ *
+ * Parameters:
+ * @param {OpenLayers.Bounds} bounds
+ */
+ initSingleTile: function(bounds) {
+
+ //determine new tile bounds
+ var center = bounds.getCenterLonLat();
+ var tileWidth = bounds.getWidth() * this.ratio;
+ var tileHeight = bounds.getHeight() * this.ratio;
+
+ var tileBounds =
+ new OpenLayers.Bounds(center.lon - (tileWidth/2),
+ center.lat - (tileHeight/2),
+ center.lon + (tileWidth/2),
+ center.lat + (tileHeight/2));
+
+ var ul = new OpenLayers.LonLat(tileBounds.left, tileBounds.top);
+ var px = this.map.getLayerPxFromLonLat(ul);
+
+ if (!this.grid.length) {
+ this.grid[0] = [];
+ }
+
+ 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);
+ }
+
+ //remove all but our single tile
+ this.removeExcessTiles(1,1);
+ },
+
+ /**
+ * Method: calculateGridLayout
+ * Generate parameters for the grid layout.
+ *
+ * Parameters:
+ * @param {OpenLayers.Bound} bounds
+ * @param {OpenLayers.LonLat} origin
+ * @param {number} resolution
+ *
+ * Returns:
+ * Object containing properties tilelon, tilelat, tileoffsetlat,
+ * tileoffsetlat, tileoffsetx, tileoffsety
+ */
+ calculateGridLayout: function(bounds, origin, resolution) {
+ var tilelon = resolution * this.tileSize.w;
+ var tilelat = resolution * this.tileSize.h;
+
+ var offsetlon = bounds.left - origin.lon;
+ var tilecol = Math.floor(offsetlon/tilelon) - this.buffer;
+ var tilecolremain = offsetlon/tilelon - tilecol;
+ var tileoffsetx = -tilecolremain * this.tileSize.w;
+ var tileoffsetlon = origin.lon + tilecol * tilelon;
+
+ var offsetlat = bounds.top - (origin.lat + tilelat);
+ var tilerow = Math.ceil(offsetlat/tilelat) + this.buffer;
+ var tilerowremain = tilerow - offsetlat/tilelat;
+ var tileoffsety = -tilerowremain * this.tileSize.h;
+ var tileoffsetlat = origin.lat + tilerow * tilelat;
+
+ return {
+ tilelon: tilelon, tilelat: tilelat,
+ tileoffsetlon: tileoffsetlon, tileoffsetlat: tileoffsetlat,
+ tileoffsetx: tileoffsetx, tileoffsety: tileoffsety
+ };
+
+ },
+
+ /**
+ * Method: getTileOrigin
+ * Determine the origin for aligning the grid of tiles. If a <tileOrigin>
+ * property is supplied, that will be returned. Otherwise, the origin
+ * will be derived from the layer's <maxExtent> property. In this case,
+ * the tile origin will be the corner of the <maxExtent> given by the
+ * <tileOriginCorner> property.
+ *
+ * Returns:
+ * @return {OpenLayers.LonLat} The tile origin.
+ */
+ getTileOrigin: function() {
+ var origin = this.tileOrigin;
+ if (!origin) {
+ var extent = this.getMaxExtent();
+ var edges = ({
+ "tl": ["left", "top"],
+ "tr": ["right", "top"],
+ "bl": ["left", "bottom"],
+ "br": ["right", "bottom"]
+ })[this.tileOriginCorner];
+ origin = new OpenLayers.LonLat(extent[edges[0]], extent[edges[1]]);
+ }
+ return origin;
+ },
+
+ /**
+ * Method: initGriddedTiles
+ *
+ * Parameters:
+ * @param {OpenLayers.Bounds} bounds
+ */
+ initGriddedTiles: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 origin = this.getTileOrigin();
+ var resolution = this.map.getResolution();
+
+ var tileLayout = this.calculateGridLayout(bounds, origin, 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.addTile(tileBounds, px);
+ this.addTileMonitoringHooks(tile);
+ 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: getMaxExtent
+ * Get this layer's maximum extent. (Implemented as a getter for
+ * potential specific implementations in sub-classes.)
+ *
+ * Returns:
+ * @return {OpenLayers.Bounds}
+ */
+ getMaxExtent: function() {
+ return this.maxExtent;
+ },
+
+ /**
+ * 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, len=tileQueue.length; i<len; i++) {
+ var tile = tileQueue[i];
+ tile.draw();
+ //mark tile as unqueued for the next time (since tiles are reused)
+ tile.queued = false;
+ }
+ },
+
+ /**
+ * APIMethod: addTile
+ * Create a tile, initialize it, and add it to the layer div.
+ *
+ * Parameters
+ * bounds - {<OpenLayers.Bounds>}
+ * position - {<OpenLayers.Pixel>}
+ *
+ * Returns:
+ * @return {OpenLayers.Tile} The added OpenLayers.Tile
+ */
+ addTile:function(bounds, position) {
+ return new OpenLayers.Tile.Image(this, position, bounds, null,
+ this.tileSize, this.tileOptions);
+ },
+
+ /**
+ * 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:
+ * @param {OpenLayers.Tile} tile
+ */
+ 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:
+ * @param {OpenLayers.Tile} tile
+ */
+ removeTileMonitoringHooks: function(tile) {
+ tile.unload();
+ tile.events.un({
+ "loadstart": tile.onLoadStart,
+ "loadend": tile.onLoadEnd,
+ "unload": tile.onLoadEnd,
+ scope: this
+ });
+ },
+
+ /**
+ * Method: moveGriddedTiles
+ */
+ moveGriddedTiles: function() {
+ var shifted = true;
+ var buffer = this.buffer || 1;
+ var tlLayer = this.grid[0][0].position;
+ var offsetX = parseInt(this.map.layerContainerDiv.style.left);
+ var offsetY = parseInt(this.map.layerContainerDiv.style.top);
+ var tlViewPort = tlLayer.add(offsetX, offsetY);
+ 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 {
+ shifted = false;
+ }
+ if (shifted) {
+ // we may have other row or columns to shift, schedule it
+ // with a setTimeout, to give the user a chance to sneak
+ // in moveTo's
+ this.timerId = window.setTimeout(this._moveGriddedTiles, 0);
+ }
+ },
+
+ /**
+ * Method: shiftRow
+ * Shifty grid work
+ *
+ * Parameters:
+ * @param {boolean} prepend 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, len=modelRow.length; i<len; 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:
+ * @param {boolean} prepend 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, len=this.grid.length; i<len; 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.
+ *
+ * Parameters:
+ * @param {number} rows Maximum number of rows we want our grid to have.
+ * @param {number} columns 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);
+ 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);
+ tile.destroy();
+ }
+ }
+ },
+
+ /**
+ * Method: onMapResize
+ * For singleTile layers, this will set a new tile size according to the
+ * dimensions of the map pane.
+ */
+ onMapResize: function() {
+ if (this.singleTile) {
+ this.clearGrid();
+ this.setTileSize();
+ }
+ },
+
+ /**
+ * APIMethod: getTileBounds
+ * Returns The tile bounds for a layer given a pixel location.
+ *
+ * Parameters:
+ * @param {OpenLayers.Pixel} viewPortPx The location in the viewport.
+ *
+ * Returns:
+ * @return {OpenLayers.Bounds} Bounds of the tile at the given pixel location.
+ */
+ getTileBounds: function(viewPortPx) {
+ var maxExtent = this.maxExtent;
+ var resolution = this.getResolution();
+ var tileMapWidth = resolution * this.tileSize.w;
+ var tileMapHeight = resolution * this.tileSize.h;
+ var mapPoint = this.getLonLatFromViewPortPx(viewPortPx);
+ var tileLeft = maxExtent.left + (tileMapWidth *
+ Math.floor((mapPoint.lon -
+ maxExtent.left) /
+ tileMapWidth));
+ var tileBottom = maxExtent.bottom + (tileMapHeight *
+ Math.floor((mapPoint.lat -
+ maxExtent.bottom) /
+ tileMapHeight));
+ return new OpenLayers.Bounds(tileLeft, tileBottom,
+ tileLeft + tileMapWidth,
+ tileBottom + tileMapHeight);
+ },
+
+ CLASS_NAME: "OpenLayers.Layer.Grid"
+});
Added: sandbox/jsdoc/jsd/OpenLayers/Layer/HTTPRequest.js
===================================================================
--- sandbox/jsdoc/jsd/OpenLayers/Layer/HTTPRequest.js (rev 0)
+++ sandbox/jsdoc/jsd/OpenLayers/Layer/HTTPRequest.js 2011-09-17 20:24:02 UTC (rev 12394)
@@ -0,0 +1,228 @@
+/* Copyright (c) 2006-2011 by OpenLayers Contributors (see authors.txt for
+ * full list of contributors). Published under the Clear BSD license.
+ * See http://svn.openlayers.org/trunk/openlayers/license.txt for the
+ * full text of the license. */
+
+
+/**
+ * @requires OpenLayers/Layer.js
+ */
+
+/**
+ * Class: OpenLayers.Layer.HTTPRequest
+ *
+ * Inherits from:
+ * @extends OpenLayers.Layer
+ */
+OpenLayers.Layer.HTTPRequest = OpenLayers.Class(OpenLayers.Layer, {
+
+ /**
+ * @const Constant: URL_HASH_FACTOR
+ * @type {number} Used to hash URL param strings for multi-WMS server selection.
+ * Set to the Golden Ratio per Knuth's recommendation.
+ */
+ URL_HASH_FACTOR: (Math.sqrt(5) - 1) / 2,
+
+ /**
+ * Property: url
+ * @type {Array.<string>|string} This is either an array of url strings or
+ * a single url string.
+ */
+ url: null,
+
+ /**
+ * Property: params
+ * @type {Object} Hashtable of key/value parameters
+ */
+ params: null,
+
+ /**
+ * APIProperty: reproject
+ * *Deprecated*. See http://docs.openlayers.org/library/spherical_mercator.html
+ * for information on the replacement for this functionality.
+ * @type {boolean} Whether layer should reproject itself based on base layer
+ * locations. This allows reprojection onto commercial layers.
+ * Default is false: Most layers can't reproject, but layers
+ * which can create non-square geographic pixels can, like WMS.
+ *
+ */
+ reproject: false,
+
+ /**
+ * @constructor Constructor: OpenLayers.Layer.HTTPRequest
+ *
+ * Parameters:
+ * @param {string} name
+ * @param {Array.<string>|string} url
+ * @param {Object} params
+ * @param {Object=} options options - {Object} Hashtable of extra options to tag onto the layer
+ */
+ initialize: function(name, url, params, options) {
+ OpenLayers.Layer.prototype.initialize.apply(this, [name, options]);
+ this.url = url;
+ this.params = OpenLayers.Util.extend( {}, params);
+ },
+
+ /**
+ * APIMethod: destroy
+ */
+ destroy: function() {
+ this.url = null;
+ this.params = null;
+ OpenLayers.Layer.prototype.destroy.apply(this, arguments);
+ },
+
+ /**
+ * APIMethod: clone
+ *
+ * Parameters:
+ * @param {Object} obj
+ *
+ * Returns:
+ * @return {OpenLayers.Layer.HTTPRequest} An exact clone of this
+ * <OpenLayers.Layer.HTTPRequest>
+ */
+ clone: function (obj) {
+
+ if (obj == null) {
+ obj = new OpenLayers.Layer.HTTPRequest(this.name,
+ this.url,
+ this.params,
+ this.getOptions());
+ }
+
+ //get all additions from superclasses
+ obj = OpenLayers.Layer.prototype.clone.apply(this, [obj]);
+
+ // copy/set any non-init, non-simple values here
+
+ return obj;
+ },
+
+ /**
+ * APIMethod: setUrl
+ *
+ * Parameters:
+ * @param {string} newUrl
+ */
+ setUrl: function(newUrl) {
+ this.url = newUrl;
+ },
+
+ /**
+ * APIMethod: mergeNewParams
+ *
+ * Parameters:
+ * @param {Object} newParams
+ *
+ * Returns:
+ * redrawn: {Boolean} whether the layer was actually redrawn.
+ */
+ mergeNewParams:function(newParams) {
+ this.params = OpenLayers.Util.extend(this.params, newParams);
+ var ret = this.redraw();
+ if(this.map != null) {
+ this.map.events.triggerEvent("changelayer", {
+ layer: this,
+ property: "params"
+ });
+ }
+ return ret;
+ },
+
+ /**
+ * APIMethod: redraw
+ * Redraws the layer. Returns true if the layer was redrawn, false if not.
+ *
+ * Parameters:
+ * @param {boolean} force Force redraw by adding random parameter.
+ *
+ * Returns:
+ * @return {boolean} The layer was redrawn.
+ */
+ redraw: function(force) {
+ if (force) {
+ return this.mergeNewParams({"_olSalt": Math.random()});
+ } else {
+ return OpenLayers.Layer.prototype.redraw.apply(this, []);
+ }
+ },
+
+ /**
+ * Method: selectUrl
+ * selectUrl() implements the standard floating-point multiplicative
+ * hash function described by Knuth, and hashes the contents of the
+ * given param string into a float between 0 and 1. This float is then
+ * scaled to the size of the provided urls array, and used to select
+ * a URL.
+ *
+ * Parameters:
+ * @param {string} paramString
+ * @param {Array.<string>} urls
+ *
+ * Returns:
+ * @return {string} An entry from the urls array, deterministically selected based
+ * on the paramString.
+ */
+ selectUrl: function(paramString, urls) {
+ var product = 1;
+ for (var i=0, len=paramString.length; i<len; i++) {
+ product *= paramString.charCodeAt(i) * this.URL_HASH_FACTOR;
+ product -= Math.floor(product);
+ }
+ return urls[Math.floor(product * urls.length)];
+ },
+
+ /**
+ * Method: getFullRequestString
+ * Combine url with layer's params and these newParams.
+ *
+ * does checking on the serverPath variable, allowing for cases when it
+ * is supplied with trailing ? or &, as well as cases where not.
+ *
+ * return in formatted string like this:
+ * "server?key1=value1&key2=value2&key3=value3"
+ *
+ * WARNING: The altUrl parameter is deprecated and will be removed in 3.0.
+ *
+ * Parameters:
+ * @param {Object} newParams
+ * @param {string} altUrl Use this as the url instead of the layer's url
+ *
+ * Returns:
+ * @return {string}
+ */
+ getFullRequestString:function(newParams, altUrl) {
+
+ // if not altUrl passed in, use layer's url
+ var url = altUrl || this.url;
+
+ // create a new params hashtable with all the layer params and the
+ // new params together. then convert to string
+ var allParams = OpenLayers.Util.extend({}, this.params);
+ allParams = OpenLayers.Util.extend(allParams, newParams);
+ var paramsString = OpenLayers.Util.getParameterString(allParams);
+
+ // if url is not a string, it should be an array of strings,
+ // in which case we will deterministically select one of them in
+ // order to evenly distribute requests to different urls.
+ //
+ if (OpenLayers.Util.isArray(url)) {
+ url = this.selectUrl(paramsString, url);
+ }
+
+ // ignore parameters that are already in the url search string
+ var urlParams =
+ OpenLayers.Util.upperCaseObject(OpenLayers.Util.getParameters(url));
+ for(var key in allParams) {
+ if(key.toUpperCase() in urlParams) {
+ delete allParams[key];
+ }
+ }
+ paramsString = OpenLayers.Util.getParameterString(allParams);
+
+ return OpenLayers.Util.urlAppend(url, paramsString);
+ },
+
+ CLASS_NAME: "OpenLayers.Layer.HTTPRequest"
+});
Added: sandbox/jsdoc/jsd/OpenLayers/Layer.js
===================================================================
--- sandbox/jsdoc/jsd/OpenLayers/Layer.js (rev 0)
+++ sandbox/jsdoc/jsd/OpenLayers/Layer.js 2011-09-17 20:24:02 UTC (rev 12394)
@@ -0,0 +1,1343 @@
+/* Copyright (c) 2006-2011 by OpenLayers Contributors (see authors.txt for
+ * full list of contributors). Published under the Clear BSD license.
+ * See http://svn.openlayers.org/trunk/openlayers/license.txt for the
+ * full text of the license. */
+
+
+/**
+ * @requires OpenLayers/BaseTypes/Class.js
+ * @requires OpenLayers/Map.js
+ * @requires OpenLayers/Projection.js
+ */
+
+/**
+ * Class: OpenLayers.Layer
+ */
+OpenLayers.Layer = OpenLayers.Class({
+
+ /**
+ * APIProperty: id
+ * @type {string}
+ */
+ id: null,
+
+ /**
+ * APIProperty: name
+ * @type {string}
+ */
+ name: null,
+
+ /**
+ * APIProperty: div
+ * @type {Element}
+ */
+ div: null,
+
+ /**
+ * Property: opacity
+ * @type {number} The layer's opacity. Float number between 0.0 and 1.0. Default
+ * is 1.
+ */
+ opacity: 1,
+
+ /**
+ * APIProperty: alwaysInRange
+ * @type {boolean} If a layer's display should not be scale-based, this should
+ * be set to true. This will cause the layer, as an overlay, to always
+ * be 'active', by always returning true from the calculateInRange()
+ * function.
+ *
+ * If not explicitly specified for a layer, its value will be
+ * determined on startup in initResolutions() based on whether or not
+ * any scale-specific properties have been set as options on the
+ * layer. If no scale-specific options have been set on the layer, we
+ * assume that it should always be in range.
+ *
+ * See #987 for more info.
+ */
+ alwaysInRange: null,
+
+ /**
+ * @const Constant: EVENT_TYPES
+ * @type {Array.<string>} Supported application event types. Register a listener
+ * for a particular event with the following syntax:
+ * (code)
+ * layer.events.register(type, obj, listener);
+ * (end)
+ *
+ * Listeners will be called with a reference to an event object. The
+ * properties of this event depends on exactly what happened.
+ *
+ * All event objects have at least the following properties:
+ * object - {Object} A reference to layer.events.object.
+ * element - {DOMElement} A reference to layer.events.element.
+ *
+ * Supported map event types:
+ * loadstart - Triggered when layer loading starts.
+ * loadend - Triggered when layer loading ends.
+ * loadcancel - Triggered when layer loading is canceled.
+ * visibilitychanged - Triggered when layer visibility is changed.
+ * move - Triggered when layer moves (triggered with every mousemove
+ * during a drag).
+ * moveend - Triggered when layer is done moving, object passed as
+ * argument has a zoomChanged boolean property which tells that the
+ * zoom has changed.
+ * added - Triggered after the layer is added to a map. Listeners will
+ * receive an object with a *map* property referencing the map and a
+ * *layer* property referencing the layer.
+ * removed - Triggered after the layer is removed from the map. Listeners
+ * will receive an object with a *map* property referencing the map and
+ * a *layer* property referencing the layer.
+ */
+ EVENT_TYPES: ["loadstart", "loadend", "loadcancel", "visibilitychanged",
+ "move", "moveend", "added", "removed"],
+
+ /**
+ * @const Constant: RESOLUTION_PROPERTIES
+ * @type {Array} The properties that are used for calculating resolutions
+ * information.
+ */
+ RESOLUTION_PROPERTIES: [
+ 'scales', 'resolutions',
+ 'maxScale', 'minScale',
+ 'maxResolution', 'minResolution',
+ 'numZoomLevels', 'maxZoomLevel'
+ ],
+
+ /**
+ * APIProperty: events
+ * @type {OpenLayers.Events}
+ */
+ events: null,
+
+ /**
+ * APIProperty: map
+ * @type {OpenLayers.Map} This variable is set when the layer is added to
+ * the map, via the accessor function setMap().
+ */
+ map: null,
+
+ /**
+ * APIProperty: isBaseLayer
+ * @type {boolean} Whether or not the layer is a base layer. This should be set
+ * individually by all subclasses. Default is false
+ */
+ isBaseLayer: false,
+
+ /**
+ * Property: alpha
+ * @type {boolean} The layer's images have an alpha channel. Default is false.
+ */
+ alpha: false,
+
+ /**
+ * APIProperty: displayInLayerSwitcher
+ * @type {boolean} Display the layer's name in the layer switcher. Default is
+ * true.
+ */
+ displayInLayerSwitcher: true,
+
+ /**
+ * APIProperty: visibility
+ * @type {boolean} The layer should be displayed in the map. Default is true.
+ */
+ visibility: true,
+
+ /**
+ * APIProperty: attribution
+ * @type {string} Attribution string, displayed when an
+ * <OpenLayers.Control.Attribution> has been added to the map.
+ */
+ attribution: null,
+
+ /**
+ * Property: inRange
+ * @type {boolean} The current map resolution is within the layer's min/max
+ * range. This is set in <OpenLayers.Map.setCenter> whenever the zoom
+ * changes.
+ */
+ inRange: false,
+
+ /**
+ * Propery: imageSize
+ * {<OpenLayers.Size>} For layers with a gutter, the image is larger than
+ * the tile by twice the gutter in each dimension.
+ */
+ imageSize: null,
+
+ /**
+ * Property: imageOffset
+ * @type {OpenLayers.Pixel} For layers with a gutter, the image offset
+ * represents displacement due to the gutter.
+ */
+ imageOffset: null,
+
+ // OPTIONS
+
+ /**
+ * Property: options
+ * @type {Object} An optional object whose properties will be set on the layer.
+ * Any of the layer properties can be set as a property of the options
+ * object and sent to the constructor when the layer is created.
+ */
+ options: null,
+
+ /**
+ * APIProperty: eventListeners
+ * @type {Object} If set as an option at construction, the eventListeners
+ * object will be registered with <OpenLayers.Events.on>. Object
+ * structure must be a listeners object as shown in the example for
+ * the events.on method.
+ */
+ eventListeners: null,
+
+ /**
+ * APIProperty: gutter
+ * @type {number} Determines the width (in pixels) of the gutter around image
+ * tiles to ignore. By setting this property to a non-zero value,
+ * images will be requested that are wider and taller than the tile
+ * size by a value of 2 x gutter. This allows artifacts of rendering
+ * at tile edges to be ignored. Set a gutter value that is equal to
+ * half the size of the widest symbol that needs to be displayed.
+ * Defaults to zero. Non-tiled layers always have zero gutter.
+ */
+ gutter: 0,
+
+ /**
+ * APIProperty: projection
+ * @type {OpenLayers.Projection} or {<String>} Set in the layer options to
+ * override the default projection string this layer - also set maxExtent,
+ * maxResolution, and units if appropriate. Can be either a string or
+ * an <OpenLayers.Projection> object when created -- will be converted
+ * to an object when setMap is called if a string is passed.
+ */
+ projection: null,
+
+ /**
+ * APIProperty: units
+ * @type {string} The layer map units. Defaults to 'degrees'. Possible values
+ * are 'degrees' (or 'dd'), 'm', 'ft', 'km', 'mi', 'inches'.
+ */
+ units: null,
+
+ /**
+ * APIProperty: scales
+ * @type {Array} An array of map scales in descending order. The values in the
+ * array correspond to the map scale denominator. Note that these
+ * values only make sense if the display (monitor) resolution of the
+ * client is correctly guessed by whomever is configuring the
+ * application. In addition, the units property must also be set.
+ * Use <resolutions> instead wherever possible.
+ */
+ scales: null,
+
+ /**
+ * APIProperty: resolutions
+ * @type {Array} A list of map resolutions (map units per pixel) in descending
+ * order. If this is not set in the layer constructor, it will be set
+ * based on other resolution related properties (maxExtent,
+ * maxResolution, maxScale, etc.).
+ */
+ resolutions: null,
+
+ /**
+ * APIProperty: maxExtent
+ * @type {OpenLayers.Bounds} The center of these bounds will not stray outside
+ * of the viewport extent during panning. In addition, if
+ * <displayOutsideMaxExtent> is set to false, data will not be
+ * requested that falls completely outside of these bounds.
+ */
+ maxExtent: null,
+
+ /**
+ * APIProperty: minExtent
+ * @type {OpenLayers.Bounds}
+ */
+ minExtent: null,
+
+ /**
+ * APIProperty: maxResolution
+ * @type {number} Default max is 360 deg / 256 px, which corresponds to
+ * zoom level 0 on gmaps. Specify a different value in the layer
+ * options if you are not using a geographic projection and
+ * displaying the whole world.
+ */
+ maxResolution: null,
+
+ /**
+ * APIProperty: minResolution
+ * @type {number}
+ */
+ minResolution: null,
+
+ /**
+ * APIProperty: numZoomLevels
+ * @type {number}
+ */
+ numZoomLevels: null,
+
+ /**
+ * APIProperty: minScale
+ * @type {number}
+ */
+ minScale: null,
+
+ /**
+ * APIProperty: maxScale
+ * @type {number}
+ */
+ maxScale: null,
+
+ /**
+ * APIProperty: displayOutsideMaxExtent
+ * @type {boolean} Request map tiles that are completely outside of the max
+ * extent for this layer. Defaults to false.
+ */
+ displayOutsideMaxExtent: false,
+
+ /**
+ * APIProperty: wrapDateLine
+ * @type {boolean} #487 for more info.
+ */
+ wrapDateLine: false,
+
+ /**
+ * APIProperty: transitionEffect
+ * @type {string} The transition effect to use when the map is panned or
+ * zoomed.
+ *
+ * There are currently two supported values:
+ * - *null* No transition effect (the default).
+ * - *resize* Existing tiles are resized on zoom to provide a visual
+ * effect of the zoom having taken place immediately. As the
+ * new tiles become available, they are drawn over top of the
+ * resized tiles.
+ */
+ transitionEffect: null,
+
+ /**
+ * Property: SUPPORTED_TRANSITIONS
+ * @type {Array} An immutable (that means don't change it!) list of supported
+ * transitionEffect values.
+ */
+ SUPPORTED_TRANSITIONS: ['resize'],
+
+ /**
+ * Property: metadata
+ * @type {Object} This object can be used to store additional information on a
+ * layer object.
+ */
+ metadata: {},
+
+ /**
+ * @constructor Constructor: OpenLayers.Layer
+ *
+ * Parameters:
+ * @param {string} name The layer name
+ * @param {Object=} options options - {Object} Hashtable of extra options to tag onto the layer
+ */
+ initialize: function(name, options) {
+
+ this.addOptions(options);
+
+ this.name = name;
+
+ if (this.id == null) {
+
+ this.id = OpenLayers.Util.createUniqueID(this.CLASS_NAME + "_");
+
+ this.div = OpenLayers.Util.createDiv(this.id);
+ this.div.style.width = "100%";
+ this.div.style.height = "100%";
+ this.div.dir = "ltr";
+
+ this.events = new OpenLayers.Events(this, this.div,
+ this.EVENT_TYPES);
+ if(this.eventListeners instanceof Object) {
+ this.events.on(this.eventListeners);
+ }
+
+ }
+
+ if (this.wrapDateLine) {
+ this.displayOutsideMaxExtent = true;
+ }
+ },
+
+ /**
+ * Method: destroy
+ * Destroy is a destructor: this is to alleviate cyclic references which
+ * the Javascript garbage cleaner can not take care of on its own.
+ *
+ * Parameters:
+ * @param {boolean} setNewBaseLayer Set a new base layer when this layer has
+ * been destroyed. Default is true.
+ */
+ destroy: function(setNewBaseLayer) {
+ if (setNewBaseLayer == null) {
+ setNewBaseLayer = true;
+ }
+ if (this.map != null) {
+ this.map.removeLayer(this, setNewBaseLayer);
+ }
+ this.projection = null;
+ this.map = null;
+ this.name = null;
+ this.div = null;
+ this.options = null;
+
+ if (this.events) {
+ if(this.eventListeners) {
+ this.events.un(this.eventListeners);
+ }
+ this.events.destroy();
+ }
+ this.eventListeners = null;
+ this.events = null;
+ },
+
+ /**
+ * Method: clone
+ *
+ * Parameters:
+ * @param {OpenLayers.Layer} obj The layer to be cloned
+ *
+ * Returns:
+ * @return {OpenLayers.Layer} An exact clone of this <OpenLayers.Layer>
+ */
+ clone: function (obj) {
+
+ if (obj == null) {
+ obj = new OpenLayers.Layer(this.name, this.getOptions());
+ }
+
+ // catch any randomly tagged-on properties
+ OpenLayers.Util.applyDefaults(obj, this);
+
+ // a cloned layer should never have its map property set
+ // because it has not been added to a map yet.
+ obj.map = null;
+
+ return obj;
+ },
+
+ /**
+ * Method: getOptions
+ * Extracts an object from the layer with the properties that were set as
+ * options, but updates them with the values currently set on the
+ * instance.
+ *
+ * Returns:
+ * @return {Object} the <options> of the layer, representing the current state.
+ */
+ getOptions: function() {
+ var options = {};
+ for(var o in this.options) {
+ options[o] = this[o];
+ }
+ return options;
+ },
+
+ /**
+ * APIMethod: setName
+ * Sets the new layer name for this layer. Can trigger a changelayer event
+ * on the map.
+ *
+ * Parameters:
+ * @param {string} newName The new name.
+ */
+ setName: function(newName) {
+ if (newName != this.name) {
+ this.name = newName;
+ if (this.map != null) {
+ this.map.events.triggerEvent("changelayer", {
+ layer: this,
+ property: "name"
+ });
+ }
+ }
+ },
+
+ /**
+ * APIMethod: addOptions
+ *
+ * Parameters:
+ * @param {Object} newOptions
+ * @param {boolean} reinitialize If set to true, and if resolution options of the
+ * current baseLayer were changed, the map will be recentered to make
+ * sure that it is displayed with a valid resolution, and a
+ * changebaselayer event will be triggered.
+ */
+ addOptions: function (newOptions, reinitialize) {
+
+ if (this.options == null) {
+ this.options = {};
+ }
+
+ // update our copy for clone
+ OpenLayers.Util.extend(this.options, newOptions);
+
+ // add new options to this
+ OpenLayers.Util.extend(this, newOptions);
+
+ // make sure this.projection references a projection object
+ if(typeof this.projection == "string") {
+ this.projection = new OpenLayers.Projection(this.projection);
+ }
+
+ // get the units from the projection, if we have a projection
+ // and it it has units
+ if(this.projection && this.projection.getUnits()) {
+ this.units = this.projection.getUnits();
+ }
+
+ // re-initialize resolutions if necessary, i.e. if any of the
+ // properties of the "properties" array defined below is set
+ // in the new options
+ if(this.map) {
+ // store current resolution so we can try to restore it later
+ var resolution = this.map.getResolution();
+ var properties = this.RESOLUTION_PROPERTIES.concat(
+ ["projection", "units", "minExtent", "maxExtent"]
+ );
+ for(var o in newOptions) {
+ if(newOptions.hasOwnProperty(o) &&
+ OpenLayers.Util.indexOf(properties, o) >= 0) {
+
+ this.initResolutions();
+ if (reinitialize && this.map.baseLayer === this) {
+ // update map position, and restore previous resolution
+ this.map.setCenter(this.map.getCenter(),
+ this.map.getZoomForResolution(resolution),
+ false, true
+ );
+ // trigger a changebaselayer event to make sure that
+ // all controls (especially
+ // OpenLayers.Control.PanZoomBar) get notified of the
+ // new options
+ this.map.events.triggerEvent("changebaselayer", {
+ layer: this
+ });
+ }
+ break;
+ }
+ }
+ }
+ },
+
+ /**
+ * APIMethod: onMapResize
+ * This function can be implemented by subclasses
+ */
+ onMapResize: function() {
+ //this function can be implemented by subclasses
+ },
+
+ /**
+ * APIMethod: redraw
+ * Redraws the layer. Returns true if the layer was redrawn, false if not.
+ *
+ * Returns:
+ * @return {boolean} The layer was redrawn.
+ */
+ redraw: function() {
+ var redrawn = false;
+ if (this.map) {
+
+ // min/max Range may have changed
+ this.inRange = this.calculateInRange();
+
+ // map's center might not yet be set
+ var extent = this.getExtent();
+
+ if (extent && this.inRange && this.visibility) {
+ var zoomChanged = true;
+ this.moveTo(extent, zoomChanged, false);
+ this.events.triggerEvent("moveend",
+ {"zoomChanged": zoomChanged});
+ redrawn = true;
+ }
+ }
+ return redrawn;
+ },
+
+ /**
+ * Method: moveTo
+ *
+ * Parameters:
+ * @param {OpenLayers.Bounds} bounds
+ * @param {boolean} zoomChanged Tells when zoom has changed, as layers have to
+ * do some init work in that case.
+ * @param {boolean} dragging
+ */
+ moveTo:function(bounds, zoomChanged, dragging) {
+ var display = this.visibility;
+ if (!this.isBaseLayer) {
+ display = display && this.inRange;
+ }
+ this.display(display);
+ },
+
+ /**
+ * Method: moveByPx
+ * Move the layer based on pixel vector. To be implemented by subclasses.
+ *
+ * Parameters:
+ * @param {number} dx The x coord of the displacement vector.
+ * @param {number} dy The y coord of the displacement vector.
+ */
+ moveByPx: function(dx, dy) {
+ },
+
+ /**
+ * Method: setMap
+ * Set the map property for the layer. This is done through an accessor
+ * so that subclasses can override this and take special action once
+ * they have their map variable set.
+ *
+ * Here we take care to bring over any of the necessary default
+ * properties from the map.
+ *
+ * Parameters:
+ * @param {OpenLayers.Map} map
+ */
+ setMap: function(map) {
+ if (this.map == null) {
+
+ this.map = map;
+
+ // grab some essential layer data from the map if it hasn't already
+ // been set
+ this.maxExtent = this.maxExtent || this.map.maxExtent;
+ this.minExtent = this.minExtent || this.map.minExtent;
+
+ this.projection = this.projection || this.map.projection;
+ if (typeof this.projection == "string") {
+ this.projection = new OpenLayers.Projection(this.projection);
+ }
+
+ // Check the projection to see if we can get units -- if not, refer
+ // to properties.
+ this.units = this.projection.getUnits() ||
+ this.units || this.map.units;
+
+ this.initResolutions();
+
+ if (!this.isBaseLayer) {
+ this.inRange = this.calculateInRange();
+ var show = ((this.visibility) && (this.inRange));
+ this.div.style.display = show ? "" : "none";
+ }
+
+ // deal with gutters
+ this.setTileSize();
+ }
+ },
+
+ /**
+ * Method: afterAdd
+ * Called at the end of the map.addLayer sequence. At this point, the map
+ * will have a base layer. To be overridden by subclasses.
+ */
+ afterAdd: function() {
+ },
+
+ /**
+ * APIMethod: removeMap
+ * Just as setMap() allows each layer the possibility to take a
+ * personalized action on being added to the map, removeMap() allows
+ * each layer to take a personalized action on being removed from it.
+ * For now, this will be mostly unused, except for the EventPane layer,
+ * which needs this hook so that it can remove the special invisible
+ * pane.
+ *
+ * Parameters:
+ * @param {OpenLayers.Map} map
+ */
+ removeMap: function(map) {
+ //to be overridden by subclasses
+ },
+
+ /**
+ * APIMethod: getImageSize
+ *
+ * Parameters:
+ * @param {OpenLayers.Bounds} bounds optional tile bounds, can be used
+ * by subclasses that have to deal with different tile sizes at the
+ * layer extent edges (e.g. Zoomify)
+ *
+ * Returns:
+ * @return {OpenLayers.Size} The size that the image should be, taking into
+ * account gutters.
+ */
+ getImageSize: function(bounds) {
+ return (this.imageSize || this.tileSize);
+ },
+
+ /**
+ * APIMethod: setTileSize
+ * Set the tile size based on the map size. This also sets layer.imageSize
+ * and layer.imageOffset for use by Tile.Image.
+ *
+ * Parameters:
+ * @param {OpenLayers.Size} size
+ */
+ setTileSize: function(size) {
+ var tileSize = (size) ? size :
+ ((this.tileSize) ? this.tileSize :
+ this.map.getTileSize());
+ this.tileSize = tileSize;
+ if(this.gutter) {
+ // layers with gutters need non-null tile sizes
+ //if(tileSize == null) {
+ // OpenLayers.console.error("Error in layer.setMap() for " +
+ // this.name + ": layers with " +
+ // "gutters need non-null tile sizes");
+ //}
+ this.imageOffset = new OpenLayers.Pixel(-this.gutter,
+ -this.gutter);
+ this.imageSize = new OpenLayers.Size(tileSize.w + (2*this.gutter),
+ tileSize.h + (2*this.gutter));
+ }
+ },
+
+ /**
+ * APIMethod: getVisibility
+ *
+ * Returns:
+ * @return {boolean} The layer should be displayed (if in range).
+ */
+ getVisibility: function() {
+ return this.visibility;
+ },
+
+ /**
+ * APIMethod: setVisibility
+ * Set the visibility flag for the layer and hide/show & redraw
+ * accordingly. Fire event unless otherwise specified
+ *
+ * Note that visibility is no longer simply whether or not the layer's
+ * style.display is set to "block". Now we store a 'visibility' state
+ * property on the layer class, this allows us to remember whether or
+ * not we *desire* for a layer to be visible. In the case where the
+ * map's resolution is out of the layer's range, this desire may be
+ * subverted.
+ *
+ * Parameters:
+ * @param {boolean} visibility Whether or not to display the layer (if in range)
+ */
+ setVisibility: function(visibility) {
+ if (visibility != this.visibility) {
+ this.visibility = visibility;
+ this.display(visibility);
+ this.redraw();
+ if (this.map != null) {
+ this.map.events.triggerEvent("changelayer", {
+ layer: this,
+ property: "visibility"
+ });
+ }
+ this.events.triggerEvent("visibilitychanged");
+ }
+ },
+
+ /**
+ * APIMethod: display
+ * Hide or show the Layer. This is designed to be used internally, and
+ * is not generally the way to enable or disable the layer. For that,
+ * use the setVisibility function instead..
+ *
+ * Parameters:
+ * @param {boolean} display
+ */
+ display: function(display) {
+ if (display != (this.div.style.display != "none")) {
+ this.div.style.display = (display && this.calculateInRange()) ? "block" : "none";
+ }
+ },
+
+ /**
+ * APIMethod: calculateInRange
+ *
+ * Returns:
+ * @return {boolean} The layer is displayable at the current map's current
+ * resolution. Note that if 'alwaysInRange' is true for the layer,
+ * this function will always return true.
+ */
+ calculateInRange: function() {
+ var inRange = false;
+
+ if (this.alwaysInRange) {
+ inRange = true;
+ } else {
+ if (this.map) {
+ var resolution = this.map.getResolution();
+ inRange = ( (resolution >= this.minResolution) &&
+ (resolution <= this.maxResolution) );
+ }
+ }
+ return inRange;
+ },
+
+ /**
+ * APIMethod: setIsBaseLayer
+ *
+ * Parameters:
+ * @param {boolean} isBaseLayer
+ */
+ setIsBaseLayer: function(isBaseLayer) {
+ if (isBaseLayer != this.isBaseLayer) {
+ this.isBaseLayer = isBaseLayer;
+ if (this.map != null) {
+ this.map.events.triggerEvent("changebaselayer", {
+ layer: this
+ });
+ }
+ }
+ },
+
+ /********************************************************/
+ /* */
+ /* Baselayer Functions */
+ /* */
+ /********************************************************/
+
+ /**
+ * Method: initResolutions
+ * This method's responsibility is to set up the 'resolutions' array
+ * for the layer -- this array is what the layer will use to interface
+ * between the zoom levels of the map and the resolution display
+ * of the layer.
+ *
+ * The user has several options that determine how the array is set up.
+ *
+ * For a detailed explanation, see the following wiki from the
+ * openlayers.org homepage:
+ * http://trac.openlayers.org/wiki/SettingZoomLevels
+ */
+ initResolutions: function() {
+
+ // ok we want resolutions, here's our strategy:
+ //
+ // 1. if resolutions are defined in the layer config, use them
+ // 2. else, if scales are defined in the layer config then derive
+ // resolutions from these scales
+ // 3. else, attempt to calculate resolutions from maxResolution,
+ // minResolution, numZoomLevels, maxZoomLevel set in the
+ // layer config
+ // 4. if we still don't have resolutions, and if resolutions
+ // are defined in the same, use them
+ // 5. else, if scales are defined in the map then derive
+ // resolutions from these scales
+ // 6. else, attempt to calculate resolutions from maxResolution,
+ // minResolution, numZoomLevels, maxZoomLevel set in the
+ // map
+ // 7. hope for the best!
+
+ var i, len, p;
+ var props = {}, alwaysInRange = true;
+
+ // get resolution data from layer config
+ // (we also set alwaysInRange in the layer as appropriate)
+ for(i=0, len=this.RESOLUTION_PROPERTIES.length; i<len; i++) {
+ p = this.RESOLUTION_PROPERTIES[i];
+ props[p] = this.options[p];
+ if(alwaysInRange && this.options[p]) {
+ alwaysInRange = false;
+ }
+ }
+ if(this.alwaysInRange == null) {
+ this.alwaysInRange = alwaysInRange;
+ }
+
+ // if we don't have resolutions then attempt to derive them from scales
+ if(props.resolutions == null) {
+ props.resolutions = this.resolutionsFromScales(props.scales);
+ }
+
+ // if we still don't have resolutions then attempt to calculate them
+ if(props.resolutions == null) {
+ props.resolutions = this.calculateResolutions(props);
+ }
+
+ // if we couldn't calculate resolutions then we look at we have
+ // in the map
+ if(props.resolutions == null) {
+ for(i=0, len=this.RESOLUTION_PROPERTIES.length; i<len; i++) {
+ p = this.RESOLUTION_PROPERTIES[i];
+ props[p] = this.options[p] != null ?
+ this.options[p] : this.map[p];
+ }
+ if(props.resolutions == null) {
+ props.resolutions = this.resolutionsFromScales(props.scales);
+ }
+ if(props.resolutions == null) {
+ props.resolutions = this.calculateResolutions(props);
+ }
+ }
+
+ // ok, we new need to set properties in the instance
+
+ // get maxResolution from the config if it's defined there
+ var maxResolution;
+ if(this.options.maxResolution &&
+ this.options.maxResolution !== "auto") {
+ maxResolution = this.options.maxResolution;
+ }
+ if(this.options.minScale) {
+ maxResolution = OpenLayers.Util.getResolutionFromScale(
+ this.options.minScale, this.units);
+ }
+
+ // get minResolution from the config if it's defined there
+ var minResolution;
+ if(this.options.minResolution &&
+ this.options.minResolution !== "auto") {
+ minResolution = this.options.minResolution;
+ }
+ if(this.options.maxScale) {
+ minResolution = OpenLayers.Util.getResolutionFromScale(
+ this.options.maxScale, this.units);
+ }
+
+ if(props.resolutions) {
+
+ //sort resolutions array descendingly
+ props.resolutions.sort(function(a, b) {
+ return (b - a);
+ });
+
+ // if we still don't have a maxResolution get it from the
+ // resolutions array
+ if(!maxResolution) {
+ maxResolution = props.resolutions[0];
+ }
+
+ // if we still don't have a minResolution get it from the
+ // resolutions array
+ if(!minResolution) {
+ var lastIdx = props.resolutions.length - 1;
+ minResolution = props.resolutions[lastIdx];
+ }
+ }
+
+ this.resolutions = props.resolutions;
+ if(this.resolutions) {
+ len = this.resolutions.length;
+ this.scales = new Array(len);
+ for(i=0; i<len; i++) {
+ this.scales[i] = OpenLayers.Util.getScaleFromResolution(
+ this.resolutions[i], this.units);
+ }
+ this.numZoomLevels = len;
+ }
+ this.minResolution = minResolution;
+ if(minResolution) {
+ this.maxScale = OpenLayers.Util.getScaleFromResolution(
+ minResolution, this.units);
+ }
+ this.maxResolution = maxResolution;
+ if(maxResolution) {
+ this.minScale = OpenLayers.Util.getScaleFromResolution(
+ maxResolution, this.units);
+ }
+ },
+
+ /**
+ * Method: resolutionsFromScales
+ * Derive resolutions from scales.
+ *
+ * Parameters:
+ * @param {Array.<number>} scales Scales
+ *
+ * Returns
+ * {Array(Number)} Resolutions
+ */
+ resolutionsFromScales: function(scales) {
+ if(scales == null) {
+ return;
+ }
+ var resolutions, i, len;
+ len = scales.length;
+ resolutions = new Array(len);
+ for(i=0; i<len; i++) {
+ resolutions[i] = OpenLayers.Util.getResolutionFromScale(
+ scales[i], this.units);
+ }
+ return resolutions;
+ },
+
+ /**
+ * Method: calculateResolutions
+ * Calculate resolutions based on the provided properties.
+ *
+ * Parameters:
+ * @param {Object} props Properties
+ *
+ * Return:
+ * @return {Array.<Number>} Array of resolutions.
+ */
+ calculateResolutions: function(props) {
+
+ var viewSize, wRes, hRes;
+
+ // determine maxResolution
+ var maxResolution = props.maxResolution;
+ if(props.minScale != null) {
+ maxResolution =
+ OpenLayers.Util.getResolutionFromScale(props.minScale,
+ this.units);
+ } else if(maxResolution == "auto" && this.maxExtent != null) {
+ viewSize = this.map.getSize();
+ wRes = this.maxExtent.getWidth() / viewSize.w;
+ hRes = this.maxExtent.getHeight() / viewSize.h;
+ maxResolution = Math.max(wRes, hRes);
+ }
+
+ // determine minResolution
+ var minResolution = props.minResolution;
+ if(props.maxScale != null) {
+ minResolution =
+ OpenLayers.Util.getResolutionFromScale(props.maxScale,
+ this.units);
+ } else if(props.minResolution == "auto" && this.minExtent != null) {
+ viewSize = this.map.getSize();
+ wRes = this.minExtent.getWidth() / viewSize.w;
+ hRes = this.minExtent.getHeight()/ viewSize.h;
+ minResolution = Math.max(wRes, hRes);
+ }
+
+ // determine numZoomLevels
+ var maxZoomLevel = props.maxZoomLevel;
+ var numZoomLevels = props.numZoomLevels;
+ if(typeof minResolution === "number" &&
+ typeof maxResolution === "number" && numZoomLevels === undefined) {
+ var ratio = maxResolution / minResolution;
+ numZoomLevels = Math.floor(Math.log(ratio) / Math.log(2)) + 1;
+ } else if(numZoomLevels === undefined && maxZoomLevel != null) {
+ numZoomLevels = maxZoomLevel + 1;
+ }
+
+ // are we able to calculate resolutions?
+ if(typeof numZoomLevels !== "number" || numZoomLevels <= 0 ||
+ (typeof maxResolution !== "number" &&
+ typeof minResolution !== "number")) {
+ return;
+ }
+
+ // now we have numZoomLevels and at least one of maxResolution
+ // or minResolution, we can populate the resolutions array
+
+ var resolutions = new Array(numZoomLevels);
+ var base = 2;
+ if(typeof minResolution == "number" &&
+ typeof maxResolution == "number") {
+ // if maxResolution and minResolution are set, we calculate
+ // the base for exponential scaling that starts at
+ // maxResolution and ends at minResolution in numZoomLevels
+ // steps.
+ base = Math.pow(
+ (maxResolution / minResolution),
+ (1 / (numZoomLevels - 1))
+ );
+ }
+
+ var i;
+ if(typeof maxResolution === "number") {
+ for(i=0; i<numZoomLevels; i++) {
+ resolutions[i] = maxResolution / Math.pow(base, i);
+ }
+ } else {
+ for(i=0; i<numZoomLevels; i++) {
+ resolutions[numZoomLevels - 1 - i] =
+ minResolution * Math.pow(base, i);
+ }
+ }
+
+ return resolutions;
+ },
+
+ /**
+ * APIMethod: getResolution
+ *
+ * Returns:
+ * @return {number} The currently selected resolution of the map, taken from the
+ * resolutions array, indexed by current zoom level.
+ */
+ getResolution: function() {
+ var zoom = this.map.getZoom();
+ return this.getResolutionForZoom(zoom);
+ },
+
+ /**
+ * APIMethod: getExtent
+ *
+ * Returns:
+ * @return {OpenLayers.Bounds} A Bounds object which represents the lon/lat
+ * bounds of the current viewPort.
+ */
+ getExtent: function() {
+ // just use stock map calculateBounds function -- passing no arguments
+ // means it will user map's current center & resolution
+ //
+ return this.map.calculateBounds();
+ },
+
+ /**
+ * APIMethod: getZoomForExtent
+ *
+ * Parameters:
+ * @param {OpenLayers.Bounds} extent
+ * @param {boolean} closest Find the zoom level that most closely fits the
+ * specified bounds. Note that this may result in a zoom that does
+ * not exactly contain the entire extent.
+ * Default is false.
+ *
+ * Returns:
+ * @return {number} The index of the zoomLevel (entry in the resolutions array)
+ * for the passed-in extent. We do this by calculating the ideal
+ * resolution for the given extent (based on the map size) and then
+ * calling getZoomForResolution(), passing along the 'closest'
+ * parameter.
+ */
+ getZoomForExtent: function(extent, closest) {
+ var viewSize = this.map.getSize();
+ var idealResolution = Math.max( extent.getWidth() / viewSize.w,
+ extent.getHeight() / viewSize.h );
+
+ return this.getZoomForResolution(idealResolution, closest);
+ },
+
+ /**
+ * Method: getDataExtent
+ * Calculates the max extent which includes all of the data for the layer.
+ * This function is to be implemented by subclasses.
+ *
+ * Returns:
+ * @return {OpenLayers.Bounds}
+ */
+ getDataExtent: function () {
+ //to be implemented by subclasses
+ },
+
+ /**
+ * APIMethod: getResolutionForZoom
+ *
+ * Parameter:
+ * @param {number} zoom
+ *
+ * Returns:
+ * @return {number} A suitable resolution for the specified zoom.
+ */
+ getResolutionForZoom: function(zoom) {
+ zoom = Math.max(0, Math.min(zoom, this.resolutions.length - 1));
+ var resolution;
+ if(this.map.fractionalZoom) {
+ var low = Math.floor(zoom);
+ var high = Math.ceil(zoom);
+ resolution = this.resolutions[low] -
+ ((zoom-low) * (this.resolutions[low]-this.resolutions[high]));
+ } else {
+ resolution = this.resolutions[Math.round(zoom)];
+ }
+ return resolution;
+ },
+
+ /**
+ * APIMethod: getZoomForResolution
+ *
+ * Parameters:
+ * @param {number} resolution
+ * @param {boolean} closest Find the zoom level that corresponds to the absolute
+ * closest resolution, which may result in a zoom whose corresponding
+ * resolution is actually smaller than we would have desired (if this
+ * is being called from a getZoomForExtent() call, then this means that
+ * the returned zoom index might not actually contain the entire
+ * extent specified... but it'll be close).
+ * Default is false.
+ *
+ * Returns:
+ * @return {number} The index of the zoomLevel (entry in the resolutions array)
+ * that corresponds to the best fit resolution given the passed in
+ * value and the 'closest' specification.
+ */
+ getZoomForResolution: function(resolution, closest) {
+ var zoom, i, len;
+ if(this.map.fractionalZoom) {
+ var lowZoom = 0;
+ var highZoom = this.resolutions.length - 1;
+ var highRes = this.resolutions[lowZoom];
+ var lowRes = this.resolutions[highZoom];
+ var res;
+ for(i=0, len=this.resolutions.length; i<len; ++i) {
+ res = this.resolutions[i];
+ if(res >= resolution) {
+ highRes = res;
+ lowZoom = i;
+ }
+ if(res <= resolution) {
+ lowRes = res;
+ highZoom = i;
+ break;
+ }
+ }
+ var dRes = highRes - lowRes;
+ if(dRes > 0) {
+ zoom = lowZoom + ((highRes - resolution) / dRes);
+ } else {
+ zoom = lowZoom;
+ }
+ } else {
+ var diff;
+ var minDiff = Number.POSITIVE_INFINITY;
+ for(i=0, len=this.resolutions.length; i<len; i++) {
+ if (closest) {
+ diff = Math.abs(this.resolutions[i] - resolution);
+ if (diff > minDiff) {
+ break;
+ }
+ minDiff = diff;
+ } else {
+ if (this.resolutions[i] < resolution) {
+ break;
+ }
+ }
+ }
+ zoom = Math.max(0, i-1);
+ }
+ return zoom;
+ },
+
+ /**
+ * APIMethod: getLonLatFromViewPortPx
+ *
+ * Parameters:
+ * @param {OpenLayers.Pixel} viewPortPx
+ *
+ * Returns:
+ * @return {OpenLayers.LonLat} An OpenLayers.LonLat which is the passed-in
+ * view port <OpenLayers.Pixel>, translated into lon/lat by the layer.
+ */
+ getLonLatFromViewPortPx: function (viewPortPx) {
+ var lonlat = null;
+ var map = this.map;
+ if (viewPortPx != null && map.minPx) {
+ var res = map.getResolution();
+ var maxExtent = map.getMaxExtent({restricted: true});
+ var lon = (viewPortPx.x - map.minPx.x) * res + maxExtent.left;
+ var lat = (map.minPx.y - viewPortPx.y) * res + maxExtent.top;
+ lonlat = new OpenLayers.LonLat(lon, lat);
+
+ if (this.wrapDateLine) {
+ lonlat = lonlat.wrapDateLine(this.maxExtent);
+ }
+ }
+ return lonlat;
+ },
+
+ /**
+ * APIMethod: getViewPortPxFromLonLat
+ * Returns a pixel location given a map location. This method will return
+ * fractional pixel values.
+ *
+ * Parameters:
+ * @param {OpenLayers.LonLat} lonlat
+ *
+ * Returns:
+ * @return {OpenLayers.Pixel} An <OpenLayers.Pixel> which is the passed-in
+ * <OpenLayers.LonLat>,translated into view port pixels.
+ */
+ getViewPortPxFromLonLat: function (lonlat) {
+ var px = null;
+ if (lonlat != null) {
+ var resolution = this.map.getResolution();
+ var extent = this.map.getExtent();
+ px = new OpenLayers.Pixel(
+ (1/resolution * (lonlat.lon - extent.left)),
+ (1/resolution * (extent.top - lonlat.lat))
+ );
+ }
+ return px;
+ },
+
+ /**
+ * APIMethod: setOpacity
+ * Sets the opacity for the entire layer (all images)
+ *
+ * Parameter:
+ * @param {number} opacity
+ */
+ setOpacity: function(opacity) {
+ if (opacity != this.opacity) {
+ this.opacity = opacity;
+ for(var i=0, len=this.div.childNodes.length; i<len; ++i) {
+ var element = this.div.childNodes[i].firstChild;
+ OpenLayers.Util.modifyDOMElement(element, null, null, null,
+ null, null, null, opacity);
+ }
+ if (this.map != null) {
+ this.map.events.triggerEvent("changelayer", {
+ layer: this,
+ property: "opacity"
+ });
+ }
+ }
+ },
+
+ /**
+ * Method: getZIndex
+ *
+ * Returns:
+ * @return {number} the z-index of this layer
+ */
+ getZIndex: function () {
+ return this.div.style.zIndex;
+ },
+
+ /**
+ * Method: setZIndex
+ *
+ * Parameters:
+ * @param {number} zIndex
+ */
+ setZIndex: function (zIndex) {
+ this.div.style.zIndex = zIndex;
+ },
+
+ /**
+ * Method: adjustBounds
+ * This function will take a bounds, and if wrapDateLine option is set
+ * on the layer, it will return a bounds which is wrapped around the
+ * world. We do not wrap for bounds which *cross* the
+ * maxExtent.left/right, only bounds which are entirely to the left
+ * or entirely to the right.
+ *
+ * Parameters:
+ * @param {OpenLayers.Bounds} bounds
+ */
+ adjustBounds: function (bounds) {
+
+ if (this.gutter) {
+ // Adjust the extent of a bounds in map units by the
+ // layer's gutter in pixels.
+ var mapGutter = this.gutter * this.map.getResolution();
+ bounds = new OpenLayers.Bounds(bounds.left - mapGutter,
+ bounds.bottom - mapGutter,
+ bounds.right + mapGutter,
+ bounds.top + mapGutter);
+ }
+
+ if (this.wrapDateLine) {
+ // wrap around the date line, within the limits of rounding error
+ var wrappingOptions = {
+ 'rightTolerance':this.getResolution(),
+ 'leftTolerance':this.getResolution()
+ };
+ bounds = bounds.wrapDateLine(this.maxExtent, wrappingOptions);
+
+ }
+ return bounds;
+ },
+
+ CLASS_NAME: "OpenLayers.Layer"
+});
More information about the Commits
mailing list