Skip to content

Commit

Permalink
Merge pull request #6968 from AnalyticalGraphicsInc/fix-credits
Browse files Browse the repository at this point in the history
Fix credits for multiple viewers
  • Loading branch information
mramato authored Sep 12, 2018
2 parents 4607a19 + ad5a448 commit aa4a877
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Change Log

##### Fixes :wrench:
* Fixed an issue in the 3D Tiles traversal where empty tiles would be selected instead of their nearest loaded ancestors. [#7011](https://github.com/AnalyticalGraphicsInc/cesium/pull/7011)
* Fixed bug where credits weren't displaying correctly if more than one viewer was initialized [#6965](expect(https://github.com/AnalyticalGraphicsInc/cesium/issues/6965)

### 1.49 - 2018-09-04

Expand Down
25 changes: 21 additions & 4 deletions Source/Core/Credit.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,37 @@ define([
'../ThirdParty/purify',
'./defaultValue',
'./defined',
'./defineProperties'
'./defineProperties',
'./Check'
], function(
DOMPurify,
defaultValue,
defined,
defineProperties) {
defineProperties,
Check) {
'use strict';

var nextCreditId = 0;
var creditToId = {};

/**
* A credit contains data pertaining to how to display attributions/credits for certain content on the screen.
* @param {String} html An string representing an html code snippet (can be text only)
* @param {String} html An string representing an html code snippet
* @param {Boolean} [showOnScreen=false] If true, the credit will be visible in the main credit container. Otherwise, it will appear in a popover
*
* @alias Credit
* @constructor
*
* @exception {DeveloperError} options.text, options.imageUrl, or options.link is required.
* @exception {DeveloperError} html is required.
*
* @example
* //Create a credit with a tooltip, image and link
* var credit = new Cesium.Credit('<a href="https://cesiumjs.org/" target="_blank"><img src="/images/cesium_logo.png" title="Cesium"/></a>');
*/
function Credit(html, showOnScreen) {
//>>includeStart('debug', pragmas.debug);
Check.typeOf.string('html', html);
//>>includeEnd('debug');
var id;
var key = html;

Expand Down Expand Up @@ -150,5 +155,17 @@ define([
return credit;
};

/**
* Duplicates a Credit instance.
*
* @param {Credit} [credit] The Credit to duplicate.
* @returns {Credit} A new Credit instance that is a duplicate of the one provided. (Returns undefined if the credit is undefined)
*/
Credit.clone = function(credit) {
if (defined(credit)) {
return new Credit(credit.html, credit.showOnScreen);
}
};

return Credit;
});
4 changes: 3 additions & 1 deletion Source/Core/IonGeocoderService.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
define([
'./Check',
'./Credit',
'./defaultValue',
'./defined',
'./defineProperties',
Expand All @@ -9,6 +10,7 @@ define([
'./Resource'
], function (
Check,
Credit,
defaultValue,
defined,
defineProperties,
Expand Down Expand Up @@ -44,7 +46,7 @@ define([

var defaultTokenCredit = Ion.getDefaultTokenCredit(accessToken);
if (defined(defaultTokenCredit)) {
options.scene.frameState.creditDisplay.addDefaultCredit(defaultTokenCredit);
options.scene.frameState.creditDisplay.addDefaultCredit(Credit.clone(defaultTokenCredit));
}

var searchEndpoint = server.getDerivedResource({
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/IonResource.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ define([
var credits = endpoint.attributions.map(Credit.getIonCredit);
var defaultTokenCredit = Ion.getDefaultTokenCredit(endpointResource.queryParameters.access_token);
if (defined(defaultTokenCredit)) {
credits.push(defaultTokenCredit);
credits.push(Credit.clone(defaultTokenCredit));
}
return credits;
};
Expand Down
15 changes: 12 additions & 3 deletions Source/Scene/CreditDisplay.js
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,7 @@ define([
container.appendChild(expandLink);

appendCss();
var cesiumCredit = Credit.clone(CreditDisplay.cesiumCredit);

this._delimiter = defaultValue(delimiter, ' • ');
this._screenContainer = screenContainer;
Expand All @@ -328,12 +329,14 @@ define([
this._expandLink = expandLink;
this._expanded = false;
this._defaultCredits = [];
this._cesiumCredit = cesiumCredit;
this._previousCesiumCredit = undefined;
this._currentCesiumCredit = CreditDisplay.cesiumCredit;
this._currentCesiumCredit = cesiumCredit;
this._currentFrameCredits = {
screenCredits : new AssociativeArray(),
lightboxCredits : new AssociativeArray()
};
this._defaultCredit = undefined;

this.viewport = viewport;

Expand All @@ -357,7 +360,10 @@ define([
if (credit._isIon) {
// If this is the an ion logo credit from the ion server
// Juse use the default credit (which is identical) to avoid blinking
this._currentCesiumCredit = getDefaultCredit();
if (!defined(this._defaultCredit)) {
this._defaultCredit = Credit.clone(getDefaultCredit());
}
this._currentCesiumCredit = this._defaultCredit;
return;
}

Expand Down Expand Up @@ -436,7 +442,10 @@ define([

currentFrameCredits.lightboxCredits.removeAll();

this._currentCesiumCredit = CreditDisplay.cesiumCredit;
if (!Credit.equals(CreditDisplay.cesiumCredit, this._cesiumCredit)) {
this._cesiumCredit = Credit.clone(CreditDisplay.cesiumCredit);
}
this._currentCesiumCredit = this._cesiumCredit;
};

/**
Expand Down
3 changes: 2 additions & 1 deletion Source/Scene/MapboxImageryProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ define([
var accessToken = MapboxApi.getAccessToken(options.accessToken);
this._mapId = mapId;
this._accessToken = accessToken;
this._accessTokenErrorCredit = MapboxApi.getErrorCredit(options.accessToken);

this._accessTokenErrorCredit = Credit.clone(MapboxApi.getErrorCredit(options.accessToken));
var format = defaultValue(options.format, 'png');
if (!/\./.test(format)) {
format = '.' + format;
Expand Down
16 changes: 16 additions & 0 deletions Specs/Scene/CreditDisplaySpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,14 @@ defineSuite([
expect(credit1.id).toEqual(credit3.id);
});

it('credit clone works', function() {
var credit1 = new Credit('<a href="http://cesiumjs.org/">credit1</a>');
var credit2 = Credit.clone(credit1);
expect(credit1).toEqual(credit2);
var credit3 = Credit.clone(undefined);
expect(credit3).toBeUndefined();
});

it('credit display displays a credit', function() {
creditDisplay = new CreditDisplay(container);
var credit = new Credit('<a href="http://cesiumjs.org">CesiumJS.org</a>', true);
Expand Down Expand Up @@ -367,4 +375,12 @@ defineSuite([
expect(creditDisplay._cesiumCreditContainer.childNodes.length).toBe(0);
CreditDisplay.cesiumCredit = cesiumCredit;
});

it('each credit display has a unique cesium credit', function() {
creditDisplay = new CreditDisplay(container);
var container2 = document.createElement('div');
var creditDisplay2 = new CreditDisplay(container2);
expect(creditDisplay._currentCesiumCredit).toEqual(creditDisplay2._currentCesiumCredit);
expect(creditDisplay._currentCesiumCredit).not.toBe(creditDisplay2._currentCesiumCredit);
});
});

0 comments on commit aa4a877

Please sign in to comment.