IonResource

new Cesium.IonResource(endpoint, endpointResource)

封装 Cesium ion 资产访问的 Resource 实例。 此对象通常不直接实例化,请使用 IonResource.fromAssetId
Name Type Description
endpoint object Cesium ion 资产端点服务的结果。
endpointResource Resource 用于检索终端节点的资源。
See:

Extends

Members

readonly credits : Array.<Credit>

获取资产归因所需的积分。

readonly extension : string

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

hasHeaders : boolean

如果 Resource 具有请求标头,则为 True。这等效于检查 headers 属性是否有任何键。
Inherited From:
将与请求一起发送的其他 HTTP 标头。
Inherited From:
如果 Resource 引用 blob URI,则为 True。
Inherited From:

isCrossOriginUrl : boolean

如果 Resource 引用跨源 URL,则为 True。
Inherited From:
如果 Resource 引用数据 URI,则为 True。
Inherited From:
加载资源时使用的代理。
Inherited From:

readonly queryParameters : object

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

retryAttempts : number

在放弃之前应调用 retryCallback 的次数。
Inherited From:

retryCallback : function

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

readonly templateValues : object

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

Methods

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

异步创建实例。
Name Type Description
assetId number The Cesium ion asset id.
options object optional 对象,具有以下属性:
Name Type Default Description
accessToken string Ion.defaultAccessToken optional 要使用的访问令牌。
server string | Resource Ion.defaultServer optional Cesium ion API 服务器的资源。
Returns:
Promise,表示 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:
复制Resource实例。
Name Type Description
result Resource optional 要在其上存储结果的对象。
Returns:
修改后的结果参数或者新的 Resource 实例(如果未提供)。
Inherited From:

delete(options)Promise.<any>|undefined

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

fetch(options)Promise.<any>|undefined

异步加载给定的资源。 返回一个 Promise,该 Promise 将解析为 加载后的结果,如果资源加载失败,则为 reject。 数据已加载 使用 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,该 Promise 将在加载时解析为请求的数据。如果 request.throttle 为 true,并且请求的优先级不够高,则返回 undefined。
Inherited From:
Example:
resource.fetch()
  .then(function(body) {
      // use the data
  }).catch(function(error) {
      // an error occurred
  });
See:

fetchArrayBuffer()Promise.<ArrayBuffer>|undefined

异步加载资源作为原始二进制数据。 返回一个 Promise,该 Promise 将解析为 加载后为 ArrayBuffer,如果资源加载失败,则为 reject。 数据已加载 使用 XMLHttpRequest,这意味着为了向另一个源发出请求, 服务器必须启用跨域资源共享 (CORS) 标头。
Returns:
一个 Promise,该 Promise 将在加载时解析为请求的数据。如果 request.throttle 为 true,并且请求的优先级不够高,则返回 undefined。
Inherited From:
Example:
// load a single URL asynchronously
resource.fetchArrayBuffer().then(function(arrayBuffer) {
    // use the data
}).catch(function(error) {
    // an error occurred
});
See:

fetchBlob()Promise.<Blob>|undefined

以异步方式将给定资源加载为 blob。 返回一个 Promise,该 Promise 将解析为 加载后为 Blob,如果资源加载失败,则为 reject。 数据已加载 使用 XMLHttpRequest,这意味着为了向另一个源发出请求, 服务器必须启用跨域资源共享 (CORS) 标头。
Returns:
一个 Promise,该 Promise 将在加载时解析为请求的数据。如果 request.throttle 为 true,并且请求的优先级不够高,则返回 undefined。
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

异步加载给定的图像资源。 返回一个 Promise,该 Promise 将解析为 an ImageBitmap 如果 preferImageBitmap 为 true,并且浏览器支持 createImageBitmap 或其他 Image,如果图像加载失败,则为 reject。
Name Type Description
options object optional 具有以下属性的对象。
Name Type Default Description
preferBlob boolean false optional 如果为 true,我们将通过 blob 加载图像。
preferImageBitmap boolean false optional 如果为 true,则在获取过程中将对图像进行解码并返回 ImageBitmap
flipY boolean false optional 如果为 true,则图像将在解码过程中垂直翻转。仅当浏览器支持 createImageBitmap 时适用。
skipColorSpaceConversion boolean false optional 如果为 true,则图像中的任何自定义灰度系数或颜色配置文件都将被忽略。仅当浏览器支持 createImageBitmap 时适用。
Returns:
一个 Promise,该 Promise 将在加载时解析为请求的数据。如果 request.throttle 为 true,并且请求的优先级不够高,则返回 undefined。
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

以 JSON 格式异步加载给定资源。 返回一个 Promise,该 Promise 将解析为 JSON 对象,如果资源加载失败,则拒绝。 数据已加载 使用 XMLHttpRequest,这意味着为了向另一个源发出请求, 服务器必须启用跨域资源共享 (CORS) 标头。此功能 添加 'Accept: application/json,*/*;q=0.01' 添加到请求标头中,如果不是 已指定。
Returns:
一个 Promise,该 Promise 将在加载时解析为请求的数据。如果 request.throttle 为 true,并且请求的优先级不够高,则返回 undefined。
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,该 Promise 将在加载时解析为请求的数据。如果 request.throttle 为 true,并且请求的优先级不够高,则返回 undefined。
Inherited From:
Example:
// load a data asynchronously
resource.fetchJsonp().then(function(data) {
    // use the loaded data
}).catch(function(error) {
    // an error occurred
});
See:

fetchText()Promise.<string>|undefined

异步加载给定的资源为文本。 返回一个 Promise,该 Promise 将解析为 一个 String,如果资源加载失败,则为 reject。 数据已加载 使用 XMLHttpRequest,这意味着为了向另一个源发出请求, 服务器必须启用跨域资源共享 (CORS) 标头。
Returns:
一个 Promise,该 Promise 将在加载时解析为请求的数据。如果 request.throttle 为 true,并且请求的优先级不够高,则返回 undefined。
Inherited From:
Example:
// load text from a URL, setting a custom header
const 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
}).catch(function(error) {
    // an error occurred
});
See:

fetchXML()Promise.<XMLDocument>|undefined

以 XML 形式异步加载给定的资源。 返回一个 Promise,该 Promise 将解析为 XML 文档,如果资源加载失败,则拒绝。 数据已加载 使用 XMLHttpRequest,这意味着为了向另一个源发出请求, 服务器必须启用跨域资源共享 (CORS) 标头。
Returns:
一个 Promise,该 Promise 将在加载时解析为请求的数据。如果 request.throttle 为 true,并且请求的优先级不够高,则返回 undefined。
Inherited From:
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
}).catch(function(error) {
    // an error occurred
});
See:

getBaseUri(includeQuery)string

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

getDerivedResource(options)Resource

返回相对于当前实例的资源。所有属性都与当前实例相同,除非在 options 中被覆盖。
Name Type Description
options object 具有以下属性的对象
Name Type Default Description
url string optional 将相对于当前实例的 url 解析的 url。
queryParameters object optional 一个包含将与当前实例的查询参数合并的对象。
templateValues object optional 用于替换模板值的键/值对(例如。这些将与当前实例的 API 合并。
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,该 Promise 将解析为 加载后的结果,如果资源加载失败,则为 reject。 数据已加载 使用 XMLHttpRequest,这意味着为了向另一个源发出请求, 服务器必须启用跨域资源共享 (CORS) 标头。
Name Type Description
options object optional 对象,具有以下属性:
Name Type Description
responseType string optional 响应的类型。 这控制返回的项的类型。
headers object optional 与请求一起发送的其他 HTTP 标头(如果有)。
overrideMimeType string optional 覆盖服务器返回的 MIME 类型。
Returns:
一个 Promise,该 Promise 将在加载时解析为请求的数据。如果 request.throttle 为 true,并且请求的优先级不够高,则返回 undefined。
Inherited From:
Example:
resource.head()
  .then(function(headers) {
      // use the data
  }).catch(function(error) {
      // an error occurred
  });
See:

options(options)Promise.<any>|undefined

异步获取给定资源的 options。 返回一个 Promise,该 Promise 将解析为 加载后的结果,如果资源加载失败,则为 reject。 数据已加载 使用 XMLHttpRequest,这意味着为了向另一个源发出请求, 服务器必须启用跨域资源共享 (CORS) 标头。
Name Type Description
options object optional 对象,具有以下属性:
Name Type Description
responseType string optional 响应的类型。 这控制返回的项的类型。
headers object optional 与请求一起发送的其他 HTTP 标头(如果有)。
overrideMimeType string optional 覆盖服务器返回的 MIME 类型。
Returns:
一个 Promise,该 Promise 将在加载时解析为请求的数据。如果 request.throttle 为 true,并且请求的优先级不够高,则返回 undefined。
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,该 Promise 将解析为 加载后的结果,如果资源加载失败,则为 reject。 数据已加载 使用 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,该 Promise 将在加载时解析为请求的数据。如果 request.throttle 为 true,并且请求的优先级不够高,则返回 undefined。
Inherited From:
Example:
resource.patch(data)
  .then(function(result) {
      // use the result
  }).catch(function(error) {
      // an error occurred
  });
See:

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

异步将数据发布到给定的资源。 返回一个 Promise,该 Promise 将解析为 加载后的结果,如果资源加载失败,则为 reject。 数据已加载 使用 XMLHttpRequest,这意味着为了向另一个源发出请求, 服务器必须启用跨域资源共享 (CORS) 标头。
Name Type Description
data object 与资源一起发布的数据。
options object optional 对象,具有以下属性:
Name Type Description
data object optional 与资源一起发布的数据。
responseType string optional 响应的类型。 这控制返回的项的类型。
headers object optional 与请求一起发送的其他 HTTP 标头(如果有)。
overrideMimeType string optional 覆盖服务器返回的 MIME 类型。
Returns:
一个 Promise,该 Promise 将在加载时解析为请求的数据。如果 request.throttle 为 true,并且请求的优先级不够高,则返回 undefined。
Inherited From:
Example:
resource.post(data)
  .then(function(result) {
      // use the result
  }).catch(function(error) {
      // an error occurred
  });
See:

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

异步将数据放入给定的资源。 返回一个 Promise,该 Promise 将解析为 加载后的结果,如果资源加载失败,则为 reject。 数据已加载 使用 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,该 Promise 将在加载时解析为请求的数据。如果 request.throttle 为 true,并且请求的优先级不够高,则返回 undefined。
Inherited From:
Example:
resource.put(data)
  .then(function(result) {
      // use the result
  }).catch(function(error) {
      // an error occurred
  });
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,以便隐式字符串转换给出 此资源表示的完整 URL。
Returns:
此资源表示的 URL
Inherited From:
Need help? The fastest way to get answers is from the community and team on the Cesium Forum.