Is it possible to only Identify on layers that I have in an array

2267
9
05-28-2013 12:36 PM
LuciHawkins
Occasional Contributor III
Hi,

I have been using the Identify tool with     idParams.layerOption = esri.tasks.IdentifyParameters.LAYER_OPTION_VISIBLE;

Well, I do not want some of those "visible" layers identified when a user clicks.  Is it possible to use an array of layer names that I already have built so that only those are displayed in the popup?

Thanks,

Luci
0 Kudos
9 Replies
KenBuja
MVP Esteemed Contributor
IdentifyParameters has the property layerIds, where you can set the layers that the are used in the task.
0 Kudos
VinayBansal
Occasional Contributor II
0 Kudos
LuciHawkins
Occasional Contributor III
I saw those and they would work if my layers were all in 1 map service.  I have over 10 different map services that I need to provide popup information for.  The problem is my identify tool returns a popup for map services that I do not want to show information for.  For example, I do not want popups for my city limits, hydrography, roadways, etc. but since they are visible they are selected when I use LAYER_OPTION_VISIBLE.  I want to filter the results from LAYER_OPTION_VISIBLE against an array I have of layer names.  Only those that are in my array should show up in a popup if they are visible. 

I am a noob and hack at best so any help would be greatly appreciated 🙂

Thanks,

Luci
0 Kudos
KenBuja
MVP Esteemed Contributor
In your loop where your executing each task, why not set the layerIds parameter of idParams for each of the tasks? You could use another array (visibleLayers) where you have stored the visible layers for each layer

        for ( i = 0; i < tasks.length; i++) {//Use 'for' instead of 'for...in' so you can sync tasks with defTasks
            try {
                idParams.layerIds = visibleLayers;
                tasks.execute(idParams, defTasks.callback, defTasks.errback);
                //Execute each task
            } catch (e) {
                console.log("Error caught");
                console.log(e);
                defTasks.errback(e);
                //If you get an error for any task, execute the errback
            }
        }
0 Kudos
LuciHawkins
Occasional Contributor III
Hey,

I have an array built (identLayers) with the layerNames of all of the layers from the 10 or more map services that I want people to be able to query popup information for. I need to be able to take the results of the map click and only produce the popup for the layers that are visible AND whose layerName appears in the array. I tried plugging it into the statement that you added below and it did not work.

for ( i = 0; i < tasks.length; i++) {//Use 'for' instead of 'for...in' so you can sync tasks with defTasks 
try { 
   idParams.layerIds = identLayers;
tasks.execute(idParams, defTasks.callback, defTasks.errback); 
//Execute each task 
} catch (e) { 
console.log("Error caught"); 
console.log(e); 
defTasks.errback(e); 
//If you get an error for any task, execute the errback 

}


This is part of my array code:
function addIdentMaps() { 
//push layers to identify array 
identLayers.push({ 
layerName : 'DEEDS' 
}); 
identLayers.push({ 
layerName : 'Parcels' 
}); 
identLayers.push({ 
layerName : 'ORDINANCES' 
}); 
identLayers.push({ 
layerName : 'RESOLUTIONS' 
}); 
identLayers.push({ 
layerName : 'EASEMENT_Disclaimer' 
});
Thanks! Luci
0 Kudos
KenBuja
MVP Esteemed Contributor
The layerIds property is expecting a array of numbers, like

idParams.layerIds = [0,1,5,9];

Instead of using identLayers, you'll have to build an array that holds the layers you want to show in your popup for each map service.
0 Kudos
LuciHawkins
Occasional Contributor III
I was using layerName because I couldnt figure out how to distinguish between layer DEEDS which is 0 in mapservice1 and layer Parcels which is 0 is mapservice2?  My array using just the layerIds would look like:  [0,1,0,1,0,2,0,1,2,3,4,0,1,2,3,4,5];

Thanks!  Luci
0 Kudos
KenBuja
MVP Esteemed Contributor
Remember, though, that you're executing an IdentifyTask for each individual map service. If you simply wanted to get the visible layers for each service, you could use this

var visLayers = dojo.map(layers, function (layer) {
    return layer.visibleLayers;
});


but that would give you more layers than you want, I suspect. Instead, you'd cycle through each service and add the visible layers for that specific service, so you'd have something like

  visibleLayers = {[0,1],[0,1],[0,2],[0,1,2,3,4],[0,1,2,3,4,5]}

These would have to be in the same order as the tasks, so you could use the line

idParams.layerIds = visibleLayers;
MichaelVolz
Esteemed Contributor

Is it possible for you to put all the data in your 10 mapservices into 1 mapservice?

0 Kudos