Migrate Cesium to ES6 Modules
See https://github.com/AnalyticalGraphicsInc/cesium/pull/8224 for details.
eslint
There are a handful of new .eslintrc.json files, mostly to identify the files that are still AMD modules (Sandcastle/Workers). These are needed because you can't change the parser type with a comment directive (since the parser is the thing reading the file). We can finally detect unusued modules! So those have all been cleaned up as well.
requirejs -> rollup & clean-css
requirejs, almond, and karma-requirejs have all been removed. We now use rollup for building and minifying (via uglify) JS code and clean-css for css. These changes are fairly straight-forward and just involve calling rollup instead of requirejs in the build process.
Overall build time is significantly faster. CI is ~11 minutes compared to ~17 in master. Running makeZipFile on my machine takes 69 seconds compared to 112 seconds in master. There's probably plenty of room for additional optimization here too.
We wrote an published a small npm module, rollup-plugin-strip-pragma, for stripping the requirejs pragmas we use out of the release builds. This is maintained in the Tools/rollup-plugin-strip-pragma directory.
As for what we produce. The built version of Cesium is now a UMD module. So it should work anywhere that hasn't made the jump to ES6 yet. For users that were already using the "legacy" combined/minified approach, nothing changes.
One awesome thing about roll-up is that it compiles all of the workers at once and automatically detects shared codes and generates separate bundles under the hood. This means the size of our worker modules shrink dramatically and Cesium itself will load them much faster. The total minified/gzipped size of all workers in master is 2.6 MB compared to 225 KB in this branch! This should be most noticeable on demos like Geometry & Appearances which load lots of workers for the various geometry typs.
roll-up is also used to build Cesium Viewer, which is now an ES6 app.
We use clean-css via gulp and it is also a straightforward change from requirejs that requires no special mention.
Workers
While the spec allows for ES6 Web Workers, no browser actually supports them yet. That means we needed a way to get our workers into non-ES6 form. Thankfully, roll-up can generate AMD modules, which means we now have a build step to compile our Worker source code back into AMD and use the existing TaskProcessor to load and execute them. This build step is part of the standard build task and is called createWorkers. During development, these "built" workers are un-optimized so you can still debug them and read the code.
Since there is a build step, that means if you are changing code that affects a worker, you need to re-run build, or you can use the build-watch task to do it automatically.
The ES6 versions of Worker code has moved into Source/WorkersES6 and we build the workers into their "old home" of Source/Workers. cesiumWorkerBootstrapper and transferTypedArrayTest which were already non-AMD ES5 scripts remain living in the Workers directory.
Surprisingly little was changed about TaskProcessor or the worker system in general, especially considering that I thought this would be one of the major hurdles.
ThirdParty
A lot of our ThirdParty either already had a hand-written wrapper for AMD (which I updated to ES6) or had UMD which created problems when importing the same code in both Node and the browser. I basically had to update the wrapper of every third-party library to fix these problems. In some cases I updated the library version itself (Autolinker, topojson). Nothing to be too concerned about, but future clean-up would be using npm versions of these libraries and auto-generating the wrappers as needed so we don't hand-edit things.
Sandcastle
Sandcastle is eternal and manages to live another day in it's ancient requirejs/dojo 1.x form. Sandcastle now automatically uses the ES6 version of Cesium if it is available and fallsback to the ES5 unminified version if it is now. The built version of Sandcastle always uses CesiumUnminified, just like master. This means Sandcastle still works in IE11 if you run the combine step first (or use the relase zip)
Removed Cesium usage from Sandcastle proper, since it wasn't really needed
Generate a VERSION propertyin the gallery index since Cesium is no longer being included.
Remove requirejs from Sandcastle bucket
Update bucket to use the built version of Cesium if it is available by fallbackto the ES6 version during development.
Standalone.html was also updated
There's a bit of room for further clean-up here, but I think this gets us into master. I did not rename bucket-requirejs.html because I'm pretty sure it would break previously shared demos. We can put in some backwards compatible code later on if we want. (But I'd rather just see a full Sandcastle rewrite).
Specs
Specs are now all ES6, except for TestWorkers, which remain standard JS worker modules. This means you can no longer run the unbuilt unit tests in IE11. No changes for Chrome and Firefox.
Since the specs use ES6 modules and built Cesium is an ES5 UMD, I added a build-specs build step which generates a combined ES5 version of the specs which rely on Cesium as a global variable. We then inject these files into jasmine instead of the standard specs and everything works exactly as it did before. SpecRunner.html has been updated to inject the correct version of the script depending on the build/release query parameters.
The Specs must always use Cesium by importing Source/Cesium.js, this is so we can replace it with the built Cesium as describe above.
There's a bunch of room for clean-up here, such as unifying our two copies of jasmine into a single helper file, but I didn't want to start doing that clean-up as part of this already overly big PR. The important thing is that we can still test the built version and still test on IE/Edge as needed.
I also found and fixed two bugs that were causing failing unit tests, one in BingMapsImageryProviderSpec.js (which was overwriting createImage andnot setting it back) and ShadowVolumeAppearance.js (which had a module level caching bug). I think these may have been the cause of random CI failures in master as well, but only time will tell.
For coverage, we had to switch to karma-coverage-istanbul-instrumenter for native ES6 support, but that's it.
Finally, I updated appveryor to build Cesium and run the built tests under IE. We still don't fail the build for IE, but we should probably fix that if we want to keep it going.
NodeJS
When NODE_ENV is production, we now require in the minified CesiumJS directly, which works great because it's now a UMD module. Otherwise, we use the excellant esmpackage to load individual modules, it was a fairly straightforward swap from our old requirejs usage. We could probably drop esm too if we don't care about debugging or if we provie source maps at some point.
2019-10-03 23:51:23 +08:00
|
|
|
import AssociativeArray from "../Core/AssociativeArray.js";
|
|
|
|
|
import Cartesian2 from "../Core/Cartesian2.js";
|
|
|
|
|
import Cartesian3 from "../Core/Cartesian3.js";
|
|
|
|
|
import Color from "../Core/Color.js";
|
|
|
|
|
import defined from "../Core/defined.js";
|
|
|
|
|
import destroyObject from "../Core/destroyObject.js";
|
|
|
|
|
import DeveloperError from "../Core/DeveloperError.js";
|
|
|
|
|
import DistanceDisplayCondition from "../Core/DistanceDisplayCondition.js";
|
|
|
|
|
import NearFarScalar from "../Core/NearFarScalar.js";
|
|
|
|
|
import HeightReference from "../Scene/HeightReference.js";
|
|
|
|
|
import HorizontalOrigin from "../Scene/HorizontalOrigin.js";
|
|
|
|
|
import LabelStyle from "../Scene/LabelStyle.js";
|
|
|
|
|
import VerticalOrigin from "../Scene/VerticalOrigin.js";
|
|
|
|
|
import BoundingSphereState from "./BoundingSphereState.js";
|
|
|
|
|
import Property from "./Property.js";
|
2012-05-09 23:19:47 +08:00
|
|
|
|
2014-07-18 23:28:40 +08:00
|
|
|
const defaultScale = 1.0;
|
|
|
|
|
const defaultFont = "30px sans-serif";
|
|
|
|
|
const defaultStyle = LabelStyle.FILL;
|
|
|
|
|
const defaultFillColor = Color.WHITE;
|
|
|
|
|
const defaultOutlineColor = Color.BLACK;
|
2016-06-16 02:06:58 +08:00
|
|
|
const defaultOutlineWidth = 1.0;
|
2016-11-27 10:40:56 +08:00
|
|
|
const defaultShowBackground = false;
|
|
|
|
|
const defaultBackgroundColor = new Color(0.165, 0.165, 0.165, 0.8);
|
2016-12-07 03:12:29 +08:00
|
|
|
const defaultBackgroundPadding = new Cartesian2(7, 5);
|
2014-07-18 23:28:40 +08:00
|
|
|
const defaultPixelOffset = Cartesian2.ZERO;
|
|
|
|
|
const defaultEyeOffset = Cartesian3.ZERO;
|
2015-04-24 23:31:16 +08:00
|
|
|
const defaultHeightReference = HeightReference.NONE;
|
2014-07-18 23:28:40 +08:00
|
|
|
const defaultHorizontalOrigin = HorizontalOrigin.CENTER;
|
|
|
|
|
const defaultVerticalOrigin = VerticalOrigin.CENTER;
|
|
|
|
|
|
2018-07-18 23:00:16 +08:00
|
|
|
const positionScratch = new Cartesian3();
|
|
|
|
|
const fillColorScratch = new Color();
|
|
|
|
|
const outlineColorScratch = new Color();
|
|
|
|
|
const backgroundColorScratch = new Color();
|
|
|
|
|
const backgroundPaddingScratch = new Cartesian2();
|
|
|
|
|
const eyeOffsetScratch = new Cartesian3();
|
|
|
|
|
const pixelOffsetScratch = new Cartesian2();
|
|
|
|
|
const translucencyByDistanceScratch = new NearFarScalar();
|
|
|
|
|
const pixelOffsetScaleByDistanceScratch = new NearFarScalar();
|
|
|
|
|
const scaleByDistanceScratch = new NearFarScalar();
|
|
|
|
|
const distanceDisplayConditionScratch = new DistanceDisplayCondition();
|
2014-07-29 03:44:37 +08:00
|
|
|
|
2015-12-12 09:31:44 +08:00
|
|
|
function EntityData(entity) {
|
2014-10-24 10:56:09 +08:00
|
|
|
this.entity = entity;
|
|
|
|
|
this.label = undefined;
|
|
|
|
|
this.index = undefined;
|
2015-12-12 09:31:44 +08:00
|
|
|
}
|
2014-10-24 10:56:09 +08:00
|
|
|
|
2012-06-23 04:29:39 +08:00
|
|
|
/**
|
2014-07-03 03:34:44 +08:00
|
|
|
* A {@link Visualizer} which maps the {@link LabelGraphics} instance
|
|
|
|
|
* in {@link Entity#label} to a {@link Label}.
|
|
|
|
|
* @alias LabelVisualizer
|
2012-06-29 07:04:26 +08:00
|
|
|
* @constructor
|
2012-06-23 04:29:39 +08:00
|
|
|
*
|
2016-08-26 05:34:42 +08:00
|
|
|
* @param {EntityCluster} entityCluster The entity cluster to manage the collection of billboards and optionally cluster with other entities.
|
2014-07-03 03:34:44 +08:00
|
|
|
* @param {EntityCollection} entityCollection The entityCollection to visualize.
|
2012-06-23 04:29:39 +08:00
|
|
|
*/
|
2016-08-26 05:34:42 +08:00
|
|
|
function LabelVisualizer(entityCluster, entityCollection) {
|
2013-12-31 04:37:32 +08:00
|
|
|
//>>includeStart('debug', pragmas.debug);
|
2016-08-26 05:34:42 +08:00
|
|
|
if (!defined(entityCluster)) {
|
|
|
|
|
throw new DeveloperError("entityCluster is required.");
|
2012-06-29 01:24:01 +08:00
|
|
|
}
|
2014-07-03 03:34:44 +08:00
|
|
|
if (!defined(entityCollection)) {
|
|
|
|
|
throw new DeveloperError("entityCollection is required.");
|
2014-04-27 10:16:05 +08:00
|
|
|
}
|
2013-12-31 04:37:32 +08:00
|
|
|
//>>includeEnd('debug');
|
|
|
|
|
|
2014-07-29 11:37:22 +08:00
|
|
|
entityCollection.collectionChanged.addEventListener(
|
|
|
|
|
LabelVisualizer.prototype._onCollectionChanged,
|
|
|
|
|
this,
|
|
|
|
|
);
|
2012-05-08 21:56:22 +08:00
|
|
|
|
2016-08-26 05:34:42 +08:00
|
|
|
this._cluster = entityCluster;
|
2014-07-03 03:34:44 +08:00
|
|
|
this._entityCollection = entityCollection;
|
2014-10-24 10:56:09 +08:00
|
|
|
this._items = new AssociativeArray();
|
2014-07-29 11:37:22 +08:00
|
|
|
|
2015-02-01 06:29:09 +08:00
|
|
|
this._onCollectionChanged(entityCollection, entityCollection.values, [], []);
|
2015-12-12 09:31:44 +08:00
|
|
|
}
|
2012-06-06 22:00:07 +08:00
|
|
|
|
2012-06-23 04:29:39 +08:00
|
|
|
/**
|
2014-04-28 01:14:19 +08:00
|
|
|
* Updates the primitives created by this visualizer to match their
|
2014-07-03 03:34:44 +08:00
|
|
|
* Entity counterpart at the given time.
|
2012-06-23 04:29:39 +08:00
|
|
|
*
|
|
|
|
|
* @param {JulianDate} time The time to update to.
|
2023-02-10 16:35:41 +08:00
|
|
|
* @returns {boolean} This function always returns true.
|
2012-06-23 04:29:39 +08:00
|
|
|
*/
|
2014-07-03 03:34:44 +08:00
|
|
|
LabelVisualizer.prototype.update = function (time) {
|
2013-12-31 04:37:32 +08:00
|
|
|
//>>includeStart('debug', pragmas.debug);
|
2013-08-12 11:05:36 +08:00
|
|
|
if (!defined(time)) {
|
2014-02-22 00:07:04 +08:00
|
|
|
throw new DeveloperError("time is required.");
|
2012-06-23 04:29:39 +08:00
|
|
|
}
|
2013-12-31 04:37:32 +08:00
|
|
|
//>>includeEnd('debug');
|
|
|
|
|
|
2014-10-24 10:56:09 +08:00
|
|
|
const items = this._items.values;
|
2016-08-26 05:34:42 +08:00
|
|
|
const cluster = this._cluster;
|
2016-08-24 03:53:14 +08:00
|
|
|
|
2014-10-24 10:56:09 +08:00
|
|
|
for (let i = 0, len = items.length; i < len; i++) {
|
|
|
|
|
const item = items[i];
|
|
|
|
|
const entity = item.entity;
|
2014-07-29 03:44:37 +08:00
|
|
|
const labelGraphics = entity._label;
|
|
|
|
|
let text;
|
2014-10-24 10:56:09 +08:00
|
|
|
let label = item.label;
|
2015-03-25 08:50:24 +08:00
|
|
|
let show =
|
|
|
|
|
entity.isShowing &&
|
|
|
|
|
entity.isAvailable(time) &&
|
|
|
|
|
Property.getValueOrDefault(labelGraphics._show, time, true);
|
2018-07-18 23:00:16 +08:00
|
|
|
let position;
|
2014-07-29 03:44:37 +08:00
|
|
|
if (show) {
|
2018-07-18 23:00:16 +08:00
|
|
|
position = Property.getValueOrUndefined(
|
|
|
|
|
entity._position,
|
|
|
|
|
time,
|
|
|
|
|
positionScratch,
|
|
|
|
|
);
|
2014-07-29 03:44:37 +08:00
|
|
|
text = Property.getValueOrUndefined(labelGraphics._text, time);
|
|
|
|
|
show = defined(position) && defined(text);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!show) {
|
|
|
|
|
//don't bother creating or updating anything else
|
2016-10-05 05:30:59 +08:00
|
|
|
returnPrimitive(item, entity, cluster);
|
2014-07-29 03:44:37 +08:00
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-28 03:39:02 +08:00
|
|
|
if (!Property.isConstant(entity._position)) {
|
|
|
|
|
cluster._clusterDirty = true;
|
|
|
|
|
}
|
2014-10-24 10:56:09 +08:00
|
|
|
|
2019-01-25 15:00:03 +08:00
|
|
|
let updateClamping = false;
|
|
|
|
|
const heightReference = Property.getValueOrDefault(
|
|
|
|
|
labelGraphics._heightReference,
|
|
|
|
|
time,
|
|
|
|
|
defaultHeightReference,
|
|
|
|
|
);
|
|
|
|
|
|
2014-10-24 10:56:09 +08:00
|
|
|
if (!defined(label)) {
|
2016-08-24 03:53:14 +08:00
|
|
|
label = cluster.getLabel(entity);
|
2014-07-29 03:44:37 +08:00
|
|
|
label.id = entity;
|
2014-10-24 10:56:09 +08:00
|
|
|
item.label = label;
|
2019-01-25 15:00:03 +08:00
|
|
|
|
|
|
|
|
// If this new label happens to have a position and height reference that match our new values,
|
|
|
|
|
// label._updateClamping will not be called automatically. That's a problem because the clamped
|
|
|
|
|
// height may be based on different terrain than is now loaded. So we'll manually call
|
|
|
|
|
// _updateClamping below.
|
|
|
|
|
updateClamping =
|
|
|
|
|
Cartesian3.equals(label.position, position) &&
|
|
|
|
|
label.heightReference === heightReference;
|
2014-07-29 03:44:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
label.show = true;
|
|
|
|
|
label.position = position;
|
|
|
|
|
label.text = text;
|
|
|
|
|
label.scale = Property.getValueOrDefault(
|
|
|
|
|
labelGraphics._scale,
|
|
|
|
|
time,
|
|
|
|
|
defaultScale,
|
|
|
|
|
);
|
|
|
|
|
label.font = Property.getValueOrDefault(
|
|
|
|
|
labelGraphics._font,
|
|
|
|
|
time,
|
|
|
|
|
defaultFont,
|
|
|
|
|
);
|
|
|
|
|
label.style = Property.getValueOrDefault(
|
|
|
|
|
labelGraphics._style,
|
|
|
|
|
time,
|
|
|
|
|
defaultStyle,
|
|
|
|
|
);
|
2018-07-18 23:00:16 +08:00
|
|
|
label.fillColor = Property.getValueOrDefault(
|
|
|
|
|
labelGraphics._fillColor,
|
|
|
|
|
time,
|
|
|
|
|
defaultFillColor,
|
|
|
|
|
fillColorScratch,
|
|
|
|
|
);
|
|
|
|
|
label.outlineColor = Property.getValueOrDefault(
|
|
|
|
|
labelGraphics._outlineColor,
|
|
|
|
|
time,
|
|
|
|
|
defaultOutlineColor,
|
|
|
|
|
outlineColorScratch,
|
|
|
|
|
);
|
2014-07-29 03:44:37 +08:00
|
|
|
label.outlineWidth = Property.getValueOrDefault(
|
|
|
|
|
labelGraphics._outlineWidth,
|
|
|
|
|
time,
|
|
|
|
|
defaultOutlineWidth,
|
|
|
|
|
);
|
2016-11-27 10:40:56 +08:00
|
|
|
label.showBackground = Property.getValueOrDefault(
|
|
|
|
|
labelGraphics._showBackground,
|
|
|
|
|
time,
|
|
|
|
|
defaultShowBackground,
|
|
|
|
|
);
|
2018-07-18 23:00:16 +08:00
|
|
|
label.backgroundColor = Property.getValueOrDefault(
|
|
|
|
|
labelGraphics._backgroundColor,
|
|
|
|
|
time,
|
|
|
|
|
defaultBackgroundColor,
|
|
|
|
|
backgroundColorScratch,
|
|
|
|
|
);
|
|
|
|
|
label.backgroundPadding = Property.getValueOrDefault(
|
|
|
|
|
labelGraphics._backgroundPadding,
|
|
|
|
|
time,
|
|
|
|
|
defaultBackgroundPadding,
|
|
|
|
|
backgroundPaddingScratch,
|
|
|
|
|
);
|
|
|
|
|
label.pixelOffset = Property.getValueOrDefault(
|
|
|
|
|
labelGraphics._pixelOffset,
|
|
|
|
|
time,
|
|
|
|
|
defaultPixelOffset,
|
|
|
|
|
pixelOffsetScratch,
|
|
|
|
|
);
|
|
|
|
|
label.eyeOffset = Property.getValueOrDefault(
|
|
|
|
|
labelGraphics._eyeOffset,
|
|
|
|
|
time,
|
|
|
|
|
defaultEyeOffset,
|
|
|
|
|
eyeOffsetScratch,
|
|
|
|
|
);
|
2019-01-25 15:00:03 +08:00
|
|
|
label.heightReference = heightReference;
|
2014-07-29 03:44:37 +08:00
|
|
|
label.horizontalOrigin = Property.getValueOrDefault(
|
|
|
|
|
labelGraphics._horizontalOrigin,
|
|
|
|
|
time,
|
|
|
|
|
defaultHorizontalOrigin,
|
|
|
|
|
);
|
|
|
|
|
label.verticalOrigin = Property.getValueOrDefault(
|
|
|
|
|
labelGraphics._verticalOrigin,
|
|
|
|
|
time,
|
|
|
|
|
defaultVerticalOrigin,
|
|
|
|
|
);
|
2018-07-18 23:00:16 +08:00
|
|
|
label.translucencyByDistance = Property.getValueOrUndefined(
|
|
|
|
|
labelGraphics._translucencyByDistance,
|
|
|
|
|
time,
|
|
|
|
|
translucencyByDistanceScratch,
|
|
|
|
|
);
|
|
|
|
|
label.pixelOffsetScaleByDistance = Property.getValueOrUndefined(
|
|
|
|
|
labelGraphics._pixelOffsetScaleByDistance,
|
|
|
|
|
time,
|
|
|
|
|
pixelOffsetScaleByDistanceScratch,
|
|
|
|
|
);
|
|
|
|
|
label.scaleByDistance = Property.getValueOrUndefined(
|
|
|
|
|
labelGraphics._scaleByDistance,
|
|
|
|
|
time,
|
|
|
|
|
scaleByDistanceScratch,
|
|
|
|
|
);
|
|
|
|
|
label.distanceDisplayCondition = Property.getValueOrUndefined(
|
|
|
|
|
labelGraphics._distanceDisplayCondition,
|
|
|
|
|
time,
|
|
|
|
|
distanceDisplayConditionScratch,
|
2018-07-26 03:52:49 +08:00
|
|
|
);
|
|
|
|
|
label.disableDepthTestDistance = Property.getValueOrUndefined(
|
|
|
|
|
labelGraphics._disableDepthTestDistance,
|
|
|
|
|
time,
|
2020-04-17 08:31:36 +08:00
|
|
|
);
|
2019-01-25 15:00:03 +08:00
|
|
|
|
|
|
|
|
if (updateClamping) {
|
|
|
|
|
label._updateClamping();
|
|
|
|
|
}
|
2012-06-23 04:29:39 +08:00
|
|
|
}
|
2014-04-15 02:38:25 +08:00
|
|
|
return true;
|
2012-06-23 04:29:39 +08:00
|
|
|
};
|
|
|
|
|
|
2015-01-14 01:24:48 +08:00
|
|
|
/**
|
2015-01-19 03:46:44 +08:00
|
|
|
* Computes a bounding sphere which encloses the visualization produced for the specified entity.
|
2015-01-20 12:35:36 +08:00
|
|
|
* The bounding sphere is in the fixed frame of the scene's globe.
|
2015-01-14 05:32:53 +08:00
|
|
|
*
|
2015-01-19 03:46:44 +08:00
|
|
|
* @param {Entity} entity The entity whose bounding sphere to compute.
|
|
|
|
|
* @param {BoundingSphere} result The bounding sphere onto which to store the result.
|
2015-01-19 04:20:39 +08:00
|
|
|
* @returns {BoundingSphereState} BoundingSphereState.DONE if the result contains the bounding sphere,
|
|
|
|
|
* BoundingSphereState.PENDING if the result is still being computed, or
|
|
|
|
|
* BoundingSphereState.FAILED if the entity has no visualization in the current scene.
|
2015-01-24 00:43:37 +08:00
|
|
|
* @private
|
2015-01-14 01:24:48 +08:00
|
|
|
*/
|
2015-01-16 07:00:59 +08:00
|
|
|
LabelVisualizer.prototype.getBoundingSphere = function (entity, result) {
|
2015-01-14 01:24:48 +08:00
|
|
|
//>>includeStart('debug', pragmas.debug);
|
|
|
|
|
if (!defined(entity)) {
|
|
|
|
|
throw new DeveloperError("entity is required.");
|
|
|
|
|
}
|
2015-01-16 07:00:59 +08:00
|
|
|
if (!defined(result)) {
|
|
|
|
|
throw new DeveloperError("result is required.");
|
|
|
|
|
}
|
2015-01-14 01:24:48 +08:00
|
|
|
//>>includeEnd('debug');
|
|
|
|
|
|
|
|
|
|
const item = this._items.get(entity.id);
|
2015-01-20 00:29:05 +08:00
|
|
|
if (!defined(item) || !defined(item.label)) {
|
2015-01-19 04:20:39 +08:00
|
|
|
return BoundingSphereState.FAILED;
|
2015-01-14 01:24:48 +08:00
|
|
|
}
|
|
|
|
|
|
2015-04-30 03:53:40 +08:00
|
|
|
const label = item.label;
|
|
|
|
|
result.center = Cartesian3.clone(
|
2025-03-04 03:03:53 +08:00
|
|
|
label._clampedPosition ?? label.position,
|
2015-04-30 03:53:40 +08:00
|
|
|
result.center,
|
|
|
|
|
);
|
2015-01-20 00:29:05 +08:00
|
|
|
result.radius = 0;
|
|
|
|
|
return BoundingSphereState.DONE;
|
2015-01-14 01:24:48 +08:00
|
|
|
};
|
|
|
|
|
|
2014-04-29 05:55:41 +08:00
|
|
|
/**
|
|
|
|
|
* Returns true if this object was destroyed; otherwise, false.
|
|
|
|
|
*
|
2023-02-10 16:35:41 +08:00
|
|
|
* @returns {boolean} True if this object was destroyed; otherwise, false.
|
2014-04-29 05:55:41 +08:00
|
|
|
*/
|
2014-07-03 03:34:44 +08:00
|
|
|
LabelVisualizer.prototype.isDestroyed = function () {
|
2014-04-29 05:55:41 +08:00
|
|
|
return false;
|
|
|
|
|
};
|
|
|
|
|
|
2012-06-23 04:29:39 +08:00
|
|
|
/**
|
2014-04-27 10:16:05 +08:00
|
|
|
* Removes and destroys all primitives created by this instance.
|
2012-06-23 04:29:39 +08:00
|
|
|
*/
|
2014-07-03 03:34:44 +08:00
|
|
|
LabelVisualizer.prototype.destroy = function () {
|
2014-10-24 10:56:09 +08:00
|
|
|
this._entityCollection.collectionChanged.removeEventListener(
|
|
|
|
|
LabelVisualizer.prototype._onCollectionChanged,
|
|
|
|
|
this,
|
|
|
|
|
);
|
2016-10-27 23:13:30 +08:00
|
|
|
const entities = this._entityCollection.values;
|
|
|
|
|
for (let i = 0; i < entities.length; i++) {
|
|
|
|
|
this._cluster.removeLabel(entities[i]);
|
|
|
|
|
}
|
2012-06-23 04:29:39 +08:00
|
|
|
return destroyObject(this);
|
|
|
|
|
};
|
|
|
|
|
|
2014-07-29 11:37:22 +08:00
|
|
|
LabelVisualizer.prototype._onCollectionChanged = function (
|
|
|
|
|
entityCollection,
|
|
|
|
|
added,
|
|
|
|
|
removed,
|
|
|
|
|
changed,
|
|
|
|
|
) {
|
|
|
|
|
let i;
|
|
|
|
|
let entity;
|
2014-10-24 10:56:09 +08:00
|
|
|
const items = this._items;
|
2016-08-26 05:34:42 +08:00
|
|
|
const cluster = this._cluster;
|
2014-07-29 11:37:22 +08:00
|
|
|
|
|
|
|
|
for (i = added.length - 1; i > -1; i--) {
|
|
|
|
|
entity = added[i];
|
|
|
|
|
if (defined(entity._label) && defined(entity._position)) {
|
2014-10-24 10:56:09 +08:00
|
|
|
items.set(entity.id, new EntityData(entity));
|
2014-07-29 11:37:22 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (i = changed.length - 1; i > -1; i--) {
|
|
|
|
|
entity = changed[i];
|
|
|
|
|
if (defined(entity._label) && defined(entity._position)) {
|
2014-10-24 10:56:09 +08:00
|
|
|
if (!items.contains(entity.id)) {
|
|
|
|
|
items.set(entity.id, new EntityData(entity));
|
|
|
|
|
}
|
2014-07-29 11:37:22 +08:00
|
|
|
} else {
|
2016-10-05 05:30:59 +08:00
|
|
|
returnPrimitive(items.get(entity.id), entity, cluster);
|
2014-10-24 10:56:09 +08:00
|
|
|
items.remove(entity.id);
|
2012-06-06 22:00:07 +08:00
|
|
|
}
|
2012-05-09 23:19:47 +08:00
|
|
|
}
|
2014-07-29 11:37:22 +08:00
|
|
|
|
|
|
|
|
for (i = removed.length - 1; i > -1; i--) {
|
|
|
|
|
entity = removed[i];
|
2016-10-05 05:30:59 +08:00
|
|
|
returnPrimitive(items.get(entity.id), entity, cluster);
|
2014-10-24 10:56:09 +08:00
|
|
|
items.remove(entity.id);
|
2014-07-29 11:37:22 +08:00
|
|
|
}
|
2012-05-08 21:56:22 +08:00
|
|
|
};
|
|
|
|
|
|
2016-10-05 05:30:59 +08:00
|
|
|
function returnPrimitive(item, entity, cluster) {
|
|
|
|
|
if (defined(item)) {
|
|
|
|
|
item.label = undefined;
|
|
|
|
|
cluster.removeLabel(entity);
|
|
|
|
|
}
|
|
|
|
|
}
|
Migrate Cesium to ES6 Modules
See https://github.com/AnalyticalGraphicsInc/cesium/pull/8224 for details.
eslint
There are a handful of new .eslintrc.json files, mostly to identify the files that are still AMD modules (Sandcastle/Workers). These are needed because you can't change the parser type with a comment directive (since the parser is the thing reading the file). We can finally detect unusued modules! So those have all been cleaned up as well.
requirejs -> rollup & clean-css
requirejs, almond, and karma-requirejs have all been removed. We now use rollup for building and minifying (via uglify) JS code and clean-css for css. These changes are fairly straight-forward and just involve calling rollup instead of requirejs in the build process.
Overall build time is significantly faster. CI is ~11 minutes compared to ~17 in master. Running makeZipFile on my machine takes 69 seconds compared to 112 seconds in master. There's probably plenty of room for additional optimization here too.
We wrote an published a small npm module, rollup-plugin-strip-pragma, for stripping the requirejs pragmas we use out of the release builds. This is maintained in the Tools/rollup-plugin-strip-pragma directory.
As for what we produce. The built version of Cesium is now a UMD module. So it should work anywhere that hasn't made the jump to ES6 yet. For users that were already using the "legacy" combined/minified approach, nothing changes.
One awesome thing about roll-up is that it compiles all of the workers at once and automatically detects shared codes and generates separate bundles under the hood. This means the size of our worker modules shrink dramatically and Cesium itself will load them much faster. The total minified/gzipped size of all workers in master is 2.6 MB compared to 225 KB in this branch! This should be most noticeable on demos like Geometry & Appearances which load lots of workers for the various geometry typs.
roll-up is also used to build Cesium Viewer, which is now an ES6 app.
We use clean-css via gulp and it is also a straightforward change from requirejs that requires no special mention.
Workers
While the spec allows for ES6 Web Workers, no browser actually supports them yet. That means we needed a way to get our workers into non-ES6 form. Thankfully, roll-up can generate AMD modules, which means we now have a build step to compile our Worker source code back into AMD and use the existing TaskProcessor to load and execute them. This build step is part of the standard build task and is called createWorkers. During development, these "built" workers are un-optimized so you can still debug them and read the code.
Since there is a build step, that means if you are changing code that affects a worker, you need to re-run build, or you can use the build-watch task to do it automatically.
The ES6 versions of Worker code has moved into Source/WorkersES6 and we build the workers into their "old home" of Source/Workers. cesiumWorkerBootstrapper and transferTypedArrayTest which were already non-AMD ES5 scripts remain living in the Workers directory.
Surprisingly little was changed about TaskProcessor or the worker system in general, especially considering that I thought this would be one of the major hurdles.
ThirdParty
A lot of our ThirdParty either already had a hand-written wrapper for AMD (which I updated to ES6) or had UMD which created problems when importing the same code in both Node and the browser. I basically had to update the wrapper of every third-party library to fix these problems. In some cases I updated the library version itself (Autolinker, topojson). Nothing to be too concerned about, but future clean-up would be using npm versions of these libraries and auto-generating the wrappers as needed so we don't hand-edit things.
Sandcastle
Sandcastle is eternal and manages to live another day in it's ancient requirejs/dojo 1.x form. Sandcastle now automatically uses the ES6 version of Cesium if it is available and fallsback to the ES5 unminified version if it is now. The built version of Sandcastle always uses CesiumUnminified, just like master. This means Sandcastle still works in IE11 if you run the combine step first (or use the relase zip)
Removed Cesium usage from Sandcastle proper, since it wasn't really needed
Generate a VERSION propertyin the gallery index since Cesium is no longer being included.
Remove requirejs from Sandcastle bucket
Update bucket to use the built version of Cesium if it is available by fallbackto the ES6 version during development.
Standalone.html was also updated
There's a bit of room for further clean-up here, but I think this gets us into master. I did not rename bucket-requirejs.html because I'm pretty sure it would break previously shared demos. We can put in some backwards compatible code later on if we want. (But I'd rather just see a full Sandcastle rewrite).
Specs
Specs are now all ES6, except for TestWorkers, which remain standard JS worker modules. This means you can no longer run the unbuilt unit tests in IE11. No changes for Chrome and Firefox.
Since the specs use ES6 modules and built Cesium is an ES5 UMD, I added a build-specs build step which generates a combined ES5 version of the specs which rely on Cesium as a global variable. We then inject these files into jasmine instead of the standard specs and everything works exactly as it did before. SpecRunner.html has been updated to inject the correct version of the script depending on the build/release query parameters.
The Specs must always use Cesium by importing Source/Cesium.js, this is so we can replace it with the built Cesium as describe above.
There's a bunch of room for clean-up here, such as unifying our two copies of jasmine into a single helper file, but I didn't want to start doing that clean-up as part of this already overly big PR. The important thing is that we can still test the built version and still test on IE/Edge as needed.
I also found and fixed two bugs that were causing failing unit tests, one in BingMapsImageryProviderSpec.js (which was overwriting createImage andnot setting it back) and ShadowVolumeAppearance.js (which had a module level caching bug). I think these may have been the cause of random CI failures in master as well, but only time will tell.
For coverage, we had to switch to karma-coverage-istanbul-instrumenter for native ES6 support, but that's it.
Finally, I updated appveryor to build Cesium and run the built tests under IE. We still don't fail the build for IE, but we should probably fix that if we want to keep it going.
NodeJS
When NODE_ENV is production, we now require in the minified CesiumJS directly, which works great because it's now a UMD module. Otherwise, we use the excellant esmpackage to load individual modules, it was a fairly straightforward swap from our old requirejs usage. We could probably drop esm too if we don't care about debugging or if we provie source maps at some point.
2019-10-03 23:51:23 +08:00
|
|
|
export default LabelVisualizer;
|