diff --git a/AUTHORS.md b/AUTHORS.md index 1aa44a2ae..8d6ac377e 100644 --- a/AUTHORS.md +++ b/AUTHORS.md @@ -9,4 +9,5 @@ Moyg Jean-Frederic Zbigniew Czernik Jonas Häggqvist -Sabas \ No newline at end of file +Sabas +Paul Spencer \ No newline at end of file diff --git a/WebContent/OSRM.config.js b/WebContent/OSRM.config.js index 5aa3115f6..5e6c452db 100644 --- a/WebContent/OSRM.config.js +++ b/WebContent/OSRM.config.js @@ -72,6 +72,18 @@ OSRM.DEFAULTS = { url:'http://{s}.tile.cloudmade.com/BC9A493B41014CAABB98F0471D759707/997/256/{z}/{x}/{y}.png', attribution:'Map data © 2011 OpenStreetMap contributors, Imagery © 2011 CloudMade', options:{maxZoom: 18} - } + }, + { + display_name: 'Bing Road', + apikey:'Ag_G9YGvTnWtqqSsQ5S4s44ddrRS7GmC7WO94Vo-NoL_p1TiWdwsYcIDirB3_5q-', + type:"Road", + bing:true, + }, + { + display_name: 'Bing Aerial', + apikey:'Ag_G9YGvTnWtqqSsQ5S4s44ddrRS7GmC7WO94Vo-NoL_p1TiWdwsYcIDirB3_5q-', + type:"Aerial", + bing:true, + } ] }; diff --git a/WebContent/base/OSRM.Map.js b/WebContent/base/OSRM.Map.js index 89b2a9844..848a71363 100644 --- a/WebContent/base/OSRM.Map.js +++ b/WebContent/base/OSRM.Map.js @@ -36,8 +36,12 @@ init: function() { var tile_servers = OSRM.DEFAULTS.TILE_SERVERS; var base_maps = {}; for(var i=0, size=tile_servers.length; i' + + '' + + //'
{copyrights}' + + '{copyrights}' + + '' + + 'Terms of Use', + + initialize: function(/*String*/ apiKey, /*String*/ mapType, /*Object*/ options) { + + this._apiKey = apiKey; + this._mapType = mapType; + + this._loadMetadata(); + + L.Util.setOptions(this, options); + }, + + _loadMetadata: function() { + this._callbackId = "_l_tilelayer_bing_" + (L.TileLayer.Bing._callbackId++); + var that = this; + window[this._callbackId] = function() { + L.TileLayer.Bing.processMetadata.apply(that, arguments); + }; + + var params = { + key: this._apiKey, + jsonp: this._callbackId, + include: 'ImageryProviders' + }, + url = "http://dev.virtualearth.net/REST/v1/Imagery/Metadata/" + + this._mapType + L.Util.getParamString(params), + script = document.createElement("script"); + + script.type = "text/javascript"; + script.src = url; + script.id = this._callbackId; + document.getElementsByTagName("head")[0].appendChild(script); + }, + + _onMetadataLoaded: function() {}, + + onAdd: function(map, insertAtTheBottom) { + if (!this.metadata) { + this._onMetadataLoaded = L.Util.bind(function() { + L.TileLayer.prototype.onAdd.call(this, map, insertAtTheBottom); + map.on('moveend', this._updateAttribution, this); + this._updateAttribution(); + }, this); + } else { + L.TileLayer.prototype.onAdd.call(this, map, insertAtTheBottom); + map.on('moveend', this._updateAttribution, this); + this._updateAttribution(); + } + }, + + onRemove: function(map) { + if (this._map.attributionControl) { + this._map.attributionControl.removeAttribution(this.attribution); + } + this._map.off('moveend', this._updateAttribution, this); + L.TileLayer.prototype.onRemove.call(this, map); + }, + + getTileUrl: function(xy, z) { + var subdomains = this.options.subdomains, + quadDigits = [], + i = z, + digit, + mask, + quadKey; + // borrowed directly from OpenLayers + for (; i > 0; --i) { + digit = '0'; + mask = 1 << (i - 1); + if ((xy.x & mask) != 0) { + digit++; + } + if ((xy.y & mask) != 0) { + digit++; + digit++; + } + quadDigits.push(digit); + } + + return this._url + .replace('{subdomain}', subdomains[(xy.x + xy.y) % subdomains.length]) + .replace('{quadkey}', quadDigits.join("")); + }, + + _updateAttribution: function() { + if (this._map.attributionControl) { + var metadata = this.metadata; + var res = metadata.resourceSets[0].resources[0]; + var bounds = this._map.getBounds(); + var providers = res.imageryProviders, zoom = this._map.getZoom() + 1, + copyrights = "", provider, i, ii, j, jj, bbox, coverage; + for (i=0,ii=providers.length; i= coverage.zoomMin && coverage.bbox.intersects(bounds)) { + copyrights += provider.attribution + " "; + j = jj; + } + } + } + this._map.attributionControl.removeAttribution(this.attribution); + this._map.attributionControl._attributions = {}; + this._map.attributionControl._update(); + this.attribution = this.attributionTemplate + .replace('{logo}', metadata.brandLogoUri) + .replace('{copyrights}', copyrights); + this._map.attributionControl.addAttribution(this.attribution); + } + } +}); + +L.TileLayer.Bing._callbackId = 0; + +L.TileLayer.Bing.processMetadata = function(metadata) { + if (metadata.authenticationResultCode != 'ValidCredentials') { + throw "Invalid Bing Maps API Key" + } + + if (!metadata.resourceSets.length || !metadata.resourceSets[0].resources.length) { + throw "No resources returned, perhaps " + this._mapType + " is an invalid map type?"; + } + + if (metadata.statusCode != 200) { + throw "Bing Maps API request failed with status code " + metadata.statusCode; + } + + this.metadata = metadata; + var res = metadata.resourceSets[0].resources[0], + providers = res.imageryProviders, + i = 0, + j, + provider, + bbox, + script = document.getElementById(this._callbackId); + + for (; i + diff --git a/WebContent/printing/printing.html b/WebContent/printing/printing.html index 388c9a3e2..9ce67d8ae 100644 --- a/WebContent/printing/printing.html +++ b/WebContent/printing/printing.html @@ -38,6 +38,7 @@ or see http://www.gnu.org/licenses/agpl.txt. + diff --git a/WebContent/printing/printing.js b/WebContent/printing/printing.js index 094867bbd..88f11da3c 100644 --- a/WebContent/printing/printing.js +++ b/WebContent/printing/printing.js @@ -53,7 +53,9 @@ OSRM.prefetchIcons = function(images_list) { // function to initialize a map in the new window OSRM.drawMap = function(tile_server, bounds) { // setup map - var tile_layer = new L.TileLayer(tile_server.url, tile_server.options); + var tile_layer; + if( tile_server.bing ) tile_layer = new L.TileLayer.Bing(tile_server.apikey, tile_server.type); + else tile_layer = new L.TileLayer(tile_server.url, tile_server.options); OSRM.G.map = new OSRM.MapView("overview-map", { center: new L.LatLng(48.84, 10.10), zoom: 13,