AnsweredAssumed Answered

Add graphic to query result

Question asked by ian.shiland on Jan 2, 2015
Latest reply on Jan 2, 2015 by jskinner-esristaff

I have some code that zooms to a query result extent, but I also want to highlight the query result. Console shows I'm returning an object but i cant seem to add the "highlightSymbol" to it. Any help is much appreciated:

 

  //Highlight Symbol
  var highlightSymbol = new SimpleFillSymbol(
  SimpleFillSymbol.STYLE_SOLID,
  new SimpleLineSymbol(
  SimpleLineSymbol.STYLE_SOLID,
  new Color([255, 0, 0]), 3),
  new Color([125, 125, 125, 0.2]));

  //Query BLOCK/LOT
  var queryTask = new QueryTask(parcels.url);

  var query = new Query();
  query.returnGeometry = true;
  query.outFields = ["*"];
  on(dom.byId("execute"), "click", execute);

  function execute() {
  map.graphics.clear();

  query.where = "SSN = '" + dijit.byId("muniSelect").value + "' AND BLOCK = '" + dom.byId("block").value + "' AND LOT = '" + dom.byId("lot").value + "'";
  queryTask.execute(query, showResults);
  }
  function showResults(results) {
  var resultItems = [];
  var resultCount = results.features.length;
  for (var i = 0; i < resultCount; i++) {
  var featureAttributes = results.features[i].attributes;
  for (var attr in featureAttributes) {
  resultItems.push("<b>" + attr + ":</b>  " + featureAttributes[attr] + "<br>");
  }
  resultItems.push("<br>");
  }
  if (resultCount === 0) {
  dom.byId("info").innerHTML = "<h3 style = 'color:#E60000'> No Record Found </h1>";
  } else {
  dom.byId("info").innerHTML = resultItems.join("");

  //Zoom to Result & Set Query Result Symbol
  var resultGraphic = new Graphic(results.features, highlightSymbol);
  var resultExtent = graphicsUtils.graphicsExtent(results.features);
  map.graphics.add(resultGraphic);
  map.setExtent(resultExtent.expand(2));

  console.log("resultGraphic:", (results.features));
  }
  }

Outcomes