Skip to content

Commit

Permalink
Add the ability to add custom field formatters
Browse files Browse the repository at this point in the history
  • Loading branch information
green3g committed Oct 10, 2016
1 parent 3d12b9a commit 5c869df
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
21 changes: 18 additions & 3 deletions viewer/js/config/identify.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
define([
'dojo/i18n!./nls/main'
], function (i18n) {
'dojo/i18n!./nls/main',
'dojo/_base/lang'
], function (i18n, lang) {

var linkTemplate = '<a href="{url}" target="_blank">{text}</a>';
var directionsFormatter = function(noValue, attributes){
return lang.replace(linkTemplate, {
url: 'https://www.google.com/maps/dir/' + attributes.Address + ' Louisville, KY',
text: 'Get Directions'
});
};
return {
map: true,
mapClickMode: true,
Expand Down Expand Up @@ -30,6 +38,13 @@ define([
2: {
title: i18n.identify.louisvillePubSafety.policeStation,
fieldInfos: [{
// example of adding a 'calculated' or formatted field
// click on a louisville kentucky police station to see
// the result
fieldName: 'Directions',
visible: true,
formatter: directionsFormatter
},{
fieldName: 'Name',
visible: true
}, {
Expand Down Expand Up @@ -62,4 +77,4 @@ define([
}
}
};
});
});
12 changes: 11 additions & 1 deletion viewer/js/gis/dijit/Identify.js
Original file line number Diff line number Diff line change
Expand Up @@ -313,11 +313,21 @@ define([
return;
}
}
fSet.push(result.feature);
var feature = this.getFormattedFeature(result.feature);
// console.log(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);
}
});
return feature;
},
identifyError: function (err) {
this.map.infoWindow.hide();
topic.publish('viewer/handleError', {
Expand Down

0 comments on commit 5c869df

Please sign in to comment.