智慧水务管理系统 - 精河县供水工程综合管理平台

BingMapsImageryProvider.js 22KB

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