From 2b5c03019e7b849da0bd6b7d09942cd733db742b Mon Sep 17 00:00:00 2001 From: yvonnesjy Date: Fri, 7 Jun 2024 04:09:57 -0700 Subject: [PATCH] Fixup: Fix format and lint errors --- src/js/models/maps/Map.js | 2 +- src/js/models/maps/assets/Cesium3DTileset.js | 4 +- src/js/models/maps/assets/CesiumImagery.js | 4 +- src/js/models/maps/assets/CesiumTerrain.js | 4 +- src/js/models/maps/assets/CesiumVectorData.js | 4 +- src/js/models/maps/assets/MapAsset.js | 408 ++++++++---------- 6 files changed, 184 insertions(+), 242 deletions(-) diff --git a/src/js/models/maps/Map.js b/src/js/models/maps/Map.js index 5cd6645a3..8c61adc67 100644 --- a/src/js/models/maps/Map.js +++ b/src/js/models/maps/Map.js @@ -143,7 +143,7 @@ define([ /** * Coordinates that describe a camera position for Cesium. Requires at * least a longitude and latitude. - * @typedef {object} MapConfig#CameraPosition + * @typedef {object} CameraPosition * @property {number} longitude - Longitude of the central home point * @property {number} latitude - Latitude of the central home point * @property {number} [height] - Height above sea level (meters) diff --git a/src/js/models/maps/assets/Cesium3DTileset.js b/src/js/models/maps/assets/Cesium3DTileset.js index 60e97f0cf..d895d29cd 100644 --- a/src/js/models/maps/assets/Cesium3DTileset.js +++ b/src/js/models/maps/assets/Cesium3DTileset.js @@ -30,7 +30,7 @@ define([ * to `Cesium.Cesium3DTileset(options)` as options, so the properties listed in * the Cesium3DTileset documentation are also supported, see * {@link https://cesium.com/learn/cesiumjs/ref-doc/Cesium3DTileset.html} - * @typedef {Object} Cesium3DTileset#cesiumOptions + * @typedef {Object} Cesium3DTilesetOptions * @property {string|number} ionAssetId - If this tileset is hosted by Cesium Ion, * then Ion asset ID. * @property {string} cesiumToken - If this tileset is hosted by Cesium Ion, then @@ -53,7 +53,7 @@ define([ * @property {Cesium.Cesium3DTileset} cesiumModel A model created and used by * Cesium that organizes the data to display in the Cesium Widget. See * {@link https://cesium.com/learn/cesiumjs/ref-doc/Cesium3DTileset.html} - * @property {Cesium3DTileset#cesiumOptions} cesiumOptions options are passed + * @property {Cesium3DTilesetOptions} cesiumOptions options are passed * to the function that creates the Cesium model. The properties of options are * specific to each type of asset. */ diff --git a/src/js/models/maps/assets/CesiumImagery.js b/src/js/models/maps/assets/CesiumImagery.js index fae5b53f6..3429240cc 100644 --- a/src/js/models/maps/assets/CesiumImagery.js +++ b/src/js/models/maps/assets/CesiumImagery.js @@ -35,7 +35,7 @@ define([ * {@link https://cesium.com/learn/cesiumjs/ref-doc/BingMapsImageryProvider.html#.ConstructorOptions} * and * {@link https://cesium.com/learn/cesiumjs/ref-doc/IonImageryProvider.html#.ConstructorOptions}. - * @typedef {Object} CesiumImagery#cesiumOptions + * @typedef {Object} CesiumImageryOptions * @property {string|number} ionAssetId - If this imagery is hosted by Cesium * Ion, then Ion asset ID. * @property {string|number} key - A key or token required to access the tiles. @@ -64,7 +64,7 @@ define([ * {@link https://cesium.com/learn/cesiumjs/ref-doc/ImageryLayer.html?classFilter=ImageryLayer} * and * {@link https://cesium.com/learn/cesiumjs/ref-doc/?classFilter=ImageryProvider} - * @property {CesiumImagery#cesiumOptions} cesiumOptions options that are passed + * @property {CesiumImageryOptions} cesiumOptions options that are passed * to the function that creates the Cesium model. The properties of options are * specific to each type of asset. */ diff --git a/src/js/models/maps/assets/CesiumTerrain.js b/src/js/models/maps/assets/CesiumTerrain.js index d54bc3066..400a39c2a 100644 --- a/src/js/models/maps/assets/CesiumTerrain.js +++ b/src/js/models/maps/assets/CesiumTerrain.js @@ -33,7 +33,7 @@ define([ * Provider, so other properties that are documented in Cesium are also supported. * See `options` here: * {@link https://cesium.com/learn/cesiumjs/ref-doc/CesiumTerrainProvider.html?classFilter=TerrainProvider} - * @typedef {Object} CesiumTerrain#cesiumOptions + * @typedef {Object} CesiumTerrainOptions * @property {string|number} ionAssetId - If this terrain is hosted by Cesium Ion, * then Ion asset ID. */ @@ -49,7 +49,7 @@ define([ * @property {Cesium.TerrainProvider} cesiumModel A model created and used by * Cesium that organizes the data to display in the Cesium Widget. See * {@link https://cesium.com/learn/cesiumjs/ref-doc/TerrainProvider.html} - * @property {CesiumTerrain#cesiumOptions} cesiumOptions options are passed to the + * @property {CesiumTerrainOptions} cesiumOptions options are passed to the * function that creates the Cesium model. The properties of options are specific * to each type of asset */ diff --git a/src/js/models/maps/assets/CesiumVectorData.js b/src/js/models/maps/assets/CesiumVectorData.js index 856345d9c..62f14ccb0 100644 --- a/src/js/models/maps/assets/CesiumVectorData.js +++ b/src/js/models/maps/assets/CesiumVectorData.js @@ -58,7 +58,7 @@ define([ * Each type of Cesium Data Source has a specific set of load method * options. See for example, the GeoJsonDataSource options: * {@link https://cesium.com/learn/cesiumjs/ref-doc/GeoJsonDataSource.html} - * @typedef {Object} CesiumVectorData#cesiumOptions + * @typedef {Object} CesiumVectorDataOptions * @property {string|Object} data - The url, GeoJSON object, or TopoJSON * object to be loaded. */ @@ -79,7 +79,7 @@ define([ * model created and used by Cesium that organizes the data to display in * the Cesium Widget. See * {@link https://cesium.com/learn/cesiumjs/ref-doc/DataSource.html?classFilter=DataSource} - * @property {CesiumVectorData#cesiumOptions} cesiumOptions options are + * @property {CesiumVectorDataOptions} cesiumOptions options are * passed to the function that creates the Cesium model. The properties of * options are specific to each type of asset. * @property {string|AssetColor} [outlineColor=null] The color of the diff --git a/src/js/models/maps/assets/MapAsset.js b/src/js/models/maps/assets/MapAsset.js index f0f9cacc4..c682db1c8 100644 --- a/src/js/models/maps/assets/MapAsset.js +++ b/src/js/models/maps/assets/MapAsset.js @@ -6,15 +6,8 @@ define([ "models/portals/PortalImage", "models/maps/AssetColorPalette", "common/IconUtilities", - MetacatUI.root + "/components/dayjs.min.js", -], function ( - _, - Backbone, - PortalImage, - AssetColorPalette, - IconUtilities, - dayjs, -) { + `${MetacatUI.root}/components/dayjs.min.js`, +], (_, Backbone, PortalImage, AssetColorPalette, IconUtilities, dayjs) => { /** * @classdesc A MapAsset Model comprises information required to fetch source data for * some asset or resource that is displayed in a map, such as imagery (raster) tiles, @@ -25,11 +18,11 @@ define([ * @classcategory Models/Maps/Assets * @class MapAsset * @name MapAsset - * @extends Backbone.Model + * @augments Backbone.Model * @since 2.18.0 - * @constructor + * @class */ - var MapAsset = Backbone.Model.extend( + const MapAsset = Backbone.Model.extend( /** @lends MapAsset.prototype */ { /** * The name of this type of model @@ -40,17 +33,17 @@ define([ /** * Default attributes for MapAsset models * @name MapAsset#defaults - * @type {Object} + * @type {object} * @property {('Cesium3DTileset'|'BingMapsImageryProvider'|'IonImageryProvider'|'WebMapTileServiceImageryProvider'|'TileMapServiceImageryProvider'|'CesiumTerrainProvider')} type * The format of the data. Must be one of the supported types. * @property {string} label A user friendly name for this asset, to be displayed * in a map. - * @property {string} [icon = ''] - * A PID for an SVG saved as a dataObject, or an SVG string. The SVG will be used - * as an icon that will be displayed next to the label in the layers list. It - * should be an SVG file that has no fills, borders, or styles set on it (since - * the icon will be shaded dynamically by the maps CSS using a fill attribute). It - * must use a viewbox property rather than a height and width. + * @property {string} [icon] A PID for an SVG saved as a dataObject, or an SVG + * string. The SVG will be used as an icon that will be displayed next to the label + * in the layers list. It should be an SVG file that has no fills, borders, or styles + * set on it (since the icon will be shaded dynamically by the maps CSS using a fill + * attribute). It must use a viewbox property rather than a height and width. When + * not specified, a layer icon is used as default. * @property {string} [description = ''] A brief description about the asset, e.g. * which area it covers, the resolution, etc. * @property {string} [attribution = ''] A credit or attribution to display along @@ -61,33 +54,33 @@ define([ * go to download the source data. * @property {string} [id = ''] If this asset's data is archived in a DataONE * repository, the ID of the data package. - * @property {Boolean} [selected = false] Set to true when this asset has been + * @property {boolean} [selected = false] Set to true when this asset has been * selected by the user in the layer list. - * @property {Number} [opacity = 1] A number between 0 and 1 indicating the + * @property {number} [opacity = 1] A number between 0 and 1 indicating the * opacity of the layer on the map, with 0 representing fully transparent and 1 * representing fully opaque. This applies to raster (imagery) and vector assets, * not to terrain assets. - * @property {Number} [saturation = 1] A number that indicates the saturation of + * @property {number} [saturation = 1] A number that indicates the saturation of * the layer on the map. Less than 1.0 reduces the saturation while greater than * 1.0 increases it. This applies to raster (imagery) only. - * @property {Boolean} [visible = true] Set to true if the layer is visible on the + * @property {boolean} [visible = true] Set to true if the layer is visible on the * map, false if it is hidden. This applies to raster (imagery) and vector assets, * not to terrain assets. * @property {AssetColorPalette} [colorPalette] The color or colors mapped to * attributes of this asset. This applies to raster/imagery and vector assets. For * imagery, the colorPalette will be used to create a legend. For vector assets * (e.g. 3Dtilesets), it will also be used to style the features. - * @property {MapConfig#FeatureTemplate} [featureTemplate] Configuration for + * @property {FeatureTemplate} [featureTemplate] Configuration for * content and layout of the Feature Info panel - the panel that shows information * about a selected feature from a vector asset ({@link FeatureInfoView}). - * @property {Cesium.Entity|Cesium.3DTilesetFeature} [featureType] For vector + * @property {Cesium.Entity|Cesium.Cesium3DTilesetFeature} [featureType] For vector * and 3d tileset assets, the object type that cesium uses to represent features * from the asset. Null for imagery and terrain assets. - * @property {MapConfig#CustomProperties} [customProperties] Configuration that + * @property {CustomProperties} [customProperties] Configuration that * allows for the definition of custom feature properties, potentially based on * other properties. For example, a custom property could be a formatted version * of an existing date property. - * @property {MapConfig#Notification} [notification] A custom badge and message to + * @property {Notification} [notification] A custom badge and message to * display about the layer in the Layer list. For example, this could highlight * the layer if it is new, give a warning if they layer is under development, etc. * @property {'ready'|'error'|null} [status = null] Set to 'ready' when the @@ -95,10 +88,10 @@ define([ * the asset is not supported, or there was a problem requesting the resource. * @property {string} [statusDetails = null] Any further details about the status, * especially when there was an error. - * @property {Boolean} [hideInLayerList = false] Set to true to hide this asset + * @property {boolean} [hideInLayerList = false] Set to true to hide this asset * from the layer list. */ - defaults: function () { + defaults() { return { type: "", label: "", @@ -127,7 +120,7 @@ define([ * as well as metadata and display properties of the asset. Some properties listed * here do not apply to all asset types, but this is specified in the property * description. - * @typedef {Object} MapAssetConfig + * @typedef {object} MapAssetConfig * @name MapConfig#MapAssetConfig * @property {('Cesium3DTileset'|'BingMapsImageryProvider'|'IonImageryProvider'|'WebMapTileServiceImageryProvider'|'WebMapServiceImageryProvider'|'TileMapServiceImageryProvider'|'NaturalEarthII'|'CesiumTerrainProvider'|'GeoJsonDataSource'|'USGSImageryTopo'|'OpenStreetMapImageryProvider')} type - * A string indicating the format of the data. Some of these types correspond @@ -136,7 +129,7 @@ define([ * that is shipped with Cesium/MetacatUI. If this type is set, then no other * cesiumOptions are required. The same is true for USGSImageryTopo, which pulls * imagery directly from USGS. - * @property {(Cesium3DTileset#cesiumOptions|CesiumImagery#cesiumOptions|CesiumTerrain#cesiumOptions|CesiumVectorData#cesiumOptions)} [cesiumOptions] - + * @property {(Cesium3DTilesetOptions|CesiumImageryOptions|CesiuCesiumTerrainOptions|CesiumVectorDataOptions)} [cesiumOptions] - * For MapAssets that are configured for Cesium, like * Cesium3DTilesets, an object with options to pass to the Cesium constructor * function that creates the Cesium model. Options are specific to each type of @@ -149,14 +142,14 @@ define([ * or styles set on it (since the icon will be shaded dynamically by the maps CSS * using a fill attribute). It must use a viewbox property rather than a height * and width. - * @property {Number} [opacity=1] - A number between 0 and 1 indicating the + * @property {number} [opacity=1] - A number between 0 and 1 indicating the * opacity of the layer on the map, with 0 representing fully transparent and 1 * representing fully opaque. This applies to raster (imagery) and vector assets, * not to terrain assets. - * @property {Number} [saturation=1] - A number that indicates the saturation of + * @property {number} [saturation=1] - A number that indicates the saturation of * the layer on the map. Less than 1.0 reduces the saturation while greater than * 1.0 increases it. This applies to raster (imagery) only. - * @property {Boolean} [visible=true] - Set to true if the layer is visible on the + * @property {boolean} [visible=true] - Set to true if the layer is visible on the * map, false if it is hidden. This applies to raster (imagery) and vector assets, * not to terrain assets. * @property {string} [description] - A brief description about the asset, e.g. @@ -169,23 +162,23 @@ define([ * where a user can go to download the source data. * @property {string} [id] If this asset's data is archived in a DataONE * repository, the ID of the data package. - * @property {MapConfig#ColorPaletteConfig} [colorPalette] The color or colors + * @property {ColorPaletteConfig} [colorPalette] The color or colors * mapped to attributes of this asset. This applies to raster/imagery and vector * assets. For imagery, the colorPalette will be used to create a legend. For * vector assets (e.g. 3Dtilesets), it will also be used to style the features. - * @property {MapConfig#FeatureTemplate} [featureTemplate] Configuration for the + * @property {FeatureTemplate} [featureTemplate] Configuration for the * content and layout of the Feature Info panel ({@link FeatureInfoView}) - the * panel that shows information about a selected feature from a vector asset. If * no feature template is set, then the default table layout is used. - * @property {MapConfig#CustomProperties} [customProperties] Definitions of custom + * @property {CustomProperties} [customProperties] Definitions of custom * properties of features, potentially based on existing properties. For example, * a custom property could be a formatted version of another date property. These * custom properties can be used in the filters, colorPalette, or featureTemplate. * So far, custom strings and formatted dates are supported. Eventually, the * custom properties may be expanded to support formatted numbers and booleans. - * @property {MapConfig#VectorFilterConfig} [filters] - A set of conditions used + * @property {VectorFilterConfig} [filters] - A set of conditions used * to show or hide specific features of this tileset. - * @property {MapConfig#Notification} [notification] A custom badge and message to + * @property {Notification} [notification] A custom badge and message to * display about the layer in the Layer list. For example, this could highlight * the layer if it is new, give a warning if they layer is under development, etc. * @property {boolean} [hideInLayerList] - Set to true to hide this asset from the @@ -196,7 +189,7 @@ define([ * A feature template configures the format and content of information displayed * in the Feature Info panel ({@link FeatureInfoView}). The Feature Info panel is * displayed in a map when a user clicks on a vector feature in a map. - * @typedef {Object} FeatureTemplate + * @typedef {object} FeatureTemplate * @name MapConfig#FeatureTemplate * @since 2.19.0 * @property {'story'|'table'} [template='table'] The name/ID of the template to @@ -205,7 +198,7 @@ define([ * @property {string} [label] Sets which of the feature properties to use as the * title for the FeatureInfoView. The string must exactly match the key for a * property that exists in the feature. - * @property {MapConfig#StoryTemplateOptions} [options] A list of key-value pairs + * @property {StoryTemplateOptions} [options] A list of key-value pairs * that map the template variable to a property/attribute of the the feature. Keys * are the template variable names and values are the names of properties in the * feature. Template variable names are specific to each template. Currently only @@ -236,7 +229,7 @@ define([ /** * An object that maps template variable to feature properties for the "story" * template. - * @typedef {Object} + * @typedef {object} StoryTemplateOptions * @name MapConfig#StoryTemplateOptions * @since 2.19.0 * @property {string} subtitle The name of a feature property to use for a @@ -254,7 +247,7 @@ define([ /** * An object where the keys indicate the name/ID of the new custom property to * create, and the values are an object that defines the new property. - * @typedef {Object.} CustomProperties + * @typedef {{string: (CustomDateProperty|CustomStringProperty)}} CustomProperties * @name MapConfig#CustomProperties * @since 2.19.0 * @example @@ -274,7 +267,7 @@ define([ /** * An object that defines a formatted date to use as a property in a feature. Used * in the {@link MapConfig#CustomProperties} object. - * @typedef {Object} CustomDateProperty + * @typedef {object} CustomDateProperty * @name MapConfig#CustomDateProperty * @since 2.19.0 * @property {'date'} type Must be set to 'date' to indicate that this is a custom @@ -288,7 +281,7 @@ define([ /** * An object that defines a custom string to use as a property in a feature. Used * in the {@link MapConfig#CustomProperties} object. - * @typedef {Object} CustomStringProperty + * @typedef {object} CustomStringProperty * @name MapConfig#CustomStringProperty * @since 2.19.0 * @property {'string'} type Must be set to 'string' to indicate that this is a @@ -302,7 +295,7 @@ define([ * A notification displays a badge in the {@link LayerListView} and a message in * the {@link LayerDetailsView}. This is useful for indicating some special status * of the layer: "new", "under development", etc. - * @typedef {Object} Notification + * @typedef {object} Notification * @name MapConfig#Notification * @since 2.22.0 * @property {'yellow'|'green'|'blue'|'contrast'} [style] - The badge and message @@ -315,69 +308,61 @@ define([ /** * Executed when a new MapAsset model is created. - * @param {MapConfig#MapAssetConfig} [assetConfig] The initial values of the + * @param {MapAssetConfig} [assetConfig] The initial values of the * attributes, which will be set on the model. */ - initialize: function (assetConfig) { - try { - const model = this; - - if (!assetConfig || typeof assetConfig !== "object") { - assetConfig = {}; - } else { - assetConfig = JSON.parse(JSON.stringify(assetConfig)); - } + initialize(assetConfig) { + const model = this; + + let parsedAssetConfig; + if (!assetConfig || typeof assetConfig !== "object") { + parsedAssetConfig = {}; + } else { + parsedAssetConfig = JSON.parse(JSON.stringify(assetConfig)); + } // Set the color palette - if (assetConfig.colorPalette) { + if (parsedAssetConfig.colorPalette) { this.set( "colorPalette", new AssetColorPalette( _.extend( - assetConfig.colorPalette, - _.pick(assetConfig, "label"), + parsedAssetConfig.colorPalette, + _.pick(parsedAssetConfig, "label"), ), ), ); } - // Fetch the icon, if there is one - if (assetConfig.icon) { - try { - if (IconUtilities.isSVG(assetConfig.icon)) { - model.updateIcon(icon); - } else { - model.set("iconStatus", "fetching"); - // If the string is not an SVG then assume it is a PID and try to fetch - // the SVG file. - IconUtilities.fetchIcon(assetConfig.icon).then((icon) => - model.updateIcon(icon), - ); - } - } catch (error) { - console.log( - "Failed to fetch an icon for a MapAsset" + - ". Error details: " + - error, + // Fetch the icon, if there is one + if (parsedAssetConfig.icon) { + try { + if (IconUtilities.isSVG(parsedAssetConfig.icon)) { + model.updateIcon(parsedAssetConfig.icon); + } else { + model.set("iconStatus", "fetching"); + // If the string is not an SVG then assume it is a PID and try to fetch + // the SVG file. + IconUtilities.fetchIcon(parsedAssetConfig.icon).then((icon) => + model.updateIcon(icon), ); - model.set("iconStatus", "error"); } + } catch (error) { + model.set("iconStatus", "error"); } - - this.set("originalVisibility", this.get("visible")); - this.setListeners(); - } catch (e) { - console.log("Error initializing a MapAsset model", e); } + + this.set("originalVisibility", this.get("visible")); + this.setListeners(); }, /** * Set an error status and message for this asset. - * @param {Object|String} error - An error object with a status code + * @param {object | string} error - An error object with a status code * attribute or or string with details about the error. * @since 2.27.0 */ - setError: function (error) { + setError(error) { // See https://cesium.com/learn/cesiumjs/ref-doc/RequestErrorEvent.html let details = error; // Write a helpful error message @@ -388,6 +373,7 @@ define([ case 500: details = "There was a server error (error code 500)."; break; + default: } this.set("status", "error"); this.set("statusDetails", details); @@ -397,7 +383,7 @@ define([ * Set a ready status for this asset. * @since 2.27.0 */ - setReady: function () { + setReady() { this.set("status", "ready"); this.set("statusDetails", null); }, @@ -406,7 +392,7 @@ define([ * When the asset can't be loaded, hide it from the map and show an error. * @since 2.27.0 */ - handleError: function () { + handleError() { this.set("visible", false); this.stopListening(this, "change:visible"); }, @@ -415,33 +401,29 @@ define([ * Set all of the listeners for this model * @since 2.27.0 */ - setListeners: function () { - try { - const status = this.get("status"); - if (status === "error") { - this.handleError(); - return; - } else { - const vis = this.get("originalVisibility"); - if (typeof vis === "boolean") { - this.set("visible", vis); - } - } - // The map asset cannot be visible on the map if there was an error - // loading the asset - this.stopListening(this, "change:status"); - this.listenTo(this, "change:status", this.setListeners); - - // Listen for changes to the cesiumOptions object - this.stopListening(this, "change:cesiumOptions"); - this.listenTo(this, "change:cesiumOptions", function () { - this.createCesiumModel(true); - }); - - this.listenToSelectedFeatures(); - } catch (e) { - console.log("Error setting MapAsset Listeners.", e); + setListeners() { + const status = this.get("status"); + if (status === "error") { + this.handleError(); + return; } + const vis = this.get("originalVisibility"); + if (typeof vis === "boolean") { + this.set("visible", vis); + } + + // The map asset cannot be visible on the map if there was an error + // loading the asset + this.stopListening(this, "change:status"); + this.listenTo(this, "change:status", this.setListeners); + + // Listen for changes to the cesiumOptions object + this.stopListening(this, "change:cesiumOptions"); + this.listenTo(this, "change:cesiumOptions", () => { + this.createCesiumModel(true); + }); + + this.listenToSelectedFeatures(); }, /** @@ -449,7 +431,7 @@ define([ * selected or deselected in the map widget. * @since 2.27.0 */ - listenToSelectedFeatures: function () { + listenToSelectedFeatures() { if (typeof this.updateAppearance !== "function") { return; } @@ -484,12 +466,12 @@ define([ // Reset the listeners if the selectedFeatures collection or the // interactions model is replaced - this.listenToOnce(interactions, "change:selectedFeatures", function () { + this.listenToOnce(interactions, "change:selectedFeatures", () => { this.updateAppearance(); this.listenToSelectedFeatures(); }); - this.listenToOnce(mapModel, "change:interactions", function () { + this.listenToOnce(mapModel, "change:interactions", () => { this.updateAppearance(); this.listenToSelectedFeatures(); }); @@ -499,11 +481,11 @@ define([ * Get the asset config's cesiumOptions, if it has any. This will return * a copy of the cesiumOptions object, so that changes made to the * returned object will not affect the original cesiumOptions object. - * @returns {Object} A copy of the cesiumOptions object, or null if there + * @returns {object} A copy of the cesiumOptions object, or null if there * are no cesiumOptions. * @since 2.26.0 */ - getCesiumOptions: function () { + getCesiumOptions() { const cesiumOptions = this.get("cesiumOptions"); if (!cesiumOptions) { return null; @@ -520,7 +502,7 @@ define([ * @returns {boolean} Returns true if the given feature is part of the * selectedFeatures collection in this asset */ - featureIsSelected: function (feature) { + featureIsSelected(feature) { const map = this.get("mapModel"); if (!map) { return false; @@ -539,12 +521,12 @@ define([ * Cesium3DTilesetFeature is passed to this function, this function * will return true if it is a Cesium3DTileset model, and false if it * is a CesiumVectorData model. - * @param {Cesium.Cesium3DTilesetFeature|Cesium.Entity} feature + * @param {Cesium.Cesium3DTilesetFeature|Cesium.Entity} feature feature to be checked. * @returns {boolean} true if the feature is an instance of the feature * type set on the asset model, false otherwise. * @since 2.25.0 */ - usesFeatureType: function (feature) { + usesFeatureType(feature) { const ft = this.get("featureType"); if (!feature || !ft) return false; if ((!feature) instanceof ft) return false; @@ -561,12 +543,12 @@ define([ * selectedFeatures collection in this asset * @since 2.25.0 */ - containsFeature: function (feature) { + containsFeature(feature) { if (!this.usesFeatureType(feature)) return false; if (!this.getCesiumModelFromFeature) return false; const cesiumModel = this.getCesiumModelFromFeature(feature); if (!cesiumModel) return false; - if (this.get("cesiumModel") == cesiumModel) return true; + if (this.get("cesiumModel") === cesiumModel) return true; return false; }, @@ -575,11 +557,11 @@ define([ * needed to create a Feature model. For vector and 3d tile models only. * @param {*} feature - An object that a Map widget uses to represent this feature * in the map, e.g. a Cesium.Entity or a Cesium.Cesium3DTileFeature - * @returns {Object} An object with properties, mapAsset, featureID, featureObject, + * @returns {object} An object with properties, mapAsset, featureID, featureObject, * and label properties. Returns null if the feature is not the correct type * for this asset model. */ - getFeatureAttributes: function (feature) { + getFeatureAttributes(feature) { if (!this.usesFeatureType(feature)) return null; if (!this.getCesiumModelFromFeature) return null; return { @@ -595,85 +577,64 @@ define([ * Given a set of properties from a Feature from this Map Asset model, add any * custom properties to the properties object and return it. * @since 2.19.0 - * @param {Object} properties A set of key-value pairs representing the existing + * @param {object} properties A set of key-value pairs representing the existing * properties of a feature from this asset. - * @returns {Object} The properties object with any custom properties added. + * @returns {object} The properties object with any custom properties added. */ - addCustomProperties: function (properties) { - try { - const model = this; - const customProperties = model.get("customProperties"); - const formattedProperties = {}; - - if (!customProperties || !Object.keys(customProperties).length) { - return properties; - } - - if (!properties || typeof properties !== "object") { - properties = {}; - } + addCustomProperties(properties) { + const model = this; + const customProperties = model.get("customProperties"); + const formattedProperties = {}; - if (customProperties) { - _.each(customProperties, function (config, key) { - let formattedValue = ""; - if (config.type === "date") { - formattedValue = model.formatDateProperty(config, properties); - // TODO: support formatted numbers and booleans... - // } else if (config.type === 'number') { - // formattedValue = model.formatNumberProperty(config, properties) - // } else if (config.type === 'boolean') { - // formattedValue = model.formatBooleanProperty(config, properties) - } else { - formattedValue = model.formatStringProperty(config, properties); - } - formattedProperties[key] = formattedValue; - }); - } - // merge the properties with the formatted properties - return Object.assign(properties, formattedProperties); - } catch (error) { - console.log( - "There was an error adding custom properties. Returning properties " + - "unchanged. Error details: " + - error, - ); + if (!customProperties || !Object.keys(customProperties).length) { return properties; } + + const propertiesCopy = + properties && typeof properties !== "object" ? properties : {}; + + if (customProperties) { + _.each(customProperties, (config, key) => { + let formattedValue = ""; + if (config.type === "date") { + formattedValue = model.formatDateProperty(config, propertiesCopy); + // TODO: support formatted numbers and booleans... + // } else if (config.type === 'number') { + // formattedValue = model.formatNumberProperty(config, properties) + // } else if (config.type === 'boolean') { + // formattedValue = model.formatBooleanProperty(config, properties) + } else { + formattedValue = model.formatStringProperty(config); + } + formattedProperties[key] = formattedValue; + }); + } + // merge the properties with the formatted properties + return Object.assign(propertiesCopy, formattedProperties); }, /** * Given a definition for a new date property, and the properties that already * exist on a specific feature, returns a new string with the formatted date. * @since 2.19.0 - * @param {MapConfig#CustomDateProperty} config - An object that defines the new + * @param {CustomDateProperty} config - An object that defines the new * date property to create - * @param {Object} properties key-value pairs representing existing properties in + * @param {object} properties key-value pairs representing existing properties in * a Feature * @returns {string} The value for the new date property, formatted as defined by * config, for the given feature */ - formatDateProperty: function (config, properties) { - try { - if (!properties) { - properties = {}; - } - let formattedDate = ""; - if (!config || !config.format) { - return formattedDate; - } - const value = properties[config.property]; - if (value) { - formattedDate = dayjs(value).format(config.format); - } + formatDateProperty(config, properties) { + const propertiesCopy = properties || {}; + let formattedDate = ""; + if (!config || !config.format) { return formattedDate; - } catch (error) { - console.log( - "There was an error formatting a date for a Feature model" + - ". Error details: " + - error, - ); - return ""; } + const value = propertiesCopy[config.property]; + if (value) { + formattedDate = dayjs(value).format(config.format); + } + return formattedDate; }, /** @@ -683,31 +644,17 @@ define([ * of config.value. This function exists to allow support of dynamic strings in * the future (e.g. combining strings from existing properties) * @since 2.19.0 - * @param {MapConfig#CustomStringProperty} config The object the defines the new + * @param {CustomStringProperty} config The object the defines the new * custom property - * @param {Object} properties key-value pairs representing existing properties in - * a Feature * @returns {string} The new string for the given Feature property */ - formatStringProperty: function (config, properties) { - try { - if (!properties) { - properties = {}; - } - let formattedString = ""; - if (!config || !config.value) { - return formattedString; - } - formattedString = config.value; + formatStringProperty(config) { + let formattedString = ""; + if (!config || !config.value) { return formattedString; - } catch (error) { - console.log( - "There was an error formatting a string for a Feature model" + - ". Error details: " + - error, - ); - return ""; } + formattedString = config.value; + return formattedString; }, // formatNumberProperty: function (config, properties) { @@ -749,7 +696,7 @@ define([ * string. Also sets the 'iconStatus' attribute to 'success'. * @param {string} icon An SVG string to use for the MapAsset icon */ - updateIcon: function (icon) { + updateIcon(icon) { if (!icon) return; this.set("icon", IconUtilities.sanitizeIcon(icon)); @@ -761,7 +708,7 @@ define([ * values. * @since 2.21.0 */ - resetStatus: function () { + resetStatus() { const defaults = this.defaults(); this.set("status", defaults.status); this.set("statusDetails", defaults.statusDetails); @@ -771,15 +718,15 @@ define([ * Checks if the asset information has been fetched and is ready to use. * @returns {Promise} Returns a promise that resolves to this model when ready. */ - whenReady: function () { + whenReady() { const model = this; - return new Promise(function (resolve, reject) { + return new Promise((resolve) => { if (model.get("status") === "ready") { resolve(model); return; } model.stopListening(model, "change:status"); - model.listenTo(model, "change:status", function () { + model.listenTo(model, "change:status", () => { if (model.get("status") === "ready") { model.stopListening(model, "change:status"); resolve(model); @@ -791,51 +738,46 @@ define([ /** * Given properties of a Feature model from this MapAsset, returns the color * associated with that feature. - * @param {Object} properties The properties of the feature to get the color for; + * @param {object} properties The properties of the feature to get the color for; * An object containing key-value mapping of property names to properties. (See * the 'properties' attribute of {@link Feature#defaults}.) - * @returns {AssetColor#Color} The color associated with the given set of + * @returns {Color} The color associated with the given set of * properties. */ - getColor: function (properties) { - try { - const model = this; - const colorPalette = model.get("colorPalette"); - return ( - colorPalette?.getColor(properties) || - new AssetColorPalette().getDefaultColor() - ); - } catch (e) { - console.log("Failed to a color in a MapAsset model", e); - } + getColor(properties) { + const model = this; + const colorPalette = model.get("colorPalette"); + return ( + colorPalette?.getColor(properties) || + new AssetColorPalette().getDefaultColor() + ); }, /** * This function checks whether a feature from the MapAsset is visible on the map * based on the properties of the feature and the MapAsset's filter settings. - * @param {Object} properties The properties of the feature to be filtered. (See + * @param {object} properties The properties of the feature to be filtered. (See * the 'properties' attribute of {@link Feature#defaults}.) * @returns {boolean} Returns true if the feature passes all the filters, or if * there are no filters set for this MapAsset. Returns false if the feature fails * any of the filters. */ - featureIsVisible: function (properties) { + featureIsVisible(properties) { const model = this; const filters = model.get("filters"); if (filters && filters.length) { return filters.featureIsVisible(properties); - } else { - return true; } + return true; }, /** - * Indicate that the map widget should navigate to a given feature from + * Indicate that the map widget should navigate to a given target from * this MapAsset. - * @param {Feature} feature The feature to navigate to. + * @param {CameraPosition} target The target to navigate to. * @since 2.27.0 */ - zoomTo: function (target) { + zoomTo(target) { this.get("mapModel")?.zoomTo(target); }, @@ -844,7 +786,7 @@ define([ * is greater than zero. If both conditions are met, returns true. * @returns {boolean} Returns true if the MapAsset has opacity > 0 and is visible. */ - isVisible: function () { + isVisible() { if (this.get("temporarilyHidden") === true) return false; return this.get("visible") && this.get("opacity") > 0; }, @@ -853,7 +795,7 @@ define([ * Make sure the layer is visible. Sets visibility to true if false, and sets * opacity to 0.5 if it's less than 0.05. */ - show: function () { + show() { // If the opacity is very low, set it to 50% if (this.get("opacity") < 0.05) { this.set("opacity", 0.5);