一个资源,包括位置和我们需要获取它或创建派生资源的其他参数。它还提供重试请求的能力。
| 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
初始化为当前浏览器位置的资源实例
如果支持 blobs,则返回 true。
资源的文件扩展名。
如果资源具有请求头,则返回真。等效于检查 headers 属性是否有任何键。
将随请求发送的额外 HTTP 头。
如果资源引用的是 blob URI,则为真。
如果资源引用的是跨域 URL,则为真。
如果资源引用的是数据 URI,则为真。
加载资源时使用的代理。
附加到 URL 的查询参数。
request : Request
将被使用的 Request 对象。仅供内部使用。
在放弃之前应调用 retryCallback 的次数。
请求该资源失败时要调用的函数。如果返回 true 或返回一个解析为 true 的 Promise,则请求将被重试。
用于替换 URL 中模板参数的键/值对。
URL,替换了模板值,附加了查询字符串,并在设置代理时进行了编码。
Methods
从 URL 创建一个 Resource 并调用 delete()。
| Name | Type | Description | ||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
string | object |
URL 或具有以下属性的对象
|
Returns:
一个承诺,当数据加载完成时将解析为请求的数据。如果
request.throttle 为真且请求的优先级不够高,则返回 undefined。
从 URL 创建一个 Resource 并调用 fetch()。
| Name | Type | Description | ||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
string | object |
URL 或具有以下属性的对象
|
Returns:
一个承诺,当数据加载完成时将解析为请求的数据。如果
request.throttle 为真且请求的优先级不够高,则返回 undefined。
创建一个 Resource 并调用 fetchArrayBuffer()。
| Name | Type | Description | ||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
string | object |
URL 或具有以下属性的对象
|
Returns:
一个承诺,当数据加载完成时将解析为请求的数据。如果
request.throttle 为 true 且请求的优先级不够高,则返回 undefined。
创建一个 Resource 并调用 fetchBlob()。
| Name | Type | Description | ||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
string | object |
URL 或具有以下属性的对象
|
Returns:
一个承诺,当数据加载完成时将解析为请求的数据。如果
request.throttle 为 true 且请求的优先级不够高,则返回 undefined。
创建一个 Resource 并调用 fetchImage()。
| Name | Type | Description | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
string | object |
URL 或具有以下属性的对象
|
Returns:
一个承诺,当数据加载完成时将解析为请求的数据。如果
request.throttle 为真且请求的优先级不够高,则返回 undefined。
创建一个 Resource 并调用 fetchJson()。
| Name | Type | Description | ||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
string | object |
URL 或具有以下属性的对象
|
Returns:
一个承诺,当数据加载完成时将解析为请求的数据。如果
request.throttle 为真且请求的优先级不够高,则返回 undefined。
从 URL 创建一个 Resource 并调用 fetchJsonp()。
| Name | Type | Description | ||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
string | object |
URL 或具有以下属性的对象
|
Returns:
一个承诺,当数据加载完成时将解析为请求的数据。如果
request.throttle 为真且请求的优先级不够高,则返回 undefined。
创建一个 Resource 并调用 fetchText()。
| Name | Type | Description | ||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
string | object |
URL 或具有以下属性的对象
|
Returns:
一个承诺,当数据加载完成时将解析为请求的数据。如果
request.throttle 为真且请求的优先级不够高,则返回 undefined。
创建一个 Resource 并调用 fetchXML()。
| Name | Type | Description | ||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
string | object |
URL 或具有以下属性的对象
|
Returns:
一个承诺,当数据加载完成时将解析为请求的数据。如果
request.throttle 为真且请求的优先级不够高,则返回 undefined。
从 URL 创建一个 Resource 并调用 head()。
| Name | Type | Description | ||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
string | object |
URL 或具有以下属性的对象
|
Returns:
一个承诺,当数据加载完成时将解析为请求的数据。如果
request.throttle 为真且请求的优先级不够高,则返回 undefined。
从 URL 创建一个 Resource 并调用 options()。
| Name | Type | Description | ||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
string | object |
URL 或具有以下属性的对象
|
Returns:
一个承诺,当数据加载完成时将解析为请求的数据。如果
request.throttle 为真且请求的优先级不够高,则返回 undefined。
从 URL 创建一个 Resource 并调用 patch()。
| Name | Type | Description | ||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
object |
URL 或具有以下属性的对象
|
Returns:
一个承诺,当数据加载完成时将解析为请求的数据。如果
request.throttle 为真且请求的优先级不够高,则返回 undefined。
从 URL 创建一个 Resource 并调用 post()。
| Name | Type | Description | ||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
object |
URL 或具有以下属性的对象
|
Returns:
一个承诺,当数据加载完成时将解析为请求的数据。如果
request.throttle 为真且请求的优先级不够高,则返回 undefined。
从 URL 创建一个 Resource 并调用 put()。
| Name | Type | Description | ||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
object |
URL 或具有以下属性的对象
|
Returns:
一个承诺,当数据加载完成时将解析为请求的数据。如果
request.throttle 为真且请求的优先级不够高,则返回 undefined。
在 URL 末尾附加一个正斜杠。
结合指定对象和现有查询参数。这允许一次添加多个参数,
反之则需要逐个添加到 queryParameters 属性。
| Name | Type | Description |
|---|---|---|
params |
object | 查询参数 |
clone(result) → Resource
复制一个 Resource 实例。
| Name | Type | Description |
|---|---|---|
result |
Resource | optional 存储结果的对象。 |
Returns:
修改后的结果参数,或者如果未提供则返回一个新 Resource 实例。
异步删除给定资源。返回一个承诺,一旦加载完成将解析为
结果,或者在资源加载失败时拒绝。数据是使用 XMLHttpRequest 加载的,
这意味着为了向其他来源发出请求,服务器必须启用跨源资源共享 (CORS) 头。
| Name | Type | Description | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
object |
optional
具有以下属性的对象:
|
Returns:
一个承诺,当数据加载完成时将解析为请求的数据。如果
request.throttle 为真且请求的优先级不够高,则返回 undefined。
Example:
resource.delete()
.then(function(body) {
// use the data
}).catch(function(error) {
// an error occurred
});
See:
异步加载给定资源。返回一个承诺,一旦加载完成将解析为
结果,或者在资源加载失败时拒绝。数据是使用 XMLHttpRequest 加载的,
这意味着为了向其他来源发出请求,服务器必须启用跨源资源共享 (CORS) 头。建议使用
更具体的函数,例如 fetchJson、fetchBlob 等。
| Name | Type | Description | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
object |
optional
具有以下属性的对象:
|
Returns:
一个承诺,当数据加载完成时将解析为请求的数据。如果
request.throttle 为真且请求的优先级不够高,则返回 undefined。
Example:
resource.fetch()
.then(function(body) {
// use the data
}).catch(function(error) {
// an error occurred
});
See:
异步加载资源作为原始二进制数据。返回一个承诺,一旦加载完成将解析为
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:
异步加载给定资源作为 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:
异步加载给定的图像资源。返回一个承诺,如果
preferImageBitmap 为真且浏览器支持 createImageBitmap,将解析为一个 ImageBitmap,
否则将解析为一个 Image,一旦加载完成;如果图像加载失败,则拒绝。
| Name | Type | Description | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
object |
optional
具有以下属性的对象。
|
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:
异步加载给定资源作为 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:
使用 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:
异步加载给定资源作为文本。返回一个承诺,一旦加载完成将解析为
字符串,或者在资源加载失败时拒绝。数据是使用 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:
异步加载给定资源作为 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:
返回资源的基本路径。
| 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 如果为真,查询字符串将被包含。 |
proxy |
boolean |
false
|
optional 如果为真,则 URL 将由代理对象处理(如果已定义)。 |
Returns:
包含所有请求组件的 URL。
异步获取给定资源的头信息。返回一个承诺,一旦加载完成将解析为
结果,或者在资源加载失败时拒绝。数据是使用 XMLHttpRequest 加载的,
这意味着为了向其他来源发出请求,服务器必须启用跨源资源共享 (CORS) 头。
| Name | Type | Description | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
object |
optional
具有以下属性的对象:
|
Returns:
一个承诺,当数据加载完成时将解析为请求的数据。如果
request.throttle 为真且请求的优先级不够高,则返回 undefined。
Example:
resource.head()
.then(function(headers) {
// use the data
}).catch(function(error) {
// an error occurred
});
See:
异步获取给定资源的选项。返回一个承诺,一旦加载完成将解析为
结果,或者在资源加载失败时拒绝。数据是使用 XMLHttpRequest 加载的,
这意味着为了向其他来源发出请求,服务器必须启用跨源资源共享 (CORS) 头。
| Name | Type | Description | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
object |
optional
具有以下属性的对象:
|
Returns:
一个承诺,当数据加载完成时将解析为请求的数据。如果
request.throttle 为真且请求的优先级不够高,则返回 undefined。
Example:
resource.options()
.then(function(headers) {
// use the data
}).catch(function(error) {
// an error occurred
});
See:
异步将数据修补到给定资源。返回一个承诺,一旦加载完成将解析为
结果,或者在资源加载失败时拒绝。数据是使用 XMLHttpRequest 加载的,
这意味着为了向其他来源发出请求,服务器必须启用跨源资源共享 (CORS) 头。
| Name | Type | Description | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
data |
object | 与资源一起发送的数据。 | ||||||||||||
options |
object |
optional
具有以下属性的对象:
|
Returns:
一个承诺,当数据加载完成时将解析为请求的数据。如果
request.throttle 为真且请求的优先级不够高,则返回 undefined。
Example:
resource.patch(data)
.then(function(result) {
// use the result
}).catch(function(error) {
// an error occurred
});
See:
异步向给定资源发送数据。返回一个承诺,一旦加载完成将解析为
结果,或者在资源加载失败时拒绝。数据是使用 XMLHttpRequest 加载的,
这意味着为了向其他来源发出请求,服务器必须启用跨源资源共享 (CORS) 头。
| Name | Type | Description | |||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
data |
object | 与资源一起发送的数据。 | |||||||||||||||
options |
object |
optional
具有以下属性的对象:
|
Returns:
一个承诺,当数据加载完成时将解析为请求的数据。如果
request.throttle 为真且请求的优先级不够高,则返回 undefined。
Example:
resource.post(data)
.then(function(result) {
// use the result
}).catch(function(error) {
// an error occurred
});
See:
异步向给定资源发送数据。返回一个承诺,一旦加载完成将解析为
结果,或者在资源加载失败时拒绝。数据是使用 XMLHttpRequest 加载的,
这意味着为了向其他来源发出请求,服务器必须启用跨源资源共享 (CORS) 头。
| Name | Type | Description | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
data |
object | 与资源一起发送的数据。 | ||||||||||||
options |
object |
optional
具有以下属性的对象:
|
Returns:
一个承诺,当数据加载完成时将解析为请求的数据。如果
request.throttle 为真且请求的优先级不够高,则返回 undefined。
Example:
resource.put(data)
.then(function(result) {
// use the result
}).catch(function(error) {
// an error occurred
});
See:
结合指定对象和现有查询参数。这允许一次添加多个参数,
反之则需要逐个添加到 queryParameters 属性。如果一个值已经设置,则会被新值替换。
| Name | Type | Default | Description |
|---|---|---|---|
params |
object | 查询参数 | |
useAsDefault |
boolean |
false
|
optional 如果为真,params 将作为默认值使用,因此只有在未定义时才会设置它们。 |
结合指定对象和现有模板值。这允许一次添加多个值,
反之则需要逐个添加到 templateValues 属性。如果一个值已经设置,它将变为一个数组,并将新值附加到其中。
| Name | Type | Default | Description |
|---|---|---|---|
template |
object | 模板值 | |
useAsDefault |
boolean |
false
|
optional 如果为真,这些值将作为默认值使用,因此只有在未定义时才会设置它们。 |
重写 Object#toString,以便隐式字符串转换返回
此资源所表示的完整 URL。
Returns:
此资源所表示的 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。 |
返回属性值的函数。
| Name | Type | Description |
|---|---|---|
resource |
Resource | optional 加载失败的资源。 |
error |
RequestErrorEvent | optional 在加载资源过程中发生的错误。 |
Returns:
如果为 true 或返回一个解析为 true 的承诺,则资源将被重试。否则将返回失败。
