PopupTemplate JavaScript promise for the contents is never being executed.

2488
16
12-06-2017 03:15 AM
AndrewPage1
New Contributor II

Summary:

My PopupTemplate JavaScript promise for the contents is never being executed.

My Requirements:

I am attempting to code a feature that will allow the user to click on a graphic in a Feature Layer and see a popup. We have integrated the map into our ASP.Net MVC web application using the JavaScript 4.5 API.

I have coded the popup in JavaScript as a Popup Template. When the user clicks on a graphic (that will represent a map pin-point), I need the code to do an (asynchronous) AJAX HTTP GET to an endpoint in order to retrieve a JSON object. The object will contain some data that will be displayed in the popup.

I have assigned the 'content' property of my PopupTemplate to my JavaScript function that returns a promise.

My Problem:

It appears that the promise is never being executed, as breakpoints in my code within the promise are never hit. 

I have tried several ways to code the promise with no success. I am using esriRequest to actually do the AJAX GET, and returning the promise from this as the function assignment. Please see my attached code.

I think the JavaScript API is just executing my function and ignoring the promise that I am returning.

0 Kudos
16 Replies
RobertScheitlin__GISP
MVP Emeritus

Andrew,

   Have you tried to change the setPopupContent function to just return some simple string (just for testing)?

0 Kudos
AndrewPage1
New Contributor II

Yes, it works fine when it is just a simple function that returns some HTML. I am having this problem because I want to do an async request. In this scenario, there does not seem to be a way to get the API to actually execute the promise that I am returning.

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Andrew,

   That is strange because the sample I linked to is using a promise.

0 Kudos
AndrewPage1
New Contributor II

Is there any difference between the promise returned from 

 return queryBlocksTask.execute(query).then(function(result)

and

return esriRequest(url, options).then(function (response) 

?

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Yes, that is very likely it all depends on that the service is returning and how it it returning it. Have you tested just doing the esriRequest somewhere else in your code like just adding it to the main code block so you can debug if the request is ever working?

0 Kudos
AndrewPage1
New Contributor II

I have got it working by reverting back to using JQuery:

function setPopupContent(target) {
   var locationId = target.graphic.attributes.ObjectID;
   var url = urlGetLocationExtendedPointsData + '/' + locationId;

   return $.get(url).then(function(data) {
      var source = $("#map-popup-content-template").html();
      var template = Handlebars.compile(source);
      var context = { RiskQualityChartTitle: data.SiteName }
      var html = template(context);

      return html;
});
}

For some reason the esriRequest was not working. Thanks for your help anyway.

BrandonFlessner
Occasional Contributor

This behavior (or lack thereof) also exists at 4.6 bug 4.x esrirequest popuptemplate

0 Kudos