fix Bing layer's zoom level management. r=tschaub (closes #2987)
git-svn-id: http://svn.openlayers.org/trunk/openlayers@10997 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
@@ -18,35 +18,6 @@
|
|||||||
*/
|
*/
|
||||||
OpenLayers.Layer.Bing = OpenLayers.Class(OpenLayers.Layer.XYZ, {
|
OpenLayers.Layer.Bing = OpenLayers.Class(OpenLayers.Layer.XYZ, {
|
||||||
|
|
||||||
/**
|
|
||||||
* Constant: RESOLUTIONS
|
|
||||||
*/
|
|
||||||
RESOLUTIONS: [
|
|
||||||
78271.517,
|
|
||||||
39135.7585,
|
|
||||||
19567.87925,
|
|
||||||
9783.939625,
|
|
||||||
4891.9698125,
|
|
||||||
2445.98490625,
|
|
||||||
1222.992453125,
|
|
||||||
611.4962265625,
|
|
||||||
305.74811328125,
|
|
||||||
152.874056640625,
|
|
||||||
76.4370283203125,
|
|
||||||
38.21851416015625,
|
|
||||||
19.109257080078127,
|
|
||||||
9.554628540039063,
|
|
||||||
4.777314270019532,
|
|
||||||
2.388657135009766,
|
|
||||||
1.194328567504883,
|
|
||||||
0.5971642837524415,
|
|
||||||
0.29858214187622073,
|
|
||||||
0.14929107093811037,
|
|
||||||
0.07464553546905518,
|
|
||||||
0.03732276773452759,
|
|
||||||
0.018661383867263796
|
|
||||||
],
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Property: attributionTemplate
|
* Property: attributionTemplate
|
||||||
* {String}
|
* {String}
|
||||||
@@ -58,12 +29,6 @@ OpenLayers.Layer.Bing = OpenLayers.Class(OpenLayers.Layer.XYZ, {
|
|||||||
'href="http://www.microsoft.com/maps/product/terms.html">' +
|
'href="http://www.microsoft.com/maps/product/terms.html">' +
|
||||||
'Terms of Use</a></span>',
|
'Terms of Use</a></span>',
|
||||||
|
|
||||||
/**
|
|
||||||
* Property: sphericalMercator
|
|
||||||
* {Boolean} always true for this layer type
|
|
||||||
*/
|
|
||||||
sphericalMercator: true,
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Property: metadata
|
* Property: metadata
|
||||||
* {Object} Metadata for this layer, as returned by the callback script
|
* {Object} Metadata for this layer, as returned by the callback script
|
||||||
@@ -131,7 +96,14 @@ OpenLayers.Layer.Bing = OpenLayers.Class(OpenLayers.Layer.XYZ, {
|
|||||||
OpenLayers.Layer.Bing.prototype.EVENT_TYPES.concat(
|
OpenLayers.Layer.Bing.prototype.EVENT_TYPES.concat(
|
||||||
OpenLayers.Layer.prototype.EVENT_TYPES
|
OpenLayers.Layer.prototype.EVENT_TYPES
|
||||||
);
|
);
|
||||||
|
|
||||||
|
options = OpenLayers.Util.applyDefaults({
|
||||||
|
zoomOffset: 1,
|
||||||
|
maxResolution: 78271.51695,
|
||||||
|
sphericalMercator: true
|
||||||
|
}, options)
|
||||||
var name = options.name || "Bing " + (options.type || this.type);
|
var name = options.name || "Bing " + (options.type || this.type);
|
||||||
|
|
||||||
var newArgs = [name, null, options];
|
var newArgs = [name, null, options];
|
||||||
OpenLayers.Layer.XYZ.prototype.initialize.apply(this, newArgs);
|
OpenLayers.Layer.XYZ.prototype.initialize.apply(this, newArgs);
|
||||||
this.loadMetadata(this.type);
|
this.loadMetadata(this.type);
|
||||||
@@ -172,15 +144,22 @@ 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;
|
||||||
this.addOptions({
|
if (this.map && this.map.baseLayer === this && this.map.getCenter()) {
|
||||||
resolutions: this.RESOLUTIONS.slice(res.zoomMin-1, res.zoomMax-1),
|
// if we are the current base layer and the map was centered
|
||||||
zoomOffset: res.zoomMin
|
// already, we need to remember the current resolution to find a
|
||||||
});
|
// matching zoom level after the maxResolution changes
|
||||||
if (this.map) {
|
resolution = this.getResolution();
|
||||||
this.redraw();
|
|
||||||
this.updateAttribution();
|
|
||||||
}
|
}
|
||||||
|
this.addOptions({
|
||||||
|
maxResolution: 78271.51695 / Math.pow(2, res.zoomMin - 1),
|
||||||
|
numZoomLevels: res.zoomMax - res.zoomMin + 1
|
||||||
|
});
|
||||||
|
// adjust zoom level to match the previous resolution - this triggers a
|
||||||
|
// moveTo on all layers.
|
||||||
|
resolution && this.map.zoomTo(this.getZoomForResolution(resolution));
|
||||||
|
// redraw to replace "blank.gif" tiles with real tiles
|
||||||
|
this.redraw();
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
+49
-1
@@ -2,7 +2,7 @@
|
|||||||
<head>
|
<head>
|
||||||
<script src="../../lib/OpenLayers.js"></script>
|
<script src="../../lib/OpenLayers.js"></script>
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
var layer;
|
var map, layer;
|
||||||
|
|
||||||
var layerType = 'Aerial';
|
var layerType = 'Aerial';
|
||||||
var key = "AqTGBsziZHIJYYxgivLBf0hVdrAk9mWO5cQcb8Yux8sW5M8c8opEC2lZqKR1ZZXf";
|
var key = "AqTGBsziZHIJYYxgivLBf0hVdrAk9mWO5cQcb8Yux8sW5M8c8opEC2lZqKR1ZZXf";
|
||||||
@@ -30,6 +30,54 @@
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function test_initLayer(t) {
|
||||||
|
t.plan(2);
|
||||||
|
|
||||||
|
var meta = [];
|
||||||
|
var origProcessMetadata = OpenLayers.Layer.Bing.processMetadata;
|
||||||
|
OpenLayers.Layer.Bing.processMetadata = function(metadata) {
|
||||||
|
meta.push(metadata);
|
||||||
|
}
|
||||||
|
map = new OpenLayers.Map("map");
|
||||||
|
layer = new OpenLayers.Layer.Bing(options);
|
||||||
|
var extent;
|
||||||
|
map.addLayers([layer, new OpenLayers.Layer(null, {
|
||||||
|
moveTo: function(bounds, changed) {
|
||||||
|
extent = bounds;
|
||||||
|
}
|
||||||
|
})]);
|
||||||
|
map.zoomToMaxExtent();
|
||||||
|
|
||||||
|
var map2 = new OpenLayers.Map("map");
|
||||||
|
var layer2 = new OpenLayers.Layer.Bing(OpenLayers.Util.extend({
|
||||||
|
initLayer: function() {
|
||||||
|
// pretend we have a zoomMin of 2
|
||||||
|
this.metadata.resourceSets[0].resources[0].zoomMin = 2;
|
||||||
|
OpenLayers.Layer.Bing.prototype.initLayer.apply(this, arguments);
|
||||||
|
}
|
||||||
|
}, options));
|
||||||
|
var extent2;
|
||||||
|
map2.addLayers([layer2, new OpenLayers.Layer(null, {
|
||||||
|
moveTo: function(bounds, changed) {
|
||||||
|
extent2 = bounds;
|
||||||
|
}
|
||||||
|
})]);
|
||||||
|
map2.zoomToMaxExtent();
|
||||||
|
|
||||||
|
t.delay_call(2.0, 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() {
|
||||||
|
origProcessMetadata.call(layer2, meta[1]);
|
||||||
|
t.eq(extent2.toBBOX(), map2.getExtent().toBBOX(), "layer extent correct for base layer with zoomMin == 2.");
|
||||||
|
map2.destroy();
|
||||||
|
OpenLayers.Layer.Bing.processMetadata = origProcessMetadata;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
function test_attribution(t) {
|
function test_attribution(t) {
|
||||||
t.plan(3);
|
t.plan(3);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user