Skip to content

Commit 5a41994

Browse files
author
Hannah
authored
Merge pull request #8173 from AnalyticalGraphicsInc/datasource-model-credits
Added credits for DataSources and Model
2 parents 12f2bf1 + 2b14a44 commit 5a41994

11 files changed

+212
-7
lines changed

CHANGES.md

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Change Log
1111
* Added `Matrix3.getRotation` to get the rotational component of a matrix with scaling removed. [#8182](https://github.com/AnalyticalGraphicsInc/cesium/pull/8182)
1212
* 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)
1313
* Added `TileMapResourceImageryProvider` and `OpenStreetMapImageryProvider` classes to improve API consistency: [#4812](https://github.com/AnalyticalGraphicsInc/cesium/issues/4812)
14+
* Added `credit` parameter to `CzmlDataSource`, `GeoJsonDataSource`, `KmlDataSource` and `Model`. [#8173](https://github.com/AnalyticalGraphicsInc/cesium/pull/8173)
1415

1516
##### Fixes :wrench:
1617
* `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)

Source/DataSources/CzmlDataSource.js

+33
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ define([
99
'../Core/Color',
1010
'../Core/CornerType',
1111
'../Core/createGuid',
12+
'../Core/Credit',
1213
'../Core/defaultValue',
1314
'../Core/defined',
1415
'../Core/defineProperties',
@@ -102,6 +103,7 @@ define([
102103
Color,
103104
CornerType,
104105
createGuid,
106+
Credit,
105107
defaultValue,
106108
defined,
107109
defineProperties,
@@ -2155,11 +2157,28 @@ define([
21552157
var promise = czml;
21562158
var sourceUri = options.sourceUri;
21572159

2160+
// User specified credit
2161+
var credit = options.credit;
2162+
if (typeof credit === 'string') {
2163+
credit = new Credit(credit);
2164+
}
2165+
dataSource._credit = credit;
2166+
21582167
// If the czml is a URL
21592168
if (typeof czml === 'string' || (czml instanceof Resource)) {
21602169
czml = Resource.createIfNeeded(czml);
21612170
promise = czml.fetchJson();
21622171
sourceUri = defaultValue(sourceUri, czml.clone());
2172+
2173+
// Add resource credits to our list of credits to display
2174+
var resourceCredits = dataSource._resourceCredits;
2175+
var credits = czml.credits;
2176+
if (defined(credits)) {
2177+
var length = credits.length;
2178+
for (var i = 0; i < length; i++) {
2179+
resourceCredits.push(credits[i]);
2180+
}
2181+
}
21632182
}
21642183

21652184
sourceUri = Resource.createIfNeeded(sourceUri);
@@ -2232,6 +2251,8 @@ define([
22322251
this._version = undefined;
22332252
this._entityCollection = new EntityCollection(this);
22342253
this._entityCluster = new EntityCluster();
2254+
this._credit = undefined;
2255+
this._resourceCredits = [];
22352256
}
22362257

22372258
/**
@@ -2240,6 +2261,7 @@ define([
22402261
* @param {Resource|String|Object} czml A url or CZML object to be processed.
22412262
* @param {Object} [options] An object with the following properties:
22422263
* @param {Resource|String} [options.sourceUri] Overrides the url to use for resolving relative links.
2264+
* @param {Credit|String} [options.credit] A credit for the data source, which is displayed on the canvas.
22432265
* @returns {Promise.<CzmlDataSource>} A promise that resolves to the new instance once the data is processed.
22442266
*/
22452267
CzmlDataSource.load = function(czml, options) {
@@ -2351,6 +2373,16 @@ define([
23512373
//>>includeEnd('debug');
23522374
this._entityCluster = value;
23532375
}
2376+
},
2377+
/**
2378+
* Gets the credit that will be displayed for the data source
2379+
* @memberof CzmlDataSource.prototype
2380+
* @type {Credit}
2381+
*/
2382+
credit : {
2383+
get : function() {
2384+
return this._credit;
2385+
}
23542386
}
23552387
});
23562388

@@ -2400,6 +2432,7 @@ define([
24002432
* @param {Resource|String|Object} czml A url or CZML object to be processed.
24012433
* @param {Object} [options] An object with the following properties:
24022434
* @param {String} [options.sourceUri] Overrides the url to use for resolving relative links.
2435+
* @param {Credit|String} [options.credit] A credit for the data source, which is displayed on the canvas.
24032436
* @returns {Promise.<CzmlDataSource>} A promise that resolves to this instances once the data is processed.
24042437
*/
24052438
CzmlDataSource.prototype.load = function(czml, options) {

Source/DataSources/DataSourceDisplay.js

+25
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ define([
7373
this._eventHelper.add(dataSourceCollection.dataSourceAdded, this._onDataSourceAdded, this);
7474
this._eventHelper.add(dataSourceCollection.dataSourceRemoved, this._onDataSourceRemoved, this);
7575
this._eventHelper.add(dataSourceCollection.dataSourceMoved, this._onDataSourceMoved, this);
76+
this._eventHelper.add(scene.postRender, this._postRender, this);
7677

7778
this._dataSourceCollection = dataSourceCollection;
7879
this._scene = scene;
@@ -284,6 +285,30 @@ define([
284285
return result;
285286
};
286287

288+
DataSourceDisplay.prototype._postRender = function() {
289+
// Adds credits for all datasources
290+
var frameState = this._scene.frameState;
291+
var dataSources = this._dataSourceCollection;
292+
var length = dataSources.length;
293+
for (var i = 0; i < length; i++) {
294+
var dataSource = dataSources.get(i);
295+
296+
var credit = dataSource.credit;
297+
if (defined(credit)) {
298+
frameState.creditDisplay.addCredit(credit);
299+
}
300+
301+
// Credits from the resource that the user can't remove
302+
var credits = dataSource._resourceCredits;
303+
if (defined(credits)) {
304+
var creditCount = credits.length;
305+
for (var c = 0; c < creditCount; c++) {
306+
frameState.creditDisplay.addCredit(credits[c]);
307+
}
308+
}
309+
}
310+
};
311+
287312
var getBoundingSphereArrayScratch = [];
288313
var getBoundingSphereBoundingSphereScratch = new BoundingSphere();
289314

Source/DataSources/GeoJsonDataSource.js

+34-3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ define([
33
'../Core/Cartesian3',
44
'../Core/Color',
55
'../Core/createGuid',
6+
'../Core/Credit',
67
'../Core/defaultValue',
78
'../Core/defined',
89
'../Core/defineProperties',
@@ -32,6 +33,7 @@ define([
3233
Cartesian3,
3334
Color,
3435
createGuid,
36+
Credit,
3537
defaultValue,
3638
defined,
3739
defineProperties,
@@ -511,6 +513,8 @@ define([
511513
this._promises = [];
512514
this._pinBuilder = new PinBuilder();
513515
this._entityCluster = new EntityCluster();
516+
this._credit = undefined;
517+
this._resourceCredits = [];
514518
}
515519

516520
/**
@@ -526,6 +530,7 @@ define([
526530
* @param {Number} [options.strokeWidth=GeoJsonDataSource.strokeWidth] The default width of polylines and polygon outlines.
527531
* @param {Color} [options.fill=GeoJsonDataSource.fill] The default color for polygon interiors.
528532
* @param {Boolean} [options.clampToGround=GeoJsonDataSource.clampToGround] true if we want the geometry features (polygons or linestrings) clamped to the ground.
533+
* @param {Credit|String} [options.credit] A credit for the data source, which is displayed on the canvas.
529534
*
530535
* @returns {Promise.<GeoJsonDataSource>} A promise that will resolve when the data is loaded.
531536
*/
@@ -786,6 +791,16 @@ define([
786791
//>>includeEnd('debug');
787792
this._entityCluster = value;
788793
}
794+
},
795+
/**
796+
* Gets the credit that will be displayed for the data source
797+
* @memberof GeoJsonDataSource.prototype
798+
* @type {Credit}
799+
*/
800+
credit : {
801+
get : function() {
802+
return this._credit;
803+
}
789804
}
790805
});
791806

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

817833
DataSource.setLoading(this, true);
834+
options = defaultValue(options, defaultValue.EMPTY_OBJECT);
835+
836+
// User specified credit
837+
var credit = options.credit;
838+
if (typeof credit === 'string') {
839+
credit = new Credit(credit);
840+
}
841+
this._credit = credit;
818842

819843
var promise = data;
820-
options = defaultValue(options, defaultValue.EMPTY_OBJECT);
821844
var sourceUri = options.sourceUri;
822845
if (typeof data === 'string' || (data instanceof Resource)) {
823846
data = Resource.createIfNeeded(data);
824-
825847
promise = data.fetchJson();
826-
827848
sourceUri = defaultValue(sourceUri, data.getUrlComponent());
849+
850+
// Add resource credits to our list of credits to display
851+
var resourceCredits = this._resourceCredits;
852+
var credits = data.credits;
853+
if (defined(credits)) {
854+
var length = credits.length;
855+
for (var i = 0; i < length; i++) {
856+
resourceCredits.push(credits[i]);
857+
}
858+
}
828859
}
829860

830861
options = {

Source/DataSources/KmlDataSource.js

+34
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ define([
99
'../Core/ClockStep',
1010
'../Core/Color',
1111
'../Core/createGuid',
12+
'../Core/Credit',
1213
'../Core/defaultValue',
1314
'../Core/defined',
1415
'../Core/defineProperties',
@@ -75,6 +76,7 @@ define([
7576
ClockStep,
7677
Color,
7778
createGuid,
79+
Credit,
7880
defaultValue,
7981
defined,
8082
defineProperties,
@@ -2392,6 +2394,16 @@ define([
23922394
data = Resource.createIfNeeded(data);
23932395
promise = data.fetchBlob();
23942396
sourceUri = defaultValue(sourceUri, data.clone());
2397+
2398+
// Add resource credits to our list of credits to display
2399+
var resourceCredits = dataSource._resourceCredits;
2400+
var credits = data.credits;
2401+
if (defined(credits)) {
2402+
var length = credits.length;
2403+
for (var i = 0; i < length; i++) {
2404+
resourceCredits.push(credits[i]);
2405+
}
2406+
}
23952407
} else {
23962408
sourceUri = defaultValue(sourceUri, Resource.DEFAULT.clone());
23972409
}
@@ -2473,6 +2485,7 @@ define([
24732485
* @param {Camera} options.camera The camera that is used for viewRefreshModes and sending camera properties to network links.
24742486
* @param {Canvas} options.canvas The canvas that is used for sending viewer properties to network links.
24752487
* @param {Ellipsoid} [options.ellipsoid=Ellipsoid.WGS84] The global ellipsoid used for geographical calculations.
2488+
* @param {Credit|String} [options.credit] A credit for the data source, which is displayed on the canvas.
24762489
*
24772490
* @see {@link http://www.opengeospatial.org/standards/kml/|Open Geospatial Consortium KML Standard}
24782491
* @see {@link https://developers.google.com/kml/|Google KML Documentation}
@@ -2526,6 +2539,16 @@ define([
25262539
};
25272540

25282541
this._ellipsoid = defaultValue(options.ellipsoid, Ellipsoid.WGS84);
2542+
2543+
// User specified credit
2544+
var credit = options.credit;
2545+
if (typeof credit === 'string') {
2546+
credit = new Credit(credit);
2547+
}
2548+
this._credit = credit;
2549+
2550+
// Create a list of Credit's from the resource that the user can't remove
2551+
this._resourceCredits = [];
25292552
}
25302553

25312554
/**
@@ -2538,6 +2561,7 @@ define([
25382561
* @param {String} [options.sourceUri] Overrides the url to use for resolving relative links and other KML network features.
25392562
* @param {Boolean} [options.clampToGround=false] true if we want the geometry features (Polygons, LineStrings and LinearRings) clamped to the ground.
25402563
* @param {Ellipsoid} [options.ellipsoid=Ellipsoid.WGS84] The global ellipsoid used for geographical calculations.
2564+
* @param {Credit|String} [options.credit] A credit for the data source, which is displayed on the canvas.
25412565
*
25422566
* @returns {Promise.<KmlDataSource>} A promise that will resolve to a new KmlDataSource instance once the KML is loaded.
25432567
*/
@@ -2679,6 +2703,16 @@ define([
26792703
//>>includeEnd('debug');
26802704
this._entityCluster = value;
26812705
}
2706+
},
2707+
/**
2708+
* Gets the credit that will be displayed for the data source
2709+
* @memberof KmlDataSource.prototype
2710+
* @type {Credit}
2711+
*/
2712+
credit : {
2713+
get : function() {
2714+
return this._credit;
2715+
}
26822716
}
26832717
});
26842718

0 commit comments

Comments
 (0)