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
This commit is contained in:
@@ -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<res.imageUrlSubdomains.length; ++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, {
|
||||
type: this.type.toLowerCase(),
|
||||
logo: metadata.brandLogoUri,
|
||||
logo: logo,
|
||||
copyrights: copyrights
|
||||
});
|
||||
this.map && this.map.events.triggerEvent("changelayer", {
|
||||
|
||||
Reference in New Issue
Block a user