Feature Layer Selection Symbol

587
4
05-12-2023 12:15 PM
GregKnight-Eptura
New Contributor

Hi all,

In the 3.x JS API, FeatureLayer had a setSelectionSymbol method to control the appearance of the selected feature. In the v4.x JS API, FeatureLayer does not have this method.

How does one set the selection symbol in the 4.x API?

Many thanks,

Greg

0 Kudos
4 Replies
UndralBatsukh
Esri Regular Contributor

Hi there, 

4.x does not have concept of selection symbol. You can change the highlightOptions for the layer view. Please take a look this sample as this shows how to change the layer view's highlightOptions: https://developers.arcgis.com/javascript/latest/sample-code/highlightoptions-layerviews/

0 Kudos
imritanshu
New Contributor III

How can we use a Picture Marker symbol as a highlightoption. Is there a way to achieve it? Or we should do it by some random way? 

0 Kudos
RachelGomez
New Contributor II

In the ArcGIS API for JavaScript 4.x, you can set the selection symbol for a FeatureLayer using the selectionSymbol property. Here's how you can set the selection symbol in the 4.x API:

Create a symbol object that represents the appearance of the selected features. This can be any valid symbol type supported by the API, such as SimpleMarkerSymbol, SimpleLineSymbol, or SimpleFillSymbol.

Assign the symbol object to the selectionSymbol property of the FeatureLayer.

Here's an example code snippet that demonstrates setting the selection symbol for a FeatureLayer in the 4.x API:

javascript
Copy code
// Create the selection symbol
const selectionSymbol = {
type: "simple-fill", // Replace with the desired symbol type
color: [255, 0, 0, 0.5], // Replace with the desired symbol color
outline: {
color: [255, 0, 0], // Replace with the desired outline color
width: 2 // Replace with the desired outline width
}
};

// Create the FeatureLayer with your data source
const featureLayer = new FeatureLayer({
// other layer properties...
// ...

// Set the selection symbol
selectionSymbol: selectionSymbol
});
In this example, selectionSymbol is created as a simple fill symbol with a red color and a red outline. You can modify the symbol properties according to your requirements.

By setting the selectionSymbol property of the FeatureLayer, the specified symbol will be used to highlight the selected features when they are interacted with, such as through selection events or user interaction.

Note: Ensure that you have loaded the appropriate modules for the symbol type you are using. For example, if you are using a SimpleMarkerSymbol, make sure you have imported the esri/symbols/SimpleMarkerSymbol module in your code.

Regards,

Rachel Gomez

0 Kudos
GregKnight_Eptura
New Contributor

selectionSymbol does not appear to be a property of FeatureLayer.  Am I missing something here?

FeatureLayer | API Reference | ArcGIS Maps SDK for JavaScript 4.26 | ArcGIS Developers

0 Kudos