Last updated

API / geotoolkit / widgets / tools / LegendTool / LegendTool

Class: LegendTool

tools.LegendTool.LegendTool

Tool to handle moving and resizing of legend around annotated widget

Example

import {LegendTool} from '@int/geotoolkit/widgets/tools/LegendTool';
const legendTool = new LegendTool({
'widget': widget,
'layer': manipulatorLayer,
'group': legendShape
});
// Insert the tool to the head of tool's collection
widget.getTool().insert(0, legendTool);

Hierarchy

Table of contents

Constructors
Methods
Css Properties
Name Type Description
enabledbooleanEnabled state
layerCompositeNodeManipulator layer
layer-clippingbooleanEnable clipping, this does not consider the clipstyle, it is related to bounds-clipping
layer-clipstyleClipStyleClipping style
layer-clipstyle-evenoddbooleanTrue if evenodd mode is on ('nonzero' mode otherwise)
layer-clipstyle-geometryGraphicsPathClipping geometry
layer-clipstyle-geometry-boundsRectBounds
layer-clipstyle-geometry-bounds-heightnumberHeight
layer-clipstyle-geometry-bounds-readonlybooleanReadonly
layer-clipstyle-geometry-bounds-widthnumberWidth
layer-clipstyle-geometry-bounds-xnumberLeft
layer-clipstyle-geometry-bounds-ynumberTop
layer-clipstyleGraphicsPathClipping style
layer-cssclassstringThe css class name of this node
layer-csscursorstringCSS cursor associated with node
layer-cssstylestringCSS style to be applied to inserted elements
layer-idstring | numberId of the node, its a unique identifier
layer-infinitybooleanMode to render outside the model limits
layer-localtransformTransformationLocal transformation
layer-localtransform-dxnumberX axis translation
layer-localtransform-dynumberY axis translation
layer-localtransform-xxnumberX scale
layer-localtransform-xynumberXy skew
layer-localtransform-yxnumberYx skew
layer-localtransform-yynumberY scale
layer-marginsnumber | stringIt has properties for specifying the margins for each side
layer-namestringName of the node. It is often used for debugging purposes or to simplify queries
layer-opacitynumberNode opacity (from 0 to 1). If it is undefined or null it inherits property from the parent. It changes globalAlpha on the rendering context
layer-opacityblendmodeBlendModeNode opacity mode to blend it
layer-scalescrollstrategyScaleScrollStrategyScale scroll strategy
layer-scalescrollstrategy-enabledbooleanEnable flag
layer-selectablebooleanSelectable node, a boolean to determine if selection should consider this node
layer-taganyCustom information associated with node. It is a user object which can be used by client code to store information or attach an application object to the shape
layer-transformstringAdditional CSS transformation applied to node or 'none'
layer-transformTransformationAdditional CSS transformation applied to node or 'none'
layer-visiblebooleanVisibility of the node, a boolean to determine if the node should be rendered or not
layer-z-indexnumberDefine node z-index
mouseradiusnumberDevice radius for mouse events
namestringName of the tool used like cross-hair etc
touchradiusnumberDevice radius for touch events

Contents

Constructors

new LegendTool(options)

new LegendTool(options)

Parameters

Name Type
optionsOptions

Overrides

CompositeTool.constructor

Methods

add

add(tool): LegendTool

Add tool to the container.

Parameters

Name Type Description
toolAbstractTool | AbstractTool[]abstract tool to be added

Returns

LegendTool

Inherited from

CompositeTool.add


addListener

addListener(eventName, listener): LegendTool

add event listener. The listener receives the message when the system event happens.

Deprecated

since 4.0 use .on() instead. Note that 3 args callback should be used in subscription via .on(): (eventType, source, args)

Parameters

Name Type Description
eventNamestringevent name or unique event identifier
listenerFunctionthe event listener

Returns

LegendTool

Inherited from

CompositeTool.addListener


captureMouseUp

captureMouseUp(): void

listen to window mouse events in order to catch a mouse up action outside of the tool container DOM element. useful for example when you pan and release click outside of DOM element.

Returns

void

Inherited from

CompositeTool.captureMouseUp


dispatchEvent

dispatchEvent(eventName, eventArgs): boolean

Dispatch event through the handlers.

Parameters

Name Type Description
eventNamestringcontains the name of the event to dispatch.
eventArgsEventArgscontains info of the event.

Returns

boolean

Inherited from

CompositeTool.dispatchEvent


dispose

dispose(): void

Dispose tool.

Returns

void

Inherited from

CompositeTool.dispose


fireEvent

fireEvent(eventName, eventArgs?): void

This method is Protected. Fire an Event.

Deprecated

since 4.0 use .notify() instead. Note that 3 args callback should be used in subscription via .on()

Parameters

Name Type Description
eventNamestringevent name
Optional eventArgsanycontains info of the event

Returns

void

Inherited from

CompositeTool.fireEvent


getClassName

getClassName(): string

Returns

string

Inherited from

CompositeTool.getClassName


getEventRadius

Protected getEventRadius(eventArgs): number

Returns device radius for the provided event

Parameters

Name Type Description
eventArgsEventArgscontains info of the event

Returns

number

Inherited from

CompositeTool.getEventRadius


getManipulatorLayer

getManipulatorLayer(): CompositeNode<Node>

return manipulator layer

Returns

CompositeNode<Node>

layer

Inherited from

CompositeTool.getManipulatorLayer


getMouseRadius

getMouseRadius(): number

Returns current device radius for mouse events

Returns

number

Inherited from

CompositeTool.getMouseRadius


getName

getName(): string

return tool name if any

Returns

string

name of the tool

Inherited from

CompositeTool.getName


getNode

getNode(): CompositeNode<Node>

Returns node associated with manipulator.

Returns

CompositeNode<Node>

Inherited from

CompositeTool.getNode


getOptions

getOptions(): Options

Get LegendTool options

Returns

Options

LegendTool options


getParentTool

getParentTool(): AbstractCompositeTool

Gets parent tool

Returns

AbstractCompositeTool

parent tool

Inherited from

CompositeTool.getParentTool


getProperties

getProperties(context?): OptionsOut

Returns all the properties pertaining to this object

Parameters

Name Type Description
Optional contextISerializationContextserialization context

Returns

OptionsOut

An object containing the properties

Inherited from

CompositeTool.getProperties


getProperty

getProperty(name): any

Gets dynamic property by name. These properties can be used as a property bags

Parameters

Name Type Description
namestringproperty name

Returns

any

Inherited from

CompositeTool.getProperty


getPropertyKeys

getPropertyKeys(): string[]

Returns known properties keys

Returns

string[]

Inherited from

CompositeTool.getPropertyKeys


getRoot

getRoot(): AbstractCompositeTool

Gets root tool

Returns

AbstractCompositeTool

parent tool

Inherited from

CompositeTool.getRoot


getToolByName

getToolByName(name): AbstractTool

Returns the tool matching the given name. This function also accepts tool 'path' instead of absolute name. For example: getToolByName("compositeTool.panningTools.trackPanning.TrackPanning") Would return the same tool as getToolByName("TrackPanning") As long as there is only one tool named "TrackPanning" in this composite

See listToolsNames()

Parameters

Name Type Description
namestringtool name or path

Returns

AbstractTool

Inherited from

CompositeTool.getToolByName


getToolByType

getToolByType(type): AbstractTool

Returns the tool matching the given type.

Parameters

Name Type Description
typeClassType<any>type

Returns

AbstractTool

Inherited from

CompositeTool.getToolByType


getToolIndex

getToolIndex(tool): number

Return index of specified tool.

Parameters

Name Type Description
toolAbstractToolabstract tool

Returns

number

index of tool

Inherited from

CompositeTool.getToolIndex


getTouchRadius

getTouchRadius(): number

Returns current device radius for touch events

Returns

number

Inherited from

CompositeTool.getTouchRadius


hasEventListener

hasEventListener(type, callback?): boolean

Check if a list of event listeners for this type contains this listener

Parameters

Name Type Description
typestringtype of event or property
Optional callbackFunctionto be called, if null, check if any callback is registered

Returns

boolean

Inherited from

CompositeTool.hasEventListener


insert

insert(index, tool): LegendTool

Insert tool at specified index.

Parameters

Name Type Description
indexnumberindex to insert the tool
toolAbstractTool | AbstractTool[]abstract tool

Returns

LegendTool

Inherited from

CompositeTool.insert


isActive

isActive(): boolean

return active state

Returns

boolean

Inherited from

CompositeTool.isActive


isDisposed

isDisposed(): boolean

Returns whether this object has been disposed

Returns

boolean

Inherited from

CompositeTool.isDisposed


isDoubleClick

Protected isDoubleClick(point, eventArgs?): boolean

returns true if double clicked

Parameters

Name Type Description
pointPointClick point
Optional eventArgsEventArgsoptional event args to verify double click

Returns

boolean

Inherited from

CompositeTool.isDoubleClick


isEnabled

isEnabled(): boolean

returns enable state

Returns

boolean

state

Inherited from

CompositeTool.isEnabled


isSilent

isSilent(): boolean

Return true if the event dispatcher doesn't notify any events

Returns

boolean

Inherited from

CompositeTool.isSilent


isTouchEvent

isTouchEvent(eventArgs): boolean

return true if the event is a touch event and false otherwise.

Parameters

Name Type Description
eventArgsEvent | EventArgscontains info of the event

Returns

boolean

Inherited from

CompositeTool.isTouchEvent


listToolsNames

listToolsNames(): string[]

List all the tools contained in this composite. Prepend their compositetool parent using a '.'

Returns

string[]

Inherited from

CompositeTool.listToolsNames


notify

notify<E>(type, source, args?): LegendTool

Notify listeners

Type parameters

NameType
Eextends string

Parameters

Name Type Description
typeEevent types
sourceLegendToolof the event
Optional argsEventMap[E]arguments of the event

Returns

LegendTool

this

Overrides

CompositeTool.notify


off

off<E>(type?, callback?): LegendTool

Detach listener on event. Calling .off() with no arguments removes all attached listeners. Calling .off(type) with no callback removes all attached listeners for specific type.

Type parameters

NameType
Eextends string

Parameters

Name Type Description
Optional typeEtype of the event
Optional callback(eventType: E, sender: LegendTool, args: EventMap[E]) => voidfunction to be called

Returns

LegendTool

this

Overrides

CompositeTool.off


on

on<E>(type, callback): LegendTool

Attach listener on event that will be called whenever the specified event is delivered to the target

If the callback function is already in the list of event listeners for this target, the function is not added a second time.

If a particular anonymous function is in the list of event listeners registered for a certain target, and then later in the code, an identical anonymous function is given in an "on" call, the second function will also be added to the list of event listeners for that target.

TypeScript hint: in case of creating derived tool with own events, EventMap should be extended and .on() and .notify() methods redeclared, see sample.

Example

// Using in derived tool
import type {EventMap as EventMapBase} from '@int/geotoolkit/controls/tools/AbstractTool';
export type EventMap = EventMapBase &amp; {
[MyToolEvents.onValueChanged]: MyToolEventArgs
}
export enum MyToolEvents {
onValueChanged = 'onValueChanged'
}
export class MyTool extends AbstractTool {
public declare on: <E extends keyof EventMap>(type: E, callback: (eventType: E, sender: this, args: EventMap[E]) => void) => this;
protected declare notify: <E extends keyof EventMap>(type: E, source: AbstractTool, args?: EventMap[E]) => this;
public declare off: <E extends keyof EventMap>(type: E, callback?: (eventType: E, sender: this, args: EventMap[E]) => void) => this;
// ...
}

Type parameters

NameType
Eextends string

Parameters

Name Type Description
typeEtype of event or property
callback(eventType: E, sender: LegendTool, args: EventMap[E]) => voidto be called

Returns

LegendTool

Overrides

CompositeTool.on


onActiveStateChanged

Protected onActiveStateChanged(): void

Fires

Events.onStateChanged

Returns

void

Inherited from

CompositeTool.onActiveStateChanged


onEnabledStateChanged

Protected onEnabledStateChanged(): void

Fires

Events.onEnabledStateChanged

Returns

void

Inherited from

CompositeTool.onEnabledStateChanged


pageToCanvas

pageToCanvas(eventArgs, externalPlot?): Object

return position relative to the canvas

Parameters

Name Type Description
eventArgsEvent | EventArgsparentElement the parent HTML element
Optional externalPlotPlotplot

Returns

Object

NameType
xnumber
ynumber

Inherited from

CompositeTool.pageToCanvas


pointToModel

pointToModel(model, eventArgs): Point

converts device coordinates to inner coordinates of node

Parameters

Name Type Description
modelNodethe model
eventArgsPoint | EventArgsarguments of the event OR point in device (plot) coordinates.

Returns

Point

Inherited from

CompositeTool.pointToModel


remove

remove(tool): LegendTool

Remove tool from container.

Parameters

Name Type Description
toolAbstractTool | AbstractTool[]to remove

Returns

LegendTool

Inherited from

CompositeTool.remove


removeListener

removeListener(eventName, listener?): LegendTool

remove event listener. The listener reveives the message when the system event happens.

Deprecated

since 4.0 use .off() instead.

Parameters

Name Type Description
eventNamestringevent name
Optional listenerFunction | Function[]the event listener, if null, remove all listeners for the event

Returns

LegendTool

Inherited from

CompositeTool.removeListener


resetAnnotationSize

resetAnnotationSize(): LegendTool

Reset annotation size to original

Returns

LegendTool

this


setActive

setActive(active): LegendTool

set active state

Fires

Events.onStateChanged

Parameters

Name Type Description
activebooleanset active state

Returns

LegendTool

Inherited from

CompositeTool.setActive


setEnabled

setEnabled(enabled): LegendTool

set enable state

Fires

Events.onEnabledStateChanged

Fires

Events.onStateChanged

Parameters

Name Type Description
enabledbooleansets the enabled state

Returns

LegendTool

this

Inherited from

CompositeTool.setEnabled


setMouseRadius

setMouseRadius(radius): LegendTool

Sets device radius for mouse events

Parameters

Name Type Description
radiusnumberradius for mouse events

Returns

LegendTool

this

Inherited from

CompositeTool.setMouseRadius


setName

setName(name): LegendTool

set tool name

Parameters

Name Type Description
namestringthe tool name

Returns

LegendTool

Inherited from

CompositeTool.setName


setNode

setNode(node): LegendTool

Sets node associated with manipulator

Parameters

Name Type Description
nodeCompositeNode<Node>node

Returns

LegendTool

this

Inherited from

CompositeTool.setNode


setOptions

setOptions(options): LegendTool

Set LegendTool options

Parameters

Name Type Description
optionsOptionsLegendTool options

Returns

LegendTool

this


setProperties

setProperties(properties?, context?): LegendTool

Sets all the properties pertaining to this object

Parameters

Name Type Description
Optional propertiesOptionsAn object containing the properties to set
Optional contextIDeserializationContextdeserialization context

Returns

LegendTool

this

Inherited from

CompositeTool.setProperties


setProperty

setProperty(name, value): LegendTool

Sets dynamic property by name

Parameters

Name Type Description
namestringproperty name
valueanyproperty value

Returns

LegendTool

this

Inherited from

CompositeTool.setProperty


setSilent

setSilent(bool): LegendTool

Set silent mode

Parameters

Name Type Description
boolbooleanflag to enable silent mode

Returns

LegendTool

this

Inherited from

CompositeTool.setSilent


setSlotEnabled

setSlotEnabled(eventName, value, target?): LegendTool

Sets slot enabled

Parameters

Name Type Description
eventNamestringeventName
valuebooleanvalue
Optional targetEventTargettarget

Returns

LegendTool

Inherited from

CompositeTool.setSlotEnabled


setSlots

setSlots(slots?, merge?): LegendTool

Sets new slots.

Example

const slots = {
'pointerdown': (event: EventArgs) => {
// event is an instance of @int/geotoolkit/controls/tools/EventArgs
...
}
};
tool.setSlots(slots);

Parameters

Name Type Description
Optional slotsRecord<string, Slot | Slot[] | (eventArgs: EventArgs) => void>type of system events
Optional mergebooleanset to true if you want to merge with existing slots

Returns

LegendTool

this

Inherited from

CompositeTool.setSlots


setTouchRadius

setTouchRadius(radius): LegendTool

Sets device radius for touch events

Parameters

Name Type Description
radiusnumberradius for touch events

Returns

LegendTool

this

Inherited from

CompositeTool.setTouchRadius


start

Protected start(eventArgs?): LegendTool

start

Parameters

Name Type Description
Optional eventArgsEventArgsevent args

Returns

LegendTool

Inherited from

CompositeTool.start


stop

Protected stop(): LegendTool

stop

Returns

LegendTool

Inherited from

CompositeTool.stop


toggle

toggle(): LegendTool

switch enable state to opposite state

Returns

LegendTool

Inherited from

CompositeTool.toggle


updateHandles

updateHandles(): LegendTool

Update adapter handles

Returns

LegendTool

this


canvasToClient

Static canvasToClient(plotPoint, plot): Point

Convert plot coordinates to global coordinates

Parameters

Name Type Description
plotPointPointpoint in plot coordinates
plotPlotplot with canvas

Returns

Point

Inherited from

CompositeTool.canvasToClient


clientToCanvas

Static clientToCanvas(nativeEvent, plot): Point

Convert global coordinates to plot coordinates

Parameters

Name Type Description
nativeEventEventnative browser event
plotPlotplot with canvas

Returns

Point

Inherited from

CompositeTool.clientToCanvas


getClassName

Static getClassName(): string

Returns

string

Inherited from

CompositeTool.getClassName


getExclusiveTool

Static getExclusiveTool(plot): AbstractTool

return exclusive tool associated with plot

Parameters

Name Type Description
plotPlotplot

Returns

AbstractTool

tool

Inherited from

CompositeTool.getExclusiveTool


getNativeEventName

Static getNativeEventName(eventName): string[]

Returns native event name

Parameters

Name Type Description
eventNamestringW3C Pointer Events Recommendation name

Returns

string[]

Inherited from

CompositeTool.getNativeEventName


isTouchEvent

Static isTouchEvent(eventArgs): eventArgs is TouchEvent

return true if the event is a touch event and false otherwise.

Parameters

Name Type Description
eventArgsEvent | EventArgscontains info of the event

Returns

eventArgs is TouchEvent

Inherited from

CompositeTool.isTouchEvent


lock

Static lock(plot, tool): void

Set exclusive tool for plot

Parameters

Name Type Description
plotPlotplot
toolAbstractTooltool

Returns

void

Inherited from

CompositeTool.lock


setDefaultMouseRadius

Static setDefaultMouseRadius(radius): void

Sets default device radius for mouse events

Parameters

Name Type Description
radiusnumberradius for mouse events

Returns

void

Inherited from

CompositeTool.setDefaultMouseRadius


setDefaultTouchRadius

Static setDefaultTouchRadius(radius): void

Sets default device radius for touch events

Parameters

Name Type Description
radiusnumberradius for touch events

Returns

void

Inherited from

CompositeTool.setDefaultTouchRadius


unlock

Static unlock(value): void

Remove exclusive tool from plot

Parameters

Name Type Description
valueAbstractTool | Plotvalue

Returns

void

Inherited from

CompositeTool.unlock