AnsweredAssumed Answered

arcgis javascript how to layer`s custom field & value rendering

Question asked by guriguri1576 on Sep 28, 2016
Latest reply on Sep 28, 2016 by guriguri1576

I try to rendering. To add custom statistics data to the layer.
when... returnGeometry = true
customdata added in the layer.
however, an error occurred when data was many layers
" Error: Error performing query operation(…)"
so the retrungeometry changed to false.
Then the data is not added to the layer.
How should I add?

var layer = new FeatureLayer(url, {
id : "SatisticsLayer",
outFields: ["*"],
mode: FeatureLayer.MODE_SNAPSHOT
});
var tempObject = new esri.layers.Field ({
alias : "STATISTICS",
name : "STATISTICS",
type : "esriFieldTypeInteger"
});

var randArr = [];
for(var i=0;i<17;i++){
randArr[i] = (Math.floor(Math.random() * 100 )+1);
}
mapObject.Layers.addLayerObject(layer);
mapObject.addEvent('layer-add',lang.hitch(this,function(evt){
console.log("layer.fields ======",layer.fields);
layer.fields.push(tempObject);
queryTask = new QueryTask(url);
var query = new Query();
query.where = "1=1";
query.outFields = ["*"];
query.returnGeometry = true;
console.log("query ====",query);
layer.queryFeatures(query, function (featureSet) {
// queryTask.execute(query, function(featureSet){
resultObject = featureSet.features;
for(var i = 0, length = resultObject.length; i < length; i++){
resultObject[i].attributes.STATISTICS = randArr[i];
console.log("resultObject[i].attributes.STATISTICS======",resultObject[i].attributes.STATISTICS);
// console.log("layer.graphics =====",layer.graphics[i]);

}
var symbol = new SimpleFillSymbol();
symbol.setColor(new Color([0, 216, 255, 0.5]));
var renderer = new ClassBreaksRenderer(null, "STATISTICS");
renderer.addBreak(0, 10, new SimpleFillSymbol().setColor(new Color([56, 168, 0, 0.5])));
renderer.addBreak(11, 30, new SimpleFillSymbol().setColor(new Color([139, 209, 0, 0.5])));
renderer.addBreak(31, 50, new SimpleFillSymbol().setColor(new Color([255, 255, 0, 0.5])));
renderer.addBreak(51, 90, new SimpleFillSymbol().setColor(new Color([255, 128, 0, 0.5])));
renderer.addBreak(91, Infinity, new SimpleFillSymbol().setColor(new Color([255, 0, 0, 0.5])));

layer.setRenderer(renderer);
layer.redraw();

});


}));

Outcomes