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.
Andrew,
Have you tried to change the setPopupContent function to just return some simple string (just for testing)?
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.
Andrew,
That is strange because the sample I linked to is using a promise.
Is there any difference between the promise returned from
return queryBlocksTask.execute(query).then(function(result)
and
return esriRequest(url, options).then(function (response)
?
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?
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.
This behavior (or lack thereof) also exists at 4.6 bug 4.x esrirequest popuptemplate