API / geotoolkit / map / tools / Measure / Measure
Measure tool for measuring distances and areas on a map
↳
Measure
Constructors
Methods
Methods
▸ addListener(eventName, listener): Measure
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)
| Name | Type | Description |
|---|---|---|
eventName | string | event name or unique event identifier |
listener | Function | the event listener |
▸ canRedo(): boolean
Checks if there is command in history to redo
boolean
▸ canUndo(): boolean
Checks if there is command in history to undo
boolean
▸ 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.
void
▸ clear(): Measure
Clears scene from all the painting elements
this
▸ Protected createEditor(options): AbstractEditorBase<Node | Node[]>
Returns editor to edit node with provided options
Throws
if supported editor was not found and default editor was not set
| Name | Type | Description |
|---|---|---|
options | Record<string, any> | editor options |
AbstractEditorBase<Node | Node[]>
▸ dispose(): void
Dispose tool.
void
▸ editNode(node): Measure
Starts editing the node provided
this
▸ execute(command): Measure
Applies the specified command to the associated node and appends it to history
| Name | Type | Description |
|---|---|---|
command | AbstractCommand | the command to execute |
▸ 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()
| Name | Type | Description |
|---|---|---|
eventName | string | event name |
Optional eventArgs | any | contains info of the event |
void
▸ getActiveShape(): Node
Returns currently edited shape. Relevant for EditMode.Ghost mode.
▸ getArea(): number
Returns measured area value
number
▸ getClassName(): string
string
▸ getDistances(): number[]
Returns distances that were measured
number[]
▸ getEditMode(): EditMode
Returns tool current edit mode
▸ getEditor(): AbstractEditorBase<Node | Node[]>
Returns current editor tool (if exists)
AbstractEditorBase<Node | Node[]>
▸ Protected getEventRadius(eventArgs): number
Returns device radius for the provided event
| Name | Type | Description |
|---|---|---|
eventArgs | EventArgs | contains info of the event |
number
▸ getHistory(): History
Returns current history
Returns label(s) that display distances or area
label(s)
▸ getManipulatorLayer(): CompositeNode<Node>
return manipulator layer
layer
▸ getMeasureMode(): MeasureMode
Returns current measure mode
mode
▸ getMode(): PaintMode
Returns current painting mode
▸ getMouseRadius(): number
Returns current device radius for mouse events
number
▸ getName(): string
return tool name if any
string
name of the tool
▸ getParentTool(): AbstractCompositeTool
Gets parent tool
parent tool
▸ getPathMode(): MeasurePathMode
Returns current mode for paths
▸ getProperties(): OptionsOut
Returns all properties
tool options
▸ getProperty(name): any
Gets dynamic property by name. These properties can be used as a property bags
| Name | Type | Description |
|---|---|---|
name | string | property name |
any
▸ getPropertyKeys(): string[]
Returns known properties keys
string[]
▸ Protected getRegistry(): Registry
▸ getRoot(): AbstractCompositeTool
Gets root tool
parent tool
▸ getShape(): Node
Returns the origin of currently edited shape (if exists, null otherwise).
▸ getTouchRadius(): number
Returns current device radius for touch events
number
▸ getUnit(): AbstractUnit
Returns current measuring unit
▸ hasEventListener(type, callback?): boolean
Check if a list of event listeners for this type contains this listener
| Name | Type | Description |
|---|---|---|
type | string | type of event or property |
Optional callback | Function | to be called, if null, check if any callback is registered |
boolean
▸ isActive(): boolean
return active state
boolean
▸ isDisposed(): boolean
Returns whether this object has been disposed
boolean
▸ Protected isDoubleClick(point, eventArgs?): boolean
returns true if double clicked
| Name | Type | Description |
|---|---|---|
point | Point | Click point |
Optional eventArgs | EventArgs | optional event args to verify double click |
boolean
▸ isEnabled(): boolean
returns enable state
boolean
state
▸ isSilent(): boolean
Return true if the event dispatcher doesn't notify any events
boolean
▸ isTouchEvent(eventArgs): boolean
return true if the event is a touch event and false otherwise.
| Name | Type | Description |
|---|---|---|
eventArgs | Event | EventArgs | contains info of the event |
boolean
▸ notify<E>(type, source, args?): Measure
Notify listeners
| Name | Type |
|---|---|
E | extends string |
| Name | Type | Description |
|---|---|---|
type | E | event types |
source | Measure | of the event |
Optional args | EventMap[E] | arguments of the event |
this
▸ off<E>(type?, callback?): Measure
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.
| Name | Type |
|---|---|
E | extends string |
| Name | Type | Description |
|---|---|---|
Optional type | E | type of the event |
Optional callback | (eventType: E, sender: Measure, args: EventMap[E]) => void | function to be called |
this
▸ on<E>(type, callback): Measure
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 & {
[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;
// ...
}| Name | Type |
|---|---|
E | extends string |
| Name | Type | Description |
|---|---|---|
type | E | type of event or property |
callback | (eventType: E, sender: Measure, args: EventMap[E]) => void | to be called |
▸ Protected onActiveStateChanged(): void
Fires
void
▸ Protected onBeforeCommandApplying(eventName, history, command): void
Fires the EditEvents.BeforeCommandApplied event
| Name | Type | Description |
|---|---|---|
eventName | EditEvents | the event name |
history | History | the source history |
command | AbstractCommand | the command applied |
void
Measure.onBeforeCommandApplying
▸ Protected onCommandApplied(eventName, history, command): void
Fires the EditEvents.CommandApplied event and the event according to the command event name
| Name | Type | Description |
|---|---|---|
eventName | EditEvents | the event name |
history | History | the source history |
command | AbstractCommand | the command applied |
void
▸ Protected onCommandApplying(eventName, history, command): void
Fires the EditEvents.CommandApplying event
| Name | Type | Description |
|---|---|---|
eventName | EditEvents | the event name |
history | History | the source history |
command | AbstractCommand | the command applied |
void
▸ Protected onCommandRedo(eventName, history, command): void
Fires the EditEvents.Redo event
| Name | Type | Description |
|---|---|---|
eventName | EditEvents | the event name |
history | History | the source history |
command | AbstractCommand | the command |
void
▸ Protected onCommandUndo(eventName, history, command): void
Fires the EditEvents.Undo event
| Name | Type | Description |
|---|---|---|
eventName | EditEvents | the event name |
history | History | the source history |
command | AbstractCommand | the command |
void
▸ Protected onEnabledStateChanged(): void
Fires
void
▸ Protected onKeyDown(eventArgs): void
Handles key down event
| Name | Type | Description |
|---|---|---|
eventArgs | EventArgs | event args |
void
▸ Protected onKeyUp(eventArgs): void
Handles key up event
| Name | Type | Description |
|---|---|---|
eventArgs | EventArgs | event args |
void
▸ Protected onMouseDown(eventArgs): void
| Name | Type | Description |
|---|---|---|
eventArgs | EventArgs | event args |
void
▸ Protected onMouseMove(eventArgs): void
| Name | Type | Description |
|---|---|---|
eventArgs | EventArgs | event args |
void
▸ Protected onMouseUp(eventArgs): void
| Name | Type | Description |
|---|---|---|
eventArgs | EventArgs | event args |
void
▸ Protected onNodeCreated(editor, eventArgs): void
Node created handler
| Name | Type | Description |
|---|---|---|
editor | AbstractEditorBase<Node | Node[]> | editor that created node |
eventArgs | PaintEventArgs | event args |
void
▸ pageToCanvas(eventArgs, externalPlot?): Object
return position relative to the canvas
| Name | Type | Description |
|---|---|---|
eventArgs | Event | EventArgs | parentElement the parent HTML element |
Optional externalPlot | Plot | plot |
Object
| Name | Type |
|---|---|
x | number |
y | number |
▸ pointToModel(model, eventArgs): Point
converts device coordinates to inner coordinates of node
| Name | Type | Description |
|---|---|---|
model | Node | the model |
eventArgs | Point | EventArgs | arguments of the event OR point in device (plot) coordinates. |
▸ redo(): Measure
Reapplies last canceled command in history (if possible)
▸ removeListener(eventName, listener?): Measure
remove event listener. The listener reveives the message when the system event happens.
Deprecated
since 4.0 use .off() instead.
| Name | Type | Description |
|---|---|---|
eventName | string | event name |
Optional listener | Function | Function[] | the event listener, if null, remove all listeners for the event |
▸ setActive(active): Measure
set active state
Fires
| Name | Type | Description |
|---|---|---|
active | boolean | set active state |
▸ setEditMode(mode): Measure
Sets tool edit mode (for nodes with node manipulators)
| Name | Type | Description |
|---|---|---|
mode | EditMode | edit mode |
this
▸ Protected setEditor(editor): Measure
For internal use
| Name | Type | Description |
|---|---|---|
editor | AbstractEditorBase<Node | Node[]> | editor to use |
this
▸ setEnabled(enabled): Measure
set enable state
Fires
Fires
| Name | Type | Description |
|---|---|---|
enabled | boolean | sets the enabled state |
this
▸ setMeasureMode(mode): Measure
Sets measure mode (for what is measured)
| Name | Type | Description |
|---|---|---|
mode | MeasureMode | measure mode |
this
▸ setMode(mode): Measure
Sets painting mode
| Name | Type | Description |
|---|---|---|
mode | PaintMode | painting mode |
▸ setMouseRadius(radius): Measure
Sets device radius for mouse events
| Name | Type | Description |
|---|---|---|
radius | number | radius for mouse events |
this
▸ setName(name): Measure
set tool name
| Name | Type | Description |
|---|---|---|
name | string | the tool name |
▸ setPathMode(mode): Measure
Sets displaying paths mode
| Name | Type | Description |
|---|---|---|
mode | MeasurePathMode | paths mode to use |
this
▸ setProperties(props?): Measure
Sets paint tool properties (mode, styles, etc.)
| Name | Type | Description |
|---|---|---|
Optional props | Options | tool props |
this
▸ setProperty(name, value): Measure
Sets dynamic property by name
| Name | Type | Description |
|---|---|---|
name | string | property name |
value | any | property value |
this
▸ setSilent(bool): Measure
Set silent mode
| Name | Type | Description |
|---|---|---|
bool | boolean | flag to enable silent mode |
this
▸ setSlotEnabled(eventName, value, target?): Measure
Sets slot enabled
| Name | Type | Description |
|---|---|---|
eventName | string | eventName |
value | boolean | value |
Optional target | EventTarget | target |
▸ setSlots(slots?, merge?): Measure
Sets new slots.
Example
const slots = {
'pointerdown': (event: EventArgs) => {
// event is an instance of @int/geotoolkit/controls/tools/EventArgs
...
}
};
tool.setSlots(slots);| Name | Type | Description |
|---|---|---|
Optional slots | Record<string, Slot | Slot[] | (eventArgs: EventArgs) => void> | type of system events |
Optional merge | boolean | set to true if you want to merge with existing slots |
this
▸ setTouchRadius(radius): Measure
Sets device radius for touch events
| Name | Type | Description |
|---|---|---|
radius | number | radius for touch events |
this
▸ setUnit(unit): Measure
Sets measuring units
| Name | Type | Description |
|---|---|---|
unit | string | Unit | unit for measuring |
this
▸ Protected start(eventArgs?): Measure
start
| Name | Type | Description |
|---|---|---|
Optional eventArgs | EventArgs | event args |
▸ Protected stop(): Measure
stop
▸ toggle(): Measure
switch enable state to opposite state
▸ undo(): Measure
Cancels last command in history (if possible)
▸ update(): Measure
Forces editing shapes and handles to be updated
this
▸ updateHandles(): Measure
Forces editing handles to be synchronized with shape
this
▸ Static canvasToClient(plotPoint, plot): Point
Convert plot coordinates to global coordinates
▸ Static clientToCanvas(nativeEvent, plot): Point
Convert global coordinates to plot coordinates
| Name | Type | Description |
|---|---|---|
nativeEvent | Event | native browser event |
plot | Plot | plot with canvas |
▸ Static getClassName(): string
string
▸ Static getExclusiveTool(plot): AbstractTool
return exclusive tool associated with plot
| Name | Type | Description |
|---|---|---|
plot | Plot | plot |
tool
▸ Static getNativeEventName(eventName): string[]
Returns native event name
| Name | Type | Description |
|---|---|---|
eventName | string | W3C Pointer Events Recommendation name |
string[]
▸ Static isTouchEvent(eventArgs): eventArgs is TouchEvent
return true if the event is a touch event and false otherwise.
| Name | Type | Description |
|---|---|---|
eventArgs | Event | EventArgs | contains info of the event |
eventArgs is TouchEvent
▸ Static lock(plot, tool): void
Set exclusive tool for plot
| Name | Type | Description |
|---|---|---|
plot | Plot | plot |
tool | AbstractTool | tool |
void
▸ Static setDefaultMouseRadius(radius): void
Sets default device radius for mouse events
| Name | Type | Description |
|---|---|---|
radius | number | radius for mouse events |
void
▸ Static setDefaultTouchRadius(radius): void
Sets default device radius for touch events
| Name | Type | Description |
|---|---|---|
radius | number | radius for touch events |
void
▸ Static unlock(value): void
Remove exclusive tool from plot
| Name | Type | Description |
|---|---|---|
value | AbstractTool | Plot | value |
void