map.on("click", executeIdentifyTask); function executeIdentifyTask(evt) { map.graphics.clear(); layerClickGraphic.clear(); layerResultsGraphic.clear(); identifyParams.geometry = evt.mapPoint; identifyParams.mapExtent = map.extent; identifyParams.layerIds = layerDynamic.visibleLayers; layerClickGraphic.add(new esri.Graphic(evt.mapPoint, symbolClick)); identifyTask.execute(identifyParams, function (results) { populateTC(results, evt); }); }
I am not using the IdentifyTask, I was hoping not to override the response.clickEventHandle in the AGOL webmap. I have all the popups defined in AGOL and I am trying to avoid manually coding popups.
Thanks!
//added global var to handle TOC popups if (configOptions.custPopup === "TOC") { operationalLayers = response.itemInfo.itemData.operationalLayers; dojo.forEach(operationalLayers, function(layer) { dojo.forEach(layer.layers, function(sublayer) { dojo.forEach(sublayer.popupInfo.fieldInfos, function(fieldInfo) { //move alias values into fieldname so it will work as fieldInfo fieldInfo.fieldName = fieldInfo.label; }); }); }); }
function executeTOCIdentifyTask(evt) { //set the visible layers for the ID var layers = []; dojo.forEach(toc.layerInfos[0].layer._tocInfos, function(layer) { if (layer.visible) { layers.push(layer.id); } }); if (layers.length > 0) { identifyParams.geometry = evt.mapPoint; identifyParams.mapExtent = map.extent; identifyParams.tolerance = 9; identifyParams.returnGeometry = true; identifyParams.layerIds = layers; identifyParams.layerOption = esri.tasks.IdentifyParameters.LAYER_OPTION_VISIBLE; identifyParams.width = map.width; identifyParams.height = map.height; identifyParams.timeExtent = map.timeExtent; var deferred = identifyTask.execute(identifyParams); deferred.addCallback(function(response) { return dojo.map(response, function(result) { var feature = result.feature; var template; dojo.forEach(operationalLayers[0].layerObject.layerInfos, function(layer) { //get the right layer from operationalLayers if (result.layerName == layer.name) { //get the right popup from operationalLayers dojo.forEach(operationalLayers[0].layers, function(popup) { if (popup.id == layer.id) { template = new esri.dijit.PopupTemplate({ title: popup.popupInfo.title, fieldInfos: popup.popupInfo.fieldInfos, showAttachments : popup.popupInfo.showAttachments }); } }); } }); feature.setInfoTemplate(template); return feature; }); }); map.infoWindow.setFeatures([deferred]); map.infoWindow.show(evt.mapPoint); } }
I sorta found a solution. It is a bit convoluted and involved overriding the response.clickEventHandle of the AGOL webmap.
I created global var that includes popup info from AGOL.//added global var to handle TOC popups if (configOptions.custPopup === "TOC") { operationalLayers = response.itemInfo.itemData.operationalLayers; dojo.forEach(operationalLayers, function(layer) { dojo.forEach(layer.layers, function(sublayer) { dojo.forEach(sublayer.popupInfo.fieldInfos, function(fieldInfo) { //move alias values into fieldname so it will work as fieldInfo fieldInfo.fieldName = fieldInfo.label; }); }); }); }
Then i added function to execute ID task using the AGOL popups.function executeTOCIdentifyTask(evt) { //set the visible layers for the ID var layers = []; dojo.forEach(toc.layerInfos[0].layer._tocInfos, function(layer) { if (layer.visible) { layers.push(layer.id); } }); if (layers.length > 0) { identifyParams.geometry = evt.mapPoint; identifyParams.mapExtent = map.extent; identifyParams.tolerance = 9; identifyParams.returnGeometry = true; identifyParams.layerIds = layers; identifyParams.layerOption = esri.tasks.IdentifyParameters.LAYER_OPTION_VISIBLE; identifyParams.width = map.width; identifyParams.height = map.height; identifyParams.timeExtent = map.timeExtent; var deferred = identifyTask.execute(identifyParams); deferred.addCallback(function(response) { return dojo.map(response, function(result) { var feature = result.feature; var template; dojo.forEach(operationalLayers[0].layerObject.layerInfos, function(layer) { //get the right layer from operationalLayers if (result.layerName == layer.name) { //get the right popup from operationalLayers dojo.forEach(operationalLayers[0].layers, function(popup) { if (popup.id == layer.id) { template = new esri.dijit.PopupTemplate({ title: popup.popupInfo.title, fieldInfos: popup.popupInfo.fieldInfos, showAttachments : popup.popupInfo.showAttachments }); } }); } }); feature.setInfoTemplate(template); return feature; }); }); map.infoWindow.setFeatures([deferred]); map.infoWindow.show(evt.mapPoint); } }
Pat
This looks like exactly what I need but I can't see exactly how to get it to work in my application. We have a modified version of the ESRI Basic Viewer Template with the TOC widget up and running
I'm not clear on a few things that hopefully you can provide some more detail on
1. How to ovverride the response.clickeventhandle
2. Where this code should be inserted (I'm assuming in the main layout.js rather than in the TOC.js)
3. how to call the executeTOCIdentifyTask function
Any help would be greatly appreciated
Thanks
Simon