包含位置以及检索或创建派生资源所需的其他参数的资源。它还提供重试请求的能力。
| 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
如果支持blobs则返回true。
资源的文件扩展名。
如果Resource有请求标头则为true。这等同于检查headers属性是否有任何键。
将随请求发送的额外HTTP标头。
True if the Resource refers to a blob URI.
如果Resource引用跨域URL则为true。
True if the Resource refers to a data URI.
加载资源时要使用的代理。
追加到URL的查询参数。
request : Request
将使用的Request对象。仅供内部使用。
The number of times the retryCallback should be called before giving up.
此资源请求失败时调用的函数。如果返回true或解析为true的Promise,将重试请求。
用于替换URL中模板参数的键值对。
替换模板值后、追加查询字符串并由代理编码(如果设置了代理)的资源URL。
Methods
从URL创建资源并在其上调用delete()。
| Name | Type | Description | ||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
string | object |
URL或具有下列属性的对象
|
Returns:
加载后将解析为请求数据的Promise。如果
request.throttle为true且请求优先级不够高,则返回undefined。
从URL创建资源并在其上调用fetch()。
| Name | Type | Description | ||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
string | object |
URL或具有下列属性的对象
|
Returns:
加载后将解析为请求数据的Promise。如果
request.throttle为true且请求优先级不够高,则返回undefined。
创建资源并在其上调用fetchArrayBuffer()。
| Name | Type | Description | ||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
string | object |
URL或具有下列属性的对象
|
Returns:
加载后将解析为请求数据的Promise。如果
request.throttle为true且请求优先级不够高,则返回undefined。
从URL创建资源并在其上调用patch()。
| Name | Type | Description | ||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
object |
URL或具有下列属性的对象
|
Returns:
加载后将解析为请求数据的Promise。如果
request.throttle为true且请求优先级不够高,则返回undefined。
创建资源并在其上调用fetchImage()。
| Name | Type | Description | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
string | object |
URL或具有下列属性的对象
|
Returns:
加载后将解析为请求数据的Promise。如果
request.throttle为true且请求优先级不够高,则返回undefined。
创建资源并在其上调用fetchJson()。
| Name | Type | Description | ||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
string | object |
URL或具有下列属性的对象
|
Returns:
加载后将解析为请求数据的Promise。如果
request.throttle为true且请求优先级不够高,则返回undefined。
从URL创建资源并在其上调用fetchJsonp()。
| Name | Type | Description | ||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
string | object |
URL或具有下列属性的对象
|
Returns:
加载后将解析为请求数据的Promise。如果
request.throttle为true且请求优先级不够高,则返回undefined。
创建资源并在其上调用fetchText()。
| Name | Type | Description | ||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
string | object |
URL或具有下列属性的对象
|
Returns:
加载后将解析为请求数据的Promise。如果
request.throttle为true且请求优先级不够高,则返回undefined。
创建资源并在其上调用fetchXML()。
| Name | Type | Description | ||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
string | object |
URL或具有下列属性的对象
|
Returns:
加载后将解析为请求数据的Promise。如果
request.throttle为true且请求优先级不够高,则返回undefined。
从URL创建资源并在其上调用head()。
| Name | Type | Description | ||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
string | object |
URL或具有下列属性的对象
|
Returns:
加载后将解析为请求数据的Promise。如果
request.throttle为true且请求优先级不够高,则返回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
|
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.
从URL创建资源并在其上调用put()。
| Name | Type | Description | ||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
object |
URL或具有下列属性的对象
|
Returns:
加载后将解析为请求数据的Promise。如果
request.throttle为true且请求优先级不够高,则返回undefined。
从URL创建资源并在其上调用post()。
| Name | Type | Description | ||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
string | object |
URL或具有下列属性的对象
|
Returns:
加载后将解析为请求数据的Promise。如果
request.throttle为true且请求优先级不够高,则返回undefined。
从URL创建资源并在其上调用post()。
| Name | Type | Description | ||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
object |
URL或具有下列属性的对象
|
Returns:
加载后将解析为请求数据的Promise。如果
request.throttle为true且请求优先级不够高,则返回undefined。
向URL追加正斜杠。
合并指定对象和现有查询参数。这允许您一次添加多个参数,
而不是一次添加一个参数到queryParameters属性。
| Name | Type | Description |
|---|---|---|
params |
object | 查询参数 |
clone(result) → Resource
复制资源实例。
| Name | Type | Description |
|---|---|---|
result |
Resource | optional 存储结果的对象。 |
Returns:
修改后的结果参数,如果未提供则返回新的Resource实例。
异步删除给定资源。返回一个Promise,加载后将解析为
结果,如果资源加载失败则拒绝。数据使用XMLHttpRequest加载,
这意味着要向后端发出请求,服务器必须启用跨域资源共享(CORS)标头。
| Name | Type | Description | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
object |
optional
具有下列属性的对象:
|
Returns:
加载后将解析为请求数据的Promise。如果
request.throttle为true且请求优先级不够高,则返回undefined。
Example:
resource.delete()
.then(function(body) {
// 使用数据
}).catch(function(error) {
// 发生错误
});
See:
异步加载给定资源。返回一个Promise,加载后将解析为
结果,如果资源加载失败则拒绝。数据使用XMLHttpRequest加载,
这意味着要向后端发出请求,服务器必须启用跨域资源共享(CORS)标头。建议您使用
更具体的函数,例如fetchJson、fetchBlob等。
| Name | Type | Description | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
object |
optional
具有下列属性的对象:
|
Returns:
加载后将解析为请求数据的Promise。如果
request.throttle为true且请求优先级不够高,则返回undefined。
Example:
resource.fetch()
.then(function(body) {
// 使用数据
}).catch(function(error) {
// 发生错误
});
See:
异步加载资源为原始二进制数据。返回一个Promise,加载后将解析为
ArrayBuffer,如果资源加载失败则拒绝。数据使用XMLHttpRequest加载,
这意味着要向后端发出请求,服务器必须启用跨域资源共享(CORS)标头。
Returns:
加载后将解析为请求数据的Promise。如果
request.throttle为true且请求优先级不够高,则返回undefined。
Example:
// 异步加载单个URL
resource.fetchArrayBuffer().then(function(arrayBuffer) {
// 使用数据
}).catch(function(error) {
// 发生错误
});
See:
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:
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.
|
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:
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:
使用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:
异步加载给定资源为文本。返回一个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:
异步加载给定资源为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:
返回Resource的基础路径。
| Name | Type | Default | Description |
|---|---|---|---|
includeQuery |
boolean |
false
|
optional 是否包含URI中的查询字符串和片段 |
Returns:
资源的基础URI
getDerivedResource(options) → Resource
返回相对于当前实例的资源。除非在选项中重写,否则所有属性保持与当前实例相同。
| Name | Type | Description | ||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
object |
具有下列属性的对象
|
Returns:
从当前资源派生的资源。
返回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
具有下列属性的对象:
|
Returns:
加载后将解析为请求数据的Promise。如果
request.throttle为true且请求优先级不够高,则返回undefined。
Example:
resource.head()
.then(function(headers) {
// 使用数据
}).catch(function(error) {
// 发生错误
});
See:
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:
|
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:
异步放置数据到给定资源。返回一个Promise,加载后将解析为
结果,如果资源加载失败则拒绝。数据使用XMLHttpRequest加载,
这意味着要向后端发出请求,服务器必须启用跨域资源共享(CORS)标头。
| Name | Type | Description | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
data |
object | 随资源发布的数据。 | ||||||||||||
options |
object |
optional
具有下列属性的对象:
|
Returns:
加载后将解析为请求数据的Promise。如果
request.throttle为true且请求优先级不够高,则返回undefined。
Example:
resource.put(data)
.then(function(result) {
// 使用结果
}).catch(function(error) {
// 发生错误
});
See:
异步向给定资源打补丁数据。返回一个Promise,加载后将解析为
结果,如果资源加载失败则拒绝。数据使用XMLHttpRequest加载,
这意味着要向后端发出请求,服务器必须启用跨域资源共享(CORS)标头。
| Name | Type | Description | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
data |
object | 随资源发布的数据。 | ||||||||||||
options |
object |
optional
具有下列属性的对象:
|
Returns:
加载后将解析为请求数据的Promise。如果
request.throttle为true且请求优先级不够高,则返回undefined。
Example:
resource.patch(data)
.then(function(result) {
// 使用结果
}).catch(function(error) {
// 发生错误
});
See:
异步放置数据到给定资源。返回一个Promise,加载后将解析为
结果,如果资源加载失败则拒绝。数据使用XMLHttpRequest加载,
这意味着要向后端发出请求,服务器必须启用跨域资源共享(CORS)标头。
| Name | Type | Description | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
data |
object | 随资源发布的数据。 | ||||||||||||
options |
object |
optional
具有下列属性的对象:
|
Returns:
加载后将解析为请求数据的Promise。如果
request.throttle为true且请求优先级不够高,则返回undefined。
Example:
resource.put(data)
.then(function(result) {
// 使用结果
}).catch(function(error) {
// 发生错误
});
See:
合并指定对象和现有查询参数。这允许您一次添加多个参数,
而不是一次添加一个参数到queryParameters属性。如果值已设置,它将被新值替换。
| Name | Type | Default | Description |
|---|---|---|---|
params |
object | 查询参数 | |
useAsDefault |
boolean |
false
|
optional 如果为true,参数将用作默认值,仅在未定义时设置。 |
合并指定对象和现有模板值。这允许您一次添加多个值,
而不是一次添加一个值到templateValues属性。如果值已设置,它将变成数组并追加新值。
| Name | Type | Default | Description |
|---|---|---|---|
template |
object | 模板值 | |
useAsDefault |
boolean |
false
|
optional 如果为true,值将用作默认值,仅在未定义时设置。 |
重写Object#toString,使隐式字符串转换给出此Resource表示的完整URL。
Returns:
此Resource表示的URL
Type Definitions
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 |
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.
