Skip to content

Commit 0175ea0

Browse files
mramatothw0rted
authored andcommitted
Re-add changes from CesiumGS#8884
1 parent 3d665a4 commit 0175ea0

File tree

7 files changed

+101
-49
lines changed

7 files changed

+101
-49
lines changed

Source/Core/Event.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import defined from "./defined.js";
77
* exposed as a property for others to subscribe to.
88
*
99
* @alias Event
10+
* @template Listener the function call signature for this event's listeners
1011
* @constructor
1112
* @example
1213
* MyObject.prototype.myListener = function(arg1, arg2) {
@@ -46,7 +47,7 @@ Object.defineProperties(Event.prototype, {
4647
* An optional scope can be provided to serve as the <code>this</code> pointer
4748
* in which the function will execute.
4849
*
49-
* @param {Function} listener The function to be executed when the event is raised.
50+
* @param {Listener} listener The function to be executed when the event is raised.
5051
* @param {Object} [scope] An optional object scope to serve as the <code>this</code>
5152
* pointer in which the listener function will execute.
5253
* @returns {Event.RemoveCallback} A function that will remove this event listener when invoked.
@@ -71,7 +72,7 @@ Event.prototype.addEventListener = function (listener, scope) {
7172
/**
7273
* Unregisters a previously registered callback.
7374
*
74-
* @param {Function} listener The function to be unregistered.
75+
* @param {Listener} listener The function to be unregistered.
7576
* @param {Object} [scope] The scope that was originally passed to addEventListener.
7677
* @returns {Boolean} <code>true</code> if the listener was removed; <code>false</code> if the listener and scope are not registered with the event.
7778
*

Source/Core/Resource.js

+24-10
Original file line numberDiff line numberDiff line change
@@ -212,21 +212,35 @@ function combineQueryParameters(q1, q2, preserveQueryParameters) {
212212
return result;
213213
}
214214

215+
/** @typedef {string | number | boolean} QueryValue */
216+
/**
217+
* @typedef {Object.<string, QueryValue | QueryValue[] | undefined>} Resource.QueryParameters
218+
* QueryParameters must be an object whose keys are parameter names and whose
219+
* values are a primitive (string, number, boolean) or an array thereof.
220+
* */
221+
222+
/**
223+
* @typedef {Object} Resource.ConstructorOptions
224+
*
225+
* Initialization options for the Resource constructor
226+
*
227+
* @property {String} url The url of the resource.
228+
* @property {Resource.QueryParameters} [queryParameters] An object containing query parameters that will be sent when retrieving the resource.
229+
* @property {Object} [templateValues] Key/Value pairs that are used to replace template values (eg. {x}).
230+
* @property {Object} [headers={}] Additional HTTP headers that will be sent.
231+
* @property {Proxy} [proxy] A proxy to be used when loading the resource.
232+
* @property {Resource.RetryCallback} [retryCallback] The Function to call when a request for this resource fails. If it returns true, the request will be retried.
233+
* @property {Number} [retryAttempts=0] The number of times the retryCallback should be called before giving up.
234+
* @property {Request} [request] A Request object that will be used. Intended for internal use only.
235+
*/
236+
215237
/**
216238
* A resource that includes the location and any other parameters we need to retrieve it or create derived resources. It also provides the ability to retry requests.
217239
*
218240
* @alias Resource
219241
* @constructor
220242
*
221-
* @param {String|Object} options A url or an object with the following properties
222-
* @param {String} options.url The url of the resource.
223-
* @param {Object} [options.queryParameters] An object containing query parameters that will be sent when retrieving the resource.
224-
* @param {Object} [options.templateValues] Key/Value pairs that are used to replace template values (eg. {x}).
225-
* @param {Object} [options.headers={}] Additional HTTP headers that will be sent.
226-
* @param {Proxy} [options.proxy] A proxy to be used when loading the resource.
227-
* @param {Resource.RetryCallback} [options.retryCallback] The Function to call when a request for this resource fails. If it returns true, the request will be retried.
228-
* @param {Number} [options.retryAttempts=0] The number of times the retryCallback should be called before giving up.
229-
* @param {Request} [options.request] A Request object that will be used. Intended for internal use only.
243+
* @param {String|Resource.ConstructorOptions} options A url or an object describing initialization options
230244
*
231245
* @example
232246
* function refreshTokenRetryCallback(resource, error) {
@@ -574,7 +588,7 @@ Resource.prototype.getUrlComponent = function (query, proxy) {
574588
* Combines the specified object and the existing query parameters. This allows you to add many parameters at once,
575589
* as opposed to adding them one at a time to the queryParameters property. If a value is already set, it will be replaced with the new value.
576590
*
577-
* @param {Object} params The query parameters
591+
* @param {Resource.QueryParameters} params The query parameters
578592
* @param {Boolean} [useAsDefault=false] If true the params will be used as the default values, so they will only be set if they are undefined.
579593
*/
580594
Resource.prototype.setQueryParameters = function (params, useAsDefault) {

Source/DataSources/DataSource.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -58,15 +58,15 @@ Object.defineProperties(DataSource.prototype, {
5858
/**
5959
* Gets an event that will be raised if an error is encountered during processing.
6060
* @memberof DataSource.prototype
61-
* @type {Event}
61+
* @type {Event<function(this, RequestErrorEvent)>}
6262
*/
6363
errorEvent: {
6464
get: DeveloperError.throwInstantiationError,
6565
},
6666
/**
6767
* Gets an event that will be raised when the value of isLoading changes.
6868
* @memberof DataSource.prototype
69-
* @type {Event}
69+
* @type {Event<function(this, boolean)>}
7070
*/
7171
loadingEvent: {
7272
get: DeveloperError.throwInstantiationError,

Source/DataSources/EntityCluster.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,7 @@ Object.defineProperties(EntityCluster.prototype, {
549549
/**
550550
* Gets the event that will be raised when a new cluster will be displayed. The signature of the event listener is {@link EntityCluster.newClusterCallback}.
551551
* @memberof EntityCluster.prototype
552-
* @type {Event}
552+
* @type {Event<EntityCluster.newClusterCallback>}
553553
*/
554554
clusterEvent: {
555555
get: function () {
@@ -963,7 +963,8 @@ EntityCluster.prototype.destroy = function () {
963963
* @callback EntityCluster.newClusterCallback
964964
*
965965
* @param {Entity[]} clusteredEntities An array of the entities contained in the cluster.
966-
* @param {Object} cluster An object containing billboard, label, and point properties. The values are the same as
966+
* @param {{billboard: Billboard, label: Label, point: PointPrimitive}} cluster An object
967+
* containing billboard, label, and point properties. The values are the same as
967968
* billboard, label and point entities, but must be the values of the ConstantProperty.
968969
*
969970
* @example

Source/DataSources/PropertyBag.js

+1-6
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,7 @@ import Property from "./Property.js";
99
/**
1010
* A {@link Property} whose value is a key-value mapping of property names to the computed value of other properties.
1111
*
12-
* @alias PropertyBag
13-
* @constructor
14-
* @implements {DictionaryLike}
15-
*
16-
* @param {Object} [value] An object, containing key-value mapping of property names to properties.
17-
* @param {Function} [createPropertyCallback] A function that will be called when the value of any of the properties in value are not a Property.
12+
* @typedef {PropertyBagType}
1813
*/
1914
function PropertyBag(value, createPropertyCallback) {
2015
this._propertyNames = [];

Source/DataSources/exportKml.js

+51-25
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,33 @@ IdManager.prototype.get = function (id) {
221221

222222
return id.toString() + "-" + ++ids[id];
223223
};
224+
/**
225+
* @variation 2 KML return
226+
* @param {Object} options An object with the following properties:
227+
* @param {EntityCollection} options.entities The EntityCollection to export as KML.
228+
* @param {Ellipsoid} [options.ellipsoid=Ellipsoid.WGS84] The ellipsoid for the output file.
229+
* @param {exportKmlModelCallback} [options.modelCallback] A callback that will be called with a {@link ModelGraphics} instance and should return the URI to use in the KML. Required if a model exists in the entity collection.
230+
* @param {JulianDate} [options.time=entities.computeAvailability().start] The time value to use to get properties that are not time varying in KML.
231+
* @param {TimeInterval} [options.defaultAvailability=entities.computeAvailability()] The interval that will be sampled if an entity doesn't have an availability.
232+
* @param {Number} [options.sampleDuration=60] The number of seconds to sample properties that are varying in KML.
233+
* @param {false} [options.kmz=false] If false or unset, returns the KML file and referenced resources individually
234+
*
235+
* @returns {Promise<exportKmlResultKml>} A promise that resolved to an object containing the KML string and a dictionary of external file Blobs
236+
*
237+
* @example
238+
* Cesium.exportKml({
239+
* entities: entityCollection
240+
* })
241+
* .then(function(result) {
242+
* // The XML string is in result.kml
243+
*
244+
* var externalFiles = result.externalFiles
245+
* for(var file in externalFiles) {
246+
* // file is the name of the file used in the KML document as the href
247+
* // externalFiles[file] is a Blob with the contents of the file
248+
* }
249+
* });
250+
*/
224251

225252
/**
226253
* @typedef exportKmlResultKml
@@ -236,44 +263,43 @@ IdManager.prototype.get = function (id) {
236263
*/
237264

238265
/**
239-
* Exports an EntityCollection as a KML document. Only Point, Billboard, Model, Path, Polygon, Polyline geometries
240-
* will be exported. Note that there is not a 1 to 1 mapping of Entity properties to KML Feature properties. For
241-
* example, entity properties that are time dynamic but cannot be dynamic in KML are exported with their values at
242-
* options.time or the beginning of the EntityCollection's time interval if not specified. For time-dynamic properties
243-
* that are supported in KML, we use the samples if it is a {@link SampledProperty} otherwise we sample the value using
244-
* the options.sampleDuration. Point, Billboard, Model and Path geometries with time-dynamic positions will be exported
245-
* as gx:Track Features. Not all Materials are representable in KML, so for more advanced Materials just the primary
246-
* color is used. Canvas objects are exported as PNG images.
266+
* Exports an EntityCollection as a KML document or KMZ archive.
267+
*
268+
* Only Point, Billboard, Model, Path, Polygon, Polyline geometries will be exported.
269+
* Note that there is not a 1 to 1 mapping of Entity properties to KML Feature
270+
* properties. For example, entity properties that are time dynamic but cannot
271+
* be dynamic in KML are exported with their values at `options.time` or the
272+
* beginning of the EntityCollection's time interval if not specified. For
273+
* time-dynamic properties that are supported in KML, we use the samples if it
274+
* is a {@link SampledProperty}, otherwise we sample the value using the
275+
* `options.sampleDuration`. Point, Billboard, Model and Path geometries with
276+
* time-dynamic positions will be exported as gx:Track Features.
247277
*
248-
* @function exportKml
278+
* Not all Materials are representable in KML, so for more advanced Materials
279+
* just the primary color is used. Canvas objects are exported as PNG images.
249280
*
281+
* @variation 1 KMZ return
250282
* @param {Object} options An object with the following properties:
251283
* @param {EntityCollection} options.entities The EntityCollection to export as KML.
252284
* @param {Ellipsoid} [options.ellipsoid=Ellipsoid.WGS84] The ellipsoid for the output file.
253285
* @param {exportKmlModelCallback} [options.modelCallback] A callback that will be called with a {@link ModelGraphics} instance and should return the URI to use in the KML. Required if a model exists in the entity collection.
254286
* @param {JulianDate} [options.time=entities.computeAvailability().start] The time value to use to get properties that are not time varying in KML.
255287
* @param {TimeInterval} [options.defaultAvailability=entities.computeAvailability()] The interval that will be sampled if an entity doesn't have an availability.
256288
* @param {Number} [options.sampleDuration=60] The number of seconds to sample properties that are varying in KML.
257-
* @param {Boolean} [options.kmz=false] If true KML and external files will be compressed into a kmz file.
289+
* @param {true} options.kmz If true, KML and external files will be compressed into a single KMZ file.
290+
*
291+
* @returns {Promise<exportKmlResultKmz>} A promise that resolves to a KMZ file as a Blob.
258292
*
259-
* @returns {Promise<exportKmlResultKml|exportKmlResultKmz>} A promise that resolved to an object containing the KML string and a dictionary of external file blobs, or a kmz file as a blob if options.kmz is true.
260293
* @demo {@link https://sandcastle.cesium.com/index.html?src=Export%20KML.html|Cesium Sandcastle KML Export Demo}
261294
* @example
262295
* Cesium.exportKml({
263-
* entities: entityCollection
264-
* })
265-
* .then(function(result) {
266-
* // The XML string is in result.kml
267-
*
268-
* var externalFiles = result.externalFiles
269-
* for(var file in externalFiles) {
270-
* // file is the name of the file used in the KML document as the href
271-
* // externalFiles[file] is a blob with the contents of the file
272-
* }
273-
* });
274-
*
275-
*/
276-
function exportKml(options) {
296+
* entities: entityCollection,
297+
* options: { kmz: true }
298+
* })
299+
* .then(function(result) {
300+
* downloadFile(result.kmz);
301+
* });
302+
*/ function exportKml(options) {
277303
options = defaultValue(options, defaultValue.EMPTY_OBJECT);
278304
var entities = options.entities;
279305
var kmz = defaultValue(options.kmz, false);

gulpfile.cjs

+17-2
Original file line numberDiff line numberDiff line change
@@ -1550,6 +1550,11 @@ function createTypeScriptDefinitions() {
15501550
.replace(/<String>/gm, "<string>")
15511551
.replace(/<Boolean>/gm, "<boolean>")
15521552
.replace(/<Object>/gm, "<object>")
1553+
// This is an ugly hack but @template doesn't actually seem to work
1554+
.replace(
1555+
/export class Event {/gm,
1556+
"export class Event<Listener extends Function = Function> {"
1557+
)
15531558
.replace(
15541559
/= "WebGLConstants\.(.+)"/gm,
15551560
(match, p1) => `= WebGLConstants.${p1}`
@@ -1562,9 +1567,19 @@ function createTypeScriptDefinitions() {
15621567
/**
15631568
* Private interfaces to support PropertyBag being a dictionary-like object.
15641569
*/
1565-
interface DictionaryLike {
1566-
[index: string]: any;
1570+
interface PropertyDictionary {
1571+
[key: string]: Property | undefined;
1572+
}
1573+
class PropertyBagBase {
1574+
readonly propertyNames: string[];
1575+
constructor(value?: object, createPropertyCallback?: Function);
1576+
addProperty(propertyName: string, value?: any, createPropertyCallback?: Function): void;
1577+
hasProperty(propertyName: string): boolean;
1578+
merge(source: Object, createPropertyCallback?: Function): void;
1579+
removeProperty(propertyName: string): void;
15671580
}
1581+
/** This has to be in the workaround section because JSDoc doesn't support Intersection Types */
1582+
type PropertyBagType = PropertyDictionary & Property & PropertyBagBase;
15681583
15691584
${source}
15701585
}

0 commit comments

Comments
 (0)