Skip to content

Commit 6f142bd

Browse files
committed
[16.0][IMP] base_geoengine: Fix Vector Layer related Errors
Notifying user to define selected attribute_field_id of supported type from vector layer in infoBox template to avoid JS error. When a field from attribute_field_id values selected from vector layer is not suitable for "custom" classification, it is notified to the user to avoid JS Error.
1 parent c4f0f23 commit 6f142bd

1 file changed

Lines changed: 50 additions & 6 deletions

File tree

base_geoengine/static/src/js/views/geoengine/geoengine_renderer/geoengine_renderer.esm.js

Lines changed: 50 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ export class GeoengineRenderer extends Component {
5353
this.orm = useService("orm");
5454
this.view = useService("view");
5555
this.user = useService("user");
56+
this.notification = useService("notification");
5657

5758
// For related model we need to load all the service needed by RelationalModel
5859
this.services = {};
@@ -749,8 +750,12 @@ export class GeoengineRenderer extends Component {
749750
const fields_to_read = this.getFieldsToRead(vector);
750751
const data = await this.getModelData(vector, fields_to_read);
751752
this.useRelatedModel(vector, layer, data);
752-
const styleInfo = this.styleVectorLayer(vector, data);
753-
this.initLegend(styleInfo, vector);
753+
if (this.checkAttributeFieldUsage(vector, data)) {
754+
const styleInfo = this.styleVectorLayer(vector, data);
755+
if (styleInfo) {
756+
this.initLegend(styleInfo, vector);
757+
}
758+
}
754759
}
755760

756761
async renderVectorLayers() {
@@ -844,9 +849,13 @@ export class GeoengineRenderer extends Component {
844849
}
845850

846851
styleVectorLayerAndLegend(cfg, data, lv) {
847-
const styleInfo = this.styleVectorLayer(cfg, data);
848-
this.initLegend(styleInfo, cfg);
849-
lv.setStyle(styleInfo.style);
852+
if (this.checkAttributeFieldUsage(cfg, data)) {
853+
const styleInfo = this.styleVectorLayer(cfg, data);
854+
if (styleInfo) {
855+
this.initLegend(styleInfo, cfg);
856+
lv.setStyle(styleInfo.style);
857+
}
858+
}
850859
}
851860

852861
initLegend(styleInfo, cfg) {
@@ -1053,7 +1062,21 @@ export class GeoengineRenderer extends Component {
10531062
if (cfg.classification === "custom") {
10541063
colors = vals.map((val) => {
10551064
if (val) {
1056-
return chroma(val).alpha(opacity).css();
1065+
try {
1066+
return chroma(val).alpha(opacity).css();
1067+
} catch (error) {
1068+
this.notification.add(
1069+
this.env._t(
1070+
"Selected Attribute Field: " +
1071+
indicator +
1072+
"is not usable for custom classification"
1073+
),
1074+
{
1075+
type: "warning",
1076+
}
1077+
);
1078+
return false;
1079+
}
10571080
}
10581081
});
10591082
} else {
@@ -1248,6 +1271,27 @@ export class GeoengineRenderer extends Component {
12481271
var indicator = cfg.attribute_field_id[1];
12491272
return data.map((item) => item._values[indicator]);
12501273
}
1274+
1275+
/**
1276+
* Check vector Layer Attribute Field is defined
1277+
* by view to display proper legends
1278+
*/
1279+
checkAttributeFieldUsage(cfg, data) {
1280+
const indicator_values = this.extractLayerValues(cfg, data);
1281+
if (indicator_values.some((item) => item === undefined)) {
1282+
this.notification.add(
1283+
this.env._t(
1284+
"Customize view to use Attribute Field: " +
1285+
cfg.attribute_field_id[1]
1286+
),
1287+
{
1288+
type: "warning",
1289+
}
1290+
);
1291+
return false;
1292+
}
1293+
return true;
1294+
}
12511295
}
12521296

12531297
GeoengineRenderer.template = "base_geoengine.GeoengineRenderer";

0 commit comments

Comments
 (0)