Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

added slightly messy but working Bing example

git-svn-id: https://modestmaps.googlecode.com/svn/trunk/js@924 a23cadb0-8de1-11de-82e5-a1837a67dc72
  • Loading branch information...
commit fcf0c61008361a284bb1ec8ef461f69f459c6f0a 1 parent 7618308
tom.carden authored
Showing with 114 additions and 0 deletions.
  1. +77 −0 examples/microsoft/bing.js
  2. +37 −0 examples/microsoft/index.html
View
77 examples/microsoft/bing.js
@@ -0,0 +1,77 @@
+// namespacing!
+if (!com) {
+ var com = { };
+ if (!com.modestmaps) {
+ com.modestmaps = { };
+ }
+}
+
+com.modestmaps.BingProvider = function(key, style, onready) {
+
+ this.key = key;
+ this.style = style;
+
+ // hit the imagery metadata service
+ // http://msdn.microsoft.com/en-us/library/ff701716.aspx
+
+ // Aerial, AerialWithLabels, Road
+ var script = document.createElement('script');
+ script.type = 'text/javascript';
+ document.getElementsByTagName('head')[0].appendChild(script);
+ script.src = 'http://dev.virtualearth.net/REST/V1/Imagery/Metadata/'+style+'/?key='+key+'&jsonp=onBingComplete';
+
+ function toMicrosoft(column, row, zoom) {
+ // generate zoom string by interleaving row/col bits
+ // NB:- this assumes you're only asking for positive row/cols
+ var quadKey = "";
+ for (var i = 1; i <= zoom; i++)
+ {
+ var rowBit = (row >> zoom-i) & 1;
+ var colBit = (column >> zoom-i) & 1;
+ quadKey += (rowBit << 1) + colBit;
+ }
+ return quadKey;
+ }
+
+ var provider = this;
+
+ window.onBingComplete = function(data) {
+
+ var resourceSets = data.resourceSets;
+ for (var i = 0; i < resourceSets.length; i++) {
+ var resources = data.resourceSets[i].resources;
+ for (var j = 0; j < resources.length; j++) {
+ var resource = resources[j];
+
+ var serverSalt = Math.floor(Math.random() * 4);
+ provider.getTileUrl = function(coord) {
+ var quadKey = toMicrosoft(coord.column, coord.row, coord.zoom);
+ // this is so that requests will be consistent in this session, rather than totally random
+ var server = Math.abs(serverSalt + coord.column + coord.row + coord.zoom) % 4;
+ return resource.imageUrl
+ .replace('{quadkey}',quadKey)
+ .replace('{subdomain}', resource.imageUrlSubdomains[server]);
+ }
+
+ // TODO: use resource.imageWidth
+ // TODO: use resource.imageHeight
+ }
+ }
+
+ // TODO: display data.brandLogoUri
+ // TODO: display data.copyright
+
+ onready(provider);
+ }
+
+
+}
+
+com.modestmaps.BingProvider.prototype = {
+ key: null,
+ style: null,
+ subdomains: null,
+ getTileUrl: null
+}
+
+com.modestmaps.extend(com.modestmaps.BingProvider, com.modestmaps.MapProvider);
View
37 examples/microsoft/index.html
@@ -0,0 +1,37 @@
+<html>
+<head>
+<title>Modest Maps JS</title>
+<script type="text/javascript" src="../../modestmaps.js"></script>
+<script type="text/javascript" src="bing.js"></script>
+<script type="text/javascript">
+
+ var map;
+
+ function initMap() {
+
+ // "import" the namespace
+ var mm = com.modestmaps;
+
+ // please use your own API key!
+ var key = "AjBbdc2nn_71Hyc__uvinjvuHX5g8GLMiVYCJdx7XLLfiSenf1qtnmbv_VO8iyOj",
+ style = 'AerialWithLabels',
+ provider = new mm.BingProvider(key, style, function() {
+ map = new mm.Map(document.body, provider)
+ map.setCenterZoom(new mm.Location(37.804656, -122.263606), 14);
+ });
+
+ }
+
+</script>
+<style type="text/css">
+ body {
+ width: 100%;
+ height: 100%;
+ padding: 0;
+ margin: 0;
+ }
+</style>
+</head>
+<body onload="initMap()">
+</body>
+</html>
Please sign in to comment.
Something went wrong with that request. Please try again.