Skip to content

Commit

Permalink
Fix zooming behavior & feature info bugs in Cesium
Browse files Browse the repository at this point in the history
Problems found during testing of changes made for issue #1720
  • Loading branch information
robyngit committed Apr 18, 2023
1 parent af71df4 commit b4b745d
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 25 deletions.
10 changes: 6 additions & 4 deletions src/js/models/maps/AssetColorPalette.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,8 @@ define([
const colorPalette = this;

// As a backup, use the default color
let color = this.getDefaultColor();
const defaultColor = colorPalette.getDefaultColor();
let color = defaultColor;

// The name of the property to conditionally color the features by
const prop = colorPalette.get("property");
Expand All @@ -180,6 +181,7 @@ define([
} else if (type === "continuous") {
color = this.getContinuousColor(propValue);
}
color = color || defaultColor;
return color;
},

Expand All @@ -193,11 +195,11 @@ define([
// just needs to match one of the values in the list of color
// conditions. If it matches, then return the color associated with that
// value.
const colorMatch = colors.findWhere({ value: propValue });
const colors = this.get("colors");
const colorMatch = colors.findWhere({ value: value });
if (colorMatch) {
color = colorMatch.get("color");
return colorMatch.get("color");
}
return color;
},

/**
Expand Down
3 changes: 2 additions & 1 deletion src/js/models/maps/Map.js
Original file line number Diff line number Diff line change
Expand Up @@ -297,10 +297,11 @@ define([
* @since x.x.x
*/
convertFeatures: function (features) {
const model = this;
const attrs = features.map(function (feature) {
if (!feature) return null;
if (feature instanceof Feature) return feature.attributes;
return this.get("layers").getFeatureAttributes(features)?.[0];
return model.get("layers").getFeatureAttributes(features)?.[0];
});
return attrs.map((attr) => new Feature(attr));
},
Expand Down
17 changes: 10 additions & 7 deletions src/js/models/maps/assets/CesiumVectorData.js
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,14 @@ define(
return null
},

/**
* @inheritdoc
*/
usesFeatureType: function (feature) {
const entity = this.getEntityFromMapObject(feature)
return this.constructor.__super__.usesFeatureType.call(this, entity)
},

/**
* Given a feature from a Cesium Vector Data source, returns any properties that are set
* on the feature, similar to an attributes table.
Expand Down Expand Up @@ -317,8 +325,6 @@ define(
getCesiumModelFromFeature: function (feature) {
feature = this.getEntityFromMapObject(feature)
if (!feature) return null
// TODO: Test - does feature.id give the entity this work for all datasources ?
// A picked feature object's ID gives the Cesium.Entity
return feature.entityCollection.owner
},

Expand Down Expand Up @@ -447,11 +453,8 @@ define(
model.trigger('appearanceChanged')

}
catch (error) {
console.log(
'There was an error updating CesiumVectorData model styles' +
'. Error details: ' + error
);
catch (e) {
console.log('Failed to update CesiumVectorData model styles.', e);
}
},

Expand Down
18 changes: 7 additions & 11 deletions src/js/models/maps/assets/MapAsset.js
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ define(
if (!this.getCesiumModelFromFeature) return false
const cesiumModel = this.getCesiumModelFromFeature(feature)
if (!cesiumModel) return false
if (this === cesiumModel) return true
if (this.get('cesiumModel') == cesiumModel) return true
return false
},

Expand Down Expand Up @@ -749,17 +749,13 @@ define(
try {
const model = this
const colorPalette = model.get('colorPalette')
if (colorPalette) {
return colorPalette.getColor(properties)
} else {
return new AssetColorPalette().getDefaultColor()
}
return (
colorPalette?.getColor(properties) ||
new AssetColorPalette().getDefaultColor()
)
}
catch (error) {
console.log(
'There was an error getting a color for a MapAsset model' +
'. Error details: ' + error
);
catch (e) {
console.log('Failed to a color in a MapAsset model', e);
}
},

Expand Down
5 changes: 3 additions & 2 deletions src/js/views/maps/CesiumWidgetView.js
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,6 @@ define(
const view = this;
if (typeof options !== 'object') options = {}


// A target is required
if (!target) {
return
Expand Down Expand Up @@ -550,7 +549,9 @@ define(
// If the object saved in the Feature is an Entity, then this
// function will get the bounding sphere for the entity on the
// next run.
view.flyTo(target.get('featureObject'), options)
setTimeout(() => {
view.flyTo(target.get('featureObject'), options)
}, 0);
return
}

Expand Down

0 comments on commit b4b745d

Please sign in to comment.