OpenLayers OpenLayers

Ticket #102: loadingpanel.patch

File loadingpanel.patch, 7.6 kB (added by crschmidt, 1 year ago)
  • tests/list-tests.html

    old new  
    5859    <li>Control/test_NavToolbar.html</li> 
    5960    <li>Control/test_MouseToolbar.html</li> 
    6061    <li>Control/test_LayerSwitcher.html</li> 
     62    <li>Control/test_LoadingPanel.html</li> 
    6163    <li>Control/test_Panel.html</li> 
    6264    <li>Control/test_PanZoom.html</li> 
    6365    <li>Control/test_PanZoomBar.html</li> 
  • tests/Control/test_LoadingPanel.html

    old new  
     1<html> 
     2<head> 
     3  <script src="../../lib/OpenLayers.js"></script> 
     4  <script type="text/javascript"><!-- 
     5    var map;  
     6    function test_Control_LoadingPanel_constructor (t) { 
     7        t.plan( 2 ); 
     8        var layer = new OpenLayers.Layer.WMS("a", "http://example.com/"); 
     9        control = new OpenLayers.Control.LoadingPanel(layer); 
     10        t.ok( control instanceof OpenLayers.Control.LoadingPanel, "new OpenLayers.Control returns object" ); 
     11        t.eq( control.displayClass,  "olControlLoadingPanel", "displayClass is correct" ); 
     12    } 
     13     
     14    function test_Control_LoadingPanel_maximize_minimize (t) { 
     15        t.plan( 2 ); 
     16        var layer = new OpenLayers.Layer.WMS("a", "http://example.com/"); 
     17        control = new OpenLayers.Control.LoadingPanel(layer); 
     18        map = new OpenLayers.Map('map'); 
     19        map.addControl(control); 
     20        control.maximizeControl(); 
     21        t.eq(control.div.style.width, "1024px", "Control div has correct width after maximize"); 
     22        control.minimizeControl(); 
     23        t.eq(control.div.style.width, "0px", "Control div has correct width after minimize"); 
     24         
     25    } 
     26  // --> 
     27  </script> 
     28</head> 
     29<body> 
     30    <div id="map" style="width: 1024px; height: 512px;"/> 
     31</body> 
     32</html> 
  • lib/OpenLayers.js

    old new  
    139140            "OpenLayers/Control/DrawFeature.js", 
    140141            "OpenLayers/Control/Panel.js", 
    141142            "OpenLayers/Control/SelectFeature.js", 
     143            "OpenLayers/Control/LoadingPanel.js", 
    142144            "OpenLayers/Geometry.js", 
    143145            "OpenLayers/Geometry/Rectangle.js", 
    144146            "OpenLayers/Geometry/Collection.js", 
  • examples/loadingPanel.html

    old new  
     1<html> 
     2<head> 
     3<script src="../lib/OpenLayers.js"></script> 
     4<title>World Map Query</title>  
     5</head> 
     6<body> 
     7  <div id="map" style="width:100%; height:90%"></div> 
     8  <script defer="defer" type="text/javascript"> 
     9    var map = new OpenLayers.Map('map', {'maxResolution':360/512}); 
     10     
     11    var wms = new OpenLayers.Layer.WMS( "OpenLayers WMS",  
     12        "http://labs.metacarta.com/wms-c/Basic.py", {'layers': 'basic'} ); 
     13     
     14    var lp = new OpenLayers.Control.LoadingPanel(wms);  
     15    map.addControl(lp); 
     16 
     17    map.addLayer(wms); 
     18     
     19    map.zoomToMaxExtent(); 
     20 
     21  </script> 
     22</body> 
     23</html> 
  • lib/OpenLayers/Control/LoadingPanel.js

    old new  
     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 */ 
     16OpenLayers.Control.LoadingPanel = OpenLayers.Class.create(); 
     17OpenLayers.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