//// Identify Widget ////
var identifyParams;
var tasks;
var clickPoint;
//var popup = new esri.dijit.Popup({ fillSymbol: new esri.symbol.SimpleFillSymbol(esri.symbol.SimpleFillSymbol.STYLE_SOLID, new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID, new dojo.Color([255, 0, 0]), 2), new dojo.Color([255, 255, 0, 0.25]))}, dojo.create("div"));
dojo.connect(map, 'onLoad', function () {
//setup generic identify parameters
identifyParams = new esri.tasks.IdentifyParameters();
identifyParams.tolerance = 5;
identifyParams.returnGeometry = true;
identifyParams.layerIds = MYDYNAMICLAYER.visibleLayers;
identifyParams.layerOption = esri.tasks.IdentifyParameters.LAYER_OPTION_VISIBLE;
dojo.connect(map, 'onClick', doIdentify);
});
dojo.connect(map, 'onLayersAddResult', setupIdentify);
function setupIdentify(results) {
//loop through operational layers and add identify task for each.
tasks = dojo.map(results, function (result) {
return new esri.tasks.IdentifyTask(result.layer.url);
});
}
function doIdentify(evt) {
map.infoWindow.hide();
clickPoint = evt.mapPoint;
identifyParams.geometry = evt.mapPoint;
identifyParams.mapExtent = map.extent;
identifyParams.width = map.width;
identifyParams.height = map.height;
identifyParams.layerIds = MYDYNAMICLAYER.visibleLayers;
identifyParams.layerOption = esri.tasks.IdentifyParameters.LAYER_OPTION_VISIBLE;
var deferreds = dojo.map(tasks, function (task) {
return task.execute(identifyParams);
});
var dlist = new dojo.DeferredList(deferreds);
dlist.then(handleQueryResults);
}
function handleQueryResults(results) {
var features = [];
dojo.forEach(results, function (result) {
// for a simplified test let's just display all the attributes in the popup
if (result[1].length > 0) {
dojo.forEach(result[1], function (r) {
var feature = r.feature;
console.log(feature);
feature.attributes.layerName = r.layerName;
var infoTemplate = new esri.InfoTemplate("${name}", "${*}");
feature.setInfoTemplate(infoTemplate);
features.push(feature);
});
}
});
map.infoWindow.setFeatures(features);
map.infoWindow.show(clickPoint);
}
//// ^^^ Identify Widget //// var infoTemplate = new esri.dijit.PopupTemplate({
description: feature.attributes.layerName,
fieldInfos: [{
fieldName: "*",
visible: true,
label: "*"
}]
});
I am with you on the UI aspect. However, it's over 100 layers each with 15+ fields and many may change soon so this is the best approach for now for us. The esri.dijit.PopupTemplate can do this, it does support wildcards for all fields, just like infoTemplate, right?
var infoTemplate = new esri.dijit.PopupTemplate({
title: feature.attributes.layerName,
description: "{*}"
});
define(['dojo/_base/array', 'helpers/templateBuilder'], function(array, templateBuilder) {
// do something on a click or identify
array.forEach(featureSet, function(feat) {
feat = templateBuilder.buildInfoTemplate(feat);
});
// do something for results
});
var content = [],
urlField = options ? options.urlField : '', // you can include url info in options
urlPrefix = options ? options.urlPrefix : ''; // you can include url info in options
// get the dom element for my infotemplate as a string
content[content.length] = '<table cellspacing="0" class="table table-striped table-condensed attr-info">';
if (feature.layerName) {
content[content.length] = '<tr><td class="fieldName">SOURCE: </td><td class="fieldName">' + feature.layerName + '</td></tr>';
}
/**
* Iterate over attributes to get field names.
* Ignore certain fields not needing to be displayed
* Order matters, so loop forward over keys.
**/
var keys = Object.keys(feature.attributes),
i = 0,
len = keys.length;
// This is where al the real work is done.
for (; i < len; i++) {
var _key = keys.toLowerCase(),
name;
// add any other values you want to ignore into this if statment || _key === 'objectid2' for example
if (!(_key.indexOf('shape') > -1 || _key === 'layername'|| _key === 'objectid' || _key === 'fid')) {
name = keys;
if (name.toLowerCase() !== urlField) {
content[content.length]= '<tr><td class="fieldName">' + name + '</td><td>${' + name + '}</td></tr>';
} else {
content[content.length] = '<tr><td class="fieldName">' + name + '</td><td><a href="' + urlPrefix + '${' + name + '}">${' + name + '}</a></td></tr>';
}
}
}
content[content.length] = '</table>';
I don't use the popup thingy at all - I redirect all to a floating pane and then go through each found layer, and each result in the layer to produce something like the attached - basically replicating what we had in ArcIMS 🙂
[ATTACH=CONFIG]23880[/ATTACH]
So it is important to only expose the fields you want to see in the ArcMap MXD. By using the layer description I have also manage a feature specific hyperlink (again like ArcIMS)
Shout if you want to see the code
ACM