[OpenLayers-Commits] r11032 - in trunk/openlayers: examples lib/OpenLayers/Layer tests/Layer

commits-20090109 at openlayers.org commits-20090109 at openlayers.org
Fri Jan 14 08:28:45 EST 2011


Author: ahocevar
Date: 2011-01-14 05:28:45 -0800 (Fri, 14 Jan 2011)
New Revision: 11032

Modified:
   trunk/openlayers/examples/bing-tiles.js
   trunk/openlayers/lib/OpenLayers/Layer/Bing.js
   trunk/openlayers/tests/Layer/Bing.html
Log:
made metadata api parameters configurable. p="Jeff Maki",me r=me (closes #3013)


Modified: trunk/openlayers/examples/bing-tiles.js
===================================================================
--- trunk/openlayers/examples/bing-tiles.js	2011-01-13 19:37:35 UTC (rev 11031)
+++ trunk/openlayers/examples/bing-tiles.js	2011-01-14 13:28:45 UTC (rev 11032)
@@ -6,7 +6,10 @@
 
 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,

Modified: trunk/openlayers/lib/OpenLayers/Layer/Bing.js
===================================================================
--- trunk/openlayers/lib/OpenLayers/Layer/Bing.js	2011-01-13 19:37:35 UTC (rev 11031)
+++ trunk/openlayers/lib/OpenLayers/Layer/Bing.js	2011-01-14 13:28:45 UTC (rev 11032)
@@ -42,6 +42,13 @@
      *     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
@@ -106,25 +113,26 @@
         
         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;

Modified: trunk/openlayers/tests/Layer/Bing.html
===================================================================
--- trunk/openlayers/tests/Layer/Bing.html	2011-01-13 19:37:35 UTC (rev 11031)
+++ trunk/openlayers/tests/Layer/Bing.html	2011-01-14 13:28:45 UTC (rev 11032)
@@ -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();
         });



More information about the Commits mailing list