Skip to content

Commit

Permalink
Merge pull request #6138 from AnalyticalGraphicsInc/load-functions-in…
Browse files Browse the repository at this point in the history
…to-resource

Moved all low level load functions into Resource
  • Loading branch information
mramato authored Jan 31, 2018
2 parents 6d7b078 + b6378de commit 87716cd
Show file tree
Hide file tree
Showing 54 changed files with 1,495 additions and 815 deletions.
16 changes: 6 additions & 10 deletions Apps/Sandcastle/CesiumSandcastle.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ require({
'Sandcastle/LinkButton',
'Source/Core/defined',
'Source/Core/getBaseUri',
'Source/Core/loadJsonp',
'Source/Core/loadWithXhr',
'Source/Core/Resource',
'Source/Cesium',
'CodeMirror/addon/hint/show-hint',
'CodeMirror/addon/hint/javascript-hint',
Expand Down Expand Up @@ -96,8 +95,7 @@ require({
LinkButton,
defined,
getBaseUri,
loadJsonp,
loadWithXhr,
Resource,
Cesium
) {
'use strict';
Expand Down Expand Up @@ -747,7 +745,7 @@ require({
demoCode = scriptCode.replace(/\s/g, '');

if (defined(queryObject.gistId)) {
loadJsonp('https://api.github.com/gists/' + queryObject.gistId + '?access_token=dd8f755c2e5d9bbb26806bb93eaa2291f2047c60')
Resource.fetchJsonp('https://api.github.com/gists/' + queryObject.gistId + '?access_token=dd8f755c2e5d9bbb26806bb93eaa2291f2047c60')
.then(function(data) {
var files = data.data.files;
var code = files['Cesium-Sandcastle.js'].content;
Expand Down Expand Up @@ -957,11 +955,9 @@ require({
}
}
};
return loadWithXhr({
url : 'https://api.github.com/gists',
data : JSON.stringify(data),
method : 'POST'
}).then(function(content) {

var resource = new Resource('https://api.github.com/gists');
return resource.post(JSON.stringify(data)).then(function(content) {
sandcastleUrl = getBaseUri(window.location.href) + '?src=Hello%20World.html&label=Showcases&gist=' + JSON.parse(content).id;
textArea.value = sandcastleUrl;
textArea.select();
Expand Down
4 changes: 2 additions & 2 deletions Apps/Sandcastle/gallery/Billboards.html
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,8 @@
function offsetByDistance() {
Sandcastle.declare(offsetByDistance);
Cesium.when.all([
Cesium.loadImage('../images/Cesium_Logo_overlay.png'),
Cesium.loadImage('../images/facility.gif')
Cesium.Resource.fetchImage('../images/Cesium_Logo_overlay.png'),
Cesium.Resource.fetchImage('../images/facility.gif')
],
function(images) {
// As viewer zooms closer to facility billboard,
Expand Down
2 changes: 1 addition & 1 deletion Apps/Sandcastle/gallery/Custom DataSource.html
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@
//Use 'when' to load the URL into a json object
//and then process is with the `load` function.
var that = this;
return Cesium.when(Cesium.loadJson(url), function(json) {
return Cesium.Resource.fetchJson(url).then(function(json) {
return that.load(json, url);
}).otherwise(function(error) {
//Otherwise will catch any errors or exceptions that occur
Expand Down
14 changes: 10 additions & 4 deletions Apps/Sandcastle/gallery/Custom Geocoder.html
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,16 @@
* @returns {Promise<GeocoderResult[]>}
*/
OpenStreetMapNominatimGeocoder.prototype.geocode = function (input) {
var endpoint = 'https://nominatim.openstreetmap.org/search?';
var query = 'format=json&q=' + input;
var requestString = endpoint + query;
return Cesium.loadJson(requestString)
var endpoint = 'https://nominatim.openstreetmap.org/search';
var resource = new Cesium.Resource({
url: endpoint,
queryParameters: {
format: 'json',
q: input
}
});

return resource.fetchJson()
.then(function (results) {
var bboxDegrees;
return results.map(function (resultObject) {
Expand Down
9 changes: 5 additions & 4 deletions Apps/Sandcastle/gallery/Reverse Geocoder.html
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,13 @@
var longitudeDegrees = Cesium.Math.toDegrees(cartographic.longitude);
var latitudeDegrees = Cesium.Math.toDegrees(cartographic.latitude);
var url = baseUrl + latitudeDegrees + "," +longitudeDegrees;
var promise = Cesium.loadJsonp(url, {
parameters : {
var resource = new Cesium.Resource({
url: url,
queryParameters: {
key : Cesium.BingMapsApi.getKey()
},
callbackParameterName : 'jsonp'
}
});
var promise = resource.fetchJsonp('jsonp');

promise.then(function(result) {
var resources = result.resourceSets[0].resources;
Expand Down
4 changes: 2 additions & 2 deletions Apps/Sandcastle/gallery/development/Billboards.html
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@
function offsetByDistance() {
Sandcastle.declare(offsetByDistance);
Cesium.when.all([
Cesium.loadImage('../images/Cesium_Logo_overlay.png'),
Cesium.loadImage('../images/facility.gif')
Cesium.Resource.createIfNeeded('../images/Cesium_Logo_overlay.png').fetchImage(),
Cesium.Resource.createIfNeeded('../images/facility.gif').fetchImage()
],
function(images) {
var billboards = scene.primitives.add(new Cesium.BillboardCollection());
Expand Down
5 changes: 3 additions & 2 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ Change Log
* The clock does not animate by default. Set the `shouldAnimate` option to `true` when creating the Viewer to enable animation.
* Deprecated
* For all classes/functions that can now take a `Resource` instance, all additional parameters that are part of the `Resource` class have been deprecated and will be removed in Cesium 1.44. This generally includes `proxy`, `headers` and `query` parameters.
* All low level load functions including `loadArrayBuffer`, `loadBlob`, `loadImage`, `loadJson`, `loadJsonp`, `loadText`, `loadXML` and `loadWithXhr` have been deprecated and will be removed in Cesium 1.44. Please use the equivalent `fetch` functions on the `Resource` class.
* Fixed Sandcastle for IE 11. [#6169](https://github.com/AnalyticalGraphicsInc/cesium/pull/6169)
* Major refactor of URL handling. All classes that take a url parameter, can now take a Resource or a String. This includes all imagery providers, all terrain providers, `Cesium3DTileset`, `KMLDataSource`, `CZMLDataSource`, `GeoJsonDataSource`, `Model`, `Billboard`, along with all the low level `load*()` functions.
* Major refactor of URL handling. All classes that take a url parameter, can now take a Resource or a String. This includes all imagery providers, all terrain providers, `Cesium3DTileset`, `KMLDataSource`, `CZMLDataSource`, `GeoJsonDataSource`, `Model`, and `Billboard`.
* Added `ClippingPlaneCollection.isSupported` function for checking if rendering with clipping planes is supported.
* Added new `CesiumIon` utility class for working with the Cesium ion beta API.
* Improved CZML Custom Properties sandcastle example [#6086](https://github.com/AnalyticalGraphicsInc/cesium/pull/6086)
Expand All @@ -33,7 +34,7 @@ Change Log
* Updated documentation links to reflect new locations on cesiumjs.org and cesium.com.
* Updated 'Viewer.zoomTo' and 'Viewer.flyTo' to take in Cesium3DTilesets as a target and updated sandcastle 3DTileset examples to reflect this change
* Added optional scene request render mode to reduce CPU usage. [#6065](https://github.com/AnalyticalGraphicsInc/cesium/pull/6065) and [#6107](https://github.com/AnalyticalGraphicsInc/cesium/pull/6107)
* `Scene.requestRenderMode` enables a mode which will only request new render frames on changes to the scene, or when the simulation time change exceeds `scene.maximumRenderTimeChange`.
* `Scene.requestRenderMode` enables a mode which will only request new render frames on changes to the scene, or when the simulation time change exceeds `scene.maximumRenderTimeChange`.
* `Scene.requestRender` will explicitly request a new render frame when in request render mode.
* Added `Scene.preUpdate` and `Scene.postUpdate` events that are raised before and after the scene updates respectively. The scene is always updated before executing a potential render. Continue to listen to `Scene.preRender and `Scene.postRender` events for when the scene renders a frame.
* Added `CreditDisplay.update`, which updates the credit display before a new frame is rendered.
Expand Down
4 changes: 1 addition & 3 deletions Source/Core/BingMapsGeocoderService.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ define([
'./defaultValue',
'./defined',
'./defineProperties',
'./loadJsonp',
'./Rectangle',
'./Resource'
], function(
Expand All @@ -13,7 +12,6 @@ define([
defaultValue,
defined,
defineProperties,
loadJsonp,
Rectangle,
Resource) {
'use strict';
Expand Down Expand Up @@ -96,7 +94,7 @@ define([
}
});

return loadJsonp(resource, 'jsonp').then(function(result) {
return resource.fetchJsonp('jsonp').then(function(result) {
if (result.resourceSets.length === 0) {
return [];
}
Expand Down
10 changes: 3 additions & 7 deletions Source/Core/CesiumTerrainProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ define([
'./GeographicTilingScheme',
'./HeightmapTerrainData',
'./IndexDatatype',
'./loadArrayBuffer',
'./loadJson',
'./Math',
'./OrientedBoundingBox',
'./QuantizedMeshTerrainData',
Expand All @@ -40,8 +38,6 @@ define([
GeographicTilingScheme,
HeightmapTerrainData,
IndexDatatype,
loadArrayBuffer,
loadJson,
CesiumMath,
OrientedBoundingBox,
QuantizedMeshTerrainData,
Expand Down Expand Up @@ -289,7 +285,7 @@ define([
metadataResource = lastResource.getDerivedResource({
url: 'layer.json'
});
var parentMetadata = loadJson(metadataResource);
var parentMetadata = metadataResource.fetchJson();
return when(parentMetadata, parseMetadataSuccess, parseMetadataFailure);
}

Expand Down Expand Up @@ -347,7 +343,7 @@ define([
}

function requestMetadata() {
var metadata = loadJson(metadataResource);
var metadata = metadataResource.fetchJson();
when(metadata, metadataSuccess, metadataFailure);
}

Expand Down Expand Up @@ -623,7 +619,7 @@ define([
request: request
});

var promise = loadArrayBuffer(resource);
var promise = resource.fetchArrayBuffer();

if (!defined(promise)) {
return undefined;
Expand Down
4 changes: 1 addition & 3 deletions Source/Core/EarthOrientationParameters.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ define([
'./freezeObject',
'./JulianDate',
'./LeapSecond',
'./loadJson',
'./Resource',
'./RuntimeError',
'./TimeConstants',
Expand All @@ -21,7 +20,6 @@ define([
freezeObject,
JulianDate,
LeapSecond,
loadJson,
Resource,
RuntimeError,
TimeConstants,
Expand Down Expand Up @@ -99,7 +97,7 @@ define([

// Download EOP data.
var that = this;
this._downloadPromise = when(loadJson(resource), function(eopData) {
this._downloadPromise = when(resource.fetchJson(), function(eopData) {
onDataReady(that, eopData);
}, function() {
that._dataError = 'An error occurred while retrieving the EOP data from the URL ' + resource.url + '.';
Expand Down
6 changes: 2 additions & 4 deletions Source/Core/GoogleEarthEnterpriseMetadata.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ define([
'./deprecationWarning',
'./GoogleEarthEnterpriseTileInformation',
'./isBitSet',
'./loadArrayBuffer',
'./Math',
'./Request',
'./Resource',
Expand All @@ -28,7 +27,6 @@ define([
deprecationWarning,
GoogleEarthEnterpriseTileInformation,
isBitSet,
loadArrayBuffer,
CesiumMath,
Request,
Resource,
Expand Down Expand Up @@ -326,7 +324,7 @@ define([
quadKey = defaultValue(quadKey, '');
var resource = getMetadataResource(this, quadKey, version, request);

var promise = loadArrayBuffer(resource);
var promise = resource.fetchArrayBuffer();

if (!defined(promise)) {
return undefined; // Throttled
Expand Down Expand Up @@ -509,7 +507,7 @@ define([
}
});

return loadArrayBuffer(resource)
return resource.fetchArrayBuffer()
.then(function(buf) {
var encryptedDbRootProto = dbrootParser.EncryptedDbRootProto.decode(new Uint8Array(buf));

Expand Down
4 changes: 1 addition & 3 deletions Source/Core/GoogleEarthEnterpriseTerrainProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ define([
'./GoogleEarthEnterpriseTerrainData',
'./HeightmapTerrainData',
'./JulianDate',
'./loadArrayBuffer',
'./Math',
'./Rectangle',
'./Request',
Expand All @@ -36,7 +35,6 @@ define([
GoogleEarthEnterpriseTerrainData,
HeightmapTerrainData,
JulianDate,
loadArrayBuffer,
CesiumMath,
Rectangle,
Request,
Expand Down Expand Up @@ -450,7 +448,7 @@ define([
sharedRequest = terrainRequests[q];
} else { // Create new request for terrain
sharedRequest = request;
var requestPromise = loadArrayBuffer(buildTerrainResource(this, q, terrainVersion, sharedRequest));
var requestPromise = buildTerrainResource(this, q, terrainVersion, sharedRequest).fetchArrayBuffer();

if (!defined(requestPromise)) {
return undefined; // Throttled
Expand Down
8 changes: 4 additions & 4 deletions Source/Core/Iau2006XysData.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ define([
'./defined',
'./Iau2006XysSample',
'./JulianDate',
'./loadJson',
'./Resource',
'./TimeStandard'
], function(
Expand All @@ -15,7 +14,6 @@ define([
defined,
Iau2006XysSample,
JulianDate,
loadJson,
Resource,
TimeStandard) {
'use strict';
Expand Down Expand Up @@ -246,10 +244,12 @@ define([
}
});
} else {
chunkUrl = buildModuleUrl('Assets/IAU2006_XYS/IAU2006_XYS_' + chunkIndex + '.json');
chunkUrl = new Resource({
url : buildModuleUrl('Assets/IAU2006_XYS/IAU2006_XYS_' + chunkIndex + '.json')
});
}

when(loadJson(chunkUrl), function(chunk) {
when(chunkUrl.fetchJson(), function(chunk) {
xysData._chunkDownloadsInProgress[chunkIndex] = false;

var samples = xysData._samples;
Expand Down
4 changes: 1 addition & 3 deletions Source/Core/PinBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,13 @@ define([
'./Color',
'./defined',
'./DeveloperError',
'./loadImage',
'./Resource',
'./writeTextToCanvas'
], function(
buildModuleUrl,
Color,
defined,
DeveloperError,
loadImage,
Resource,
writeTextToCanvas) {
'use strict';
Expand Down Expand Up @@ -218,7 +216,7 @@ define([
var resource = Resource.createIfNeeded(url);

//If we have an image url, load it and then stamp the pin.
var promise = loadImage(resource).then(function(image) {
var promise = resource.fetchImage().then(function(image) {
drawIcon(context2D, image, size);
cache[id] = canvas;
return canvas;
Expand Down
33 changes: 33 additions & 0 deletions Source/Core/Request.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
define([
'./defaultValue',
'./defined',
'./RequestState',
'./RequestType'
], function(
defaultValue,
defined,
RequestState,
RequestType) {
'use strict';
Expand Down Expand Up @@ -148,6 +150,37 @@ define([
this.cancelled = true;
};


/**
* Duplicates a Request instance.
*
* @param {Request} [result] The object onto which to store the result.
*
* @returns {Request} The modified result parameter or a new Resource instance if one was not provided.
*/
Request.prototype.clone = function(result) {
if (!defined(result)) {
return new Request(this);
}

result.url = this.url;
result.requestFunction = this.requestFunction;
result.cancelFunction = this.cancelFunction;
result.priorityFunction = this.priorityFunction;
result.priority = this.priority;
result.throttle = this.throttle;
result.throttleByServer = this.throttleByServer;
result.type = this.type;
result.serverKey = this.serverKey;

// These get defaulted because the cloned request hasn't been issued
result.state = this.RequestState.UNISSUED;
result.deferred = undefined;
result.cancelled = false;

return result;
};

/**
* The function that makes the actual data request.
* @callback Request~RequestCallback
Expand Down
Loading

0 comments on commit 87716cd

Please sign in to comment.