import GeographicTilingScheme from "./GeographicTilingScheme"
import when from "./when"
// import {
// Cesium.ImageryLayerFeatureInfo,
// Cesium.DiscardMissingTileImagePolicy,
// Cesium.WebMercatorTilingScheme,
// Cesium.WebMercatorProjection,
// Cesium.TileProviderError,
// Cesium.RuntimeError,
// Cesium.Resource,
// Cesium.Rectangle,
// Math as Cesium.Math,
// Cesium.GeographicProjection,
// Cesium.Event,
// Cesium.DeveloperError,
// Cesium.defined,
// Cesium.defaultValue,
// Cesium.Credit,
// Cesium.Cartographic,
// Cesium.Cartesian3,
// Cesium.Cartesian2
// } from "cesium"
/**
* @typedef {Object} ArcGisMapServerImageryProvider.ConstructorOptions
*
* Initialization options for the ArcGisMapServerImageryProvider constructor
*
* @property {Cesium.Resource|String} url The URL of the ArcGIS MapServer service.
* @property {String} [token] The ArcGIS token used to authenticate with the ArcGIS MapServer service.
* @property {TileDiscardPolicy} [tileDiscardPolicy] The policy that determines if a tile
* is invalid and should be discarded. If this value is not specified, a default
* {@link Cesium.DiscardMissingTileImagePolicy} is used for tiled map servers, and a
* {@link NeverTileDiscardPolicy} is used for non-tiled map servers. In the former case,
* we request tile 0,0 at the maximum tile level and check pixels (0,0), (200,20), (20,200),
* (80,110), and (160, 130). If all of these pixels are transparent, the discard check is
* disabled and no tiles are discarded. If any of them have a non-transparent color, any
* tile that has the same values in these pixel locations is discarded. The end result of
* these defaults should be correct tile discarding for a standard ArcGIS Server. To ensure
* that no tiles are discarded, construct and pass a {@link NeverTileDiscardPolicy} for this
* parameter.
* @property {Boolean} [usePreCachedTilesIfAvailable=true] If true, the server's pre-cached
* tiles are used if they are available. If false, any pre-cached tiles are ignored and the
* 'export' service is used.
* @property {String} [layers] A comma-separated list of the layers to show, or undefined if all layers should be shown.
* @property {Boolean} [enablePickFeatures=true] If true, {@link ArcGisMapServerImageryProvider#pickFeatures} will invoke
* the Identify service on the MapServer and return the features included in the response. If false,
* {@link ArcGisMapServerImageryProvider#pickFeatures} will immediately return undefined (indicating no pickable features)
* without communicating with the server. Set this property to false if you don't want this provider's features to
* be pickable. Can be overridden by setting the {@link ArcGisMapServerImageryProvider#enablePickFeatures} property on the object.
* @property {Cesium.Rectangle} [rectangle=Cesium.Rectangle.MAX_VALUE] The rectangle of the layer. This parameter is ignored when accessing
* a tiled layer.
* @property {TilingScheme} [tilingScheme=new GeographicTilingScheme()] The tiling scheme to use to divide the world into tiles.
* This parameter is ignored when accessing a tiled server.
* @property {Ellipsoid} [ellipsoid] The ellipsoid. If the tilingScheme is specified and used,
* this parameter is ignored and the tiling scheme's ellipsoid is used instead. If neither
* parameter is specified, the WGS84 ellipsoid is used.
* @property {Cesium.Credit|String} [credit] A credit for the data source, which is displayed on the canvas. This parameter is ignored when accessing a tiled server.
* @property {Number} [tileWidth=256] The width of each tile in pixels. This parameter is ignored when accessing a tiled server.
* @property {Number} [tileHeight=256] The height of each tile in pixels. This parameter is ignored when accessing a tiled server.
* @property {Number} [maximumLevel] The maximum tile level to request, or undefined if there is no maximum. This parameter is ignored when accessing
* a tiled server.
*/
/**
* Provides tiled imagery hosted by an ArcGIS MapServer. By default, the server's pre-cached tiles are
* used, if available.
*
* @alias ArcGisMapServerImageryProvider
* @constructor
*
* @param {ArcGisMapServerImageryProvider.ConstructorOptions} options Object describing initialization options
*
* @see BingMapsImageryProvider
* @see GoogleEarthEnterpriseMapsProvider
* @see OpenStreetMapImageryProvider
* @see SingleTileImageryProvider
* @see TileMapServiceImageryProvider
* @see WebMapServiceImageryProvider
* @see WebMapTileServiceImageryProvider
* @see UrlTemplateImageryProvider
*
*
* @example
* var esri = new Cesium.ArcGisMapServerImageryProvider({
* url : 'https://services.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer'
* });
*
* @see {@link https://developers.arcgis.com/rest/|ArcGIS Server REST API}
* @see {@link http://www.w3.org/TR/cors/|Cross-Origin Cesium.Resource Sharing}
*/
function ArcGisMapServerImageryProvider(options) {
options = Cesium.defaultValue(options, Cesium.defaultValue.EMPTY_OBJECT)
//>>includeStart('debug', pragmas.debug);
if (!Cesium.defined(options.url)) {
throw new Cesium.DeveloperError("options.url is required.")
}
//>>includeEnd('debug');
/**
* The default alpha blending value of this provider, with 0.0 representing fully transparent and
* 1.0 representing fully opaque.
*
* @type {Number|undefined}
* @default undefined
*/
this.defaultAlpha = undefined
/**
* The default alpha blending value on the night side of the globe of this provider, with 0.0 representing fully transparent and
* 1.0 representing fully opaque.
*
* @type {Number|undefined}
* @default undefined
*/
this.defaultNightAlpha = undefined
/**
* The default alpha blending value on the day side of the globe of this provider, with 0.0 representing fully transparent and
* 1.0 representing fully opaque.
*
* @type {Number|undefined}
* @default undefined
*/
this.defaultDayAlpha = undefined
/**
* The default brightness of this provider. 1.0 uses the unmodified imagery color. Less than 1.0
* makes the imagery darker while greater than 1.0 makes it brighter.
*
* @type {Number|undefined}
* @default undefined
*/
this.defaultBrightness = undefined
/**
* The default contrast of this provider. 1.0 uses the unmodified imagery color. Less than 1.0 reduces
* the contrast while greater than 1.0 increases it.
*
* @type {Number|undefined}
* @default undefined
*/
this.defaultContrast = undefined
/**
* The default hue of this provider in radians. 0.0 uses the unmodified imagery color.
*
* @type {Number|undefined}
* @default undefined
*/
this.defaultHue = undefined
/**
* The default saturation of this provider. 1.0 uses the unmodified imagery color. Less than 1.0 reduces the
* saturation while greater than 1.0 increases it.
*
* @type {Number|undefined}
* @default undefined
*/
this.defaultSaturation = undefined
/**
* The default gamma correction to apply to this provider. 1.0 uses the unmodified imagery color.
*
* @type {Number|undefined}
* @default undefined
*/
this.defaultGamma = undefined
/**
* The default texture minification filter to apply to this provider.
*
* @type {TextureMinificationFilter}
* @default undefined
*/
this.defaultMinificationFilter = undefined
/**
* The default texture magnification filter to apply to this provider.
*
* @type {TextureMagnificationFilter}
* @default undefined
*/
this.defaultMagnificationFilter = undefined
this._layerDefs = options.layerDefs
this._layerName = options.layerName
var resource = Cesium.Resource.create