OpenLayers OpenLayers

Ticket #442: final_animatedZooming_LayerImage.patch

File final_animatedZooming_LayerImage.patch, 5.4 kB (added by emanuel, 3 years ago)

Image baselayer supports animated zooming (included unit tests)

  • tests/Layer/test_Image.html

    old new  
    3838        t.ok( layer.options instanceof Object, "layer.options correctly initialized as a non-null Object" ); 
    3939    } 
    4040 
    41     function test_50_Layer_Image_tileTests (t) { 
     41    function test_02_Layer_Image_tileTests (t) { 
    4242        t.plan(4); 
    4343        var map = new OpenLayers.Map('map'); 
    4444         
     
    6565 */ 
    6666 
    6767 
     68/*** animated zooming test functions ***/ 
     69    function test_03_Layer_Image_getTileSize (t) { 
     70        t.plan(2); 
     71 
     72        map = new OpenLayers.Map('map'); 
     73        layer = new OpenLayers.Layer.Image('Test Layer',  
     74                'http://earthtrends.wri.org/images/maps/4_m_citylights_lg.gif', 
     75                new OpenLayers.Bounds(-180, -88.759, 180, 88.759), 
     76                new OpenLayers.Size(580, 288)); 
     77        map.addLayer(layer); 
     78        map.setCenter(new OpenLayers.LonLat(0,0)); 
     79 
     80        var size = map.baseLayer.getTileSize(); 
     81        t.eq(size.w, 580, "tile width is correct");  
     82        t.eq(size.h, 288, "tile height is correct"); 
     83    } 
     84    function test_04_Layer_Image_getCenterTile (t) { 
     85        t.plan(1); 
     86 
     87        map = new OpenLayers.Map('map'); 
     88        layer = new OpenLayers.Layer.Image('Test Layer',  
     89                'http://earthtrends.wri.org/images/maps/4_m_citylights_lg.gif', 
     90                new OpenLayers.Bounds(-180, -88.759, 180, 88.759), 
     91                new OpenLayers.Size(580, 288)); 
     92        map.addLayer(layer); 
     93        map.setCenter(new OpenLayers.LonLat(0,0)); 
     94 
     95        tile = map.baseLayer.getCenterTile();  
     96        t.ok(map.baseLayer.tile == tile,  
     97                "center tile has been set correctly" ); 
     98    } 
     99    function test_05_Layer_Image_cloneBaseLayerDiv (t) { 
     100        t.plan(3); 
     101 
     102        map = new OpenLayers.Map('map'); 
     103        layer = new OpenLayers.Layer.Image('Test Layer',  
     104                'http://earthtrends.wri.org/images/maps/4_m_citylights_lg.gif', 
     105                new OpenLayers.Bounds(-180, -88.759, 180, 88.759), 
     106                new OpenLayers.Size(580, 288)); 
     107        map.addLayer(layer); 
     108         
     109        map.baseLayer.cloneBaseLayerDiv(); 
     110        var cloneDiv = map.baseLayerDivClone; 
     111        var originDiv = map.baseLayer.div;  
     112        t.ok( cloneDiv instanceof HTMLDivElement,  
     113                "cloned baseLayerDiv is a valid HTMLDivElement"); 
     114        t.eq( cloneDiv.childNodes.length, originDiv.childNodes.length, 
     115                "cloned baseLayerDiv has the same number of childs"); 
     116        t.eq( parseInt(cloneDiv.style.zIndex)+1, parseInt(originDiv.style.zIndex), 
     117                "zIndex has been set correctly"); 
     118    } 
     119 
     120 
    68121    function test_99_Layer_Image_destroy (t) { 
    69122        t.plan( 4 );     
    70123 
    71124        var map = new OpenLayers.Map('map'); 
    72125         
    73126        layer = new OpenLayers.Layer.Image('Test Layer',  
    74                                         'http://earthtrends.wri.org/images/maps/4_m_citylights_lg.gif', 
    75                                                                         new OpenLayers.Bounds(-180, -88.759, 180, 88.759), 
    76                                                                                                         new OpenLayers.Size(580, 288)); 
     127                    'http://earthtrends.wri.org/images/maps/4_m_citylights_lg.gif', 
     128                    new OpenLayers.Bounds(-180, -88.759, 180, 88.759), 
     129                    new OpenLayers.Size(580, 288)); 
    77130 
    78131        map.addLayer(layer); 
    79132        map.zoomToMaxExtent(); 
  • lib/OpenLayers/Layer/Image.js

    old new  
    156156        return this.url; 
    157157    }, 
    158158         
     159 
     160 
     161    /********************************************************/ 
     162    /*                                                      */ 
     163    /*       Baselayer Functions for zooming/scaling        */ 
     164    /*                                                      */ 
     165    /********************************************************/ 
     166 
     167 
     168    /**  
     169     * Gets tile (image) size. 
     170     *   
     171     * @returns the image size if tile exists; otherwise 
     172     * null 
     173     * @type {OpenLayers.Size} 
     174     */ 
     175    getTileSize:function() { 
     176        if (this.tile)  
     177            return this.tile.size; 
     178        else 
     179            return null; 
     180    }, 
     181 
     182    /**  
     183     * Gets the tile of this image layer.  
     184     * 
     185     * @returns the only tile of the layer 
     186     * @type {OpenLayers.Tile} 
     187     */ 
     188    getCenterTile:function() {    
     189        if (this.tile) 
     190            return this.tile;  
     191        else 
     192            return null; 
     193    }, 
     194 
     195    /**  
     196     * Clones layerContainer for "smooth tile update".  
     197     * So, it gets no blank map while map is loading in new zoomlevel. 
     198     * 
     199     * @returns true after layerContainer is cloned 
     200     * @type Boolean 
     201     */ 
     202    cloneBaseLayerDiv:function() { 
     203        // share clone algorithm with other baselayers 
     204        this.cloneBaseLayerDiv_share(); 
     205 
     206        // remove the old imgDiv tile  
     207        // (so it doesn't becomes complicate with the same imgDiv of the 
     208        // cloned layerContainerDiv) 
     209        if (this.tile) 
     210            this.div.removeChild(this.tile.imgDiv); 
     211         
     212        this.tile = null;         
     213 
     214        return true; 
     215    }, 
     216 
    159217    /** @final @type String */ 
    160218    CLASS_NAME: "OpenLayers.Layer.Image" 
    161219});