The default controller for a LuciadRIA map allows users to touch an object shape or an object label on the map to select the object. They can only select objects in layers that are marked as selectable.

The selection is managed on the Map, and the Map has API methods to query and alter the selection.

Selecting features

You can select one or more Feature objects of a FeatureLayer using the selectObjects method:

map.selectObjects([
  {
    layer: layerOfFeature,
    objects: [featureToSelect]
  }
]);

De-selecting features

You can de-select one or more Feature objects of a FeatureLayer using the selectObjects method:

map.selectObjects([
      {
        layer: layerOfFeature,
        objects: [featureToSelect]
      }
    ], {
      editSelection: SelectionType.REMOVE
    }
);

By changing the SelectionType, you can also toggle the selection for an object, or replace the existing selection.

Clearing the selection

You can de-select all objects in all layers with one API call:

map.clearSelection()

Querying the selection state

You can query the map for the selection state of a certain Feature:

const selectedState = map.isSelected(layerOfFeature, feature);

Looping over the selected objects

You can query the map for all selected objects, and loop over the selection. The selection is grouped per layer.

const selection = map.selectedObjects;
for (const layerSelection of selection) {
  //The layer of which objects are selected on the map
  const layer = layerSelection.layer;
  const selectedObjects = layerSelection.selected;
  for (const selectedObject of selectedObjects) {
    console.log(`Object ${selectedObject} is selected in ${layer}`);
  }
}

Listening for changes in selection

The Map fires events each time the selection changes. You can subscribe to those events. The event describes the features that were selected or de-selected, and the layer that contains them.

map.on("SelectionChanged", selectionChangeEvents => {
  const selectionChanges = selectionChangeEvents.selectionChanges;
  for (const selectionChange of selectionChanges) {
    const layer = selectionChange.layer;
    for (const selectedObject of selectionChange.selected) {
      console.log(`Object ${selectedObject} is selected in ${layer}`);
    }

    for (const deselectedObject of selectionChange.deselected) {
      console.log(`Object ${deselectedObject} is deselected in ${layer}`);
    }
  }
});