Different Identify Params Tolerances In One Popup

1041
4
Jump to solution
10-05-2016 08:12 AM
LloydBronn
Occasional Contributor II

I have a map service with feature and raster layers. I'm trying to configure my popup so that it only displays results from the visible layers toggled on in the layer list. This works setting identifyParams.layerIds = analysisLayer.visibleLayers. However, I need an identifyParams tolerance of around 7 pixels for the features, and 1 pixel for the rasters. Only setting one tolerance gives me results from one or the other. Is it possible to set two difference tolerances in one popup? I've tried writing an if/else statement to define the different tolerances, but the popup disappeared from the map. Here is the code snippet:

function mapReady() {
                    map.on("click", executeIdentifyTask);
                         
                    //create identify tasks and setup parameters
                    identifyTask = new IdentifyTask(analysisURL);
                    identifyParams = new IdentifyParameters();
                    identifyParams.returnGeometry = true;
                    //identifyParams.layerOption = IdentifyParameters.LAYER_OPTION_ALL;
                         //identifyParams.tolerance = 7;
                         //identifyParams.layerIds = [1,2,4,5,6,8,9];
                    //identifyParams.tolerance = 1;
                    //identifyParams.layerIds = [12,13,14,17,18,19];
                    identifyParams.width = map.width;
                    identifyParams.height = map.height;
                         promises = [];
     
                }
                
                    function executeIdentifyTask(event) {
                    identifyParams.geometry = event.mapPoint;
                    identifyParams.mapExtent = map.extent;
                    identifyParams.layerIds = analysisLayer.visibleLayers;
                         promises.push(identifyTask.execute(identifyParams));
                    
                         

                    var iPromises = new all(promises);
                    iPromises.then(lang.hitch(this, function (r) {
                      var idResults = [];
                      arrayUtils.map(r, function(response) {
                        arrayUtils.map(response, function(result) {
                          var feature = result.feature;
                          var layerName = result.layerName;
                          feature.attributes.layerName = layerName;
                          var iTemplate;‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍
0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus

Llyod,

No not quite:

                function mapReady() {
                    map.on("click", executeIdentifyTask);
                    
                    //create identify tasks and setup parameters
                    identifyTask = new IdentifyTask(analysisURL);
                    identifyParams = new IdentifyParameters();
                    identifyParams.width = map.width;
                    identifyParams.height = map.height;
                    identifyParams.returnGeometry = true;
                    identifyParams.layerOption = IdentifyParameters.LAYER_OPTION_ALL;
                    identifyParams.tolerance = 7;
                }
                
                function executeIdentifyTask(event) {
                    identifyParams.geometry = event.mapPoint;
                    identifyParams.mapExtent = map.extent;
                    promises = [];
                    //This is for your non-raster layers
                    var visArr = analysisLayer.visibleLayers;
                    //check to see if the raster layer is visble
                    var rasterIds = [12,13,14,17,18,19], rindex, visRasters = [];
                    for(var r=rasterIds.length; r>0; r--){
                      rindex = visArr.indexOf(rasterIds[r]);
                      if(rindex > 0){
                        visArr.splice(rindex, 1);
                        visRasters.push(rasterIds[r]);
                      }
                    }
                    identifyParams.layerIds = visArr;
                    promises.push(identifyTask.execute(identifyParams));

                    if(visRasters.length > 0){
                      //Now change the identifyParams tolerance to one for your rasters
                      identifyParams.tolerance = 1;
                      //this will be the id(s) for your visible raster layer(s)
                      identifyParams.layerIds = visRasters;
                      promises.push(identifyTask.execute(identifyParams));
                    }
                    
                    var iPromises = new all(promises);
                    iPromises.then(lang.hitch(this, function (r) {
                      var idResults = [];
                      arrayUtils.map(r, function(response) {
                        arrayUtils.map(response, function(result) {
                          var feature = result.feature;
                          var layerName = result.layerName;
                          feature.attributes.layerName = layerName;
                          var iTemplate;

View solution in original post

4 Replies
RobertScheitlin__GISP
MVP Emeritus

Lloyd,

Here is how I would handle it:

                function mapReady() {
                    map.on("click", executeIdentifyTask);
                    
                    //create identify tasks and setup parameters
                    identifyTask = new IdentifyTask(analysisURL);
                    identifyParams = new IdentifyParameters();
                    identifyParams.width = map.width;
                    identifyParams.height = map.height;
                    identifyParams.returnGeometry = true;
                    identifyParams.layerOption = IdentifyParameters.LAYER_OPTION_ALL;
                    identifyParams.tolerance = 7;
                }
                
                function executeIdentifyTask(event) {
                    identifyParams.geometry = event.mapPoint;
                    identifyParams.mapExtent = map.extent;
                    promises = [];
                    //This is for your non-raster layers
                    var visArr = analysisLayer.visibleLayers;
                    //check to see if the raster layer is visble
                    //assuming that your raster layer is id 13
                    var index = visArr.indexOf(13);
                    //if it is visible then remove it from the visible array since you
                    //don't want to use a tolerance of 7 on it.
                    if(index > 0){
                      visArr.splice(index, 1);
                    }
                    identifyParams.layerIds = visArr;
                    promises.push(identifyTask.execute(identifyParams));

                    if(index > 0){
                      //Now change the identifyParams tolerance to one for your raster
                      identifyParams.tolerance = 1;
                      //this needs to be the id for your raster layer
                      identifyParams.layerIds = [13];
                      promises.push(identifyTask.execute(identifyParams));
                    }
                    
                    var iPromises = new all(promises);
                    iPromises.then(lang.hitch(this, function (r) {
                      var idResults = [];
                      arrayUtils.map(r, function(response) {
                        arrayUtils.map(response, function(result) {
                          var feature = result.feature;
                          var layerName = result.layerName;
                          feature.attributes.layerName = layerName;
                          var iTemplate;‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍
0 Kudos
LloydBronn
Occasional Contributor II

OK. There are six rasters, IDs [12,13,14,17,18,19]. Would I add the array to var index = visArr.indexOf(12,13,14,17,18,19);?

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Llyod,

No not quite:

                function mapReady() {
                    map.on("click", executeIdentifyTask);
                    
                    //create identify tasks and setup parameters
                    identifyTask = new IdentifyTask(analysisURL);
                    identifyParams = new IdentifyParameters();
                    identifyParams.width = map.width;
                    identifyParams.height = map.height;
                    identifyParams.returnGeometry = true;
                    identifyParams.layerOption = IdentifyParameters.LAYER_OPTION_ALL;
                    identifyParams.tolerance = 7;
                }
                
                function executeIdentifyTask(event) {
                    identifyParams.geometry = event.mapPoint;
                    identifyParams.mapExtent = map.extent;
                    promises = [];
                    //This is for your non-raster layers
                    var visArr = analysisLayer.visibleLayers;
                    //check to see if the raster layer is visble
                    var rasterIds = [12,13,14,17,18,19], rindex, visRasters = [];
                    for(var r=rasterIds.length; r>0; r--){
                      rindex = visArr.indexOf(rasterIds[r]);
                      if(rindex > 0){
                        visArr.splice(rindex, 1);
                        visRasters.push(rasterIds[r]);
                      }
                    }
                    identifyParams.layerIds = visArr;
                    promises.push(identifyTask.execute(identifyParams));

                    if(visRasters.length > 0){
                      //Now change the identifyParams tolerance to one for your rasters
                      identifyParams.tolerance = 1;
                      //this will be the id(s) for your visible raster layer(s)
                      identifyParams.layerIds = visRasters;
                      promises.push(identifyTask.execute(identifyParams));
                    }
                    
                    var iPromises = new all(promises);
                    iPromises.then(lang.hitch(this, function (r) {
                      var idResults = [];
                      arrayUtils.map(r, function(response) {
                        arrayUtils.map(response, function(result) {
                          var feature = result.feature;
                          var layerName = result.layerName;
                          feature.attributes.layerName = layerName;
                          var iTemplate;
LloydBronn
Occasional Contributor II

Thanks Robert, this works! The popup is reeeealy slow to come up now, though. 

0 Kudos