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:
@@ -77,8 +77,7 @@ OpenLayers.Layer.Bing = OpenLayers.Class(OpenLayers.Layer.XYZ, {
|
|||||||
*/
|
*/
|
||||||
initialize: function(options) {
|
initialize: function(options) {
|
||||||
options = OpenLayers.Util.applyDefaults({
|
options = OpenLayers.Util.applyDefaults({
|
||||||
zoomOffset: 1,
|
restrictedMinZoom: 1,
|
||||||
maxResolution: 78271.51695,
|
|
||||||
sphericalMercator: true
|
sphericalMercator: true
|
||||||
}, options)
|
}, options)
|
||||||
var name = options.name || "Bing " + (options.type || this.type);
|
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) {
|
for (var i=0; i<res.imageUrlSubdomains.length; ++i) {
|
||||||
this.url.push(url.replace("{subdomain}", res.imageUrlSubdomains[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({
|
this.addOptions({
|
||||||
maxResolution: 78271.51695 / Math.pow(2, res.zoomMin - 1),
|
restrictedMinZoom: res.zoomMin,
|
||||||
numZoomLevels: res.zoomMax - res.zoomMin + 1
|
numZoomLevels: res.zoomMax + 1
|
||||||
});
|
});
|
||||||
// adjust zoom level to match the previous resolution - this triggers a
|
this.updateAttribution();
|
||||||
// moveTo on all layers.
|
|
||||||
resolution && this.map.zoomTo(this.getZoomForResolution(resolution));
|
|
||||||
// redraw to replace "blank.gif" tiles with real tiles
|
// redraw to replace "blank.gif" tiles with real tiles
|
||||||
this.redraw();
|
this.redraw();
|
||||||
},
|
},
|
||||||
@@ -179,7 +169,7 @@ OpenLayers.Layer.Bing = OpenLayers.Class(OpenLayers.Layer.XYZ, {
|
|||||||
*/
|
*/
|
||||||
updateAttribution: function() {
|
updateAttribution: function() {
|
||||||
var metadata = this.metadata;
|
var metadata = this.metadata;
|
||||||
if (!metadata || !this.map) {
|
if (!metadata || !this.map || !this.map.center) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var res = metadata.resourceSets[0].resources[0];
|
var res = metadata.resourceSets[0].resources[0];
|
||||||
@@ -213,9 +203,7 @@ OpenLayers.Layer.Bing = OpenLayers.Class(OpenLayers.Layer.XYZ, {
|
|||||||
*/
|
*/
|
||||||
setMap: function() {
|
setMap: function() {
|
||||||
OpenLayers.Layer.XYZ.prototype.setMap.apply(this, arguments);
|
OpenLayers.Layer.XYZ.prototype.setMap.apply(this, arguments);
|
||||||
if (this.map.getCenter()) {
|
this.updateAttribution();
|
||||||
this.updateAttribution();
|
|
||||||
}
|
|
||||||
this.map.events.register("moveend", this, this.updateAttribution);
|
this.map.events.register("moveend", this, this.updateAttribution);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
@@ -24,7 +24,7 @@
|
|||||||
};
|
};
|
||||||
layer = new OpenLayers.Layer.Bing({metadataParams: {foo: "bar"}});
|
layer = new OpenLayers.Layer.Bing({metadataParams: {foo: "bar"}});
|
||||||
t.ok(layer instanceof OpenLayers.Layer.Bing, "returns OpenLayers.Layer.Bing object" );
|
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(log.length, 1, "processMetadata called");
|
||||||
t.eq(OpenLayers.Util.getParameters(log[0]).foo, "bar", "metadataParams passed to url correctly.");
|
t.eq(OpenLayers.Util.getParameters(log[0]).foo, "bar", "metadataParams passed to url correctly.");
|
||||||
OpenLayers.Layer.Bing.processMetadata = origProcessMetadata;
|
OpenLayers.Layer.Bing.processMetadata = origProcessMetadata;
|
||||||
@@ -66,13 +66,13 @@
|
|||||||
})]);
|
})]);
|
||||||
map2.zoomToMaxExtent();
|
map2.zoomToMaxExtent();
|
||||||
|
|
||||||
t.delay_call(2.0, function() {
|
t.delay_call(5, function() {
|
||||||
origProcessMetadata.call(layer, meta[0]);
|
origProcessMetadata.call(layer, meta[0]);
|
||||||
t.eq(extent.toBBOX(), map.getExtent().toBBOX(), "layer extent correct for base layer with zoomMin == 1.");
|
t.eq(extent.toBBOX(), map.getExtent().toBBOX(), "layer extent correct for base layer with zoomMin == 1.");
|
||||||
map.destroy();
|
map.destroy();
|
||||||
});
|
});
|
||||||
|
|
||||||
t.delay_call(2.5, function() {
|
t.delay_call(6, function() {
|
||||||
origProcessMetadata.call(layer2, meta[1]);
|
origProcessMetadata.call(layer2, meta[1]);
|
||||||
t.eq(extent2.toBBOX(), map2.getExtent().toBBOX(), "layer extent correct for base layer with zoomMin == 2.");
|
t.eq(extent2.toBBOX(), map2.getExtent().toBBOX(), "layer extent correct for base layer with zoomMin == 2.");
|
||||||
map2.destroy();
|
map2.destroy();
|
||||||
|
|||||||
Reference in New Issue
Block a user