一个资源,其中包括位置以及我们检索它或创建派生资源所需的任何其他参数。它还提供重试请求的功能。
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
初始化为当前浏览器位置的资源实例
如果支持 blob,则返回 true。
资源的文件扩展名。
如果 Resource 具有请求标头,则为 True。这等效于检查 headers 属性是否有任何键。
将与请求一起发送的其他 HTTP 标头。
如果 Resource 引用 blob URI,则为 True。
如果 Resource 引用跨源 URL,则为 True。
如果 Resource 引用数据 URI,则为 True。
加载资源时使用的代理。
附加到 URL 的查询参数。
request : Request
将使用的 Request 对象。仅供内部使用。
在放弃之前应调用 retryCallback 的次数。
请求此资源失败时调用的函数。如果返回 true 或 Promise 解析为 true,则将重试请求。
用于替换 url 中的模板参数的键/值对。
替换了模板值的资源的 URL,附加了查询字符串,并由代理编码(如果已设置)。
Methods
从 URL 创建 Resource 并对其调用 delete()。
Name | Type | Description | ||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
string | object |
具有以下属性的 url 或对象
|
Returns:
一个 Promise,该 Promise 将在加载时解析为请求的数据。如果
request.throttle
为 true,并且请求的优先级不够高,则返回 undefined。
从 URL 创建一个 Resource 并对其调用 fetch()。
Name | Type | Description | ||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
string | object |
具有以下属性的 url 或对象
|
Returns:
一个 Promise,该 Promise 将在加载时解析为请求的数据。如果
request.throttle
为 true,并且请求的优先级不够高,则返回 undefined。
创建一个 Resource 并对其调用 fetchArrayBuffer()。
Name | Type | Description | ||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
string | object |
具有以下属性的 url 或对象
|
Returns:
一个 Promise,该 Promise 将在加载时解析为请求的数据。如果
request.throttle
为 true,并且请求的优先级不够高,则返回 undefined。
创建一个 Resource 并对其调用 fetchBlob()。
Name | Type | Description | ||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
string | object |
具有以下属性的 url 或对象
|
Returns:
一个 Promise,该 Promise 将在加载时解析为请求的数据。如果
request.throttle
为 true,并且请求的优先级不够高,则返回 undefined。
创建一个 Resource 并对其调用 fetchImage()。
Name | Type | Description | ||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
string | object |
具有以下属性的 url 或对象
|
Returns:
一个 Promise,该 Promise 将在加载时解析为请求的数据。如果
request.throttle
为 true,并且请求的优先级不够高,则返回 undefined。
创建一个 Resource 并对其调用 fetchJson()。
Name | Type | Description | ||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
string | object |
具有以下属性的 url 或对象
|
Returns:
一个 Promise,该 Promise 将在加载时解析为请求的数据。如果
request.throttle
为 true,并且请求的优先级不够高,则返回 undefined。
从 URL 创建一个 Resource 并对其调用 fetchJsonp()。
Name | Type | Description | ||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
string | object |
具有以下属性的 url 或对象
|
Returns:
一个 Promise,该 Promise 将在加载时解析为请求的数据。如果
request.throttle
为 true,并且请求的优先级不够高,则返回 undefined。
创建一个 Resource 并对其调用 fetchText()。
Name | Type | Description | ||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
string | object |
具有以下属性的 url 或对象
|
Returns:
一个 Promise,该 Promise 将在加载时解析为请求的数据。如果
request.throttle
为 true,并且请求的优先级不够高,则返回 undefined。
创建一个 Resource 并对其调用 fetchXML()。
Name | Type | Description | ||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
string | object |
具有以下属性的 url 或对象
|
Returns:
一个 Promise,该 Promise 将在加载时解析为请求的数据。如果
request.throttle
为 true,并且请求的优先级不够高,则返回 undefined。
从 URL 创建一个 Resource 并对其调用 head()。
Name | Type | Description | ||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
string | object |
具有以下属性的 url 或对象
|
Returns:
一个 Promise,该 Promise 将在加载时解析为请求的数据。如果
request.throttle
为 true,并且请求的优先级不够高,则返回 undefined。
从 URL 创建一个 Resource 并对其调用 options()。
Name | Type | Description | ||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
string | object |
具有以下属性的 url 或对象
|
Returns:
一个 Promise,该 Promise 将在加载时解析为请求的数据。如果
request.throttle
为 true,并且请求的优先级不够高,则返回 undefined。
从 URL 创建一个 Resource 并对其调用 patch()。
Name | Type | Description | ||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
object |
具有以下属性的 url 或对象
|
Returns:
一个 Promise,该 Promise 将在加载时解析为请求的数据。如果
request.throttle
为 true,并且请求的优先级不够高,则返回 undefined。
从 URL 创建一个 Resource 并对其调用 post()。
Name | Type | Description | ||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
object |
具有以下属性的 url 或对象
|
Returns:
一个 Promise,该 Promise 将在加载时解析为请求的数据。如果
request.throttle
为 true,并且请求的优先级不够高,则返回 undefined。
从 URL 创建 Resource 并对其调用 put()。
Name | Type | Description | ||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
object |
具有以下属性的 url 或对象
|
Returns:
一个 Promise,该 Promise 将在加载时解析为请求的数据。如果
request.throttle
为 true,并且请求的优先级不够高,则返回 undefined。
在 URL 后附加一个正斜杠。
组合指定的对象和现有的查询参数。这允许您一次添加多个参数。
而不是一次将它们添加到 queryParameters 属性中。
Name | Type | Description |
---|---|---|
params |
object | 查询参数 |
clone(result) → Resource
复制Resource实例。
Name | Type | Description |
---|---|---|
result |
Resource | optional 要在其上存储结果的对象。 |
Returns:
修改后的结果参数或者新的 Resource 实例(如果未提供)。
异步删除给定的资源。 返回一个 Promise,该 Promise 将解析为
加载后的结果,如果资源加载失败,则为 reject。 数据已加载
使用 XMLHttpRequest,这意味着为了向另一个源发出请求,
服务器必须启用跨域资源共享 (CORS) 标头。
Name | Type | Description | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
object |
optional
对象,具有以下属性:
|
Returns:
一个 Promise,该 Promise 将在加载时解析为请求的数据。如果
request.throttle
为 true,并且请求的优先级不够高,则返回 undefined。
Example:
resource.delete()
.then(function(body) {
// use the data
}).catch(function(error) {
// an error occurred
});
See:
异步加载给定的资源。 返回一个 Promise,该 Promise 将解析为
加载后的结果,如果资源加载失败,则为 reject。 数据已加载
使用 XMLHttpRequest,这意味着为了向另一个源发出请求,
服务器必须启用跨域资源共享 (CORS) 标头。建议您使用
更具体的功能,例如。fetchJson、fetchBlob 等。
Name | Type | Description | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
object |
optional
对象,具有以下属性:
|
Returns:
一个 Promise,该 Promise 将在加载时解析为请求的数据。如果
request.throttle
为 true,并且请求的优先级不够高,则返回 undefined。
Example:
resource.fetch()
.then(function(body) {
// use the data
}).catch(function(error) {
// an error occurred
});
See:
异步加载资源作为原始二进制数据。 返回一个 Promise,该 Promise 将解析为
加载后为 ArrayBuffer,如果资源加载失败,则为 reject。 数据已加载
使用 XMLHttpRequest,这意味着为了向另一个源发出请求,
服务器必须启用跨域资源共享 (CORS) 标头。
Returns:
一个 Promise,该 Promise 将在加载时解析为请求的数据。如果
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。 返回一个 Promise,该 Promise 将解析为
加载后为 Blob,如果资源加载失败,则为 reject。 数据已加载
使用 XMLHttpRequest,这意味着为了向另一个源发出请求,
服务器必须启用跨域资源共享 (CORS) 标头。
Returns:
一个 Promise,该 Promise 将在加载时解析为请求的数据。如果
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:
异步加载给定的图像资源。 返回一个 Promise,该 Promise 将解析为
an ImageBitmap 如果
preferImageBitmap
为 true,并且浏览器支持 createImageBitmap
或其他
Image,如果图像加载失败,则为 reject。
Name | Type | Description | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
object |
optional
具有以下属性的对象。
|
Returns:
一个 Promise,该 Promise 将在加载时解析为请求的数据。如果
request.throttle
为 true,并且请求的优先级不够高,则返回 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 格式异步加载给定资源。 返回一个 Promise,该 Promise 将解析为
JSON 对象,如果资源加载失败,则拒绝。 数据已加载
使用 XMLHttpRequest,这意味着为了向另一个源发出请求,
服务器必须启用跨域资源共享 (CORS) 标头。此功能
添加 'Accept: application/json,*/*;q=0.01' 添加到请求标头中,如果不是
已指定。
Returns:
一个 Promise,该 Promise 将在加载时解析为请求的数据。如果
request.throttle
为 true,并且请求的优先级不够高,则返回 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:
一个 Promise,该 Promise 将在加载时解析为请求的数据。如果
request.throttle
为 true,并且请求的优先级不够高,则返回 undefined。
Example:
// load a data asynchronously
resource.fetchJsonp().then(function(data) {
// use the loaded data
}).catch(function(error) {
// an error occurred
});
See:
异步加载给定的资源为文本。 返回一个 Promise,该 Promise 将解析为
一个 String,如果资源加载失败,则为 reject。 数据已加载
使用 XMLHttpRequest,这意味着为了向另一个源发出请求,
服务器必须启用跨域资源共享 (CORS) 标头。
Returns:
一个 Promise,该 Promise 将在加载时解析为请求的数据。如果
request.throttle
为 true,并且请求的优先级不够高,则返回 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 形式异步加载给定的资源。 返回一个 Promise,该 Promise 将解析为
XML 文档,如果资源加载失败,则拒绝。 数据已加载
使用 XMLHttpRequest,这意味着为了向另一个源发出请求,
服务器必须启用跨域资源共享 (CORS) 标头。
Returns:
一个 Promise,该 Promise 将在加载时解析为请求的数据。如果
request.throttle
为 true,并且请求的优先级不够高,则返回 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:
返回 Resource 的基路径。
Name | Type | Default | Description |
---|---|---|---|
includeQuery |
boolean |
false
|
optional 是否在 uri 中包含查询字符串和片段 |
Returns:
资源的基 URI
getDerivedResource(options) → Resource
返回相对于当前实例的资源。所有属性都与当前实例相同,除非在 options 中被覆盖。
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,该 Promise 将解析为
加载后的结果,如果资源加载失败,则为 reject。 数据已加载
使用 XMLHttpRequest,这意味着为了向另一个源发出请求,
服务器必须启用跨域资源共享 (CORS) 标头。
Name | Type | Description | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
object |
optional
对象,具有以下属性:
|
Returns:
一个 Promise,该 Promise 将在加载时解析为请求的数据。如果
request.throttle
为 true,并且请求的优先级不够高,则返回 undefined。
Example:
resource.head()
.then(function(headers) {
// use the data
}).catch(function(error) {
// an error occurred
});
See:
异步获取给定资源的 options。 返回一个 Promise,该 Promise 将解析为
加载后的结果,如果资源加载失败,则为 reject。 数据已加载
使用 XMLHttpRequest,这意味着为了向另一个源发出请求,
服务器必须启用跨域资源共享 (CORS) 标头。
Name | Type | Description | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
object |
optional
对象,具有以下属性:
|
Returns:
一个 Promise,该 Promise 将在加载时解析为请求的数据。如果
request.throttle
为 true,并且请求的优先级不够高,则返回 undefined。
Example:
resource.options()
.then(function(headers) {
// use the data
}).catch(function(error) {
// an error occurred
});
See:
异步将数据修补到给定资源。 返回一个 Promise,该 Promise 将解析为
加载后的结果,如果资源加载失败,则为 reject。 数据已加载
使用 XMLHttpRequest,这意味着为了向另一个源发出请求,
服务器必须启用跨域资源共享 (CORS) 标头。
Name | Type | Description | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
data |
object | 与资源一起发布的数据。 | ||||||||||||
options |
object |
optional
对象,具有以下属性:
|
Returns:
一个 Promise,该 Promise 将在加载时解析为请求的数据。如果
request.throttle
为 true,并且请求的优先级不够高,则返回 undefined。
Example:
resource.patch(data)
.then(function(result) {
// use the result
}).catch(function(error) {
// an error occurred
});
See:
异步将数据发布到给定的资源。 返回一个 Promise,该 Promise 将解析为
加载后的结果,如果资源加载失败,则为 reject。 数据已加载
使用 XMLHttpRequest,这意味着为了向另一个源发出请求,
服务器必须启用跨域资源共享 (CORS) 标头。
Name | Type | Description | |||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
data |
object | 与资源一起发布的数据。 | |||||||||||||||
options |
object |
optional
对象,具有以下属性:
|
Returns:
一个 Promise,该 Promise 将在加载时解析为请求的数据。如果
request.throttle
为 true,并且请求的优先级不够高,则返回 undefined。
Example:
resource.post(data)
.then(function(result) {
// use the result
}).catch(function(error) {
// an error occurred
});
See:
异步将数据放入给定的资源。 返回一个 Promise,该 Promise 将解析为
加载后的结果,如果资源加载失败,则为 reject。 数据已加载
使用 XMLHttpRequest,这意味着为了向另一个源发出请求,
服务器必须启用跨域资源共享 (CORS) 标头。
Name | Type | Description | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
data |
object | 与资源一起发布的数据。 | ||||||||||||
options |
object |
optional
对象,具有以下属性:
|
Returns:
一个 Promise,该 Promise 将在加载时解析为请求的数据。如果
request.throttle
为 true,并且请求的优先级不够高,则返回 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 如果为 true,则参数将用作默认值,因此只有在未定义时才会设置它们。 |
合并指定的对象和现有模板值。这允许您一次添加多个值。
而不是一次将它们添加到 templateValues 属性中。如果已设置值,它将变为数组,并附加新值。
Name | Type | Default | Description |
---|---|---|---|
template |
object | 模板值 | |
useAsDefault |
boolean |
false
|
optional 如果为 true,则值将用作默认值,因此只有在未定义时才会设置它们。 |
覆盖 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 的 Promise,则将重试资源。否则将返回失败。