AnsweredAssumed Answered

what is the best practice for using ClassBreaksRender in buffer searching?

Question asked by stephenlam1988 on Dec 12, 2014
Latest reply on Jan 15, 2015 by stephenlam1988

Referring to this topic, I can search the result within a drawn polygon, however it requires me to set a template for returned result:

var symbol = new SimpleMarkerSymbol(

  SimpleMarkerSymbol.STYLE_CIRCLE,

  12,

  new SimpleLineSymbol(

  SimpleLineSymbol.STYLE_NULL,

  new Color([247, 34, 101, 0.9]),

  1

  ),

  new Color([207, 34, 171, 0.5])

);

featureLayer.setSelectionSymbol(symbol);

 

It works fine, but I want to make every returned records have its own color which is determined by its attributes value, i.e. blue color represents cars, yellow represents building, etc...

 

featureLayer.queryFeatures(query, function (featureSet) {

  var inBuffer = [];

  var renderer = new ClassBreaksRenderer(null, "category_id");

  renderer.setMaxInclusive(true);

  var categoryColorList = [];

  var inBuffer = [];

  for (var i = 0; i < featureSet.features.length; i++) {

  if (featureSet.features[i].geometry == null)

  continue;

  inBuffer.push(featureSet.features[i].attributes[featureLayer.objectIdField]);

  var rcolor = new Color([Math.floor((Math.random() * 255) + 1), Math.floor((Math.random() * 255) + 1), Math.floor((Math.random() * 255) + 1)]);

  if (typeof eval("categoryColorList._" + featureSet.features[i].attributes.category_id)

  == "undefined") {

  eval("categoryColorList._" + featureSet.features[i].attributes.category_id + " = rcolor");

  }

 

 

  var symbol = new SimpleMarkerSymbol({

  "color": eval("categoryColorList._" + featureSet.features[i].attributes.category_id),

  "size": 5,

  "angle": 0,

  "xoffset": 0,

  "yoffset": 0,

  "type": "esriSMS",

  "style": "esriSMSSquare",

  "outline": { "color": eval("categoryColorList._" + featureSet.features[i].attributes.category_id), "width": 1, "type": "esriSLS", "style": "esriSLSSolid" }

  });

 

  renderer.addBreak({

  field: "category_id",

  minValue: featureSet.features[i].attributes.category_id,

  maxValue: featureSet.features[i].attributes.category_id,

  symbol: symbol

  });

  }

 

  query = new Query();

  query.objectIds = inBuffer;

  (function (featureLayer) {

  featureLayer.selectFeatures(query, esri.layers.FeatureLayer.SELECTION_NEW, function (results) {

  featureLayer.refresh();

  });

  })(featureLayer);

});

 

Although within the polygon, the results are returned, the related records outside the polygon are also being shown. I was wondering if someone could let me know if there are something else that I should care about. I am not going to use graphic layer to store the returned result because I want to keep things simple, with only 1 feature layer, thanks you.

related_color_also_selected.png

Outcomes