ESRI.ArcGIS.ADF.IMS
CreateSelectionLayer(Filter,Renderer,String) Method
See Also  Example
ESRI.ArcGIS.ADF.IMS.Carto.Layer Namespace > FeatureLayer Class > CreateSelectionLayer Method : CreateSelectionLayer(Filter,Renderer,String) Method




filter
Filter of the selection layer to be created.
selectionRenderer
Renderer of the selection layer to be created.
newLayerID
ID of the selection layer to be created.
Creates a selection layer based on the current FeatureLayer and a given Filter.

Syntax

Visual Basic (Declaration) 
Public Overloads Function CreateSelectionLayer( _
   ByVal filter As Filter, _
   ByVal selectionRenderer As Renderer, _
   ByVal newLayerID As String _
) As FeatureLayer
Visual Basic (Usage)Copy Code
Dim instance As FeatureLayer
Dim filter As Filter
Dim selectionRenderer As Renderer
Dim newLayerID As String
Dim value As FeatureLayer
 
value = instance.CreateSelectionLayer(filter, selectionRenderer, newLayerID)
C# 
public FeatureLayer CreateSelectionLayer( 
   Filter filter,
   Renderer selectionRenderer,
   string newLayerID
)

Parameters

filter
Filter of the selection layer to be created.
selectionRenderer
Renderer of the selection layer to be created.
newLayerID
ID of the selection layer to be created.

Return Value

Created selection layer.

Example

The following example selects and highlights the cities within 500 kilometers of a specified envelope. It creates a filter with the envelope and a buffer tolerance of 500 kilometers. It creates a renderer for the selected cities. Finally, it creates the selection layer with the filter and renderer and adds it to the map. This examples assumes as existing MapView object.
C#Copy Code
// Get a reference to the layer 

FeatureLayer originalLayer = 

    (FeatureLayer)mapView.Layers.FindByName("Cities"); 

  

// Create filter for the selection 

Filter selFilter = new Filter(); 

selFilter.Geometry = new Envelope(25, 35, 28, 38); 

selFilter.Tolerance = 500.0; 

selFilter.ToleranceUnits = BufferUnits.Kilometers; 

  

// Create a renderer for the selected features 

SimpleMarkerSymbol selSymbol = new SimpleMarkerSymbol(System.Drawing.Color.Red, 16); 

SimpleRenderer selRenderer = new SimpleRenderer(selSymbol); 

  

// Create the selection layer and add it to the map 

FeatureLayer selectionLayer =  

    originalLayer.CreateSelectionLayer(selFilter, selRenderer, "SelectedCities"); 

mapView.Layers.Add(selectionLayer); 

Image1.ImageUrl = mapView.Draw().Url; 

    
Visual BasicCopy Code
' Get a reference To the layer

Dim originalLayer As FeatureLayer = _

    CType(mapView.Layers.FindByName("Cities"), FeatureLayer)



' Create filter For the selection

Dim selFilter As New Filter()

selFilter.Geometry = New Envelope(25, 35, 28, 38)

selFilter.Tolerance = 500.0

selFilter.ToleranceUnits = BufferUnits.Kilometers



' Create a renderer For the selected features

Dim selSymbol As New SimpleMarkerSymbol(System.Drawing.Color.Red, 16)

Dim selRenderer As New SimpleRenderer(selSymbol)



' Create the selection layer And add it To the map

Dim selectionLayer As FeatureLayer = _

    originalLayer.CreateSelectionLayer(selFilter, selRenderer, "SelectedCities")

mapView.Layers.Add(selectionLayer)

Image1.ImageUrl = mapView.Draw().Url

Remarks

This method creates a layer that highlights features from an existing layer. It selects features using a Filter object. Features can be filtered by attributes and geometry. If geometry is used, it can be buffered to select features within some distance of the geometry. A renderer must be assigned to the layer for map display. The renderer's symbol must be appropriate to the source layer. For example, if a point layer is used for the selection, then a symbol derived from MarkerSymbol must be used for rendering.

This method is not recommended for ArcMap image services. Renderers cannot be used in selection layers for ArcMap image services. If a renderer is used, an error will be thrown. A workaround with this method is to set the renderer to null after using this method. As an alternative, use the FeatureLayer(FeatureLayer) to construct a copy of the layer, then set the Filter and ID of the new layer before adding it to the map's layer collection.

The selection layer ID must be unique among all layers in the collection. The ID can be any combination of alpha and numeric characters.

See Also

© 2010 All Rights Reserved.