Help with ArcGIS API for JS, Custom Popups

1172
2
06-27-2017 01:19 PM
JeffSherriff
New Contributor

Hi all, I have be messing around with the ArcGIS API for Javascript.  So far, I have a basemap, added in a point feature layer that I published to AGOL and I have set up a popup template displaying the attributes from my feature layer. 

I would like to display live data in my popup when a user clicks on a point feature.  

How would I go about using the ID from the point feature selected, embed that into a URL and then run a HTTP GET request (with Header auth) and return the data .  Then take that data and use it in my popup.

I am hoping to find some sample code where the popup attribute data is being pulled from a URL or feature layer that is not currenlly added to the map.

My HTTP GET request returns the data like below:

<Statistics>
<max_speed>59</max_speed>
<min_speed>7</min_speed>
<avg_speed>40</avg_speed>
<avg_speed85>49</avg_speed85>
<speed_limit>40</speed_limit>
<count>163</count>
</Statistics>
<Parametrs>
<minutes>60</minutes>
<speed_type>kmh</speed_type>
</Parametrs>
<raw_records>
<recorddatetime="2017-06-27 15:00:00"></record>
 

Any assistance would be appreciated.

Thanks

0 Kudos
2 Replies
JeffSherriff
New Contributor

I believe this will work for what I need using XMLHttpRequest().   I will need to add my header parameters in.

btn.addEventListener("click", function() {
   var ourRequest = new XMLHttpRequest();
   ourRequest.open('GET', 'MyURL' + pageCounter + '.json');
   ourRequest.onload = function() {
      if (ourRequest.status >= 200 && ourRequest.status < 400) {
         var ourData = JSON.parse(ourRequest.responseText);
         renderHTML(ourData);
      } else {
console.log("returned an error.");
}

};

0 Kudos
FC_Basson
MVP Regular Contributor

You could quite easily retrieve the data by ID with esri.request: esri/request | API Reference | ArcGIS API for JavaScript 3.21.  So when you click on the feature, maybe set the popup window content to a load spinner image, and when the request completes, parse the XML and populate the popup window with the new content.