rollinsio

Problems Adding Graphics to a Feature Layer using applyEdits

Discussion created by rollinsio on Sep 21, 2010
Latest reply on Sep 22, 2010 by rollinsio
I'm attempting to add a Graphic to a FeatureLayer.  Whenever I do, the graphic gets added, but then a Type Error pops up.  Neither the success callback nor the error callback are being triggered.  The error is propagating up to a higher calling function which checks for intersections.

If I add the Graphic through the .add function (instead of applyEdits) it will add fine, but then it won't assign an object ID.

The error reads: "Type Error: Cannot read property "name" of null".  There is no name property for the graphic.

The function that checks for intersection (where the error is bubbling up to):

[PHP]
intersectByGeometryService: function(result){
//      Ext.Msg.alert('Added a graphic to the layer');
       
        var resultGeometry = result.geometry;
        var resultOID = result.attributes.valueOf('Object ID');
        var layer = result.getLayer();
       
        // Loop through the graphics of the layer, snagging the geometries of any that are there into an array.
        var geometries = new Array();
        for(var i = 0; i < layer.graphics.length; i++){
            if(resultOID != layer.graphics[i].attributes.valueOf('Object ID')){
                geometries.push(layer.graphics[i].geometry);
            }
        }
//        var geometries = dojo.map(layer.graphics, function(feature){
//            if(resultOID != feature.attributes.valueOf('Object ID')){
//                return feature.geometry;
//            }
//        });
       
        this.geometryService.intersect(geometries, resultGeometry, this.highlightIntersections,
        function(err){
            Ext.Msg.alert('Error occurred when checking for intersection: ' + err);  // error propagates to here
        });
    }
[/PHP]

The function where I add the Graphics:

[PHP]
highlightIntersections: function(geometries){
        // When this function is called from intersection calculations, this refers to Window.
        var emp = Ext.getCmp('editormappanel');
        for(var i = 0; i < geometries.length; i++){
//            var symbol = new esri.symbol.SimpleFillSymbol({
//                type : "esriSFS",
//                style : "esriSFSSolid",
//                color : [255, 0, 0, 255],
//                outline : {
//                    type : "esriSLS",
//                    style : "esriSLSSolid",
//                    color : [255, 194, 0, 255],
//                    width : 2
//                }
//            });
            var attributes = {name: 'composite value', type: 0, description: 'Intersection'};
            var graphic = new esri.Graphic(geometries[i], null, attributes);
            emp.compositelayer.applyEdits([graphic], null, null, function(adds, updates, deletes){
                Ext.Msg.alert('Composite layer update successful');
            }, function(err){
                Ext.Msg.alert('Composite layer update failed: ' + err);
            });
            //this.map.graphics.add(new esri.Graphic(geometries[i], symbol));
        }
       
       
    }
[/PHP]

Outcomes