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

4217
2
Jump to solution
12-12-2014 02:11 AM
StephenLam
New Contributor III

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.geometry == null)

  continue;

  inBuffer.push(featureSet.features.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.attributes.category_id)

  == "undefined") {

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

  }

  var symbol = new SimpleMarkerSymbol({

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

  "size": 5,

  "angle": 0,

  "xoffset": 0,

  "yoffset": 0,

  "type": "esriSMS",

  "style": "esriSMSSquare",

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

  });

  renderer.addBreak({

  field: "category_id",

  minValue: featureSet.features.attributes.category_id,

  maxValue: featureSet.features.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

0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus

Stephen,

   That sample uses a Featurelayer that is already drawing ALL the layers feature and then just selecting the features that intersect the buffer and applies a symbol to the selected features. The way That I suggest that you go is to change the FeatureLayer to MODE_SELECTION that way none of the feature show until your buffer is done and then all your other code will be fine.

View solution in original post

2 Replies
RobertScheitlin__GISP
MVP Emeritus

Stephen,

   That sample uses a Featurelayer that is already drawing ALL the layers feature and then just selecting the features that intersect the buffer and applies a symbol to the selected features. The way That I suggest that you go is to change the FeatureLayer to MODE_SELECTION that way none of the feature show until your buffer is done and then all your other code will be fine.

StephenLam
New Contributor III

Thank you.

0 Kudos