Last updated

API / geotoolkit / selection / Selector / Selector

Class: Selector

selection.Selector.Selector

Defines node selection. This class provides the logic to do shape selection using device coordinates.
It implements several algorithms to perform different types of selection:

  • By point: At a given point with an optional radius
  • By rect: In a given rectangle
  • By polygon: In a given arbitrary polygon
  • By ellipse: In a given arbitrary ellipse
The picking algorithm implemented in this Selector emulates 'rendering' to perform the selection and find the shape(s) at the given coordinates.
Selection returns multiple objects in the current position. It can be Node or SelectedItem. SelectedItem usually is using when there is a composite object inside selected area like chart or curve. In this case SelectedItem contains info about samples inside area.

Example

// following code show how to get the names of the selected items.
// The method 'select' returns an array of selected objects. Also it has a radius of selection. In this code is 5 pixels.
import {Selector} from '@int/geotoolkit/selection/Selector';
import {isNode} from '@int/geotoolkit/scene/Node';
const radius = 5;
const select = Selector.select(widget, pt.x, pt.y, radius).filter(isNode);
if (select == null) return;
for (let i = 0; i < select.length; i++) {
console.log(select[i].getName());
}

Example

// result can be filtered using predicates (https://www.typescriptlang.org/docs/handbook/2/narrowing.html#using-type-predicates)
// embedded predicates or any custom predicate can be used
import {isSelectedItem} from '@int/geotoolkit/selection/SelectedItem';
// after filter 'items' is SelectedItem[]
const items = Selector.select(root, point, 2).filter(isSelectedItem);

Table of contents

Constructors
Methods

Contents

Constructors

new Selector(transformation)

new Selector(transformation?)

Create selector

Parameters

Name Type Description
Optional transformationTransformationtransformation from current node to plot (device). It is equal to node.getParent().getSceneTransform(). If a root node is used as a start node then it is not necessary to specify transformation.
Methods

asyncSelect

asyncSelect(callback, root, rectArea, allowIntersection?): void

Select node in the current rectangular area. This method starts selection from the specified node. Coordinates provided are in the parent node coordinate system or device coordinates if the node is a root.

Parameters

Name Type Description
callbackSelectionCallbackcallback
rootNodenode to be used for selection.
rectAreaRectselection rectangle.
Optional allowIntersectionbooleanallow intersection flag

Returns

void

asyncSelect(callback, root, point, radius?): void

Select node in the current point. This method starts selection from the specified node. Coordinates provided are in the parent node coordinate system or device coordinates if the node is a root.

Parameters

Name Type Description
callbackSelectionCallbackcallback
rootNodenode to be used for selection.
pointPointselection point
Optional radiusnumberselection radius

Returns

void

asyncSelect(callback, root, x, y, radius?): void

Select node in the current point. This method starts selection from the specified node. Coordinates provided are in the parent node coordinate system or device coordinates if the node is a root.

Parameters

Name Type Description
callbackSelectionCallbackcallback
rootNodenode to be used for selection.
xnumberx-coordinate of the selection point
ynumbery-coordinate of the selection point
Optional radiusnumberselection radius

Returns

void

asyncSelect(callback, root, point, halfWidth, halfHeight, allowIntersection?): void

Select node in the ellipse area. This method starts selection from the specified node. Coordinates provided are in the parent node coordinate system or device coordinates if the node is a root.

Parameters

Name Type Description
callbackSelectionCallbackcallback
rootNodenode to be used for selection.
pointPointselection point
halfWidthnumberselection ellipse half width
halfHeightnumberselection ellipse half height
Optional allowIntersectionbooleanallow intersection

Returns

void

asyncSelect(callback, root, xx, yy, allowIntersection?, evenOdd?): void

Select node in the polygonal area. This method starts selection from the specified node. Coordinates provided are in the parent node coordinate system or device coordinates if the node is a root.

Parameters

Name Type Description
callbackSelectionCallbackcallback
rootNodenode to be used for selection.
xxnumber[]x-coordinates of the selection polygon
yynumber[]y-coordinates of the selection polygon
Optional allowIntersectionbooleanallow intersection flag
Optional evenOddbooleaneven odd mode

Returns

void


getTransformation

getTransformation(): Transformation

Gets current transformation

Returns

Transformation


select

select(root, rectArea, allowIntersection?): (Node | SelectedItem<any>)[]

Select node in the current rectangular area. This method starts selection from the specified node. Coordinates provided are in the parent node coordinate system or device coordinates if the node is a root.

Parameters

Name Type Description
rootNodenode to be used for selection.
rectAreaRectselection rectangle.
Optional allowIntersectionbooleanallow intersection flag

Returns

(Node | SelectedItem<any>)[]

a collection of selected nodes

select(root, point, radius?): (Node | SelectedItem<any>)[]

Select node in the current point. This method starts selection from the specified node. Coordinates provided are in the parent node coordinate system or device coordinates if the node is a root.

Parameters

Name Type Description
rootNodenode to be used for selection.
pointPointselection point
Optional radiusnumberselection radius

Returns

(Node | SelectedItem<any>)[]

a collection of selected nodes

select(root, x, y, radius?): (Node | SelectedItem<any>)[]

Select node in the current point. This method starts selection from the specified node. Coordinates provided are in the parent node coordinate system or device coordinates if the node is a root.

Parameters

Name Type Description
rootNodenode to be used for selection.
xnumberx-coordinate of the selection point
ynumbery-coordinate of the selection point
Optional radiusnumberselection radius

Returns

(Node | SelectedItem<any>)[]

a collection of selected nodes

select(root, point, halfWidth, halfHeight, allowIntersection?): (Node | SelectedItem<any>)[]

Select node in the ellipse area. This method starts selection from the specified node. Coordinates provided are in the parent node coordinate system or device coordinates if the node is a root.

Parameters

Name Type Description
rootNodenode to be used for selection.
pointPointcenter of ellipse
halfWidthnumberselection ellipse half width
halfHeightnumberselection ellipse half height
Optional allowIntersectionbooleanallow intersection

Returns

(Node | SelectedItem<any>)[]

a collection of selected nodes

select(root, xx, yy, allowIntersection?, evenOdd?): (Node | SelectedItem<any>)[]

Select node in the polygonal area. This method starts selection from the specified node. Coordinates provided are in the parent node coordinate system or device coordinates if the node is a root.

Parameters

Name Type Description
rootNodenode to be used for selection.
xxnumber[]x-coordinates of the selection polygon
yynumber[]y-coordinates of the selection polygon
Optional allowIntersectionbooleanallow intersection flag
Optional evenOddbooleaneven odd mode

Returns

(Node | SelectedItem<any>)[]

a collection of selected nodes


setTransformation

setTransformation(transformation): Selector

Sets current transformation

Parameters

Name Type Description
transformationTransformationtransformation from current node to device

Returns

Selector

this


select

Static select(root, rectArea, allowIntersection?): (Node | SelectedItem<any>)[]

Select node in the current rectangular area. This method starts selection from the specified node. Coordinates provided are in the parent node coordinate system or device coordinates if the node is a root.

Parameters

Name Type Description
rootNodenode to be used for selection.
rectAreaRectselection rectangle.
Optional allowIntersectionbooleanallow intersection flag

Returns

(Node | SelectedItem<any>)[]

a collection of selected nodes

Static select(root, point, radius?): (Node | SelectedItem<any>)[]

Select node in the current point. This method starts selection from the specified node. Coordinates provided are in the parent node coordinate system or device coordinates if the node is a root.

Parameters

Name Type Description
rootNodenode to be used for selection.
pointPointselection point
Optional radiusnumberselection radius

Returns

(Node | SelectedItem<any>)[]

a collection of selected nodes

Static select(root, x, y, radius?): (Node | SelectedItem<any>)[]

Select node in the current point. This method starts selection from the specified node. Coordinates provided are in the parent node coordinate system or device coordinates if the node is a root.

Parameters

Name Type Description
rootNodenode to be used for selection.
xnumberx-coordinate of the selection point
ynumbery-coordinate of the selection point
Optional radiusnumberselection radius

Returns

(Node | SelectedItem<any>)[]

a collection of selected nodes

Static select(root, point, halfWidth, halfHeight, allowIntersection?): (Node | SelectedItem<any>)[]

Select node in the current ellipse. This method starts selection from the specified node. Coordinates provided are in the parent node coordinate system or device coordinates if the node is a root.

Parameters

Name Type Description
rootNodenode to be used for selection.
pointPointselection point
halfWidthnumberselection ellipse half width
halfHeightnumberselection ellipse half height
Optional allowIntersectionbooleanallow intersection

Returns

(Node | SelectedItem<any>)[]

a collection of selected nodes

Static select(root, xx, yy, allowIntersection?, evenOdd?): (Node | SelectedItem<any>)[]

Select node in the polygonal area. This method starts selection from the specified node. Coordinates provided are in the parent node coordinate system or device coordinates if the node is a root.

Parameters

Name Type Description
rootNodenode to be used for selection.
xxnumber[]x-coordinates of the selection polygon
yynumber[]y-coordinates of the selection polygon
Optional allowIntersectionbooleanallow intersection flag
Optional evenOddbooleaneven odd mode

Returns

(Node | SelectedItem<any>)[]

a collection of selected nodes