Skip to content

Commit

Permalink
Clone cesiumOptions object before modifying
Browse files Browse the repository at this point in the history
Fixes #2172
  • Loading branch information
robyngit committed Aug 4, 2023
1 parent b10ff03 commit 50ce947
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/js/models/maps/assets/Cesium3DTileset.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ define(
try {

var model = this;
var cesiumOptions = model.get('cesiumOptions')
var cesiumOptions = this.getCesiumOptions();
var cesiumModel = null

// If the cesium model already exists, don't create it again unless specified
Expand Down Expand Up @@ -183,7 +183,7 @@ define(
setCesiumURL: function () {
try {

var cesiumOptions = this.get('cesiumOptions')
var cesiumOptions = this.getCesiumOptions();

// Set the asset URL if this is a Cesium Ion 3D tileset or terrain
if (cesiumOptions && cesiumOptions.ionAssetId) {
Expand Down
2 changes: 1 addition & 1 deletion src/js/models/maps/assets/CesiumGeohash.js
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ define([
return;
}
// Set the GeoJSON representing geohashes on the model
const cesiumOptions = model.get("cesiumOptions");
const cesiumOptions = this.getCesiumOptions();
const type = model.get("type");
const data = type === "geojson" ? this.getGeoJSON() : this.getCZML();
cesiumOptions["data"] = data;
Expand Down
9 changes: 3 additions & 6 deletions src/js/models/maps/assets/CesiumImagery.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,8 @@ define(

this.getThumbnail();
}
catch (error) {
console.log(
'There was an error initializing a CesiumImagery model' +
'. Error details: ' + error
);
catch (e) {
console.log('Error initializing a CesiumImagery model: ', e);
}
},

Expand Down Expand Up @@ -196,7 +193,7 @@ define(
createCesiumModel: function (recreate = false) {

var model = this;
var cesiumOptions = this.get('cesiumOptions');
const cesiumOptions = this.getCesiumOptions();
var type = this.get('type')
var providerFunction = Cesium[type]

Expand Down
4 changes: 2 additions & 2 deletions src/js/models/maps/assets/CesiumTerrain.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ define(
createCesiumModel: function (recreate = false) {

var model = this;
var cesiumOptions = this.get('cesiumOptions');
var cesiumOptions = model.getCesiumOptions();
var type = this.get('type')
var terrainFunction = Cesium[type]

Expand Down Expand Up @@ -145,7 +145,7 @@ define(
setCesiumURL: function () {
try {

var cesiumOptions = this.get('cesiumOptions')
var cesiumOptions = this.getCesiumOptions();

// Set the asset URL if this is a Cesium Ion 3D tileset or terrain
if (cesiumOptions && cesiumOptions.ionAssetId) {
Expand Down
2 changes: 1 addition & 1 deletion src/js/models/maps/assets/CesiumVectorData.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ define(
try {

const model = this;
const cesiumOptions = model.get('cesiumOptions')
const cesiumOptions = this.getCesiumOptions();
const type = model.get('type')
const label = model.get('label') || ''
const dataSourceFunction = Cesium[type]
Expand Down
16 changes: 16 additions & 0 deletions src/js/models/maps/assets/MapAsset.js
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,8 @@ define(

if (!assetConfig || typeof assetConfig !== 'object') {
assetConfig = {}
} else {
assetConfig = JSON.parse(JSON.stringify(assetConfig))
}

// Set the color palette
Expand Down Expand Up @@ -379,6 +381,20 @@ 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
* are no cesiumOptions.
* @since x.x.x
*/
getCesiumOptions: function () {
const cesiumOptions = this.get('cesiumOptions')
if (!cesiumOptions) { return null }
return JSON.parse(JSON.stringify(cesiumOptions))
},

/**
* Given a feature object from a Feature model, checks if it is part of the
* selectedFeatures collection. See featureObject property from
Expand Down

0 comments on commit 50ce947

Please sign in to comment.