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

git-svn-id: http://svn.openlayers.org/trunk/openlayers@7596 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
euzuro
2008-07-30 00:36:26 +00:00
parent 27ce7fe099
commit 0b58117c06
2 changed files with 97 additions and 5 deletions

View File

@@ -1695,13 +1695,25 @@ OpenLayers.Map = OpenLayers.Class({
/**
* APIMethod: getMaxExtent
*
* Parameters:
* options - {Object}
*
* Allowed Options:
* restricted - {Boolean} If true, returns restricted extent (if it is
* available.)
*
* Returns:
* {<OpenLayers.Bounds>}
* {<OpenLayers.Bounds>} The maxExtent property as set on the current
* baselayer, unless the 'restricted' option is set, in which case
* the 'restrictedExtent' option from the map is returned (if it
* is set).
*/
getMaxExtent: function () {
getMaxExtent: function (options) {
var maxExtent = null;
if (this.baseLayer != null) {
if(options && options.restricted && this.restrictedExtent){
maxExtent = this.restrictedExtent;
} else if (this.baseLayer != null) {
maxExtent = this.baseLayer.maxExtent;
}
return maxExtent;
@@ -1942,9 +1954,22 @@ OpenLayers.Map = OpenLayers.Class({
/**
* APIMethod: zoomToMaxExtent
* Zoom to the full extent and recenter.
*
* Parameters:
* options -
*
* Allowed Options:
* restricted - {Boolean} True to zoom to restricted extent if it is
* set. Defaults to true.
*/
zoomToMaxExtent: function() {
this.zoomToExtent(this.getMaxExtent());
zoomToMaxExtent: function(options) {
//restricted is true by default
var restricted = (options) ? options.restricted : true;
var maxExtent = this.getMaxExtent({
'restricted': restricted
});
this.zoomToExtent(maxExtent);
},
/**

View File

@@ -1028,6 +1028,73 @@
t.eq( map.controls, null, "map.controls is null after destroy" );
t.eq( map.viewPortDiv, null, "map's viewportDiv nullified");
}
function test_Map_getMaxExtent(t){
t.plan(5);
var options = null;
var map = {};
//null options, no baseLayer
var maxExtent = OpenLayers.Map.prototype.getMaxExtent.apply(map, [options]);
t.eq(maxExtent, null, "null options, no baseLayer returns null");
//null options.restricted, no baseLayer
maxExtent = OpenLayers.Map.prototype.getMaxExtent.apply(map, [options]);
t.eq(maxExtent, null, "null options.restricted, no baseLayer returns null");
//true options.restricted, null map.restrictedExtent no baseLayer
maxExtent = OpenLayers.Map.prototype.getMaxExtent.apply(map, [options]);
t.eq(maxExtent, null, "true options.restricted, null map.restrictedExtent no baseLayer returns null");
//true options.restricted, valid map.restrictedExtent no baseLayer
options = {
'restricted': true
};
map.restrictedExtent = {};
maxExtent = OpenLayers.Map.prototype.getMaxExtent.apply(map, [options]);
t.ok(maxExtent == map.restrictedExtent, "true options.restricted, valid map.restrictedExtent no baseLayer returns map.restrictedExtent");
//null options, valid baseLayer
options = null;
map.baseLayer = {
'maxExtent': {}
};
var maxExtent = OpenLayers.Map.prototype.getMaxExtent.apply(map, [options]);
t.ok(maxExtent == map.baseLayer.maxExtent, "null options, valid baseLayer returns map.baseLayer.maxExtent");
}
function test_Map_zoomToMaxExtent(t){
t.plan(4)
gMaxExtent = {};
var map = {
'getMaxExtent': function(options) {
gRestricted = options.restricted;
return gMaxExtent;
},
'zoomToExtent': function(extent) {
t.ok(extent == gMaxExtent, "zoomToExtent() always called on return from map.getMaxExtent()");
}
};
//options is null
var options = null;
gRestricted = null;
OpenLayers.Map.prototype.zoomToMaxExtent.apply(map, [options]);
t.eq(gRestricted, true, "default 'restricted' passed to map.getMaxExtent() is true");
//valid options
options = {
'restricted': {}
};
gRestricted = null;
OpenLayers.Map.prototype.zoomToMaxExtent.apply(map, [options]);
t.ok(gRestricted == options.restricted, "when valid options argument, 'options.restricted' passed to map.getMaxExtent()");
}
</script>
</head>