A resource that includes the location and any other parameters we need to retrieve it or create derived resources. It also provides the ability to retry requests.
参数名称 | 类型 | 描述信息 |
---|---|---|
options |
string | Resource.ConstructorOptions | A url or an object describing initialization options |
使用示例:
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
});
成员(属性)
static constant Cesium.Resource.DEFAULT : Resource
A resource instance initialized to the current browser location
Returns true if blobs are supported.
The file extension of the resource.
True if the Resource has request headers. This is equivalent to checking if the headers property has any keys.
Additional HTTP headers that will be sent with the request.
True if the Resource refers to a blob URI.
True if the Resource refers to a cross origin URL.
True if the Resource refers to a data URI.
A proxy to be used when loading the resource.
Query parameters appended to the url.
request : Request
A Request object that will be used. Intended for internal use only.
The number of times the retryCallback should be called before giving up.
Function to call when a request for this resource fails. If it returns true or a Promise that resolves to true, the request will be retried.
The key/value pairs used to replace template parameters in the url.
The url to the resource with template values replaced, query string appended and encoded by proxy if one was set.
方法
Creates a Resource from a URL and calls delete() on it.
参数名称 | 类型 | 描述信息 | ||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
string | object |
A url or an object with the following properties
|
返回值:
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.
Creates a Resource from a URL and calls fetch() on it.
参数名称 | 类型 | 描述信息 | ||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
string | object |
A url or an object with the following properties
|
返回值:
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.
Creates a Resource and calls fetchArrayBuffer() on it.
参数名称 | 类型 | 描述信息 | ||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
string | object |
A url or an object with the following properties
|
返回值:
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.
Creates a Resource and calls fetchBlob() on it.
参数名称 | 类型 | 描述信息 | ||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
string | object |
A url or an object with the following properties
|
返回值:
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.
Creates a Resource and calls fetchImage() on it.
参数名称 | 类型 | 描述信息 | ||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
string | object |
A url or an object with the following properties
|
返回值:
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.
Creates a Resource and calls fetchJson() on it.
参数名称 | 类型 | 描述信息 | ||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
string | object |
A url or an object with the following properties
|
返回值:
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.
Creates a Resource from a URL and calls fetchJsonp() on it.
参数名称 | 类型 | 描述信息 | ||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
string | object |
A url or an object with the following properties
|
返回值:
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.
Creates a Resource and calls fetchText() on it.
参数名称 | 类型 | 描述信息 | ||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
string | object |
A url or an object with the following properties
|
返回值:
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.
Creates a Resource and calls fetchXML() on it.
参数名称 | 类型 | 描述信息 | ||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
string | object |
A url or an object with the following properties
|
返回值:
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.
Creates a Resource from a URL and calls head() on it.
参数名称 | 类型 | 描述信息 | ||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
string | object |
A url or an object with the following properties
|
返回值:
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.
Creates a Resource from a URL and calls options() on it.
参数名称 | 类型 | 描述信息 | ||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
string | object |
A url or an object with the following properties
|
返回值:
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.
Creates a Resource from a URL and calls patch() on it.
参数名称 | 类型 | 描述信息 | ||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
object |
A url or an object with the following properties
|
返回值:
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.
Creates a Resource from a URL and calls post() on it.
参数名称 | 类型 | 描述信息 | ||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
object |
A url or an object with the following properties
|
返回值:
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.
Creates a Resource from a URL and calls put() on it.
参数名称 | 类型 | 描述信息 | ||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
object |
A url or an object with the following properties
|
返回值:
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.
Appends a forward slash to the URL.
Combines the specified object and the existing query parameters. This allows you to add many parameters at once,
as opposed to adding them one at a time to the queryParameters property.
参数名称 | 类型 | 描述信息 |
---|---|---|
params |
object | The query parameters |
clone(result) → Resource
Duplicates a Resource instance.
参数名称 | 类型 | 描述信息 |
---|---|---|
result |
Resource | 可选 The object onto which to store the result. |
返回值:
The modified result parameter or a new Resource instance if one was not provided.
Asynchronously deletes 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.
参数名称 | 类型 | 描述信息 | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
object |
可选
Object with the following properties:
|
返回值:
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.
使用示例:
resource.delete()
.then(function(body) {
// use the data
}).catch(function(error) {
// an error occurred
});
参考:
Asynchronously loads 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. It's recommended that you use
the more specific functions eg. fetchJson, fetchBlob, etc.
参数名称 | 类型 | 描述信息 | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
object |
可选
Object with the following properties:
|
返回值:
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.
使用示例:
resource.fetch()
.then(function(body) {
// use the data
}).catch(function(error) {
// an error occurred
});
参考:
Asynchronously loads the resource as raw binary data. Returns a promise that will resolve to
an ArrayBuffer 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.
返回值:
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.
使用示例:
// load a single URL asynchronously
resource.fetchArrayBuffer().then(function(arrayBuffer) {
// use the data
}).catch(function(error) {
// an error occurred
});
参考:
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.
返回值:
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.
使用示例:
// load a single URL asynchronously
resource.fetchBlob().then(function(blob) {
// use the data
}).catch(function(error) {
// an error occurred
});
参考:
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.
参数名称 | 类型 | 描述信息 | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
object |
可选
An object with the following properties.
|
返回值:
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.
使用示例:
// 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
});
参考:
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.
返回值:
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.
使用示例:
resource.fetchJson().then(function(jsonData) {
// Do something with the JSON object
}).catch(function(error) {
// an error occurred
});
参考:
Requests a resource using JSONP.
参数名称 | 类型 | 默认值 | 描述信息 |
---|---|---|---|
callbackParameterName |
string |
'callback'
|
可选 The callback parameter name that the server expects. |
返回值:
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.
使用示例:
// load a data asynchronously
resource.fetchJsonp().then(function(data) {
// use the loaded data
}).catch(function(error) {
// an error occurred
});
参考:
Asynchronously loads the given resource as text. Returns a promise that will resolve to
a String 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.
返回值:
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.
使用示例:
// 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
});
参考:
Asynchronously loads the given resource as XML. Returns a promise that will resolve to
an XML Document 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.
返回值:
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.
使用示例:
// 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
});
参考:
Returns the base path of the Resource.
参数名称 | 类型 | 默认值 | 描述信息 |
---|---|---|---|
includeQuery |
boolean |
false
|
可选 Whether or not to include the query string and fragment form the uri |
返回值:
The base URI of the resource
getDerivedResource(options) → Resource
Returns a resource relative to the current instance. All properties remain the same as the current instance unless overridden in options.
参数名称 | 类型 | 描述信息 | ||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
object |
An object with the following properties
|
返回值:
The resource derived from the current one.
Returns the url, optional with the query string and processed by a proxy.
参数名称 | 类型 | 默认值 | 描述信息 |
---|---|---|---|
query |
boolean |
false
|
可选 If true, the query string is included. |
proxy |
boolean |
false
|
可选 If true, the url is processed by the proxy object, if defined. |
返回值:
The url with all the requested components.
Asynchronously gets headers 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.
参数名称 | 类型 | 描述信息 | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
object |
可选
Object with the following properties:
|
返回值:
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.
使用示例:
resource.head()
.then(function(headers) {
// use the data
}).catch(function(error) {
// an error occurred
});
参考:
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.
参数名称 | 类型 | 描述信息 | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
object |
可选
Object with the following properties:
|
返回值:
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.
使用示例:
resource.options()
.then(function(headers) {
// use the data
}).catch(function(error) {
// an error occurred
});
参考:
Asynchronously patches data to 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.
参数名称 | 类型 | 描述信息 | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
data |
object | Data that is posted with the resource. | ||||||||||||
options |
object |
可选
Object with the following properties:
|
返回值:
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.
使用示例:
resource.patch(data)
.then(function(result) {
// use the result
}).catch(function(error) {
// an error occurred
});
参考:
Asynchronously posts data to 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.
参数名称 | 类型 | 描述信息 | |||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
data |
object | Data that is posted with the resource. | |||||||||||||||
options |
object |
可选
Object with the following properties:
|
返回值:
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.
使用示例:
resource.post(data)
.then(function(result) {
// use the result
}).catch(function(error) {
// an error occurred
});
参考:
Asynchronously puts data to 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.
参数名称 | 类型 | 描述信息 | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
data |
object | Data that is posted with the resource. | ||||||||||||
options |
object |
可选
Object with the following properties:
|
返回值:
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.
使用示例:
resource.put(data)
.then(function(result) {
// use the result
}).catch(function(error) {
// an error occurred
});
参考:
Combines the specified object and the existing query parameters. This allows you to add many parameters at once,
as opposed to adding them one at a time to the queryParameters property. If a value is already set, it will be replaced with the new value.
参数名称 | 类型 | 默认值 | 描述信息 |
---|---|---|---|
params |
object | The query parameters | |
useAsDefault |
boolean |
false
|
可选 If true the params will be used as the default values, so they will only be set if they are undefined. |
Combines the specified object and the existing template values. This allows you to add many values at once,
as opposed to adding them one at a time to the templateValues property. If a value is already set, it will become an array and the new value will be appended.
参数名称 | 类型 | 默认值 | 描述信息 |
---|---|---|---|
template |
object | The template values | |
useAsDefault |
boolean |
false
|
可选 If true the values will be used as the default values, so they will only be set if they are undefined. |
Override Object#toString so that implicit string conversion gives the
complete URL represented by this Resource.
返回值:
The URL represented by this Resource
定义的类型
Initialization options for the Resource constructor
属性:
属性名称 | 类型 | 可选 | 默认值 | 描述信息 |
---|---|---|---|---|
url |
string | The url of the resource. | ||
queryParameters |
object |
<可选> |
An object containing query parameters that will be sent when retrieving the resource. | |
templateValues |
object |
<可选> |
Key/Value pairs that are used to replace template values (eg. {x}). | |
headers |
object |
<可选> |
{} | Additional HTTP headers that will be sent. |
proxy |
Proxy |
<可选> |
A proxy to be used when loading the resource. | |
retryCallback |
Resource.RetryCallback |
<可选> |
The Function to call when a request for this resource fails. If it returns true, the request will be retried. | |
retryAttempts |
number |
<可选> |
0 | The number of times the retryCallback should be called before giving up. |
request |
Request |
<可选> |
A Request object that will be used. Intended for internal use only. | |
parseUrl |
boolean |
<可选> |
true | If true, parse the url for query parameters; otherwise store the url without change |
A function that returns the value of the property.
参数名称 | 类型 | 描述信息 |
---|---|---|
resource |
Resource | 可选 The resource that failed to load. |
error |
RequestErrorEvent | 可选 The error that occurred during the loading of the resource. |
返回值:
If true or a promise that resolved to true, the resource will be retried. Otherwise the failure will be returned.