Last updated

Picking

# Introduction

Picking is based on the rendering procedure. This structuring avoids duplication in the source code. The figure above shows the selection, which contains a mechanism that picks nodes in the scene graph using spatial properties. During selection, a special implementation of a visitor can visit nodes and emulate rendering with specific implementations of context and graphics. The selected nodes will be put in a list. In addition, the context can give information about the type of rendering.

# Usage

The code below shows a typical usage of the point selection API.

import {Selector} from '@int/geotoolkit/selection/Selector'

const selection =  new Selector();
const nodes = selection.select(plot.getRoot(), posx, posy, 2, 2);
if (nodes && nodes.length > 0) {
    const text = 'Selected nodes:';
    for (let i = 0; i < nodes.length; ++i) {
        text = text + nodes[i];
    }
    alert(text);
}

This code creates a selector and calls the method select and provides a root node to start picking at the specified position and spot area. It returns an array of nodes in direct Z order. For example, if there is a track and a curve in the container display then an array contains two elements {track, curve}.

# Architecture

The class diagram below shows selection architecture.

A user calls the select method on the selector. The selector creates an instance of PointSelectionContext, an implementation of RenderingContext, and passes the new context to the root node. If the geometry of a node intersects a specified spot area then that node is added to a collection of the selected nodes. PointSelectionContext emulates the rendering procedures to check for geometry intersections or containment. The same logic works in a retained mode with RenderingState. A PointSelectionContext provides its own implementation of RenderingState, which checks geometry with context.