Reference Source
public class | source

MarqueePicker

Extends:

Component → MarqueePicker

Picks a Viewer's Entitys with a canvas-space 2D marquee box.

Usage

In the example below, we

  1. Create a Viewer, arrange the Camera
  2. Use an XKTLoaderPlugin to load a BIM model,
  3. Create a ObjectsKdTree3 to automatically index the Viewer's Entitys for fast spatial lookup,
  4. Create a MarqueePicker to pick Entitys in the Viewer, using the ObjectsKdTree3 to accelerate picking
  5. Create a MarqueePickerMouseControl to perform the marquee-picking with the MarqueePicker, using mouse input to draw the marquee box on the Viewer's canvas.

When the MarqueePickerMouseControl is active:

  • Long-click, drag and release on the canvas to define a marque box that picks Entitys.
  • Drag left-to-right to pick Entitys that intersect the box.
  • Drag right-to-left to pick Entitys that are fully inside the box.
  • On release, the MarqueePicker will fire a "picked" event with IDs of the picked Entitys, if any.
  • Handling that event, we mark the Entitys as selected.
  • Hold down CTRL to multi-pick.
import {
        Viewer,
        XKTLoaderPlugin,
        ObjectsKdTree3,
        MarqueePicker,
        MarqueePickerMouseControl
} from "xeokit-sdk.es.js";

// 1

const viewer = new Viewer({
    canvasId: "myCanvas"
});

viewer.scene.camera.eye = [14.9, 14.3, 5.4];
viewer.scene.camera.look = [6.5, 8.3, -4.1];
viewer.scene.camera.up = [-0.28, 0.9, -0.3];

// 2

const xktLoader = new XKTLoaderPlugin(viewer);

const sceneModel = xktLoader.load({
    id: "myModel",
    src: "../../assets/models/xkt/v8/ifc/HolterTower.ifc.xkt"
});

// 3

const objectsKdTree3 = new ObjectsKdTree3({viewer});

// 4

const marqueePicker = new MarqueePicker({viewer, objectsKdTree3});

// 5

const marqueePickerMouseControl = new MarqueePickerMouseControl({marqueePicker});

marqueePicker.on("clear", () => {
    viewer.scene.setObjectsSelected(viewer.scene.selectedObjectIds, false);
});

marqueePicker.on("picked", (objectIds) => {
    viewer.scene.setObjectsSelected(objectIds, true);
});

marqueePickerMouseControl.setActive(true);

Design Notes

  • The ObjectsKdTree3 can be shared with any other components that want to use it to spatially search for Entitys.
  • The MarqueePickerMouseControl can be replaced with other types of controllers (i.e. touch), or used alongside them.
  • The MarqueePicker has no input handlers of its own, and provides an API through which to programmatically control marquee picking. By firing the "picked" events, MarqueePicker implements the Blackboard Pattern.

Constructor Summary

Public Constructor
public

constructor(cfg: *)

Creates a MarqueePicker.

Member Summary

Public Members
public

viewer: *

Method Summary

Public Methods
public

clear()

Fires a "clear" event on this MarqueePicker.

public

Destroys this MarqueePicker.

public

Gets if the marquee box is visible.

public

Gets the pick mode.

public

pick(): string[]

Attempts to pick Entitys, using the current MarquePicker settings.

public

setMarquee(corner1: *, corner2: *)

Sets both canvas-space corner positions of the marquee box.

public

setMarqueeCorner1(corner1: *)

Sets the canvas-space position of the first marquee box corner.

public

setMarqueeCorner2(corner2: *)

Sets the canvas-space position of the second marquee box corner.

public

Sets if the marquee box is visible.

public

setPickMode(pickMode: number)

Sets the pick mode.

Inherited Summary

From class Component
public get

The Component that owns the lifecycle of this Component, if any.

public

True as soon as this Component has been destroyed

public

ID of this Component, unique within the Scene.

public

meta: *

Arbitrary, user-defined metadata on this component.

public

The parent Scene that contains this Component.

public

The viewer that contains this Scene.

public

clear()

Destroys all Components that are owned by this.

public

Destroys this component.

public

error(message: String)

Logs an error for this component to the JavaScript console.

public

fire(event: String, value: Object, forget: Boolean)

Fires an event on this component.

public

Returns true if there are any subscribers to the given event on this component.

public

isType(type: *): *: Boolean

Tests if this component is of the given type, or is a subclass of the given type.

public

log(message: String)

Logs a console debugging message for this component.

public

off(subId: String)

Cancels an event subscription that was previously made with Component#on or Component#once.

public

on(event: String, callback: Function, scope: Object): String

Subscribes to an event on this component.

public

once(event: String, callback: Function, scope: Object)

Subscribes to the next occurrence of the given event, then un-subscribes as soon as the event is subIdd.

public

scheduleTask(task: *)

Schedule a task to perform on the next browser interval

public

warn(message: String)

Logs a warning for this component to the JavaScript console.

Public Constructors

public constructor(cfg: *) source

Creates a MarqueePicker.

Override:

Component#constructor

Params:

NameTypeAttributeDescription
cfg *

Configuration

cfg.viewer Viewer

The Viewer to pick Entities from.

cfg.objectsKdTree3 ObjectsKdTree3

A k-d tree that indexes the Entities in the Viewer for fast spatial lookup.

Public Members

public viewer: * source

The viewer that contains this Scene.

Override:

Component#viewer

Public Methods

public clear() source

Fires a "clear" event on this MarqueePicker.

Override:

Component#clear

public destroy() source

Destroys this MarqueePicker.

Does not destroy the Viewer or the ObjectsKdTree3 provided to the constructor of this MarqueePicker.

Override:

Component#destroy

public getMarqueeVisible(): boolean source

Gets if the marquee box is visible.

Return:

boolean

True if the marquee box is visible, else false.

public getPickMode(): number source

Gets the pick mode.

Supported pick modes are:

  • MarqueePicker.PICK_MODE_INSIDE - picks Entitys that are completely inside the marquee box.
  • MarqueePicker.PICK_MODE_INTERSECTS - picks Entitys that intersect the marquee box.

Return:

number

The pick mode.

public pick(): string[] source

Attempts to pick Entitys, using the current MarquePicker settings.

Fires a "picked" event with the IDs of the Entitys that were picked, if any.

Return:

string[]

IDs of the Entitys that were picked, if any

public setMarquee(corner1: *, corner2: *) source

Sets both canvas-space corner positions of the marquee box.

Params:

NameTypeAttributeDescription
corner1 *
corner2 *

public setMarqueeCorner1(corner1: *) source

Sets the canvas-space position of the first marquee box corner.

Params:

NameTypeAttributeDescription
corner1 *

public setMarqueeCorner2(corner2: *) source

Sets the canvas-space position of the second marquee box corner.

Params:

NameTypeAttributeDescription
corner2 *

public setMarqueeVisible(visible: boolean) source

Sets if the marquee box is visible.

Params:

NameTypeAttributeDescription
visible boolean

True if the marquee box is to be visible, else false.

public setPickMode(pickMode: number) source

Sets the pick mode.

Supported pick modes are:

  • MarqueePicker.PICK_MODE_INSIDE - picks Entitys that are completely inside the marquee box.
  • MarqueePicker.PICK_MODE_INTERSECTS - picks Entitys that intersect the marquee box.

Params:

NameTypeAttributeDescription
pickMode number

The pick mode.