1
/* Copyright (c) 2006-2008 MetaCarta, Inc., published under the Clear BSD
2
* license. See http://svn.openlayers.org/trunk/openlayers/license.txt for the
3
* full text of the license. */
7
* @requires OpenLayers/Tile/Image.js
11
* Class: OpenLayers.Tile.Image.IFrame
12
* Instances of OpenLayers.Tile.Image.IFrame are used to manage the image tiles
13
* used by Layer.WMS.Post loaded via HTTP-POST-protocol. Create a new image
14
* tile with the <OpenLayers.Tile.Image.IFrame> constructor.
17
* - <OpenLayers.Tile.Image>
19
OpenLayers.Tile.Image.IFrame = OpenLayers.Class(OpenLayers.Tile.Image, {
22
* Property: layerAlphaHack
23
* {Boolean} Always false for an instance.
27
* Constructor: OpenLayers.Tile.Image.IFrame
28
* Constructor for a new <OpenLayers.Tile.Image.IFrame> instance.
31
* layer - {<OpenLayers.Layer>} layer that the tile will go in.
32
* position - {<OpenLayers.Pixel>}
33
* bounds - {<OpenLayers.Bounds>}
34
* size - {<OpenLayers.Size>}
36
initialize: function(layer, position, bounds, url, size) {
37
OpenLayers.Tile.Image.prototype.initialize.apply(this, arguments);
38
this.layerAlphaHack = false;
43
* nullify references to prevent circular references and memory leaks
46
if(this.imgDiv != null) {
47
// unregister the "load" handler
48
OpenLayers.Event.stopObservingElement(this.imgDiv.firstChild);
50
OpenLayers.Tile.Image.prototype.destroy.apply(this, arguments);
55
* Removes the iframe from DOM (avoids back-button problems).
59
var iFrame = this.imgDiv.firstChild;
60
OpenLayers.Event.stopObservingElement(iFrame);
61
this.imgDiv.removeChild(iFrame);
69
* obj - {<OpenLayers.Tile.Image.IFrame>} The tile to be cloned
72
* {<OpenLayers.Tile.Image.IFrame>} An exact clone of this
73
* <OpenLayers.Tile.Image.IFrame>
75
clone: function (obj) {
77
obj = new OpenLayers.Tile.Image.IFrame(
78
this.layer, this.position, this.bounds, this.url, this.size);
81
//pick up properties from superclass
82
obj = OpenLayers.Tile.Image.prototype.clone.apply(this, [obj]);
90
renderTile: function() {
91
if(OpenLayers.Tile.Image.prototype.renderTile.apply(this, arguments)) {
92
// create a html form and add it temporary to the layer div
93
var form = this.createRequestForm();
94
this.imgDiv.appendChild(form);
96
// submit the form (means fetching the image)
98
this.imgDiv.removeChild(form);
104
* Creates the imgDiv property on the tile.
106
initImgDiv: function() {
107
this.imgDiv = this.createImgDiv()
109
OpenLayers.Util.modifyDOMElement(this.imgDiv, this.id, null,
110
this.layer.getImageSize(), "relative");
111
this.imgDiv.className = 'olTileImage';
113
this.frame.appendChild(this.imgDiv);
114
this.layer.div.appendChild(this.frame);
116
if(this.layer.opacity != null) {
118
OpenLayers.Util.modifyDOMElement(this.imgDiv, null, null, null,
123
// we need this reference to check back the viewRequestID
124
this.imgDiv.map = this.layer.map;
128
* Method: createImgDiv
129
* Creates a div with iframe.and eventPane
134
createImgDiv: function() {
135
var eventPane = document.createElement("div");
137
if(OpenLayers.Util.getBrowserName() == "msie") {
138
// IE cannot handle events on elements without backgroundcolor. So we
139
// use this little hack to make elements transparent
140
eventPane.style.backgroundColor = '#FFFFFF';
141
eventPane.style.filter = 'chroma(color=#FFFFFF)';
144
OpenLayers.Util.modifyDOMElement(eventPane, null,
145
new OpenLayers.Pixel(0,0), this.layer.getImageSize(), "absolute");
147
var imgDiv = document.createElement("div");
148
imgDiv.appendChild(eventPane);
153
* Method: createIFrame
154
* Create the IFrame which shows the image.
157
* {DOMElement} Iframe
159
createIFrame: function() {
160
var id = this.id+'_iFrame';
162
if(OpenLayers.Util.getBrowserName() == "msie") {
163
// InternetExplorer does not set the name attribute of an iFrame
164
// properly via DOM manipulation, so we need to do it on our own with
166
iframe = document.createElement('<iframe name="'+id+'">');
168
// IFrames in InternetExplorer are not transparent, if you set the
169
// backgroundColor transparent. This is a workarround to get
170
// transparent iframes.
171
iframe.style.backgroundColor = '#FFFFFF';
172
iframe.style.filter = 'chroma(color=#FFFFFF)';
175
iframe = document.createElement('iframe');
176
iframe.style.backgroundColor = 'transparent';
178
// iframe.name needs to be an unique id, otherwise it
179
// could happen that other iframes are overwritten.
184
// some special properties to avoid scaling the images and scrollbars
186
iframe.scrolling = 'no';
187
iframe.marginWidth = '0px';
188
iframe.marginHeight = '0px';
189
iframe.frameBorder = '0';
191
OpenLayers.Util.modifyDOMElement(iframe, id,
192
new OpenLayers.Pixel(0,0), this.layer.getImageSize(), "absolute");
194
//bind a listener to the onload of the iframe so that we
195
// can register when a tile has finished loading.
196
var onload = function() {
198
//normally isLoading should always be true here but there are some
199
// right funky conditions where loading and then reloading a tile
200
// with the same url *really*fast*. this check prevents sending
201
// a 'loadend' if the msg has already been sent
203
if (this.isLoading) {
204
this.isLoading = false;
205
this.events.triggerEvent("loadend");
208
OpenLayers.Event.observe(iframe, 'load',
209
OpenLayers.Function.bind(onload, this));
215
* Method: createRequestForm
216
* Create the html <form> element with width, height, bbox and all
217
* parameters specified in the layer params.
220
* {DOMElement} The form element which sends the HTTP-POST request to the
223
createRequestForm: function() {
224
// creation of the form element
225
var form = document.createElement('form');
226
form.method = 'POST';
227
var cacheId = this.layer.params["_OLSALT"];
228
cacheId = (cacheId ? cacheId + "_" : "") + this.bounds.toBBOX();
229
form.action = OpenLayers.Util.urlAppend(this.layer.url, cacheId);
231
// insert the iframe, which has been removed to avoid back-button
233
this.imgDiv.insertBefore(this.createIFrame(), this.imgDiv.firstChild);
235
form.target = this.id+'_iFrame';
237
// adding all parameters in layer params as hidden fields to the html
239
var imageSize = this.layer.getImageSize();
240
var params = OpenLayers.Util.extend(
242
"BBOX": this.encodeBBOX ? this.bounds.toBBOX() :
243
this.bounds.toArray(),
244
"WIDTH": imageSize.w,
245
"HEIGHT": imageSize.h
246
}, this.layer.params);
248
for(var par in params) {
249
var field = document.createElement('input');
250
field.type = 'hidden';
252
field.value = params[par];
253
form.appendChild(field);
259
CLASS_NAME: "OpenLayers.Tile.Image.IFrame"