Skip to content

Commit

Permalink
Enable identify formatters for feature layers.
Browse files Browse the repository at this point in the history
Pass the feature geometry to formatter to allow for calculated area/length/position/etc.
  • Loading branch information
tmcgee committed Dec 22, 2016
1 parent 42356d0 commit 5f79e48
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, feature.geometry);
}
});
}
return feature;
},
identifyError: function (err) {
Expand Down Expand Up @@ -682,4 +694,4 @@ define([
}, this);
}
});
});
});

0 comments on commit 5f79e48

Please sign in to comment.