Select to view content in your preferred language

Category selector doesn't use virtual fields/attribute expressions configured in the map

108
0
a week ago
Labels (1)
MappyIan
Frequent Contributor

Background

I have a hosted feature layer in AGOL which is a point dataset of Libraries.  This dataset has two attributes:

  • capacity (integer)
  • currrentoccpuancy (integer)

Map setup

In the map, I have an attribute expression set up to drive the symbology based on a simple calculation to work out the current percentage occupancy of each library:

var percentageoccupancy = ''
var occupancystatus = ''
var capacity = $feature.capacity
var currentoccupancy = $feature.currentoccupancy

// need some checks here:
// - check that currentoccupancy and capacity both have value
// - check that currentoccupancy and capacity > 0
// - check that currentoccupancy <= capacity
if (capacity != null && capacity >= 0
		&& currentoccupancy != null && currentoccupancy >=0
		&& currentoccupancy <= capacity)
	{

	// calculate the current percentage occupancy value and round to 0 decimal places
	percentageoccupancy = round((currentoccupancy / capacity) * 100,0)

	When(
		percentageoccupancy <= 50,occupancystatus = 'Quiet',
		percentageoccupancy <= 75,occupancystatus = 'Busy',
		percentageoccupancy <= 95,occupancystatus = 'Very busy',
		percentageoccupancy > 95,occupancystatus = 'Full',
		occupancystatus = 'Unknown'
	)
}
// set value for all other features that don't meet the checks above
else { occupancystatus = 'No data' }

return occupancystatus

 

This works great and allows me to colour up my library point features based on how busy each library currently is (we have a process running in the background that updates the 'currentoccupancy' of each library feature every few minutes so that the user is presented with near real-time occupancy):

MappyIan_0-1749034142095.png

I have the exact same expression added to the popup area in my map so that the information is also displayed in the popup:

MappyIan_1-1749034180118.png

In the Fields area in Map Viewer, this expression is listed as a field at the bottom of the list:

MappyIan_2-1749034288021.png

Dashboard bit

Now the bit I'm struggling with is using this map in a Dashboard, and I want the user to be able to filter the data using this 'current occupancy status' attribute expression, e.g. to show just those libraries that are currently 'quiet' or 'busy'.  The problem is, these attribute expressions don't appear to be pulled through in to the Dashboard and are not listed as an option in the Category Selector widget (I'm using 'grouped values' as I want to present the user with a list of 'quiet', 'busy', 'very busy' etc. etc.):

MappyIan_3-1749034656427.png

The 'Category field' only lists fields that exist on the actual hosted feature layer, not any attribute expressions defined in the map.

I've tried writing a data expression in the Dashboard that creates a FeatureSet and calculates the 'current status' of each library:

MappyIan_4-1749035731094.png

This looks promising as this is how I want the Category Selector to appear to the user, but I can't link this to the map in the Actions section because the 'Target field' drop down doesn't include a matching field in the Library (point) dataset (same problem as identified above):

MappyIan_5-1749035929126.png

I've spent quite a while trying to work out if there is any way of doing this in Dashboards, but I haven't managed to get around this.  It seems like a fairly simple requirement: to be able to filter data in a Dashboard using the same expression set up to categorise the data in the map.  So really I'm reaching out to see if anyone has managed to do anything similar that I can learn from.

Any help would be greatly appreciated.

0 Replies