Select to view content in your preferred language

Add a point by lat, lon using featurelayer.applyEdits

4340
3
08-24-2010 06:55 AM
BradleyStrittmatter
New Contributor
What i'm trying to do is have a user enter in a lat/lon to create a point and save it to the featureclass.  It throws an error everytime, however it still saves the point but won't execute the onEditComplete event???  The error is "TypeError: cannot read property '876' of undefined".  I have no clue what the error means?

Below is the code which creates the point then inputs it into the applyEdits method for my featurelayer named surveyPointLayer.

I do have the proxy setup and working and the data lives in a SqlExpress ArcSDE geodatabase.  The projection i'm getting the point in is the same as the projection of the maplayer it's being saved to.

Any help is much appreciated!  Thanks!!!!

        var x = dojo.byId("txtX").value;
        var y = dojo.byId("txtY").value;
    
        var point = new esri.geometry.Point(x,y, new esri.SpatialReference({ wkid: 4326 }));

        var graphic = new esri.Graphic(point,null,null);
        
        surveyPointLayer.applyEdits([graphic],null,null, function(addResults) {
          surveyPointLayer.refresh();
        },function(err){
          alert(err);
        });
0 Kudos
3 Replies
KellyHutchins
Esri Frequent Contributor
Perhaps there are some required attributes? If there are try setting them to see if it resolves the error. Here's an example that shows how to set attributes for the graphic.

          var attributes = {};
          attributes.SPEED = location.coords.speed;
          attributes.ACCURACY = location.coords.accuracy;
          attributes.DATETIME = now.getTime();

          var pt = esri.geometry.geographicToWebMercator(new esri.geometry.Point(location.coords.longitude, location.coords.latitude));
          var graphic = new esri.Graphic(new esri.geometry.Point(pt, map.spatialReference), null, attributes);

          featureLayer.applyEdits([graphic], null, null, function(adds) {
0 Kudos
BradleyStrittmatter
New Contributor
Thanks for the tips on the attributes.  However i don't have any attributes in this feature class at the present time.

Here is the present version of the code:
function SubmitControlPoint(){

        var x = dojo.byId("txtX").value;
        var y = dojo.byId("txtY").value;
    
        var point = new esri.geometry.Point(x,y, new esri.SpatialReference({ wkid: 4326 }));
        
        var attributes = {};
        
        var pt = esri.geometry.geographicToWebMercator(point);
        var graphic = new esri.Graphic(pt, null, attributes);
        
        surveyPointLayer.applyEdits([graphic],null,null,function(addResults) {
          surveyPointLayer.refresh();
        },function(err){
          alert(err);
        });
}


It doesn't make any sense.  Below you'll see the Post, Response, and Error i receive in Firefox and Firebug.  Everything looks fine, i get a 200 response which looks fine and it saves the feature. But refuses to trigger the onEditsComplete function and instead throws the error function.  I'm at a loss... Anyone have any ideas why?

Post:
[{"geometry":{"x":8571600.79108192,"y":4579425.812870007,"spatialReference":{"wkid":102100}},"attributes":{}}]

Response:
{"addResults":[{"objectId":1,"globalId":"{07EC7EE2-D36D-4D84-9C69-A30EEA9EEB2A}","success":true}],"updateResults":[],"deleteResults":[]}

Error returned from error alert:
TypeError: _158[cell.row] is undefined
0 Kudos
KellyHutchins
Esri Frequent Contributor
In your revised snippet you don't need to convert the point to web mercator if your featurelayer is in geographic. I ran a quick test using the code below and was able to add a point with no errors. Here's the code:

      function addData(){
      var x = dojo.byId('xval').value;
      var y = dojo.byId('yval').value;
        var point = new esri.geometry.Point(x,y,new esri.SpatialReference({wkid:4326}));
        var graphic = new esri.Graphic(point,null,null);
        featureLayer.applyEdits([graphic],null,null, function(addResults,updateResults,deleteResults) {
            console.log("ObjectId = " + addResults[0].objectId);
          },function(error){
            console.log("error occurred");
        });
      }

0 Kudos