mcdade31

Turn off Popups for certain layers only

Discussion created by mcdade31 on Feb 27, 2013
Latest reply on Feb 28, 2013 by peter_siebert
Is there a way to turn off popups for only certain layers? My app loops through the visible layers and returns a popup for each. Some of the layers only show boundaries, so I don't need anything to be created for it.

the loop:
function initIdentifies(map) {
        idParams = new esri.tasks.IdentifyParameters();
                idParams.tolerance = 5;
                idParams.returnGeometry = true;
                idParams.layerOption = esri.tasks.IdentifyParameters.LAYER_OPTION_VISIBLE;
                dojo.connect(map, "onClick", runIdentifies);
            }
            function runIdentifies(evt) {
                var layers = dojo.map(map.layerIds, function(layerId) {
                    return map.getLayer(layerId);
                }); //Create an array of all layers in the map
                layers = dojo.filter(layers, function(layer) {
                    return layer.getImageUrl && layer.visible;
                }); //Only dynamic layers have the getImageUrl function. Filter so you only query visible dynamic layers
                var tasks = dojo.map(layers, function(layer) {
                    return new esri.tasks.IdentifyTask(layer.url);
                }); //map each visible dynamic layer to a new identify task, using the layer url
                var defTasks = dojo.map(tasks, function (task) {
                    return new dojo.Deferred();
                }); //map each identify task to a new dojo.Deferred
                var dlTasks = new dojo.DeferredList(defTasks); //And use all of these Deferreds in a DeferredList
                dlTasks.then(IDResults); //chain IDResults onto your DeferredList
                idParams.width = map.width;
                idParams.height = map.height;
                idParams.geometry = evt.mapPoint;
                idParams.mapExtent = map.extent;
                for (i=0;i<tasks.length;i++) { //Use 'for' instead of 'for...in' so you can sync tasks with defTasks
                    try {
                        tasks[i].execute(idParams, defTasks[i].callback, defTasks[i].errback); //Execute each task
                    } catch (e) {
                        console.log("Error caught");
                        console.log(e);
                        defTasks[i].errback(e); //If you get an error for any task, execute the errback
                    }
                }
            }


How I built my popups:
function IDResults(r) {
                var results = [];
                r = dojo.filter(r, function (result) {
                    return r[0];
                }); //filter out any failed tasks
                for (i=0;i<r.length;i++) {
                    results = results.concat(r[i][1]);
                }
                results = dojo.map(results, function(result) {
            var feature = result.feature;
            feature.attributes.layerName = result.layerName;
            if(result.layerName === 'Zoning Classifications'){
              console.log(feature.attributes.NAME);
              var template = new esri.dijit.PopupTemplate({
       title:"Zoning",
       description:"<b>Zoning:</b> {Zoning Classification} <br/> <b>Description:</b> {Zoning Description}"
       });
              feature.setInfoTemplate(template);
            }
            else if (result.layerName === 'Assisted Living Facilities'){
              var template = new esri.dijit.PopupTemplate({
       title:"Assisted Living Facilities",
       description:"<b>Parcel ID:</b> {Parcel} <br/> <b>Applicant:</b> {BusinessApplicantName} <br/> <b>No. of Residents</b> {NbrResidents}"
       });
              feature.setInfoTemplate(template);
            }
      else if (result.layerName === 'Family Divisions'){
              var template = new esri.dijit.PopupTemplate({
       title:"Family Divisions",
       description:"<b>Parcel ID:</b> {Parcel} <br/> <b>Project Number:</b> {project_nbr} </br> <b>Status:</b> {Status}"
       });
              feature.setInfoTemplate(template);
            }
return feature;

if(results.length === 0) {
                    map.infoWindow.clearFeatures();
                } else {
                    map.infoWindow.setFeatures(results);
                }
                map.infoWindow.show(idParams.geometry);
                return results;
            }

Outcomes