Kelly Hutchins: Please Help With Esri.Request Issue!

1109
4
10-17-2012 07:41 AM
AlexDeVine
New Contributor III
Kelly,

I have been trying to adapt your updatePopup solution for displaying HTML popups in a popup window and cannot get it to work.  This is your original code:

function updatePopup(graphic){
      var deferred = new dojo.Deferred();
      var url = graphic.getLayer().url + "/" + graphic.attributes.OBJECTID + "/htmlPopup?f=json";
      esri.request({
      url: url,
      content:url.query,
      callbackParamName: "callback",
      load: function(response) {
          //esriServerHTMLPopupTypeAsURL
          deferred.callback( "<iframe src='" + response.content +"' frameborder='0' width='100%' height='100%' style='width: 100%; height: 100%; display: block; padding: 0px; margin: 0px;'></iframe>");

      },
      error: function(error) {
         deferred.errback("Error occurred while generating profile");
      }
      });
      return deferred;
     
      return requestHandle;
 
  }


I am reading your code thusly: Make a new deferred object. Construct a new url to the access the REST location of the esriServerHTMLPopupTypeAsURL. make esri.request defining the callback of the deferred object as the HTML for displaying the esriServerHTMLPopupTypeAsURL content in an iframe and hand it to the popup window. It works when I run it. It uses the 2.4 JSAPI.

Now, I think I am doing the same thing. My code: 

       function updatePopup(feature) {
          var deferred = new dojo.Deferred();
          var url_string = sustainBase.url + "/" + feature.attributes.layerId + "/" + feature.attributes.OBJECTID + "/htmlPopup?f=json";
            
          esri.request({
                url: url_string,
                content: url_string.query,
                callbackParamName: "callback",
                load: function (response) {
                    //esriServerHTMLPopupTypeAsURL                    
                    deferred.callback(response.content);
                },
                error: function (error) {
                    deferred.errback("Error occurred while generating profile");
                }
          });
          return deferred;
          return requestHandle;

        }


(Using JSAPI 2.8) I am making a new deferred object. I am construct a new url to the access the REST location of the esriServerHTMLPopupTypeAsURL. I am making an esri.request defining the callback of the deferred object as the HTML for displaying the esriServerHTMLPopupTypeAsURL content in an iframe (I defined my esriServerHTMLPopupTypeAsURL as the entire iframe HTML so I can just use response.content). and hand it to the popup window. It does not work. The function breaks when it hits "return deferred". 

Exception... "Could not convert JavaScript argument arg 0 [nsIDOMHTMLDivElement.appendChild]"  nsresult: "0x80570009 (NS_ERROR_XPC_BAD_CONVERT_JS)"  location: "JS frame :: http://serverapi.arcgisonline.com/jsapi/arcgis/?v=2.8 :: <TOP_LEVEL> :: line 14"  data: no] 


I have tried using the 2.4 JSAPI which didn't work. I have tried using console.log to verify that my esri.request is working and returning the correct string, and it is. Also, after researching the error, i tried using DOMParser to convert the response.content string to a DOM and that didn't work either. The error Firebug is returning indicates a type mismatch error but I cannot figure it out.

Any help or insight into this that you could provide would be very much appreciated.

Alex
0 Kudos
4 Replies
KellyHutchins
Esri Frequent Contributor
Alex,

I took a quick look and noticed a few things. First not all the layers in your service have a HTML Popup type of Url. I ran a quick test using the LEED_Point layer and it worked for me. See a working example here:

http://jsfiddle.net/xjcfY/

Note that the Popup class does not support setting content using the deferred approach only the InfoWindow does. You can tell if you are using a Popup by looking for code that creates a popup and associated it with the map:

  var popup = new esri.dijit.Popup(null, dojo.create("div"));
  map = new esri.Map("map", {
    extent: initExtent,
    infoWindow: popup
  });



If you see the above in your code try commenting out the line that sets the popup to the info window and see if it works.
0 Kudos
AlexDeVine
New Contributor III
Hi Kelly,

Thank you for your reply.

Yes, the LEED layer is is the only one I have set up the HTML Popup on as a test layer. There are ten layers and some of them have quite a few features so I wanted to get down my methodology before populating the entire database.

I suspected the popup dijit was the culprit at the end of the day yesterday. After seeing you suggestion this morning, I tried to change to infoWindow and it has proved more difficult than just commenting out the dijit.popup references. I am also running an identify task like in the sample Display Identify Results in Popup Window. When I remove the references to the popup dijit, the window does not popup at all. That sample relies on the popup dijit to run map.infoWindow.setFeatures to pass the deferred array to the popup and allow for using the arrows in the popup to scroll through the results in a single popup. I have looked through infoWindow API reference and cannot see a way to have a plain infoWindow to handle an array. Have I placed myself in a Catch-22 situation? I can't access the HTML popup with the popup dijit but I can't display an array of results from my identify task without it? This is my identifytask code.
function executeIdentifyTask(evt) {
            //create identify task and setup parameters
            identifyParams1.geometry = evt.mapPoint;
            identifyParams1.mapExtent = map.extent;
            //lets manually set the identifyParams.layerIds
            var lids = [];
            lids = sustainBase.visibleLayers;
            identifyParams1.layerIds = lids;
 
            var deferred1 = identifyTask1.execute(identifyParams1);

            deferred1.addCallback(function (response) {
                // response is an array of identify result objects    
                // Let's return an array of features.
                return dojo.map(response, function (result) {
                    var feature = result.feature;
                    feature.attributes.layerName = result.layerName;
                    feature.attributes.layerId = result.layerId;
                    //I REPLACED THE IF ELSE IN THE SAMPLE WITH A SWITCH AND LEFT IT IN IN CASE I NEEDED IT LATER
                    switch (result.layerId) {
                        case 12:
                            break;
                        case 14:
                            break;
                        case 0:
                            break;
                        case 1:
                            break;
                        case 2:
                            break;
                        case 3:
                            break;
                        case 4:
                            break;
                        case 5:
                            break;
                        case 6:
                            break;
                        case 7:
                            break;
                        case 8:
                            break;
                        case 9:
                            break;
                        case 10:
                            break;
                        default:
                    }
                    return feature;
                });
            });

            //THIS IS WHAT BREAKS IT WITHOUT THE POPUP DIJIT
            map.infoWindow.setFeatures([deferred1]);
            map.infoWindow.show(evt.mapPoint, map.getInfoWindowAnchor(evt.screenPoint));
        }


If something jumps out at you about how I could leverage the identify task to be able to display multiple results and access the HTML popup, I would appreciate some advice. If you don't have time, I understand.

Good thing I cut my hair short recently because I would be pulling it out right now.

Thank you,

Alex
0 Kudos
KellyHutchins
Esri Frequent Contributor
Hi Alex,

You are correct the 'setFeatures' portion is causing the issue. The infoWindow doesn't support setFeatures. The info window doesn't have built-in feature navigation either so if you want to display content from multiple features you'll have to  add this capability. We have a sample in the help that displays the content for each feature in a separate tab.

http://help.arcgis.com/en/webapi/javascript/arcgis/help/jssamples/find_drilldown.html
0 Kudos
AlexDeVine
New Contributor III
Thank you, Kelly. I am in process of adapting the code you suggested to put my results in tabs. I think will have to change the logic a bit, but it should be fine.

Have a good weekend!

Alex

Hi Alex,

You are correct the 'setFeatures' portion is causing the issue. The infoWindow doesn't support setFeatures. The info window doesn't have built-in feature navigation either so if you want to display content from multiple features you'll have to  add this capability. We have a sample in the help that displays the content for each feature in a separate tab.

http://help.arcgis.com/en/webapi/javascript/arcgis/help/jssamples/find_drilldown.html
0 Kudos