BingMapsImageryProvider.js 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699
  1. import BingMapsApi from '../Core/BingMapsApi.js';
  2. import buildModuleUrl from '../Core/buildModuleUrl.js';
  3. import Check from '../Core/Check.js';
  4. import Credit from '../Core/Credit.js';
  5. import defaultValue from '../Core/defaultValue.js';
  6. import defined from '../Core/defined.js';
  7. import defineProperties from '../Core/defineProperties.js';
  8. import DeveloperError from '../Core/DeveloperError.js';
  9. import Event from '../Core/Event.js';
  10. import CesiumMath from '../Core/Math.js';
  11. import Rectangle from '../Core/Rectangle.js';
  12. import Resource from '../Core/Resource.js';
  13. import RuntimeError from '../Core/RuntimeError.js';
  14. import TileProviderError from '../Core/TileProviderError.js';
  15. import WebMercatorTilingScheme from '../Core/WebMercatorTilingScheme.js';
  16. import when from '../ThirdParty/when.js';
  17. import BingMapsStyle from './BingMapsStyle.js';
  18. import DiscardEmptyTilePolicy from './DiscardEmptyTileImagePolicy.js';
  19. import ImageryProvider from './ImageryProvider.js';
  20. /**
  21. * Provides tiled imagery using the Bing Maps Imagery REST API.
  22. *
  23. * @alias BingMapsImageryProvider
  24. * @constructor
  25. *
  26. * @param {Object} options Object with the following properties:
  27. * @param {Resource|String} options.url The url of the Bing Maps server hosting the imagery.
  28. * @param {String} [options.key] The Bing Maps key for your application, which can be
  29. * created at {@link https://www.bingmapsportal.com/}.
  30. * If this parameter is not provided, {@link BingMapsApi.defaultKey} is used, which is undefined by default.
  31. * @param {String} [options.tileProtocol] The protocol to use when loading tiles, e.g. 'http' or 'https'.
  32. * By default, tiles are loaded using the same protocol as the page.
  33. * @param {BingMapsStyle} [options.mapStyle=BingMapsStyle.AERIAL] The type of Bing Maps imagery to load.
  34. * @param {String} [options.culture=''] The culture to use when requesting Bing Maps imagery. Not
  35. * all cultures are supported. See {@link http://msdn.microsoft.com/en-us/library/hh441729.aspx}
  36. * for information on the supported cultures.
  37. * @param {Ellipsoid} [options.ellipsoid] The ellipsoid. If not specified, the WGS84 ellipsoid is used.
  38. * @param {TileDiscardPolicy} [options.tileDiscardPolicy] The policy that determines if a tile
  39. * is invalid and should be discarded. By default, a {@link DiscardEmptyTileImagePolicy}
  40. * will be used, with the expectation that the Bing Maps server will send a zero-length response for missing tiles.
  41. * To ensure that no tiles are discarded, construct and pass a {@link NeverTileDiscardPolicy} for this parameter.
  42. *
  43. * @see ArcGisMapServerImageryProvider
  44. * @see GoogleEarthEnterpriseMapsProvider
  45. * @see OpenStreetMapImageryProvider
  46. * @see SingleTileImageryProvider
  47. * @see TileMapServiceImageryProvider
  48. * @see WebMapServiceImageryProvider
  49. * @see WebMapTileServiceImageryProvider
  50. * @see UrlTemplateImageryProvider
  51. *
  52. *
  53. * @example
  54. * var bing = new Cesium.BingMapsImageryProvider({
  55. * url : 'https://dev.virtualearth.net',
  56. * key : 'get-yours-at-https://www.bingmapsportal.com/',
  57. * mapStyle : Cesium.BingMapsStyle.AERIAL
  58. * });
  59. *
  60. * @see {@link http://msdn.microsoft.com/en-us/library/ff701713.aspx|Bing Maps REST Services}
  61. * @see {@link http://www.w3.org/TR/cors/|Cross-Origin Resource Sharing}
  62. */
  63. function BingMapsImageryProvider(options) {
  64. options = defaultValue(options, defaultValue.EMPTY_OBJECT);
  65. //>>includeStart('debug', pragmas.debug);
  66. if (!defined(options.url)) {
  67. throw new DeveloperError('options.url is required.');
  68. }
  69. //>>includeEnd('debug');
  70. this._key = BingMapsApi.getKey(options.key);
  71. this._resource = Resource.createIfNeeded(options.url);
  72. this._resource.appendForwardSlash();
  73. this._tileProtocol = options.tileProtocol;
  74. this._mapStyle = defaultValue(options.mapStyle, BingMapsStyle.AERIAL);
  75. this._culture = defaultValue(options.culture, '');
  76. this._tileDiscardPolicy = options.tileDiscardPolicy;
  77. if (!defined(this._tileDiscardPolicy)) {
  78. this._tileDiscardPolicy = new DiscardEmptyTilePolicy();
  79. }
  80. this._proxy = options.proxy;
  81. this._credit = new Credit('<a href="http://www.bing.com"><img src="' + BingMapsImageryProvider.logoUrl + '" title="Bing Imagery"/></a>');
  82. /**
  83. * The default {@link ImageryLayer#gamma} to use for imagery layers created for this provider.
  84. * Changing this value after creating an {@link ImageryLayer} for this provider will have
  85. * no effect. Instead, set the layer's {@link ImageryLayer#gamma} property.
  86. *
  87. * @type {Number}
  88. * @default 1.0
  89. */
  90. this.defaultGamma = 1.0;
  91. this._tilingScheme = new WebMercatorTilingScheme({
  92. numberOfLevelZeroTilesX : 2,
  93. numberOfLevelZeroTilesY : 2,
  94. ellipsoid : options.ellipsoid
  95. });
  96. this._tileWidth = undefined;
  97. this._tileHeight = undefined;
  98. this._maximumLevel = undefined;
  99. this._imageUrlTemplate = undefined;
  100. this._imageUrlSubdomains = undefined;
  101. this._errorEvent = new Event();
  102. this._ready = false;
  103. this._readyPromise = when.defer();
  104. var tileProtocol = this._tileProtocol;
  105. // For backward compatibility reasons, the tileProtocol may end with
  106. // a `:`. Remove it.
  107. if (defined(tileProtocol)) {
  108. if (tileProtocol.length > 0 && tileProtocol[tileProtocol.length - 1] === ':') {
  109. tileProtocol = tileProtocol.substr(0, tileProtocol.length - 1);
  110. }
  111. } else {
  112. // use http if the document's protocol is http, otherwise use https
  113. var documentProtocol = document.location.protocol;
  114. tileProtocol = documentProtocol === 'http:' ? 'http' : 'https';
  115. }
  116. var metadataResource = this._resource.getDerivedResource({
  117. url:'REST/v1/Imagery/Metadata/' + this._mapStyle,
  118. queryParameters: {
  119. incl: 'ImageryProviders',
  120. key: this._key,
  121. uriScheme: tileProtocol
  122. }
  123. });
  124. var that = this;
  125. var metadataError;
  126. function metadataSuccess(data) {
  127. if (data.resourceSets.length !== 1) {
  128. metadataFailure();
  129. return;
  130. }
  131. var resource = data.resourceSets[0].resources[0];
  132. that._tileWidth = resource.imageWidth;
  133. that._tileHeight = resource.imageHeight;
  134. that._maximumLevel = resource.zoomMax - 1;
  135. that._imageUrlSubdomains = resource.imageUrlSubdomains;
  136. that._imageUrlTemplate = resource.imageUrl;
  137. var attributionList = that._attributionList = resource.imageryProviders;
  138. if (!attributionList) {
  139. attributionList = that._attributionList = [];
  140. }
  141. for (var attributionIndex = 0, attributionLength = attributionList.length; attributionIndex < attributionLength; ++attributionIndex) {
  142. var attribution = attributionList[attributionIndex];
  143. if (attribution.credit instanceof Credit) {
  144. // If attribution.credit has already been created
  145. // then we are using a cached value, which means
  146. // none of the remaining processing needs to be done.
  147. break;
  148. }
  149. attribution.credit = new Credit(attribution.attribution);
  150. var coverageAreas = attribution.coverageAreas;
  151. for (var areaIndex = 0, areaLength = attribution.coverageAreas.length; areaIndex < areaLength; ++areaIndex) {
  152. var area = coverageAreas[areaIndex];
  153. var bbox = area.bbox;
  154. area.bbox = new Rectangle(
  155. CesiumMath.toRadians(bbox[1]),
  156. CesiumMath.toRadians(bbox[0]),
  157. CesiumMath.toRadians(bbox[3]),
  158. CesiumMath.toRadians(bbox[2]));
  159. }
  160. }
  161. that._ready = true;
  162. that._readyPromise.resolve(true);
  163. TileProviderError.handleSuccess(metadataError);
  164. }
  165. function metadataFailure(e) {
  166. var message = 'An error occurred while accessing ' + metadataResource.url + '.';
  167. metadataError = TileProviderError.handleError(metadataError, that, that._errorEvent, message, undefined, undefined, undefined, requestMetadata);
  168. that._readyPromise.reject(new RuntimeError(message));
  169. }
  170. var cacheKey = metadataResource.url;
  171. function requestMetadata() {
  172. var promise = metadataResource.fetchJsonp('jsonp');
  173. BingMapsImageryProvider._metadataCache[cacheKey] = promise;
  174. promise.then(metadataSuccess).otherwise(metadataFailure);
  175. }
  176. var promise = BingMapsImageryProvider._metadataCache[cacheKey];
  177. if (defined(promise)) {
  178. promise.then(metadataSuccess).otherwise(metadataFailure);
  179. } else {
  180. requestMetadata();
  181. }
  182. }
  183. defineProperties(BingMapsImageryProvider.prototype, {
  184. /**
  185. * Gets the name of the BingMaps server url hosting the imagery.
  186. * @memberof BingMapsImageryProvider.prototype
  187. * @type {String}
  188. * @readonly
  189. */
  190. url : {
  191. get : function() {
  192. return this._resource.url;
  193. }
  194. },
  195. /**
  196. * Gets the proxy used by this provider.
  197. * @memberof BingMapsImageryProvider.prototype
  198. * @type {Proxy}
  199. * @readonly
  200. */
  201. proxy : {
  202. get : function() {
  203. return this._resource.proxy;
  204. }
  205. },
  206. /**
  207. * Gets the Bing Maps key.
  208. * @memberof BingMapsImageryProvider.prototype
  209. * @type {String}
  210. * @readonly
  211. */
  212. key : {
  213. get : function() {
  214. return this._key;
  215. }
  216. },
  217. /**
  218. * Gets the type of Bing Maps imagery to load.
  219. * @memberof BingMapsImageryProvider.prototype
  220. * @type {BingMapsStyle}
  221. * @readonly
  222. */
  223. mapStyle : {
  224. get : function() {
  225. return this._mapStyle;
  226. }
  227. },
  228. /**
  229. * The culture to use when requesting Bing Maps imagery. Not
  230. * all cultures are supported. See {@link http://msdn.microsoft.com/en-us/library/hh441729.aspx}
  231. * for information on the supported cultures.
  232. * @memberof BingMapsImageryProvider.prototype
  233. * @type {String}
  234. * @readonly
  235. */
  236. culture : {
  237. get : function() {
  238. return this._culture;
  239. }
  240. },
  241. /**
  242. * Gets the width of each tile, in pixels. This function should
  243. * not be called before {@link BingMapsImageryProvider#ready} returns true.
  244. * @memberof BingMapsImageryProvider.prototype
  245. * @type {Number}
  246. * @readonly
  247. */
  248. tileWidth : {
  249. get : function() {
  250. //>>includeStart('debug', pragmas.debug);
  251. if (!this._ready) {
  252. throw new DeveloperError('tileWidth must not be called before the imagery provider is ready.');
  253. }
  254. //>>includeEnd('debug');
  255. return this._tileWidth;
  256. }
  257. },
  258. /**
  259. * Gets the height of each tile, in pixels. This function should
  260. * not be called before {@link BingMapsImageryProvider#ready} returns true.
  261. * @memberof BingMapsImageryProvider.prototype
  262. * @type {Number}
  263. * @readonly
  264. */
  265. tileHeight: {
  266. get : function() {
  267. //>>includeStart('debug', pragmas.debug);
  268. if (!this._ready) {
  269. throw new DeveloperError('tileHeight must not be called before the imagery provider is ready.');
  270. }
  271. //>>includeEnd('debug');
  272. return this._tileHeight;
  273. }
  274. },
  275. /**
  276. * Gets the maximum level-of-detail that can be requested. This function should
  277. * not be called before {@link BingMapsImageryProvider#ready} returns true.
  278. * @memberof BingMapsImageryProvider.prototype
  279. * @type {Number}
  280. * @readonly
  281. */
  282. maximumLevel : {
  283. get : function() {
  284. //>>includeStart('debug', pragmas.debug);
  285. if (!this._ready) {
  286. throw new DeveloperError('maximumLevel must not be called before the imagery provider is ready.');
  287. }
  288. //>>includeEnd('debug');
  289. return this._maximumLevel;
  290. }
  291. },
  292. /**
  293. * Gets the minimum level-of-detail that can be requested. This function should
  294. * not be called before {@link BingMapsImageryProvider#ready} returns true.
  295. * @memberof BingMapsImageryProvider.prototype
  296. * @type {Number}
  297. * @readonly
  298. */
  299. minimumLevel : {
  300. get : function() {
  301. //>>includeStart('debug', pragmas.debug);
  302. if (!this._ready) {
  303. throw new DeveloperError('minimumLevel must not be called before the imagery provider is ready.');
  304. }
  305. //>>includeEnd('debug');
  306. return 0;
  307. }
  308. },
  309. /**
  310. * Gets the tiling scheme used by this provider. This function should
  311. * not be called before {@link BingMapsImageryProvider#ready} returns true.
  312. * @memberof BingMapsImageryProvider.prototype
  313. * @type {TilingScheme}
  314. * @readonly
  315. */
  316. tilingScheme : {
  317. get : function() {
  318. //>>includeStart('debug', pragmas.debug);
  319. if (!this._ready) {
  320. throw new DeveloperError('tilingScheme must not be called before the imagery provider is ready.');
  321. }
  322. //>>includeEnd('debug');
  323. return this._tilingScheme;
  324. }
  325. },
  326. /**
  327. * Gets the rectangle, in radians, of the imagery provided by this instance. This function should
  328. * not be called before {@link BingMapsImageryProvider#ready} returns true.
  329. * @memberof BingMapsImageryProvider.prototype
  330. * @type {Rectangle}
  331. * @readonly
  332. */
  333. rectangle : {
  334. get : function() {
  335. //>>includeStart('debug', pragmas.debug);
  336. if (!this._ready) {
  337. throw new DeveloperError('rectangle must not be called before the imagery provider is ready.');
  338. }
  339. //>>includeEnd('debug');
  340. return this._tilingScheme.rectangle;
  341. }
  342. },
  343. /**
  344. * Gets the tile discard policy. If not undefined, the discard policy is responsible
  345. * for filtering out "missing" tiles via its shouldDiscardImage function. If this function
  346. * returns undefined, no tiles are filtered. This function should
  347. * not be called before {@link BingMapsImageryProvider#ready} returns true.
  348. * @memberof BingMapsImageryProvider.prototype
  349. * @type {TileDiscardPolicy}
  350. * @readonly
  351. */
  352. tileDiscardPolicy : {
  353. get : function() {
  354. //>>includeStart('debug', pragmas.debug);
  355. if (!this._ready) {
  356. throw new DeveloperError('tileDiscardPolicy must not be called before the imagery provider is ready.');
  357. }
  358. //>>includeEnd('debug');
  359. return this._tileDiscardPolicy;
  360. }
  361. },
  362. /**
  363. * Gets an event that is raised when the imagery provider encounters an asynchronous error. By subscribing
  364. * to the event, you will be notified of the error and can potentially recover from it. Event listeners
  365. * are passed an instance of {@link TileProviderError}.
  366. * @memberof BingMapsImageryProvider.prototype
  367. * @type {Event}
  368. * @readonly
  369. */
  370. errorEvent : {
  371. get : function() {
  372. return this._errorEvent;
  373. }
  374. },
  375. /**
  376. * Gets a value indicating whether or not the provider is ready for use.
  377. * @memberof BingMapsImageryProvider.prototype
  378. * @type {Boolean}
  379. * @readonly
  380. */
  381. ready : {
  382. get : function() {
  383. return this._ready;
  384. }
  385. },
  386. /**
  387. * Gets a promise that resolves to true when the provider is ready for use.
  388. * @memberof BingMapsImageryProvider.prototype
  389. * @type {Promise.<Boolean>}
  390. * @readonly
  391. */
  392. readyPromise : {
  393. get : function() {
  394. return this._readyPromise.promise;
  395. }
  396. },
  397. /**
  398. * Gets the credit to display when this imagery provider is active. Typically this is used to credit
  399. * the source of the imagery. This function should not be called before {@link BingMapsImageryProvider#ready} returns true.
  400. * @memberof BingMapsImageryProvider.prototype
  401. * @type {Credit}
  402. * @readonly
  403. */
  404. credit : {
  405. get : function() {
  406. return this._credit;
  407. }
  408. },
  409. /**
  410. * Gets a value indicating whether or not the images provided by this imagery provider
  411. * include an alpha channel. If this property is false, an alpha channel, if present, will
  412. * be ignored. If this property is true, any images without an alpha channel will be treated
  413. * as if their alpha is 1.0 everywhere. Setting this property to false reduces memory usage
  414. * and texture upload time.
  415. * @memberof BingMapsImageryProvider.prototype
  416. * @type {Boolean}
  417. * @readonly
  418. */
  419. hasAlphaChannel : {
  420. get : function() {
  421. return false;
  422. }
  423. }
  424. });
  425. var rectangleScratch = new Rectangle();
  426. /**
  427. * Gets the credits to be displayed when a given tile is displayed.
  428. *
  429. * @param {Number} x The tile X coordinate.
  430. * @param {Number} y The tile Y coordinate.
  431. * @param {Number} level The tile level;
  432. * @returns {Credit[]} The credits to be displayed when the tile is displayed.
  433. *
  434. * @exception {DeveloperError} <code>getTileCredits</code> must not be called before the imagery provider is ready.
  435. */
  436. BingMapsImageryProvider.prototype.getTileCredits = function(x, y, level) {
  437. //>>includeStart('debug', pragmas.debug);
  438. if (!this._ready) {
  439. throw new DeveloperError('getTileCredits must not be called before the imagery provider is ready.');
  440. }
  441. //>>includeEnd('debug');
  442. var rectangle = this._tilingScheme.tileXYToRectangle(x, y, level, rectangleScratch);
  443. var result = getRectangleAttribution(this._attributionList, level, rectangle);
  444. return result;
  445. };
  446. /**
  447. * Requests the image for a given tile. This function should
  448. * not be called before {@link BingMapsImageryProvider#ready} returns true.
  449. *
  450. * @param {Number} x The tile X coordinate.
  451. * @param {Number} y The tile Y coordinate.
  452. * @param {Number} level The tile level.
  453. * @param {Request} [request] The request object. Intended for internal use only.
  454. * @returns {Promise.<Image|Canvas>|undefined} A promise for the image that will resolve when the image is available, or
  455. * undefined if there are too many active requests to the server, and the request
  456. * should be retried later. The resolved image may be either an
  457. * Image or a Canvas DOM object.
  458. *
  459. * @exception {DeveloperError} <code>requestImage</code> must not be called before the imagery provider is ready.
  460. */
  461. BingMapsImageryProvider.prototype.requestImage = function(x, y, level, request) {
  462. //>>includeStart('debug', pragmas.debug);
  463. if (!this._ready) {
  464. throw new DeveloperError('requestImage must not be called before the imagery provider is ready.');
  465. }
  466. //>>includeEnd('debug');
  467. var promise = ImageryProvider.loadImage(this, buildImageResource(this, x, y, level, request));
  468. if (defined(promise)) {
  469. return promise.otherwise(function(error) {
  470. // One cause of an error here is that the image we tried to load was zero-length.
  471. // This isn't actually a problem, since it indicates that there is no tile.
  472. // So, in that case we return the EMPTY_IMAGE sentinel value for later discarding.
  473. if (defined(error.blob) && error.blob.size === 0) {
  474. return DiscardEmptyTilePolicy.EMPTY_IMAGE;
  475. }
  476. return when.reject(error);
  477. });
  478. }
  479. return undefined;
  480. };
  481. /**
  482. * Picking features is not currently supported by this imagery provider, so this function simply returns
  483. * undefined.
  484. *
  485. * @param {Number} x The tile X coordinate.
  486. * @param {Number} y The tile Y coordinate.
  487. * @param {Number} level The tile level.
  488. * @param {Number} longitude The longitude at which to pick features.
  489. * @param {Number} latitude The latitude at which to pick features.
  490. * @return {Promise.<ImageryLayerFeatureInfo[]>|undefined} A promise for the picked features that will resolve when the asynchronous
  491. * picking completes. The resolved value is an array of {@link ImageryLayerFeatureInfo}
  492. * instances. The array may be empty if no features are found at the given location.
  493. * It may also be undefined if picking is not supported.
  494. */
  495. BingMapsImageryProvider.prototype.pickFeatures = function(x, y, level, longitude, latitude) {
  496. return undefined;
  497. };
  498. /**
  499. * Converts a tiles (x, y, level) position into a quadkey used to request an image
  500. * from a Bing Maps server.
  501. *
  502. * @param {Number} x The tile's x coordinate.
  503. * @param {Number} y The tile's y coordinate.
  504. * @param {Number} level The tile's zoom level.
  505. *
  506. * @see {@link http://msdn.microsoft.com/en-us/library/bb259689.aspx|Bing Maps Tile System}
  507. * @see BingMapsImageryProvider#quadKeyToTileXY
  508. */
  509. BingMapsImageryProvider.tileXYToQuadKey = function(x, y, level) {
  510. var quadkey = '';
  511. for ( var i = level; i >= 0; --i) {
  512. var bitmask = 1 << i;
  513. var digit = 0;
  514. if ((x & bitmask) !== 0) {
  515. digit |= 1;
  516. }
  517. if ((y & bitmask) !== 0) {
  518. digit |= 2;
  519. }
  520. quadkey += digit;
  521. }
  522. return quadkey;
  523. };
  524. /**
  525. * Converts a tile's quadkey used to request an image from a Bing Maps server into the
  526. * (x, y, level) position.
  527. *
  528. * @param {String} quadkey The tile's quad key
  529. *
  530. * @see {@link http://msdn.microsoft.com/en-us/library/bb259689.aspx|Bing Maps Tile System}
  531. * @see BingMapsImageryProvider#tileXYToQuadKey
  532. */
  533. BingMapsImageryProvider.quadKeyToTileXY = function(quadkey) {
  534. var x = 0;
  535. var y = 0;
  536. var level = quadkey.length - 1;
  537. for ( var i = level; i >= 0; --i) {
  538. var bitmask = 1 << i;
  539. var digit = +quadkey[level - i];
  540. if ((digit & 1) !== 0) {
  541. x |= bitmask;
  542. }
  543. if ((digit & 2) !== 0) {
  544. y |= bitmask;
  545. }
  546. }
  547. return {
  548. x : x,
  549. y : y,
  550. level : level
  551. };
  552. };
  553. BingMapsImageryProvider._logoUrl = undefined;
  554. defineProperties(BingMapsImageryProvider, {
  555. /**
  556. * Gets or sets the URL to the Bing logo for display in the credit.
  557. * @memberof BingMapsImageryProvider
  558. * @type {String}
  559. */
  560. logoUrl: {
  561. get: function() {
  562. if (!defined(BingMapsImageryProvider._logoUrl)) {
  563. BingMapsImageryProvider._logoUrl = buildModuleUrl('Assets/Images/bing_maps_credit.png');
  564. }
  565. return BingMapsImageryProvider._logoUrl;
  566. },
  567. set: function(value) {
  568. //>>includeStart('debug', pragmas.debug);
  569. Check.defined('value', value);
  570. //>>includeEnd('debug');
  571. BingMapsImageryProvider._logoUrl = value;
  572. }
  573. }
  574. });
  575. function buildImageResource(imageryProvider, x, y, level, request) {
  576. var imageUrl = imageryProvider._imageUrlTemplate;
  577. var subdomains = imageryProvider._imageUrlSubdomains;
  578. var subdomainIndex = (x + y + level) % subdomains.length;
  579. return imageryProvider._resource.getDerivedResource({
  580. url: imageUrl,
  581. request: request,
  582. templateValues: {
  583. quadkey: BingMapsImageryProvider.tileXYToQuadKey(x, y, level),
  584. subdomain: subdomains[subdomainIndex],
  585. culture: imageryProvider._culture
  586. },
  587. queryParameters: {
  588. // this parameter tells the Bing servers to send a zero-length response
  589. // instead of a placeholder image for missing tiles.
  590. n: 'z'
  591. }
  592. });
  593. }
  594. var intersectionScratch = new Rectangle();
  595. function getRectangleAttribution(attributionList, level, rectangle) {
  596. // Bing levels start at 1, while ours start at 0.
  597. ++level;
  598. var result = [];
  599. for (var attributionIndex = 0, attributionLength = attributionList.length; attributionIndex < attributionLength; ++attributionIndex) {
  600. var attribution = attributionList[attributionIndex];
  601. var coverageAreas = attribution.coverageAreas;
  602. var included = false;
  603. for (var areaIndex = 0, areaLength = attribution.coverageAreas.length; !included && areaIndex < areaLength; ++areaIndex) {
  604. var area = coverageAreas[areaIndex];
  605. if (level >= area.zoomMin && level <= area.zoomMax) {
  606. var intersection = Rectangle.intersection(rectangle, area.bbox, intersectionScratch);
  607. if (defined(intersection)) {
  608. included = true;
  609. }
  610. }
  611. }
  612. if (included) {
  613. result.push(attribution.credit);
  614. }
  615. }
  616. return result;
  617. }
  618. // Exposed for testing
  619. BingMapsImageryProvider._metadataCache = {};
  620. export default BingMapsImageryProvider;