Working with feature

Tip: To use all the methods below, you must first select the desired layer through the result array of the map.getFeatureLayers().

Properties:

selectionSet

After selecting features, you can access the list of selected Ids using selectionSet.

Returns:

Set: Returns a set of ids

Example:

const allFeatureLayers = map.getFeatureLayers(); 
const intendedLayer = allFeatureLayers["<intended layer name>"]; 
const Ids = intendedLayer.selectionSet;

highlightSet

After highlighting features, you can access the list of highlighted Ids using highlightSet .

Returns:

Set: Returns a set of ids

Example:

const allFeatureLayers = map.getFeatureLayers(); 
const intendedLayer = allFeatureLayers["<intended layer name>"]; 
const Ids = intendedLayer.highlightSet;

Methods:

select(Ids)

Selects one or multiple features.

Parameters:

Ids(Number | Array): Array of features ids. If you want a single feature, insert id as a number.

Returns:

String: Returns a message that shows selecting features was successful or not. Null message means selecting was successful.

Example:

const allFeatureLayers = map.getFeatureLayers();
const intendedLayer = allFeatureLayers["<intended layer name>"];
intendedLayer.select([10,25]); 

addToSelection(Ids)

Adds one or multiple features from the layer to the selected features.

Parameters:

Ids(Number | Array): Array of features ids. If you want a single feature, insert id as a number.

Returns:

String: Returns a message that shows selecting features was successful or not. Null message means selecting was successful.

Example:

const allFeatureLayers = map.getFeatureLayers();
const intendedLayer = allFeatureLayers["<intended layer name>"];
intendedLayer.addToSelection([10,25]); 

removeFromSelecion(Ids)

Deselects one or multiple features.

Parameters:

Ids(Number | Array): Array of features ids. If you want a single feature, insert id as a number.

Returns:

String: Returns a message that shows deselecting features was successful or not. Null message means deselecting was successful.

Example:

const allFeatureLayers = map.getFeatureLayers();
const intendedLayer = allFeatureLayers["<intended layer name>"];
intendedLayer.removeFromSelection([10,25]); 

clearSelection()

Deselects all features.

Returns:

String: Returns a message that shows deselecting features was successful or not. Null message means deselecting was successful.

Example:

const allFeatureLayers = map.getFeatureLayers();
const intendedLayer = allFeatureLayers["<intended layer name>"];
intendedLayer.clearSelection(); 

highlight (Ids)

Highlights one or multiple features.

Parameters:

Ids(Number | Array): Array of features ids. If you want a single feature, insert id as a number.

Returns:

String: Returns a message that shows highlighting features was successful or not. Null message means highlighting was successful.

Example:

const allFeatureLayers = map.getFeatureLayers();
const intendedLayer = allFeatureLayers["<intended layer name>"];
intendedLayer.highlight([10,25]); 

addToHighlight(Ids)

Adds one or multiple features from the layer to the highlighted features.

Parameters:

Ids(Number | Array): Array of features ids. If you want a single feature, insert id as a number.

Returns:

String: Returns a message that shows highlighting features was successful or not. Null message means highlighting was successful.

Example:

const allFeatureLayers = map.getFeatureLayers();
const intendedLayer = allFeatureLayers["<intended layer name>"];
intendedLayer.addToHighlight([10,25]); 

removeFromHighlight(Ids)

Removes one or multiple features from the highlight mode.

Parameters:

Ids(Number | Array): Array of features ids. If you want a single feature, insert id as a number.

Returns:

String: Returns a message that shows removing features from highlight mode was successful or not. Null message means removing features from highlight mode was successful.

Example:

const allFeatureLayers = map.getFeatureLayers();
const intendedLayer = allFeatureLayers["<intended layer name>"];
intendedLayer.removeFromHighlight([10,25]); 

clearHighlight()

Removes all features from the highlight mode.

Returns:

String: Returns a message that shows removing all features from highlight mode was successful or not. Null message means removing all features from highlight mode was successful.

Example:

const allFeatureLayers = map.getFeatureLayers();
const intendedLayer = allFeatureLayers["<intended layer name>"];
intendedLayer.clearHighlight(); 

flashFeature(Id)

Sets a feature to blink.

Parameters:

Id (Number): A feature id.

Returns:

String: Returns a message that shows flashing feature was successful or not. Null message means flashing was successful.

Example:

const allFeatureLayers = map.getFeatureLayers();
const intendedLayer = allFeatureLayers["<intended layer name>"];
intendedLayer.flashFeature(10); 

See the Pen Contact Form – Pen a Day 20 by Geobox (@geobox-gl-demo) on CodePen.1

zoomToFeature(Id)

Zooms to the feature.

Parameters:

Id (Number): A feature id.

Returns:

String: Returns a message that shows zooming to feature was successful or not. Null message means zooming was successful.

Example:

const allFeatureLayers = map.getFeatureLayers();
const intendedLayer = allFeatureLayers["<intended layer name>"];
intendedLayer.zoomToFeature(10);

openPopup(Id, titleField, latLngLocation)

Opens the feature popup. If you want to open the popup in another location, enter its location as the third argument.

Parameters:

Id (Number): A feature id.

Id (String)?: Field name that you want to show field value as a title.

latLngLocation(Array)?: An array contains latitude and longitude. e.g. [32, 51]. If you want to open popup in another location, use this parameter.

Returns:

String: Returns a message that shows opening popup was successful or not. Null message means opening popup was successful.

Example:

const allFeatureLayers = map.getFeatureLayers();
const intendedLayer = allFeatureLayers["<intended layer name>"];
intendedLayer.openPopup(10,'name',[37,53]);

removePopup()

Closes the existing popup. (Note that only one popup can be opened in the map, and the popup will be closed when a new popup is opened)

Returns:

String: Returns a message that shows flashing feature was successful or not. Null message means flashing was successful.

Example:

const allFeatureLayers = map.getFeatureLayers();
const intendedLayer = allFeatureLayers["<intended layer name>"];
intendedLayer.removePopup();

Leave a comment

Your email address will not be published. Required fields are marked *