Rounding the Service Pixel Value in a PopupTemplate

954
1
Jump to solution
08-06-2020 02:14 AM
Gianna_BBSRC
Occasional Contributor

Hello,

I have an 32 bit Float single-band ImageryLayer with a popupTemplate assigned.

The popup shows the raster service pixel value with the following code:

const variableLayer = new ImageryLayer({
       url: 'https://this_is_a_fake_url/ImageServer',
       popupTemplate: {
            title: '{Raster.ServicePixelValue} variable count(s) in {Year}' 
            content: [],
       },
});‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

Is there a way to round the service pixel value which is displayed in the popup? Note: I do not want to round the raster data pixels themselves.

I've tried something like this: 

const variableLayer = new ImageryLayer({
       url: 'https://this_is_a_fake_url/ImageServer',
       popupTemplate: {
            //title: '{Raster.ServicePixelValue} variable count(s) in {Year}'
            content: '{expression/pixelvalue} variable count(s) in {Year}',
            expressionInfos: [{
                    name: 'pixelvalue',
                    expression: 'Round($Raster.ServicePixelValue, 2)'
            }]
       },
});‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

Any combination of experimenting that I've tried has resulted in either undefined or null in the place where the pixel value should be displayed in the popup.

Any help is massively appreciated! Thank you for reading.

0 Kudos
1 Solution

Accepted Solutions
Gianna_BBSRC
Occasional Contributor

I've found the answer on the updated page for popupTemplate

let popupTemplate = {
   title: '',
   fieldInfos: [{
      fieldName: 'Raster.ItemPixelValue',
      format: {
         places: 0, // precision
         digitSeparator: true // thousands comma separator
            }
   }]
};

View solution in original post

1 Reply
Gianna_BBSRC
Occasional Contributor

I've found the answer on the updated page for popupTemplate

let popupTemplate = {
   title: '',
   fieldInfos: [{
      fieldName: 'Raster.ItemPixelValue',
      format: {
         places: 0, // precision
         digitSeparator: true // thousands comma separator
            }
   }]
};