Resource

new Cesium.Resource(options)

包含位置以及检索或创建派生资源所需的其他参数的资源。它还提供重试请求的能力。
Name Type Description
options string | Resource.ConstructorOptions URL或描述初始化选项的对象
Example:
function refreshTokenRetryCallback(resource, error) {
  if (error.statusCode === 403) {
    // 403状态码表示应生成新令牌
    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

A resource instance initialized to the current browser location

static readonly Cesium.Resource.isBlobSupported : boolean

如果支持blobs则返回true。

readonly extension : string

资源的文件扩展名。

hasHeaders : boolean

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

isCrossOriginUrl : boolean

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

readonly queryParameters : object

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

retryAttempts : number

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

retryCallback : function

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

readonly templateValues : object

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

Methods

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

从URL创建资源并在其上调用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:
加载后将解析为请求数据的Promise。如果request.throttle为true且请求优先级不够高,则返回undefined。

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

从URL创建资源并在其上调用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:
加载后将解析为请求数据的Promise。如果request.throttle为true且请求优先级不够高,则返回undefined。

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

创建资源并在其上调用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:
加载后将解析为请求数据的Promise。如果request.throttle为true且请求优先级不够高,则返回undefined。

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

从URL创建资源并在其上调用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:
加载后将解析为请求数据的Promise。如果request.throttle为true且请求优先级不够高,则返回undefined。

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

创建资源并在其上调用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 optional 在放弃之前应调用retryCallback的次数。
request Request optional 将使用的Request对象。仅供内部使用。
preferBlob boolean false optional 如果为true,将通过blob加载图像。
preferImageBitmap boolean false optional 如果为true,图像将在获取期间解码并返回ImageBitmap
skipColorSpaceConversion boolean false optional 如果为true,图像中的任何自定义gamma或颜色配置文件将被忽略。仅当请求图像且浏览器支持createImageBitmap时适用。
Returns:
加载后将解析为请求数据的Promise。如果request.throttle为true且请求优先级不够高,则返回undefined。

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

创建资源并在其上调用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:
加载后将解析为请求数据的Promise。如果request.throttle为true且请求优先级不够高,则返回undefined。

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

从URL创建资源并在其上调用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:
加载后将解析为请求数据的Promise。如果request.throttle为true且请求优先级不够高,则返回undefined。

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

创建资源并在其上调用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:
加载后将解析为请求数据的Promise。如果request.throttle为true且请求优先级不够高,则返回undefined。

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

创建资源并在其上调用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:
加载后将解析为请求数据的Promise。如果request.throttle为true且请求优先级不够高,则返回undefined。

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

从URL创建资源并在其上调用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:
加载后将解析为请求数据的Promise。如果request.throttle为true且请求优先级不够高,则返回undefined。

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

Creates a Resource from a URL and calls options() on it.
Name Type Description
options string | object A url or an object with the following properties
Name Type Default Description
url string The url of the resource.
queryParameters object optional An object containing query parameters that will be sent when retrieving the resource.
templateValues object optional Key/Value pairs that are used to replace template values (eg. {x}).
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 a request for this resource fails. If it returns true, the request will be retried.
retryAttempts number 0 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.
responseType string optional The type of response. This controls the type of item returned.
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.

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

从URL创建资源并在其上调用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:
加载后将解析为请求数据的Promise。如果request.throttle为true且请求优先级不够高,则返回undefined。

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

从URL创建资源并在其上调用post()。
Name Type Description
options string | 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:
加载后将解析为请求数据的Promise。如果request.throttle为true且请求优先级不够高,则返回undefined。

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

从URL创建资源并在其上调用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:
加载后将解析为请求数据的Promise。如果request.throttle为true且请求优先级不够高,则返回undefined。

appendForwardSlash()

向URL追加正斜杠。

appendQueryParameters(params)

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

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。
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。
Example:
resource.fetch()
  .then(function(body) {
      // 使用数据
  }).catch(function(error) {
      // 发生错误
  });
See:

fetchArrayBuffer()Promise.<ArrayBuffer>|undefined

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

fetchText()Promise.<string>|undefined

异步加载给定资源为文本。返回一个Promise,加载后将解析为 字符串,如果资源加载失败则拒绝。数据使用XMLHttpRequest加载, 这意味着要向后端发出请求,服务器必须启用跨域资源共享(CORS)标头。
Returns:
加载后将解析为请求数据的Promise。如果request.throttle为true且请求优先级不够高,则返回undefined。
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。
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

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:
从当前资源派生的资源。

getUrlComponent(query, proxy)string

返回URL,可选包含查询字符串并由代理处理。
Name Type Default Description
query boolean false optional 如果为true,则包含查询字符串。
proxy boolean false optional 如果为true,则URL由代理对象处理(如果已定义)。
Returns:
包含所有请求组件的URL。
异步获取给定资源的标头。返回一个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。
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.
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。
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。
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。
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,参数将用作默认值,仅在未定义时设置。

setTemplateValues(template, useAsDefault)

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

toString()string

重写Object#toString,使隐式字符串转换给出此Resource表示的完整URL。
Returns:
此Resource表示的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>

A function that returns the value of the property.
Name Type Description
resource Resource optional The resource that failed to load.
error RequestErrorEvent optional The error that occurred during the loading of the resource.
Returns:
If true or a promise that resolved to true, the resource will be retried. Otherwise the failure will be returned.
Need help? The fastest way to get answers is from the community and team on the Cesium Forum.