Show InfoWindow on Table Selection

687
6
Jump to solution
11-19-2014 09:23 AM
WesAskew
New Contributor II

I am trying to show the infowindow of a point when the specific point's OBJECTID is clicked on in a table.  I am able to get a blank infowindow to show, but no title or attributes are displayed.  Could someone please direct me to what I am missing? The function that I am currently calling is attached.  Any help is greatly appreciated!  Thanks in advance.

0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus

Wesley,

  I had to put together a sample to figure out what was going wrong. Here is your corrected function, lines 13, 17 and 18 are the fix (use InfoTemplate instead of PopupTemplate).

   function selectSite(e) {

            // select the feature

            var queryGrid = new Query();

            queryGrid.objectIds = [e.target.innerHTML];

            sitesQuery.selectFeatures(queryGrid, featureLayer.SELECTION_NEW, function(result) {

              if (result.length > 0) {

                // re-center the map to the selected feature

               var pt = result[0];

               var ptGeom = result[0].geometry;

               var factor = 10; //some factor for converting point to extent

               var newExtent = new Extent(ptGeom.x - factor, ptGeom.y - factor, ptGeom.x + factor, ptGeom.y + factor, ptGeom.spatialReference);

               map.setExtent(newExtent);

               var template = new InfoTemplate({title: "Site"});

               template.setContent("<tr><b>Facility: </b><td>${FAC_NAME}</tr><br><tr><b>Address: </b><td>${ADDRESS_1} ${CITY}, ${STATE_CODE} ${ZIP_CODE}<br><tr><b>Contamination Type: </b><td>${CONTAM_TYPE}</tr></td><br><tr><b>Latitude: </b><td>${LAT_DECIMAL}</tr></td><br><tr><b>Longitude: </b><td>${LONG_DECIMAL}</tr>");

           

               pt.setInfoTemplate(template);           

               map.infoWindow.setFeatures([pt]);

               map.infoWindow.show(ptGeom);

              } else {

                alert("Select an OBJECTID to Zoom to Feature");

              };

            });   

    }

View solution in original post

0 Kudos
6 Replies
RobertScheitlin__GISP
MVP Emeritus

Wesley,

   Are you sure that "e.target.innerHTML" is actually getting the ObjectID?

Did you try a console.info(e.target.innerHTML);

0 Kudos
WesAskew
New Contributor II

Thanks for your response. Yes, e.target.innerHTML returns the proper ObjectID. I also checked the ObjectID of the associated graphic by using alert(pt.attributes.OBJECTID);. Something seems to be missing when creating the infowindow that prevent the attributes from displaying.

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Wesley,

   So does the sitesQuery FeatureLayer have FAC_NAME, ADDRESS_1, etc, etc in its out fields?

Have you tried to print the pt.attributes to the console?

0 Kudos
WesAskew
New Contributor II

Yes, all necessary attributes are present and will print to the console.

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Wesley,

  I had to put together a sample to figure out what was going wrong. Here is your corrected function, lines 13, 17 and 18 are the fix (use InfoTemplate instead of PopupTemplate).

   function selectSite(e) {

            // select the feature

            var queryGrid = new Query();

            queryGrid.objectIds = [e.target.innerHTML];

            sitesQuery.selectFeatures(queryGrid, featureLayer.SELECTION_NEW, function(result) {

              if (result.length > 0) {

                // re-center the map to the selected feature

               var pt = result[0];

               var ptGeom = result[0].geometry;

               var factor = 10; //some factor for converting point to extent

               var newExtent = new Extent(ptGeom.x - factor, ptGeom.y - factor, ptGeom.x + factor, ptGeom.y + factor, ptGeom.spatialReference);

               map.setExtent(newExtent);

               var template = new InfoTemplate({title: "Site"});

               template.setContent("<tr><b>Facility: </b><td>${FAC_NAME}</tr><br><tr><b>Address: </b><td>${ADDRESS_1} ${CITY}, ${STATE_CODE} ${ZIP_CODE}<br><tr><b>Contamination Type: </b><td>${CONTAM_TYPE}</tr></td><br><tr><b>Latitude: </b><td>${LAT_DECIMAL}</tr></td><br><tr><b>Longitude: </b><td>${LONG_DECIMAL}</tr>");

           

               pt.setInfoTemplate(template);           

               map.infoWindow.setFeatures([pt]);

               map.infoWindow.show(ptGeom);

              } else {

                alert("Select an OBJECTID to Zoom to Feature");

              };

            });   

    }

0 Kudos
WesAskew
New Contributor II

Thanks a lot!  I figured it was something simple but could not determine what.

0 Kudos