Skip to content
Last updated

API / geotoolkit / selection / QueryBuilder / QueryBuilder

Class: QueryBuilder<T&gt;

selection.QueryBuilder.QueryBuilder

Provides search by any item in the hierarchical structure. <T> is base type for root and child elements

Type parameters

NameType
Textends any = any

Table of contents

Constructors
  • [new QueryBuilder<T&gt;(item, options)](/solutions/geotoolkit/GeoToolkit_JS/apis/classes/geotoolkit.selection.querybuilder.querybuilder.md#new querybuilder<t>(item, options))
Methods

Contents

Constructors

new QueryBuilder&lt;T&amp;gt;(item, options)

• new QueryBuilder<T&gt;(item, options?)

Type parameters

NameType
Textends unknown = any

Parameters

Name Type Description
itemT | T[]item to apply this query
Optional optionsOptions<T&gt;an additional options
Methods

enumerateNodes

▸ enumerateNodes(item, callback): void

Iterates over the children of the given item. This iterator does not support concurrent modification (the callback provided should not add/remove children)

Parameters

Name Type Description
itemT | T[]item to apply this query
callback(node: T, x?: QueryBuilder<any&gt;) => voidThe callback function

Returns

void


execute

▸ execute(callback): QueryBuilder<T&gt;

Execute all queries

Parameters

Name Type Description
callback(item: T) => boolean | voidfunction called for each item that matches this query condition

Returns

QueryBuilder<T&gt;


functions

▸ functions(functions): QueryBuilder<T&gt;

Register functions

Example

import {from} from '@int/geotoolkit/selection/from';
import {Line} from '@int/geotoolkit/scene/shapes/Line';
import {Rectangle} from '@int/geotoolkit/scene/shapes/Rectangle';
from(group1)
.functions({'isLine': (node) =&gt; node instanceof Line,
'isRect': (node) =&gt; node instanceof Rectangle})
.where( 'node =&gt; isLine(node) || node =&gt; isRectangle(node)' )

Parameters

Name Type Description
functionsRecord<string, Function&gt;allows to register additional functions

Returns

QueryBuilder<T&gt;


getClassName

▸ getClassName(): string

Returns

string


instanceOf

▸ instanceOf<U&gt;(cls): QueryBuilder<U&gt;

Specify instance filter

Type parameters

NameType
Uextends unknown

Parameters

Name Type Description
clsClassType<U&gt; | Constructor<U&gt;class type to check with

Returns

QueryBuilder<U&gt;


select

▸ select(callback): QueryBuilder<T&gt;

Execute all queries

Parameters

Name Type Description
callback(item: T) => boolean | voidfunction called for each item that matches this query condition

Returns

QueryBuilder<T&gt;


selectFirst

▸ selectFirst(): T

Select the first item

Returns

T


selectLast

▸ selectLast(): T

Select the last item

Returns

T


selectToArray

▸ selectToArray(): T[]

Select all items to array

Returns

T[]

an array of the selected items


where

▸ where(f): QueryBuilder<T&gt;

Specify filter

Parameters

Name Type Description
fstring | (item: T) => booleanfunction or condition to provide filter of items or string to specify query

Returns

QueryBuilder<T&gt;


getClassName

▸ Static getClassName(): string

Returns

string