adevine

Using Identify Task to Display HTML Popup Problem

Discussion created by adevine on Oct 11, 2012
Latest reply on Oct 11, 2012 by adevine
Good Afternoon,

I am trying to combine two examples found in the ESRI resource center to use an identifyTask to display an HTML popup from my map service (esriServerHTMLPopupTypeAsURL). One example was a sample: Display Identify Results in Popup and the other was a solution by Kelly Hutchins to a forum question accessing the HTML Popup in a map service: Link.

I can make the identifyTask work, but when I try to use the updatePopup function Kelly provided to set the content of my infoWindow, I get an error: TypeError: Cannot read property 'url' of null {}. I think this has to do with the fact that the identifyTask uses the ArcGISDynamicMapServiceLayer while the updatePopup function wants a featureLayer. My data is added to the map as both types as I needed FeatureLayers for the custom renderers I created for the point data so both versions of the data are there, but I am having trouble making updatePopup return the full infoWindow.content needed to access the HTML Popup.

This is an excerpt of my code with the identify task. The feature.setInfoTemplate in my switch statement in the identify task is set to a empty template but I would ideally want to use the sustaintemplate I define and link to updatePopup in my init(). Attached is my full website. (Note: As this is a development site, only the LEED layer has the pdf I am hoping to display configured to be displayed in the popup but the other points, if the HTML Popup is properly being accessed, will throw a 404)

//Get the map ready for identify tasks
        dojo.connect(map, "onLoad", mapReady);

        //Set templates up for sustainability infowindows
        sustaintemplate = new esri.InfoTemplate();


        //Set infoTemplates for sustainability layers
        setSustainInfoTemplates();
        sustaintemplate.setTitle("<b>UGA Sustainability Info</b>");
        sustaintemplate.setContent(updatePopup);
        
        function setSustainInfoTemplates() {
            for (var j = 0; j < featureLayers.length; j++) {
                featureLayers[j].setInfoTemplate(sustaintemplate);
            }
        }

        function updatePopup(graphic) {

            var deferred = new dojo.Deferred();
            alert("Before URL variable declared");
            var url = graphic.getLayer().url + "/" + graphic.attributes.OBJECTID + "/htmlPopup?f=json";
            alert("after URL variable declared");
            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");
                }
            });
            console.log(url);
            return deferred;
            return requestHandle;

        } 

     }

     function mapReady(map) {
         map.infoWindow.resize(400, 430);   

         dojo.connect(map, "onClick", executeIdentifyTask);

         identifyTask1 = new esri.tasks.IdentifyTask("http://falcon.camplan.uga.edu/OUAGISSERVER/rest/services/UGA_SustainBase/MapServer");

         identifyParams1 = new esri.tasks.IdentifyParameters();
         identifyParams1.tolerance = 5;
         identifyParams1.returnGeometry = true;
         identifyParams1.layerIds = [0,1,2,3,4,5,6,7,8,9,10,12,14];
         identifyParams1.layerOption = esri.tasks.IdentifyParameters.LAYER_OPTION_VISIBLE;
         identifyParams1.width = map.width;
         identifyParams1.height = map.height;

         //resize the map when the browser resizes
         dojo.connect(dijit.byId('map'), 'resize', map, map.resize);      
     }

     function executeIdentifyTask(evt) {
         //create identify task and setup parameters
         identifyParams1.geometry = evt.mapPoint;
         identifyParams1.mapExtent = map.extent;

         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;
                switch(result.layerName){
                case 'UGA Buildings': 
                    alert("UGA Buildings!!");
                    var template = new esri.InfoTemplate();
                    feature.setInfoTemplate(template);
                    break;
                case 'Road Names':
                    alert("Road Names!!");
                    var template = new esri.InfoTemplate();
                    feature.setInfoTemplate(template);
                    break;
                case 'Cisterns_Point':
                    alert("Cisterns!!");
                    //var template = new esri.InfoTemplate("<iframe src='http://http://falcon.camplan.uga.edu/OUAGISSERVER/rest/services/UGA_SustainBase/MapServer/0/${OBJECTID}/htmlPopup?f=html' frameborder='0' width='100%' height='100%' style='width: 100%; height: 100%; display: block; padding: 0px; margin: 0px;'></iframe>");
                    var template = new esri.InfoTemplate();
                    feature.setInfoTemplate(template);                                        
                    break;
                case 'DinHall_Point':
                    alert("DinHall!!");
                    var template = new esri.InfoTemplate();
                    feature.setInfoTemplate(sustaintemplate);
                    break;
                case 'GrRoofs_Point':
                    alert("Grroofs!!");
                    var template = new esri.InfoTemplate();
                    feature.setInfoTemplate(template);
                    break;
                case 'HistBuild_Point':
                    alert("Histbuild!!");
                    var template = new esri.InfoTemplate();
                    feature.setInfoTemplate(template);
                    break;
                case 'LEED_Point':
                    alert("LEED!!");
                    var template = new esri.InfoTemplate();
                    feature.setInfoTemplate(template);
                    break;
                case 'Prod_Point':
                    alert("Prod!!");
                    var template = new esri.InfoTemplate();
                    feature.setInfoTemplate(template);
                    break;
                case 'Retail_Point':
                    alert("Retail!!");
                    var template = new esri.InfoTemplate();
                    feature.setInfoTemplate(template);
                    break;
                case 'StrRest_Point':
                    alert("Strrest!!");
                    var template = new esri.InfoTemplate();
                    feature.setInfoTemplate(template);
                    break;
                case 'SusBuild_Point':
                    alert("Susbuild!!");
                    var template = new esri.InfoTemplate();
                    feature.setInfoTemplate(template);
                    break;
                case 'RainGardens':
                    alert("Raingar!!");
                    var template = new esri.InfoTemplate();
                    feature.setInfoTemplate(template);
                    break;
                case 'PorPave_Point':
                    alert("PorPave!!");
                    var template = new esri.InfoTemplate();
                    feature.setInfoTemplate(template);
                    break;
                }
                 return feature;
             });
         });

         // InfoWindow expects an array of features from each deferred
         // object that you pass. If the response from the task execution 
         // above is not an array of features, then you need to add a callback
         // like the one above to post-process the response and return an
         // array of features.
         map.infoWindow.setFeatures([deferred1]);
         map.infoWindow.show(evt.mapPoint);


     }  


Any help or advice would be appreciated.

Alex

Attachments

Outcomes