IonResource

new Cesium.IonResource(endpoint, endpointResource)

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 original resource used to retrieve the endpoint.
See:

Extends

Members

readonly credits : Array.<Credit>

Gets the credits required for attribution of the asset.

readonly extension : string

资源的文件扩展名。
Inherited From:

hasHeaders : boolean

如果Resource有请求标头则为true。这等同于检查headers属性是否有任何键。
Inherited From:
将随请求发送的额外HTTP标头。
Inherited From:
True if the Resource refers to a blob URI.
Inherited From:

isCrossOriginUrl : boolean

如果Resource引用跨域URL则为true。
Inherited From:
True if the Resource refers to a data URI.
Inherited From:
加载资源时要使用的代理。
Inherited From:

readonly queryParameters : object

追加到URL的查询参数。
Inherited From:
将使用的Request对象。仅供内部使用。
Inherited From:

retryAttempts : number

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

retryCallback : function

此资源请求失败时调用的函数。如果返回true或解析为true的Promise,将重试请求。
Inherited From:

readonly templateValues : object

用于替换URL中模板参数的键值对。
Inherited From:
替换模板值后、追加查询字符串并由代理编码(如果设置了代理)的资源URL。
Inherited From:

Methods

static Cesium.IonResource.fromAssetId(assetId, options)Promise.<IonResource>

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 an instance representing the Cesium ion Asset.
Examples:
// Load a Cesium3DTileset with asset ID of 124624234
try {
  const resource = await Cesium.IonResource.fromAssetId(124624234);
  const tileset = await Cesium.Cesium3DTileset.fromUrl(resource);
  scene.primitives.add(tileset);
} catch (error) {
  console.error(`Error creating tileset: ${error}`);
}
//Load a CZML file with asset ID of 10890
Cesium.IonResource.fromAssetId(10890)
  .then(function (resource) {
    viewer.dataSources.add(Cesium.CzmlDataSource.load(resource));
  });

appendForwardSlash()

向URL追加正斜杠。
Inherited From:

appendQueryParameters(params)

合并指定对象和现有查询参数。这允许您一次添加多个参数, 而不是一次添加一个参数到queryParameters属性。
Name Type Description
params object 查询参数
Inherited From:
复制资源实例。
Name Type Description
result Resource optional 存储结果的对象。
Returns:
修改后的结果参数,如果未提供则返回新的Resource实例。
Inherited From:

delete(options)Promise.<any>|undefined

异步删除给定资源。返回一个Promise,加载后将解析为 结果,如果资源加载失败则拒绝。数据使用XMLHttpRequest加载, 这意味着要向后端发出请求,服务器必须启用跨域资源共享(CORS)标头。
Name Type Description
options object optional 具有下列属性的对象:
Name Type Description
responseType string optional 响应类型。这控制返回项的类型。
headers object optional 随请求发送的额外HTTP标头(如果有)。
overrideMimeType string optional 覆盖服务器返回的MIME类型。
Returns:
加载后将解析为请求数据的Promise。如果request.throttle为true且请求优先级不够高,则返回undefined。
Inherited From:
Example:
resource.delete()
  .then(function(body) {
      // 使用数据
  }).catch(function(error) {
      // 发生错误
  });
See:

fetch(options)Promise.<any>|undefined

异步加载给定资源。返回一个Promise,加载后将解析为 结果,如果资源加载失败则拒绝。数据使用XMLHttpRequest加载, 这意味着要向后端发出请求,服务器必须启用跨域资源共享(CORS)标头。建议您使用 更具体的函数,例如fetchJson、fetchBlob等。
Name Type Description
options object optional 具有下列属性的对象:
Name Type Description
responseType string optional 响应类型。这控制返回项的类型。
headers object optional 随请求发送的额外HTTP标头(如果有)。
overrideMimeType string optional 覆盖服务器返回的MIME类型。
Returns:
加载后将解析为请求数据的Promise。如果request.throttle为true且请求优先级不够高,则返回undefined。
Inherited From:
Example:
resource.fetch()
  .then(function(body) {
      // 使用数据
  }).catch(function(error) {
      // 发生错误
  });
See:

fetchArrayBuffer()Promise.<ArrayBuffer>|undefined

异步加载资源为原始二进制数据。返回一个Promise,加载后将解析为 ArrayBuffer,如果资源加载失败则拒绝。数据使用XMLHttpRequest加载, 这意味着要向后端发出请求,服务器必须启用跨域资源共享(CORS)标头。
Returns:
加载后将解析为请求数据的Promise。如果request.throttle为true且请求优先级不够高,则返回undefined。
Inherited From:
Example:
// 异步加载单个URL
resource.fetchArrayBuffer().then(function(arrayBuffer) {
    // 使用数据
}).catch(function(error) {
    // 发生错误
});
See:

fetchBlob()Promise.<Blob>|undefined

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:
Example:
// load a single URL asynchronously
resource.fetchBlob().then(function(blob) {
    // use the data
}).catch(function(error) {
    // an error occurred
});
See:

fetchImage(options)Promise.<(ImageBitmap|HTMLImageElement)>|undefined

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:
Example:
// load a single image asynchronously
resource.fetchImage().then(function(image) {
    // use the loaded image
}).catch(function(error) {
    // an error occurred
});

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

fetchJson()Promise.<any>|undefined

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:
Example:
resource.fetchJson().then(function(jsonData) {
    // Do something with the JSON object
}).catch(function(error) {
    // an error occurred
});
See:

fetchJsonp(callbackParameterName)Promise.<any>|undefined

使用JSONP请求资源。
Name Type Default Description
callbackParameterName string 'callback' optional 服务器期望的回调参数名。
Returns:
加载后将解析为请求数据的Promise。如果request.throttle为true且请求优先级不够高,则返回undefined。
Inherited From:
Example:
// 异步加载数据
resource.fetchJsonp().then(function(data) {
    // 使用加载的数据
}).catch(function(error) {
    // 发生错误
});
See:

fetchText()Promise.<string>|undefined

异步加载给定资源为文本。返回一个Promise,加载后将解析为 字符串,如果资源加载失败则拒绝。数据使用XMLHttpRequest加载, 这意味着要向后端发出请求,服务器必须启用跨域资源共享(CORS)标头。
Returns:
加载后将解析为请求数据的Promise。如果request.throttle为true且请求优先级不够高,则返回undefined。
Inherited From:
Example:
// 从URL加载文本,设置自定义标头
const resource = new Resource({
  url: 'http://someUrl.com/someJson.txt',
  headers: {
    'X-Custom-Header' : 'some value'
  }
});
resource.fetchText().then(function(text) {
    // 对文本执行某些操作
}).catch(function(error) {
    // 发生错误
});
See:

fetchXML()Promise.<XMLDocument>|undefined

异步加载给定资源为XML。返回一个Promise,加载后将解析为 XML文档,如果资源加载失败则拒绝。数据使用XMLHttpRequest加载, 这意味着要向后端发出请求,服务器必须启用跨域资源共享(CORS)标头。
Returns:
加载后将解析为请求数据的Promise。如果request.throttle为true且请求优先级不够高,则返回undefined。
Inherited From:
Example:
// 从URL加载XML,设置自定义标头
Cesium.loadXML('http://someUrl.com/someXML.xml', {
  'X-Custom-Header' : 'some value'
}).then(function(document) {
    // 对文档执行某些操作
}).catch(function(error) {
    // 发生错误
});
See:

getBaseUri(includeQuery)string

返回Resource的基础路径。
Name Type Default Description
includeQuery boolean false optional 是否包含URI中的查询字符串和片段
Returns:
资源的基础URI
Inherited From:

getDerivedResource(options)Resource

返回相对于当前实例的资源。除非在选项中重写,否则所有属性保持与当前实例相同。
Name Type Description
options object 具有下列属性的对象
Name Type Default Description
url string optional 将相对于当前实例URL解析的URL。
queryParameters object optional 包含将与当前实例参数合并的查询参数的对象。
templateValues object optional 用于替换模板值(例如{x})的键值对。这些将与当前实例的值合并。
headers object {} optional 将发送的额外HTTP标头。
proxy Proxy optional 加载资源时要使用的代理。
retryCallback Resource.RetryCallback optional 加载资源失败时调用的函数。
retryAttempts number optional 在放弃之前应调用retryCallback的次数。
request Request optional 将使用的Request对象。仅供内部使用。
preserveQueryParameters boolean false optional 如果为true,将保留当前资源和派生资源的所有查询参数。如果为false,派生参数将替换当前资源的参数。
Returns:
从当前资源派生的资源。
Inherited From:

getUrlComponent(query, proxy)string

返回URL,可选包含查询字符串并由代理处理。
Name Type Default Description
query boolean false optional 如果为true,则包含查询字符串。
proxy boolean false optional 如果为true,则URL由代理对象处理(如果已定义)。
Returns:
包含所有请求组件的URL。
Inherited From:
异步获取给定资源的标头。返回一个Promise,加载后将解析为 结果,如果资源加载失败则拒绝。数据使用XMLHttpRequest加载, 这意味着要向后端发出请求,服务器必须启用跨域资源共享(CORS)标头。
Name Type Description
options object optional 具有下列属性的对象:
Name Type Description
responseType string optional 响应类型。这控制返回项的类型。
headers object optional 随请求发送的额外HTTP标头(如果有)。
overrideMimeType string optional 覆盖服务器返回的MIME类型。
Returns:
加载后将解析为请求数据的Promise。如果request.throttle为true且请求优先级不够高,则返回undefined。
Inherited From:
Example:
resource.head()
  .then(function(headers) {
      // 使用数据
  }).catch(function(error) {
      // 发生错误
  });
See:

options(options)Promise.<any>|undefined

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:
Example:
resource.options()
  .then(function(headers) {
      // use the data
  }).catch(function(error) {
      // an error occurred
  });
See:

patch(data, options)Promise.<any>|undefined

异步放置数据到给定资源。返回一个Promise,加载后将解析为 结果,如果资源加载失败则拒绝。数据使用XMLHttpRequest加载, 这意味着要向后端发出请求,服务器必须启用跨域资源共享(CORS)标头。
Name Type Description
data object 随资源发布的数据。
options object optional 具有下列属性的对象:
Name Type Description
responseType string optional 响应类型。这控制返回项的类型。
headers object optional 随请求发送的额外HTTP标头(如果有)。
overrideMimeType string optional 覆盖服务器返回的MIME类型。
Returns:
加载后将解析为请求数据的Promise。如果request.throttle为true且请求优先级不够高,则返回undefined。
Inherited From:
Example:
resource.put(data)
  .then(function(result) {
      // 使用结果
  }).catch(function(error) {
      // 发生错误
  });
See:

post(data, options)Promise.<any>|undefined

异步向给定资源打补丁数据。返回一个Promise,加载后将解析为 结果,如果资源加载失败则拒绝。数据使用XMLHttpRequest加载, 这意味着要向后端发出请求,服务器必须启用跨域资源共享(CORS)标头。
Name Type Description
data object 随资源发布的数据。
options object optional 具有下列属性的对象:
Name Type Description
responseType string optional 响应类型。这控制返回项的类型。
headers object optional 随请求发送的额外HTTP标头(如果有)。
overrideMimeType string optional 覆盖服务器返回的MIME类型。
Returns:
加载后将解析为请求数据的Promise。如果request.throttle为true且请求优先级不够高,则返回undefined。
Inherited From:
Example:
resource.patch(data)
  .then(function(result) {
      // 使用结果
  }).catch(function(error) {
      // 发生错误
  });
See:

put(data, options)Promise.<any>|undefined

异步放置数据到给定资源。返回一个Promise,加载后将解析为 结果,如果资源加载失败则拒绝。数据使用XMLHttpRequest加载, 这意味着要向后端发出请求,服务器必须启用跨域资源共享(CORS)标头。
Name Type Description
data object 随资源发布的数据。
options object optional 具有下列属性的对象:
Name Type Description
responseType string optional 响应类型。这控制返回项的类型。
headers object optional 随请求发送的额外HTTP标头(如果有)。
overrideMimeType string optional 覆盖服务器返回的MIME类型。
Returns:
加载后将解析为请求数据的Promise。如果request.throttle为true且请求优先级不够高,则返回undefined。
Inherited From:
Example:
resource.put(data)
  .then(function(result) {
      // 使用结果
  }).catch(function(error) {
      // 发生错误
  });
See:

setQueryParameters(params, useAsDefault)

合并指定对象和现有查询参数。这允许您一次添加多个参数, 而不是一次添加一个参数到queryParameters属性。如果值已设置,它将被新值替换。
Name Type Default Description
params object 查询参数
useAsDefault boolean false optional 如果为true,参数将用作默认值,仅在未定义时设置。
Inherited From:

setTemplateValues(template, useAsDefault)

合并指定对象和现有模板值。这允许您一次添加多个值, 而不是一次添加一个值到templateValues属性。如果值已设置,它将变成数组并追加新值。
Name Type Default Description
template object 模板值
useAsDefault boolean false optional 如果为true,值将用作默认值,仅在未定义时设置。
Inherited From:

toString()string

重写Object#toString,使隐式字符串转换给出此Resource表示的完整URL。
Returns:
此Resource表示的URL
Inherited From:
Need help? The fastest way to get answers is from the community and team on the Cesium Forum.