# IonResource

#### new Cesium.IonResource(endpoint, endpointResource)
Core/IonResource.js 27

A `Resource` instance that encapsulates Cesium ion asset access. This object is normally not instantiated directly, use `IonResource.fromAssetId`.

Name | Type | Description
--- | --- | ---
`endpoint` | Object | The result of the Cesium ion asset endpoint service.
`endpointResource` | Resource | The resource used to retreive the endpoint.

##### See:

- Ion
- IonImageryProvider
- createWorldTerrain
- https://cesium.com

### Extends

- Resource

### Members

#### readonly credits : Array.<Credit>
Core/IonResource.js 117

Gets the credits required for attribution of the asset.

#### readonly extension : String
Core/Resource.js 471

The file extension of the resource.

Inherited From:
  - Resource#extension

#### hasHeaders : Boolean
Core/Resource.js 519

True if the Resource has request headers. This is equivalent to checking if the headers property has any keys.

Inherited From:
  - Resource#hasHeaders

#### headers : Object
Core/Resource.js 283

Additional HTTP headers that will be sent with the request.

Inherited From:
  - Resource#headers

#### isBlobUri : Boolean
Core/Resource.js 495

True if the Resource refers to a blob URI.

Inherited From:
  - Resource#isBlobUri

#### isCrossOriginUrl : Boolean
Core/Resource.js 507

True if the Resource refers to a cross origin URL.

Inherited From:
  - Resource#isCrossOriginUrl

#### isDataUri : Boolean
Core/Resource.js 483

True if the Resource refers to a data URI.

Inherited From:
  - Resource#isDataUri

#### proxy : Proxy
Core/Resource.js 297

A proxy to be used when loading the resource.

Inherited From:
  - Resource#proxy

#### readonly queryParameters : Object
Core/Resource.js 421

Query parameters appended to the url.

Inherited From:
  - Resource#queryParameters

#### request : Request
Core/Resource.js 290

A Request object that will be used. Intended for internal use only.

Inherited From:
  - Resource#request

#### retryAttempts : Number
Core/Resource.js 311

The number of times the retryCallback should be called before giving up.

Inherited From:
  - Resource#retryAttempts

#### retryCallback : function
Core/Resource.js 304

Function to call when a request for this resource fails. If it returns true or a Promise that resolves to true, the request will be retried.

Inherited From:
  - Resource#retryCallback

#### readonly templateValues : Object
Core/Resource.js 435

The key/value pairs used to replace template parameters in the url.

Inherited From:
  - Resource#templateValues

#### url : String
Core/Resource.js 447

The url to the resource with template values replaced, query string appended and encoded by proxy if one was set.

Inherited From:
  - Resource#url

### Methods

#### static Cesium.IonResource.fromAssetId(assetId, options) → Promise.<IonResource>
Core/IonResource.js 101

Asynchronously creates an instance.

Name | Type | Description
--- | --- | ---
`assetId` | Number | The Cesium ion asset id.

`options`

Object

optional An object with the following properties:

Name | Type | Default | Description
--- | --- | --- | ---
`accessToken` | String | `Ion.defaultAccessToken` | optional The access token to use.
`server` | String | Resource | `Ion.defaultServer` | optional The resource to the Cesium ion API server.

##### Returns:

A Promise to am instance representing the Cesium ion Asset.

##### Examples:

    //Load a Cesium3DTileset with asset ID of 124624234
    viewer.scene.primitives.add(new Cesium.Cesium3DTileset({ url: Cesium.IonResource.fromAssetId(124624234) }));

    //Load a CZML file with asset ID of 10890
    Cesium.IonResource.fromAssetId(10890)
      .then(function (resource) {
        viewer.dataSources.add(Cesium.CzmlDataSource.load(resource));
      });

#### appendForwardSlash()
Core/Resource.js 766

Appends a forward slash to the URL.

Inherited From:
  - Resource#appendForwardSlash

#### appendQueryParameters(params)
Core/Resource.js 604

Combines the specified object and the existing query parameters. This allows you to add many parameters at once, as opposed to adding them one at a time to the queryParameters property.

Name | Type | Description
--- | --- | ---
`params` | Object | The query parameters

Inherited From:
  - Resource#appendQueryParameters

#### clone(result) → Resource
Core/Resource.js 732

Duplicates a Resource instance.

Name | Type | Description
--- | --- | ---
`result` | Resource | optional The object onto which to store the result.

##### Returns:

The modified result parameter or a new Resource instance if one was not provided.

Inherited From:
  - Resource#clone

#### delete(options) → Promise.<*>|undefined
Core/Resource.js 1546

Asynchronously deletes the given resource. Returns a promise that will resolve to the result once loaded, or reject if the resource failed to load. The data is loaded using XMLHttpRequest, which means that in order to make requests to another origin, the server must have Cross-Origin Resource Sharing (CORS) headers enabled.

Name | Type | Description
--- | --- | ---

`options`

Object

optional Object with the following properties:

Name | Type | Description
--- | --- | ---
`responseType` | String | optional The type of response. This controls the type of item returned.
`headers` | Object | optional Additional HTTP headers to send with the request, if any.
`overrideMimeType` | String | optional Overrides the MIME type returned by the server.

##### Returns:

a promise that will resolve to the requested data when loaded. Returns undefined if `request.throttle` is true and the request does not have high enough priority.

Inherited From:
  - Resource#delete

##### Example:

    resource.delete()
      .then(function(body) {
          // use the data
      }).otherwise(function(error) {
          // an error occurred
      });

##### See:

- Cross-Origin Resource Sharing
- CommonJS Promises/A

#### fetch(options) → Promise.<*>|undefined
Core/Resource.js 1490

Asynchronously loads the given resource. Returns a promise that will resolve to the result once loaded, or reject if the resource failed to load. The data is loaded using XMLHttpRequest, which means that in order to make requests to another origin, the server must have Cross-Origin Resource Sharing (CORS) headers enabled. It's recommended that you use the more specific functions eg. fetchJson, fetchBlob, etc.

Name | Type | Description
--- | --- | ---

`options`

Object

optional Object with the following properties:

Name | Type | Description
--- | --- | ---
`responseType` | String | optional The type of response. This controls the type of item returned.
`headers` | Object | optional Additional HTTP headers to send with the request, if any.
`overrideMimeType` | String | optional Overrides the MIME type returned by the server.

##### Returns:

a promise that will resolve to the requested data when loaded. Returns undefined if `request.throttle` is true and the request does not have high enough priority.

Inherited From:
  - Resource#fetch

##### Example:

    resource.fetch()
      .then(function(body) {
          // use the data
      }).otherwise(function(error) {
          // an error occurred
      });

##### See:

- Cross-Origin Resource Sharing
- CommonJS Promises/A

#### fetchArrayBuffer() → Promise.<ArrayBuffer>|undefined
Core/Resource.js 789

Asynchronously loads the resource as raw binary data. Returns a promise that will resolve to an ArrayBuffer once loaded, or reject if the resource failed to load. The data is loaded using XMLHttpRequest, which means that in order to make requests to another origin, the server must have Cross-Origin Resource Sharing (CORS) headers enabled.

##### Returns:

a promise that will resolve to the requested data when loaded. Returns undefined if `request.throttle` is true and the request does not have high enough priority.

Inherited From:
  - Resource#fetchArrayBuffer

##### Example:

    // load a single URL asynchronously
    resource.fetchArrayBuffer().then(function(arrayBuffer) {
        // use the data
    }).otherwise(function(error) {
        // an error occurred
    });

##### See:

- Cross-Origin Resource Sharing
- CommonJS Promises/A

#### fetchBlob() → Promise.<Blob>|undefined
Core/Resource.js 833

Asynchronously loads the given resource as a blob. Returns a promise that will resolve to a Blob once loaded, or reject if the resource failed to load. The data is loaded using XMLHttpRequest, which means that in order to make requests to another origin, the server must have Cross-Origin Resource Sharing (CORS) headers enabled.

##### Returns:

a promise that will resolve to the requested data when loaded. Returns undefined if `request.throttle` is true and the request does not have high enough priority.

Inherited From:
  - Resource#fetchBlob

##### Example:

    // load a single URL asynchronously
    resource.fetchBlob().then(function(blob) {
        // use the data
    }).otherwise(function(error) {
        // an error occurred
    });

##### See:

- Cross-Origin Resource Sharing
- CommonJS Promises/A

#### fetchImage(options) → Promise.<ImageBitmap>|Promise.<HTMLImageElement>|undefined
Core/Resource.js 887

Asynchronously loads the given image resource. Returns a promise that will resolve to an ImageBitmap if `preferImageBitmap` is true and the browser supports `createImageBitmap` or otherwise an Image once loaded, or reject if the image failed to load.

Name | Type | Description
--- | --- | ---

`options`

Object

optional An object with the following properties.

Name | Type | Default | Description
--- | --- | --- | ---
`preferBlob` | Boolean | `false` | optional If true, we will load the image via a blob.
`preferImageBitmap` | Boolean | `false` | optional If true, image will be decoded during fetch and an `ImageBitmap` is returned.
`flipY` | Boolean | `false` | optional If true, image will be vertically flipped during decode. Only applies if the browser supports `createImageBitmap`.
`skipColorSpaceConversion` | Boolean | `false` | optional If true, any custom gamma or color profiles in the image will be ignored. Only applies if the browser supports `createImageBitmap`.

##### Returns:

a promise that will resolve to the requested data when loaded. Returns undefined if `request.throttle` is true and the request does not have high enough priority.

Inherited From:
  - Resource#fetchImage

##### Example:

    // load a single image asynchronously
    resource.fetchImage().then(function(image) {
        // use the loaded image
    }).otherwise(function(error) {
        // an error occurred
    });

    // load several images in parallel
    when.all([resource1.fetchImage(), resource2.fetchImage()]).then(function(images) {
        // images is an array containing all the loaded images
    });

##### See:

- Cross-Origin Resource Sharing
- CommonJS Promises/A

#### fetchJson() → Promise.<*>|undefined
Core/Resource.js 1155

Asynchronously loads the given resource as JSON. Returns a promise that will resolve to a JSON object once loaded, or reject if the resource failed to load. The data is loaded using XMLHttpRequest, which means that in order to make requests to another origin, the server must have Cross-Origin Resource Sharing (CORS) headers enabled. This function adds 'Accept: application/json,*/*;q=0.01' to the request headers, if not already specified.

##### Returns:

a promise that will resolve to the requested data when loaded. Returns undefined if `request.throttle` is true and the request does not have high enough priority.

Inherited From:
  - Resource#fetchJson

##### Example:

    resource.fetchJson().then(function(jsonData) {
        // Do something with the JSON object
    }).otherwise(function(error) {
        // an error occurred
    });

##### See:

- Cross-Origin Resource Sharing
- CommonJS Promises/A

#### fetchJsonp(callbackParameterName) → Promise.<*>|undefined
Core/Resource.js 1260

Requests a resource using JSONP.

Name | Type | Default | Description
--- | --- | --- | ---
`callbackParameterName` | String | `'callback'` | optional The callback parameter name that the server expects.

##### Returns:

a promise that will resolve to the requested data when loaded. Returns undefined if `request.throttle` is true and the request does not have high enough priority.

Inherited From:
  - Resource#fetchJsonp

##### Example:

    // load a data asynchronously
    resource.fetchJsonp().then(function(data) {
        // use the loaded data
    }).otherwise(function(error) {
        // an error occurred
    });

##### See:

- CommonJS Promises/A

#### fetchText() → Promise.<String>|undefined
Core/Resource.js 1108

Asynchronously loads the given resource as text. Returns a promise that will resolve to a String once loaded, or reject if the resource failed to load. The data is loaded using XMLHttpRequest, which means that in order to make requests to another origin, the server must have Cross-Origin Resource Sharing (CORS) headers enabled.

##### Returns:

a promise that will resolve to the requested data when loaded. Returns undefined if `request.throttle` is true and the request does not have high enough priority.

Inherited From:
  - Resource#fetchText

##### Example:

    // load text from a URL, setting a custom header
    var resource = new Resource({
      url: 'http://someUrl.com/someJson.txt',
      headers: {
        'X-Custom-Header' : 'some value'
      }
    });
    resource.fetchText().then(function(text) {
        // Do something with the text
    }).otherwise(function(error) {
        // an error occurred
    });

##### See:

- XMLHttpRequest
- Cross-Origin Resource Sharing
- CommonJS Promises/A

#### fetchXML() → Promise.<XMLDocument>|undefined
Core/Resource.js 1217

Asynchronously loads the given resource as XML. Returns a promise that will resolve to an XML Document once loaded, or reject if the resource failed to load. The data is loaded using XMLHttpRequest, which means that in order to make requests to another origin, the server must have Cross-Origin Resource Sharing (CORS) headers enabled.

##### Returns:

a promise that will resolve to the requested data when loaded. Returns undefined if `request.throttle` is true and the request does not have high enough priority.

Inherited From:
  - Resource#fetchXML

##### Example:

    // load XML from a URL, setting a custom header
    Cesium.loadXML('http://someUrl.com/someXML.xml', {
      'X-Custom-Header' : 'some value'
    }).then(function(document) {
        // Do something with the document
    }).otherwise(function(error) {
        // an error occurred
    });

##### See:

- XMLHttpRequest
- Cross-Origin Resource Sharing
- CommonJS Promises/A

#### getBaseUri(includeQuery) → String
Core/Resource.js 759

Returns the base path of the Resource.

Name | Type | Default | Description
--- | --- | --- | ---
`includeQuery` | Boolean | `false` | optional Whether or not to include the query string and fragment form the uri

##### Returns:

The base URI of the resource

Inherited From:
  - Resource#getBaseUri

#### getDerivedResource(options) → Resource
Core/Resource.js 643

Returns a resource relative to the current instance. All properties remain the same as the current instance unless overridden in options.

Name | Type | Description
--- | --- | ---

`options`

Object

An object with the following properties

Name | Type | Default | Description
--- | --- | --- | ---
`url` | String |  | optional The url that will be resolved relative to the url of the current instance.
`queryParameters` | Object |  | optional An object containing query parameters that will be combined with those of the current instance.
`templateValues` | Object |  | optional Key/Value pairs that are used to replace template values (eg. {x}). These will be combined with those of the current instance.
`headers` | Object | `{}` | optional Additional HTTP headers that will be sent.
`proxy` | Proxy |  | optional A proxy to be used when loading the resource.
`retryCallback` | Resource.RetryCallback |  | optional The function to call when loading the resource fails.
`retryAttempts` | Number |  | optional The number of times the retryCallback should be called before giving up.
`request` | Request |  | optional A Request object that will be used. Intended for internal use only.
`preserveQueryParameters` | Boolean | `false` | optional If true, this will keep all query parameters from the current resource and derived resource. If false, derived parameters will replace those of the current resource.

##### Returns:

The resource derived from the current one.

Inherited From:
  - Resource#getDerivedResource

#### getUrlComponent(query, proxy) → String
Core/Resource.js 544

Returns the url, optional with the query string and processed by a proxy.

Name | Type | Default | Description
--- | --- | --- | ---
`query` | Boolean | `false` | optional If true, the query string is included.
`proxy` | Boolean | `false` | optional If true, the url is processed by the proxy object, if defined.

##### Returns:

The url with all the requested components.

Inherited From:
  - Resource#getUrlComponent

#### head(options) → Promise.<*>|undefined
Core/Resource.js 1604

Asynchronously gets headers the given resource. Returns a promise that will resolve to the result once loaded, or reject if the resource failed to load. The data is loaded using XMLHttpRequest, which means that in order to make requests to another origin, the server must have Cross-Origin Resource Sharing (CORS) headers enabled.

Name | Type | Description
--- | --- | ---

`options`

Object

optional Object with the following properties:

Name | Type | Description
--- | --- | ---
`responseType` | String | optional The type of response. This controls the type of item returned.
`headers` | Object | optional Additional HTTP headers to send with the request, if any.
`overrideMimeType` | String | optional Overrides the MIME type returned by the server.

##### Returns:

a promise that will resolve to the requested data when loaded. Returns undefined if `request.throttle` is true and the request does not have high enough priority.

Inherited From:
  - Resource#head

##### Example:

    resource.head()
      .then(function(headers) {
          // use the data
      }).otherwise(function(error) {
          // an error occurred
      });

##### See:

- Cross-Origin Resource Sharing
- CommonJS Promises/A

#### options(options) → Promise.<*>|undefined
Core/Resource.js 1660

Asynchronously gets options the given resource. Returns a promise that will resolve to the result once loaded, or reject if the resource failed to load. The data is loaded using XMLHttpRequest, which means that in order to make requests to another origin, the server must have Cross-Origin Resource Sharing (CORS) headers enabled.

Name | Type | Description
--- | --- | ---

`options`

Object

optional Object with the following properties:

Name | Type | Description
--- | --- | ---
`responseType` | String | optional The type of response. This controls the type of item returned.
`headers` | Object | optional Additional HTTP headers to send with the request, if any.
`overrideMimeType` | String | optional Overrides the MIME type returned by the server.

##### Returns:

a promise that will resolve to the requested data when loaded. Returns undefined if `request.throttle` is true and the request does not have high enough priority.

Inherited From:
  - Resource#options

##### Example:

    resource.options()
      .then(function(headers) {
          // use the data
      }).otherwise(function(error) {
          // an error occurred
      });

##### See:

- Cross-Origin Resource Sharing
- CommonJS Promises/A

#### patch(data, options) → Promise.<*>|undefined
Core/Resource.js 1840

Asynchronously patches data to the given resource. Returns a promise that will resolve to the result once loaded, or reject if the resource failed to load. The data is loaded using XMLHttpRequest, which means that in order to make requests to another origin, the server must have Cross-Origin Resource Sharing (CORS) headers enabled.

Name | Type | Description
--- | --- | ---
`data` | Object | Data that is posted with the resource.

`options`

Object

optional Object with the following properties:

Name | Type | Description
--- | --- | ---
`responseType` | String | optional The type of response. This controls the type of item returned.
`headers` | Object | optional Additional HTTP headers to send with the request, if any.
`overrideMimeType` | String | optional Overrides the MIME type returned by the server.

##### Returns:

a promise that will resolve to the requested data when loaded. Returns undefined if `request.throttle` is true and the request does not have high enough priority.

Inherited From:
  - Resource#patch

##### Example:

    resource.patch(data)
      .then(function(result) {
          // use the result
      }).otherwise(function(error) {
          // an error occurred
      });

##### See:

- Cross-Origin Resource Sharing
- CommonJS Promises/A

#### post(data, options) → Promise.<*>|undefined
Core/Resource.js 1718

Asynchronously posts data to the given resource. Returns a promise that will resolve to the result once loaded, or reject if the resource failed to load. The data is loaded using XMLHttpRequest, which means that in order to make requests to another origin, the server must have Cross-Origin Resource Sharing (CORS) headers enabled.

Name | Type | Description
--- | --- | ---
`data` | Object | Data that is posted with the resource.

`options`

Object

optional Object with the following properties:

Name | Type | Description
--- | --- | ---
`data` | Object | optional Data that is posted with the resource.
`responseType` | String | optional The type of response. This controls the type of item returned.
`headers` | Object | optional Additional HTTP headers to send with the request, if any.
`overrideMimeType` | String | optional Overrides the MIME type returned by the server.

##### Returns:

a promise that will resolve to the requested data when loaded. Returns undefined if `request.throttle` is true and the request does not have high enough priority.

Inherited From:
  - Resource#post

##### Example:

    resource.post(data)
      .then(function(result) {
          // use the result
      }).otherwise(function(error) {
          // an error occurred
      });

##### See:

- Cross-Origin Resource Sharing
- CommonJS Promises/A

#### put(data, options) → Promise.<*>|undefined
Core/Resource.js 1779

Asynchronously puts data to the given resource. Returns a promise that will resolve to the result once loaded, or reject if the resource failed to load. The data is loaded using XMLHttpRequest, which means that in order to make requests to another origin, the server must have Cross-Origin Resource Sharing (CORS) headers enabled.

Name | Type | Description
--- | --- | ---
`data` | Object | Data that is posted with the resource.

`options`

Object

optional Object with the following properties:

Name | Type | Description
--- | --- | ---
`responseType` | String | optional The type of response. This controls the type of item returned.
`headers` | Object | optional Additional HTTP headers to send with the request, if any.
`overrideMimeType` | String | optional Overrides the MIME type returned by the server.

##### Returns:

a promise that will resolve to the requested data when loaded. Returns undefined if `request.throttle` is true and the request does not have high enough priority.

Inherited From:
  - Resource#put

##### Example:

    resource.put(data)
      .then(function(result) {
          // use the result
      }).otherwise(function(error) {
          // an error occurred
      });

##### See:

- Cross-Origin Resource Sharing
- CommonJS Promises/A

#### setQueryParameters(params, useAsDefault)
Core/Resource.js 582

Combines the specified object and the existing query parameters. This allows you to add many parameters at once, as opposed to adding them one at a time to the queryParameters property. If a value is already set, it will be replaced with the new value.

Name | Type | Default | Description
--- | --- | --- | ---
`params` | Object |  | The query parameters
`useAsDefault` | Boolean | `false` | optional If true the params will be used as the default values, so they will only be set if they are undefined.

Inherited From:
  - Resource#setQueryParameters

#### setTemplateValues(template, useAsDefault)
Core/Resource.js 619

Combines the specified object and the existing template values. This allows you to add many values at once, as opposed to adding them one at a time to the templateValues property. If a value is already set, it will become an array and the new value will be appended.

Name | Type | Default | Description
--- | --- | --- | ---
`template` | Object |  | The template values
`useAsDefault` | Boolean | `false` | optional If true the values will be used as the default values, so they will only be set if they are undefined.

Inherited From:
  - Resource#setTemplateValues

#### toString() → String
Core/Resource.js 532

Override Object#toString so that implicit string conversion gives the complete URL represented by this Resource.

##### Returns:

The URL represented by this Resource

Inherited From:
  - Resource#toString