AnsweredAssumed Answered

featurelayers.graphics

Question asked by sucinimad on Mar 9, 2016
Latest reply on Mar 9, 2016 by sucinimad


Hi guys,

 

I'm working on a map that uses FeatureLayer.Mode_ONDEMAND. To see certain layer, I pass in a project ID using featureLayer.setDefinitionExpression. Where such layer exists, I see it. What I want to know is how to detect when no layer exists. I want to print an alert to the viewer instead of showing just a blank map. Here's my code:

 

function init() {

  map = new esri.Map("mapDiv", {

   basemap: "topo",

   center: [-116.73536, 33.033989],

   zoom: 9

  });

 

  var featureLayer = new esri.layers.FeatureLayer("http://services.arcgis.com/v01gqwM5QqNysAAi/arcgis/rest/services/Project_boundaries_021616/FeatureServer/0",{

   mode: esri.layers.FeatureLayer.MODE_ONDEMAND,

   outFields: ["*"],

   opacity: 1

  });

 

 

  featureLayer.setDefinitionExpression("SrvyDescID=\'' . htmlspecialchars($ProjectID) . '\'");

  console.log(featureLayer.graphics);

  console.log(featureLayer.graphics[0]);

  map.addLayer(featureLayer);

   }

 

What I learned is when the project is valid, feature.graphics will return an array. But I'm unable to treat it like an array. For example, featureLayer.graphic[0] returns "undefined". featureLayer.graphic.length also doesn't work. And yet, my console.log does return an object. How do I detect this object?

 

Attached is a screenshot of the console log. Thanks for your help.

Attachments

Outcomes