| | 1 | /* Copyright (c) 2006 MetaCarta, Inc., published under a modified BSD license. |
|---|
| | 2 | * See http://svn.openlayers.org/trunk/openlayers/repository-license.txt |
|---|
| | 3 | * for the full text of the license. */ |
|---|
| | 4 | |
|---|
| | 5 | /** |
|---|
| | 6 | * @requires OpenLayers/Control.js |
|---|
| | 7 | * |
|---|
| | 8 | * Class: OpenLayers.Control.LoadingPanel |
|---|
| | 9 | * In some applications, it makes sense to alert the user that something is happening |
|---|
| | 10 | * while tiles are loading. This control displays a div across the map when this is |
|---|
| | 11 | * going on. |
|---|
| | 12 | * |
|---|
| | 13 | * Inherits from: |
|---|
| | 14 | * - <OpenLayers.Control> |
|---|
| | 15 | */ |
|---|
| | 16 | OpenLayers.Control.LoadingPanel = OpenLayers.Class.create(); |
|---|
| | 17 | OpenLayers.Control.LoadingPanel.prototype = |
|---|
| | 18 | OpenLayers.Class.inherit( OpenLayers.Control, { |
|---|
| | 19 | /** |
|---|
| | 20 | * Constructor: OpenLayers.Control.LoadingPanel |
|---|
| | 21 | * Display a panel across the map that says 'loading'. |
|---|
| | 22 | * |
|---|
| | 23 | * Parameters: |
|---|
| | 24 | * layer - {<OpenLayers.Layer.Grid>} Some layer which implements the loadstart and loadend |
|---|
| | 25 | * properties. At the moment, this is only subclasses of the Grid layer. |
|---|
| | 26 | * options - {Object} additional options. |
|---|
| | 27 | */ |
|---|
| | 28 | initialize: function(layer, options) { |
|---|
| | 29 | OpenLayers.Control.prototype.initialize.apply(this, [options]); |
|---|
| | 30 | layer.events.register('loadstart', this, this.maximizeControl); |
|---|
| | 31 | layer.events.register('loadend', this, this.minimizeControl); |
|---|
| | 32 | }, |
|---|
| | 33 | |
|---|
| | 34 | /** |
|---|
| | 35 | * Method: draw |
|---|
| | 36 | * Create and return the element to be splashed over the map. |
|---|
| | 37 | */ |
|---|
| | 38 | draw: function () { |
|---|
| | 39 | if (this.div == null) { |
|---|
| | 40 | var viewSize = this.map.getSize(); |
|---|
| | 41 | |
|---|
| | 42 | msgW = Math.max(viewSize.w, 300); |
|---|
| | 43 | msgH = Math.max(viewSize.h, 200); |
|---|
| | 44 | var size = new OpenLayers.Size(msgW, msgH); |
|---|
| | 45 | |
|---|
| | 46 | var centerPx = new OpenLayers.Pixel(viewSize.w/2, viewSize.h/2); |
|---|
| | 47 | |
|---|
| | 48 | var topLeft = centerPx.add(-size.w/2, -size.h/2); |
|---|
| | 49 | |
|---|
| | 50 | this.div = OpenLayers.Util.createDiv(this.name + "_warning1", |
|---|
| | 51 | topLeft, |
|---|
| | 52 | size, |
|---|
| | 53 | null, |
|---|
| | 54 | null, |
|---|
| | 55 | null, |
|---|
| | 56 | "auto"); |
|---|
| | 57 | |
|---|
| | 58 | this.div.style.backgroundColor = "transparent"; |
|---|
| | 59 | |
|---|
| | 60 | var size2 = new OpenLayers.Size(msgW, msgH); |
|---|
| | 61 | var centerPx2 = centerPx.add(-msgW/2, -msgH/2); |
|---|
| | 62 | var div2 = OpenLayers.Util.createDiv(this.name + "_warning2", |
|---|
| | 63 | centerPx2, |
|---|
| | 64 | size2, |
|---|
| | 65 | null, |
|---|
| | 66 | null, |
|---|
| | 67 | null, |
|---|
| | 68 | "auto", |
|---|
| | 69 | .75); |
|---|
| | 70 | div2.style.backgroundColor = "white"; |
|---|
| | 71 | div2.innerHTML = "<img src='../img/loading.gif' width='"+msgW+"' height='"+msgH+"'/>"; |
|---|
| | 72 | this.div.appendChild(div2); |
|---|
| | 73 | |
|---|
| | 74 | } |
|---|
| | 75 | |
|---|
| | 76 | return this.div; |
|---|
| | 77 | }, |
|---|
| | 78 | |
|---|
| | 79 | /** |
|---|
| | 80 | * Method: minimizeControl |
|---|
| | 81 | * Set the display properties of the control to make it disappear. |
|---|
| | 82 | */ |
|---|
| | 83 | minimizeControl: function(e) { |
|---|
| | 84 | |
|---|
| | 85 | this.div.style.width = "0px"; |
|---|
| | 86 | this.div.style.height = "0px"; |
|---|
| | 87 | |
|---|
| | 88 | if (e != null) { |
|---|
| | 89 | OpenLayers.Event.stop(e); |
|---|
| | 90 | } |
|---|
| | 91 | }, |
|---|
| | 92 | |
|---|
| | 93 | /** |
|---|
| | 94 | * Method: maximizeControl |
|---|
| | 95 | * Make the control visible. |
|---|
| | 96 | */ |
|---|
| | 97 | maximizeControl: function(e) { |
|---|
| | 98 | var viewSize = this.map.getSize(); |
|---|
| | 99 | |
|---|
| | 100 | msgW = Math.max(viewSize.w, 300); |
|---|
| | 101 | msgH = Math.max(viewSize.h, 200); |
|---|
| | 102 | |
|---|
| | 103 | this.div.style.width = msgW; |
|---|
| | 104 | this.div.style.height = msgH; |
|---|
| | 105 | |
|---|
| | 106 | if (e != null) { |
|---|
| | 107 | OpenLayers.Event.stop(e); |
|---|
| | 108 | } |
|---|
| | 109 | }, |
|---|
| | 110 | |
|---|
| | 111 | CLASS_NAME: "OpenLayers.Control.LoadingPanel" |
|---|
| | 112 | |
|---|
| | 113 | }); |
|---|
| | 114 | |