OpenLayers OpenLayers

Ticket #677: ymapsize.2.patch

File ymapsize.2.patch, 6.0 kB (added by euzuro, 1 year ago)

patch *slightly* modified... and tests added. please opine

  • tests/Layer/test_Yahoo.html

    old new  
     1<html> 
     2<head> 
     3  <script src="http://api.maps.yahoo.com/ajaxymap?v=3.0&appid=euzuro-openlayers"></script> 
     4  <script src="../../lib/OpenLayers.js"></script> 
     5  <script type="text/javascript"><!-- 
     6    var layer;  
     7 
     8    function test_01_Layer_Yahoo_constructor (t) { 
     9        t.plan( 4 ); 
     10 
     11        var tempEventPane = OpenLayers.Layer.EventPane.prototype.initialize; 
     12        OpenLayers.Layer.EventPane.prototype.initialize = function(name, options) { 
     13            t.ok(name == g_Name, "EventPane initialize() called with correct name"); 
     14            t.ok(options == g_Options, "EventPane initialize() called with correct options"); 
     15        } 
     16 
     17        var tempFixedZoomLevels = OpenLayers.Layer.FixedZoomLevels.prototype.initialize; 
     18        OpenLayers.Layer.FixedZoomLevels.prototype.initialize = function(name, options) { 
     19            t.ok(name == g_Name, "FixedZoomLevels initialize() called with correct name"); 
     20            t.ok(options == g_Options, "FixedZoomLevels initialize() called with correct options"); 
     21        } 
     22 
     23 
     24        g_Name = {}; 
     25        g_Options = {};         
     26        var l = new OpenLayers.Layer.Yahoo(g_Name, g_Options); 
     27 
     28        OpenLayers.Layer.EventPane.prototype.initialize = tempEventPane; 
     29        OpenLayers.Layer.FixedZoomLevels.prototype.initialize = tempFixedZoomLevels; 
     30    } 
     31 
     32    function test_02_Layer_Yahoo_loadMapObject(t) { 
     33        t.plan(5); 
     34         
     35        var temp = YMap; 
     36        YMap = OpenLayers.Class({ 
     37            initialize: function(div, type, size) { 
     38                t.ok(div == g_Div, "correct div passed to YMap constructor"); 
     39                t.ok(type == g_Type, "correct type passed to YMap constructor"); 
     40                t.ok(size == g_YMapSize, "correct size passed to YMap constructor"); 
     41            }, 
     42            disableKeyControls: function() { 
     43                t.ok(true, "disableKeyControls called on map object"); 
     44            } 
     45        }); 
     46         
     47        g_Div = {}; 
     48        g_Type = {}; 
     49        g_MapSize = {}; 
     50        g_YMapSize = {}; 
     51         
     52        var l = new OpenLayers.Layer.Yahoo(); 
     53        l.div = g_Div; 
     54        l.type = g_Type; 
     55        l.map = { 
     56            'getSize': function() { 
     57                return g_MapSize; 
     58            } 
     59        }; 
     60        l.getMapObjectSizeFromOLSize = function(mapSize) { 
     61            t.ok(mapSize == g_MapSize, "correctly translating map size from ol to YSize"); 
     62            return g_YMapSize; 
     63        }; 
     64 
     65        l.loadMapObject(); 
     66 
     67        YMap = temp; 
     68    }     
     69 
     70    function test_03_Layer_Yahoo_onMapResize(t) { 
     71        t.plan(2); 
     72         
     73        g_MapSize = {}; 
     74        g_YMapSize = {}; 
     75         
     76        var l = new OpenLayers.Layer.Yahoo(); 
     77        l.mapObject = { 
     78            'resizeTo': function(size) { 
     79                t.ok(size == g_YMapSize, "correct YSize passed to reiszeTo on map object"); 
     80            } 
     81        } 
     82        l.map = { 
     83            'getSize': function() { 
     84                return g_MapSize; 
     85            } 
     86        }; 
     87        l.getMapObjectSizeFromOLSize = function(mapSize) { 
     88            t.ok(mapSize == g_MapSize, "correctly translating map size from ol to YSize"); 
     89            return g_YMapSize; 
     90        }; 
     91 
     92        l.onMapResize(); 
     93    } 
     94     
     95    function test_04_Layer_Yahoo_getMapObjectSizeFromOLSize(t) { 
     96        t.plan(2); 
     97         
     98        var temp = YSize; 
     99        YSize = function(w, h) { 
     100            t.ok(w == g_Size.w, "correct width passed to YSize constructor"); 
     101            t.ok(h == g_Size.h, "correct height passed to YSize constructor"); 
     102        } 
     103         
     104        g_Size = { 
     105            'w': {}, 
     106            'h': {} 
     107        }; 
     108         
     109        OpenLayers.Layer.Yahoo.prototype.getMapObjectSizeFromOLSize(g_Size); 
     110 
     111        YSize = temp; 
     112    } 
     113 
     114  // --> 
     115  </script> 
     116</head> 
     117<body> 
     118  <div id="map"></div> 
     119</body> 
     120</html> 
  • tests/list-tests.html

    old new  
    5151    <li>Layer/test_TMS.html</li> 
    5252    <li>Layer/test_TileCache.html</li> 
    5353    <li>Layer/test_Vector.html</li> 
     54    <li>Layer/test_Yahoo.html</li> 
    5455    <li>Layer/test_GML.html</li> 
    5556    <li>Layer/test_WrapDateLine.html</li> 
    5657    <li>test_Tile.html</li> 
  • lib/OpenLayers/Layer/Yahoo.js

    old new  
    5959     */ 
    6060    loadMapObject:function() { 
    6161        try { //do not crash!  
    62             this.mapObject = new YMap(this.div, this.type); 
     62            var size = this.getMapObjectSizeFromOLSize(this.map.getSize()); 
     63            this.mapObject = new YMap(this.div, this.type, size); 
    6364            this.mapObject.disableKeyControls(); 
    6465        } catch(e) {} 
    6566    }, 
     67 
     68    /** 
     69     * Method: onMapResize 
     70     *  
     71     */ 
     72    onMapResize: function() { 
     73        try { 
     74            var size = this.getMapObjectSizeFromOLSize(this.map.getSize()); 
     75            this.mapObject.resizeTo(size); 
     76        } catch(e) {}      
     77    },     
    6678     
    6779     
    6880    /**  
     
    336348    getMapObjectPixelFromXY: function(x, y) { 
    337349        return new YCoordPoint(x, y); 
    338350    }, 
    339  
     351     
     352  // Size 
     353   
     354    /** 
     355     * APIMethod: getMapObjectSizeFromOLSize 
     356     *  
     357     * Parameters: 
     358     * olSize - {<OpenLayers.Size>} 
     359     *  
     360     * Return: 
     361     * {Object} MapObject Size from olSize parameter 
     362     */ 
     363    getMapObjectSizeFromOLSize: function(olSize) { 
     364        return new YSize(olSize.w, olSize.h); 
     365    }, 
     366     
    340367    CLASS_NAME: "OpenLayers.Layer.Yahoo" 
    341368});