Access Bing maps via SSL / https

2748
6
10-12-2011 02:49 PM
bradcochran1
New Contributor
I have seen other questions about this without answers.  Hopefully someone out there can give some assistance. 

I need to access the 'esri.virtualearth.VETiledLayer' over SSL and have the results returned via https.  I have confirmed that everything works with SSL from the Bing side of things, but apparently the wrapper that ESRI made for this will only use http. 

Does anyone know how this can be accomplished?  I would greatly appreciate any assistance with this. 

Thanks!
0 Kudos
6 Replies
derekswingley1
Frequent Contributor
Hi Brad,

You can use https by adding the following code to your app (please use your own bing key):
esri.setRequestPreCallback(function(ioArgs) {
  if(ioArgs.url.search("serverapi.arcgisonline.com/veadaptor/") > 0) {
    ioArgs.url = ioArgs.url.replace("http:", "https:");
  }
  return ioArgs;
});

//Creates the Virtual Earth layer to add to the map
veTileLayer = new esri.virtualearth.VETiledLayer({
  bingMapsKey: 'Ah29HpXlpKwqVbjHzm6mlwMwgw69CYjaMIiW_YOdfTEMFvMr5SNiltLpYAcIocsi',
  mapStyle: esri.virtualearth.VETiledLayer.MAP_STYLE_AERIAL
});

dojo.connect(veTileLayer, "onLoad", function(veTileLayer) {
  veTileLayer.tileServers = dojo.map(veTileLayer.tileServers, function(tileServer) {
    return tileServer.replace("http:", "https:");
  });
});


We'll put a fix in for this in the next version of the API (2.6).
0 Kudos
bradcochran1
New Contributor
Thank you so much, this worked perfectly.
0 Kudos
DavidHollema
New Contributor III
Was this fix implemented at 2.6?  If so, how do I create an https bing maps layer at 2.6?  I'm trying to find API documentation on it but can't.

Further, can I create an https bing maps layer as an esri.dijit.BaseMapLayer type?


We'll put a fix in for this in the next version of the API (2.6).
0 Kudos
derekswingley1
Frequent Contributor
Yes, we fixed this with 2.6. The way you create bing layers hasn't changed, use the esri.virtualearth.VETiledLayer class.
0 Kudos
DavidHollema
New Contributor III
To follow up on this question.  I tested at 2.6 on an SSL hosted page and the JS API automatically switched the bing maps call to https.  I'm using an esri.dijit.BaseMapLayer with type set to "BingMapsHybrid".  So it appears the JS API is detecting the protocol (http vs https) of the host page and switching the bing maps request protocol automatically.  Works nice.

Was this fix implemented at 2.6?  If so, how do I create an https bing maps layer at 2.6?  I'm trying to find API documentation on it but can't.

Further, can I create an https bing maps layer as an esri.dijit.BaseMapLayer type?
0 Kudos
derekswingley1
Frequent Contributor
...it appears the JS API is detecting the protocol (http vs https) of the host page and switching the bing maps request protocol automatically.

Yes, that is correct!
0 Kudos