Resource

new Cesium.Resource(options)

一个资源,包括位置和我们需要获取它或创建派生资源的其他参数。它还提供重试请求的能力。
Name Type Description
options string | Resource.ConstructorOptions URL 或描述初始化选项的对象
Example:
function refreshTokenRetryCallback(resource, error) {
  if (error.statusCode === 403) {
    // 403 status code means a new token should be generated
    return getNewAccessToken()
      .then(function(token) {
        resource.queryParameters.access_token = token;
        return true;
      })
      .catch(function() {
        return false;
      });
  }

  return false;
}

const resource = new Resource({
   url: 'http://server.com/path/to/resource.json',
   proxy: new DefaultProxy('/proxy/'),
   headers: {
     'X-My-Header': 'valueOfHeader'
   },
   queryParameters: {
     'access_token': '123-435-456-000'
   },
   retryCallback: refreshTokenRetryCallback,
   retryAttempts: 1
});

Members

static constant Cesium.Resource.DEFAULT : Resource

初始化为当前浏览器位置的资源实例

static readonly Cesium.Resource.isBlobSupported : boolean

如果支持 blobs,则返回 true。

readonly extension : string

资源的文件扩展名。

hasHeaders : boolean

如果资源具有请求头,则返回真。等效于检查 headers 属性是否有任何键。
将随请求发送的额外 HTTP 头。
如果资源引用的是 blob URI,则为真。

isCrossOriginUrl : boolean

如果资源引用的是跨域 URL,则为真。
如果资源引用的是数据 URI,则为真。
加载资源时使用的代理。

readonly queryParameters : object

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

retryAttempts : number

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

retryCallback : function

请求该资源失败时要调用的函数。如果返回 true 或返回一个解析为 true 的 Promise,则请求将被重试。

readonly templateValues : object

用于替换 URL 中模板参数的键/值对。
URL,替换了模板值,附加了查询字符串,并在设置代理时进行了编码。

Methods

static Cesium.Resource.delete(options)Promise.<any>|undefined

从 URL 创建一个 Resource 并调用 delete()。
Name Type Description
options string | object URL 或具有以下属性的对象
Name Type Default Description
url string 资源的 URL。
data object optional 与资源一起发送的数据。
queryParameters object optional 一个包含在检索资源时将发送的查询参数的对象。
templateValues object optional 用于替换模板值的键/值对(例如 {x})。
headers object {} optional 将发送的额外 HTTP 头。
proxy Proxy optional 加载资源时使用的代理。
retryCallback Resource.RetryCallback optional 当请求该资源失败时要调用的函数。如果返回 true,则会重试请求。
retryAttempts number 0 optional 在放弃之前应调用 retryCallback 的次数。
request Request optional 将被使用的 Request 对象。仅供内部使用。
responseType string optional 响应的类型。控制返回的项目类型。
overrideMimeType string optional 覆盖服务器返回的 MIME 类型。
Returns:
一个承诺,当数据加载完成时将解析为请求的数据。如果 request.throttle 为真且请求的优先级不够高,则返回 undefined。

static Cesium.Resource.fetch(options)Promise.<any>|undefined

从 URL 创建一个 Resource 并调用 fetch()。
Name Type Description
options string | object URL 或具有以下属性的对象
Name Type Default Description
url string 资源的 URL。
queryParameters object optional 一个包含在检索资源时将发送的查询参数的对象。
templateValues object optional 用于替换模板值的键/值对(例如 {x})。
headers object {} optional 将发送的额外 HTTP 头。
proxy Proxy optional 加载资源时使用的代理。
retryCallback Resource.RetryCallback optional 当请求该资源失败时要调用的函数。如果返回 true,则会重试请求。
retryAttempts number 0 optional 在放弃之前应调用 retryCallback 的次数。
request Request optional 将被使用的 Request 对象。仅供内部使用。
responseType string optional 响应的类型。控制返回的项目类型。
overrideMimeType string optional 覆盖服务器返回的 MIME 类型。
Returns:
一个承诺,当数据加载完成时将解析为请求的数据。如果 request.throttle 为真且请求的优先级不够高,则返回 undefined。

static Cesium.Resource.fetchArrayBuffer(options)Promise.<ArrayBuffer>|undefined

创建一个 Resource 并调用 fetchArrayBuffer()。
Name Type Description
options string | object URL 或具有以下属性的对象
Name Type Default Description
url string 资源的 URL。
queryParameters object optional 一个包含在检索资源时将发送的查询参数的对象。
templateValues object optional 用于替换模板值的键/值对(例如 {x})。
headers object {} optional 将发送的额外 HTTP 头。
proxy Proxy optional 加载资源时使用的代理。
retryCallback Resource.RetryCallback optional 当请求该资源失败时要调用的函数。如果返回 true,则会重试请求。
retryAttempts number 0 optional 在放弃之前应调用 retryCallback 的次数。
request Request optional 将被使用的 Request 对象。仅供内部使用。
Returns:
一个承诺,当数据加载完成时将解析为请求的数据。如果 request.throttle 为 true 且请求的优先级不够高,则返回 undefined。

static Cesium.Resource.fetchBlob(options)Promise.<Blob>|undefined

创建一个 Resource 并调用 fetchBlob()。
Name Type Description
options string | object URL 或具有以下属性的对象
Name Type Default Description
url string 资源的 URL。
queryParameters object optional 一个包含在检索资源时将发送的查询参数的对象。
templateValues object optional 用于替换模板值的键/值对(例如 {x})。
headers object {} optional 将发送的额外 HTTP 头。
proxy Proxy optional 加载资源时使用的代理。
retryCallback Resource.RetryCallback optional 当请求该资源失败时要调用的函数。如果返回 true,则会重试请求。
retryAttempts number 0 optional 在放弃之前应调用 retryCallback 的次数。
request Request optional 将被使用的 Request 对象。仅供内部使用。
Returns:
一个承诺,当数据加载完成时将解析为请求的数据。如果 request.throttle 为 true 且请求的优先级不够高,则返回 undefined。

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

创建一个 Resource 并调用 fetchImage()。
Name Type Description
options string | object URL 或具有以下属性的对象
Name Type Default Description
url string 资源的 URL。
queryParameters object optional 一个包含在检索资源时将发送的查询参数的对象。
templateValues object optional 用于替换模板值的键/值对(例如 {x})。
headers object {} optional 将发送的额外 HTTP 头。
proxy Proxy optional 加载资源时使用的代理。
flipY boolean false optional 是否在获取和解码期间垂直翻转图像。仅在请求图像且浏览器支持 createImageBitmap 时适用。
retryCallback Resource.RetryCallback optional 当请求该资源失败时要调用的函数。如果返回 true,则会重试请求。
retryAttempts number 0 optional 在放弃之前应调用 retryCallback 的次数。
request Request optional 将被使用的 Request 对象。仅供内部使用。
preferBlob boolean false optional 如果为真,我们将通过 blob 加载图像。
preferImageBitmap boolean false optional 如果为真,图像将在获取期间解码并返回 ImageBitmap
skipColorSpaceConversion boolean false optional 如果为真,图像中的任何自定义伽马或色彩配置文件将被忽略。仅在请求图像且浏览器支持 createImageBitmap 时适用。
Returns:
一个承诺,当数据加载完成时将解析为请求的数据。如果 request.throttle 为真且请求的优先级不够高,则返回 undefined。

static Cesium.Resource.fetchJson(options)Promise.<any>|undefined

创建一个 Resource 并调用 fetchJson()。
Name Type Description
options string | object URL 或具有以下属性的对象
Name Type Default Description
url string 资源的 URL。
queryParameters object optional 一个包含在检索资源时将发送的查询参数的对象。
templateValues object optional 用于替换模板值的键/值对(例如 {x})。
headers object {} optional 将发送的额外 HTTP 头。
proxy Proxy optional 加载资源时使用的代理。
retryCallback Resource.RetryCallback optional 当请求该资源失败时要调用的函数。如果返回 true,则会重试请求。
retryAttempts number 0 optional 在放弃之前应调用 retryCallback 的次数。
request Request optional 将被使用的 Request 对象。仅供内部使用。
Returns:
一个承诺,当数据加载完成时将解析为请求的数据。如果 request.throttle 为真且请求的优先级不够高,则返回 undefined。

static Cesium.Resource.fetchJsonp(options)Promise.<any>|undefined

从 URL 创建一个 Resource 并调用 fetchJsonp()。
Name Type Description
options string | object URL 或具有以下属性的对象
Name Type Default Description
url string 资源的 URL。
queryParameters object optional 一个包含在检索资源时将发送的查询参数的对象。
templateValues object optional 用于替换模板值的键/值对(例如 {x})。
headers object {} optional 将发送的额外 HTTP 头。
proxy Proxy optional 加载资源时使用的代理。
retryCallback Resource.RetryCallback optional 当请求该资源失败时要调用的函数。如果返回 true,则会重试请求。
retryAttempts number 0 optional 在放弃之前应调用 retryCallback 的次数。
request Request optional 将被使用的 Request 对象。仅供内部使用。
callbackParameterName string 'callback' optional 服务器期望的回调参数名称。
Returns:
一个承诺,当数据加载完成时将解析为请求的数据。如果 request.throttle 为真且请求的优先级不够高,则返回 undefined。

static Cesium.Resource.fetchText(options)Promise.<string>|undefined

创建一个 Resource 并调用 fetchText()。
Name Type Description
options string | object URL 或具有以下属性的对象
Name Type Default Description
url string 资源的 URL。
queryParameters object optional 一个包含在检索资源时将发送的查询参数的对象。
templateValues object optional 用于替换模板值的键/值对(例如 {x})。
headers object {} optional 将发送的额外 HTTP 头。
proxy Proxy optional 加载资源时使用的代理。
retryCallback Resource.RetryCallback optional 当请求该资源失败时要调用的函数。如果返回 true,则会重试请求。
retryAttempts number 0 optional 在放弃之前应调用 retryCallback 的次数。
request Request optional 将被使用的 Request 对象。仅供内部使用。
Returns:
一个承诺,当数据加载完成时将解析为请求的数据。如果 request.throttle 为真且请求的优先级不够高,则返回 undefined。

static Cesium.Resource.fetchXML(options)Promise.<XMLDocument>|undefined

创建一个 Resource 并调用 fetchXML()。
Name Type Description
options string | object URL 或具有以下属性的对象
Name Type Default Description
url string 资源的 URL。
queryParameters object optional 一个包含在检索资源时将发送的查询参数的对象。
templateValues object optional 用于替换模板值的键/值对(例如 {x})。
headers object {} optional 将发送的额外 HTTP 头。
proxy Proxy optional 加载资源时使用的代理。
retryCallback Resource.RetryCallback optional 当请求该资源失败时要调用的函数。如果返回 true,则会重试请求。
retryAttempts number 0 optional 在放弃之前应调用 retryCallback 的次数。
request Request optional 将被使用的 Request 对象。仅供内部使用。
Returns:
一个承诺,当数据加载完成时将解析为请求的数据。如果 request.throttle 为真且请求的优先级不够高,则返回 undefined。

static Cesium.Resource.head(options)Promise.<any>|undefined

从 URL 创建一个 Resource 并调用 head()。
Name Type Description
options string | object URL 或具有以下属性的对象
Name Type Default Description
url string 资源的 URL。
queryParameters object optional 一个包含在检索资源时将发送的查询参数的对象。
templateValues object optional 用于替换模板值的键/值对(例如 {x})。
headers object {} optional 将发送的额外 HTTP 头。
proxy Proxy optional 加载资源时使用的代理。
retryCallback Resource.RetryCallback optional 当请求该资源失败时要调用的函数。如果返回 true,则会重试请求。
retryAttempts number 0 optional 在放弃之前应调用 retryCallback 的次数。
request Request optional 将被使用的 Request 对象。仅供内部使用。
responseType string optional 响应的类型。控制返回的项目类型。
overrideMimeType string optional 覆盖服务器返回的 MIME 类型。
Returns:
一个承诺,当数据加载完成时将解析为请求的数据。如果 request.throttle 为真且请求的优先级不够高,则返回 undefined。

static Cesium.Resource.options(options)Promise.<any>|undefined

从 URL 创建一个 Resource 并调用 options()。
Name Type Description
options string | object URL 或具有以下属性的对象
Name Type Default Description
url string 资源的 URL。
queryParameters object optional 一个包含在检索资源时将发送的查询参数的对象。
templateValues object optional 用于替换模板值的键/值对(例如 {x})。
headers object {} optional 将发送的额外 HTTP 头。
proxy Proxy optional 加载资源时使用的代理。
retryCallback Resource.RetryCallback optional 当请求该资源失败时要调用的函数。如果返回 true,则会重试请求。
retryAttempts number 0 optional 在放弃之前应调用 retryCallback 的次数。
request Request optional 将被使用的 Request 对象。仅供内部使用。
responseType string optional 响应的类型。控制返回的项目类型。
overrideMimeType string optional 覆盖服务器返回的 MIME 类型。
Returns:
一个承诺,当数据加载完成时将解析为请求的数据。如果 request.throttle 为真且请求的优先级不够高,则返回 undefined。

static Cesium.Resource.patch(options)Promise.<any>|undefined

从 URL 创建一个 Resource 并调用 patch()。
Name Type Description
options object URL 或具有以下属性的对象
Name Type Default Description
url string 资源的 URL。
data object 与资源一起发送的数据。
queryParameters object optional 一个包含在检索资源时将发送的查询参数的对象。
templateValues object optional 用于替换模板值的键/值对(例如 {x})。
headers object {} optional 将发送的额外 HTTP 头。
proxy Proxy optional 加载资源时使用的代理。
retryCallback Resource.RetryCallback optional 当请求该资源失败时要调用的函数。如果返回 true,则会重试请求。
retryAttempts number 0 optional 在放弃之前应调用 retryCallback 的次数。
request Request optional 将被使用的 Request 对象。仅供内部使用。
responseType string optional 响应的类型。控制返回的项目类型。
overrideMimeType string optional 覆盖服务器返回的 MIME 类型。
Returns:
一个承诺,当数据加载完成时将解析为请求的数据。如果 request.throttle 为真且请求的优先级不够高,则返回 undefined。

static Cesium.Resource.post(options)Promise.<any>|undefined

从 URL 创建一个 Resource 并调用 post()。
Name Type Description
options object URL 或具有以下属性的对象
Name Type Default Description
url string 资源的 URL。
data object 与资源一起发送的数据。
queryParameters object optional 一个包含在检索资源时将发送的查询参数的对象。
templateValues object optional 用于替换模板值的键/值对(例如 {x})。
headers object {} optional 将发送的额外 HTTP 头。
proxy Proxy optional 加载资源时使用的代理。
retryCallback Resource.RetryCallback optional 当请求该资源失败时要调用的函数。如果返回 true,则会重试请求。
retryAttempts number 0 optional 在放弃之前应调用 retryCallback 的次数。
request Request optional 将被使用的 Request 对象。仅供内部使用。
responseType string optional 响应的类型。控制返回的项目类型。
overrideMimeType string optional 覆盖服务器返回的 MIME 类型。
Returns:
一个承诺,当数据加载完成时将解析为请求的数据。如果 request.throttle 为真且请求的优先级不够高,则返回 undefined。

static Cesium.Resource.put(options)Promise.<any>|undefined

从 URL 创建一个 Resource 并调用 put()。
Name Type Description
options object URL 或具有以下属性的对象
Name Type Default Description
url string 资源的 URL。
data object 与资源一起发送的数据。
queryParameters object optional 一个包含在检索资源时将发送的查询参数的对象。
templateValues object optional 用于替换模板值的键/值对(例如 {x})。
headers object {} optional 将发送的额外 HTTP 头。
proxy Proxy optional 加载资源时使用的代理。
retryCallback Resource.RetryCallback optional 当请求该资源失败时要调用的函数。如果返回 true,则会重试请求。
retryAttempts number 0 optional 在放弃之前应调用 retryCallback 的次数。
request Request optional 将被使用的 Request 对象。仅供内部使用。
responseType string optional 响应的类型。控制返回的项目类型。
overrideMimeType string optional 覆盖服务器返回的 MIME 类型。
Returns:
一个承诺,当数据加载完成时将解析为请求的数据。如果 request.throttle 为真且请求的优先级不够高,则返回 undefined。

appendForwardSlash()

在 URL 末尾附加一个正斜杠。

appendQueryParameters(params)

结合指定对象和现有查询参数。这允许一次添加多个参数, 反之则需要逐个添加到 queryParameters 属性。
Name Type Description
params object 查询参数
复制一个 Resource 实例。
Name Type Description
result Resource optional 存储结果的对象。
Returns:
修改后的结果参数,或者如果未提供则返回一个新 Resource 实例。

delete(options)Promise.<any>|undefined

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

fetch(options)Promise.<any>|undefined

异步加载给定资源。返回一个承诺,一旦加载完成将解析为 结果,或者在资源加载失败时拒绝。数据是使用 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:
一个承诺,当数据加载完成时将解析为请求的数据。如果 request.throttle 为真且请求的优先级不够高,则返回 undefined。
Example:
resource.fetch()
  .then(function(body) {
      // use the data
  }).catch(function(error) {
      // an error occurred
  });
See:

fetchArrayBuffer()Promise.<ArrayBuffer>|undefined

异步加载资源作为原始二进制数据。返回一个承诺,一旦加载完成将解析为 ArrayBuffer,或者在资源加载失败时拒绝。数据是使用 XMLHttpRequest 加载的, 这意味着为了向其他来源发出请求,服务器必须启用跨源资源共享 (CORS) 头。
Returns:
一个承诺,当数据加载完成时将解析为请求的数据。如果 request.throttle 为 true 且请求的优先级不够高,则返回 undefined。
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。返回一个承诺,一旦加载完成将解析为 Blob,或者在资源加载失败时拒绝。数据是使用 XMLHttpRequest 加载的, 这意味着为了向其他来源发出请求,服务器必须启用跨源资源共享 (CORS) 头。
Returns:
一个承诺,当数据加载完成时将解析为请求的数据。如果 request.throttle 为 true 且请求的优先级不够高,则返回 undefined。
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

异步加载给定的图像资源。返回一个承诺,如果 preferImageBitmap 为真且浏览器支持 createImageBitmap,将解析为一个 ImageBitmap, 否则将解析为一个 Image,一旦加载完成;如果图像加载失败,则拒绝。
Name Type Description
options object optional 具有以下属性的对象。
Name Type Default Description
preferBlob boolean false optional 如果为真,我们将通过 blob 加载图像。
preferImageBitmap boolean false optional 如果为真,图像将在获取期间解码并返回 ImageBitmap
flipY boolean false optional 如果为真,图像将在解码时垂直翻转。仅在浏览器支持 createImageBitmap 时适用。
skipColorSpaceConversion boolean false optional 如果为真,图像中的任何自定义伽马或色彩配置文件将被忽略。仅在浏览器支持 createImageBitmap 时适用。
Returns:
一个承诺,当数据加载完成时将解析为请求的数据。如果 request.throttle 为真且请求的优先级不够高,则返回 undefined。
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。返回一个承诺,一旦加载完成将解析为 JSON 对象,或者在资源加载失败时拒绝。数据是使用 XMLHttpRequest 加载的, 这意味着为了向其他来源发出请求,服务器必须启用跨源资源共享 (CORS) 头。如果未 指定,则此函数会将 'Accept: application/json,*/*;q=0.01' 添加到请求头。
Returns:
一个承诺,当数据加载完成时将解析为请求的数据。如果 request.throttle 为真且请求的优先级不够高,则返回 undefined。
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:
一个承诺,当数据加载完成时将解析为请求的数据。如果 request.throttle 为真且请求的优先级不够高,则返回 undefined。
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

异步加载给定资源作为文本。返回一个承诺,一旦加载完成将解析为 字符串,或者在资源加载失败时拒绝。数据是使用 XMLHttpRequest 加载的, 这意味着为了向其他来源发出请求,服务器必须启用跨源资源共享 (CORS) 头。
Returns:
一个承诺,当数据加载完成时将解析为请求的数据。如果 request.throttle 为真且请求的优先级不够高,则返回 undefined。
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。返回一个承诺,一旦加载完成将解析为 XML 文档,或者在资源加载失败时拒绝。数据是使用 XMLHttpRequest 加载的, 这意味着为了向其他来源发出请求,服务器必须启用跨源资源共享 (CORS) 头。
Returns:
一个承诺,当数据加载完成时将解析为请求的数据。如果 request.throttle 为真且请求的优先级不够高,则返回 undefined。
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

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

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 如果为真,则保留当前资源和派生资源的所有查询参数。如果为假,派生参数将替换当前资源的参数。
Returns:
从当前资源派生的资源。

getUrlComponent(query, proxy)string

返回 URL,可选包含查询字符串,并由代理处理。
Name Type Default Description
query boolean false optional 如果为真,查询字符串将被包含。
proxy boolean false optional 如果为真,则 URL 将由代理对象处理(如果已定义)。
Returns:
包含所有请求组件的 URL。
异步获取给定资源的头信息。返回一个承诺,一旦加载完成将解析为 结果,或者在资源加载失败时拒绝。数据是使用 XMLHttpRequest 加载的, 这意味着为了向其他来源发出请求,服务器必须启用跨源资源共享 (CORS) 头。
Name Type Description
options object optional 具有以下属性的对象:
Name Type Description
responseType string optional 响应的类型。控制返回的项目类型。
headers object optional 附加的 HTTP 头,将随请求发送(如果有)。
overrideMimeType string optional 覆盖服务器返回的 MIME 类型。
Returns:
一个承诺,当数据加载完成时将解析为请求的数据。如果 request.throttle 为真且请求的优先级不够高,则返回 undefined。
Example:
resource.head()
  .then(function(headers) {
      // use the data
  }).catch(function(error) {
      // an error occurred
  });
See:

options(options)Promise.<any>|undefined

异步获取给定资源的选项。返回一个承诺,一旦加载完成将解析为 结果,或者在资源加载失败时拒绝。数据是使用 XMLHttpRequest 加载的, 这意味着为了向其他来源发出请求,服务器必须启用跨源资源共享 (CORS) 头。
Name Type Description
options object optional 具有以下属性的对象:
Name Type Description
responseType string optional 响应的类型。控制返回的项目类型。
headers object optional 附加的 HTTP 头,将随请求发送(如果有)。
overrideMimeType string optional 覆盖服务器返回的 MIME 类型。
Returns:
一个承诺,当数据加载完成时将解析为请求的数据。如果 request.throttle 为真且请求的优先级不够高,则返回 undefined。
Example:
resource.options()
  .then(function(headers) {
      // use the data
  }).catch(function(error) {
      // an error occurred
  });
See:

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

异步将数据修补到给定资源。返回一个承诺,一旦加载完成将解析为 结果,或者在资源加载失败时拒绝。数据是使用 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:
一个承诺,当数据加载完成时将解析为请求的数据。如果 request.throttle 为真且请求的优先级不够高,则返回 undefined。
Example:
resource.patch(data)
  .then(function(result) {
      // use the result
  }).catch(function(error) {
      // an error occurred
  });
See:

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

异步向给定资源发送数据。返回一个承诺,一旦加载完成将解析为 结果,或者在资源加载失败时拒绝。数据是使用 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:
一个承诺,当数据加载完成时将解析为请求的数据。如果 request.throttle 为真且请求的优先级不够高,则返回 undefined。
Example:
resource.post(data)
  .then(function(result) {
      // use the result
  }).catch(function(error) {
      // an error occurred
  });
See:

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

异步向给定资源发送数据。返回一个承诺,一旦加载完成将解析为 结果,或者在资源加载失败时拒绝。数据是使用 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:
一个承诺,当数据加载完成时将解析为请求的数据。如果 request.throttle 为真且请求的优先级不够高,则返回 undefined。
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 如果为真,params 将作为默认值使用,因此只有在未定义时才会设置它们。

setTemplateValues(template, useAsDefault)

结合指定对象和现有模板值。这允许一次添加多个值, 反之则需要逐个添加到 templateValues 属性。如果一个值已经设置,它将变为一个数组,并将新值附加到其中。
Name Type Default Description
template object 模板值
useAsDefault boolean false optional 如果为真,这些值将作为默认值使用,因此只有在未定义时才会设置它们。

toString()string

重写 Object#toString,以便隐式字符串转换返回 此资源所表示的完整 URL。
Returns:
此资源所表示的 URL

Type Definitions

Cesium.Resource.ConstructorOptions

Resource 构造函数的初始化选项
Properties:
Name Type Attributes Default Description
url string 资源的 URL。
queryParameters object <optional>
一个包含查询参数的对象,这些参数将在检索资源时发送。
templateValues object <optional>
用于替换模板值的键/值对(例如 {x})。
headers object <optional>
{} 将被发送的额外 HTTP 头。
proxy Proxy <optional>
加载资源时使用的代理。
retryCallback Resource.RetryCallback <optional>
请求该资源失败时要调用的函数。如果它返回 true,则会重试请求。
retryAttempts number <optional>
0 在放弃之前应调用 retryCallback 的次数。
request Request <optional>
将被使用的 Request 对象。仅供内部使用。
parseUrl boolean <optional>
true 如果为 true,则解析 URL 以获取查询参数;否则存储未更改的 URL。

Cesium.Resource.RetryCallback(resource, error)boolean|Promise.<boolean>

返回属性值的函数。
Name Type Description
resource Resource optional 加载失败的资源。
error RequestErrorEvent optional 在加载资源过程中发生的错误。
Returns:
如果为 true 或返回一个解析为 true 的承诺,则资源将被重试。否则将返回失败。
需要帮助?获得答案的最快方法是来自社区和团队 Cesium Forum.