Using If...Then Statements from Attributes

733
2
09-20-2011 08:54 AM
BenReilly
New Contributor
Is there a way to have Javascript's If/Then statements work from a polygon's attributes? I was just wondering since it would be a great way to add functionality to a web application. I'm developing a building floor plan map, and would like the search function to be able to automatically switch to a room's given floor automatically. Something like (this is just a rough idea) if floor = "1" then [run function that shows floor one], else if floor = "2" [run function that shows floor two] and so on. Has anybody tried this or had any luck using this (or a similar) method?
0 Kudos
2 Replies
derekswingley1
Frequent Contributor
Yes. I would see this as allowing someone to search via a text box or drop down list. When the search runs (a "search" button is clicked or the value of the drop down changes), the app hits a layer in a map service via a queryTask. Once the queryTask returns results, you loop through them and then use an if/then or switch statement to do something.
0 Kudos
StephenLead
Regular Contributor III
if floor = "1" then [run function that shows floor one], else if floor = "2" [run function that shows floor two] and so on


Ben,

Just a small comment. Rather than having a separate function for each floor, a potentially more robust and scalable method would be:

function showFloor(floor_number) {
  //run code to show floor = floor_number
}


Cheers,
Steve
0 Kudos