ArcGisMapServerImageryProvider.js 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929
  1. import Cartesian2 from "../Core/Cartesian2.js";
  2. import Cartesian3 from "../Core/Cartesian3.js";
  3. import Cartographic from "../Core/Cartographic.js";
  4. import Credit from "../Core/Credit.js";
  5. import defaultValue from "../Core/defaultValue.js";
  6. import defined from "../Core/defined.js";
  7. import DeveloperError from "../Core/DeveloperError.js";
  8. import Event from "../Core/Event.js";
  9. import GeographicProjection from "../Core/GeographicProjection.js";
  10. import GeographicTilingScheme from "../Core/GeographicTilingScheme.js";
  11. import CesiumMath from "../Core/Math.js";
  12. import Rectangle from "../Core/Rectangle.js";
  13. import Resource from "../Core/Resource.js";
  14. import RuntimeError from "../Core/RuntimeError.js";
  15. import TileProviderError from "../Core/TileProviderError.js";
  16. import WebMercatorProjection from "../Core/WebMercatorProjection.js";
  17. import WebMercatorTilingScheme from "../Core/WebMercatorTilingScheme.js";
  18. import when from "../ThirdParty/when.js";
  19. import DiscardMissingTileImagePolicy from "./DiscardMissingTileImagePolicy.js";
  20. import ImageryLayerFeatureInfo from "./ImageryLayerFeatureInfo.js";
  21. import ImageryProvider from "./ImageryProvider.js";
  22. /**
  23. * @typedef {Object} ArcGisMapServerImageryProvider.ConstructorOptions
  24. *
  25. * Initialization options for the ArcGisMapServerImageryProvider constructor
  26. *
  27. * @property {Resource|String} url The URL of the ArcGIS MapServer service.
  28. * @property {String} [token] The ArcGIS token used to authenticate with the ArcGIS MapServer service.
  29. * @property {TileDiscardPolicy} [tileDiscardPolicy] The policy that determines if a tile
  30. * is invalid and should be discarded. If this value is not specified, a default
  31. * {@link DiscardMissingTileImagePolicy} is used for tiled map servers, and a
  32. * {@link NeverTileDiscardPolicy} is used for non-tiled map servers. In the former case,
  33. * we request tile 0,0 at the maximum tile level and check pixels (0,0), (200,20), (20,200),
  34. * (80,110), and (160, 130). If all of these pixels are transparent, the discard check is
  35. * disabled and no tiles are discarded. If any of them have a non-transparent color, any
  36. * tile that has the same values in these pixel locations is discarded. The end result of
  37. * these defaults should be correct tile discarding for a standard ArcGIS Server. To ensure
  38. * that no tiles are discarded, construct and pass a {@link NeverTileDiscardPolicy} for this
  39. * parameter.
  40. * @property {Boolean} [usePreCachedTilesIfAvailable=true] If true, the server's pre-cached
  41. * tiles are used if they are available. If false, any pre-cached tiles are ignored and the
  42. * 'export' service is used.
  43. * @property {String} [layers] A comma-separated list of the layers to show, or undefined if all layers should be shown.
  44. * @property {Boolean} [enablePickFeatures=true] If true, {@link ArcGisMapServerImageryProvider#pickFeatures} will invoke
  45. * the Identify service on the MapServer and return the features included in the response. If false,
  46. * {@link ArcGisMapServerImageryProvider#pickFeatures} will immediately return undefined (indicating no pickable features)
  47. * without communicating with the server. Set this property to false if you don't want this provider's features to
  48. * be pickable. Can be overridden by setting the {@link ArcGisMapServerImageryProvider#enablePickFeatures} property on the object.
  49. * @property {Rectangle} [rectangle=Rectangle.MAX_VALUE] The rectangle of the layer. This parameter is ignored when accessing
  50. * a tiled layer.
  51. * @property {TilingScheme} [tilingScheme=new GeographicTilingScheme()] The tiling scheme to use to divide the world into tiles.
  52. * This parameter is ignored when accessing a tiled server.
  53. * @property {Ellipsoid} [ellipsoid] The ellipsoid. If the tilingScheme is specified and used,
  54. * this parameter is ignored and the tiling scheme's ellipsoid is used instead. If neither
  55. * parameter is specified, the WGS84 ellipsoid is used.
  56. * @property {Credit|String} [credit] A credit for the data source, which is displayed on the canvas. This parameter is ignored when accessing a tiled server.
  57. * @property {Number} [tileWidth=256] The width of each tile in pixels. This parameter is ignored when accessing a tiled server.
  58. * @property {Number} [tileHeight=256] The height of each tile in pixels. This parameter is ignored when accessing a tiled server.
  59. * @property {Number} [maximumLevel] The maximum tile level to request, or undefined if there is no maximum. This parameter is ignored when accessing
  60. * a tiled server.
  61. */
  62. /**
  63. * Provides tiled imagery hosted by an ArcGIS MapServer. By default, the server's pre-cached tiles are
  64. * used, if available.
  65. *
  66. * @alias ArcGisMapServerImageryProvider
  67. * @constructor
  68. *
  69. * @param {ArcGisMapServerImageryProvider.ConstructorOptions} options Object describing initialization options
  70. *
  71. * @see BingMapsImageryProvider
  72. * @see GoogleEarthEnterpriseMapsProvider
  73. * @see OpenStreetMapImageryProvider
  74. * @see SingleTileImageryProvider
  75. * @see TileMapServiceImageryProvider
  76. * @see WebMapServiceImageryProvider
  77. * @see WebMapTileServiceImageryProvider
  78. * @see UrlTemplateImageryProvider
  79. *
  80. *
  81. * @example
  82. * var esri = new Cesium.ArcGisMapServerImageryProvider({
  83. * url : 'https://services.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer'
  84. * });
  85. *
  86. * @see {@link https://developers.arcgis.com/rest/|ArcGIS Server REST API}
  87. * @see {@link http://www.w3.org/TR/cors/|Cross-Origin Resource Sharing}
  88. */
  89. function ArcGisMapServerImageryProvider(options) {
  90. options = defaultValue(options, defaultValue.EMPTY_OBJECT);
  91. //>>includeStart('debug', pragmas.debug);
  92. if (!defined(options.url)) {
  93. throw new DeveloperError("options.url is required.");
  94. }
  95. //>>includeEnd('debug');
  96. /**
  97. * The default alpha blending value of this provider, with 0.0 representing fully transparent and
  98. * 1.0 representing fully opaque.
  99. *
  100. * @type {Number|undefined}
  101. * @default undefined
  102. */
  103. this.defaultAlpha = undefined;
  104. /**
  105. * The default alpha blending value on the night side of the globe of this provider, with 0.0 representing fully transparent and
  106. * 1.0 representing fully opaque.
  107. *
  108. * @type {Number|undefined}
  109. * @default undefined
  110. */
  111. this.defaultNightAlpha = undefined;
  112. /**
  113. * The default alpha blending value on the day side of the globe of this provider, with 0.0 representing fully transparent and
  114. * 1.0 representing fully opaque.
  115. *
  116. * @type {Number|undefined}
  117. * @default undefined
  118. */
  119. this.defaultDayAlpha = undefined;
  120. /**
  121. * The default brightness of this provider. 1.0 uses the unmodified imagery color. Less than 1.0
  122. * makes the imagery darker while greater than 1.0 makes it brighter.
  123. *
  124. * @type {Number|undefined}
  125. * @default undefined
  126. */
  127. this.defaultBrightness = undefined;
  128. /**
  129. * The default contrast of this provider. 1.0 uses the unmodified imagery color. Less than 1.0 reduces
  130. * the contrast while greater than 1.0 increases it.
  131. *
  132. * @type {Number|undefined}
  133. * @default undefined
  134. */
  135. this.defaultContrast = undefined;
  136. /**
  137. * The default hue of this provider in radians. 0.0 uses the unmodified imagery color.
  138. *
  139. * @type {Number|undefined}
  140. * @default undefined
  141. */
  142. this.defaultHue = undefined;
  143. /**
  144. * The default saturation of this provider. 1.0 uses the unmodified imagery color. Less than 1.0 reduces the
  145. * saturation while greater than 1.0 increases it.
  146. *
  147. * @type {Number|undefined}
  148. * @default undefined
  149. */
  150. this.defaultSaturation = undefined;
  151. /**
  152. * The default gamma correction to apply to this provider. 1.0 uses the unmodified imagery color.
  153. *
  154. * @type {Number|undefined}
  155. * @default undefined
  156. */
  157. this.defaultGamma = undefined;
  158. /**
  159. * The default texture minification filter to apply to this provider.
  160. *
  161. * @type {TextureMinificationFilter}
  162. * @default undefined
  163. */
  164. this.defaultMinificationFilter = undefined;
  165. /**
  166. * The default texture magnification filter to apply to this provider.
  167. *
  168. * @type {TextureMagnificationFilter}
  169. * @default undefined
  170. */
  171. this.defaultMagnificationFilter = undefined;
  172. var resource = Resource.createIfNeeded(options.url);
  173. resource.appendForwardSlash();
  174. if (defined(options.token)) {
  175. resource.setQueryParameters({
  176. token: options.token,
  177. });
  178. }
  179. this._resource = resource;
  180. this._tileDiscardPolicy = options.tileDiscardPolicy;
  181. this._tileWidth = defaultValue(options.tileWidth, 256);
  182. this._tileHeight = defaultValue(options.tileHeight, 256);
  183. this._maximumLevel = options.maximumLevel;
  184. this._tilingScheme = defaultValue(
  185. options.tilingScheme,
  186. new GeographicTilingScheme({ ellipsoid: options.ellipsoid })
  187. );
  188. this._useTiles = defaultValue(options.usePreCachedTilesIfAvailable, true);
  189. this._rectangle = defaultValue(
  190. options.rectangle,
  191. this._tilingScheme.rectangle
  192. );
  193. this._layers = options.layers;
  194. var credit = options.credit;
  195. if (typeof credit === "string") {
  196. credit = new Credit(credit);
  197. }
  198. this._credit = credit;
  199. /**
  200. * Gets or sets a value indicating whether feature picking is enabled. If true, {@link ArcGisMapServerImageryProvider#pickFeatures} will
  201. * invoke the "identify" operation on the ArcGIS server and return the features included in the response. If false,
  202. * {@link ArcGisMapServerImageryProvider#pickFeatures} will immediately return undefined (indicating no pickable features)
  203. * without communicating with the server.
  204. * @type {Boolean}
  205. * @default true
  206. */
  207. this.enablePickFeatures = defaultValue(options.enablePickFeatures, true);
  208. this._errorEvent = new Event();
  209. this._ready = false;
  210. this._readyPromise = when.defer();
  211. // Grab the details of this MapServer.
  212. var that = this;
  213. var metadataError;
  214. function metadataSuccess(data) {
  215. var tileInfo = data.tileInfo;
  216. if (!defined(tileInfo)) {
  217. that._useTiles = false;
  218. } else {
  219. that._tileWidth = tileInfo.rows;
  220. that._tileHeight = tileInfo.cols;
  221. if (
  222. tileInfo.spatialReference.wkid === 102100 ||
  223. tileInfo.spatialReference.wkid === 102113
  224. ) {
  225. that._tilingScheme = new WebMercatorTilingScheme({
  226. ellipsoid: options.ellipsoid,
  227. });
  228. } else if (data.tileInfo.spatialReference.wkid === 4326) {
  229. that._tilingScheme = new GeographicTilingScheme({
  230. ellipsoid: options.ellipsoid,
  231. });
  232. } else {
  233. var message =
  234. "Tile spatial reference WKID " +
  235. data.tileInfo.spatialReference.wkid +
  236. " is not supported.";
  237. metadataError = TileProviderError.handleError(
  238. metadataError,
  239. that,
  240. that._errorEvent,
  241. message,
  242. undefined,
  243. undefined,
  244. undefined,
  245. requestMetadata
  246. );
  247. return;
  248. }
  249. that._maximumLevel = data.tileInfo.lods.length - 1;
  250. if (defined(data.fullExtent)) {
  251. if (
  252. defined(data.fullExtent.spatialReference) &&
  253. defined(data.fullExtent.spatialReference.wkid)
  254. ) {
  255. if (
  256. data.fullExtent.spatialReference.wkid === 102100 ||
  257. data.fullExtent.spatialReference.wkid === 102113
  258. ) {
  259. var projection = new WebMercatorProjection();
  260. var extent = data.fullExtent;
  261. var sw = projection.unproject(
  262. new Cartesian3(
  263. Math.max(
  264. extent.xmin,
  265. -that._tilingScheme.ellipsoid.maximumRadius * Math.PI
  266. ),
  267. Math.max(
  268. extent.ymin,
  269. -that._tilingScheme.ellipsoid.maximumRadius * Math.PI
  270. ),
  271. 0.0
  272. )
  273. );
  274. var ne = projection.unproject(
  275. new Cartesian3(
  276. Math.min(
  277. extent.xmax,
  278. that._tilingScheme.ellipsoid.maximumRadius * Math.PI
  279. ),
  280. Math.min(
  281. extent.ymax,
  282. that._tilingScheme.ellipsoid.maximumRadius * Math.PI
  283. ),
  284. 0.0
  285. )
  286. );
  287. that._rectangle = new Rectangle(
  288. sw.longitude,
  289. sw.latitude,
  290. ne.longitude,
  291. ne.latitude
  292. );
  293. } else if (data.fullExtent.spatialReference.wkid === 4326) {
  294. that._rectangle = Rectangle.fromDegrees(
  295. data.fullExtent.xmin,
  296. data.fullExtent.ymin,
  297. data.fullExtent.xmax,
  298. data.fullExtent.ymax
  299. );
  300. } else {
  301. var extentMessage =
  302. "fullExtent.spatialReference WKID " +
  303. data.fullExtent.spatialReference.wkid +
  304. " is not supported.";
  305. metadataError = TileProviderError.handleError(
  306. metadataError,
  307. that,
  308. that._errorEvent,
  309. extentMessage,
  310. undefined,
  311. undefined,
  312. undefined,
  313. requestMetadata
  314. );
  315. return;
  316. }
  317. }
  318. } else {
  319. that._rectangle = that._tilingScheme.rectangle;
  320. }
  321. // Install the default tile discard policy if none has been supplied.
  322. if (!defined(that._tileDiscardPolicy)) {
  323. that._tileDiscardPolicy = new DiscardMissingTileImagePolicy({
  324. missingImageUrl: buildImageResource(that, 0, 0, that._maximumLevel)
  325. .url,
  326. pixelsToCheck: [
  327. new Cartesian2(0, 0),
  328. new Cartesian2(200, 20),
  329. new Cartesian2(20, 200),
  330. new Cartesian2(80, 110),
  331. new Cartesian2(160, 130),
  332. ],
  333. disableCheckIfAllPixelsAreTransparent: true,
  334. });
  335. }
  336. that._useTiles = true;
  337. }
  338. if (defined(data.copyrightText) && data.copyrightText.length > 0) {
  339. that._credit = new Credit(data.copyrightText);
  340. }
  341. that._ready = true;
  342. that._readyPromise.resolve(true);
  343. TileProviderError.handleSuccess(metadataError);
  344. }
  345. function metadataFailure(e) {
  346. var message =
  347. "An error occurred while accessing " + that._resource.url + ".";
  348. metadataError = TileProviderError.handleError(
  349. metadataError,
  350. that,
  351. that._errorEvent,
  352. message,
  353. undefined,
  354. undefined,
  355. undefined,
  356. requestMetadata
  357. );
  358. that._readyPromise.reject(new RuntimeError(message));
  359. }
  360. function requestMetadata() {
  361. var resource = that._resource.getDerivedResource({
  362. queryParameters: {
  363. f: "json",
  364. },
  365. });
  366. var metadata = resource.fetchJsonp();
  367. when(metadata, metadataSuccess, metadataFailure);
  368. }
  369. if (this._useTiles) {
  370. requestMetadata();
  371. } else {
  372. this._ready = true;
  373. this._readyPromise.resolve(true);
  374. }
  375. }
  376. function buildImageResource(imageryProvider, x, y, level, request) {
  377. var resource;
  378. if (imageryProvider._useTiles) {
  379. resource = imageryProvider._resource.getDerivedResource({
  380. url: "tile/" + level + "/" + y + "/" + x,
  381. request: request,
  382. });
  383. } else {
  384. var nativeRectangle = imageryProvider._tilingScheme.tileXYToNativeRectangle(
  385. x,
  386. y,
  387. level
  388. );
  389. var bbox =
  390. nativeRectangle.west +
  391. "," +
  392. nativeRectangle.south +
  393. "," +
  394. nativeRectangle.east +
  395. "," +
  396. nativeRectangle.north;
  397. var query = {
  398. bbox: bbox,
  399. size: imageryProvider._tileWidth + "," + imageryProvider._tileHeight,
  400. format: "png",
  401. transparent: true,
  402. f: "image",
  403. };
  404. if (
  405. imageryProvider._tilingScheme.projection instanceof GeographicProjection
  406. ) {
  407. query.bboxSR = 4326;
  408. query.imageSR = 4326;
  409. } else {
  410. query.bboxSR = 3857;
  411. query.imageSR = 3857;
  412. }
  413. if (imageryProvider.layers) {
  414. query.layers = "show:" + imageryProvider.layers;
  415. }
  416. resource = imageryProvider._resource.getDerivedResource({
  417. url: "export",
  418. request: request,
  419. queryParameters: query,
  420. });
  421. }
  422. return resource;
  423. }
  424. Object.defineProperties(ArcGisMapServerImageryProvider.prototype, {
  425. /**
  426. * Gets the URL of the ArcGIS MapServer.
  427. * @memberof ArcGisMapServerImageryProvider.prototype
  428. * @type {String}
  429. * @readonly
  430. */
  431. url: {
  432. get: function () {
  433. return this._resource._url;
  434. },
  435. },
  436. /**
  437. * Gets the ArcGIS token used to authenticate with the ArcGis MapServer service.
  438. * @memberof ArcGisMapServerImageryProvider.prototype
  439. * @type {String}
  440. * @readonly
  441. */
  442. token: {
  443. get: function () {
  444. return this._resource.queryParameters.token;
  445. },
  446. },
  447. /**
  448. * Gets the proxy used by this provider.
  449. * @memberof ArcGisMapServerImageryProvider.prototype
  450. * @type {Proxy}
  451. * @readonly
  452. */
  453. proxy: {
  454. get: function () {
  455. return this._resource.proxy;
  456. },
  457. },
  458. /**
  459. * Gets the width of each tile, in pixels. This function should
  460. * not be called before {@link ArcGisMapServerImageryProvider#ready} returns true.
  461. * @memberof ArcGisMapServerImageryProvider.prototype
  462. * @type {Number}
  463. * @readonly
  464. */
  465. tileWidth: {
  466. get: function () {
  467. //>>includeStart('debug', pragmas.debug);
  468. if (!this._ready) {
  469. throw new DeveloperError(
  470. "tileWidth must not be called before the imagery provider is ready."
  471. );
  472. }
  473. //>>includeEnd('debug');
  474. return this._tileWidth;
  475. },
  476. },
  477. /**
  478. * Gets the height of each tile, in pixels. This function should
  479. * not be called before {@link ArcGisMapServerImageryProvider#ready} returns true.
  480. * @memberof ArcGisMapServerImageryProvider.prototype
  481. * @type {Number}
  482. * @readonly
  483. */
  484. tileHeight: {
  485. get: function () {
  486. //>>includeStart('debug', pragmas.debug);
  487. if (!this._ready) {
  488. throw new DeveloperError(
  489. "tileHeight must not be called before the imagery provider is ready."
  490. );
  491. }
  492. //>>includeEnd('debug');
  493. return this._tileHeight;
  494. },
  495. },
  496. /**
  497. * Gets the maximum level-of-detail that can be requested. This function should
  498. * not be called before {@link ArcGisMapServerImageryProvider#ready} returns true.
  499. * @memberof ArcGisMapServerImageryProvider.prototype
  500. * @type {Number|undefined}
  501. * @readonly
  502. */
  503. maximumLevel: {
  504. get: function () {
  505. //>>includeStart('debug', pragmas.debug);
  506. if (!this._ready) {
  507. throw new DeveloperError(
  508. "maximumLevel must not be called before the imagery provider is ready."
  509. );
  510. }
  511. //>>includeEnd('debug');
  512. return this._maximumLevel;
  513. },
  514. },
  515. /**
  516. * Gets the minimum level-of-detail that can be requested. This function should
  517. * not be called before {@link ArcGisMapServerImageryProvider#ready} returns true.
  518. * @memberof ArcGisMapServerImageryProvider.prototype
  519. * @type {Number}
  520. * @readonly
  521. */
  522. minimumLevel: {
  523. get: function () {
  524. //>>includeStart('debug', pragmas.debug);
  525. if (!this._ready) {
  526. throw new DeveloperError(
  527. "minimumLevel must not be called before the imagery provider is ready."
  528. );
  529. }
  530. //>>includeEnd('debug');
  531. return 0;
  532. },
  533. },
  534. /**
  535. * Gets the tiling scheme used by this provider. This function should
  536. * not be called before {@link ArcGisMapServerImageryProvider#ready} returns true.
  537. * @memberof ArcGisMapServerImageryProvider.prototype
  538. * @type {TilingScheme}
  539. * @readonly
  540. */
  541. tilingScheme: {
  542. get: function () {
  543. //>>includeStart('debug', pragmas.debug);
  544. if (!this._ready) {
  545. throw new DeveloperError(
  546. "tilingScheme must not be called before the imagery provider is ready."
  547. );
  548. }
  549. //>>includeEnd('debug');
  550. return this._tilingScheme;
  551. },
  552. },
  553. /**
  554. * Gets the rectangle, in radians, of the imagery provided by this instance. This function should
  555. * not be called before {@link ArcGisMapServerImageryProvider#ready} returns true.
  556. * @memberof ArcGisMapServerImageryProvider.prototype
  557. * @type {Rectangle}
  558. * @readonly
  559. */
  560. rectangle: {
  561. get: function () {
  562. //>>includeStart('debug', pragmas.debug);
  563. if (!this._ready) {
  564. throw new DeveloperError(
  565. "rectangle must not be called before the imagery provider is ready."
  566. );
  567. }
  568. //>>includeEnd('debug');
  569. return this._rectangle;
  570. },
  571. },
  572. /**
  573. * Gets the tile discard policy. If not undefined, the discard policy is responsible
  574. * for filtering out "missing" tiles via its shouldDiscardImage function. If this function
  575. * returns undefined, no tiles are filtered. This function should
  576. * not be called before {@link ArcGisMapServerImageryProvider#ready} returns true.
  577. * @memberof ArcGisMapServerImageryProvider.prototype
  578. * @type {TileDiscardPolicy}
  579. * @readonly
  580. */
  581. tileDiscardPolicy: {
  582. get: function () {
  583. //>>includeStart('debug', pragmas.debug);
  584. if (!this._ready) {
  585. throw new DeveloperError(
  586. "tileDiscardPolicy must not be called before the imagery provider is ready."
  587. );
  588. }
  589. //>>includeEnd('debug');
  590. return this._tileDiscardPolicy;
  591. },
  592. },
  593. /**
  594. * Gets an event that is raised when the imagery provider encounters an asynchronous error. By subscribing
  595. * to the event, you will be notified of the error and can potentially recover from it. Event listeners
  596. * are passed an instance of {@link TileProviderError}.
  597. * @memberof ArcGisMapServerImageryProvider.prototype
  598. * @type {Event}
  599. * @readonly
  600. */
  601. errorEvent: {
  602. get: function () {
  603. return this._errorEvent;
  604. },
  605. },
  606. /**
  607. * Gets a value indicating whether or not the provider is ready for use.
  608. * @memberof ArcGisMapServerImageryProvider.prototype
  609. * @type {Boolean}
  610. * @readonly
  611. */
  612. ready: {
  613. get: function () {
  614. return this._ready;
  615. },
  616. },
  617. /**
  618. * Gets a promise that resolves to true when the provider is ready for use.
  619. * @memberof ArcGisMapServerImageryProvider.prototype
  620. * @type {Promise.<Boolean>}
  621. * @readonly
  622. */
  623. readyPromise: {
  624. get: function () {
  625. return this._readyPromise.promise;
  626. },
  627. },
  628. /**
  629. * Gets the credit to display when this imagery provider is active. Typically this is used to credit
  630. * the source of the imagery. This function should not be called before {@link ArcGisMapServerImageryProvider#ready} returns true.
  631. * @memberof ArcGisMapServerImageryProvider.prototype
  632. * @type {Credit}
  633. * @readonly
  634. */
  635. credit: {
  636. get: function () {
  637. return this._credit;
  638. },
  639. },
  640. /**
  641. * Gets a value indicating whether this imagery provider is using pre-cached tiles from the
  642. * ArcGIS MapServer. If the imagery provider is not yet ready ({@link ArcGisMapServerImageryProvider#ready}), this function
  643. * will return the value of `options.usePreCachedTilesIfAvailable`, even if the MapServer does
  644. * not have pre-cached tiles.
  645. * @memberof ArcGisMapServerImageryProvider.prototype
  646. *
  647. * @type {Boolean}
  648. * @readonly
  649. * @default true
  650. */
  651. usingPrecachedTiles: {
  652. get: function () {
  653. return this._useTiles;
  654. },
  655. },
  656. /**
  657. * Gets a value indicating whether or not the images provided by this imagery provider
  658. * include an alpha channel. If this property is false, an alpha channel, if present, will
  659. * be ignored. If this property is true, any images without an alpha channel will be treated
  660. * as if their alpha is 1.0 everywhere. When this property is false, memory usage
  661. * and texture upload time are reduced.
  662. * @memberof ArcGisMapServerImageryProvider.prototype
  663. *
  664. * @type {Boolean}
  665. * @readonly
  666. * @default true
  667. */
  668. hasAlphaChannel: {
  669. get: function () {
  670. return true;
  671. },
  672. },
  673. /**
  674. * Gets the comma-separated list of layer IDs to show.
  675. * @memberof ArcGisMapServerImageryProvider.prototype
  676. *
  677. * @type {String}
  678. */
  679. layers: {
  680. get: function () {
  681. return this._layers;
  682. },
  683. },
  684. });
  685. /**
  686. * Gets the credits to be displayed when a given tile is displayed.
  687. *
  688. * @param {Number} x The tile X coordinate.
  689. * @param {Number} y The tile Y coordinate.
  690. * @param {Number} level The tile level;
  691. * @returns {Credit[]} The credits to be displayed when the tile is displayed.
  692. *
  693. * @exception {DeveloperError} <code>getTileCredits</code> must not be called before the imagery provider is ready.
  694. */
  695. ArcGisMapServerImageryProvider.prototype.getTileCredits = function (
  696. x,
  697. y,
  698. level
  699. ) {
  700. return undefined;
  701. };
  702. /**
  703. * Requests the image for a given tile. This function should
  704. * not be called before {@link ArcGisMapServerImageryProvider#ready} returns true.
  705. *
  706. * @param {Number} x The tile X coordinate.
  707. * @param {Number} y The tile Y coordinate.
  708. * @param {Number} level The tile level.
  709. * @param {Request} [request] The request object. Intended for internal use only.
  710. * @returns {Promise.<HTMLImageElement|HTMLCanvasElement>|undefined} A promise for the image that will resolve when the image is available, or
  711. * undefined if there are too many active requests to the server, and the request
  712. * should be retried later. The resolved image may be either an
  713. * Image or a Canvas DOM object.
  714. *
  715. * @exception {DeveloperError} <code>requestImage</code> must not be called before the imagery provider is ready.
  716. */
  717. ArcGisMapServerImageryProvider.prototype.requestImage = function (
  718. x,
  719. y,
  720. level,
  721. request
  722. ) {
  723. //>>includeStart('debug', pragmas.debug);
  724. if (!this._ready) {
  725. throw new DeveloperError(
  726. "requestImage must not be called before the imagery provider is ready."
  727. );
  728. }
  729. //>>includeEnd('debug');
  730. return ImageryProvider.loadImage(
  731. this,
  732. buildImageResource(this, x, y, level, request)
  733. );
  734. };
  735. /**
  736. /**
  737. * Asynchronously determines what features, if any, are located at a given longitude and latitude within
  738. * a tile. This function should not be called before {@link ImageryProvider#ready} returns true.
  739. *
  740. * @param {Number} x The tile X coordinate.
  741. * @param {Number} y The tile Y coordinate.
  742. * @param {Number} level The tile level.
  743. * @param {Number} longitude The longitude at which to pick features.
  744. * @param {Number} latitude The latitude at which to pick features.
  745. * @return {Promise.<ImageryLayerFeatureInfo[]>|undefined} A promise for the picked features that will resolve when the asynchronous
  746. * picking completes. The resolved value is an array of {@link ImageryLayerFeatureInfo}
  747. * instances. The array may be empty if no features are found at the given location.
  748. *
  749. * @exception {DeveloperError} <code>pickFeatures</code> must not be called before the imagery provider is ready.
  750. */
  751. ArcGisMapServerImageryProvider.prototype.pickFeatures = function (
  752. x,
  753. y,
  754. level,
  755. longitude,
  756. latitude
  757. ) {
  758. //>>includeStart('debug', pragmas.debug);
  759. if (!this._ready) {
  760. throw new DeveloperError(
  761. "pickFeatures must not be called before the imagery provider is ready."
  762. );
  763. }
  764. //>>includeEnd('debug');
  765. if (!this.enablePickFeatures) {
  766. return undefined;
  767. }
  768. var rectangle = this._tilingScheme.tileXYToNativeRectangle(x, y, level);
  769. var horizontal;
  770. var vertical;
  771. var sr;
  772. if (this._tilingScheme.projection instanceof GeographicProjection) {
  773. horizontal = CesiumMath.toDegrees(longitude);
  774. vertical = CesiumMath.toDegrees(latitude);
  775. sr = "4326";
  776. } else {
  777. var projected = this._tilingScheme.projection.project(
  778. new Cartographic(longitude, latitude, 0.0)
  779. );
  780. horizontal = projected.x;
  781. vertical = projected.y;
  782. sr = "3857";
  783. }
  784. var layers = "visible";
  785. if (defined(this._layers)) {
  786. layers += ":" + this._layers;
  787. }
  788. var query = {
  789. f: "json",
  790. tolerance: 2,
  791. geometryType: "esriGeometryPoint",
  792. geometry: horizontal + "," + vertical,
  793. mapExtent:
  794. rectangle.west +
  795. "," +
  796. rectangle.south +
  797. "," +
  798. rectangle.east +
  799. "," +
  800. rectangle.north,
  801. imageDisplay: this._tileWidth + "," + this._tileHeight + ",96",
  802. sr: sr,
  803. layers: layers,
  804. };
  805. var resource = this._resource.getDerivedResource({
  806. url: "identify",
  807. queryParameters: query,
  808. });
  809. return resource.fetchJson().then(function (json) {
  810. var result = [];
  811. var features = json.results;
  812. if (!defined(features)) {
  813. return result;
  814. }
  815. for (var i = 0; i < features.length; ++i) {
  816. var feature = features[i];
  817. var featureInfo = new ImageryLayerFeatureInfo();
  818. featureInfo.data = feature;
  819. featureInfo.name = feature.value;
  820. featureInfo.properties = feature.attributes;
  821. featureInfo.configureDescriptionFromProperties(feature.attributes);
  822. // If this is a point feature, use the coordinates of the point.
  823. if (feature.geometryType === "esriGeometryPoint" && feature.geometry) {
  824. var wkid =
  825. feature.geometry.spatialReference &&
  826. feature.geometry.spatialReference.wkid
  827. ? feature.geometry.spatialReference.wkid
  828. : 4326;
  829. if (wkid === 4326 || wkid === 4283) {
  830. featureInfo.position = Cartographic.fromDegrees(
  831. feature.geometry.x,
  832. feature.geometry.y,
  833. feature.geometry.z
  834. );
  835. } else if (wkid === 102100 || wkid === 900913 || wkid === 3857) {
  836. var projection = new WebMercatorProjection();
  837. featureInfo.position = projection.unproject(
  838. new Cartesian3(
  839. feature.geometry.x,
  840. feature.geometry.y,
  841. feature.geometry.z
  842. )
  843. );
  844. }
  845. }
  846. result.push(featureInfo);
  847. }
  848. return result;
  849. });
  850. };
  851. export default ArcGisMapServerImageryProvider;