Created
August 5, 2014 20:44
-
-
Save alexnorton/76734e56e475a868376c to your computer and use it in GitHub Desktop.
Use Bing Maps Ordnance Survey tiles as a Leaflet TileLayer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var BingLayer = L.TileLayer.extend({ | |
getTileUrl: function (tilePoint) { | |
this._adjustTilePoint(tilePoint); | |
return L.Util.template(this._url, { | |
s: this._getSubdomain(tilePoint), | |
q: this._quadKey(tilePoint.x, tilePoint.y, this._getZoomForUrl()) | |
}); | |
}, | |
_quadKey: function (x, y, z) { | |
var quadKey = []; | |
for (var i = z; i > 0; i--) { | |
var digit = '0'; | |
var mask = 1 << (i - 1); | |
if ((x & mask) != 0) { | |
digit++; | |
} | |
if ((y & mask) != 0) { | |
digit++; | |
digit++; | |
} | |
quadKey.push(digit); | |
} | |
return quadKey.join(''); | |
} | |
}); | |
var layer = new BingLayer('http://ecn.t{s}.tiles.virtualearth.net/tiles/r{q}?g=1567&lbl=l1&productSet=mmOS', { | |
subdomains: ['0', '1', '2', '3', '4', '5', '6', '7'], | |
attribution: '© <a href="http://bing.com/maps">Bing Maps</a>', | |
detectRetina: true | |
}); | |
var map = new L.Map(document.querySelector('#map'), { | |
layers: [layer], | |
center: new L.LatLng(51.7617353,-1.2427226), | |
zoom: 12 | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Adapted from http://stackoverflow.com/a/17156220