Setting Popup's featureMenuOpen = true for map clicks

750
3
Jump to solution
04-22-2022 07:56 AM
MatthewDesjardins
New Contributor II

I'm currently trying to set featureMenuOpen to true for my popup using the following:

 

const view = new MapView({
  container: mapContainer,
  map: new WebMap({
    portalItem: {
      id: '91a05f5984164ecf876b4b2a11711846',
    },
  }),
});

view.when(() => {
  view.popup.featureMenuOpen = true;
});

 

However, whenever you click on a location, it ends up selecting the first feature and resetting featureMenuOpen to false. Is there something else I need to make that work? Or am I misunderstanding the point of that option?

I have also tried setting the popup.featureMenuOpen property directly in the MapView constructor's properties parameter,  but I get the same behavior:

 

const view = new MapView({
  container: mapContainer,
  map: new WebMap({
    portalItem: {
      id: '91a05f5984164ecf876b4b2a11711846',
    },
  }),
  popup: {
    featureMenuOpen: true,
  },
});

 

 

EDIT:

I suppose a workaround would be to set view.popup.autoOpenEnabled to false, watch for click events on the MapView, doing a manual view.popup.fetchFeatures, and then a view.popup.open with its featureMenuOpen property set to true. I'm not sure if setting the featureMenuOpen on the popup directly is supposed to work the way I'm expecting it to.

Tags (1)
0 Kudos
1 Solution

Accepted Solutions
LaurenBoyd
Esri Contributor

Hi @MatthewDesjardins 

The featureMenuOpen property is only meant for the open method on the Popup. We will update the documentation to remove the featureMenuOpen property from the Popup itself and the open method will still have the option.

Were you able to get this working when using the popup's open method? The following sample has an example of how to use this option in the open method for the popup: https://developers.arcgis.com/javascript/latest/sample-code/query/ If you weren't able to get it work, can you provide a codepen showing the issue?

Lauren

View solution in original post

0 Kudos
3 Replies
MatthewDesjardins
New Contributor II

I may have figured it out myself, sorry.

It looks like it has to do with the way it moves features from the Popup's promises array to its features array. When clicking on a location it will add the query to the promises array, but when it resolves and gets moved to features, it just opens the popup to the first feature instead. I get the same behavior using my workaround if I just use the promises array instead of awaiting the query and adding it to features.


And as a side note, I'm not sure if maybe the docs are wrong regarding the promises array, but it implies that once a promise in the array resolves, it gets removed from that array and added to features; however, I'm seeing that the promises stay in that array even after they are fulfilled.

0 Kudos
LaurenBoyd
Esri Contributor

Hi @MatthewDesjardins 

The featureMenuOpen property is only meant for the open method on the Popup. We will update the documentation to remove the featureMenuOpen property from the Popup itself and the open method will still have the option.

Were you able to get this working when using the popup's open method? The following sample has an example of how to use this option in the open method for the popup: https://developers.arcgis.com/javascript/latest/sample-code/query/ If you weren't able to get it work, can you provide a codepen showing the issue?

Lauren
0 Kudos
MatthewDesjardins
New Contributor II

Thank you. Yes, I was able to get it to work using the open method.

Is there a way to keep the loading spinner (from the spinnerEnabled property) at the click location using this method? From what I understand it is meant to interact with the promises array. If I use the open method with the featureMenuOpen and promises options (using the promise from fetchFeatures' allGraphicsPromise result), it also doesn't open the feature menu once it resolves.

Awaiting the fetchFeatures result and calling open with the features option does work, though; it just doesn't give that spinner while the results are loading.

0 Kudos