Skip to content

Commit

Permalink
Fixup: Address linter issues
Browse files Browse the repository at this point in the history
  • Loading branch information
ianguerin committed Jun 5, 2024
1 parent 9b36b2d commit 904f908
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 35 deletions.
6 changes: 2 additions & 4 deletions src/js/collections/maps/AssetCategories.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ define([
"models/maps/AssetCategory",
"models/maps/Map",
"collections/maps/MapAssets",
], function (Backbone, AssetCategory, MapModel, MapAssets) {
], (Backbone, AssetCategory, MapModel, MapAssets) => {
/**
* @classdesc AssetCategories collection is a group of AssetCategory models - models
* that provide the information required to render geo-spatial data in categories,
Expand Down Expand Up @@ -53,9 +53,7 @@ define([
* @returns {MapAssets[]} A list of MapAssets collections.
*/
getMapAssets() {
return this.map((assetCategory) => {
return assetCategory.get("mapAssets");
});
return this.map((assetCategory) => assetCategory.get("mapAssets"));
},
},
);
Expand Down
37 changes: 26 additions & 11 deletions src/js/collections/maps/viewfinder/ZoomPresets.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,54 @@ define([
"underscore",
"backbone",
"models/maps/viewfinder/ZoomPresetModel",
], function (_, Backbone, ZoomPresetModel) {
], (_, Backbone, ZoomPresetModel) => {
/**
* Determine if array is empty.
* @param {Array} a The array in question.
* @returns {boolean} Whether the array is empty.
*/
function isNonEmptyArray(a) {
return a && a.length && Array.isArray(a);
}

/**
* @class ZoomPresets
* @classdesc A ZoomPresets collection is a group of ZoomPresetModel models
* that provide a location and list of layers to make visible when the user
* selects.
* @class ZoomPresets
* @classcategory Collections/Maps
* @extends Backbone.Collection
* @augments Backbone.Collection
* @since 2.29.0
* @constructor
* @class
*/
const ZoomPresets = Backbone.Collection.extend(
/** @lends ZoomPresets.prototype */ {
/** @inheritdoc */
model: ZoomPresetModel,

/**
* @param {Object[]} zoomPresets The raw list of objects that represent
* @typedef {object} ZoomPresetsParseOptions
* @property {object} zoomPresets The raw list of objects that represent
* the zoom presets, to be converted into ZoomPresetModels.
* @param {MapAsset[]} allLayers All of the layers available for display
* @property {MapAsset[]} allLayers All of the layers available for display
* in the map.
*/

/**
* Parse values and return a list of models for creating a
* Backbone.Collection.
* @param {ZoomPresetsParseOptions} object Values to be parsed into the
* Backbone.Collection.
* @returns {ZoomPresets} A collection of models representative of the
* values passed in.
*/
parse({ zoomPresetObjects, allLayers }) {
if (isNonEmptyArray(zoomPresetObjects)) {
const zoomPresets = zoomPresetObjects.map((zoomPresetObj) => {
const enabledLayerIds = [];
const enabledLayerLabels = [];
for (const layer of allLayers.models) {
allLayers.models.forEach(layer => {
if (
zoomPresetObj.layerIds?.find(
(id) => id === layer.get("layerId"),
Expand All @@ -41,7 +60,7 @@ define([
enabledLayerIds.push(layer.get("layerId"));
enabledLayerLabels.push(layer.get("label"));
}
}
});

return new ZoomPresetModel(
{
Expand All @@ -67,9 +86,5 @@ define([
},
);

function isNonEmptyArray(a) {
return a && a.length && Array.isArray(a);
}

return ZoomPresets;
});
45 changes: 25 additions & 20 deletions src/js/models/maps/Map.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ define([
"collections/maps/AssetCategories",
"models/maps/GeoPoint",
"collections/maps/viewfinder/ZoomPresets",
], function (
], (
$,
_,
Backbone,
Expand All @@ -18,24 +18,33 @@ define([
AssetCategories,
GeoPoint,
ZoomPresets,
) {
) => {
/**
* Determine if array is empty.
* @param {Array} a The array in question.
* @returns {boolean} Whether the array is empty.
*/
function isNonEmptyArray(a) {
return a && a.length && Array.isArray(a);
}

/**
* @class MapModel
* @classdesc The Map Model contains all of the settings and options for a
* required to render a map view.
* @classcategory Models/Maps
* @name MapModel
* @since 2.18.0
* @extends Backbone.Model
* @augments Backbone.Model
*/
var MapModel = Backbone.Model.extend(
const MapModel = Backbone.Model.extend(
/** @lends MapModel.prototype */ {
/**
* Configuration options for a {@link MapModel} that control the
* appearance of the map, the data/imagery displayed, and which UI
* components are rendered. A MapConfig object can be used when
* initializing a Map model, e.g. `new Map(myMapConfig)`
* @namespace {Object} MapConfig
* @namespace {object} MapConfig
* @property {MapConfig#CameraPosition} [homePosition] - A set of
* coordinates that give the (3D) starting point of the Viewer. This
* position is also where the "home" button in the Cesium widget will
Expand Down Expand Up @@ -134,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} MapConfig#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)
Expand Down Expand Up @@ -227,7 +236,7 @@ define([
* UI appears within the ViewfinderView.
* UI appears within the ViewfinderView.
*/
defaults: function () {
defaults() {
return {
homePosition: {
longitude: -65,
Expand Down Expand Up @@ -266,13 +275,9 @@ define([
* for the map. If any config option is not specified, the default will be
* used instead (see {@link MapModel#defaults}).
*/
initialize: function (config) {
initialize(config) {
try {
if (config && config instanceof Object) {
function isNonEmptyArray(a) {
return a && a.length && Array.isArray(a);
}

if (isNonEmptyArray(config.layerCategories)) {
const assetCategories = new AssetCategories(
config.layerCategories,
Expand Down Expand Up @@ -316,7 +321,7 @@ define([
* @returns {MapInteraction} The new interactions model.
* @since 2.27.0
*/
setUpInteractions: function () {
setUpInteractions() {
const interactions = new Interactions({
mapModel: this,
});
Expand All @@ -330,7 +335,7 @@ define([
* @param {Feature[]} features - An array of Feature models to select.
* since 2.28.0
*/
selectFeatures: function (features) {
selectFeatures(features) {
this.get("interactions")?.selectFeatures(features);
},

Expand All @@ -339,7 +344,7 @@ define([
* @returns {Features} The selected Feature collection.
* @since 2.27.0
*/
getSelectedFeatures: function () {
getSelectedFeatures() {
return this.get("interactions")?.get("selectedFeatures");
},

Expand All @@ -352,14 +357,14 @@ define([
* zoom to. See {@link CesiumWidgetView#flyTo} for more details on types
* of targets.
*/
zoomTo: function (target) {
zoomTo(target) {
this.get("interactions")?.set("zoomTarget", target);
},

/**
* Indicate that the map widget view should navigate to the home position.
*/
flyHome: function () {
flyHome() {
this.zoomTo(this.get("homePosition"));
},

Expand All @@ -379,7 +384,7 @@ define([
* @returns {MapAssets} The new layers collection.
* @since 2.25.0
*/
resetLayers: function () {
resetLayers() {
const newLayers = this.defaults()?.layers || new MapAssets();
this.set("layers", newLayers);
return newLayers;
Expand Down Expand Up @@ -410,7 +415,7 @@ define([
* @returns {MapAsset} The new layer model.
* @since 2.25.0
*/
addAsset: function (asset) {
addAsset(asset) {
const layers = this.get("layers") || this.resetLayers();
return layers.addAsset(asset, this);
},
Expand All @@ -420,7 +425,7 @@ define([
* @param {MapAsset} asset - The layer model to remove from the map.
* @since 2.27.0
*/
removeAsset: function (asset) {
removeAsset(asset) {
if (!asset) return;
const layers = this.get("layers");
if (!layers) return;
Expand Down

0 comments on commit 904f908

Please sign in to comment.