diff --git a/cesiumjs4gwt-main/pom.xml b/cesiumjs4gwt-main/pom.xml index bfaa048bb336678f56597ad87265537c9381cb39..71a1cf17d6c2ce1ece4962cbeb21c2a8abee1041 100644 --- a/cesiumjs4gwt-main/pom.xml +++ b/cesiumjs4gwt-main/pom.xml @@ -7,7 +7,7 @@ cesiumjs4gwt org.cesiumjs - 1.74 + 1.79.1-SNAPSHOT CesiumJS GWT Wrapper diff --git a/cesiumjs4gwt-main/src/main/java/org/cesiumjs/cs/Cesium.java b/cesiumjs4gwt-main/src/main/java/org/cesiumjs/cs/Cesium.java index 2f00ee8f1571fddb20d3deeb99f44b5fee19ea41..ceba95cc24717029c73633daf4ce616843143b43 100644 --- a/cesiumjs4gwt-main/src/main/java/org/cesiumjs/cs/Cesium.java +++ b/cesiumjs4gwt-main/src/main/java/org/cesiumjs/cs/Cesium.java @@ -16,6 +16,7 @@ package org.cesiumjs.cs; +import jsinterop.annotations.*; import org.cesiumjs.cs.collections.EntityCollection; import org.cesiumjs.cs.core.*; import org.cesiumjs.cs.core.providers.CesiumTerrainProvider; @@ -27,437 +28,433 @@ import org.cesiumjs.cs.scene.Material; import org.cesiumjs.cs.scene.Scene; import org.cesiumjs.cs.widgets.Command; -import jsinterop.annotations.JsConstructor; -import jsinterop.annotations.JsFunction; -import jsinterop.annotations.JsMethod; -import jsinterop.annotations.JsOverlay; -import jsinterop.annotations.JsPackage; -import jsinterop.annotations.JsProperty; -import jsinterop.annotations.JsType; - /** * @author Serge Silaev aka iSergio */ public class Cesium { - @JsProperty(namespace = JsPackage.GLOBAL, name = "Cesium") - public static native boolean isInitialized(); - - @JsProperty(namespace = "Cesium", name = "VERSION") - public static native String version(); - - @JsProperty(namespace = JsPackage.GLOBAL, name = "CesiumPath") - public static native String path(); - - public static native void log(Object object) /*-{ - console.log(object); - }-*/; - - /** - * Fix for SmartGWT Thanks for Mark Erikson - * (https://groups.google.com/forum/#!msg/cesium-dev/ZfyW0CNRsSU/lP6KTaUpEQAJ) - */ - public static native void fixSmartGWT() /*-{ - if ($wnd.buildInDataView !== undefined) { - console.log("Native DataView restored."); - $wnd.DataView = $wnd.buildInDataView; - } else { - console.log("Native DataView not modified."); - } - }-*/; - - /** - * Given a non-relative moduleID, returns an absolute URL to the file - * represented by that module ID, using, in order of preference, require.toUrl, - * the value of a global CESIUM_BASE_URL, or the base URL of the Cesium.js - * script. - */ - @JsMethod(namespace = "Cesium", name = "buildModuleUrl") - public static native String buildModuleUrl(String moduleId); - - @JsMethod(namespace = "Cesium") - public static native boolean defined(Object object); - - /** - * Initiates a terrain height query for an array of {@link Cartographic} - * positions by requesting tiles from a terrain provider, sampling, and - * interpolating. The interpolation matches the triangles used to render the - * terrain at the specified level. The query happens asynchronously, so this - * function returns a promise that is resolved when the query completes. Each - * point height is modified in place. If a height can not be determined because - * no terrain data is available for the specified level at that location, or - * another error occurs, the height is set to undefined. As is typical of the - * {@link Cartographic} type, the supplied height is a height above the - * reference ellipsoid (such as {@link Ellipsoid#WGS84()}) rather than an - * altitude above mean sea level. In other words, it will not necessarily be 0.0 - * if sampled in the ocean. - * - * @param terrainProvider The terrain provider from which to query heights. - * @param level The terrain level-of-detail from which to query - * terrain heights. - * @param positions The positions to update with terrain heights. - * @return A promise that resolves to the provided list of positions when - * terrain the query has completed. - */ - @JsMethod(namespace = "Cesium", name = "sampleTerrain") - public static native Promise sampleTerrain(TerrainProvider terrainProvider, int level, - Cartographic[] positions); - - /** - * Create a Command from a given function, for use with ViewModels. A Command is - * a function with an extra canExecute observable property to determine whether - * the command can be executed. When executed, a Command function will check the - * value of canExecute and throw if false. It also provides events for when a - * command has been or is about to be executed. - * - * @param func The function to execute. - * @return Command function - */ - @JsMethod(namespace = "Cesium", name = "createCommand") - public static native Command createCommand(Function func); - - /** - * Create a Command from a given function, for use with ViewModels. A Command is - * a function with an extra canExecute observable property to determine whether - * the command can be executed. When executed, a Command function will check the - * value of canExecute and throw if false. It also provides events for when a - * command has been or is about to be executed. - * - * @param func The function to execute. - * @param canExecute A boolean indicating whether the function can currently be - * executed. - * @return Command function - */ - @JsMethod(namespace = "Cesium", name = "createCommand") - public static native Command createCommand(Function func, boolean canExecute); - - /** - * A browser-independent function to request a new animation frame. This is used - * to create an application's draw loop as shown in the example below. - * - * @param callback The function to call when the next frame should be drawn. - * @return An ID that can be passed to {@link #cancelAnimationFrame} to cancel - * the request. - */ - // TODO Example - @JsMethod(namespace = "Cesium", name = "requestAnimationFrame") - public static native Number requestAnimationFrame(RequestAnimationFrameCallback callback); - - /** - * A browser-independent function to cancel an animation frame requested using - * requestAnimationFrame. - * - * @param requestID The value returned by requestAnimationFrame. - */ - @JsMethod(namespace = "Cesium", name = "cancelAnimationFrame") - public static native void cancelAnimationFrame(Number requestID); - - /** - * Initiates a sampleTerrain() request at the maximum available tile level for a - * terrain dataset. - * - * @param terrainProvider The terrain provider from which to query heights. - * @param positions The positions to update with terrain heights. - * @return A promise that resolves to the provided list of positions when - * terrain the query has completed. This promise will reject if the - * terrain provider's `availability` property is undefined. - * - *
-   *     Example:
-   *     {@code
-   *     CesiumTerrainProviderOptions options = new CesiumTerrainProviderOptions();
-   *     options.url = "https://assets.agi.com/stk-terrain/world";
-   *     CesiumTerrainProvider terrainProvider = new CesiumTerrainProvider(options);
-   *     Cartographic[] positions = new Cartographic[] {Cartographic.fromDegrees(86.925145, 27.988257), Cartographic.fromDegrees(87.0, 28.0)};
-   *     Promise promise = Cesium.sampleTerrainMostDetailed(terrainProvider, positions);
-   *     promise.then(new Fulfill() {
-   *         {@literal @}Override
-   *         public void onFulfilled(Cartographic[] updatedPositions) {
-   *             //
-   *         }
-   *     });
-   *     }
-   *         
- */ - @JsMethod(namespace = "Cesium", name = "sampleTerrainMostDetailed") - public static native Promise sampleTerrainMostDetailed(TerrainProvider terrainProvider, - Cartographic[] positions); - - // TODO: Example - /** - * Destroys an object. Each of the object's functions, including functions in - * its prototype, is replaced with a function that throws a DeveloperError, - * except for the object's isDestroyed function, which is set to a function that - * returns true. The object's properties are removed with delete. - * - * This function is used by objects that hold native resources, e.g., WebGL - * resources, which need to be - * - * explicitly released. Client code calls an object's destroy function, which - * then releases the native resource and calls destroyObject to put itself in a - * destroyed state. - * - * @param object The object to destroy. - */ - @JsMethod(namespace = "Cesium", name = "destroyObject") - public static native void destroyObject(Object object); - - // TODO: Example - /** - * Destroys an object. Each of the object's functions, including functions in - * its prototype, is replaced with a function that throws a DeveloperError, - * except for the object's isDestroyed function, which is set to a function that - * returns true. The object's properties are removed with delete. - * - * This function is used by objects that hold native resources, e.g., WebGL - * resources, which need to be - * - * explicitly released. Client code calls an object's destroy function, which - * then releases the native resource and calls destroyObject to put itself in a - * destroyed state. - * - * @param object The object to destroy. - * @param message The message to include in the exception that is thrown if a - * destroyed object's function is called. - */ - @JsMethod(namespace = "Cesium", name = "destroyObject") - public static native void destroyObject(Object object, String message); - - /** - * Creates a {@link CesiumTerrainProvider} instance for the - * Cesium World - * Terrain. - * - * @return {@link CesiumTerrainProvider} instance for the - * Cesium World - * Terrain. - */ - @JsMethod(namespace = "Cesium", name = "createWorldTerrain") - public static native CesiumTerrainProvider createWorldTerrain(); - - /** - * Creates a {@link CesiumTerrainProvider} instance for the - * Cesium World - * Terrain. - * - * @param options {@link CreateWorldTerrainOptions} object. - * @return {@link CesiumTerrainProvider} instance for the - * Cesium World - * Terrain. - */ - @JsMethod(namespace = "Cesium", name = "createWorldTerrain") - public static native CesiumTerrainProvider createWorldTerrain(CreateWorldTerrainOptions options); - - /** - * Exports an EntityCollection as a KML document. Only Point, Billboard, Model, - * Path, Polygon, Polyline geometries will be exported. Note that there is not a - * 1 to 1 mapping of Entity properties to KML Feature properties. For example, - * entity properties that are time dynamic but cannot be dynamic in KML are - * exported with their values at options.time or the beginning of the - * EntityCollection's time interval if not specified. For time-dynamic - * properties that are supported in KML, we use the samples if it is a - * {@link org.cesiumjs.cs.datasources.properties.SampledProperty} otherwise we - * sample the value using the options.sampleDuration. Point, Billboard, Model - * and Path geometries with time-dynamic positions will be exported as gx:Track - * Features. Not all Materials are representable in KML, so for more advanced - * Materials just the primary color is used. Canvas objects are exported as PNG - * images. - * - * @param options object with properties - * @return 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. - */ - @JsMethod(namespace = "Cesium", name = "exportKml") - public static native Promise exportKml(ExportKmlOptions options); - - /** - * Creates a Material that combines multiple layers of color/gradient bands and maps them to terrain heights. - * The shader does a binary search over all the heights to find out which colors are above and below a given height, - * and interpolates between them for the final color. This material supports hundreds of entries relatively cheaply. - * @param options {@link ElevationBandMaterialOptions} with the following properties - * @return A new Material instance. - */ - @JsMethod(namespace = "Cesium", name = "createElevationBandMaterial") - public static native Material createElevationBandMaterial(ElevationBandMaterialOptions options); - - @JsFunction - public interface Function { - Object function(Object... args); - } - - @JsFunction - public interface RequestAnimationFrameCallback { + @JsProperty(namespace = JsPackage.GLOBAL, name = "Cesium") + public static native boolean isInitialized(); + + @JsProperty(namespace = "Cesium", name = "VERSION") + public static native String version(); + + @JsProperty(namespace = JsPackage.GLOBAL, name = "CesiumPath") + public static native String path(); + + public static native void log(Object object) /*-{ + console.log(object); + }-*/; + /** - * A function that will be called when the next frame should be drawn. - * - * @param timestamp A timestamp for the frame, in milliseconds. + * Fix for SmartGWT Thanks for Mark Erikson + * (https://groups.google.com/forum/#!msg/cesium-dev/ZfyW0CNRsSU/lP6KTaUpEQAJ) */ - @SuppressWarnings("unusable-by-js") - void Callback(Number timestamp); - } + public static native void fixSmartGWT() /*-{ + if ($wnd.buildInDataView !== undefined) { + console.log("Native DataView restored."); + $wnd.DataView = $wnd.buildInDataView; + } else { + console.log("Native DataView not modified."); + } + }-*/; - @JsType(isNative = true, namespace = JsPackage.GLOBAL, name = "Object") - public static class CreateWorldTerrainOptions { /** - * Flag that indicates if the client should request additional lighting - * information from the server if available. Default: false + * Given a non-relative moduleID, returns an absolute URL to the file + * represented by that module ID, using, in order of preference, require.toUrl, + * the value of a global CESIUM_BASE_URL, or the base URL of the Cesium.js + * script. */ - @JsProperty - public boolean requestVertexNormals; + @JsMethod(namespace = "Cesium", name = "buildModuleUrl") + public static native String buildModuleUrl(String moduleId); + + @JsMethod(namespace = "Cesium") + public static native boolean defined(Object object); + /** - * Flag that indicates if the client should request per tile water masks from - * the server if available. Default: false + * Initiates a terrain height query for an array of {@link Cartographic} + * positions by requesting tiles from a terrain provider, sampling, and + * interpolating. The interpolation matches the triangles used to render the + * terrain at the specified level. The query happens asynchronously, so this + * function returns a promise that is resolved when the query completes. Each + * point height is modified in place. If a height can not be determined because + * no terrain data is available for the specified level at that location, or + * another error occurs, the height is set to undefined. As is typical of the + * {@link Cartographic} type, the supplied height is a height above the + * reference ellipsoid (such as {@link Ellipsoid#WGS84()}) rather than an + * altitude above mean sea level. In other words, it will not necessarily be 0.0 + * if sampled in the ocean. + * + * @param terrainProvider The terrain provider from which to query heights. + * @param level The terrain level-of-detail from which to query + * terrain heights. + * @param positions The positions to update with terrain heights. + * @return A promise that resolves to the provided list of positions when + * terrain the query has completed. */ - @JsProperty - public boolean requestWaterMask; + @JsMethod(namespace = "Cesium", name = "sampleTerrain") + public static native Promise sampleTerrain(TerrainProvider terrainProvider, int level, + Cartographic[] positions); - @JsConstructor - public CreateWorldTerrainOptions() { - } + /** + * Create a Command from a given function, for use with ViewModels. A Command is + * a function with an extra canExecute observable property to determine whether + * the command can be executed. When executed, a Command function will check the + * value of canExecute and throw if false. It also provides events for when a + * command has been or is about to be executed. + * + * @param func The function to execute. + * @return Command function + */ + @JsMethod(namespace = "Cesium", name = "createCommand") + public static native Command createCommand(Function func); /** - * Create instance for {@link Cesium#createWorldTerrain()}. + * Create a Command from a given function, for use with ViewModels. A Command is + * a function with an extra canExecute observable property to determine whether + * the command can be executed. When executed, a Command function will check the + * value of canExecute and throw if false. It also provides events for when a + * command has been or is about to be executed. * - * @param requestVertexNormals Flag that indicates if the client should request - * additional lighting information from the server - * if available. - * @return instance for {@link Cesium#createWorldTerrain()}. + * @param func The function to execute. + * @param canExecute A boolean indicating whether the function can currently be + * executed. + * @return Command function */ - @JsOverlay - public static CreateWorldTerrainOptions create(boolean requestVertexNormals) { - CreateWorldTerrainOptions options = new CreateWorldTerrainOptions(); - options.requestVertexNormals = requestVertexNormals; - return options; - } + @JsMethod(namespace = "Cesium", name = "createCommand") + public static native Command createCommand(Function func, boolean canExecute); /** - * Create instance for {@link Cesium#createWorldTerrain()}. + * A browser-independent function to request a new animation frame. This is used + * to create an application's draw loop as shown in the example below. * - * @param requestVertexNormals Flag that indicates if the client should request - * additional lighting information from the server - * if available. - * @param requestWaterMask Flag that indicates if the client should request - * per tile water masks from the server if - * available. - * @return instance for {@link Cesium#createWorldTerrain()}. + * @param callback The function to call when the next frame should be drawn. + * @return An ID that can be passed to {@link #cancelAnimationFrame} to cancel + * the request. */ - @JsOverlay - public static CreateWorldTerrainOptions create(boolean requestVertexNormals, boolean requestWaterMask) { - CreateWorldTerrainOptions options = new CreateWorldTerrainOptions(); - options.requestVertexNormals = requestVertexNormals; - options.requestWaterMask = requestWaterMask; - return options; - } - } + // TODO Example + @JsMethod(namespace = "Cesium", name = "requestAnimationFrame") + public static native Number requestAnimationFrame(RequestAnimationFrameCallback callback); - /** - * Options for {@link Cesium#exportKml(ExportKmlOptions)} - */ - @JsType(isNative = true, namespace = JsPackage.GLOBAL, name = "Object") - public static class ExportKmlOptions { /** - * The EntityCollection to export as KML. + * A browser-independent function to cancel an animation frame requested using + * requestAnimationFrame. + * + * @param requestID The value returned by requestAnimationFrame. */ - @JsProperty - public EntityCollection entities; + @JsMethod(namespace = "Cesium", name = "cancelAnimationFrame") + public static native void cancelAnimationFrame(Number requestID); + /** - * The ellipsoid for the output file. Default: {@link Ellipsoid#WGS84()} + * Initiates a sampleTerrain() request at the maximum available tile level for a + * terrain dataset. + * + * @param terrainProvider The terrain provider from which to query heights. + * @param positions The positions to update with terrain heights. + * @return A promise that resolves to the provided list of positions when + * terrain the query has completed. This promise will reject if the + * terrain provider's `availability` property is undefined. + * + *
+     *     Example:
+     *     {@code
+     *     CesiumTerrainProviderOptions options = new CesiumTerrainProviderOptions();
+     *     options.url = "https://assets.agi.com/stk-terrain/world";
+     *     CesiumTerrainProvider terrainProvider = new CesiumTerrainProvider(options);
+     *     Cartographic[] positions = new Cartographic[] {Cartographic.fromDegrees(86.925145, 27.988257), Cartographic.fromDegrees(87.0, 28.0)};
+     *     Promise promise = Cesium.sampleTerrainMostDetailed(terrainProvider, positions);
+     *     promise.then(new Fulfill() {
+     *         {@literal @}Override
+     *         public void onFulfilled(Cartographic[] updatedPositions) {
+     *             //
+     *         }
+     *     });
+     *     }
+     *         
*/ - @JsProperty - public Ellipsoid ellipsoid; + @JsMethod(namespace = "Cesium", name = "sampleTerrainMostDetailed") + public static native Promise sampleTerrainMostDetailed(TerrainProvider terrainProvider, + Cartographic[] positions); + + // TODO: Example + /** - * A callback that will be called with a ModelGraphics instance and should - * return the URI to use in the KML. Required if a model exists in the entity - * collection. + * Destroys an object. Each of the object's functions, including functions in + * its prototype, is replaced with a function that throws a DeveloperError, + * except for the object's isDestroyed function, which is set to a function that + * returns true. The object's properties are removed with delete. + *

+ * This function is used by objects that hold native resources, e.g., WebGL + * resources, which need to be + *

+ * explicitly released. Client code calls an object's destroy function, which + * then releases the native resource and calls destroyObject to put itself in a + * destroyed state. + * + * @param object The object to destroy. */ - @JsProperty - public ModelCallback modelCallback; + @JsMethod(namespace = "Cesium", name = "destroyObject") + public static native void destroyObject(Object object); + + // TODO: Example + /** - * The time value to use to get properties that are not time varying in KML. + * Destroys an object. Each of the object's functions, including functions in + * its prototype, is replaced with a function that throws a DeveloperError, + * except for the object's isDestroyed function, which is set to a function that + * returns true. The object's properties are removed with delete. + *

+ * This function is used by objects that hold native resources, e.g., WebGL + * resources, which need to be + *

+ * explicitly released. Client code calls an object's destroy function, which + * then releases the native resource and calls destroyObject to put itself in a + * destroyed state. + * + * @param object The object to destroy. + * @param message The message to include in the exception that is thrown if a + * destroyed object's function is called. */ - @JsProperty - public JulianDate time; + @JsMethod(namespace = "Cesium", name = "destroyObject") + public static native void destroyObject(Object object, String message); + /** - * The interval that will be sampled if an entity doesn't have an availability. + * Creates a {@link CesiumTerrainProvider} instance for the + * Cesium World + * Terrain. + * + * @return {@link CesiumTerrainProvider} instance for the + * Cesium World + * Terrain. */ - @JsProperty - public TimeInterval defaultAvailability; + @JsMethod(namespace = "Cesium", name = "createWorldTerrain") + public static native CesiumTerrainProvider createWorldTerrain(); + /** - * The number of seconds to sample properties that are varying in KML. Default: - * 60 + * Creates a {@link CesiumTerrainProvider} instance for the + * Cesium World + * Terrain. + * + * @param options {@link CreateWorldTerrainOptions} object. + * @return {@link CesiumTerrainProvider} instance for the + * Cesium World + * Terrain. */ - @JsProperty - public int sampleDuration; + @JsMethod(namespace = "Cesium", name = "createWorldTerrain") + public static native CesiumTerrainProvider createWorldTerrain(CreateWorldTerrainOptions options); + /** - * If true KML and external files will be compressed into a kmz file. Default: - * false + * Exports an EntityCollection as a KML document. Only Point, Billboard, Model, + * Path, Polygon, Polyline geometries will be exported. Note that there is not a + * 1 to 1 mapping of Entity properties to KML Feature properties. For example, + * entity properties that are time dynamic but cannot be dynamic in KML are + * exported with their values at options.time or the beginning of the + * EntityCollection's time interval if not specified. For time-dynamic + * properties that are supported in KML, we use the samples if it is a + * {@link org.cesiumjs.cs.datasources.properties.SampledProperty} otherwise we + * sample the value using the options.sampleDuration. Point, Billboard, Model + * and Path geometries with time-dynamic positions will be exported as gx:Track + * Features. Not all Materials are representable in KML, so for more advanced + * Materials just the primary color is used. Canvas objects are exported as PNG + * images. + * + * @param options object with properties + * @return 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. */ - @JsProperty - public boolean kmz; + @JsMethod(namespace = "Cesium", name = "exportKml") + public static native Promise exportKml(ExportKmlOptions options); - @JsConstructor - private ExportKmlOptions() { - } + /** + * Creates a Material that combines multiple layers of color/gradient bands and maps them to terrain heights. + * The shader does a binary search over all the heights to find out which colors are above and below a given height, + * and interpolates between them for the final color. This material supports hundreds of entries relatively cheaply. + * + * @param options {@link ElevationBandMaterialOptions} with the following properties + * @return A new Material instance. + */ + @JsMethod(namespace = "Cesium", name = "createElevationBandMaterial") + public static native Material createElevationBandMaterial(ElevationBandMaterialOptions options); - @JsOverlay - public static ExportKmlOptions create(EntityCollection entities) { - ExportKmlOptions options = new ExportKmlOptions(); - options.entities = entities; - return options; + @JsFunction + public interface Function { + Object function(Object... args); } - /** - * Since KML does not support glTF models, this callback is required to specify - * what URL to use for the model in the KML document. It can also be used to add - * additional files to the externalFiles object, which is the list of files - * embedded in the exported KMZ, or otherwise returned with the KML string when - * exporting. - */ @JsFunction - public interface ModelCallback { - /** - * Since KML does not support glTF models, this callback is required to specify - * what URL to use for the model in the KML document. It can also be used to add - * additional files to the externalFiles object, which is the list of files - * embedded in the exported KMZ, or otherwise returned with the KML string when - * exporting. - * - * @param model The ModelGraphics instance for an Entity. - * @param time The time that any properties should use to get the - * value. - * @param externalFiles An object that maps a filename to a Blob or a Promise - * that resolves to a Blob. - * @return The URL to use for the href in the KML document. - */ - String Callback(ModelGraphics model, org.cesiumjs.cs.core.JulianDate time, JsObject externalFiles); + public interface RequestAnimationFrameCallback { + /** + * A function that will be called when the next frame should be drawn. + * + * @param timestamp A timestamp for the frame, in milliseconds. + */ + @SuppressWarnings("unusable-by-js") + void Callback(Number timestamp); + } + + @JsType(isNative = true, namespace = JsPackage.GLOBAL, name = "Object") + public static class CreateWorldTerrainOptions { + /** + * Flag that indicates if the client should request additional lighting + * information from the server if available. Default: false + */ + @JsProperty + public boolean requestVertexNormals; + /** + * Flag that indicates if the client should request per tile water masks from + * the server if available. Default: false + */ + @JsProperty + public boolean requestWaterMask; + + @JsConstructor + public CreateWorldTerrainOptions() { + } + + /** + * Create instance for {@link Cesium#createWorldTerrain()}. + * + * @param requestVertexNormals Flag that indicates if the client should request + * additional lighting information from the server + * if available. + * @return instance for {@link Cesium#createWorldTerrain()}. + */ + @JsOverlay + public static CreateWorldTerrainOptions create(boolean requestVertexNormals) { + CreateWorldTerrainOptions options = new CreateWorldTerrainOptions(); + options.requestVertexNormals = requestVertexNormals; + return options; + } + + /** + * Create instance for {@link Cesium#createWorldTerrain()}. + * + * @param requestVertexNormals Flag that indicates if the client should request + * additional lighting information from the server + * if available. + * @param requestWaterMask Flag that indicates if the client should request + * per tile water masks from the server if + * available. + * @return instance for {@link Cesium#createWorldTerrain()}. + */ + @JsOverlay + public static CreateWorldTerrainOptions create(boolean requestVertexNormals, boolean requestWaterMask) { + CreateWorldTerrainOptions options = new CreateWorldTerrainOptions(); + options.requestVertexNormals = requestVertexNormals; + options.requestWaterMask = requestWaterMask; + return options; + } } - } - /** - * Options for {@link Cesium#createElevationBandMaterial(ElevationBandMaterialOptions)}. - */ - @JsType(isNative = true, namespace = JsPackage.GLOBAL, name = "Object") - public static class ElevationBandMaterialOptions { /** - * The scene where the visualization is taking place. + * Options for {@link Cesium#exportKml(ExportKmlOptions)} */ - @JsProperty - public Scene scene; + @JsType(isNative = true, namespace = JsPackage.GLOBAL, name = "Object") + public static class ExportKmlOptions { + /** + * The EntityCollection to export as KML. + */ + @JsProperty + public EntityCollection entities; + /** + * The ellipsoid for the output file. Default: {@link Ellipsoid#WGS84()} + */ + @JsProperty + public Ellipsoid ellipsoid; + /** + * A callback that will be called with a ModelGraphics instance and should + * return the URI to use in the KML. Required if a model exists in the entity + * collection. + */ + @JsProperty + public ModelCallback modelCallback; + /** + * The time value to use to get properties that are not time varying in KML. + */ + @JsProperty + public JulianDate time; + /** + * The interval that will be sampled if an entity doesn't have an availability. + */ + @JsProperty + public TimeInterval defaultAvailability; + /** + * The number of seconds to sample properties that are varying in KML. Default: + * 60 + */ + @JsProperty + public int sampleDuration; + /** + * If true KML and external files will be compressed into a kmz file. Default: + * false + */ + @JsProperty + public boolean kmz; + + @JsConstructor + private ExportKmlOptions() { + } + + @JsOverlay + public static ExportKmlOptions create(EntityCollection entities) { + ExportKmlOptions options = new ExportKmlOptions(); + options.entities = entities; + return options; + } + + /** + * Since KML does not support glTF models, this callback is required to specify + * what URL to use for the model in the KML document. It can also be used to add + * additional files to the externalFiles object, which is the list of files + * embedded in the exported KMZ, or otherwise returned with the KML string when + * exporting. + */ + @JsFunction + public interface ModelCallback { + /** + * Since KML does not support glTF models, this callback is required to specify + * what URL to use for the model in the KML document. It can also be used to add + * additional files to the externalFiles object, which is the list of files + * embedded in the exported KMZ, or otherwise returned with the KML string when + * exporting. + * + * @param model The ModelGraphics instance for an Entity. + * @param time The time that any properties should use to get the + * value. + * @param externalFiles An object that maps a filename to a Blob or a Promise + * that resolves to a Blob. + * @return The URL to use for the href in the KML document. + */ + String Callback(ModelGraphics model, org.cesiumjs.cs.core.JulianDate time, JsObject externalFiles); + } + } + /** - * A list of bands ordered from lowest to highest precedence. + * Options for {@link Cesium#createElevationBandMaterial(ElevationBandMaterialOptions)}. */ - @JsProperty - public ElevationBandMaterialBand[] layers; - - @JsConstructor - protected ElevationBandMaterialOptions() {} - - @JsOverlay - public static ElevationBandMaterialOptions create(Scene scene, ElevationBandMaterialBand[] layers) { - ElevationBandMaterialOptions options = new ElevationBandMaterialOptions(); - options.scene = scene; - options.layers = layers; - return options; + @JsType(isNative = true, namespace = JsPackage.GLOBAL, name = "Object") + public static class ElevationBandMaterialOptions { + /** + * The scene where the visualization is taking place. + */ + @JsProperty + public Scene scene; + /** + * A list of bands ordered from lowest to highest precedence. + */ + @JsProperty + public ElevationBandMaterialBand[] layers; + + @JsConstructor + protected ElevationBandMaterialOptions() { + } + + @JsOverlay + public static ElevationBandMaterialOptions create(Scene scene, ElevationBandMaterialBand[] layers) { + ElevationBandMaterialOptions options = new ElevationBandMaterialOptions(); + options.scene = scene; + options.layers = layers; + return options; + } } - } } diff --git a/cesiumjs4gwt-main/src/main/java/org/cesiumjs/cs/CesiumEntryPoint.java b/cesiumjs4gwt-main/src/main/java/org/cesiumjs/cs/CesiumEntryPoint.java index b1eccaa97ad9eb32fc36b30e3ad97f4b658493a6..ee4ee3573472cda30a7b9e89ce6bc7a8dff01376 100644 --- a/cesiumjs4gwt-main/src/main/java/org/cesiumjs/cs/CesiumEntryPoint.java +++ b/cesiumjs4gwt-main/src/main/java/org/cesiumjs/cs/CesiumEntryPoint.java @@ -23,16 +23,16 @@ import com.google.gwt.core.client.GWT; * @author Serge Silaev aka iSergio */ public class CesiumEntryPoint implements EntryPoint { - @Override - public void onModuleLoad() { - Cesium.fixSmartGWT(); - GWT.log("Cesium GTW module loaded"); - if (!Cesium.isInitialized()) { - String message = "The Core of Cesium (Cesium.js) JavaScript libraryes not loaded.\n" - + "If you inherit Cesium from NoScript gwt.xml, \nyou need include ');\n" + "}\n"; - } - - private String getScriptLoadJS(Set scriptsToLoad, String pageRelativeModulePath) { - String result = "if (!window." + LOADED_SCRIPTS + ") window." + LOADED_SCRIPTS + " = {};\n"; - for (ScriptReference script : scriptsToLoad) { - String src = script.getSrc(); - if (!src.startsWith("cs/")) { - continue; - } - result += "if (!" + LOADED_SCRIPTS + "['" + src + "']) {\n " + LOADED_SCRIPTS + "['" + src + "'] = true;\n " - + "document.write('');\n}\n"; - System.out.println(src); + private static final String SCRIPT_LOADER = "loadCesiumScripts.js"; + private static final String LOADED_SCRIPTS = "__gwt_cesiumScriptsLoaded"; + private static final String PAGE_RELATIVE_MODULE_PATH = "cesiumScriptInjector.pageRelativeModulePath"; + + private static String getPageRelativeModulePath(LinkerContext context) { + String moduleName = context.getModuleName(); + + List pathBindings = null; + for (ConfigurationProperty property : context.getConfigurationProperties()) { + if (PAGE_RELATIVE_MODULE_PATH.equals(property.getName())) { + pathBindings = property.getValues(); + } + } + if (pathBindings == null) + return moduleName; + + for (String binding : pathBindings) { + String[] parts = binding.split("="); + if (parts.length == 2 && moduleName.equals(parts[0])) { + System.out + .println(" Setting page-relative module path for module '" + moduleName + "' using gwt.xml config"); + return parts[1]; + } + } + + return moduleName; } - return result; - } - private static String getPageRelativeModulePath(LinkerContext context) { - String moduleName = context.getModuleName(); - - List pathBindings = null; - for (ConfigurationProperty property : context.getConfigurationProperties()) { - if (PAGE_RELATIVE_MODULE_PATH.equals(property.getName())) { - pathBindings = property.getValues(); - } + private boolean forceScriptLoad(TreeLogger logger, String moduleName, Float gwtVersion) { + try { + ModuleDef module; + Method getModuleDef; + + if (gwtVersion < 2.6f) { + getModuleDef = ModuleDefLoader.class.getDeclaredMethod("loadFromClassPath", + TreeLogger.class, String.class); + module = (ModuleDef) getModuleDef.invoke(null, logger, moduleName); + } else if (gwtVersion < 2.8f) { + Class compilerContextClass = Class.forName("com.google.gwt.dev.CompilerContext"); + Object context = compilerContextClass.getDeclaredConstructor().newInstance(); + + getModuleDef = ModuleDefLoader.class.getDeclaredMethod("loadFromClassPath", + TreeLogger.class, compilerContextClass, String.class); + module = (ModuleDef) getModuleDef.invoke(null, logger, compilerContextClass.cast(context), moduleName); + } else { + getModuleDef = ModuleDefLoader.class.getDeclaredMethod("loadFromClassPath", + TreeLogger.class, String.class, boolean.class); + module = (ModuleDef) getModuleDef.invoke(null, logger, moduleName, false); + } + + if (module != null) + return CrossSiteIframeLinker.class.equals(module.getActivePrimaryLinker()); + logger.log(TreeLogger.WARN, "Can't find module reference - not injecting scripts."); + + } catch (Throwable t) { + logger.log(TreeLogger.ERROR, "Encountered an exception while trying to resolve the ModuleDef for " + moduleName, + t); + } + return false; } - if (pathBindings == null) - return moduleName; - - for (String binding : pathBindings) { - String[] parts = binding.split("="); - if (parts.length == 2 && moduleName.equals(parts[0])) { - System.out - .println(" Setting page-relative module path for module '" + moduleName + "' using gwt.xml config"); - return parts[1]; - } + + private String getScriptLoaderJS(String pageRelativeModulePath) { + return "if (!/loaded|complete/.test(document.readyState)) {\n" + " document.write('');\n" + "}\n"; } - return moduleName; - } + private String getScriptLoadJS(Set scriptsToLoad, String pageRelativeModulePath) { + String result = "if (!window." + LOADED_SCRIPTS + ") window." + LOADED_SCRIPTS + " = {};\n"; + for (ScriptReference script : scriptsToLoad) { + String src = script.getSrc(); + if (!src.startsWith("cs/")) { + continue; + } + result += "if (!" + LOADED_SCRIPTS + "['" + src + "']) {\n " + LOADED_SCRIPTS + "['" + src + "'] = true;\n " + + "document.write('');\n}\n"; + System.out.println(src); + } + return result; + } - @Override - public String getDescription() { - return "CesiumScriptInjector"; - } + @Override + public String getDescription() { + return "CesiumScriptInjector"; + } - protected SyntheticArtifact emitString(TreeLogger logger, String what, String partialPath, LinkerContext context) - throws UnableToCompleteException { - if (context.isOutputCompact()) { - what = what.replaceAll("\n\\s*", ""); + protected SyntheticArtifact emitString(TreeLogger logger, String what, String partialPath, LinkerContext context) + throws UnableToCompleteException { + if (context.isOutputCompact()) { + what = what.replaceAll("\n\\s*", ""); + } + return super.emitString(logger, what, partialPath); } - return super.emitString(logger, what, partialPath); - } - @Override - public ArtifactSet link(TreeLogger logger, LinkerContext context, ArtifactSet artifacts, boolean permutation) - throws UnableToCompleteException { - Float gwtVersion = Float.parseFloat(About.getGwtVersionNum().replaceFirst("([0-9]+\\.[0-9]+).*", "$1")); - String moduleName = context.getModuleName(); + @Override + public ArtifactSet link(TreeLogger logger, LinkerContext context, ArtifactSet artifacts, boolean permutation) + throws UnableToCompleteException { + Float gwtVersion = Float.parseFloat(About.getGwtVersionNum().replaceFirst("([0-9]+\\.[0-9]+).*", "$1")); + String moduleName = context.getModuleName(); - if (permutation) { - return artifacts; - } + if (permutation) { + return artifacts; + } - Artifact scriptLoader = emitString(logger, "", SCRIPT_LOADER); - ArtifactSet result = new ArtifactSet(artifacts); - result.add(scriptLoader); + Artifact scriptLoader = emitString(logger, "", SCRIPT_LOADER); + ArtifactSet result = new ArtifactSet(artifacts); + result.add(scriptLoader); - if (gwtVersion < 2.5f || !forceScriptLoad(logger, moduleName, gwtVersion)) { - return result; - } + if (gwtVersion < 2.5f || !forceScriptLoad(logger, moduleName, gwtVersion)) { + return result; + } - Set scripts = result.find(ScriptReference.class); - if (scripts.size() == 0) { - return result; - } + Set scripts = result.find(ScriptReference.class); + if (scripts.size() == 0) { + return result; + } - Set emittedArtifacts = artifacts.find(EmittedArtifact.class); - for (EmittedArtifact emittedArtifact : emittedArtifacts) { - String partialPath = emittedArtifact.getPartialPath(); - if (!partialPath.endsWith(moduleName + ".nocache.js")) - continue; + Set emittedArtifacts = artifacts.find(EmittedArtifact.class); + for (EmittedArtifact emittedArtifact : emittedArtifacts) { + String partialPath = emittedArtifact.getPartialPath(); + if (!partialPath.endsWith(moduleName + ".nocache.js")) + continue; - System.out.println(" Invoking Linker CesiumScriptInjector"); + System.out.println(" Invoking Linker CesiumScriptInjector"); - String pageRelativeModulePath = getPageRelativeModulePath(context); + String pageRelativeModulePath = getPageRelativeModulePath(context); - System.out.println(" Creating " + SCRIPT_LOADER + " to manually load the following script tags:"); + System.out.println(" Creating " + SCRIPT_LOADER + " to manually load the following script tags:"); - result.remove(emittedArtifact); - String nocacheJS = CesiumLinkerUtils.getContents(emittedArtifact, logger); - nocacheJS += getScriptLoaderJS(pageRelativeModulePath); - result.add(emitString(logger, nocacheJS, partialPath, context)); + result.remove(emittedArtifact); + String nocacheJS = CesiumLinkerUtils.getContents(emittedArtifact, logger); + nocacheJS += getScriptLoaderJS(pageRelativeModulePath); + result.add(emitString(logger, nocacheJS, partialPath, context)); - result.remove(scriptLoader); - String loadTags = getScriptLoadJS(scripts, pageRelativeModulePath); - result.add(emitString(logger, loadTags, SCRIPT_LOADER, context)); + result.remove(scriptLoader); + String loadTags = getScriptLoadJS(scripts, pageRelativeModulePath); + result.add(emitString(logger, loadTags, SCRIPT_LOADER, context)); - break; - } + break; + } - return result; - } + return result; + } } diff --git a/cesiumjs4gwt-main/src/main/resources/org/cesiumjs/Cesium.gwt.xml b/cesiumjs4gwt-main/src/main/resources/org/cesiumjs/Cesium.gwt.xml index 19151f7c513103c948332099bdf66c2914d98844..4c6bff72b27fbec66b428a7a8afec8fdc6403404 100644 --- a/cesiumjs4gwt-main/src/main/resources/org/cesiumjs/Cesium.gwt.xml +++ b/cesiumjs4gwt-main/src/main/resources/org/cesiumjs/Cesium.gwt.xml @@ -20,6 +20,6 @@ - - + + \ No newline at end of file diff --git a/cesiumjs4gwt-main/src/main/resources/org/cesiumjs/CesiumClientBundle.gwt.xml b/cesiumjs4gwt-main/src/main/resources/org/cesiumjs/CesiumClientBundle.gwt.xml index 8c6d4dc79c516e670839ee91024a3dc1775f044d..790919ae71737e24b24aa53f06de473deb56810a 100644 --- a/cesiumjs4gwt-main/src/main/resources/org/cesiumjs/CesiumClientBundle.gwt.xml +++ b/cesiumjs4gwt-main/src/main/resources/org/cesiumjs/CesiumClientBundle.gwt.xml @@ -16,11 +16,11 @@ - - - + + + - + diff --git a/cesiumjs4gwt-main/src/main/resources/org/cesiumjs/CesiumNoScript.gwt.xml b/cesiumjs4gwt-main/src/main/resources/org/cesiumjs/CesiumNoScript.gwt.xml index 2c8cb3f6fbcec3f250d59d60bda8a317ff2b9f64..97513e81d141ff6dd28d94a39b24a1230b778779 100644 --- a/cesiumjs4gwt-main/src/main/resources/org/cesiumjs/CesiumNoScript.gwt.xml +++ b/cesiumjs4gwt-main/src/main/resources/org/cesiumjs/CesiumNoScript.gwt.xml @@ -20,16 +20,16 @@ - - + + - + - - + + diff --git a/cesiumjs4gwt-main/src/main/resources/org/cesiumjs/CesiumScript.gwt.xml b/cesiumjs4gwt-main/src/main/resources/org/cesiumjs/CesiumScript.gwt.xml index d31ef129490b65ade5d16455afc737fad8a0ef9a..33ba9a795aa7ed497449d88e93e0cd10b0a95eec 100644 --- a/cesiumjs4gwt-main/src/main/resources/org/cesiumjs/CesiumScript.gwt.xml +++ b/cesiumjs4gwt-main/src/main/resources/org/cesiumjs/CesiumScript.gwt.xml @@ -19,9 +19,9 @@ -