Feature layer only renders 1st feature...

510
1
09-17-2012 02:57 PM
SavanThongvanh
New Contributor
I'm new to esri so thanks in advance for reading.  I have a json string that I'm trying to turn into points on a feature layer.  esri doesn't complain about the json but it only puts one of the points on the map.

Am I missing something obvious here?  Thanks in advance:
data= {"geometryType": "esriGeometryPoint",
"spatialReference": {
  "wkid": 102100,
  "latestWkid": 102100
},

   "features":[
      {
         "attributes":{
            "Moisture":"2.66",
            "Width":"914",
            "Yield":"144.725399633191"
         },
         "geometry":{
            "spatialReference":{
               "wkid":102100
            },
            "x":-1.0402576116868861E7,
            "y":5138355.49346632
         }
      },
      {
         "attributes":{
            "Moisture":"25.64",
            "Width":"914",
            "Yield":"12.5850541487206"
         },
         "geometry":{
            "spatialReference":{
               "wkid":102100
            },
            "x":-1.0402517685268145E7,
            "y":5138268.160804208
         }
      }
   ]
};

     
         var featureCollection = {
        layerDefinition: null,
        featureSet: data
      };
      console.log(featureCollection.featureSet);
          featureCollection.layerDefinition = {
                  "geometryType": "esriGeometryPoint",
                  "objectIdField": "ObjectID",
                  "fields": [{
                    "name": "ObjectID",
                    "alias": "ObjectID",
                    "type": "esriFieldTypeOID"
                  },
         /*{ "name": "description",
                    "alias": "Description",
                    "type": "esriFieldTypeString"
                  },
         {"name": "title",
                    "alias": "Title",
                    "type": "esriFieldTypeString"
                  },*/
         {"name": "Yield",
                    "alias": "Yield",
                    "type": "esriFieldTypeString"
                  }]
                };

      var featureLayer = new esri.layers.FeatureLayer(featureCollection,{"mode":esri.layers.FeatureLayer.MODE_SNAPSHOT});
      featureLayer.setRenderer(yieldRenderer);
      featureLayer.id="yieldLayer";
      map.addLayer(featureLayer);
0 Kudos
1 Reply
derekswingley1
Frequent Contributor
This happens when your features don't have object IDs. Make sure each feature has a unique ID with a field name that matches what's specified in the layerDefinition. In your case, this would be ObjectID.
0 Kudos