AnsweredAssumed Answered

Problem calling function from a list of selected features

Question asked by rcsellman on Feb 17, 2015
Latest reply on Feb 18, 2015 by tsellste

Hello,

 

In my app, I have a query set up that selects parcels from a feature layer.  After the query is executed, I loop through the selected features that are returned and populate a list showing basic attribute information of the selected features (2 fields for now).  In the created list, I am trying to make a button for each feature that would fire a function (searchParcelDetail) that takes the selected feature's OBJECTID and passes it into another query.  From here I can zoom to the parcel and show more attributes.  I am creating the button in line 51, for each selected parcel in the first query:

 

var parcel3Url = "http://summitmaps.summitoh.net/arcgis/rest/services/Fiscal_Mercator/MapServer/6";
  featureLayerParcelFor = new esri.layers.FeatureLayer(parcel3Url, {
  mode: esri.layers.FeatureLayer.MODE_SELECTION,
  visible: true,
  id: "Selected Parcels",
  outFields: ["PARID", "ALT_ID", "ADDR", "OWN1"]
  });
  var symbol2 = new esri.symbol.SimpleFillSymbol(esri.symbol.SimpleFillSymbol.STYLE_NULL, new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleFillSymbol.STYLE_SOLID, new dojo.Color([100, 100, 100]), 2), new dojo.Color([0, 0, 255, 0.20]));
  featureLayerParcelFor.setSelectionSymbol(symbol2);
  map.addLayer(featureLayerParcelFor);

  
  featureLayerParcelDetail = new esri.layers.FeatureLayer(parcel3Url, {
  mode: esri.layers.FeatureLayer.MODE_SELECTION,
  visible: true,
  id: "Selected Parcels - Detailed",
  outFields: ["PARID", "ALT_ID", "ADDR", "OWN1", "OWNADDR1", "OWNZIP1", "CITYNAME", "STATECODE", "OWN2", "OWNADDR2", "OWNZIP2", "NBHD", "CLASS", "LUC", "ACRES", "DESC_"]
  });
  var symbol2 = new esri.symbol.SimpleFillSymbol(esri.symbol.SimpleFillSymbol.STYLE_NULL, new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleFillSymbol.STYLE_SOLID, new dojo.Color([100, 100, 100]), 2), new dojo.Color([0, 0, 255, 0.20]));
  featureLayerParcelDetail.setSelectionSymbol(symbol2);
  map.addLayer(featureLayerParcelDetail);
   
   
  function queryParcels2() {
   
  var queryParcels = new esri.tasks.Query();
  queryParcels.where = "PARID LIKE '" + "%" + dom.byId("parcelText2").value + "'";


  featureLayerParcelFor.selectFeatures(queryParcels, esri.layers.FeatureLayer.SELECTION_NEW, function(features, selectionMethod) {
   
  map.setExtent(graphicsUtils.graphicsExtent(featureLayerParcelFor.getSelectedFeatures()), true);

  });
  }
   
   

  featureLayerParcelFor.on("selection-complete", function(fset) {
  console.log("Selection Complete");
  var resultFeatures = fset.features;
  var details, number;


  details = "Number of parcels found: " + resultFeatures.length + "<br /><hr><table>";
  for (var i = 0, il = resultFeatures.length; i < il; i++) {
  number = i + 1;

  details = details + "<tr><td><b>    PARID:</b> " + resultFeatures[i].attributes.PARID + "</td></tr>";
  details = details + "<tr><td><b>    ALT_ID:</b> " + resultFeatures[i].attributes.ALT_ID + "</td></tr>";
  details = details + "<tr><td><button onClick=searchParcelDetail('" + resultFeatures[i].attributes.OBJECTID + "')>More Details</button></td></tr>";
  details = details + "<tr><td></td></tr>";
  details = details + "<tr><td><hr /></td></tr>";



  }
  details = details + "</table>";

  document.getElementById("parcelSearchResults").innerHTML = details;


  });
function searchParcelDetail(objectid){

  var queryParcels = new esri.tasks.Query();
  queryParcels.where = "OBJECTID = '" + objectid + "'";


  featureLayerParcelDetail.selectFeatures(queryParcels, esri.layers.FeatureLayer.SELECTION_NEW, function(features, selectionMethod) {
   
  map.setExtent(graphicsUtils.graphicsExtent(featureLayerParcelDetail.getSelectedFeatures()), true);

  });
   
  dijit.byId("leftPane2").selectChild(dijit.byId("propertyDetails3"));

  }

Everything works until I try to click the button to fire the searchParcelDetail function. I get the error:

 

"Uncaught ReferenceError: searchParcelDetail is not defined"

 

Can anyone see what I am doing wrong?  To be honest I'm not sure if this is  the best way to accomplish this.  Any ideas?

 

Any help is appreciated!

Thanks,

 

Ryan

Outcomes