Select to view content in your preferred language

Display no value for Dynamic Text when no filter applied

269
2
Jump to solution
4 weeks ago
JustinWolff
Regular Contributor

In ArcGIS Online, I have a Filter widget applied to some polygons representing project areas.  I have a Text widget configured to dynamically display the name of the project.  When no filter is applied (ALL projects are visible) I would like the dynamic text to display something like 'Select a Filter' or just appear blank or something - right now it always shows the first project record as a default when no project is selected in the filter.  I think this can be accomplished with a text widget arcade expression but I'm not sure how to put it together.  I've tried the 'View for empty selection' of the data source and switching 'Default' and 'Selected features' in the text widget and dynamic content properties but nothing changes.  Thanks.

The Arcade script for the Text widget looks like this:

// Documentation: https://arcg.is/18ejKn3

function getFilteredFeatureSet(ds) {
  var result = ds.layer;
  var queryParams = ds.queryParams;

  if (!IsEmpty(queryParams.where)) {
    result = Filter(result, queryParams.where);
  }

  if (!IsEmpty(queryParams.geometry)) {
    result = Intersects(result, queryParams.geometry);
  }

  return result;
}


// Projects
// The filteredFeatureSet1 has already been filtered using spatial filters and attribute filters.
// var filteredFeatureSet1 = getFilteredFeatureSet($dataSources["dataSource_2-1989fddf1cf-layer-14"]);
// selectedFeatures1 is the selection view of data source.
// var selectedFeatures1 = $dataSources["dataSource_2-1989fddf1cf-layer-14"].selectedFeatures;


// NOTE: When using selectedFeatures, cases with no selected features must be handled manually.


return {
  value: '',
  text: {
    // size: 14,
    // color: 'rgb(0, 0, 255)',
    // bold: true,
    // italic: false,
    // underline: false,
    // strike: false
  },
};
  

 

Tags (1)
0 Kudos
1 Solution

Accepted Solutions
ShengdiZhang
Esri Regular Contributor

Hi @JustinWolff ,

You can use the script below as a reference.

// Retrieve the data source
var dataSource = $dataSources["dataSource_2-1989fddf1cf-layer-14"];

// Get the current filter (WHERE clause)
var whereClause = dataSource.queryParams.where;

// Check if no filter is applied
if (IsEmpty(whereClause)) {
  return "Select a Filter";
}

// Apply the filter to the layer
var filteredFeatures = Filter(dataSource.layer, whereClause);

// Return the number of filtered records
return Count(filteredFeatures);

Please let me know if you have other questions.

Thanks,
Shengdi

View solution in original post

0 Kudos
2 Replies
ShengdiZhang
Esri Regular Contributor

Hi @JustinWolff ,

You can use the script below as a reference.

// Retrieve the data source
var dataSource = $dataSources["dataSource_2-1989fddf1cf-layer-14"];

// Get the current filter (WHERE clause)
var whereClause = dataSource.queryParams.where;

// Check if no filter is applied
if (IsEmpty(whereClause)) {
  return "Select a Filter";
}

// Apply the filter to the layer
var filteredFeatures = Filter(dataSource.layer, whereClause);

// Return the number of filtered records
return Count(filteredFeatures);

Please let me know if you have other questions.

Thanks,
Shengdi

0 Kudos
JustinWolff
Regular Contributor

Thank you Shengdi, that got me pointed in the right direction.

Now to figure out formatting bold/italic based on the conditions...

0 Kudos