PopupTemplate runtime context

741
3
01-15-2018 03:22 PM
yangwen
New Contributor III

Short summary: I have a requirement where a popup has custom markup and actions bound to the markup that trigger various logic outside of the arcGis instance context.

Surely we can have container app supply the custom markup for a given popup. Within the popup markup, there needs the ability to listen to onclick actions within the markup.  Then that onclick needs to call a function with a specific context.  Am I stuck with the global context for popups?  I saw some example of popups calling functions defined in the local scope, via Arcade Expression.  There is no mentioning of managing contexts though.

Long Details: I'm creating a map module that wraps the arcGIS map instance + API.  I need to allow container app to specify a collection of "actions" it wants the popup to display.  These actions will be bound to some HTML elements via custom popuptemplate markup.  From the an ArcGIS perspective, clicking on these action triggers should simply call the method prescribed, such as an action handler proxy method:

triggeredAction(actionId){

   emit.ActionTriggered(actionId)

}

The container app would then listen to the action that was triggered from the popup and then execute logic accordingly.

The tricky part is to how from the context of the popup, resolve the triggeredAction method.

I want to avoid using the actions construct of popup.  I think they are all rendered in a very fixed way.  I just want flexible markups and the ability to call some function with specific context.

0 Kudos
3 Replies
yangwen
New Contributor III

From looking at this sample, it looks like Arcade is resolving function identifier in the global context.

PopupTemplate - use functions to set content | ArcGIS API for JavaScript 4.6 

0 Kudos
yangwen
New Contributor III

So I'm able to do a watch on the view.popup.visible property.


When it becomes true, I set some values from the popup to a global variable.  I then can call a global method from within the popup markup.  

I also have a global reference to the mapView instance.  If I modify some of the view's properties, I can then trigger their respective watch functions.

I wonder which properties on the view would be appropriate to use as a proxy to communicate these user invoked custom actions from within the popup?

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Yang,

   The popup widget as an emit method that I would look at for your use.

https://developers.arcgis.com/javascript/latest/api-reference/esri-widgets-Popup.html#emit 

0 Kudos