make Layer.addOptions call initResolutions if necessary, r=bartvde (closes #2360)

git-svn-id: http://svn.openlayers.org/trunk/openlayers@10680 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
Éric Lemoine
2010-08-23 12:28:57 +00:00
parent ce0ba0b570
commit 6f73f7059f
2 changed files with 105 additions and 11 deletions

View File

@@ -312,7 +312,7 @@ OpenLayers.Layer = OpenLayers.Class({
* transitionEffect values.
*/
SUPPORTED_TRANSITIONS: ['resize'],
/**
* Property: metadata
* {Object} This object can be used to store additional information on a
@@ -456,18 +456,46 @@ OpenLayers.Layer = OpenLayers.Class({
* newOptions - {Object}
*/
addOptions: function (newOptions) {
if (this.options == null) {
this.options = {};
}
// update our copy for clone
OpenLayers.Util.extend(this.options, newOptions);
// add new options to this
OpenLayers.Util.extend(this, newOptions);
// make sure this.projection references a projection object
if(typeof this.projection == "string") {
this.projection = new OpenLayers.Projection(this.projection);
}
// get the units from the projection, if we have a projection
// and it it has units
if(this.projection && this.projection.getUnits()) {
this.units = this.projection.getUnits();
}
// re-initialize resolutions if necessary, i.e. if any of the
// properties of the "properties" array defined below is set
// in the new options
if(this.map) {
var properties = this.RESOLUTION_PROPERTIES.concat(
["projection", "units", "minExtent", "maxExtent"]
);
for(var o in newOptions) {
if(newOptions.hasOwnProperty(o) &&
OpenLayers.Util.indexOf(properties, o) >= 0) {
this.initResolutions();
break;
}
}
}
},
/**
* APIMethod: onMapResize
* This function can be implemented by subclasses
@@ -542,12 +570,12 @@ OpenLayers.Layer = OpenLayers.Class({
// been set
this.maxExtent = this.maxExtent || this.map.maxExtent;
this.minExtent = this.minExtent || this.map.minExtent;
this.projection = this.projection || this.map.projection;
if (this.projection && typeof this.projection == "string") {
if (typeof this.projection == "string") {
this.projection = new OpenLayers.Projection(this.projection);
}
// Check the projection to see if we can get units -- if not, refer
// to properties.
this.units = this.projection.getUnits() ||