Skip to content

Commit

Permalink
made metadata api parameters configurable. p="Jeff Maki",me r=me (clo…
Browse files Browse the repository at this point in the history
…ses #3013)

git-svn-id: http://svn.openlayers.org/trunk/openlayers@11032 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
  • Loading branch information
ahocevar committed Jan 14, 2011
1 parent f68ee50 commit 3515d23
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 11 deletions.
5 changes: 4 additions & 1 deletion examples/bing-tiles.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ var map = new OpenLayers.Map( 'map');

var road = new OpenLayers.Layer.Bing({
key: apiKey,
type: "Road"
type: "Road",
// custom metadata parameter to request the new map style - only useful
// before May 1st, 2011
metadataParams: {mapVersion: "v1"}
});
var aerial = new OpenLayers.Layer.Bing({
key: apiKey,
Expand Down
22 changes: 15 additions & 7 deletions lib/OpenLayers/Layer/Bing.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@ OpenLayers.Layer.Bing = OpenLayers.Class(OpenLayers.Layer.XYZ, {
* used. Default is "Road".
*/
type: "Road",

/**
* APIProperty: metadataParams
* {Object} Optional url parameters for the Get Imagery Metadata request
* as described here: http://msdn.microsoft.com/en-us/library/ff701716.aspx
*/
metadataParams: null,

/**
* Constant: EVENT_TYPES
Expand Down Expand Up @@ -106,25 +113,26 @@ OpenLayers.Layer.Bing = OpenLayers.Class(OpenLayers.Layer.XYZ, {

var newArgs = [name, null, options];
OpenLayers.Layer.XYZ.prototype.initialize.apply(this, newArgs);
this.loadMetadata(this.type);
this.loadMetadata();
},

/**
* Method: loadMetadata
*
* Parameters:
* imageryType - {String}
*/
loadMetadata: function(imageryType) {
loadMetadata: function() {
this._callbackId = "_callback_" + this.id.replace(/\./g, "_");
// link the processMetadata method to the global scope and bind it
// to this instance
window[this._callbackId] = OpenLayers.Function.bind(
OpenLayers.Layer.Bing.processMetadata, this
);
var params = OpenLayers.Util.applyDefaults({
key: this.key,
jsonp: this._callbackId,
include: "ImageryProviders"
}, this.metadataParams);
var url = "http://dev.virtualearth.net/REST/v1/Imagery/Metadata/" +
imageryType + "?key=" + this.key + "&jsonp=" + this._callbackId +
"&include=ImageryProviders";
this.type + "?" + OpenLayers.Util.getParameterString(params);
var script = document.createElement("script");
script.type = "text/javascript";
script.src = url;
Expand Down
8 changes: 5 additions & 3 deletions tests/Layer/Bing.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,20 @@
};

function test_constructor(t) {
t.plan(2);
t.plan(3);

var origProcessMetadata = OpenLayers.Layer.Bing.processMetadata;
var log = [];
OpenLayers.Layer.Bing.processMetadata = function(metadata) {
log.push(metadata);
var script = document.getElementById(this._callbackId);
log.push(script.src);
origProcessMetadata.apply(this, arguments);
};
layer = new OpenLayers.Layer.Bing(options);
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.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();
});
Expand Down

0 comments on commit 3515d23

Please sign in to comment.