@@ -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
12531297GeoengineRenderer . template = "base_geoengine.GeoengineRenderer" ;
0 commit comments