Bienvenue sur PostGIS.fr

Bienvenue sur PostGIS.fr , le site de la communauté des utilisateurs francophones de PostGIS.

PostGIS ajoute le support d'objets géographique à la base de données PostgreSQL. En effet, PostGIS "spatialise" le serverur PostgreSQL, ce qui permet de l'utiliser comme une base de données SIG.

Maintenu à jour, en fonction de nos disponibilités et des diverses sorties des outils que nous testons, nous vous proposons l'ensemble de nos travaux publiés en langue française.

source: trunk/workshop-routing-foss4g/web/OpenLayers/lib/OpenLayers/Tile/Image/IFrame.js @ 76

Revision 76, 8.6 KB checked in by djay, 12 years ago (diff)

Ajout du répertoire web

  • Property svn:executable set to *
Line 
1/* Copyright (c) 2006-2010 by OpenLayers Contributors (see authors.txt for
2 * full list of contributors). Published under the Clear BSD license. 
3 * See http://svn.openlayers.org/trunk/openlayers/license.txt for the
4 * full text of the license. */
5
6
7/**
8 * @requires OpenLayers/Tile/Image.js
9 */
10
11/**
12 * Class: OpenLayers.Tile.Image.IFrame
13 * Instances of OpenLayers.Tile.Image.IFrame are used to manage the image tiles
14 * used by Layer.WMS.Post loaded via HTTP-POST-protocol. Create a new image
15 * tile with the <OpenLayers.Tile.Image.IFrame> constructor.
16 *
17 * Inherits from:
18 *  - <OpenLayers.Tile.Image>
19 */
20OpenLayers.Tile.Image.IFrame = OpenLayers.Class(OpenLayers.Tile.Image, {
21   
22    /**
23     * Property: layerAlphaHack
24     * {Boolean} Always false for an instance.
25     */
26
27    /**
28     * Constructor: OpenLayers.Tile.Image.IFrame
29     * Constructor for a new <OpenLayers.Tile.Image.IFrame> instance.
30     *
31     * Parameters:
32     * layer - {<OpenLayers.Layer>} layer that the tile will go in.
33     * position - {<OpenLayers.Pixel>}
34     * bounds - {<OpenLayers.Bounds>}
35     * size - {<OpenLayers.Size>}
36     */   
37    initialize: function(layer, position, bounds, url, size) {
38        OpenLayers.Tile.Image.prototype.initialize.apply(this, arguments);
39        this.layerAlphaHack = false;
40    },
41
42    /**
43     * Method: destroy
44     * nullify references to prevent circular references and memory leaks
45     */
46    destroy: function() {
47        if(this.imgDiv != null) {
48            // unregister the "load" handler
49            OpenLayers.Event.stopObservingElement(this.imgDiv.firstChild);
50        }
51        OpenLayers.Tile.Image.prototype.destroy.apply(this, arguments);
52    },
53
54    /**
55     * Method: clear
56     * Removes the iframe from DOM (avoids back-button problems).
57     */
58    clear: function() {
59        if(this.imgDiv) {
60            var iFrame = this.imgDiv.firstChild;
61            OpenLayers.Event.stopObservingElement(iFrame);
62            this.imgDiv.removeChild(iFrame);
63        }
64    },
65
66    /**
67     * Method: clone
68     *
69     * Parameters:
70     * obj - {<OpenLayers.Tile.Image.IFrame>} The tile to be cloned
71     *
72     * Returns:
73     * {<OpenLayers.Tile.Image.IFrame>} An exact clone of this
74     * <OpenLayers.Tile.Image.IFrame>
75     */
76    clone: function (obj) {
77        if (obj == null) {
78            obj = new OpenLayers.Tile.Image.IFrame(
79                this.layer, this.position, this.bounds, this.url, this.size);
80        } 
81       
82        //pick up properties from superclass
83        obj = OpenLayers.Tile.Image.prototype.clone.apply(this, [obj]);
84       
85        return obj;
86    },
87
88    /**
89     * Method: renderTile
90     */
91     renderTile: function() {
92        if(OpenLayers.Tile.Image.prototype.renderTile.apply(this, arguments)) {
93            // create a html form and add it temporary to the layer div
94            var form = this.createRequestForm();
95            this.imgDiv.appendChild(form);
96
97            // submit the form (means fetching the image)
98            form.submit();
99            this.imgDiv.removeChild(form);
100        }
101    },
102
103    /**
104     * Method: initImgDiv
105     * Creates the imgDiv property on the tile.
106     */
107    initImgDiv: function() {
108        this.imgDiv = this.createImgDiv();
109
110        OpenLayers.Util.modifyDOMElement(this.imgDiv, this.id, null,
111            this.layer.getImageSize(), "relative");
112        this.imgDiv.className = 'olTileImage';
113
114        this.frame.appendChild(this.imgDiv); 
115        this.layer.div.appendChild(this.frame); 
116
117        if(this.layer.opacity != null) {
118           
119            OpenLayers.Util.modifyDOMElement(this.imgDiv, null, null, null,
120                                             null, null, null, 
121                                             this.layer.opacity);
122        }
123
124        // we need this reference to check back the viewRequestID
125        this.imgDiv.map = this.layer.map;
126    },
127
128    /**
129     * Method: createImgDiv
130     * Creates a div with iframe.and eventPane
131     *
132     * Returns:
133     * {DOMElement}
134     */
135    createImgDiv: function() {
136        var eventPane = document.createElement("div");
137
138        if(OpenLayers.Util.getBrowserName() == "msie") {
139            // IE cannot handle events on elements without backgroundcolor. So we
140            // use this little hack to make elements transparent
141            eventPane.style.backgroundColor = '#FFFFFF';
142            eventPane.style.filter          = 'chroma(color=#FFFFFF)';
143        }
144
145        OpenLayers.Util.modifyDOMElement(eventPane, null,
146            new OpenLayers.Pixel(0,0), this.layer.getImageSize(), "absolute");
147
148        var imgDiv = document.createElement("div");
149        imgDiv.appendChild(eventPane);
150        return imgDiv;
151    },
152
153    /**
154     * Method: createIFrame
155     * Create the IFrame which shows the image.
156     *
157     * Returns:
158     * {DOMElement} Iframe
159     */
160    createIFrame: function() {
161        var id = this.id+'_iFrame';
162        var iframe;
163        if(OpenLayers.Util.getBrowserName() == "msie") {
164            // InternetExplorer does not set the name attribute of an iFrame
165            // properly via DOM manipulation, so we need to do it on our own with
166            // this hack.
167            iframe = document.createElement('<iframe name="'+id+'">');
168
169            // IFrames in InternetExplorer are not transparent, if you set the
170            // backgroundColor transparent. This is a workarround to get
171            // transparent iframes.
172            iframe.style.backgroundColor = '#FFFFFF';
173            iframe.style.filter          = 'chroma(color=#FFFFFF)';
174        }
175        else {
176            iframe = document.createElement('iframe');
177            iframe.style.backgroundColor = 'transparent';
178       
179            // iframe.name needs to be an unique id, otherwise it
180            // could happen that other iframes are overwritten.
181            iframe.name = id;
182        }
183        iframe.id = id;
184
185        // some special properties to avoid scaling the images and scrollbars
186        // in the iframe
187        iframe.scrolling             = 'no';
188        iframe.marginWidth           = '0px';
189        iframe.marginHeight          = '0px';
190        iframe.frameBorder           = '0';
191
192        OpenLayers.Util.modifyDOMElement(iframe, id, 
193            new OpenLayers.Pixel(0,0), this.layer.getImageSize(), "absolute");
194
195        //bind a listener to the onload of the iframe so that we
196        // can register when a tile has finished loading.
197        var onload = function() {
198            this.show();
199            //normally isLoading should always be true here but there are some
200            // right funky conditions where loading and then reloading a tile
201            // with the same url *really*fast*. this check prevents sending
202            // a 'loadend' if the msg has already been sent
203            //
204            if (this.isLoading) {
205                this.isLoading = false;
206                this.events.triggerEvent("loadend");
207            }
208        };
209        OpenLayers.Event.observe(iframe, 'load',
210            OpenLayers.Function.bind(onload, this));
211
212        return iframe;
213    },
214   
215    /**
216     * Method: createRequestForm
217     * Create the html <form> element with width, height, bbox and all
218     * parameters specified in the layer params.
219     *
220     * Returns:
221     * {DOMElement} The form element which sends the HTTP-POST request to the
222     *              WMS.
223     */
224    createRequestForm: function() {
225        // creation of the form element
226        var form = document.createElement('form');
227        form.method = 'POST';
228        var cacheId = this.layer.params["_OLSALT"];
229        cacheId = (cacheId ? cacheId + "_" : "") + this.bounds.toBBOX();
230        form.action = OpenLayers.Util.urlAppend(this.layer.url, cacheId);
231
232        // insert the iframe, which has been removed to avoid back-button
233        // problems
234        this.imgDiv.insertBefore(this.createIFrame(), this.imgDiv.firstChild);
235
236        form.target = this.id+'_iFrame';
237
238        // adding all parameters in layer params as hidden fields to the html
239        // form element
240        var imageSize = this.layer.getImageSize();
241        var params = OpenLayers.Util.extend(
242            {
243                "BBOX": this.encodeBBOX ? this.bounds.toBBOX() :
244                        this.bounds.toArray(),
245                "WIDTH": imageSize.w,
246                "HEIGHT": imageSize.h
247            }, this.layer.params);
248           
249        for(var par in params) {
250            var field = document.createElement('input');
251            field.type  = 'hidden';
252            field.name  = par;
253            field.value = params[par];
254            form.appendChild(field);
255        }   
256
257        return form;
258    },
259   
260    CLASS_NAME: "OpenLayers.Tile.Image.IFrame"
261  }
262);
Note: See TracBrowser for help on using the repository browser.