Select to view content in your preferred language

Can we clone a featurelayer

870
2
06-07-2011 08:52 AM
MuralidharMoka
Emerging Contributor
Hi,

I have a featurelayer(f) which contains features which we deal with. This is defined on the XAML.
I have created a draw tool for adding new polygons  to this featurelayer(f) using templatePicker.

We have a requirement where, we want to add these newly drawn polygons first to a temporary featurelayer same as the featurelayer f.

so wanted to know whether we can clone the featurelayer f in the code and create a temporary featurelayer.

Thanks
Muralidhar Moka
0 Kudos
2 Replies
JenniferNery
Esri Regular Contributor
You can subscribe to Layer.Graphics.CollectionChanged once layer has been initialized so you may add/remove graphics of the same geometry, symbol and attributes to the other GraphicsLayer.

Graphics cannot be shared by layers, but you can clone geometry using Geometry.Clone(Geometry toClone). Here's a short code snippet, where target is another GraphicsLayer.
void Graphics_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
  {
   if (e.NewItems != null)
   {
    foreach (var item in e.NewItems)
    {
     Graphic g = item as Graphic;
     Graphic clone = new Graphic()
     {
      Geometry = Geometry.Clone(g.Geometry),
      Symbol = g.Symbol
     };
     foreach (var attribute in g.Attributes)
      clone.Attributes[attribute.Key] = attribute.Value;
     target.Graphics.Add(clone);
    }
   }
  }
0 Kudos
dotMorten_esri
Esri Notable Contributor
FeatureLayer needs a service to work against, so the only thing you can really clone is Url, but that means your features etc are also pulled from the service there, and that's probably not what you want.

Instead create an empty GraphicsLayer and use that to edit instead (you could copy the Renderer over to get some similar rendering). However, then TemplatePicker might now work that well, and you might have to go a little bit more low-level and the Draw class instead. The TemplatePicker is really designed to work with a FeatureLayer(s) backed by a FeatureService.
0 Kudos