cesium/packages/engine/Source/Scene/GetFeatureInfoFormat.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

397 lines
12 KiB
JavaScript
Raw Permalink Normal View History

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 Cartographic from "../Core/Cartographic.js";
import defined from "../Core/defined.js";
import DeveloperError from "../Core/DeveloperError.js";
import RuntimeError from "../Core/RuntimeError.js";
import ImageryLayerFeatureInfo from "./ImageryLayerFeatureInfo.js";
2020-04-17 08:31:36 +08:00
2015-05-18 14:19:32 +08:00
/**
* Describes the format in which to request GetFeatureInfo from a Web Map Service (WMS) server.
*
* @alias GetFeatureInfoFormat
* @constructor
*
* @param {string} type The type of response to expect from a GetFeatureInfo request. Valid
2015-08-27 04:17:35 +08:00
* values are 'json', 'xml', 'html', or 'text'.
* @param {string} [format] The info format to request from the WMS server. This is usually a
2015-05-18 14:19:32 +08:00
* MIME type such as 'application/json' or text/xml'. If this parameter is not specified, the provider will request 'json'
* using 'application/json', 'xml' using 'text/xml', 'html' using 'text/html', and 'text' using 'text/plain'.
* @param {Function} [callback] A function to invoke with the GetFeatureInfo response from the WMS server
2015-05-18 14:19:32 +08:00
* in order to produce an array of picked {@link ImageryLayerFeatureInfo} instances. If this parameter is not specified,
* a default function for the type of response is used.
2020-04-17 08:31:36 +08:00
*/
2015-05-18 14:19:32 +08:00
function GetFeatureInfoFormat(type, format, callback) {
//>>includeStart('debug', pragmas.debug);
if (!defined(type)) {
throw new DeveloperError("type is required.");
}
//>>includeEnd('debug');
2020-04-17 08:31:36 +08:00
2015-05-18 14:19:32 +08:00
this.type = type;
2020-04-17 08:31:36 +08:00
2015-05-18 14:19:32 +08:00
if (!defined(format)) {
if (type === "json") {
format = "application/json";
} else if (type === "xml") {
format = "text/xml";
} else if (type === "html") {
format = "text/html";
} else if (type === "text") {
format = "text/plain";
}
2015-05-18 14:19:32 +08:00
//>>includeStart('debug', pragmas.debug);
2020-04-17 08:31:36 +08:00
else {
2015-05-18 14:19:32 +08:00
throw new DeveloperError(
'format is required when type is not "json", "xml", "html", or "text".',
);
}
//>>includeEnd('debug');
2020-04-17 08:31:36 +08:00
}
2015-05-18 14:19:32 +08:00
this.format = format;
2020-04-17 08:31:36 +08:00
2015-05-18 14:19:32 +08:00
if (!defined(callback)) {
if (type === "json") {
callback = geoJsonToFeatureInfo;
} else if (type === "xml") {
callback = xmlToFeatureInfo;
} else if (type === "html") {
callback = textToFeatureInfo;
} else if (type === "text") {
callback = textToFeatureInfo;
}
//>>includeStart('debug', pragmas.debug);
else {
throw new DeveloperError(
'callback is required when type is not "json", "xml", "html", or "text".',
);
}
//>>includeEnd('debug');
2020-04-17 08:31:36 +08:00
}
2015-05-18 14:19:32 +08:00
this.callback = callback;
2020-04-17 08:31:36 +08:00
}
2015-05-18 14:19:32 +08:00
function geoJsonToFeatureInfo(json) {
const result = [];
2020-04-17 08:31:36 +08:00
const features = json.features;
for (let i = 0; i < features.length; ++i) {
const feature = features[i];
2020-04-17 08:31:36 +08:00
const featureInfo = new ImageryLayerFeatureInfo();
featureInfo.data = feature;
featureInfo.properties = feature.properties;
featureInfo.configureNameFromProperties(feature.properties);
featureInfo.configureDescriptionFromProperties(feature.properties);
2020-04-17 08:31:36 +08:00
// If this is a point feature, use the coordinates of the point.
if (defined(feature.geometry) && feature.geometry.type === "Point") {
2015-05-18 14:19:32 +08:00
const longitude = feature.geometry.coordinates[0];
const latitude = feature.geometry.coordinates[1];
featureInfo.position = Cartographic.fromDegrees(longitude, latitude);
}
result.push(featureInfo);
2020-04-17 08:31:36 +08:00
}
2015-05-18 14:19:32 +08:00
return result;
2020-04-17 08:31:36 +08:00
}
2015-05-18 14:19:32 +08:00
const mapInfoMxpNamespace = "http://www.mapinfo.com/mxp";
const esriWmsNamespace = "http://www.esri.com/wms";
const wfsNamespace = "http://www.opengis.net/wfs";
const gmlNamespace = "http://www.opengis.net/gml";
2020-04-17 08:31:36 +08:00
function xmlToFeatureInfo(xml) {
2015-05-18 14:19:32 +08:00
const documentElement = xml.documentElement;
2020-04-17 08:31:36 +08:00
if (
2015-05-18 14:19:32 +08:00
documentElement.localName === "MultiFeatureCollection" &&
documentElement.namespaceURI === mapInfoMxpNamespace
2020-04-17 08:31:36 +08:00
) {
2015-05-18 14:19:32 +08:00
// This looks like a MapInfo MXP response
return mapInfoXmlToFeatureInfo(xml);
} else if (
2015-05-18 14:19:32 +08:00
documentElement.localName === "FeatureInfoResponse" &&
documentElement.namespaceURI === esriWmsNamespace
2020-04-17 08:31:36 +08:00
) {
2015-05-18 14:19:32 +08:00
// This looks like an Esri WMS response
return esriXmlToFeatureInfo(xml);
} else if (
2015-05-18 14:19:32 +08:00
documentElement.localName === "FeatureCollection" &&
documentElement.namespaceURI === wfsNamespace
2020-04-17 08:31:36 +08:00
) {
2015-05-18 14:19:32 +08:00
// This looks like a WFS/GML response.
return gmlToFeatureInfo(xml);
} else if (documentElement.localName === "ServiceExceptionReport") {
2015-05-18 14:19:32 +08:00
// This looks like a WMS server error, so no features picked.
throw new RuntimeError(
new XMLSerializer().serializeToString(documentElement),
2020-04-17 08:31:36 +08:00
);
} else if (documentElement.localName === "msGMLOutput") {
return msGmlToFeatureInfo(xml);
2020-04-17 08:31:36 +08:00
} else {
2015-05-18 14:19:32 +08:00
// Unknown response type, so just dump the XML itself into the description.
return unknownXmlToFeatureInfo(xml);
2020-04-17 08:31:36 +08:00
}
}
2015-05-18 14:19:32 +08:00
function mapInfoXmlToFeatureInfo(xml) {
const result = [];
2020-04-17 08:31:36 +08:00
const multiFeatureCollection = xml.documentElement;
2020-04-17 08:31:36 +08:00
const features = multiFeatureCollection.getElementsByTagNameNS(
mapInfoMxpNamespace,
"Feature",
);
for (let featureIndex = 0; featureIndex < features.length; ++featureIndex) {
const feature = features[featureIndex];
2020-04-17 08:31:36 +08:00
const properties = {};
2020-04-17 08:31:36 +08:00
const propertyElements = feature.getElementsByTagNameNS(
mapInfoMxpNamespace,
2020-04-17 08:31:36 +08:00
"Val",
);
2020-04-17 08:31:36 +08:00
for (
2015-05-18 14:19:32 +08:00
let propertyIndex = 0;
propertyIndex < propertyElements.length;
2015-11-13 09:35:10 +08:00
++propertyIndex
2020-04-17 08:31:36 +08:00
) {
2015-11-13 09:35:10 +08:00
const propertyElement = propertyElements[propertyIndex];
if (propertyElement.hasAttribute("ref")) {
const name = propertyElement.getAttribute("ref");
const value = propertyElement.textContent.trim();
properties[name] = value;
2015-05-18 14:19:32 +08:00
}
}
const featureInfo = new ImageryLayerFeatureInfo();
featureInfo.data = feature;
featureInfo.properties = properties;
2015-05-18 14:19:32 +08:00
featureInfo.configureNameFromProperties(properties);
featureInfo.configureDescriptionFromProperties(properties);
result.push(featureInfo);
2020-04-17 08:31:36 +08:00
}
2015-05-18 14:19:32 +08:00
return result;
2020-04-17 08:31:36 +08:00
}
function esriXmlToFeatureInfo(xml) {
const featureInfoResponse = xml.documentElement;
const result = [];
let properties;
2020-04-17 08:31:36 +08:00
2017-10-05 01:44:45 +08:00
const features = featureInfoResponse.getElementsByTagNameNS("*", "FIELDS");
if (features.length > 0) {
// Standard esri format
2015-05-18 14:19:32 +08:00
for (let featureIndex = 0; featureIndex < features.length; ++featureIndex) {
const feature = features[featureIndex];
2020-04-17 08:31:36 +08:00
properties = {};
2020-04-17 08:31:36 +08:00
const propertyAttributes = feature.attributes;
2020-04-17 08:31:36 +08:00
for (
let attributeIndex = 0;
attributeIndex < propertyAttributes.length;
++attributeIndex
2020-04-17 08:31:36 +08:00
) {
const attribute = propertyAttributes[attributeIndex];
properties[attribute.name] = attribute.value;
2020-04-17 08:31:36 +08:00
}
result.push(
imageryLayerFeatureInfoFromDataAndProperties(feature, properties),
);
2015-05-18 14:19:32 +08:00
}
} else {
// Thredds format -- looks like esri, but instead of containing FIELDS, contains FeatureInfo element
const featureInfoElements = featureInfoResponse.getElementsByTagNameNS(
2020-04-17 08:31:36 +08:00
"*",
"FeatureInfo",
2020-04-17 08:31:36 +08:00
);
for (
2015-05-18 14:19:32 +08:00
let featureInfoElementIndex = 0;
featureInfoElementIndex < featureInfoElements.length;
++featureInfoElementIndex
2015-05-18 14:19:32 +08:00
) {
const featureInfoElement = featureInfoElements[featureInfoElementIndex];
2020-04-17 08:31:36 +08:00
2015-05-18 14:19:32 +08:00
properties = {};
2020-04-17 08:31:36 +08:00
2016-01-07 07:19:44 +08:00
// node.children is not supported in IE9-11, so use childNodes and check that child.nodeType is an element
const featureInfoChildren = featureInfoElement.childNodes;
2016-01-07 07:19:44 +08:00
for (
let childIndex = 0;
childIndex < featureInfoChildren.length;
++childIndex
2020-04-17 08:31:36 +08:00
) {
const child = featureInfoChildren[childIndex];
2015-05-18 14:19:32 +08:00
if (child.nodeType === Node.ELEMENT_NODE) {
properties[child.localName] = child.textContent;
}
2020-04-17 08:31:36 +08:00
}
2015-05-18 14:19:32 +08:00
result.push(
imageryLayerFeatureInfoFromDataAndProperties(
featureInfoElement,
2015-11-13 09:35:10 +08:00
properties,
2020-04-17 08:31:36 +08:00
),
2015-05-18 14:19:32 +08:00
);
}
2020-04-17 08:31:36 +08:00
}
2015-05-18 14:19:32 +08:00
return result;
2020-04-17 08:31:36 +08:00
}
2015-11-13 09:35:10 +08:00
function gmlToFeatureInfo(xml) {
2015-05-18 14:19:32 +08:00
const result = [];
2020-04-17 08:31:36 +08:00
2015-05-18 14:19:32 +08:00
const featureCollection = xml.documentElement;
2020-04-17 08:31:36 +08:00
2015-11-13 09:35:10 +08:00
const featureMembers = featureCollection.getElementsByTagNameNS(
2015-05-18 14:19:32 +08:00
gmlNamespace,
2016-01-07 07:19:44 +08:00
"featureMember",
2020-04-17 08:31:36 +08:00
);
for (
let featureIndex = 0;
featureIndex < featureMembers.length;
++featureIndex
2020-04-17 08:31:36 +08:00
) {
const featureMember = featureMembers[featureIndex];
2020-04-17 08:31:36 +08:00
2015-05-18 14:19:32 +08:00
const properties = {};
getGmlPropertiesRecursively(featureMember, properties);
result.push(
2015-11-13 09:35:10 +08:00
imageryLayerFeatureInfoFromDataAndProperties(featureMember, properties),
);
2020-04-17 08:31:36 +08:00
}
2015-05-18 14:19:32 +08:00
return result;
2020-04-17 08:31:36 +08:00
}
2015-11-13 09:35:10 +08:00
// msGmlToFeatureInfo is similar to gmlToFeatureInfo, but assumes different XML structure
// eg. <msGMLOutput> <ABC_layer> <ABC_feature> <foo>bar</foo> ... </ABC_feature> </ABC_layer> </msGMLOutput>
2020-04-17 08:31:36 +08:00
2015-11-13 09:35:10 +08:00
function msGmlToFeatureInfo(xml) {
const result = [];
2020-04-17 08:31:36 +08:00
2015-11-13 09:35:10 +08:00
// Find the first child. Except for IE, this would work:
// const layer = xml.documentElement.children[0];
2015-11-13 09:35:10 +08:00
let layer;
const children = xml.documentElement.childNodes;
for (let i = 0; i < children.length; i++) {
if (children[i].nodeType === Node.ELEMENT_NODE) {
layer = children[i];
2015-11-13 09:35:10 +08:00
break;
}
2020-04-17 08:31:36 +08:00
}
2015-05-18 14:19:32 +08:00
if (!defined(layer)) {
throw new RuntimeError(
"Unable to find first child of the feature info xml document",
);
2020-04-17 08:31:36 +08:00
}
2015-05-18 14:19:32 +08:00
const featureMembers = layer.childNodes;
2020-04-17 08:31:36 +08:00
for (
let featureIndex = 0;
2015-05-18 14:19:32 +08:00
featureIndex < featureMembers.length;
++featureIndex
2020-04-17 08:31:36 +08:00
) {
2015-05-18 14:19:32 +08:00
const featureMember = featureMembers[featureIndex];
if (featureMember.nodeType === Node.ELEMENT_NODE) {
const properties = {};
getGmlPropertiesRecursively(featureMember, properties);
result.push(
imageryLayerFeatureInfoFromDataAndProperties(featureMember, properties),
);
}
2020-04-17 08:31:36 +08:00
}
2015-05-18 14:19:32 +08:00
return result;
2020-04-17 08:31:36 +08:00
}
2015-05-18 14:19:32 +08:00
function getGmlPropertiesRecursively(gmlNode, properties) {
let isSingleValue = true;
2015-05-18 15:17:29 +08:00
for (let i = 0; i < gmlNode.childNodes.length; ++i) {
const child = gmlNode.childNodes[i];
2015-05-18 14:19:32 +08:00
if (child.nodeType === Node.ELEMENT_NODE) {
isSingleValue = false;
2020-04-17 08:31:36 +08:00
}
2015-05-18 14:19:32 +08:00
if (
child.localName === "Point" ||
2015-05-18 14:19:32 +08:00
child.localName === "LineString" ||
child.localName === "Polygon" ||
2015-05-18 14:19:32 +08:00
child.localName === "boundedBy"
2020-04-17 08:31:36 +08:00
) {
2015-05-18 14:19:32 +08:00
continue;
}
if (
child.hasChildNodes() &&
getGmlPropertiesRecursively(child, properties)
2020-04-17 08:31:36 +08:00
) {
2015-05-18 14:19:32 +08:00
properties[child.localName] = child.textContent;
}
2020-04-17 08:31:36 +08:00
}
2015-05-18 14:19:32 +08:00
return isSingleValue;
2020-04-17 08:31:36 +08:00
}
2015-05-18 14:19:32 +08:00
function imageryLayerFeatureInfoFromDataAndProperties(data, properties) {
const featureInfo = new ImageryLayerFeatureInfo();
2015-11-13 09:35:10 +08:00
featureInfo.data = data;
featureInfo.properties = properties;
2015-05-18 14:19:32 +08:00
featureInfo.configureNameFromProperties(properties);
featureInfo.configureDescriptionFromProperties(properties);
return featureInfo;
2020-04-17 08:31:36 +08:00
}
2015-05-18 14:19:32 +08:00
function unknownXmlToFeatureInfo(xml) {
const xmlText = new XMLSerializer().serializeToString(xml);
2020-04-17 08:31:36 +08:00
2015-05-18 14:19:32 +08:00
const element = document.createElement("div");
const pre = document.createElement("pre");
pre.textContent = xmlText;
element.appendChild(pre);
2020-04-17 08:31:36 +08:00
2015-05-18 14:19:32 +08:00
const featureInfo = new ImageryLayerFeatureInfo();
featureInfo.data = xml;
featureInfo.description = element.innerHTML;
return [featureInfo];
2020-04-17 08:31:36 +08:00
}
2015-05-18 14:19:32 +08:00
const emptyBodyRegex = /<body>\s*<\/body>/im;
const wmsServiceExceptionReportRegex =
/<ServiceExceptionReport([\s\S]*)<\/ServiceExceptionReport>/im;
const titleRegex = /<title>([\s\S]*)<\/title>/im;
2020-04-17 08:31:36 +08:00
2015-05-18 14:19:32 +08:00
function textToFeatureInfo(text) {
// If the text is HTML and it has an empty body tag, assume it means no features were found.
if (emptyBodyRegex.test(text)) {
return undefined;
2020-04-17 08:31:36 +08:00
}
2015-05-18 15:17:29 +08:00
// If this is a WMS exception report, treat it as "no features found" rather than showing
// bogus feature info.
2015-05-19 07:57:03 +08:00
if (wmsServiceExceptionReportRegex.test(text)) {
2015-05-18 14:19:32 +08:00
return undefined;
2020-04-17 08:31:36 +08:00
}
2015-05-18 14:19:32 +08:00
// If the text has a <title> element, use it as the name.
let name;
const title = titleRegex.exec(text);
if (title && title.length > 1) {
name = title[1];
2020-04-17 08:31:36 +08:00
}
2015-05-18 14:19:32 +08:00
const featureInfo = new ImageryLayerFeatureInfo();
featureInfo.name = name;
featureInfo.description = text;
featureInfo.data = text;
return [featureInfo];
2020-04-17 08:31:36 +08:00
}
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 GetFeatureInfoFormat;