Skip to content

Commit f6b87e3

Browse files
author
hpinkos
committedFeb 22, 2018
Merge branch 'master' into better-batching
2 parents 6f329ff + d207b1a commit f6b87e3

20 files changed

+1236
-768
lines changed
 

‎CHANGES.md

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ Change Log
2828
* Fixed bug where 3D Tiles Point Clouds would fail in Internet Explorer. [#6220](https://github.com/AnalyticalGraphicsInc/cesium/pull/6220)
2929
* Fixed `Material` so it can now take a `Resource` object as an image. [#6199](https://github.com/AnalyticalGraphicsInc/cesium/issues/6199)
3030
* Fixed issue where `CESIUM_BASE_URL` wouldn't work without a trailing `/`. [#6225](https://github.com/AnalyticalGraphicsInc/cesium/issues/6225)
31+
* Fixed an issue causing the Bing Maps key to be sent unnecessarily with every tile request. [#6250](https://github.com/AnalyticalGraphicsInc/cesium/pull/6250)
3132
* Fixed documentation issue for the `Cesium.Math` class. [#6233](https://github.com/AnalyticalGraphicsInc/cesium/issues/6233)
3233

3334
##### Additions :tada:

‎Source/Core/CesiumIon.js

+142
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
define([
2+
'./Check',
3+
'./Credit',
4+
'./defaultValue',
5+
'./defined',
6+
'./Resource',
7+
'./RuntimeError',
8+
'./CesiumIonResource'
9+
], function(
10+
Check,
11+
Credit,
12+
defaultValue,
13+
defined,
14+
Resource,
15+
RuntimeError,
16+
CesiumIonResource) {
17+
'use strict';
18+
19+
/**
20+
* Utility object for working with the Cesium ion API.
21+
*
22+
* @see https://cesium.com
23+
*
24+
* @exports CesiumIon
25+
*/
26+
var CesiumIon = {};
27+
28+
/**
29+
* The default Cesium ion access token to use.
30+
*
31+
* @type {String}
32+
*/
33+
CesiumIon.defaultAccessToken = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiI0NDViM2NkNi0xYTE2LTRlZTUtODBlNy05M2Q4ODg4M2NmMTQiLCJpZCI6MjU5LCJpYXQiOjE1MTgxOTc4MDh9.sld5jPORDf_lWavMEsugh6vHPnjR6j3qd1aBkQTswNM';
34+
35+
/**
36+
* The default Cesium ion server to use.
37+
*
38+
* @type {String}
39+
* @default https://api.cesium.com
40+
*/
41+
CesiumIon.defaultServerUrl = 'https://api.cesium.com';
42+
43+
/**
44+
* Asynchronously creates a {@link Resource} representing a Cesium ion asset.
45+
*
46+
* @param {Number} assetId The Cesium ion asset id.
47+
* @param {Object} [options] An object with the following properties:
48+
* @param {String} [options.accessToken=CesiumIon.defaultAccessToken] The access token to use.
49+
* @param {String} [options.serverUrl=CesiumIon.defaultServerUrl] The url to the Cesium ion API server.
50+
* @returns {Promise.<Resource>} A Promise to a Resource representing the Cesium ion Asset.
51+
*
52+
* @example
53+
* //Load a Cesium3DTileset with asset ID of 124624234
54+
* Cesium.CesiumIon.createResource(124624234)
55+
* .then(function (resource) {
56+
* viewer.scene.primitives.add(new Cesium.Cesium3DTileset({ url: resource }));
57+
* });
58+
*
59+
* @example
60+
* //Load a CZML file with asset ID of 10890
61+
* Cesium.CesiumIon.createResource(10890)
62+
* .then(function (resource) {
63+
* viewer.dataSources.add(Cesium.CzmlDataSource.load(resource));
64+
* });
65+
*
66+
* @example
67+
* //Load an ImageryProvider with asset ID of 2347923
68+
* Cesium.CesiumIon.createResource(2347923)
69+
* .then(function (resource) {
70+
* viewer.imageryLayers.addProvider(Cesium.createTileMapServiceImageryProvider({url : resource }));
71+
* });
72+
*/
73+
CesiumIon.createResource = function(assetId, options) {
74+
var endpointResource = CesiumIon._createEndpointResource(assetId, options);
75+
76+
return CesiumIon._loadJson(endpointResource)
77+
.then(function (endpoint) {
78+
79+
var externalType = endpoint.externalType;
80+
if (!defined(externalType)) {
81+
return CesiumIonResource.create(endpoint, endpointResource);
82+
}
83+
84+
// 3D Tiles and STK Terrain Server external assets can still be represented as a resource
85+
// object, just not the CesiumIonResource object.
86+
if (externalType === '3DTILES' || externalType === 'STK_TERRAIN_SERVER') {
87+
var resource = new Resource({ url: endpoint.options.url });
88+
89+
resource.credits = endpoint.attributions.map(function(attribution) {
90+
return new Credit({
91+
text: attribution.text,
92+
link: attribution.url,
93+
imageUrl: attribution.image,
94+
showOnScreen: defined(attribution.collapsible) && !attribution.collapsible
95+
});
96+
});
97+
resource.ionEndpoint = endpoint;
98+
var oldClone = resource.clone;
99+
resource.clone = function(result) {
100+
result = oldClone.apply(resource, result);
101+
result.ionEndpoint = this.ionEndpoint;
102+
result.credits = this.credits;
103+
return result;
104+
};
105+
return resource;
106+
}
107+
108+
//External imagery assets have additional configuration that can't be represented as a Resource
109+
throw new RuntimeError('CesiumIon.createResource does not support external imagery assets; use IonImageryProvider instead.');
110+
});
111+
};
112+
113+
/**
114+
* @private
115+
*/
116+
CesiumIon._createEndpointResource = function (assetId, options) {
117+
//>>includeStart('debug', pragmas.debug);
118+
Check.defined('assetId', assetId);
119+
//>>includeEnd('debug');
120+
121+
options = defaultValue(options, defaultValue.EMPTY_OBJECT);
122+
var serverUrl = defaultValue(options.serverUrl, CesiumIon.defaultServerUrl);
123+
var accessToken = defaultValue(options.accessToken, CesiumIon.defaultAccessToken);
124+
125+
var resourceOptions = {
126+
url: serverUrl + '/v1/assets/' + assetId + '/endpoint'
127+
};
128+
129+
if (defined(accessToken)) {
130+
resourceOptions.queryParameters = { access_token: accessToken };
131+
}
132+
133+
return new Resource(resourceOptions);
134+
};
135+
136+
//Exposed for testing
137+
CesiumIon._loadJson = function(resource) {
138+
return resource.fetchJson();
139+
};
140+
141+
return CesiumIon;
142+
});

‎Source/Scene/CesiumIonResource.js ‎Source/Core/CesiumIonResource.js

+18-28
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,17 @@
11
define([
2-
'../Core/Check',
3-
'../Core/defaultValue',
4-
'../Core/defined',
5-
'../Core/loadJson',
6-
'../Core/Resource',
7-
'../Core/RuntimeError',
8-
'../ThirdParty/when',
9-
'./ArcGisMapServerImageryProvider',
10-
'./BingMapsImageryProvider',
11-
'./createTileMapServiceImageryProvider',
12-
'./GoogleEarthEnterpriseMapsProvider',
13-
'./MapboxImageryProvider',
14-
'./SingleTileImageryProvider',
15-
'./UrlTemplateImageryProvider',
16-
'./WebMapServiceImageryProvider',
17-
'./WebMapTileServiceImageryProvider'
2+
'./Credit',
3+
'./defaultValue',
4+
'./defined',
5+
'./loadJson',
6+
'./Resource',
7+
'../ThirdParty/when'
188
], function(
19-
Check,
9+
Credit,
2010
defaultValue,
2111
defined,
2212
loadJson,
2313
Resource,
24-
RuntimeError,
25-
when,
26-
ArcGisMapServerImageryProvider,
27-
BingMapsImageryProvider,
28-
createTileMapServiceImageryProvider,
29-
GoogleEarthEnterpriseMapsProvider,
30-
MapboxImageryProvider,
31-
SingleTileImageryProvider,
32-
UrlTemplateImageryProvider,
33-
WebMapServiceImageryProvider,
34-
WebMapTileServiceImageryProvider) {
14+
when) {
3515
'use strict';
3616

3717
/**
@@ -44,6 +24,16 @@ define([
4424
function CesiumIonResource(options, endpoint, endpointResource) {
4525
Resource.call(this, options);
4626

27+
// Array of credits pertaining to this asset.
28+
this.credits = endpoint.attributions.map(function(attribution) {
29+
return new Credit({
30+
text: attribution.text,
31+
link: attribution.url,
32+
imageUrl: attribution.image,
33+
showOnScreen: defined(attribution.collapsible) && !attribution.collapsible
34+
});
35+
});
36+
4737
// The asset endpoint data returned from ion.
4838
this.ionEndpoint = endpoint;
4939

‎Source/Core/CesiumTerrainProvider.js

+8-2
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ define([
154154
var deferred = when.defer();
155155
this._ready = false;
156156
this._readyPromise = deferred;
157+
this._tileCredits = undefined;
157158

158159
var that = this;
159160
var lastResource;
@@ -174,6 +175,9 @@ define([
174175
url: 'layer.json'
175176
});
176177

178+
// ion resources have a credits property we can use for additional attribution.
179+
that._tileCredits = resource.credits;
180+
177181
requestMetadata();
178182
})
179183
.otherwise(function(e) {
@@ -405,7 +409,8 @@ define([
405409
waterMask : new Uint8Array(buffer, heightBuffer.byteLength + 1, buffer.byteLength - heightBuffer.byteLength - 1),
406410
width : provider._heightmapWidth,
407411
height : provider._heightmapWidth,
408-
structure : provider._heightmapStructure
412+
structure : provider._heightmapStructure,
413+
credits: provider._tileCredits
409414
});
410415
}
411416

@@ -550,7 +555,8 @@ define([
550555
eastSkirtHeight : skirtHeight,
551556
northSkirtHeight : skirtHeight,
552557
childTileMask: provider.availability.computeChildMaskForTile(level, x, y),
553-
waterMask: waterMaskBuffer
558+
waterMask: waterMaskBuffer,
559+
credits: provider._tileCredits
554560
});
555561
}
556562

‎Source/Core/Credit.js

+54
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,43 @@ define([
1313
var nextCreditId = 0;
1414
var creditToId = {};
1515

16+
function getElement(credit) {
17+
var element = document.createElement('span');
18+
var text = credit.text;
19+
var link = credit.link;
20+
var a;
21+
if (credit._hasImage) {
22+
var content = document.createElement('img');
23+
content.src = credit.imageUrl;
24+
if (defined(text)) {
25+
content.alt = text;
26+
content.title = text;
27+
}
28+
if (credit._hasLink) {
29+
a = document.createElement('a');
30+
a.appendChild(content);
31+
a.href = link;
32+
a.target = '_blank';
33+
element.appendChild(a);
34+
} else {
35+
element.appendChild(content);
36+
}
37+
element.className = 'cesium-credit-image';
38+
} else {
39+
if (credit._hasLink) {
40+
a = document.createElement('a');
41+
a.textContent = text;
42+
a.href = link;
43+
a.target = '_blank';
44+
element.appendChild(a);
45+
} else {
46+
element.textContent = text;
47+
}
48+
element.className = 'cesium-credit-text';
49+
}
50+
return element;
51+
}
52+
1653
/**
1754
* A credit contains data pertaining to how to display attributions/credits for certain content on the screen.
1855
* @param {Object} [options] An object with the following properties
@@ -75,6 +112,8 @@ define([
75112
}
76113

77114
this._id = id;
115+
116+
this._element = undefined;
78117
}
79118

80119
defineProperties(Credit.prototype, {
@@ -137,6 +176,21 @@ define([
137176
get : function() {
138177
return this._showOnScreen;
139178
}
179+
},
180+
181+
/**
182+
* Gets the credit element
183+
* @memberof Credit.prototype
184+
* @type {HTMLElement}
185+
* @readonly
186+
*/
187+
element: {
188+
get: function() {
189+
if (!defined(this._element)) {
190+
this._element = getElement(this);
191+
}
192+
return this._element;
193+
}
140194
}
141195
});
142196

‎Source/Core/QuantizedMeshTerrainData.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -439,8 +439,9 @@ define([
439439
var southSkirtHeight = isNorthChild ? (shortestSkirt * 0.5) : this._southSkirtHeight;
440440
var eastSkirtHeight = isEastChild ? this._eastSkirtHeight : (shortestSkirt * 0.5);
441441
var northSkirtHeight = isNorthChild ? this._northSkirtHeight : (shortestSkirt * 0.5);
442+
var credits = this._credits;
442443

443-
return when(upsamplePromise, function(result) {
444+
return when(upsamplePromise).then(function(result) {
444445
var quantizedVertices = new Uint16Array(result.vertices);
445446
var indicesTypedArray = IndexDatatype.createTypedArray(quantizedVertices.length / 3, result.indices);
446447
var encodedNormals;
@@ -466,6 +467,7 @@ define([
466467
eastSkirtHeight : eastSkirtHeight,
467468
northSkirtHeight : northSkirtHeight,
468469
childTileMask : 0,
470+
credits: credits,
469471
createdByUpsampling : true
470472
});
471473
});

‎Source/Core/Resource.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1811,7 +1811,7 @@ define([
18111811
// While non-standard, file protocol always returns a status of 0 on success
18121812
var localFile = false;
18131813
if (typeof url === 'string') {
1814-
localFile = url.indexOf('file://') === 0;
1814+
localFile = (url.indexOf('file://') === 0) || window.location.origin === 'file://';
18151815
}
18161816

18171817
xhr.onload = function() {

‎Source/Renderer/ShaderSource.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ define([
313313
return new ShaderSource({
314314
sources : this.sources,
315315
defines : this.defines,
316-
pickColorQuantifier : this.pickColorQualifier,
316+
pickColorQualifier : this.pickColorQualifier,
317317
includeBuiltIns : this.includeBuiltIns
318318
});
319319
};

‎Source/Scene/BingMapsImageryProvider.js

+4-9
Original file line numberDiff line numberDiff line change
@@ -109,16 +109,10 @@ define([
109109
this._key = BingMapsApi.getKey(options.key);
110110
this._keyErrorCredit = BingMapsApi.getErrorCredit(options.key);
111111

112-
var urlResource = Resource.createIfNeeded(options.url, {
112+
this._resource = Resource.createIfNeeded(options.url, {
113113
proxy: options.proxy
114114
});
115115

116-
urlResource.setQueryParameters({
117-
key: this._key
118-
});
119-
120-
this._resource = urlResource;
121-
122116
this._tileProtocol = options.tileProtocol;
123117
this._mapStyle = defaultValue(options.mapStyle, BingMapsStyle.AERIAL);
124118
this._culture = defaultValue(options.culture, '');
@@ -157,10 +151,11 @@ define([
157151
this._ready = false;
158152
this._readyPromise = when.defer();
159153

160-
var metadataResource = urlResource.getDerivedResource({
154+
var metadataResource = this._resource.getDerivedResource({
161155
url:'/REST/v1/Imagery/Metadata/' + this._mapStyle,
162156
queryParameters: {
163-
incl: 'ImageryProviders'
157+
incl: 'ImageryProviders',
158+
key: this._key
164159
}
165160
});
166161
var that = this;

0 commit comments

Comments
 (0)
Please sign in to comment.