Hello,
I made a custom widget to simplify the filtering process, it applies the filter just fine (for example, filtering by state will filter out all but the selected states in a drop down menu) but the moment I click any of the feature polygons in the map to see the attributes of that feature, the filter disappears and I can see all the states again.
Here are the relevant parts of my code:
// Apply filter function from BlocksBeadFilter.tsx
const addFilter = (): void => {
if (!layerInfo) return
const lyr = layerInfo.lyr
// Build age clause
const ageClause = (() => {
if (!ageSelected.length || ageMin.value <= 0) return ''
const flds = ageSelected.flatMap(l => ageMap[l] || [])
return flds.length ? `(${flds.map(f => `${f} > ${ageMin.value}`).join(' OR ')})` : ''
})()
// Build all clauses
const clauses = [
buildInClause('ProviderName', provider.selected),
buildInClause('StateName', state.selected),
buildInClause('CountyName', county.selected),
ageClause,
buildGroupClause(bslSelected, bslMin.value, f => f),
buildGroupClause(raceSelected, raceMin.value, lbl => raceMap[lbl]),
buildIncomeClause(incMin.value, incMax.value)
].filter(Boolean)
lyr.definitionExpression = clauses.join(' AND ')
// Clear all widget selections after applying the filter
clearWidgetSelections()
}
// From filterUtils.ts
export const buildInClause = (field: string, values: string[]): string => {
if (!values.length) return ''
return `${field} IN (${values.map(val => `'${val.replace(/'/g, "''")}'`).join(', ')})`
}
export const buildGroupClause = (
arr: string[],
min: number,
getField: (s: string) => string
): string => {
return (arr.length && min > 0)
? `(${arr.map(a => `${getField(a)} > ${min}`).join(' OR ')})`
: ''
}
export const buildIncomeClause = (incMin: number, incMax: number): string => {
const parts: string[] = []
if (incMin > 0) parts.push(`ASQPE001 >= ${incMin}`)
if (incMax > 0) parts.push(`ASQPE001 <= ${incMax}`)
return parts.length ? `(${parts.join(' AND ')})` : ''
}
Thank you for your advice.