Hello,
I'm hoping that someone can tell me whether this is the expected behaviour in Experience Builder:
Thanks in advance for your help
Solved! Go to Solution.
Have you tried setting a filter in your webmap? If you want to hide something and never unhide it, it is a simple solution.
From your description, this sounds like an issue where React is triggering a re-rendering of some component that is removing your definition expression. There is probably a way to write a useEffect hook that watches your definition expression and re-adds it if it is removed, but it will be tricky to find the right way to do it without triggering an infinite loop.
Have you tried setting a filter in your webmap? If you want to hide something and never unhide it, it is a simple solution.
From your description, this sounds like an issue where React is triggering a re-rendering of some component that is removing your definition expression. There is probably a way to write a useEffect hook that watches your definition expression and re-adds it if it is removed, but it will be tricky to find the right way to do it without triggering an infinite loop.
Hi JeffreyThompson2,
Many thanks for your reply. Your suggestion of watching the definition expression and re-add if removed worked. Just had to include a condition to avoid triggering the infinite loop that you mentioned.
However, this is just a workaround, a hack to correct a faulty behaviour. In my opinion, a layer property shouldn't be overwritten by default functionality, like opening a pop-up.
Hello DiegoDíazDoce,
I am suffering the same issue with setting the DefExpression (in my case on three featurelayers). I am having trouble coming up with a solution. Would you mind sharing your code?
Hi,
In case you are still looking for a solution/workaround, this snippet will watch changes in a layerView filter and will re-add the old value if the new value is null. It should work in the same way with layers and definitionExpressions.
reactiveUtils.watch(
// getValue function
() => layerView.filter?.where,
// Callback function
(newValue, oldValue) => {
console.log('Old value: ', oldValue, 'New value: ', newValue);
if (!newValue && oldValue) {
layerView.filter = {
where: oldValue
};
}
},
// Optional parameters
{
initial: true
}
);
That's a life saver, thanks!
Still not entirely sure if the reset of definitionExpression on map interaction is intended behaviour, or if we are doing something wrong when it comes to component rerendering?
cc: @esriesri @esriesri3