OpenLayers OpenLayers

Changeset 7596

Show
Ignore:
Timestamp:
07/29/08 20:36:26 (4 months ago)
Author:
euzuro
Message:

zoomToMaxExtent() and getMaxExtent() should be smarter if a 'restrictedExtent' property is set on the map. (Closes #1134)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/openlayers/lib/OpenLayers/Map.js

    r7584 r7596  
    16961696    /** 
    16971697     * APIMethod: getMaxExtent 
    1698      *  
    1699      * Returns: 
    1700      * {<OpenLayers.Bounds>} 
    1701      */ 
    1702     getMaxExtent: function () { 
     1698     * 
     1699     * Parameters: 
     1700     * options - {Object}  
     1701     *  
     1702     * Allowed Options: 
     1703     * restricted - {Boolean} If true, returns restricted extent (if it is  
     1704     *     available.) 
     1705     * 
     1706     * Returns: 
     1707     * {<OpenLayers.Bounds>} The maxExtent property as set on the current  
     1708     *     baselayer, unless the 'restricted' option is set, in which case 
     1709     *     the 'restrictedExtent' option from the map is returned (if it 
     1710     *     is set). 
     1711     */ 
     1712    getMaxExtent: function (options) { 
    17031713        var maxExtent = null; 
    1704         if (this.baseLayer != null) { 
     1714        if(options && options.restricted && this.restrictedExtent){ 
     1715            maxExtent = this.restrictedExtent; 
     1716        } else if (this.baseLayer != null) { 
    17051717            maxExtent = this.baseLayer.maxExtent; 
    17061718        }         
     
    19431955     * APIMethod: zoomToMaxExtent 
    19441956     * Zoom to the full extent and recenter. 
    1945      */ 
    1946     zoomToMaxExtent: function() { 
    1947         this.zoomToExtent(this.getMaxExtent()); 
     1957     * 
     1958     * Parameters: 
     1959     * options -  
     1960     *  
     1961     * Allowed Options: 
     1962     * restricted - {Boolean} True to zoom to restricted extent if it is  
     1963     *     set. Defaults to true. 
     1964     */ 
     1965    zoomToMaxExtent: function(options) { 
     1966        //restricted is true by default 
     1967        var restricted = (options) ? options.restricted : true; 
     1968 
     1969        var maxExtent = this.getMaxExtent({ 
     1970            'restricted': restricted  
     1971        }); 
     1972        this.zoomToExtent(maxExtent); 
    19481973    }, 
    19491974 
  • trunk/openlayers/tests/Map.html

    r7584 r7596  
    10291029        t.eq( map.viewPortDiv, null, "map's viewportDiv nullified"); 
    10301030    } 
     1031     
     1032    function test_Map_getMaxExtent(t){ 
     1033        t.plan(5); 
     1034         
     1035        var options = null; 
     1036        var map = {}; 
     1037         
     1038      //null options, no baseLayer 
     1039        var maxExtent = OpenLayers.Map.prototype.getMaxExtent.apply(map, [options]); 
     1040        t.eq(maxExtent, null, "null options, no baseLayer returns null");      
     1041 
     1042      //null options.restricted, no baseLayer 
     1043        maxExtent = OpenLayers.Map.prototype.getMaxExtent.apply(map, [options]); 
     1044        t.eq(maxExtent, null, "null options.restricted, no baseLayer returns null");      
     1045 
     1046      //true options.restricted, null map.restrictedExtent no baseLayer 
     1047        maxExtent = OpenLayers.Map.prototype.getMaxExtent.apply(map, [options]); 
     1048        t.eq(maxExtent, null, "true options.restricted, null map.restrictedExtent no baseLayer returns null");      
     1049 
     1050      //true options.restricted, valid map.restrictedExtent no baseLayer 
     1051        options = { 
     1052            'restricted': true 
     1053        }; 
     1054        map.restrictedExtent = {}; 
     1055        maxExtent = OpenLayers.Map.prototype.getMaxExtent.apply(map, [options]); 
     1056        t.ok(maxExtent == map.restrictedExtent, "true options.restricted, valid map.restrictedExtent no baseLayer returns map.restrictedExtent");      
     1057 
     1058      //null options, valid baseLayer 
     1059        options = null; 
     1060        map.baseLayer = { 
     1061            'maxExtent': {} 
     1062        }; 
     1063        var maxExtent = OpenLayers.Map.prototype.getMaxExtent.apply(map, [options]); 
     1064        t.ok(maxExtent == map.baseLayer.maxExtent, "null options, valid baseLayer returns map.baseLayer.maxExtent");      
     1065    } 
     1066 
     1067    function test_Map_zoomToMaxExtent(t){ 
     1068        t.plan(4) 
     1069 
     1070        gMaxExtent = {}; 
     1071 
     1072        var map = { 
     1073            'getMaxExtent': function(options) { 
     1074                gRestricted = options.restricted;  
     1075                return gMaxExtent; 
     1076            },  
     1077            'zoomToExtent': function(extent) { 
     1078                t.ok(extent == gMaxExtent, "zoomToExtent() always called on return from map.getMaxExtent()"); 
     1079            }  
     1080        }; 
     1081         
     1082      //options is null 
     1083        var options = null; 
     1084        gRestricted = null; 
     1085        OpenLayers.Map.prototype.zoomToMaxExtent.apply(map, [options]); 
     1086        t.eq(gRestricted, true, "default 'restricted' passed to map.getMaxExtent() is true"); 
     1087         
     1088      //valid options 
     1089        options = { 
     1090            'restricted': {} 
     1091        }; 
     1092        gRestricted = null; 
     1093        OpenLayers.Map.prototype.zoomToMaxExtent.apply(map, [options]); 
     1094        t.ok(gRestricted == options.restricted, "when valid options argument, 'options.restricted' passed to map.getMaxExtent()"); 
     1095    } 
     1096 
     1097     
    10311098 
    10321099  </script>