lang.clone === error? when copying esri graphic

4682
4
01-15-2015 12:05 PM
JerryGarcia
Occasional Contributor II

I get the following error when trying to clone a grahic:

Uncaught TypeError: Cannot read property 'path' of null

If I cannot use Dojo lang.clone to copy a graphic, then can someone provide some sample code to do this?

I need to make a copy of a graphic, change it's name attribute, and add it to a FeatureLayer.

Thanks!

Tags (2)
0 Kudos
4 Replies
KenBuja
MVP Esteemed Contributor

What is your code for cloning the graphic? This example seems to work properly, which slightly modifies the "Add graphics to a map" sample.

var graphic = new Graphic(evt.geometry, symbol);
var clone = lang.clone(graphic);
map.graphics.add(clone);
0 Kudos
JerryGarcia
Occasional Contributor II

I get the error with this code:

var g = this.polylineGraphics.graphics[0];

var clone = lang.clone(g);

...

where as polylineGraphics:

        this.polylineGraphics = new FeatureLayer({
            layerDefinition: {
                geometryType: 'esriGeometrypolyline',
                fields: [{
                    name: 'OBJECTID',
                    type: 'esriFieldTypeOID',
                    alias: 'OBJECTID',
                    domain: null,
                    editable: false,
                    nullable: false
                }, {
                    name: 'name',
                    type: 'esriFieldTypeString',
                    alias: 'name',
                    domain: null,
                    editable: true,
                    nullable: false
                }]
            },
            featureSet: null
        }, {
            id: 'polylineGraphics',
            title: 'polylineGraphics',
            mode: FeatureLayer.MODE_SNAPSHOT
        });

0 Kudos
JohnGrayson
Esri Regular Contributor

I wonder if this will work:

var clonedGraphic = new Graphic(sourceGraphic.toJson()):

SrihariManepalli
New Contributor II

This worked for me. Thanks.

0 Kudos