From 3189a473fbaf627ee2354a1ab2655917d4d8e550 Mon Sep 17 00:00:00 2001 From: Robbie Mackay Date: Fri, 14 Dec 2012 12:13:24 +1300 Subject: [PATCH 1/2] Fetch Bing map tiles and logo over HTTPS if document uses https The Bing REST api still returns HTTP urls in meta data even if we hit the API over SSL. This replaces http:// with // to avoid any SSL browser errors. Default to replacing with // but can force http: or https: with the protocol parameter --- lib/OpenLayers/Layer/Bing.js | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/lib/OpenLayers/Layer/Bing.js b/lib/OpenLayers/Layer/Bing.js index 761c000aa0..8945662fe1 100644 --- a/lib/OpenLayers/Layer/Bing.js +++ b/lib/OpenLayers/Layer/Bing.js @@ -58,6 +58,12 @@ OpenLayers.Layer.Bing = OpenLayers.Class(OpenLayers.Layer.XYZ, { * {Object} Metadata for this layer, as returned by the callback script */ metadata: null, + + /** + * Property: protocolRegex + * {RegExp} Regular expression to match and replace http: in bing urls + */ + protocolRegex: /^http:/i, /** * APIProperty: type @@ -91,6 +97,19 @@ OpenLayers.Layer.Bing = OpenLayers.Class(OpenLayers.Layer.XYZ, { */ tileOptions: null, + /** APIProperty: protocol + * {String} Protocol to use to fetch Imagery Metadata, tiles and bing logo + * Can be 'http:' 'https:' or '' + * + * Warning: tiles may not be available under both HTTP and HTTPS protocols. + * Microsoft approved use of both HTTP and HTTPS urls for tiles. However + * this is undocumented and the Imagery Metadata API always returns HTTP + * urls. + * + * Default is + */ + protocol: '', + /** * Constructor: OpenLayers.Layer.Bing * Create a new Bing layer. @@ -145,7 +164,7 @@ OpenLayers.Layer.Bing = OpenLayers.Class(OpenLayers.Layer.XYZ, { jsonp: this._callbackId, include: "ImageryProviders" }, this.metadataParams); - var url = "//dev.virtualearth.net/REST/v1/Imagery/Metadata/" + + var url = this.protocol + "//dev.virtualearth.net/REST/v1/Imagery/Metadata/" + this.type + "?" + OpenLayers.Util.getParameterString(params); var script = document.createElement("script"); script.type = "text/javascript"; @@ -163,6 +182,7 @@ OpenLayers.Layer.Bing = OpenLayers.Class(OpenLayers.Layer.XYZ, { var res = this.metadata.resourceSets[0].resources[0]; var url = res.imageUrl.replace("{quadkey}", "${quadkey}"); url = url.replace("{culture}", this.culture); + url = url.replace(this.protocolRegex, this.protocol); this.url = []; for (var i=0; i Date: Fri, 14 Dec 2012 12:34:26 +1300 Subject: [PATCH 2/2] Add unit test for OpenLayers.Layer.Bing.protocol * Test that attribution logo uses correct protocol * Test that tile urls use correct protocol --- tests/Layer/Bing.html | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/tests/Layer/Bing.html b/tests/Layer/Bing.html index 69525df7a5..d930e719b0 100644 --- a/tests/Layer/Bing.html +++ b/tests/Layer/Bing.html @@ -178,6 +178,37 @@ t.ok(clone instanceof OpenLayers.Layer.Bing, "clone is a Layer.Bing instance"); } + function test_protocol(t) + { + t.plan(5); + + var map = new OpenLayers.Map("map"); + layer = new OpenLayers.Layer.Bing(options); + map.addLayer(layer); + map.zoomToMaxExtent(); + var tile = layer.tileQueue[0]; + + t.delay_call(5, function() { + t.ok(OpenLayers.Util.indexOf(layer.attribution, '