Skip to content

Commit

Permalink
Merge pull request #8173 from AnalyticalGraphicsInc/datasource-model-…
Browse files Browse the repository at this point in the history
…credits

Added credits for DataSources and Model
  • Loading branch information
Hannah authored Sep 20, 2019
2 parents 12f2bf1 + 2b14a44 commit 5a41994
Show file tree
Hide file tree
Showing 11 changed files with 212 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Change Log
* Added `Matrix3.getRotation` to get the rotational component of a matrix with scaling removed. [#8182](https://github.com/AnalyticalGraphicsInc/cesium/pull/8182)
* Added ability to create partial ellipsoids using both the Entity API and CZML. New ellipsoid geometry properties: `innerRadii`, `minimumClock`, `maximumClock`, `minimumCone`, and `maximumCone`. This affects both `EllipsoidGeometry` and `EllipsoidOutlineGeometry`. See the updated [Sandcastle example](https://cesiumjs.org/Cesium/Apps/Sandcastle/?src=Partial%20Ellipsoids.html&label=Geometries). [#5995](https://github.com/AnalyticalGraphicsInc/cesium/pull/5995)
* Added `TileMapResourceImageryProvider` and `OpenStreetMapImageryProvider` classes to improve API consistency: [#4812](https://github.com/AnalyticalGraphicsInc/cesium/issues/4812)
* Added `credit` parameter to `CzmlDataSource`, `GeoJsonDataSource`, `KmlDataSource` and `Model`. [#8173](https://github.com/AnalyticalGraphicsInc/cesium/pull/8173)

##### Fixes :wrench:
* `Camera.flyTo` flies to the correct location in 2D when the destination crosses the international date line [#7909](https://github.com/AnalyticalGraphicsInc/cesium/pull/7909)
Expand Down
33 changes: 33 additions & 0 deletions Source/DataSources/CzmlDataSource.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ define([
'../Core/Color',
'../Core/CornerType',
'../Core/createGuid',
'../Core/Credit',
'../Core/defaultValue',
'../Core/defined',
'../Core/defineProperties',
Expand Down Expand Up @@ -102,6 +103,7 @@ define([
Color,
CornerType,
createGuid,
Credit,
defaultValue,
defined,
defineProperties,
Expand Down Expand Up @@ -2155,11 +2157,28 @@ define([
var promise = czml;
var sourceUri = options.sourceUri;

// User specified credit
var credit = options.credit;
if (typeof credit === 'string') {
credit = new Credit(credit);
}
dataSource._credit = credit;

// If the czml is a URL
if (typeof czml === 'string' || (czml instanceof Resource)) {
czml = Resource.createIfNeeded(czml);
promise = czml.fetchJson();
sourceUri = defaultValue(sourceUri, czml.clone());

// Add resource credits to our list of credits to display
var resourceCredits = dataSource._resourceCredits;
var credits = czml.credits;
if (defined(credits)) {
var length = credits.length;
for (var i = 0; i < length; i++) {
resourceCredits.push(credits[i]);
}
}
}

sourceUri = Resource.createIfNeeded(sourceUri);
Expand Down Expand Up @@ -2232,6 +2251,8 @@ define([
this._version = undefined;
this._entityCollection = new EntityCollection(this);
this._entityCluster = new EntityCluster();
this._credit = undefined;
this._resourceCredits = [];
}

/**
Expand All @@ -2240,6 +2261,7 @@ define([
* @param {Resource|String|Object} czml A url or CZML object to be processed.
* @param {Object} [options] An object with the following properties:
* @param {Resource|String} [options.sourceUri] Overrides the url to use for resolving relative links.
* @param {Credit|String} [options.credit] A credit for the data source, which is displayed on the canvas.
* @returns {Promise.<CzmlDataSource>} A promise that resolves to the new instance once the data is processed.
*/
CzmlDataSource.load = function(czml, options) {
Expand Down Expand Up @@ -2351,6 +2373,16 @@ define([
//>>includeEnd('debug');
this._entityCluster = value;
}
},
/**
* Gets the credit that will be displayed for the data source
* @memberof CzmlDataSource.prototype
* @type {Credit}
*/
credit : {
get : function() {
return this._credit;
}
}
});

Expand Down Expand Up @@ -2400,6 +2432,7 @@ define([
* @param {Resource|String|Object} czml A url or CZML object to be processed.
* @param {Object} [options] An object with the following properties:
* @param {String} [options.sourceUri] Overrides the url to use for resolving relative links.
* @param {Credit|String} [options.credit] A credit for the data source, which is displayed on the canvas.
* @returns {Promise.<CzmlDataSource>} A promise that resolves to this instances once the data is processed.
*/
CzmlDataSource.prototype.load = function(czml, options) {
Expand Down
25 changes: 25 additions & 0 deletions Source/DataSources/DataSourceDisplay.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ define([
this._eventHelper.add(dataSourceCollection.dataSourceAdded, this._onDataSourceAdded, this);
this._eventHelper.add(dataSourceCollection.dataSourceRemoved, this._onDataSourceRemoved, this);
this._eventHelper.add(dataSourceCollection.dataSourceMoved, this._onDataSourceMoved, this);
this._eventHelper.add(scene.postRender, this._postRender, this);

this._dataSourceCollection = dataSourceCollection;
this._scene = scene;
Expand Down Expand Up @@ -284,6 +285,30 @@ define([
return result;
};

DataSourceDisplay.prototype._postRender = function() {
// Adds credits for all datasources
var frameState = this._scene.frameState;
var dataSources = this._dataSourceCollection;
var length = dataSources.length;
for (var i = 0; i < length; i++) {
var dataSource = dataSources.get(i);

var credit = dataSource.credit;
if (defined(credit)) {
frameState.creditDisplay.addCredit(credit);
}

// Credits from the resource that the user can't remove
var credits = dataSource._resourceCredits;
if (defined(credits)) {
var creditCount = credits.length;
for (var c = 0; c < creditCount; c++) {
frameState.creditDisplay.addCredit(credits[c]);
}
}
}
};

var getBoundingSphereArrayScratch = [];
var getBoundingSphereBoundingSphereScratch = new BoundingSphere();

Expand Down
37 changes: 34 additions & 3 deletions Source/DataSources/GeoJsonDataSource.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ define([
'../Core/Cartesian3',
'../Core/Color',
'../Core/createGuid',
'../Core/Credit',
'../Core/defaultValue',
'../Core/defined',
'../Core/defineProperties',
Expand Down Expand Up @@ -32,6 +33,7 @@ define([
Cartesian3,
Color,
createGuid,
Credit,
defaultValue,
defined,
defineProperties,
Expand Down Expand Up @@ -511,6 +513,8 @@ define([
this._promises = [];
this._pinBuilder = new PinBuilder();
this._entityCluster = new EntityCluster();
this._credit = undefined;
this._resourceCredits = [];
}

/**
Expand All @@ -526,6 +530,7 @@ define([
* @param {Number} [options.strokeWidth=GeoJsonDataSource.strokeWidth] The default width of polylines and polygon outlines.
* @param {Color} [options.fill=GeoJsonDataSource.fill] The default color for polygon interiors.
* @param {Boolean} [options.clampToGround=GeoJsonDataSource.clampToGround] true if we want the geometry features (polygons or linestrings) clamped to the ground.
* @param {Credit|String} [options.credit] A credit for the data source, which is displayed on the canvas.
*
* @returns {Promise.<GeoJsonDataSource>} A promise that will resolve when the data is loaded.
*/
Expand Down Expand Up @@ -786,6 +791,16 @@ define([
//>>includeEnd('debug');
this._entityCluster = value;
}
},
/**
* Gets the credit that will be displayed for the data source
* @memberof GeoJsonDataSource.prototype
* @type {Credit}
*/
credit : {
get : function() {
return this._credit;
}
}
});

Expand All @@ -804,6 +819,7 @@ define([
* @param {Number} [options.strokeWidth=GeoJsonDataSource.strokeWidth] The default width of polylines and polygon outlines.
* @param {Color} [options.fill=GeoJsonDataSource.fill] The default color for polygon interiors.
* @param {Boolean} [options.clampToGround=GeoJsonDataSource.clampToGround] true if we want the features clamped to the ground.
* @param {Credit|String} [options.credit] A credit for the data source, which is displayed on the canvas.
*
* @returns {Promise.<GeoJsonDataSource>} a promise that will resolve when the GeoJSON is loaded.
*/
Expand All @@ -815,16 +831,31 @@ define([
//>>includeEnd('debug');

DataSource.setLoading(this, true);
options = defaultValue(options, defaultValue.EMPTY_OBJECT);

// User specified credit
var credit = options.credit;
if (typeof credit === 'string') {
credit = new Credit(credit);
}
this._credit = credit;

var promise = data;
options = defaultValue(options, defaultValue.EMPTY_OBJECT);
var sourceUri = options.sourceUri;
if (typeof data === 'string' || (data instanceof Resource)) {
data = Resource.createIfNeeded(data);

promise = data.fetchJson();

sourceUri = defaultValue(sourceUri, data.getUrlComponent());

// Add resource credits to our list of credits to display
var resourceCredits = this._resourceCredits;
var credits = data.credits;
if (defined(credits)) {
var length = credits.length;
for (var i = 0; i < length; i++) {
resourceCredits.push(credits[i]);
}
}
}

options = {
Expand Down
34 changes: 34 additions & 0 deletions Source/DataSources/KmlDataSource.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ define([
'../Core/ClockStep',
'../Core/Color',
'../Core/createGuid',
'../Core/Credit',
'../Core/defaultValue',
'../Core/defined',
'../Core/defineProperties',
Expand Down Expand Up @@ -75,6 +76,7 @@ define([
ClockStep,
Color,
createGuid,
Credit,
defaultValue,
defined,
defineProperties,
Expand Down Expand Up @@ -2392,6 +2394,16 @@ define([
data = Resource.createIfNeeded(data);
promise = data.fetchBlob();
sourceUri = defaultValue(sourceUri, data.clone());

// Add resource credits to our list of credits to display
var resourceCredits = dataSource._resourceCredits;
var credits = data.credits;
if (defined(credits)) {
var length = credits.length;
for (var i = 0; i < length; i++) {
resourceCredits.push(credits[i]);
}
}
} else {
sourceUri = defaultValue(sourceUri, Resource.DEFAULT.clone());
}
Expand Down Expand Up @@ -2473,6 +2485,7 @@ define([
* @param {Camera} options.camera The camera that is used for viewRefreshModes and sending camera properties to network links.
* @param {Canvas} options.canvas The canvas that is used for sending viewer properties to network links.
* @param {Ellipsoid} [options.ellipsoid=Ellipsoid.WGS84] The global ellipsoid used for geographical calculations.
* @param {Credit|String} [options.credit] A credit for the data source, which is displayed on the canvas.
*
* @see {@link http://www.opengeospatial.org/standards/kml/|Open Geospatial Consortium KML Standard}
* @see {@link https://developers.google.com/kml/|Google KML Documentation}
Expand Down Expand Up @@ -2526,6 +2539,16 @@ define([
};

this._ellipsoid = defaultValue(options.ellipsoid, Ellipsoid.WGS84);

// User specified credit
var credit = options.credit;
if (typeof credit === 'string') {
credit = new Credit(credit);
}
this._credit = credit;

// Create a list of Credit's from the resource that the user can't remove
this._resourceCredits = [];
}

/**
Expand All @@ -2538,6 +2561,7 @@ define([
* @param {String} [options.sourceUri] Overrides the url to use for resolving relative links and other KML network features.
* @param {Boolean} [options.clampToGround=false] true if we want the geometry features (Polygons, LineStrings and LinearRings) clamped to the ground.
* @param {Ellipsoid} [options.ellipsoid=Ellipsoid.WGS84] The global ellipsoid used for geographical calculations.
* @param {Credit|String} [options.credit] A credit for the data source, which is displayed on the canvas.
*
* @returns {Promise.<KmlDataSource>} A promise that will resolve to a new KmlDataSource instance once the KML is loaded.
*/
Expand Down Expand Up @@ -2679,6 +2703,16 @@ define([
//>>includeEnd('debug');
this._entityCluster = value;
}
},
/**
* Gets the credit that will be displayed for the data source
* @memberof KmlDataSource.prototype
* @type {Credit}
*/
credit : {
get : function() {
return this._credit;
}
}
});

Expand Down
Loading

0 comments on commit 5a41994

Please sign in to comment.