Skip to content

Instantly share code, notes, and snippets.

@tedrick
Created May 13, 2016 12:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tedrick/048587fa29ec168ed210c93d5df87307 to your computer and use it in GitHub Desktop.
Save tedrick/048587fa29ec168ed210c93d5df87307 to your computer and use it in GitHub Desktop.
Dynamic Text for Story Map example
require(
["esri/tasks/query", "esri/tasks/QueryTask", "dojo/query", "dojo/NodeList-html"],
function(Query, QTask, dQuery){
var config = {
url: <LAYER URL>
query: "1=1",
fields: [<STAT FIELD(s)>],
dynTextMapping: {
statement: {
field: "datetext",
method:"FIRST",
target: "#REPLACE_ME"
}
},
};
var q = new Query();
q.where = config.query;
q.outFields = config.fields;
q.returnGeometry = false;
var qt = new QTask(config.url);
qt.execute(q, function(fSet){
var dataSet = fSet.features.map(function(obj){
return obj.attributes;
});
for (var key in config.dynTextMapping) {
if (!config.dynTextMapping.hasOwnProperty(key)) continue;
var thisAttrSpec = config.dynTextMapping[key];
var thisText = "";
switch (thisAttrSpec.method) {
case "FIRST":
thisText = dataSet[0][thisAttrSpec.field];
break;
case "SUM":
break;
case "AVERAGE":
break;
default:
break;
}
var tNode = dQuery(thisAttrSpec.target).html(thisText);
}
});
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment