infoWindow.setTitle problem

2501
0
10-15-2012 05:19 AM
KeithGanzenmuller
Occasional Contributor II
I'm having a problem setting the title on the maps infoWindow. The script will not show the infowindow if I attempt to use the attribute of the selected graphic.
I have a feature layer with an infoWindow template that works great on click, shows the title of the infoWindow derived from the ProjectName attribute.
The maps infoWindow takes its information from the same featurelayer but only shows, by design, when the user clicks the projects row in the datagrid.

The problem comes if I try to set the title using the value returned from the selected feature. I will include the code below:

//this populates the datagrid with only those projects in the map.extent. dojo.connect(map, "onExtentChange", function(extent){ var selectQuery = new esri.tasks.Query(); selectQuery.geometry = map.extent; CIPLayer.queryFeatures(selectQuery,  function(featureSet){                 var items = dojo.map(featureSet.features,function(feature){               return feature.attributes;             });             var data = {                 identifier:"OBJECTID",                 items:items};             store = new dojo.data.ItemFileReadStore({data:data});             //grid = dojo.byId("grid")              grid.setStore(store);                     });   });          //this selects the project feature based on the grid row click.   dojo.connect(grid, "onRowClick", onRowClickHandler);        function onRowClickHandler(evt){             var myObjectID = grid.getItem(evt.rowIndex).OBJECTID;             myquery = "OBJECTID = " + myObjectID         var query = new esri.tasks.Query();             query.where = myquery//"OBJECTID=1";             query.returnGeometry = true;             query.outFields = ["*"];         CIPLayer.selectFeatures(query, esri.layers.FeatureLayer.SELECTION_NEW);                    }                           //this fires when the above selection completes.  dojo.connect(CIPLayer, "onSelectionComplete", CIPselectcomplete);     function CIPselectcomplete(){              var selectedProject = CIPLayer.getSelectedFeatures();              map.infoWindow.setContent(getWindowContent(selectedProject[0])); //these two attempts below fail and the infoWindow does not show              //titletext = "<div>" + selectedProject[0].attributes.ProjectName + "</div>";              //map.infoWindow.setTitle(selectedProject[0].attributes.ProjectName); //this below works, the title appears as "test title" with the correct project info in the tab container.               titletext = "test title";              map.infoWindow.setTitle(titletext); //this alert window shows the correct ProjectName                           alert(selectedProject[0].attributes.ProjectName);              map.infoWindow.show(selectedProject[0].geometry);                }  // this formats the infoWindow content       function getWindowContent(graphic) {         //make a tab container               var anchor = "<a href='http://70.167.136.51/Assets/CIP/" + graphic.attributes.DocName + "'target= _blank>Project Document</a>";         var tc = new dijit.layout.TabContainer({            style: "height: 100%; width: 100%;background-color:Maroon;"         }, dojo.create("div"));          //tab 1         var cp1 = new dijit.layout.ContentPane({           title: "Details",           style: "padding:3px;padding-left:7px;background-color:Cornsilk;color: DimGray;",           content: "<div style='color: DarkSlateGray;'>Project Number: <b>" + graphic.attributes.ProjectNumber + "</b></div><br><div>Latest Update:<ul><li>" + graphic.attributes.ProjectUpdate           + "</ul><br></div>" +           "<div>Would you like more information? " + anchor + "</div>"         });         tc.addChild(cp1);         //tab 2         var cp2 = new dijit.layout.ContentPane({           title: "Project Description",           style: "padding:7px;padding-top:10px;background-color:Cornsilk;",           content: "<div style='color: DarkSlateGray;'>" + graphic.attributes.ProjectDescription  +  "</div>"         });          tc.addChild(cp2);          return tc.domNode;        }     


Well, seems like I have it working now.

 //this works titletext = "<div>" + selectedProject[0].attributes.ProjectName + "</div>"; map.infoWindow.setTitle(titletext);  //This does not work  titletext = selectedProject[0].attributes.ProjectName; map.infoWindow.setTitle(titletext);


Thanks,
Keith
0 Kudos
0 Replies