3

I've been asked to develop a strategy to work with Layers that have not yet been added to a Map.

From what I can tell, one cannot simply create a new layer as one can with ArcObjects. One must use a method on the LayerFactory, all of which add a layer to the map upon creation.

So instead of using Layers, I thought I would have my analysis engine deal with layer definitions, e.g. CIMFeatureLayer, which can exist outside of a map.

For example, my analysis engine would generate CIMFeatureLayers and then, once I'm ready to present the layer, I would use something similar to LayerFactory.CreateFeaturelayer to create a layer from the CIMFeatureLayer.

I've searched but cannot find any method that does this.

Clearly Pro does this behind the scenes - if I save a .lyrx file and look at it in a text editor, I see that it is a json serialization of a CIMLayerDocument with CIMFeatureLayers within it. How can I do what Pro does when it reads the .lyrx file?

Update

I also tried this code, but SetDefinition doesn't seem to do anything.

private void Test()
{
 var def = MapView.Active.Map.Layers[0].GetDefinition() as CIMFeatureLayer;
 var fLayer = LayerFactory.CreateLayer(def.FeatureTable.DataConnection,MapView.Active.Map) as FeatureLayer;
 fLayer.SetName("my layer");
 // name remains "my layer" Setdefinition has no discernable effect
 fLayer.SetDefinition(def);
}
asked Feb 21, 2017 at 23:48

1 Answer 1

2

You can use this:

 private void Test() 
 {
 var layer=await QueuedTask.Run(()=>MapView.Active.Map.Layers[0].GetDefinition() as CIMFeatureLayer);
 var fLayer = await QueuedTask.Run(()=>LayerFactory.CreateLayer(polyLayer.FeatureTable.DataConnection, MapView.Active.Map)) as FeatureLayer;
 await QueuedTask.Run(()=> fLayer.SetName("My Name"));
 await QueuedTask.Run(()=> fLayer.SetDefinition(polyLayer));
 }
Kadir Şahbaz
78.6k57 gold badges260 silver badges407 bronze badges
answered Jun 21, 2017 at 5:24

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.