Call Default Popup from ActionToggle?

726
3
Jump to solution
01-25-2022 02:19 PM
IfThenTim
New Contributor III

Is there a way to programmatically display a popup as if the location marker (graphic) was clicked?

I want to use an ActionToggle to display and/or hide some additional content in the popup. Everything is good except for me knowing what to call to redisplay the default incarnation of the popup.

As an example, suppose I am mapping ice cream shops and the default popup displays a name, address, and phone number. I define the popup template like this:

const store_popup = {
    title: "{name}",
    content: "<p>{address}</p>" + "<p>{phone}</p> </div>",
    actions: [flavorsToggle]
};

 

For the popup, I have an ActionToggle to display specialty flavors of ice cream available at the shop (in an HTML table). I might have one function to display the extra information using view.popup.content:

showFlavors() {
    return view.popup.content =
        "<div class='esri-feature-content'>" 							
        + "<p>" + view.popup.selectedFeature.attributes.address 
        + "<p>" + view.popup.selectedFeature.attributes.phone
        + "<table>" 
        + view.popup.selectedFeature.attributes.flavors
        + "</table>"
        + "</div>";
}

 

When I write the code for the companion hideFlavors() function, I want to call the popup in its default form -- as it is defined by the popup template. Is there a way to do that?

0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus

@IfThenTim 

Without seeing your code it is a little hard to speculate. The view.popup has a features property that is an array of graphics. You could use this then:

view.popup.open({
  features: view.popup.features,  // array of graphics
  fetchFeatures: true  //fetch the content of this feature and display it
});

 

View solution in original post

3 Replies
RobertScheitlin__GISP
MVP Emeritus
view.popup.open({
     location: somePointObject,  // location 
     fetchFeatures: true // display the content for the selected feature if a popupTemplate is defined.
   });
0 Kudos
IfThenTim
New Contributor III

Thanks for the reply!

Being new to almost everything having to do with this, it's not obvious to me how somePointObject gets set to the location value of the last graphic clicked. Can you elaborate on how that might happen or refer me to an example or relevant doc?

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

@IfThenTim 

Without seeing your code it is a little hard to speculate. The view.popup has a features property that is an array of graphics. You could use this then:

view.popup.open({
  features: view.popup.features,  // array of graphics
  fetchFeatures: true  //fetch the content of this feature and display it
});