Skip to content

Commit

Permalink
Merge pull request #655 from cmv/feature/formatters-for-feature-layers
Browse files Browse the repository at this point in the history
Enable identify formatters for feature layers.
  • Loading branch information
DavidSpriggs authored Jan 1, 2017
2 parents 42356d0 + 7984458 commit f636350
Showing 1 changed file with 20 additions and 8 deletions.
28 changes: 20 additions & 8 deletions viewer/js/gis/dijit/Identify.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,13 @@ define([
infoTemplate = this.getInfoTemplate(layer, layer.layerId);
if (infoTemplate) {
layer.setInfoTemplate(infoTemplate);
var fieldInfos = infoTemplate.info.fieldInfos;
var formatters = array.filter(fieldInfos, function (info) {
return (info.formatter);
});
if (formatters.length > 0) {
layer.on('graphic-draw', lang.hitch(this, 'getFormattedFeature', layer.infoTemplate));
}
return;
}
}
Expand Down Expand Up @@ -343,18 +350,23 @@ define([
return;
}
}
var feature = this.getFormattedFeature(result.feature);
var feature = this.getFormattedFeature(result.feature.infoTemplate, result.feature);
fSet.push(feature);
}, this);
}, this);
this.map.infoWindow.setFeatures(fSet);
},
getFormattedFeature: function (feature) {
array.forEach(feature.infoTemplate.info.fieldInfos, function (info) {
if (typeof info.formatter === 'function') {
feature.attributes[info.fieldName] = info.formatter(feature.attributes[info.fieldName], feature.attributes);
}
});
getFormattedFeature: function (infoTemplate, feature) {
if (feature.graphic) {
feature = feature.graphic;
}
if (feature && infoTemplate && infoTemplate.info) {
array.forEach(infoTemplate.info.fieldInfos, function (info) {
if (typeof info.formatter === 'function') {
feature.attributes[info.fieldName] = info.formatter(feature.attributes[info.fieldName], feature.attributes, lang.clone(feature.geometry));
}
});
}
return feature;
},
identifyError: function (err) {
Expand Down Expand Up @@ -682,4 +694,4 @@ define([
}, this);
}
});
});
});

0 comments on commit f636350

Please sign in to comment.