一种资源,它包括检索它或创建派生资源所需的位置和任何其他参数。它还提供了重试请求的能力。
Name | Type | Description | ||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
String | Object | 具有以下属性的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;
})
.otherwise(function() {
return false;
});
}
return false;
}
var 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
初始化到当前浏览器位置的资源实例
如果支持blob,则返回true。
资源的文件扩展名。
如果资源具有请求标头,则为True。这相当于检查headers属性是否有任何键。
将随请求一起发送的其他HTTP标头。
如果资源引用blob URI,则为True。
如果资源引用跨源URL,则为True。
如果资源引用数据URI,则为True。
proxy : Proxy
加载资源时要使用的代理。
附加到url的查询参数。
request : Request
将使用的请求对象。仅供内部使用。
放弃前应调用retryCallback的次数。
当此资源的请求失败时调用的函数。如果返回true或承诺解析为true,则将重试请求。
用于替换url中模板参数的键/值对。
替换模板值、附加查询字符串并由代理(如果已设置)编码的资源的url。
Methods
从URL创建资源并对其调用delete()。
Name | Type | Description | ||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
String | Object | 具有以下属性的url或对象
|
Returns:
加载时将解析为请求的数据的承诺。如果
request.throttle
为真且请求的优先级不够高,则返回未定义。从URL创建资源并对其调用fetch()。
Name | Type | Description | ||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
String | Object | 具有以下属性的url或对象
|
Returns:
加载时将解析为请求的数据的承诺。如果
request.throttle
为真且请求的优先级不够高,则返回未定义。创建资源并对其调用fetchArrayBuffer()。
Name | Type | Description | ||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
String | Object | 具有以下属性的url或对象
|
Returns:
加载时将解析为请求的数据的承诺。如果
request.throttle
为真且请求的优先级不够高,则返回未定义。创建资源并对其调用fetchBlob()。
Name | Type | Description | ||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
String | Object | 具有以下属性的url或对象
|
Returns:
加载时将解析为请求的数据的承诺。如果
request.throttle
为真且请求的优先级不够高,则返回未定义。static Cesium.Resource.fetchImage(options) → Promise.<ImageBitmap>|Promise.<HTMLImageElement>|undefined
创建资源并对其调用fetchImage()。
Name | Type | Description | ||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
String | Object | 具有以下属性的url或对象
|
Returns:
加载时将解析为请求的数据的承诺。如果
request.throttle
为真且请求的优先级不够高,则返回未定义。创建资源并对其调用fetchJson()。
Name | Type | Description | ||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
String | Object | 具有以下属性的url或对象
|
Returns:
加载时将解析为请求的数据的承诺。如果
request.throttle
为真且请求的优先级不够高,则返回未定义。从URL创建资源并对其调用fetchJsonp()。
Name | Type | Description | ||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
String | Object | 具有以下属性的url或对象
|
Returns:
加载时将解析为请求的数据的承诺。如果
request.throttle
为真且请求的优先级不够高,则返回未定义。创建资源并对其调用fetchText()。
Name | Type | Description | ||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
String | Object | 具有以下属性的url或对象
|
Returns:
加载时将解析为请求的数据的承诺。如果
request.throttle
为真且请求的优先级不够高,则返回未定义。创建资源并对其调用fetchXML()。
Name | Type | Description | ||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
String | Object | 具有以下属性的url或对象
|
Returns:
加载时将解析为请求的数据的承诺。如果
request.throttle
为真且请求的优先级不够高,则返回未定义。从URL创建资源并对其调用head()。
Name | Type | Description | ||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
String | Object | 具有以下属性的url或对象
|
Returns:
加载时将解析为请求的数据的承诺。如果
request.throttle
为真且请求的优先级不够高,则返回未定义。从URL创建资源并对其调用options()。
Name | Type | Description | ||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
String | Object | 具有以下属性的url或对象
|
Returns:
加载时将解析为请求的数据的承诺。如果
request.throttle
为真且请求的优先级不够高,则返回未定义。从URL创建资源,并在其上调用patch()。
Name | Type | Description | ||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
Object | 具有以下属性的url或对象
|
Returns:
加载时将解析为请求的数据的承诺。如果
request.throttle
为真且请求的优先级不够高,则返回未定义。从URL创建资源并对其调用post()。
Name | Type | Description | ||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
Object | 具有以下属性的url或对象
|
Returns:
加载时将解析为请求的数据的承诺。如果
request.throttle
为真且请求的优先级不够高,则返回未定义。从URL创建资源并对其调用put()。
Name | Type | Description | ||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
Object | 具有以下属性的url或对象
|
Returns:
加载时将解析为请求的数据的承诺。如果
request.throttle
为真且请求的优先级不够高,则返回未定义。向URL追加正斜杠。
组合指定对象和现有查询参数。这允许您一次添加多个参数,
而不是一次一个地将它们添加到queryParameters属性中。
Name | Type | Description |
---|---|---|
params |
Object | 查询参数 |
clone(result) → Resource
复制资源实例。
Name | Type | Description |
---|---|---|
result |
Resource | optional 要将结果存储到的对象。 |
Returns:
修改后的结果参数或新的资源实例(如果未提供)。
异步删除给定资源。返回一个承诺
结果一旦加载,或拒绝如果资源加载失败。数据已加载
使用XMLHttpRequest,这意味着为了向另一个源发出请求,
服务器必须启用跨源资源共享(CORS)标头。
Name | Type | Description | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
Object | optional
具有以下属性的对象:
|
Returns:
加载时将解析为请求的数据的承诺。如果
request.throttle
为真且请求的优先级不够高,则返回未定义。Example:
resource.delete()
.then(function(body) {
// use the data
}).otherwise(function(error) {
// an error occurred
});
See:
异步加载给定资源。返回一个承诺
结果一旦加载,或拒绝如果资源加载失败。数据已加载
使用XMLHttpRequest,这意味着为了向另一个源发出请求,
服务器必须启用跨源资源共享(CORS)标头。建议您使用
更具体的函数,如fetchJson、fetchBlob等。
Name | Type | Description | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
Object | optional
具有以下属性的对象:
|
Returns:
加载时将解析为请求的数据的承诺。如果
request.throttle
为真且请求的优先级不够高,则返回未定义。Example:
resource.fetch()
.then(function(body) {
// use the data
}).otherwise(function(error) {
// an error occurred
});
See:
以原始二进制数据的形式异步加载资源。返回一个承诺
ArrayBuffer一旦加载,或在资源加载失败时拒绝。数据已加载
使用XMLHttpRequest,这意味着为了向另一个源发出请求,
服务器必须启用跨源资源共享(CORS)标头。
Returns:
加载时将解析为请求的数据的承诺。如果
request.throttle
为真且请求的优先级不够高,则返回未定义。Example:
// load a single URL asynchronously
resource.fetchArrayBuffer().then(function(arrayBuffer) {
// use the data
}).otherwise(function(error) {
// an error occurred
});
See:
以blob的形式异步加载给定资源。返回一个承诺
一个Blob一旦加载,或者在资源加载失败时拒绝。数据已加载
使用XMLHttpRequest,这意味着为了向另一个源发出请求,
服务器必须启用跨源资源共享(CORS)标头。
Returns:
加载时将解析为请求的数据的承诺。如果
request.throttle
为真且请求的优先级不够高,则返回未定义。Example:
// load a single URL asynchronously
resource.fetchBlob().then(function(blob) {
// use the data
}).otherwise(function(error) {
// an error occurred
});
See:
Name | Type | Description | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
Object | optional
具有以下属性的对象。
|
Returns:
加载时将解析为请求的数据的承诺。如果
request.throttle
为真且请求的优先级不够高,则返回未定义。Example:
// load a single image asynchronously
resource.fetchImage().then(function(image) {
// use the loaded image
}).otherwise(function(error) {
// an error occurred
});
// load several images in parallel
when.all([resource1.fetchImage(), resource2.fetchImage()]).then(function(images) {
// images is an array containing all the loaded images
});
See:
以JSON的形式异步加载给定资源。返回一个承诺
JSON对象一旦加载,或者如果资源加载失败则拒绝。数据已加载
使用XMLHttpRequest,这意味着为了向另一个源发出请求,
服务器必须启用跨源资源共享(CORS)标头。这个函数
如果没有,则将“Accept:application/json,*/*;q=0.01”添加到请求头中
已经指定。
Returns:
加载时将解析为请求的数据的承诺。如果
request.throttle
为真且请求的优先级不够高,则返回未定义。Example:
resource.fetchJson().then(function(jsonData) {
// Do something with the JSON object
}).otherwise(function(error) {
// an error occurred
});
See:
使用JSONP请求资源。
Name | Type | Default | Description |
---|---|---|---|
callbackParameterName |
String |
'callback'
|
optional 服务器需要的回调参数名称。 |
Returns:
加载时将解析为请求的数据的承诺。如果
request.throttle
为真且请求的优先级不够高,则返回未定义。Example:
// load a data asynchronously
resource.fetchJsonp().then(function(data) {
// use the loaded data
}).otherwise(function(error) {
// an error occurred
});
See:
以文本的形式异步加载给定资源。返回一个承诺
一个字符串一旦加载,或拒绝如果资源加载失败。数据已加载
使用XMLHttpRequest,这意味着为了向另一个源发出请求,
服务器必须启用跨源资源共享(CORS)标头。
Returns:
加载时将解析为请求的数据的承诺。如果
request.throttle
为真且请求的优先级不够高,则返回未定义。Example:
// load text from a URL, setting a custom header
var 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
}).otherwise(function(error) {
// an error occurred
});
See:
以XML的形式异步加载给定资源。返回一个承诺
XML文档一旦加载,或在资源加载失败时拒绝。数据已加载
使用XMLHttpRequest,这意味着为了向另一个源发出请求,
服务器必须启用跨源资源共享(CORS)标头。
Returns:
加载时将解析为请求的数据的承诺。如果
request.throttle
为真且请求的优先级不够高,则返回未定义。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
}).otherwise(function(error) {
// an error occurred
});
See:
返回资源的基路径。
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。
异步获取给定资源的标头。返回一个承诺
结果一旦加载,或拒绝如果资源加载失败。数据已加载
使用XMLHttpRequest,这意味着为了向另一个源发出请求,
服务器必须启用跨源资源共享(CORS)标头。
Name | Type | Description | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
Object | optional
具有以下属性的对象:
|
Returns:
加载时将解析为请求的数据的承诺。如果
request.throttle
为真且请求的优先级不够高,则返回未定义。Example:
resource.head()
.then(function(headers) {
// use the data
}).otherwise(function(error) {
// an error occurred
});
See:
异步获取给定资源的选项。返回一个承诺
结果一旦加载,或拒绝如果资源加载失败。数据已加载
使用XMLHttpRequest,这意味着为了向另一个源发出请求,
服务器必须启用跨源资源共享(CORS)标头。
Name | Type | Description | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
Object | optional
具有以下属性的对象:
|
Returns:
加载时将解析为请求的数据的承诺。如果
request.throttle
为真且请求的优先级不够高,则返回未定义。Example:
resource.options()
.then(function(headers) {
// use the data
}).otherwise(function(error) {
// an error occurred
});
See:
异步提供给资源修补程序。返回一个承诺
结果一旦加载,或拒绝如果资源加载失败。数据已加载
使用XMLHttpRequest,这意味着为了向另一个源发出请求,
服务器必须启用跨源资源共享(CORS)标头。
Name | Type | Description | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
data |
Object | 与资源一起过帐的数据。 | ||||||||||||
options |
Object | optional
具有以下属性的对象:
|
Returns:
加载时将解析为请求的数据的承诺。如果
request.throttle
为真且请求的优先级不够高,则返回未定义。Example:
resource.patch(data)
.then(function(result) {
// use the result
}).otherwise(function(error) {
// an error occurred
});
See:
异步地将数据发布到给定的资源。返回一个承诺
结果一旦加载,或拒绝如果资源加载失败。数据已加载
使用XMLHttpRequest,这意味着为了向另一个源发出请求,
服务器必须启用跨源资源共享(CORS)标头。
Name | Type | Description | |||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
data |
Object | 与资源一起过帐的数据。 | |||||||||||||||
options |
Object | optional
具有以下属性的对象:
|
Returns:
加载时将解析为请求的数据的承诺。如果
request.throttle
为真且请求的优先级不够高,则返回未定义。Example:
resource.post(data)
.then(function(result) {
// use the result
}).otherwise(function(error) {
// an error occurred
});
See:
异步地将数据放入给定资源。返回一个承诺
结果一旦加载,或拒绝如果资源加载失败。数据已加载
使用XMLHttpRequest,这意味着为了向另一个源发出请求,
服务器必须启用跨源资源共享(CORS)标头。
Name | Type | Description | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
data |
Object | 与资源一起过帐的数据。 | ||||||||||||
options |
Object | optional
具有以下属性的对象:
|
Returns:
加载时将解析为请求的数据的承诺。如果
request.throttle
为真且请求的优先级不够高,则返回未定义。Example:
resource.put(data)
.then(function(result) {
// use the result
}).otherwise(function(error) {
// an error occurred
});
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,以便隐式字符串转换为
此资源表示的完整URL。
Returns:
此资源表示的URL
Type Definitions
返回属性值的函数。
Name | Type | Description |
---|---|---|
resource |
Resource | optional 未能加载的资源。 |
error |
Error | optional 加载资源期间发生的错误。 |
Returns:
如果为true或某个承诺解析为true,则将重试资源。否则将返回失败。