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

ArcGisMapServerImageryProvider.js 29KB

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