Select to view content in your preferred language

How to create Layer from selected features

932
3
10-22-2018 08:03 AM
BradJones3
Regular Contributor

Is there a simpler way to create a layer from selected features? 

From the research I have done I would:

Get the selected feature-->create a list/array of OBJECTIDs-->Copy the layer containing the selected features --> apply a definition query based on the list of OBJECTIDs-->

This is obviously an abbreviated description, but I do not see a simpler approach.

0 Kudos
3 Replies
UmaHarano
Esri Regular Contributor

Hi Brad,

You could also add a definition to a feature layer using BasicFeatureLayer.SetDefinitionQuery.

You can see a sample with this method: QueryBuilderControl

Thanks

Uma

BradJones3
Regular Contributor

Uma, I used CreateFeatureLayer then the SetDefinitionQuery method on the layer.  

var slectionLayer = LayerFactory.Instance.CreateFeatureLayer(uri, mapView, 0, "Selection Layer")

selectionLayer.SetDefinitionQuery(defQuery);‍‍‍

I noticed that the CreateFeatureLayer method has the optional parameter RendererDefinition. I couldn't find any documentation or examples on how to use this parameter to set a simple single symbol renderer. I found plenty for graduated and unique colour symbol examples. 

This isn't a big deal.  I just used the CIMSimpleRenderer class to create a renderer then SetRenderer after the layer has loaded. 

Just curious how this would work since I initially wanted the layer load with the renderer set. 

Thanks.

0 Kudos
UmaHarano
Esri Regular Contributor

Hi Brad,

Here are some snippets that make simple renderers:

SimpleRenderers

Thanks

Uma

0 Kudos