WebMapServiceImageryProvider.js 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705
  1. import defaultValue from "../Core/defaultValue.js";
  2. import defined from "../Core/defined.js";
  3. import DeveloperError from "../Core/DeveloperError.js";
  4. import GeographicTilingScheme from "../Core/GeographicTilingScheme.js";
  5. import Resource from "../Core/Resource.js";
  6. import WebMercatorProjection from "../Core/WebMercatorProjection.js";
  7. import GetFeatureInfoFormat from "./GetFeatureInfoFormat.js";
  8. import TimeDynamicImagery from "./TimeDynamicImagery.js";
  9. import UrlTemplateImageryProvider from "./UrlTemplateImageryProvider.js";
  10. /**
  11. * @typedef {Object} WebMapServiceImageryProvider.ConstructorOptions
  12. *
  13. * Initialization options for the WebMapServiceImageryProvider constructor
  14. *
  15. * @property {Resource|String} url The URL of the WMS service. The URL supports the same keywords as the {@link UrlTemplateImageryProvider}.
  16. * @property {String} layers The layers to include, separated by commas.
  17. * @property {Object} [parameters=WebMapServiceImageryProvider.DefaultParameters] Additional parameters to pass to the WMS server in the GetMap URL.
  18. * @property {Object} [getFeatureInfoParameters=WebMapServiceImageryProvider.GetFeatureInfoDefaultParameters] Additional parameters to pass to the WMS server in the GetFeatureInfo URL.
  19. * @property {Boolean} [enablePickFeatures=true] If true, {@link WebMapServiceImageryProvider#pickFeatures} will invoke
  20. * the GetFeatureInfo operation on the WMS server and return the features included in the response. If false,
  21. * {@link WebMapServiceImageryProvider#pickFeatures} will immediately return undefined (indicating no pickable features)
  22. * without communicating with the server. Set this property to false if you know your WMS server does not support
  23. * GetFeatureInfo or if you don't want this provider's features to be pickable. Note that this can be dynamically
  24. * overridden by modifying the WebMapServiceImageryProvider#enablePickFeatures property.
  25. * @property {GetFeatureInfoFormat[]} [getFeatureInfoFormats=WebMapServiceImageryProvider.DefaultGetFeatureInfoFormats] The formats
  26. * in which to try WMS GetFeatureInfo requests.
  27. * @property {Rectangle} [rectangle=Rectangle.MAX_VALUE] The rectangle of the layer.
  28. * @property {TilingScheme} [tilingScheme=new GeographicTilingScheme()] The tiling scheme to use to divide the world into tiles.
  29. * @property {Ellipsoid} [ellipsoid] The ellipsoid. If the tilingScheme is specified,
  30. * this parameter is ignored and the tiling scheme's ellipsoid is used instead. If neither
  31. * parameter is specified, the WGS84 ellipsoid is used.
  32. * @property {Number} [tileWidth=256] The width of each tile in pixels.
  33. * @property {Number} [tileHeight=256] The height of each tile in pixels.
  34. * @property {Number} [minimumLevel=0] The minimum level-of-detail supported by the imagery provider. Take care when
  35. * specifying this that the number of tiles at the minimum level is small, such as four or less. A larger number is
  36. * likely to result in rendering problems.
  37. * @property {Number} [maximumLevel] The maximum level-of-detail supported by the imagery provider, or undefined if there is no limit.
  38. * If not specified, there is no limit.
  39. * @property {String} [crs] CRS specification, for use with WMS specification >= 1.3.0.
  40. * @property {String} [srs] SRS specification, for use with WMS specification 1.1.0 or 1.1.1
  41. * @property {Credit|String} [credit] A credit for the data source, which is displayed on the canvas.
  42. * @property {String|String[]} [subdomains='abc'] The subdomains to use for the <code>{s}</code> placeholder in the URL template.
  43. * If this parameter is a single string, each character in the string is a subdomain. If it is
  44. * an array, each element in the array is a subdomain.
  45. * @property {Clock} [clock] A Clock instance that is used when determining the value for the time dimension. Required when `times` is specified.
  46. * @property {TimeIntervalCollection} [times] TimeIntervalCollection with its data property being an object containing time dynamic dimension and their values.
  47. */
  48. /**
  49. * Provides tiled imagery hosted by a Web Map Service (WMS) server.
  50. *
  51. * @alias WebMapServiceImageryProvider
  52. * @constructor
  53. *
  54. * @param {WebMapServiceImageryProvider.ConstructorOptions} options Object describing initialization options
  55. *
  56. * @see ArcGisMapServerImageryProvider
  57. * @see BingMapsImageryProvider
  58. * @see GoogleEarthEnterpriseMapsProvider
  59. * @see OpenStreetMapImageryProvider
  60. * @see SingleTileImageryProvider
  61. * @see TileMapServiceImageryProvider
  62. * @see WebMapTileServiceImageryProvider
  63. * @see UrlTemplateImageryProvider
  64. *
  65. * @see {@link http://resources.esri.com/help/9.3/arcgisserver/apis/rest/|ArcGIS Server REST API}
  66. * @see {@link http://www.w3.org/TR/cors/|Cross-Origin Resource Sharing}
  67. *
  68. * @example
  69. * var provider = new Cesium.WebMapServiceImageryProvider({
  70. * url : 'https://sampleserver1.arcgisonline.com/ArcGIS/services/Specialty/ESRI_StatesCitiesRivers_USA/MapServer/WMSServer',
  71. * layers : '0',
  72. * proxy: new Cesium.DefaultProxy('/proxy/')
  73. * });
  74. *
  75. * viewer.imageryLayers.addImageryProvider(provider);
  76. */
  77. function WebMapServiceImageryProvider(options) {
  78. options = defaultValue(options, defaultValue.EMPTY_OBJECT);
  79. //>>includeStart('debug', pragmas.debug);
  80. if (!defined(options.url)) {
  81. throw new DeveloperError("options.url is required.");
  82. }
  83. if (!defined(options.layers)) {
  84. throw new DeveloperError("options.layers is required.");
  85. }
  86. //>>includeEnd('debug');
  87. if (defined(options.times) && !defined(options.clock)) {
  88. throw new DeveloperError(
  89. "options.times was specified, so options.clock is required."
  90. );
  91. }
  92. /**
  93. * The default alpha blending value of this provider, with 0.0 representing fully transparent and
  94. * 1.0 representing fully opaque.
  95. *
  96. * @type {Number|undefined}
  97. * @default undefined
  98. */
  99. this.defaultAlpha = undefined;
  100. /**
  101. * The default alpha blending value on the night side of the globe of this provider, with 0.0 representing fully transparent and
  102. * 1.0 representing fully opaque.
  103. *
  104. * @type {Number|undefined}
  105. * @default undefined
  106. */
  107. this.defaultNightAlpha = undefined;
  108. /**
  109. * The default alpha blending value on the day side of the globe of this provider, with 0.0 representing fully transparent and
  110. * 1.0 representing fully opaque.
  111. *
  112. * @type {Number|undefined}
  113. * @default undefined
  114. */
  115. this.defaultDayAlpha = undefined;
  116. /**
  117. * The default brightness of this provider. 1.0 uses the unmodified imagery color. Less than 1.0
  118. * makes the imagery darker while greater than 1.0 makes it brighter.
  119. *
  120. * @type {Number|undefined}
  121. * @default undefined
  122. */
  123. this.defaultBrightness = undefined;
  124. /**
  125. * The default contrast of this provider. 1.0 uses the unmodified imagery color. Less than 1.0 reduces
  126. * the contrast while greater than 1.0 increases it.
  127. *
  128. * @type {Number|undefined}
  129. * @default undefined
  130. */
  131. this.defaultContrast = undefined;
  132. /**
  133. * The default hue of this provider in radians. 0.0 uses the unmodified imagery color.
  134. *
  135. * @type {Number|undefined}
  136. * @default undefined
  137. */
  138. this.defaultHue = undefined;
  139. /**
  140. * The default saturation of this provider. 1.0 uses the unmodified imagery color. Less than 1.0 reduces the
  141. * saturation while greater than 1.0 increases it.
  142. *
  143. * @type {Number|undefined}
  144. * @default undefined
  145. */
  146. this.defaultSaturation = undefined;
  147. /**
  148. * The default gamma correction to apply to this provider. 1.0 uses the unmodified imagery color.
  149. *
  150. * @type {Number|undefined}
  151. * @default undefined
  152. */
  153. this.defaultGamma = undefined;
  154. /**
  155. * The default texture minification filter to apply to this provider.
  156. *
  157. * @type {TextureMinificationFilter}
  158. * @default undefined
  159. */
  160. this.defaultMinificationFilter = undefined;
  161. /**
  162. * The default texture magnification filter to apply to this provider.
  163. *
  164. * @type {TextureMagnificationFilter}
  165. * @default undefined
  166. */
  167. this.defaultMagnificationFilter = undefined;
  168. var resource = Resource.createIfNeeded(options.url);
  169. var pickFeatureResource = resource.clone();
  170. resource.setQueryParameters(
  171. WebMapServiceImageryProvider.DefaultParameters,
  172. true
  173. );
  174. pickFeatureResource.setQueryParameters(
  175. WebMapServiceImageryProvider.GetFeatureInfoDefaultParameters,
  176. true
  177. );
  178. if (defined(options.parameters)) {
  179. resource.setQueryParameters(objectToLowercase(options.parameters));
  180. }
  181. if (defined(options.getFeatureInfoParameters)) {
  182. pickFeatureResource.setQueryParameters(
  183. objectToLowercase(options.getFeatureInfoParameters)
  184. );
  185. }
  186. var that = this;
  187. this._reload = undefined;
  188. if (defined(options.times)) {
  189. this._timeDynamicImagery = new TimeDynamicImagery({
  190. clock: options.clock,
  191. times: options.times,
  192. requestImageFunction: function (x, y, level, request, interval) {
  193. return requestImage(that, x, y, level, request, interval);
  194. },
  195. reloadFunction: function () {
  196. if (defined(that._reload)) {
  197. that._reload();
  198. }
  199. },
  200. });
  201. }
  202. var parameters = {};
  203. parameters.layers = options.layers;
  204. parameters.bbox =
  205. "{westProjected},{southProjected},{eastProjected},{northProjected}";
  206. parameters.width = "{width}";
  207. parameters.height = "{height}";
  208. // Use SRS or CRS based on the WMS version.
  209. if (parseFloat(resource.queryParameters.version) >= 1.3) {
  210. // Use CRS with 1.3.0 and going forward.
  211. // For GeographicTilingScheme, use CRS:84 vice EPSG:4326 to specify lon, lat (x, y) ordering for
  212. // bbox requests.
  213. parameters.crs = defaultValue(
  214. options.crs,
  215. options.tilingScheme &&
  216. options.tilingScheme.projection instanceof WebMercatorProjection
  217. ? "EPSG:3857"
  218. : "CRS:84"
  219. );
  220. } else {
  221. // SRS for WMS 1.1.0 or 1.1.1.
  222. parameters.srs = defaultValue(
  223. options.srs,
  224. options.tilingScheme &&
  225. options.tilingScheme.projection instanceof WebMercatorProjection
  226. ? "EPSG:3857"
  227. : "EPSG:4326"
  228. );
  229. }
  230. resource.setQueryParameters(parameters, true);
  231. pickFeatureResource.setQueryParameters(parameters, true);
  232. var pickFeatureParams = {
  233. query_layers: options.layers,
  234. x: "{i}",
  235. y: "{j}",
  236. info_format: "{format}",
  237. };
  238. pickFeatureResource.setQueryParameters(pickFeatureParams, true);
  239. this._resource = resource;
  240. this._pickFeaturesResource = pickFeatureResource;
  241. this._layers = options.layers;
  242. // Let UrlTemplateImageryProvider do the actual URL building.
  243. this._tileProvider = new UrlTemplateImageryProvider({
  244. url: resource,
  245. pickFeaturesUrl: pickFeatureResource,
  246. tilingScheme: defaultValue(
  247. options.tilingScheme,
  248. new GeographicTilingScheme({ ellipsoid: options.ellipsoid })
  249. ),
  250. rectangle: options.rectangle,
  251. tileWidth: options.tileWidth,
  252. tileHeight: options.tileHeight,
  253. minimumLevel: options.minimumLevel,
  254. maximumLevel: options.maximumLevel,
  255. subdomains: options.subdomains,
  256. tileDiscardPolicy: options.tileDiscardPolicy,
  257. credit: options.credit,
  258. getFeatureInfoFormats: defaultValue(
  259. options.getFeatureInfoFormats,
  260. WebMapServiceImageryProvider.DefaultGetFeatureInfoFormats
  261. ),
  262. enablePickFeatures: options.enablePickFeatures,
  263. });
  264. }
  265. function requestImage(imageryProvider, col, row, level, request, interval) {
  266. var dynamicIntervalData = defined(interval) ? interval.data : undefined;
  267. var tileProvider = imageryProvider._tileProvider;
  268. if (defined(dynamicIntervalData)) {
  269. // We set the query parameters within the tile provider, because it is managing the query.
  270. tileProvider._resource.setQueryParameters(dynamicIntervalData);
  271. }
  272. return tileProvider.requestImage(col, row, level, request);
  273. }
  274. function pickFeatures(
  275. imageryProvider,
  276. x,
  277. y,
  278. level,
  279. longitude,
  280. latitude,
  281. interval
  282. ) {
  283. var dynamicIntervalData = defined(interval) ? interval.data : undefined;
  284. var tileProvider = imageryProvider._tileProvider;
  285. if (defined(dynamicIntervalData)) {
  286. // We set the query parameters within the tile provider, because it is managing the query.
  287. tileProvider._pickFeaturesResource.setQueryParameters(dynamicIntervalData);
  288. }
  289. return tileProvider.pickFeatures(x, y, level, longitude, latitude);
  290. }
  291. Object.defineProperties(WebMapServiceImageryProvider.prototype, {
  292. /**
  293. * Gets the URL of the WMS server.
  294. * @memberof WebMapServiceImageryProvider.prototype
  295. * @type {String}
  296. * @readonly
  297. */
  298. url: {
  299. get: function () {
  300. return this._resource._url;
  301. },
  302. },
  303. /**
  304. * Gets the proxy used by this provider.
  305. * @memberof WebMapServiceImageryProvider.prototype
  306. * @type {Proxy}
  307. * @readonly
  308. */
  309. proxy: {
  310. get: function () {
  311. return this._resource.proxy;
  312. },
  313. },
  314. /**
  315. * Gets the names of the WMS layers, separated by commas.
  316. * @memberof WebMapServiceImageryProvider.prototype
  317. * @type {String}
  318. * @readonly
  319. */
  320. layers: {
  321. get: function () {
  322. return this._layers;
  323. },
  324. },
  325. /**
  326. * Gets the width of each tile, in pixels. This function should
  327. * not be called before {@link WebMapServiceImageryProvider#ready} returns true.
  328. * @memberof WebMapServiceImageryProvider.prototype
  329. * @type {Number}
  330. * @readonly
  331. */
  332. tileWidth: {
  333. get: function () {
  334. return this._tileProvider.tileWidth;
  335. },
  336. },
  337. /**
  338. * Gets the height of each tile, in pixels. This function should
  339. * not be called before {@link WebMapServiceImageryProvider#ready} returns true.
  340. * @memberof WebMapServiceImageryProvider.prototype
  341. * @type {Number}
  342. * @readonly
  343. */
  344. tileHeight: {
  345. get: function () {
  346. return this._tileProvider.tileHeight;
  347. },
  348. },
  349. /**
  350. * Gets the maximum level-of-detail that can be requested. This function should
  351. * not be called before {@link WebMapServiceImageryProvider#ready} returns true.
  352. * @memberof WebMapServiceImageryProvider.prototype
  353. * @type {Number|undefined}
  354. * @readonly
  355. */
  356. maximumLevel: {
  357. get: function () {
  358. return this._tileProvider.maximumLevel;
  359. },
  360. },
  361. /**
  362. * Gets the minimum level-of-detail that can be requested. This function should
  363. * not be called before {@link WebMapServiceImageryProvider#ready} returns true.
  364. * @memberof WebMapServiceImageryProvider.prototype
  365. * @type {Number}
  366. * @readonly
  367. */
  368. minimumLevel: {
  369. get: function () {
  370. return this._tileProvider.minimumLevel;
  371. },
  372. },
  373. /**
  374. * Gets the tiling scheme used by this provider. This function should
  375. * not be called before {@link WebMapServiceImageryProvider#ready} returns true.
  376. * @memberof WebMapServiceImageryProvider.prototype
  377. * @type {TilingScheme}
  378. * @readonly
  379. */
  380. tilingScheme: {
  381. get: function () {
  382. return this._tileProvider.tilingScheme;
  383. },
  384. },
  385. /**
  386. * Gets the rectangle, in radians, of the imagery provided by this instance. This function should
  387. * not be called before {@link WebMapServiceImageryProvider#ready} returns true.
  388. * @memberof WebMapServiceImageryProvider.prototype
  389. * @type {Rectangle}
  390. * @readonly
  391. */
  392. rectangle: {
  393. get: function () {
  394. return this._tileProvider.rectangle;
  395. },
  396. },
  397. /**
  398. * Gets the tile discard policy. If not undefined, the discard policy is responsible
  399. * for filtering out "missing" tiles via its shouldDiscardImage function. If this function
  400. * returns undefined, no tiles are filtered. This function should
  401. * not be called before {@link WebMapServiceImageryProvider#ready} returns true.
  402. * @memberof WebMapServiceImageryProvider.prototype
  403. * @type {TileDiscardPolicy}
  404. * @readonly
  405. */
  406. tileDiscardPolicy: {
  407. get: function () {
  408. return this._tileProvider.tileDiscardPolicy;
  409. },
  410. },
  411. /**
  412. * Gets an event that is raised when the imagery provider encounters an asynchronous error. By subscribing
  413. * to the event, you will be notified of the error and can potentially recover from it. Event listeners
  414. * are passed an instance of {@link TileProviderError}.
  415. * @memberof WebMapServiceImageryProvider.prototype
  416. * @type {Event}
  417. * @readonly
  418. */
  419. errorEvent: {
  420. get: function () {
  421. return this._tileProvider.errorEvent;
  422. },
  423. },
  424. /**
  425. * Gets a value indicating whether or not the provider is ready for use.
  426. * @memberof WebMapServiceImageryProvider.prototype
  427. * @type {Boolean}
  428. * @readonly
  429. */
  430. ready: {
  431. get: function () {
  432. return this._tileProvider.ready;
  433. },
  434. },
  435. /**
  436. * Gets a promise that resolves to true when the provider is ready for use.
  437. * @memberof WebMapServiceImageryProvider.prototype
  438. * @type {Promise.<Boolean>}
  439. * @readonly
  440. */
  441. readyPromise: {
  442. get: function () {
  443. return this._tileProvider.readyPromise;
  444. },
  445. },
  446. /**
  447. * Gets the credit to display when this imagery provider is active. Typically this is used to credit
  448. * the source of the imagery. This function should not be called before {@link WebMapServiceImageryProvider#ready} returns true.
  449. * @memberof WebMapServiceImageryProvider.prototype
  450. * @type {Credit}
  451. * @readonly
  452. */
  453. credit: {
  454. get: function () {
  455. return this._tileProvider.credit;
  456. },
  457. },
  458. /**
  459. * Gets a value indicating whether or not the images provided by this imagery provider
  460. * include an alpha channel. If this property is false, an alpha channel, if present, will
  461. * be ignored. If this property is true, any images without an alpha channel will be treated
  462. * as if their alpha is 1.0 everywhere. When this property is false, memory usage
  463. * and texture upload time are reduced.
  464. * @memberof WebMapServiceImageryProvider.prototype
  465. * @type {Boolean}
  466. * @readonly
  467. */
  468. hasAlphaChannel: {
  469. get: function () {
  470. return this._tileProvider.hasAlphaChannel;
  471. },
  472. },
  473. /**
  474. * Gets or sets a value indicating whether feature picking is enabled. If true, {@link WebMapServiceImageryProvider#pickFeatures} will
  475. * invoke the <code>GetFeatureInfo</code> service on the WMS server and attempt to interpret the features included in the response. If false,
  476. * {@link WebMapServiceImageryProvider#pickFeatures} will immediately return undefined (indicating no pickable
  477. * features) without communicating with the server. Set this property to false if you know your data
  478. * source does not support picking features or if you don't want this provider's features to be pickable.
  479. * @memberof WebMapServiceImageryProvider.prototype
  480. * @type {Boolean}
  481. * @default true
  482. */
  483. enablePickFeatures: {
  484. get: function () {
  485. return this._tileProvider.enablePickFeatures;
  486. },
  487. set: function (enablePickFeatures) {
  488. this._tileProvider.enablePickFeatures = enablePickFeatures;
  489. },
  490. },
  491. /**
  492. * Gets or sets a clock that is used to get keep the time used for time dynamic parameters.
  493. * @memberof WebMapServiceImageryProvider.prototype
  494. * @type {Clock}
  495. */
  496. clock: {
  497. get: function () {
  498. return this._timeDynamicImagery.clock;
  499. },
  500. set: function (value) {
  501. this._timeDynamicImagery.clock = value;
  502. },
  503. },
  504. /**
  505. * Gets or sets a time interval collection that is used to get time dynamic parameters. The data of each
  506. * TimeInterval is an object containing the keys and values of the properties that are used during
  507. * tile requests.
  508. * @memberof WebMapServiceImageryProvider.prototype
  509. * @type {TimeIntervalCollection}
  510. */
  511. times: {
  512. get: function () {
  513. return this._timeDynamicImagery.times;
  514. },
  515. set: function (value) {
  516. this._timeDynamicImagery.times = value;
  517. },
  518. },
  519. });
  520. /**
  521. * Gets the credits to be displayed when a given tile is displayed.
  522. *
  523. * @param {Number} x The tile X coordinate.
  524. * @param {Number} y The tile Y coordinate.
  525. * @param {Number} level The tile level;
  526. * @returns {Credit[]} The credits to be displayed when the tile is displayed.
  527. *
  528. * @exception {DeveloperError} <code>getTileCredits</code> must not be called before the imagery provider is ready.
  529. */
  530. WebMapServiceImageryProvider.prototype.getTileCredits = function (x, y, level) {
  531. return this._tileProvider.getTileCredits(x, y, level);
  532. };
  533. /**
  534. * Requests the image for a given tile. This function should
  535. * not be called before {@link WebMapServiceImageryProvider#ready} returns true.
  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 {Request} [request] The request object. Intended for internal use only.
  541. * @returns {Promise.<HTMLImageElement|HTMLCanvasElement>|undefined} A promise for the image that will resolve when the image is available, or
  542. * undefined if there are too many active requests to the server, and the request
  543. * should be retried later. The resolved image may be either an
  544. * Image or a Canvas DOM object.
  545. *
  546. * @exception {DeveloperError} <code>requestImage</code> must not be called before the imagery provider is ready.
  547. */
  548. WebMapServiceImageryProvider.prototype.requestImage = function (
  549. x,
  550. y,
  551. level,
  552. request
  553. ) {
  554. var result;
  555. var timeDynamicImagery = this._timeDynamicImagery;
  556. var currentInterval;
  557. // Try and load from cache
  558. if (defined(timeDynamicImagery)) {
  559. currentInterval = timeDynamicImagery.currentInterval;
  560. result = timeDynamicImagery.getFromCache(x, y, level, request);
  561. }
  562. // Couldn't load from cache
  563. if (!defined(result)) {
  564. result = requestImage(this, x, y, level, request, currentInterval);
  565. }
  566. // If we are approaching an interval, preload this tile in the next interval
  567. if (defined(result) && defined(timeDynamicImagery)) {
  568. timeDynamicImagery.checkApproachingInterval(x, y, level, request);
  569. }
  570. return result;
  571. };
  572. /**
  573. * Asynchronously determines what features, if any, are located at a given longitude and latitude within
  574. * a tile. This function should not be called before {@link ImageryProvider#ready} returns true.
  575. *
  576. * @param {Number} x The tile X coordinate.
  577. * @param {Number} y The tile Y coordinate.
  578. * @param {Number} level The tile level.
  579. * @param {Number} longitude The longitude at which to pick features.
  580. * @param {Number} latitude The latitude at which to pick features.
  581. * @return {Promise.<ImageryLayerFeatureInfo[]>|undefined} A promise for the picked features that will resolve when the asynchronous
  582. * picking completes. The resolved value is an array of {@link ImageryLayerFeatureInfo}
  583. * instances. The array may be empty if no features are found at the given location.
  584. *
  585. * @exception {DeveloperError} <code>pickFeatures</code> must not be called before the imagery provider is ready.
  586. */
  587. WebMapServiceImageryProvider.prototype.pickFeatures = function (
  588. x,
  589. y,
  590. level,
  591. longitude,
  592. latitude
  593. ) {
  594. var timeDynamicImagery = this._timeDynamicImagery;
  595. var currentInterval = defined(timeDynamicImagery)
  596. ? timeDynamicImagery.currentInterval
  597. : undefined;
  598. return pickFeatures(this, x, y, level, longitude, latitude, currentInterval);
  599. };
  600. /**
  601. * The default parameters to include in the WMS URL to obtain images. The values are as follows:
  602. * service=WMS
  603. * version=1.1.1
  604. * request=GetMap
  605. * styles=
  606. * format=image/jpeg
  607. *
  608. * @constant
  609. * @type {Object}
  610. */
  611. WebMapServiceImageryProvider.DefaultParameters = Object.freeze({
  612. service: "WMS",
  613. version: "1.1.1",
  614. request: "GetMap",
  615. styles: "",
  616. format: "image/jpeg",
  617. });
  618. /**
  619. * The default parameters to include in the WMS URL to get feature information. The values are as follows:
  620. * service=WMS
  621. * version=1.1.1
  622. * request=GetFeatureInfo
  623. *
  624. * @constant
  625. * @type {Object}
  626. */
  627. WebMapServiceImageryProvider.GetFeatureInfoDefaultParameters = Object.freeze({
  628. service: "WMS",
  629. version: "1.1.1",
  630. request: "GetFeatureInfo",
  631. });
  632. WebMapServiceImageryProvider.DefaultGetFeatureInfoFormats = Object.freeze([
  633. Object.freeze(new GetFeatureInfoFormat("json", "application/json")),
  634. Object.freeze(new GetFeatureInfoFormat("xml", "text/xml")),
  635. Object.freeze(new GetFeatureInfoFormat("text", "text/html")),
  636. ]);
  637. function objectToLowercase(obj) {
  638. var result = {};
  639. for (var key in obj) {
  640. if (obj.hasOwnProperty(key)) {
  641. result[key.toLowerCase()] = obj[key];
  642. }
  643. }
  644. return result;
  645. }
  646. export default WebMapServiceImageryProvider;