Select to view content in your preferred language

need help with ArcGIS API Javascript sidebar

1181
6
06-04-2012 07:13 PM
LisaD
by
Emerging Contributor
This is an assignment but I am really stuck and when I can work on the assignment my professor is asleep so I can't get help until the next day (tough when the assignment is due in 2 days and you are only 1/3rd done).  Anyway, I created a map with 3 layers.  One is a basemap and 2 show election information for two different candidates.  I got that part of the map to work but I am having trouble incorporating a clickable sidebar.  Right now I get no map with the sidebar titles at the top left of the page. I attached my code.  Any help would be greatly appreciated.
0 Kudos
6 Replies
BenStewart
Deactivated User
I can't get this to work at all on my machine, are you sure it works on yours? A couple changes I made that are necessary

1. The call to the <script type="text/javascript" src="http://serverapi.arcgisonline.com/jsapi/arcgis/?v=2.8"></script> needs to come before the vvar djconfig { parseOnLoad: true };
2. In the init call implements a definition query qryStates that I don't see anywhere.
3. In the function initOperationalLayer() your first renderer is set on featureLayer, when I think it should be on states

Try those and see what happens, but I still think you need a lot of work
0 Kudos
LisaD
by
Emerging Contributor
I was able to get a little further last night.  However, I still have lines of code that make my map vanish (commented out of my code right now) and the table in my sidebar is not showing up.  What I would like is for a third layer that has all those states to be used for the sidebar.  Right now when you click a state an info window comes up based on that particular candidate layer.  I want it to pull from one layer.  I am not sure how right now.  I will check out your suggestions as well.

http://www.personal.psu.edu/lud143/lesson5e.html
0 Kudos
BenStewart
Deactivated User
To start, what are you using to debug your javascript? Regardless of what it is, I would suggest using firebug for firefox.

Anyway, I see two problems with the section with the line you comment as //map vanishes... First, you are registering a function to execute on featureLayer's onLoad event, but featureLayer is not defined, should that be states? What is the purpose of that event? Second, in the query definition for that connection, the qrystates is not defined.

Anyway, I have attached a piece of code below from a website of mine, sorry I can't give you a live version. It defines a data table and the events for it, the populates that table as well

//This function creates the Data table at the bottom of the page storing all the projects
 function createDataTable(){
  var data = { identifier: 'id', items: [] };
  
  //Create the store object to populate the table
  var rows=nProj;
  for (var i=0; i < rows; i++){ data.items.push(dojo.mixin({ id:i+1 }, projectTable)); }
  var store = new dojo.data.ItemFileWriteStore({data:data});
  
  //Define layout
  var layout = [[
   {'name':'Project ID','field':'projID', 'width':'100px'},
   {'name':'Title','field':'Title', 'width':'500px'},
   {'name':'Provider','field':'Provider', 'width':'100px'},
   {'name':'Seeker','field':'Seeker', 'width':'100px'},
   {'name':'Topic','field':'Topic', 'width':'200px'},
   {'name':'Sub Topic','field':'SubTopic', 'width':'300px'},
  ]];
  
  var grid = new dojox.grid.DataGrid({
   id:'grid',
   store:store,
   structure:layout,
   rowSelector:'20px'}, 
   document.createElement('div')
  );
  
  dojo.byId("projectInformation").appendChild(grid.domNode);
  grid.startup();
  
  //Event handlers below are used to visualize projects. A single click maps a single connection, a double click maps and entire project
  dojo.connect(grid, "onRowClick", grid, function(evt){
   var idx = evt.rowIndex,
   item = this.getItem(idx);
   var defn = "Provider='" + item.Provider + "' AND Seeker='" + item.Seeker + "' AND ProjectID='" + item.projID + "'";
   mapLines(defn);
  }); 
  
  dojo.connect(grid, "onRowDblClick", grid, function(evt){
   var idx = evt.rowIndex,
   item = this.getItem(idx);
   var defn = "ProjectID='" + item.projID + "'";
   mapLines(defn);
  }); 
 }
0 Kudos
LisaD
by
Emerging Contributor
I am attempting to use states as that third layer so the grid is not pulling data from the candidate layers.  I want it to pull from the 3rd layer for the sidebar and infoWindow.
0 Kudos
LisaD
by
Emerging Contributor
One last thing - everything works now except the "clickable" sidebar.  The assignment calls for either getting an info window when you click the map or when you click the name in the sidebar.  I already have the clicking the map right but the over-achiever in me would like to get the sidebar to work.  My code is at the same page indicated above.  I know this has to do with the query and defining the query but I don't understand exactly what the query does so I can't work it out.  Any help would be appreciated.
0 Kudos
BenStewart
Deactivated User
The onRowClickHandler is firing, just not doing anything. You get the objectiID in the first line, but after that I am a bit confused about what you are doing.

I would try to use that OBJECTID to make a selection query, then select the features you want using a query feature. You could then set up a dojo handler to handle selection complete on the layer

  var query = new esri.tasks.Query();
  query.where= "OBJECTID = " + clickedStatesID 
  featureLayer.selectFeatures(query,esri.layers.FeatureLayer.SELECTION_NEW);
0 Kudos