popup - how to fetch the query result after the popup appears on view click event

2515
8
02-01-2017 03:32 AM
LaxmanThapa
New Contributor II
  1. I have a webmap attached to a view.
  2. Now when ever a view is clicked, a default popup appears over the map.
  3. After the popup has been added, a query is called automatically to load the features
  4. I need to get the result of this query.

How can I get the result, so that I can use the result data. I cannot see any event related to the query nor the popup object to get the result.  I am using js ver 4.2 btw.

0 Kudos
8 Replies
FC_Basson
MVP Regular Contributor

You should be able to get the query feature with view.popup.features and then iterate through the features returned to get the attributes.

LaxmanThapa
New Contributor II

But how to trigger the callback function? How do I know when the query request has completed ? 

0 Kudos
FC_Basson
MVP Regular Contributor

Event handler?

view.popup.on("open", function(evt){
// code
});
0 Kudos
LaxmanThapa
New Contributor II

Hi Basson, thanks for the quick reply but your code didnot help.

The event 'open' doesnot fire..

0 Kudos
FC_Basson
MVP Regular Contributor

Sorry, no time to test.

0 Kudos
LaxmanThapa
New Contributor II

I tried to add a popup template  for the layer like

var popupTemplate = new PopupTemplate({
    title: "Régions Industrielles 2017: {NOM}",
    content: setContentInfo
});

function setContentInfo(feature){
    console.log(feature)
    return "?? no idea what the original template is....";
}

//later added this template to the layer
lyr.popupTemplate = popupTemplate;

Now I can access the query feature, but now I do not know the 'content' template for the popup.
0 Kudos
EvelynHernandez
Occasional Contributor III

Hello there, here comes an example :

var myTitle = "Hello";
var sum1  ="there";
var point = feature.attributes.geometry;
var content = `<div style=padding-top: 10px;>Title: ${myTitle}<br /></div>
 <div style=padding-top: 10px;>Sum1: ${sum1}<br /></div>`;
map.infoWindow.resize(450, 250);
 map.infoWindow.setContent(esri.substitute(esri.geometry.webMercatorToGeographic(point), content));
0 Kudos
LaxmanThapa
New Contributor II

Also, there is no event 'open' for the view.popup @ api reference Popup | API Reference | ArcGIS API for JavaScript 4.2 

0 Kudos