using new restricedMinZoom property to make Layer.Bing code much cleaner. r=bartvde (closes #3025)

git-svn-id: http://svn.openlayers.org/trunk/openlayers@11059 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
ahocevar
2011-01-24 21:45:44 +00:00
parent a1c80ffb7e
commit b434c02e1d
2 changed files with 9 additions and 21 deletions

View File

@@ -77,8 +77,7 @@ OpenLayers.Layer.Bing = OpenLayers.Class(OpenLayers.Layer.XYZ, {
*/
initialize: function(options) {
options = OpenLayers.Util.applyDefaults({
zoomOffset: 1,
maxResolution: 78271.51695,
restrictedMinZoom: 1,
sphericalMercator: true
}, options)
var name = options.name || "Bing " + (options.type || this.type);
@@ -124,20 +123,11 @@ OpenLayers.Layer.Bing = OpenLayers.Class(OpenLayers.Layer.XYZ, {
for (var i=0; i<res.imageUrlSubdomains.length; ++i) {
this.url.push(url.replace("{subdomain}", res.imageUrlSubdomains[i]));
};
var resolution;
if (this.map && this.map.baseLayer === this && this.map.getCenter()) {
// if we are the current base layer and the map was centered
// already, we need to remember the current resolution to find a
// matching zoom level after the maxResolution changes
resolution = this.getResolution();
}
this.addOptions({
maxResolution: 78271.51695 / Math.pow(2, res.zoomMin - 1),
numZoomLevels: res.zoomMax - res.zoomMin + 1
restrictedMinZoom: res.zoomMin,
numZoomLevels: res.zoomMax + 1
});
// adjust zoom level to match the previous resolution - this triggers a
// moveTo on all layers.
resolution && this.map.zoomTo(this.getZoomForResolution(resolution));
this.updateAttribution();
// redraw to replace "blank.gif" tiles with real tiles
this.redraw();
},
@@ -179,7 +169,7 @@ OpenLayers.Layer.Bing = OpenLayers.Class(OpenLayers.Layer.XYZ, {
*/
updateAttribution: function() {
var metadata = this.metadata;
if (!metadata || !this.map) {
if (!metadata || !this.map || !this.map.center) {
return;
}
var res = metadata.resourceSets[0].resources[0];
@@ -213,9 +203,7 @@ OpenLayers.Layer.Bing = OpenLayers.Class(OpenLayers.Layer.XYZ, {
*/
setMap: function() {
OpenLayers.Layer.XYZ.prototype.setMap.apply(this, arguments);
if (this.map.getCenter()) {
this.updateAttribution();
}
this.updateAttribution();
this.map.events.register("moveend", this, this.updateAttribution);
},

View File

@@ -24,7 +24,7 @@
};
layer = new OpenLayers.Layer.Bing({metadataParams: {foo: "bar"}});
t.ok(layer instanceof OpenLayers.Layer.Bing, "returns OpenLayers.Layer.Bing object" );
t.delay_call(2, function() {
t.delay_call(5, function() {
t.eq(log.length, 1, "processMetadata called");
t.eq(OpenLayers.Util.getParameters(log[0]).foo, "bar", "metadataParams passed to url correctly.");
OpenLayers.Layer.Bing.processMetadata = origProcessMetadata;
@@ -66,13 +66,13 @@
})]);
map2.zoomToMaxExtent();
t.delay_call(2.0, function() {
t.delay_call(5, function() {
origProcessMetadata.call(layer, meta[0]);
t.eq(extent.toBBOX(), map.getExtent().toBBOX(), "layer extent correct for base layer with zoomMin == 1.");
map.destroy();
});
t.delay_call(2.5, function() {
t.delay_call(6, function() {
origProcessMetadata.call(layer2, meta[1]);
t.eq(extent2.toBBOX(), map2.getExtent().toBBOX(), "layer extent correct for base layer with zoomMin == 2.");
map2.destroy();