Merge branch 'master' of github.com:openlayers/openlayers into convenience

This commit is contained in:
tschaub
2011-11-08 08:44:33 -07:00
31 changed files with 1191 additions and 620 deletions
-1
View File
@@ -121,7 +121,6 @@
"OpenLayers/Marker/Box.js",
"OpenLayers/Popup.js",
"OpenLayers/Tile.js",
"OpenLayers/Tile/BackBufferable.js",
"OpenLayers/Tile/Image.js",
"OpenLayers/Tile/Image/IFrame.js",
"OpenLayers/Tile/WFS.js",
+24 -4
View File
@@ -171,12 +171,24 @@ OpenLayers.Format.OWSCommon.v1 = OpenLayers.Class(OpenLayers.Format.XML, {
this.readChildNodes(node, dcp.http);
},
"Get": function(node, http) {
http.get = this.getAttributeNS(node,
this.namespaces.xlink, "href");
if (!http.get) {
http.get = [];
}
var obj = {
url: this.getAttributeNS(node, this.namespaces.xlink, "href")
};
this.readChildNodes(node, obj);
http.get.push(obj);
},
"Post": function(node, http) {
http.post = this.getAttributeNS(node,
this.namespaces.xlink, "href");
if (!http.post) {
http.post = [];
}
var obj = {
url: this.getAttributeNS(node, this.namespaces.xlink, "href")
};
this.readChildNodes(node, obj);
http.post.push(obj);
},
"Parameter": function(node, operation) {
if (!operation.parameters) {
@@ -186,6 +198,14 @@ OpenLayers.Format.OWSCommon.v1 = OpenLayers.Class(OpenLayers.Format.XML, {
operation.parameters[name] = {};
this.readChildNodes(node, operation.parameters[name]);
},
"Constraint": function(node, obj) {
if (!obj.constraints) {
obj.constraints = {};
}
var name = node.getAttribute("name");
obj.constraints[name] = {};
this.readChildNodes(node, obj.constraints[name]);
},
"Value": function(node, allowedValues) {
allowedValues[this.getChildValue(node)] = true;
},
+5 -2
View File
@@ -114,10 +114,13 @@ OpenLayers.Format.WMTSCapabilities = OpenLayers.Class(OpenLayers.Format.XML.Vers
layer = new OpenLayers.Layer.WMTS(
OpenLayers.Util.applyDefaults(config, {
url: capabilities.operationsMetadata.GetTile.dcp.http.get,
url: config.requestEncoding === "REST" && layerDef.resourceUrl ?
layerDef.resourceUrl.tile.template :
capabilities.operationsMetadata.GetTile.dcp.http.get[0].url,
name: layerDef.title,
style: style.identifier,
matrixIds: matrixSet.matrixIds
matrixIds: matrixSet.matrixIds,
tileFullExtent: matrixSet.bounds
})
);
}
-7
View File
@@ -314,13 +314,6 @@ OpenLayers.Layer = OpenLayers.Class({
*/
transitionEffect: null,
/**
* Property: SUPPORTED_TRANSITIONS
* {Array} An immutable (that means don't change it!) list of supported
* transitionEffect values.
*/
SUPPORTED_TRANSITIONS: ['resize'],
/**
* Property: metadata
* {Object} This object can be used to store additional information on a
+162 -11
View File
@@ -111,6 +111,34 @@ OpenLayers.Layer.Grid = OpenLayers.Class(OpenLayers.Layer.HTTPRequest, {
*/
timerId: null,
/**
* Property: backBuffer
* {DOMElement} The back buffer.
*/
backBuffer: null,
/**
* Property: gridResolution
* {Number} The resolution of the current grid. Used for backbuffering.
* This property is updated each the grid is initialized.
*/
gridResolution: null,
/**
* Property: backBufferResolution
* {Number} The resolution of the current back buffer. This property is
* updated each time a back buffer is created.
*/
backBufferResolution: null,
/**
* Property: backBufferLonLat
* {Object} The top-left corner of the current back buffer. Includes lon
* and lat properties. This object is updated each time a back buffer
* is created.
*/
backBufferLonLat: null,
/**
* Constructor: OpenLayers.Layer.Grid
* Create a new grid layer
@@ -133,7 +161,7 @@ OpenLayers.Layer.Grid = OpenLayers.Class(OpenLayers.Layer.HTTPRequest, {
this.events.addEventType("tileloaded");
this.grid = [];
this._moveGriddedTiles = OpenLayers.Function.bind(
this.moveGriddedTiles, this
);
@@ -159,6 +187,9 @@ OpenLayers.Layer.Grid = OpenLayers.Class(OpenLayers.Layer.HTTPRequest, {
*/
destroy: function() {
this.clearGrid();
// clearGrid should remove any back buffer from the layer,
// so no need to call removeBackBuffer here
this.grid = null;
this.tileSize = null;
OpenLayers.Layer.HTTPRequest.prototype.destroy.apply(this, arguments);
@@ -180,6 +211,7 @@ OpenLayers.Layer.Grid = OpenLayers.Class(OpenLayers.Layer.HTTPRequest, {
}
}
this.grid = [];
this.gridResolution = null;
}
},
@@ -212,6 +244,7 @@ OpenLayers.Layer.Grid = OpenLayers.Class(OpenLayers.Layer.HTTPRequest, {
// we do not want to copy reference to grid, so we make a new array
obj.grid = [];
obj.gridResolution = null;
return obj;
},
@@ -240,14 +273,37 @@ OpenLayers.Layer.Grid = OpenLayers.Class(OpenLayers.Layer.HTTPRequest, {
// total bounds of the tiles
var tilesBounds = this.getTilesBounds();
// the new map resolution
var resolution = this.map.getResolution();
// the server-supported resolution for the new map resolution
var serverResolution = this.getServerResolution(resolution);
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))) {
// In single tile mode with no transition effect, we insert
// a non-scaled backbuffer when the layer is moved. But if
// a zoom occurs right after a move, i.e. before the new
// image is received, we need to remove the backbuffer, or
// an ill-positioned image will be visible during the zoom
// transition.
if(zoomChanged && this.transitionEffect !== 'resize') {
this.removeBackBuffer();
}
if(!zoomChanged || this.transitionEffect === 'resize') {
this.applyBackBuffer(serverResolution);
}
this.initSingleTile(bounds);
}
} else {
@@ -260,10 +316,6 @@ OpenLayers.Layer.Grid = OpenLayers.Class(OpenLayers.Layer.HTTPRequest, {
forceReTile = forceReTile ||
!tilesBounds.containsBounds(bounds, true);
var resolution = this.map.getResolution();
var serverResolution =
this.getServerResolution(resolution);
if(resolution !== serverResolution) {
bounds = this.map.calculateBounds(null, serverResolution);
if(forceReTile) {
@@ -281,6 +333,9 @@ OpenLayers.Layer.Grid = OpenLayers.Class(OpenLayers.Layer.HTTPRequest, {
}
if(forceReTile) {
if(zoomChanged && this.transitionEffect === 'resize') {
this.applyBackBuffer(serverResolution);
}
this.initGriddedTiles(bounds);
} else {
this.scheduleMoveGriddedTiles();
@@ -306,7 +361,7 @@ OpenLayers.Layer.Grid = OpenLayers.Class(OpenLayers.Layer.HTTPRequest, {
if(this.serverResolutions &&
OpenLayers.Util.indexOf(this.serverResolutions, resolution) === -1) {
var i, serverResolution;
for(var i=this.serverResolutions.length-1; i>= 0; i--) {
for(i=this.serverResolutions.length-1; i>= 0; i--) {
serverResolution = this.serverResolutions[i];
if(serverResolution > resolution) {
resolution = serverResolution;
@@ -352,14 +407,13 @@ OpenLayers.Layer.Grid = OpenLayers.Class(OpenLayers.Layer.HTTPRequest, {
var size = this.map.getSize();
var lcX = parseInt(this.map.layerContainerDiv.style.left, 10);
var lcY = parseInt(this.map.layerContainerDiv.style.top, 10);
var x = (lcX - (size.w / 2.)) * (scale - 1);
var y = (lcY - (size.h / 2.)) * (scale - 1);
var x = (lcX - (size.w / 2.0)) * (scale - 1);
var y = (lcY - (size.h / 2.0)) * (scale - 1);
this.div.style.left = x + '%';
this.div.style.top = y + '%';
},
/**
* Method: getResolutionScale
* Return the value by which the layer is currently scaled.
@@ -371,6 +425,96 @@ OpenLayers.Layer.Grid = OpenLayers.Class(OpenLayers.Layer.HTTPRequest, {
return parseInt(this.div.style.width, 10) / 100;
},
/**
* Method: applyBackBuffer
* Create, insert, scale and position a back buffer for the layer.
*
* Parameters:
* resolution - {Number} The resolution to transition to.
*/
applyBackBuffer: function(resolution) {
var backBuffer = this.backBuffer;
if(!backBuffer) {
backBuffer = this.createBackBuffer();
if(!backBuffer) {
return;
}
this.div.insertBefore(backBuffer, this.div.firstChild);
this.backBuffer = backBuffer;
// set some information in the instance for subsequent
// calls to applyBackBuffer where the same back buffer
// is reused
var topLeftTileBounds = this.grid[0][0].bounds;
this.backBufferLonLat = {
lon: topLeftTileBounds.left,
lat: topLeftTileBounds.top
};
this.backBufferResolution = this.gridResolution;
}
var style = backBuffer.style;
// scale the back buffer
var ratio = this.backBufferResolution / resolution;
style.width = 100 * ratio + '%';
style.height = 100 * ratio + '%';
// and position it (based on the grid's top-left corner)
var position = this.getViewPortPxFromLonLat(
this.backBufferLonLat, resolution);
var leftOffset = parseInt(this.map.layerContainerDiv.style.left, 10);
var topOffset = parseInt(this.map.layerContainerDiv.style.top, 10);
backBuffer.style.left = (position.x - leftOffset) + '%';
backBuffer.style.top = (position.y - topOffset) + '%';
},
/**
* Method: createBackBuffer
* Create a back buffer.
*
* Returns:
* {DOMElement} The DOM element for the back buffer, undefined if the
* grid isn't initialized yet.
*/
createBackBuffer: function() {
var backBuffer;
if(this.grid.length > 0) {
backBuffer = document.createElement('div');
backBuffer.id = this.div.id + '_bb';
backBuffer.className = 'olBackBuffer';
backBuffer.style.position = 'absolute';
backBuffer.style.width = '100%';
backBuffer.style.height = '100%';
for(var i=0, lenI=this.grid.length; i<lenI; i++) {
for(var j=0, lenJ=this.grid[i].length; j<lenJ; j++) {
var tile = this.grid[i][j].createBackBuffer();
if(!tile) {
continue;
}
// to be able to correctly position the back buffer we
// place the tiles grid at (0, 0) in the back buffer
tile.style.top = (i * this.tileSize.h) + '%';
tile.style.left = (j * this.tileSize.w) + '%';
backBuffer.appendChild(tile);
}
}
}
return backBuffer;
},
/**
* Method: removeBackBuffer
* Remove back buffer from DOM.
*/
removeBackBuffer: function() {
if(this.backBuffer && this.backBuffer.parentNode) {
this.div.removeChild(this.backBuffer);
this.backBuffer = null;
this.backBufferResolution = null;
}
},
/**
* Method: moveByPx
* Move the layer based on pixel vector.
@@ -500,6 +644,9 @@ OpenLayers.Layer.Grid = OpenLayers.Class(OpenLayers.Layer.HTTPRequest, {
//remove all but our single tile
this.removeExcessTiles(1,1);
// store the resolution of the grid
this.gridResolution = this.getServerResolution();
},
/**
@@ -660,6 +807,9 @@ OpenLayers.Layer.Grid = OpenLayers.Class(OpenLayers.Layer.HTTPRequest, {
//shave off exceess rows and colums
this.removeExcessTiles(rowidx, colidx);
// store the resolution of the grid
this.gridResolution = this.getServerResolution();
//now actually draw the tiles
this.spiralTileLoad();
},
@@ -790,6 +940,7 @@ OpenLayers.Layer.Grid = OpenLayers.Class(OpenLayers.Layer.HTTPRequest, {
//if that was the last tile, then trigger a 'loadend' on the layer
if (this.numLoadingTiles == 0) {
this.events.triggerEvent("loadend");
this.removeBackBuffer();
}
};
tile.events.register("loadend", this, tile.onLoadEnd);
@@ -993,6 +1144,6 @@ OpenLayers.Layer.Grid = OpenLayers.Class(OpenLayers.Layer.HTTPRequest, {
tileLeft + tileMapWidth,
tileBottom + tileMapHeight);
},
CLASS_NAME: "OpenLayers.Layer.Grid"
});
+48 -25
View File
@@ -38,7 +38,10 @@ OpenLayers.Layer.WMTS = OpenLayers.Class(OpenLayers.Layer.Grid, {
/**
* APIProperty: url
* {String} The base URL for the WMTS service. Must be provided.
* {String|Array(String)} The base URL or request URL template for the WMTS
* service. Must be provided. Array is only supported for base URLs, not
* for request URL templates. URL templates are only supported for
* REST <requestEncoding>.
*/
url: null,
@@ -416,39 +419,59 @@ OpenLayers.Layer.WMTS = OpenLayers.Class(OpenLayers.Layer.Grid, {
var center = bounds.getCenterLonLat();
var info = this.getTileInfo(center);
var matrixId = this.matrix.identifier;
var dimensions = this.dimensions, params;
if (this.requestEncoding.toUpperCase() === "REST") {
// include 'version', 'layer' and 'style' in tile resource url
var path = this.version + "/" + this.layer + "/" + this.style + "/";
// append optional dimension path elements
if (this.dimensions) {
for (var i=0; i<this.dimensions.length; i++) {
if (this.params[this.dimensions[i]]) {
path = path + this.params[this.dimensions[i]] + "/";
params = this.params;
if (typeof this.url === "string" && this.url.indexOf("{") !== -1) {
var template = this.url.replace(/\{/g, "${");
var context = {
// spec does not make clear if capital S or not
style: this.style, Style: this.style,
TileMatrixSet: this.matrixSet,
TileMatrix: this.matrix.identifier,
TileRow: info.row,
TileCol: info.col
};
if (dimensions) {
var dimension, i;
for (i=dimensions.length-1; i>=0; --i) {
dimension = dimensions[i];
context[dimension] = params[dimension.toUpperCase()];
}
}
}
// append other required path elements
path = path + this.matrixSet + "/" + this.matrix.identifier +
"/" + info.row + "/" + info.col + "." + this.formatSuffix;
if (OpenLayers.Util.isArray(this.url)) {
url = this.selectUrl(path, this.url);
url = OpenLayers.String.format(template, context);
} else {
url = this.url;
}
if (!url.match(/\/$/)) {
url = url + "/";
}
url = url + path;
// include 'version', 'layer' and 'style' in tile resource url
var path = this.version + "/" + this.layer + "/" + this.style + "/";
// append optional dimension path elements
if (dimensions) {
for (var i=0; i<dimensions.length; i++) {
if (params[dimensions[i]]) {
path = path + params[dimensions[i]] + "/";
}
}
}
// append other required path elements
path = path + this.matrixSet + "/" + this.matrix.identifier +
"/" + info.row + "/" + info.col + "." + this.formatSuffix;
if (OpenLayers.Util.isArray(this.url)) {
url = this.selectUrl(path, this.url);
} else {
url = this.url;
}
if (!url.match(/\/$/)) {
url = url + "/";
}
url = url + path;
}
} else if (this.requestEncoding.toUpperCase() === "KVP") {
// assemble all required parameters
var params = {
params = {
SERVICE: "WMTS",
REQUEST: "GetTile",
VERSION: this.version,
+1 -1
View File
@@ -513,7 +513,7 @@ OpenLayers.Popup = OpenLayers.Class({
this.contentDiv.innerHTML +
"</div>";
var containerElement = (this.map) ? this.map.layerContainerDiv
var containerElement = (this.map) ? this.map.div
: document.body;
var realSize = OpenLayers.Util.getRenderedDimensions(
preparedHTML, null, {
-218
View File
@@ -1,218 +0,0 @@
/* 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/Tile.js
* @requires OpenLayers/Util.js
*/
/**
* Class: OpenLayers.Tile.BackBufferable
* Base class for tiles that can have backbuffers during transitions. Do not
* create instances of this class.
*/
OpenLayers.Tile.BackBufferable = OpenLayers.Class(OpenLayers.Tile, {
/**
* Property: backBufferMode
* {Integer} Bitmap: 0 for no backbuffering at all, 1 for singleTile
* layers, 2 for transition effect set, 3 for both.
*/
backBufferMode: null,
/**
* Property: backBufferData
* {Object} Object including the necessary data for the back
* buffer.
*
* The object includes three properties:
* tile - {DOMElement} The DOM element for the back buffer.
* bounds - {<OpenLayers.Bounds>} The bounds of the tile to back.
* resolution - {Number} The resolution of the tile to back.
*/
backBufferData: null,
/**
* Method: initialize
* Determines the backBuffer mode and registers events
*/
initialize: function() {
OpenLayers.Tile.prototype.initialize.apply(this, arguments);
var transitionSupported = OpenLayers.Util.indexOf(
this.layer.SUPPORTED_TRANSITIONS,
this.layer.transitionEffect) != -1;
this.backBufferMode = (this.layer.singleTile && 1) |
(transitionSupported && 2);
this.backBufferData = {};
if (!this.size) {
this.size = new OpenLayers.Size(256, 256);
}
},
/**
* Method: draw
* Check that a tile should be drawn, and draw it.
*
* Returns:
* {Boolean} Was a tile drawn?
*/
draw: function() {
var draw = OpenLayers.Tile.prototype.shouldDraw.apply(this, arguments);
if (draw) {
this.updateBackBuffer();
}
this.clear();
if (!draw) {
this.resetBackBuffer();
};
return draw;
},
/**
* Method: getTile
* Get the tile's markup. To be implemented by subclasses.
*
* Returns:
* {DOMElement} The tile's markup
*/
/**
* Method: createBackBuffer
* Create a copy of this tile's markup for the back buffer. To be
* implemented by subclasses.
*
* Returns:
* {DOMElement} A copy of the tile's markup.
*/
/**
* Method: getTileResolution
* Get the tile's actual resolution.
*
* Returns:
* {Number}
*/
getTileResolution: function() {
var layer = this.layer,
map = layer.map,
mapResolution = map.getResolution();
return layer.getServerResolution ?
layer.getServerResolution(mapResolution) :
mapResolution;
},
/**
* Method: setBackBufferData
* Stores the current bounds and resolution, for offset and ratio
* calculations
*/
setBackBufferData: function() {
this.backBufferData = OpenLayers.Util.extend(this.backBufferData, {
bounds: this.bounds,
resolution: this.getTileResolution()
});
},
/**
* Method: updateBackBuffer
* Update the <backBufferData>, and return a new or reposition the
* backBuffer. When a backbuffer is returned, the tile's markup is not
* available any more.
*
* Returns:
* {HTMLDivElement} the tile's markup in a cloned element, or undefined if
* no backbuffer is currently available or needed
*/
updateBackBuffer: function() {
var layer = this.layer, map = layer.map,
backBufferMode = this.backBufferMode,
data = this.backBufferData,
tile = this.getTile(),
backBuffer = data.tile,
prevResolution = data.resolution,
nextResolution = this.getTileResolution(),
ratio = prevResolution ? prevResolution / nextResolution : 1,
// Cases where we don't position and return a back buffer, but only
// update backBufferData and return undefined:
// (1) current ratio and backBufferMode dont't require a backbuffer
notNeeded = !(ratio == 1 ? backBufferMode & 1 : backBufferMode & 2),
// (2) the tile is not appended to the layer's div
noParent = tile && tile.parentNode !== layer.div,
// (3) we don't have a tile available that we could use as buffer
noTile = !(tile && tile.childNodes.length > 0),
// (4) no backbuffer is displayed for a tile that's still loading
noBackBuffer = !backBuffer && this.isLoading;
if (notNeeded || noParent || noTile || noBackBuffer) {
this.setBackBufferData();
return;
}
// Create a back buffer tile and add it to the DOM
if (!backBuffer) {
backBuffer = this.insertBackBuffer();
// some browsers fire the onload event before the image is
// displayed, so we keep the buffer until the whole layer finished
// loading to avoid visual glitches
layer.events.register("loadend", this, this.resetBackBuffer);
data.tile = backBuffer;
}
// Position the back buffer now that we have one
var lonLat = {lon: data.bounds.left, lat: data.bounds.top},
position = layer.getViewPortPxFromLonLat(lonLat, nextResolution),
containerStyle = map.layerContainerDiv.style,
leftOffset = parseInt(containerStyle.left, 10),
topOffset = parseInt(containerStyle.top, 10),
style = backBuffer.style;
style.left = (position.x - leftOffset) + "%";
style.top = (position.y - topOffset) + "%";
style.width = (this.size.w * ratio) + "%";
style.height = (this.size.h * ratio) + "%";
return backBuffer;
},
/**
* Method: resetBackBuffer
* Handler for the layer's loadend event.
*/
resetBackBuffer: function() {
this.layer.events.unregister("loadend", this, this.resetBackBuffer);
this.removeBackBuffer();
this.setBackBufferData();
},
/**
* Method: removeBackBuffer
* Removes the backBuffer for this tile.
*/
removeBackBuffer: function() {
var backBufferData = this.backBufferData;
var backBuffer = backBufferData.tile;
delete backBufferData.tile;
var parent = backBuffer && backBuffer.parentNode;
if (backBuffer) {
parent.removeChild(backBuffer);
}
},
/**
* APIMethod: destroy
* nullify references to prevent circular references and memory leaks
*/
destroy: function() {
this.removeBackBuffer();
this.layer.events.unregister("loadend", this, this.resetBackBuffer);
this.backBufferData = null;
OpenLayers.Tile.prototype.destroy.apply(this, arguments);
}
});
+19 -15
View File
@@ -5,7 +5,7 @@
/**
* @requires OpenLayers/Tile/BackBufferable.js
* @requires OpenLayers/Tile.js
*/
/**
@@ -15,9 +15,9 @@
* <OpenLayers.Tile.Image> constructor.
*
* Inherits from:
* - <OpenLayers.Tile.BackBufferable>
* - <OpenLayers.Tile>
*/
OpenLayers.Tile.Image = OpenLayers.Class(OpenLayers.Tile.BackBufferable, {
OpenLayers.Tile.Image = OpenLayers.Class(OpenLayers.Tile, {
/**
* Property: url
@@ -96,7 +96,7 @@ OpenLayers.Tile.Image = OpenLayers.Class(OpenLayers.Tile.BackBufferable, {
* options - {Object}
*/
initialize: function(layer, position, bounds, url, size, options) {
OpenLayers.Tile.BackBufferable.prototype.initialize.apply(this, arguments);
OpenLayers.Tile.prototype.initialize.apply(this, arguments);
this.url = url; //deprecated remove me
@@ -123,7 +123,7 @@ OpenLayers.Tile.Image = OpenLayers.Class(OpenLayers.Tile.BackBufferable, {
}
// don't handle async requests any more
this.asyncRequestId = null;
OpenLayers.Tile.BackBufferable.prototype.destroy.apply(this, arguments);
OpenLayers.Tile.prototype.destroy.apply(this, arguments);
},
/**
@@ -134,7 +134,7 @@ OpenLayers.Tile.Image = OpenLayers.Class(OpenLayers.Tile.BackBufferable, {
* {Boolean} Was a tile drawn?
*/
draw: function() {
var drawn = OpenLayers.Tile.BackBufferable.prototype.draw.apply(this, arguments);
var drawn = OpenLayers.Tile.prototype.draw.apply(this, arguments);
if (drawn) {
if (this.layer != this.layer.map.baseLayer && this.layer.reproject) {
this.bounds = this.getBoundsFromBaseLayer(this.position);
@@ -320,19 +320,23 @@ OpenLayers.Tile.Image = OpenLayers.Class(OpenLayers.Tile.BackBufferable, {
},
/**
* Method: insertBackBuffer
* Create a copy of this tile's markup and insert it to the layer
* div.
* Method: createBackBuffer
* Create a backbuffer for this tile. A backbuffer isn't exactly a clone
* of the tile's markup, because we want to avoid the reloading of the
* image. So we clone the frame, and steal the image from the tile.
*
* Returns:
* {DOMElement} The back buffer.
* {DOMElement} The markup, or undefined if the tile has no image
* or if it's currently loading.
*/
insertBackBuffer: function() {
var frame = this.frame.cloneNode(false);
this.layer.div.insertBefore(frame, this.frame);
frame.appendChild(this.imgDiv);
createBackBuffer: function() {
if(!this.imgDiv || this.isLoading) {
return;
}
var backBuffer = this.frame.cloneNode(false);
backBuffer.appendChild(this.imgDiv);
this.imgDiv = null;
return frame;
return backBuffer;
},
/**
+59 -34
View File
@@ -15,9 +15,6 @@
*
* This mixin will be applied to <OpenLayers.Tile.Image> instances
* configured with <OpenLayers.Tile.Image.maxGetUrlLength> set.
*
* Inherits from:
* - <OpenLayers.Tile.Image>
*/
OpenLayers.Tile.Image.IFrame = {
@@ -29,40 +26,52 @@ OpenLayers.Tile.Image.IFrame = {
useIFrame: null,
/**
* Method: updateBackBuffer
* Update the <backBufferData>, and return a new or reposition the
* backBuffer. When a backbuffer is returned, the tile's markup is not
* available any more.
*
* Returns:
* {HTMLDivElement} the tile's markup in a cloned element, or undefined if
* no backbuffer is currently available or needed
* Method: draw
* Set useIFrame in the instance, and operate the image/iframe switch.
* Then call Tile.Image.draw.
*
* Returns:
* {Boolean}
*/
updateBackBuffer: function() {
this.url = this.layer.getURL(this.bounds);
var usedIFrame = this.useIFrame;
this.useIFrame = this.maxGetUrlLength !== null && !this.layer.async &&
this.url.length > this.maxGetUrlLength;
var fromIFrame = usedIFrame && !this.useIFrame;
var toIFrame = !usedIFrame && this.useIFrame;
if (fromIFrame || toIFrame) {
// switch between get (image) and post (iframe)
this.clear();
if (this.imgDiv && this.imgDiv.parentNode === this.frame) {
this.frame.removeChild(this.imgDiv);
}
this.imgDiv = null;
if (fromIFrame) {
// remove eventPane
this.frame.removeChild(this.frame.firstChild);
this.resetBackBuffer();
draw: function() {
var draw = OpenLayers.Tile.Image.prototype.shouldDraw.call(this);
if(draw) {
// this.url isn't set to the currect value yet, so we call getURL
// on the layer and store the result in a local variable
var url = this.layer.getURL(this.bounds);
var usedIFrame = this.useIFrame;
this.useIFrame = this.maxGetUrlLength !== null &&
!this.layer.async &&
url.length > this.maxGetUrlLength;
var fromIFrame = usedIFrame && !this.useIFrame;
var toIFrame = !usedIFrame && this.useIFrame;
if(fromIFrame || toIFrame) {
// Switching between GET (image) and POST (iframe).
// We remove the imgDiv (really either an image or an iframe)
// from the frame and set it to null to make sure initImage
// will call createImage.
if(this.imgDiv && this.imgDiv.parentNode === this.frame) {
this.frame.removeChild(this.imgDiv);
}
this.imgDiv = null;
// And if we had an iframe we also remove the event pane.
if(fromIFrame) {
this.frame.removeChild(this.frame.firstChild);
}
}
}
if (!this.useIFrame) {
OpenLayers.Tile.Image.prototype.updateBackBuffer.apply(this, arguments);
}
return OpenLayers.Tile.Image.prototype.draw.apply(this, arguments);
},
/**
* Method: createImage
* Creates the content for the frame on the tile.
@@ -183,6 +192,22 @@ OpenLayers.Tile.Image.IFrame = {
} else {
OpenLayers.Tile.Image.prototype.setImgSrc.apply(this, arguments);
}
}
},
/**
* Method: createBackBuffer
* Override createBackBuffer to do nothing when we use an iframe. Moving an
* iframe from one element to another makes it necessary to reload the iframe
* because its content is lost. So we just give up.
*
* Returns:
* {DOMElement}
*/
createBackBuffer: function() {
var backBuffer;
if(!this.useIFrame) {
backBuffer = OpenLayers.Tile.Image.prototype.createBackBuffer.call(this);
}
return backBuffer;
}
};