populating dropdown menu with query results

5144
13
06-27-2012 05:45 AM
ChrisBerryman1
New Contributor II
Hello, I am trying to create a dropdown menu for my routing app that allows a user to select from a list of buildings, and when the user selects a building the location of that building is added to the route for them to navigate to.  I have gotten the the drop down menu to populate with buildings, but not from the query results.  I was thinking that it might just be easier to hard code an array that includes all the buildings and the xy coordinates for each building. 

here is the url for my app:
0 Kudos
13 Replies
ReneeMaxwell
Occasional Contributor
Thanks for directing me to that sample, that's what I've been hunting for. I wish they hadn't buried it there but at least it's a start.

I'm disappointed that I will apparently have to significantly rewrite and restructure pretty much all of my code on all of my sites with the new release. The differences are substantial.
0 Kudos
KellyHutchins
Esri Frequent Contributor
Renee,

You don't need to perform a significant re-write to upgrade to 3.0. Here's a version of your sample that works for me that uses 3.0 with the 1.6 style syntax:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
     <html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <meta http-equiv="X-UA-Compatible" content="IE=7,IE=9" />
    <!--The viewport meta tag is used to improve the presentation and behavior of the samples
      on iOS devices-->
    <meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no"/>
    <title>Dojo Dropdown Demo</title>

    <link rel="stylesheet" href="https://community.esri.com//serverapi.arcgisonline.com/jsapi/arcgis/3.0/js/dojo/dijit/themes/claro/claro.css">
    <!-- ArcGIS API for JavaScript -->
    <script type="text/javascript" src="http://serverapi.arcgisonline.com/jsapi/arcgis/?v=3.0compact"></script>



    <script type="text/javascript">


      dojo.require("esri.map");
      dojo.require("esri.tasks.Query");
      dojo.require("dijit.form.FilteringSelect");
      dojo.require("dojo.data.ItemFileReadStore");
      
      dojo.addOnLoad(init);

      var map,queryTask;

      function init() {     
        queryTask = new esri.tasks.QueryTask("http://armstrong.uww.edu/ArcGIS/rest/services/NewCampus/MapServer/27");
      
        map = new esri.Map("map");
    
        dojo.connect(map, "onLoad", function() {
          //populate dropdown 
          executeQuery();
        });

        // Add the campus basemap 
        var campusMap = new esri.layers.ArcGISTiledMapServiceLayer('http://armstrong.uww.edu/ArcGIS/rest/services/NewCampus/MapServer');
        map.addLayer(campusMap);
      }

      function executeQuery() {

          
        //execute the query task then populate the dropdown menu with list of building names 
        var query = new esri.tasks.Query();
        query.returnGeometry = true;
        query.outFields = ["BldgName","FID"];
        query.where = "1=1";
        queryTask.execute(query,populateMenu);
        
      }
      function populateMenu(featureSet){
      
         var items = dojo.map(featureSet.features, function (item) {
                    return {
                        name: item.attributes.BldgName,
                        id:item.attributes.FID
                    };
                });
             var data = {
              identifier:"id",
              items:items
              };
             var objStore = new dojo.data.ItemFileReadStore({data:data});

          var filteringSelect = new dijit.form.FilteringSelect({
            style:'width:300px;',
            placeHolder:'Select a building or start typing',
            store:objStore,
            required:false,
            labelAttr:'name',
            fetchProperties:{sort:[{attribute:'name'}]},
            onChange:function(val){
                if(val){
                  var selectQuery = new esri.tasks.Query();
                  selectQuery.returnGeometry = true;
                  selectQuery.objectIds = [val];
                  queryTask.execute(selectQuery,function(featureSet){  
                    map.graphics.clear(); //clear any existing map graphics 
                    //get the first feature and add to map 
                        if(featureSet.features.length > 0){
                          var symbol = new esri.symbol.SimpleFillSymbol(esri.symbol.SimpleFillSymbol.STYLE_SOLID,
                           new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID,
                           new dojo.Color([255,0,0]), 2),new dojo.Color([255,255,0,0.25]));
                          var feature = featureSet.features[0];
                          var graphic = new esri.Graphic(feature.geometry,symbol);
                          map.graphics.add(graphic);
                    }
                });
                }
            }            
          },'bldgSelect');




      }

    </script>
  </head>

  <body class='claro' style="font-family: Arial Unicode MS,Arial,sans-serif;">

    <input id='bldgSelect'/>
    <div id="wrapper" style="position: relative; width: 700px; height: 500px; border:1px solid #000;">
      <!-- Map canvas -->
      <div id="map" style="position: absolute; width: 700px; height: 500px; z-index: 1;"></div>
    </div>
  </body>

</html>

   
�??





Thanks for directing me to that sample, that's what I've been hunting for. I wish they hadn't buried it there but at least it's a start.

I'm disappointed that I will apparently have to significantly rewrite and restructure pretty much all of my code on all of my sites with the new release. The differences are substantial.
0 Kudos
ReneeMaxwell
Occasional Contributor
Thank you Kelly. It's a shame that we still can't leverage the performance advantages of dojo 1.7.
0 Kudos
ChrisBerryman1
New Contributor II
thats great, thanks.  here is the working url with the dropdown menu if you select goto:  gis.uww.edu/wordpress/jqmmap.php
0 Kudos