Previously, Bing overlays that were added to an existing map had empty tiles, because tiles are added before the layer url is set in initLayer. This change makes sure tiles are only rendered when the layer url is available, by not processing the tile queue before the layer url is set.
187 lines
6.5 KiB
HTML
187 lines
6.5 KiB
HTML
<html>
|
|
<head>
|
|
<script>
|
|
/**
|
|
* Because browsers that implement requestAnimationFrame may not execute
|
|
* animation functions while a window is not displayed (e.g. in a hidden
|
|
* iframe as in these tests), we mask the native implementations here. The
|
|
* native requestAnimationFrame functionality is tested in Util.html and
|
|
* in PanZoom.html (where a popup is opened before panning).
|
|
*/
|
|
window.requestAnimationFrame =
|
|
window.webkitRequestAnimationFrame =
|
|
window.mozRequestAnimationFrame =
|
|
window.oRequestAnimationFrame =
|
|
window.msRequestAnimationFrame = null;
|
|
</script>
|
|
<script src="../OLLoader.js"></script>
|
|
<script type="text/javascript">
|
|
var map, layer;
|
|
|
|
var layerType = 'Aerial';
|
|
var key = "AqTGBsziZHIJYYxgivLBf0hVdrAk9mWO5cQcb8Yux8sW5M8c8opEC2lZqKR1ZZXf";
|
|
|
|
var options = {
|
|
type: layerType,
|
|
key: key
|
|
};
|
|
|
|
function test_constructor(t) {
|
|
t.plan(3);
|
|
|
|
var origProcessMetadata = OpenLayers.Layer.Bing.processMetadata;
|
|
var log = [];
|
|
OpenLayers.Layer.Bing.processMetadata = function(metadata) {
|
|
var script = document.getElementById(this._callbackId);
|
|
log.push(script.src);
|
|
origProcessMetadata.apply(this, arguments);
|
|
};
|
|
layer = new OpenLayers.Layer.Bing(OpenLayers.Util.extend({
|
|
metadataParams: {foo: "bar"}
|
|
}, options));
|
|
t.ok(layer instanceof OpenLayers.Layer.Bing, "returns OpenLayers.Layer.Bing object" );
|
|
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;
|
|
layer.destroy();
|
|
});
|
|
}
|
|
|
|
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(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(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();
|
|
OpenLayers.Layer.Bing.processMetadata = origProcessMetadata;
|
|
});
|
|
}
|
|
|
|
function test_initLayer_notempty(t) {
|
|
t.plan(1);
|
|
|
|
map = new OpenLayers.Map("map", {
|
|
projection: "EPSG:3857",
|
|
layers: [new OpenLayers.Layer("dummy", {isBaseLayer: true})]
|
|
});
|
|
map.zoomToExtent([-14768652, 4492113, -12263964, 5744457]);
|
|
var layer = new OpenLayers.Layer.Bing(OpenLayers.Util.extend({
|
|
isBaseLayer: false
|
|
}, options));
|
|
map.addLayer(layer);
|
|
var tile = layer.tileQueue[0];
|
|
|
|
t.delay_call(5, function() {
|
|
t.ok(tile.url, "Tile not empty");
|
|
map.destroy();
|
|
});
|
|
}
|
|
|
|
function test_attribution(t) {
|
|
t.plan(3);
|
|
|
|
var log = [];
|
|
var map = new OpenLayers.Map("map");
|
|
layer = new OpenLayers.Layer.Bing(options);
|
|
map.addLayer(layer);
|
|
map.zoomToMaxExtent();
|
|
|
|
t.delay_call(2, function() {
|
|
t.ok(layer.attribution.indexOf('olBingAttribution aerial') !== -1, "Attribution has the correct css class");
|
|
t.ok(layer.attribution.indexOf('<img src="">') == -1, "Attribution contains a logo");
|
|
t.ok(layer.attribution.indexOf('</img></div></a><a style=') == -1 , "Attribution contains a copyright");
|
|
map.destroy();
|
|
});
|
|
}
|
|
|
|
function test_attribution_notempty(t) {
|
|
t.plan(1);
|
|
|
|
var log = [];
|
|
var map = new OpenLayers.Map("map");
|
|
layer = new OpenLayers.Layer.Bing(OpenLayers.Util.applyDefaults({type: 'Road'}, options));
|
|
map.addLayer(layer);
|
|
var format = OpenLayers.String.format;
|
|
OpenLayers.String.format = function(tpl, options) {
|
|
log.push(options.copyrights);
|
|
}
|
|
map.zoomToExtent(new OpenLayers.Bounds(-14768652, 4492113, -12263964, 5744457));
|
|
t.delay_call(2, function() {
|
|
t.ok(log.join("") !== "", "Copyright not empty");
|
|
OpenLayers.String.format = format;
|
|
map.destroy();
|
|
});
|
|
}
|
|
|
|
function test_getXYZ(t) {
|
|
t.plan(1);
|
|
|
|
var map = new OpenLayers.Map("map", {allOverlays: true});
|
|
var osm = new OpenLayers.Layer.OSM();
|
|
map.addLayer(osm);
|
|
map.zoomToExtent(new OpenLayers.Bounds(11373579,-2445208,13628777,680760));
|
|
layer = new OpenLayers.Layer.Bing(options);
|
|
map.addLayer(layer);
|
|
|
|
t.delay_call(2, function() {
|
|
var xyz = layer.getXYZ(layer.getTileBounds(new OpenLayers.Pixel(1,1)));
|
|
t.eq(xyz.z, OpenLayers.Util.indexOf(layer.serverResolutions, map.getResolution()), "zoom level correct");
|
|
});
|
|
}
|
|
|
|
function test_clone(t) {
|
|
t.plan(1);
|
|
|
|
var clone;
|
|
|
|
layer = new OpenLayers.Layer.Bing(options);
|
|
clone = layer.clone();
|
|
t.ok(clone instanceof OpenLayers.Layer.Bing, "clone is a Layer.Bing instance");
|
|
}
|
|
|
|
</script>
|
|
</head>
|
|
<body>
|
|
<div id="map" style="width:500px;height:550px"></div>
|
|
</body>
|
|
</html>
|