包括位置和我们需要的任何其他参数的资源,以获取或创建衍生资源。 它还提供了重试请求的能力.
| 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,则返回真值 .
资源的文件扩展名 .
如果资源有请求信头, 则为真 。 这相当于检查信头属性是否有密钥 .
Additional HTTP headers that will be sent with the request.
True if the Resource refers to a blob URI.
如果资源指的是一个交叉来源 URL .
True if the Resource refers to a data URI.
proxy : Proxy
装入资源时要使用的代理 .
Url 所附查询参数.
request : Request
将使用的请求对象。 仅供内部使用.
重试Callback在放弃前应该呼叫的次数.
当请求此资源失败时调用函数 。 如果它返回真,或者一个 Promise 确定为真,则请求会被重审.
URL中用于替换模板参数的密钥/值对.
使用模板值替换的 URL 到资源, 查询字符串 附加, 如果设置了 .
Methods
Creates a Resource from a URL and calls delete() on it.
| Name | Type | Description | ||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
string | object |
Url 或具有以下属性的对象
|
Returns:
承诺在装入时将解决所要求的数据。 如果 NT%% 2 是真的, 且请求没有足够优先级, 返回未定义 .
Creates a Resource from a URL and calls fetch() on it.
| Name | Type | Description | ||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
string | object |
Url 或具有以下属性的对象
|
Returns:
承诺在装入时将解决所要求的数据。 如果 NT%% 2 是真的, 且请求没有足够优先级, 返回未定义 .
创建资源并调用其中的抓取ArrayBuffer () .
| Name | Type | Description | ||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
string | object |
Url 或具有以下属性的对象
|
Returns:
承诺在装入时将解决所要求的数据。 如果 NT%% 2 是真的, 且请求没有足够优先级, 返回未定义 .
创建资源并调用其中的获取Blob( ) .
| Name | Type | Description | ||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
string | object |
Url 或具有以下属性的对象
|
Returns:
承诺在装入时将解决所要求的数据。 如果 NT%% 2 是真的, 且请求没有足够优先级, 返回未定义 .
Creates a Resource and calls fetchImage() on it.
| Name | Type | Description | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
string | object |
Url 或具有以下属性的对象
|
Returns:
承诺在装入时将解决所要求的数据。 如果 NT%% 2 是真的, 且请求没有足够优先级, 返回未定义 .
创建资源并调用 Json () .
| Name | Type | Description | ||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
string | object |
Url 或具有以下属性的对象
|
Returns:
承诺在装入时将解决所要求的数据。 如果 NT%% 2 是真的, 且请求没有足够优先级, 返回未定义 .
Creates a Resource from a URL and calls fetchJsonp() on it.
| Name | Type | Description | ||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
string | object |
Url 或具有以下属性的对象
|
Returns:
承诺在装入时将解决所要求的数据。 如果 NT%% 2 是真的, 且请求没有足够优先级, 返回未定义 .
创建资源, 并调用其中的获取Text( ) .
| Name | Type | Description | ||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
string | object |
Url 或具有以下属性的对象
|
Returns:
承诺在装入时将解决所要求的数据。 如果 NT%% 2 是真的, 且请求没有足够优先级, 返回未定义 .
在其上创建资源并调用获取 XML () .
| Name | Type | Description | ||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
string | object |
Url 或具有以下属性的对象
|
Returns:
承诺在装入时将解决所要求的数据。 如果 NT%% 2 是真的, 且请求没有足够优先级, 返回未定义 .
Creates a Resource from a URL and calls head() on it.
| Name | Type | Description | ||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
string | object |
Url 或具有以下属性的对象
|
Returns:
承诺在装入时将解决所要求的数据。 如果 NT%% 2 是真的, 且请求没有足够优先级, 返回未定义 .
Creates a Resource from a URL and calls options() on it.
| Name | Type | Description | ||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
string | object |
Url 或具有以下属性的对象
|
Returns:
承诺在装入时将解决所要求的数据。 如果 NT%% 2 是真的, 且请求没有足够优先级, 返回未定义 .
Creates a Resource from a URL and calls patch() on it.
| Name | Type | Description | ||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
object |
Url 或具有以下属性的对象
|
Returns:
承诺在装入时将解决所要求的数据。 如果 NT%% 2 是真的, 且请求没有足够优先级, 返回未定义 .
Creates a Resource from a URL and calls post() on it.
| Name | Type | Description | ||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
object |
Url 或具有以下属性的对象
|
Returns:
承诺在装入时将解决所要求的数据。 如果 NT%% 2 是真的, 且请求没有足够优先级, 返回未定义 .
Creates a Resource from a URL and calls put() on it.
| Name | Type | Description | ||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
object |
Url 或具有以下属性的对象
|
Returns:
承诺在装入时将解决所要求的数据。 如果 NT%% 2 是真的, 且请求没有足够优先级, 返回未定义 .
Appends a forward slash to the URL.
合并指定的对象和现有的查询参数。 这使得您可以同时添加许多参数,
而不是在查询Parameters 属性中一次添加一个.
| Name | Type | Description |
|---|---|---|
params |
object | 查询参数 |
clone(result) → Resource
复制资源实例.
| Name | Type | Description |
|---|---|---|
result |
Resource | optional 存储结果的对象 . |
Returns:
未提供修改的结果参数或新资源实例 .
同步删除给定的资源。 返回一个承诺,决心
生成结果,或者如果资源未加载,则拒绝。 数据已装入
使用 XMLHttp 请求,这意味着为了向另一个来源提出请求,
服务器必须启用 Cross-Origin 资源共享( CORS ) 信头 .
| Name | Type | Description | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
object |
optional
下列属性的对象 :
|
Returns:
承诺在装入时将解决所要求的数据。 如果 NT%% 2 是真的, 且请求没有足够优先级, 返回未定义 .
Example:
resource.delete()
.then(function(body) {
// use the data
}).catch(function(error) {
// an error occurred
});
See:
同步加载给定资源 。 返回一个承诺,决心
生成结果,或者如果资源未加载,则拒绝。 数据已装入
使用 XMLHttp 请求,这意味着为了向另一个来源提出请求,
服务器必须启用 Cross-Origin 资源共享( CORS ) 信头 。 建议您使用
更具体的函数,例如抓Json、抓Blob等.
| Name | Type | Description | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
object |
optional
下列属性的对象 :
|
Returns:
承诺在装入时将解决所要求的数据。 如果 NT%% 2 是真的, 且请求没有足够优先级, 返回未定义 .
Example:
resource.fetch()
.then(function(body) {
// use the data
}).catch(function(error) {
// an error occurred
});
See:
同步加载资源为原始二进制数据. 返回一个承诺,决心
a 矩阵缓冲器已装入,如果资源未装入,则拒绝。 数据已装入
使用 XMLHttp 请求,这意味着为了向另一个来源提出请求,
服务器必须启用 Cross-Origin 资源共享( CORS ) 信头 .
Returns:
承诺在装入时将解决所要求的数据。 如果 NT%% 2 是真的, 且请求没有足够优先级, 返回未定义 .
Example:
// load a single URL asynchronously
resource.fetchArrayBuffer().then(function(arrayBuffer) {
// use the data
}).catch(function(error) {
// an error occurred
});
See:
同步加载给定的资源为 blob 。 返回一个承诺,决心
a Blob 已装入,如果资源未装入,则拒绝。 数据已装入
使用 XMLHttp 请求,这意味着为了向另一个来源提出请求,
服务器必须启用 Cross-Origin 资源共享( CORS ) 信头 .
Returns:
承诺在装入时将解决所要求的数据。 如果 NT%% 2 是真的, 且请求没有足够优先级, 返回未定义 .
Example:
// load a single URL asynchronously
resource.fetchBlob().then(function(blob) {
// use the data
}).catch(function(error) {
// an error occurred
});
See:
同步加载给定的图像资源 。 返回一个承诺,决心
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
具有下列属性的对象.
|
Returns:
承诺在装入时将解决所要求的数据。 如果 NT%% 2 是真的, 且请求没有足够优先级, 返回未定义 .
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 . 返回承诺,决心
a JSON object once loaded, or reject if the resource failed to load. The data is loaded
使用 XMLHttp 请求,这意味着为了向另一个来源提出请求,
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:
承诺在装入时将解决所要求的数据。 如果 NT%% 2 是真的, 且请求没有足够优先级, 返回未定义 .
Example:
resource.fetchJson().then(function(jsonData) {
// Do something with the JSON object
}).catch(function(error) {
// an error occurred
});
See:
请使用 NT 0 请求资源 .
| Name | Type | Default | Description |
|---|---|---|---|
callbackParameterName |
string |
'召回'
|
optional 服务器所期望的召回参数名称 . |
Returns:
承诺在装入时将解决所要求的数据。 如果 NT%% 2 是真的, 且请求没有足够优先级, 返回未定义 .
Example:
// load a data asynchronously
resource.fetchJsonp().then(function(data) {
// use the loaded data
}).catch(function(error) {
// an error occurred
});
See:
同步加载给定的资源为文本 。 返回一个承诺,决心
a 字符串已装入,如果资源未装入,则拒绝。 数据已装入
使用 XMLHttp 请求,这意味着为了向另一个来源提出请求,
服务器必须启用 Cross-Origin 资源共享( CORS ) 信头 .
Returns:
承诺在装入时将解决所要求的数据。 如果 NT%% 2 是真的, 且请求没有足够优先级, 返回未定义 .
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 . 返回承诺,决心
an XML Document once loaded, or reject if the resource failed to load. The data is loaded
使用 XMLHttp 请求,这意味着为了向另一个来源提出请求,
服务器必须启用 Cross-Origin 资源共享( CORS ) 信头 .
Returns:
承诺在装入时将解决所要求的数据。 如果 NT%% 2 是真的, 且请求没有足够优先级, 返回未定义 .
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 |
虚假
|
optional 是否包含查询字符串和片段构成uri |
Returns:
资源基数 NT% 0
getDerivedResource(options) → Resource
返回相对于当前实例的资源。 所有属性都与当前实例相同,除非选项被推翻.
| Name | Type | Description | ||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
object |
具有下列属性的对象
|
Returns:
资源来源于当前版本.
返回 URL,可选择的查询字符串,并由代理处理.
| Name | Type | Default | Description |
|---|---|---|---|
query |
boolean |
false
|
optional If true, the query string is included. |
proxy |
boolean |
false
|
optional If true, the url is processed by the proxy object, if defined. |
Returns:
包含所有请求组件的url.
同步获得给定的资源头 。 返回一个承诺,决心
生成结果,或者如果资源未加载,则拒绝。 数据已装入
使用 XMLHttp 请求,这意味着为了向另一个来源提出请求,
服务器必须启用 Cross-Origin 资源共享( CORS ) 信头 .
| Name | Type | Description | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
object |
optional
下列属性的对象 :
|
Returns:
承诺在装入时将解决所要求的数据。 如果 NT%% 2 是真的, 且请求没有足够优先级, 返回未定义 .
Example:
resource.head()
.then(function(headers) {
// use the data
}).catch(function(error) {
// an error occurred
});
See:
同步获得给定的资源选项 。 返回一个承诺,决心
生成结果,或者如果资源未加载,则拒绝。 数据已装入
使用 XMLHttp 请求,这意味着为了向另一个来源提出请求,
服务器必须启用 Cross-Origin 资源共享( CORS ) 信头 .
| Name | Type | Description | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
object |
optional
下列属性的对象 :
|
Returns:
承诺在装入时将解决所要求的数据。 如果 NT%% 2 是真的, 且请求没有足够优先级, 返回未定义 .
Example:
resource.options()
.then(function(headers) {
// use the data
}).catch(function(error) {
// an error occurred
});
See:
同步补丁给定资源的数据 。 返回一个承诺,决心
生成结果,或者如果资源未加载,则拒绝。 数据已装入
使用 XMLHttp 请求,这意味着为了向另一个来源提出请求,
服务器必须启用 Cross-Origin 资源共享( CORS ) 信头 .
| Name | Type | Description | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
data |
object | 与资源一起发布的数据 . | ||||||||||||
options |
object |
optional
下列属性的对象 :
|
Returns:
承诺在装入时将解决所要求的数据。 如果 NT%% 2 是真的, 且请求没有足够优先级, 返回未定义 .
Example:
resource.patch(data)
.then(function(result) {
// use the result
}).catch(function(error) {
// an error occurred
});
See:
同步向给定资源发送数据 。 返回一个承诺,决心
生成结果,或者如果资源未加载,则拒绝。 数据已装入
使用 XMLHttp 请求,这意味着为了向另一个来源提出请求,
服务器必须启用 Cross-Origin 资源共享( CORS ) 信头 .
| Name | Type | Description | |||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
data |
object | 与资源一起发布的数据 . | |||||||||||||||
options |
object |
optional
下列属性的对象 :
|
Returns:
承诺在装入时将解决所要求的数据。 如果 NT%% 2 是真的, 且请求没有足够优先级, 返回未定义 .
Example:
resource.post(data)
.then(function(result) {
// use the result
}).catch(function(error) {
// an error occurred
});
See:
同步将数据输入给定资源 。 返回一个承诺,决心
生成结果,或者如果资源未加载,则拒绝。 数据已装入
使用 XMLHttp 请求,这意味着为了向另一个来源提出请求,
服务器必须启用 Cross-Origin 资源共享( CORS ) 信头 .
| Name | Type | Description | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
data |
object | 与资源一起发布的数据 . | ||||||||||||
options |
object |
optional
下列属性的对象 :
|
Returns:
承诺在装入时将解决所要求的数据。 如果 NT%% 2 是真的, 且请求没有足够优先级, 返回未定义 .
Example:
resource.put(data)
.then(function(result) {
// use the result
}).catch(function(error) {
// an error occurred
});
See:
合并指定的对象和现有的查询参数。 这使得您可以同时添加许多参数,
而不是在查询Parameters 属性中一次添加一个。 如果一个值已经设置, 它将被替换为新值 .
| Name | Type | Default | Description |
|---|---|---|---|
params |
object | 查询参数 | |
useAsDefault |
boolean |
false
|
optional If true the params will be used as the default values, so they will only be set if they are undefined. |
合并指定的对象和现有的模板值。 这使得您可以同时添加许多值,
而不是将它们一次添加到模板Values属性中。 如果一个值已经设定,它将成为数组,并将附加新的值.
| Name | Type | Default | Description |
|---|---|---|---|
template |
object | 模板值 | |
useAsDefault |
boolean |
false
|
optional If true the values will be used as the default values, so they will only be set if they are undefined. |
覆盖对象 # to String , 以使隐性字符串转换给出
complete URL represented by this Resource.
Returns:
The URL represented by this Resource
Type Definitions
资源构建器的初始化选项
Properties:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
url |
string | 资源url. | ||
queryParameters |
object |
<optional> |
包含查询参数的对象,在检索资源时会发送. | |
templateValues |
object |
<optional> |
用于替换模板值的密钥/值对(如 {x} ). | |
headers |
object |
<optional> |
{} | Additional HTTP headers that will be sent. |
proxy |
Proxy |
<optional> |
装入资源时要使用的代理 . | |
retryCallback |
Resource.RetryCallback |
<optional> |
当请求此资源失败时调用函数 。 如果它返回真实,则请求会被重审. | |
retryAttempts |
number |
<optional> |
0 | The number of times the retryCallback should be called before giving up. |
request |
Request |
<optional> |
将使用的请求对象。 仅供内部使用. | |
parseUrl |
boolean |
<optional> |
true | If true, parse the url for query parameters; otherwise store the url without change |
返回属性值的函数 .
| Name | Type | Description |
|---|---|---|
resource |
Resource | optional 无法装入的资源 . |
error |
RequestErrorEvent | optional 资源加载过程中发生的错误 . |
Returns:
如果真有或承诺成真,资源将重新审查。 否则失败将被退回.