hi, I'm working with the version 3.17 and I'm generating popups to display feature attributes using the IdentifyTask object. I basically used the sample code for "Display identify results in a popup". I have two issues:
1) I used the LAYER_OPTION_VISIBLE setting for my identify parameters. But it's still identifying on features that aren't visible. I don't know why...
2) When I click on the map but not on a feature, a popup displays saying "No information available". I'd like nothing to pop up when I do this, because I have other click tools and I don't want this to pop up unnecessarily. Not sure how to do this..
Thanks for any help...
P.S. I would love to provide my code but I have absolutely no idea how to cut and paste it. I tried to do it directly and also using the "Javascript Syntax Highlighting" thing. In both cases, the spacing is completely messed up and I see strange squiggles and boxes, etc. Sorry...
Solved! Go to Solution.
1) In your Identify Parameters, define the layerIds as only the visible layers on the map for the selected layer
identifyParams.layerIds = myLayer.visibleLayers;
You can do this in the executeIdentifyTask function if your visible layers are goint to change dynamically
2) Set the popup to only show if the identify response returns 1 or more feature
function executeIdentifyTask (event) { map.infoWindow.hide(); identifyParams.geometry = event.mapPoint; identifyParams.mapExtent = map.extent; var deferred = identifyTask .execute(identifyParams) .addCallback(function (response) { // response is an array of identify result objects // Let's return an array of features. if (response.length > 0) { map.infoWindow.show(event.mapPoint); return arrayUtils.map(response, function (result) { var feature = result.feature; var layerName = result.layerName; feature.attributes.layerName = layerName; if (layerName === 'Tax Parcels') { var taxParcelTemplate = new InfoTemplate("", "${Postal Address} <br/> Owner of record: ${First Owner Name}"); feature.setInfoTemplate(taxParcelTemplate); } else if (layerName === 'Building Footprints') { console.log(feature.attributes.PARCELID); var buildingFootprintTemplate = new InfoTemplate("", "Parcel ID: ${PARCELID}"); feature.setInfoTemplate(buildingFootprintTemplate); } return feature; }); } }); // InfoWindow expects an array of features from each deferred // object that you pass. If the response from the task execution // above is not an array of features, then you need to add a callback // like the one above to post-process the response and return an // array of features. map.infoWindow.setFeatures([deferred]); }
1) In your Identify Parameters, define the layerIds as only the visible layers on the map for the selected layer
identifyParams.layerIds = myLayer.visibleLayers;
You can do this in the executeIdentifyTask function if your visible layers are goint to change dynamically
2) Set the popup to only show if the identify response returns 1 or more feature
function executeIdentifyTask (event) { map.infoWindow.hide(); identifyParams.geometry = event.mapPoint; identifyParams.mapExtent = map.extent; var deferred = identifyTask .execute(identifyParams) .addCallback(function (response) { // response is an array of identify result objects // Let's return an array of features. if (response.length > 0) { map.infoWindow.show(event.mapPoint); return arrayUtils.map(response, function (result) { var feature = result.feature; var layerName = result.layerName; feature.attributes.layerName = layerName; if (layerName === 'Tax Parcels') { var taxParcelTemplate = new InfoTemplate("", "${Postal Address} <br/> Owner of record: ${First Owner Name}"); feature.setInfoTemplate(taxParcelTemplate); } else if (layerName === 'Building Footprints') { console.log(feature.attributes.PARCELID); var buildingFootprintTemplate = new InfoTemplate("", "Parcel ID: ${PARCELID}"); feature.setInfoTemplate(buildingFootprintTemplate); } return feature; }); } }); // InfoWindow expects an array of features from each deferred // object that you pass. If the response from the task execution // above is not an array of features, then you need to add a callback // like the one above to post-process the response and return an // array of features. map.infoWindow.setFeatures([deferred]); }
thanks FC! Much appreciated!!
Dan