Popup clears definition expression on Feature Layer

574
4
Jump to solution
10-13-2023 08:09 AM
DiegoDíazDoce
New Contributor II

Hello,

I'm hoping that someone can tell me whether this is the expected behaviour in Experience Builder:

  1. I have a map widget (widget1) that points at a webmap
  2. I also have a second widget (widget2) that uses the MapViewManager to access the JimuMapView instance from widget1.
  3. From that instance, it gets access to one of the webmap feature layers (JimuMapView.MapView.Map.Layers) and sets a definition expression on it
  4. The feature layer is then filtered on the map according to the definition expression as expected.
  5. However, when you click on the map and a popup displays, the definition expression is automatically cleared (I checked the definition expression value before and after displaying the popup) and the feature layer displays again all features, making setting the definition expression directly on the feature layer not viable in Experience Builder.

Thanks in advance for your help

0 Kudos
1 Solution

Accepted Solutions
JeffreyThompson2
MVP Regular Contributor

Have you tried setting a filter in your webmap? If you want to hide something and never unhide it, it is a simple solution.

JeffreyThompson2_0-1697210610673.png

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.

GIS Developer
City of Arlington, Texas

View solution in original post

0 Kudos
4 Replies
JeffreyThompson2
MVP Regular Contributor

Have you tried setting a filter in your webmap? If you want to hide something and never unhide it, it is a simple solution.

JeffreyThompson2_0-1697210610673.png

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.

GIS Developer
City of Arlington, Texas
0 Kudos
DiegoDíazDoce
New Contributor II

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.

0 Kudos
RobertBrundage
New Contributor III

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?

 

0 Kudos
DiegoDíazDoce
New Contributor II

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
  (newValueoldValue=> {
    console.log('Old value: 'oldValue'New value: 'newValue);
    if (!newValue && oldValue) {
      layerView.filter = {
        whereoldValue
      };
    }
  },
  // Optional parameters
  {
    initialtrue
  }
);