Merge pull request #700 from rjmackay/bing-maps-ssl-699
Make Bing maps use SSL (if current document does)
This commit is contained in:
@@ -59,6 +59,12 @@ OpenLayers.Layer.Bing = OpenLayers.Class(OpenLayers.Layer.XYZ, {
|
|||||||
*/
|
*/
|
||||||
metadata: null,
|
metadata: null,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Property: protocolRegex
|
||||||
|
* {RegExp} Regular expression to match and replace http: in bing urls
|
||||||
|
*/
|
||||||
|
protocolRegex: /^http:/i,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* APIProperty: type
|
* APIProperty: type
|
||||||
* {String} The layer identifier. Any non-birdseye imageryType
|
* {String} The layer identifier. Any non-birdseye imageryType
|
||||||
@@ -91,6 +97,19 @@ OpenLayers.Layer.Bing = OpenLayers.Class(OpenLayers.Layer.XYZ, {
|
|||||||
*/
|
*/
|
||||||
tileOptions: null,
|
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
|
* Constructor: OpenLayers.Layer.Bing
|
||||||
* Create a new Bing layer.
|
* Create a new Bing layer.
|
||||||
@@ -145,7 +164,7 @@ OpenLayers.Layer.Bing = OpenLayers.Class(OpenLayers.Layer.XYZ, {
|
|||||||
jsonp: this._callbackId,
|
jsonp: this._callbackId,
|
||||||
include: "ImageryProviders"
|
include: "ImageryProviders"
|
||||||
}, this.metadataParams);
|
}, 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);
|
this.type + "?" + OpenLayers.Util.getParameterString(params);
|
||||||
var script = document.createElement("script");
|
var script = document.createElement("script");
|
||||||
script.type = "text/javascript";
|
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 res = this.metadata.resourceSets[0].resources[0];
|
||||||
var url = res.imageUrl.replace("{quadkey}", "${quadkey}");
|
var url = res.imageUrl.replace("{quadkey}", "${quadkey}");
|
||||||
url = url.replace("{culture}", this.culture);
|
url = url.replace("{culture}", this.culture);
|
||||||
|
url = url.replace(this.protocolRegex, this.protocol);
|
||||||
this.url = [];
|
this.url = [];
|
||||||
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]));
|
||||||
@@ -248,9 +268,10 @@ OpenLayers.Layer.Bing = OpenLayers.Class(OpenLayers.Layer.XYZ, {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
var logo = metadata.brandLogoUri.replace(this.protocolRegex, this.protocol);
|
||||||
this.attribution = OpenLayers.String.format(this.attributionTemplate, {
|
this.attribution = OpenLayers.String.format(this.attributionTemplate, {
|
||||||
type: this.type.toLowerCase(),
|
type: this.type.toLowerCase(),
|
||||||
logo: metadata.brandLogoUri,
|
logo: logo,
|
||||||
copyrights: copyrights
|
copyrights: copyrights
|
||||||
});
|
});
|
||||||
this.map && this.map.events.triggerEvent("changelayer", {
|
this.map && this.map.events.triggerEvent("changelayer", {
|
||||||
|
|||||||
@@ -178,6 +178,37 @@
|
|||||||
t.ok(clone instanceof OpenLayers.Layer.Bing, "clone is a Layer.Bing instance");
|
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, '<img src="//') != -1, "Attribution contains a logo with protocol //");
|
||||||
|
t.ok(OpenLayers.Util.indexOf(layer.attribution, '<img src="http://') == -1, "Attribution logo does not have http:// protocol");
|
||||||
|
t.ok(OpenLayers.Util.indexOf(tile.url, 'http:') == -1, "Tile url does not contain http:");
|
||||||
|
|
||||||
|
map.destroy();
|
||||||
|
});
|
||||||
|
|
||||||
|
var map2 = new OpenLayers.Map("map");
|
||||||
|
layer_https = new OpenLayers.Layer.Bing(OpenLayers.Util.applyDefaults({protocol: 'https:'}, options));
|
||||||
|
map2.addLayer(layer_https);
|
||||||
|
map2.zoomToMaxExtent();
|
||||||
|
var tile = layer_https.tileQueue[0];
|
||||||
|
|
||||||
|
t.delay_call(5, function() {
|
||||||
|
t.ok(OpenLayers.Util.indexOf(layer_https.attribution, '<img src="https://') != -1, "Attribution logo has https:// protocol");
|
||||||
|
t.ok(OpenLayers.Util.indexOf(tile.url, 'https:') == 0, "Tile url contains https:");
|
||||||
|
map2.destroy();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|||||||
Reference in New Issue
Block a user