Last updated

API / geotoolkit / css / CssStyle / CssStyle

Class: CssStyle

css.CssStyle.CssStyle

Defines a CSS style that contains a set of CSS rules to be applied to a node and all of its children. This CSS style class can also parse CSS provided as a string.
For more details on how to apply CSS styles, refer to the CSS Styles Tutorial.

Example

import {CssStyle} from '@int/geotoolkit/css/CssStyle';
const css = `
.Text {
textstyle-color: darkblue;
textstyle-font: 42px Roboto;
textstyle-alignment: center;
}
`;
// Style will be applied for all text shapes
group.setCss(new CssStyle({'css': css}));

Example

CSS as an object

// CSS as an object
const css = {
'selector': '.Group',
'properties': {
'fillstyle': {
'color': 'green'
},
'visible': false
}
};
group.setCss(css);

Example

// CSS as a string
import {Rectangle} from '@int/geotoolkit/scene/shapes/Rectangle';
import {KnownColors} from '@int/geotoolkit/util/ColorUtil';

new Rectangle({
'left': 60,
'top': 60,
'width': 150,
'height': 150,
'fillstyle': KnownColors.Blue
})
.setCss(`
.Rectangle:hover {
fillstyle: red;
}`);

Hierarchy

Table of contents

Constructors
Methods

Contents

Constructors

new CssStyle(options)

new CssStyle(options?)

Create CssStyle

Parameters

Name Type Description
Optional optionsstring | Options | Css | Css[]Object containing css and additional properties or the CSS string

Overrides

Style.constructor

Methods

apply

apply(node): CssStyle

Apply CSS for the current node

Parameters

Name Type Description
nodeNode | Node[]current instance of the node

Returns

CssStyle


clone

clone(): CssStyle

All inheritors should implement copy constructor or provide custom implementation for this method

Returns

CssStyle

this

Overrides

Style.clone


copyConstructor

Protected copyConstructor(src, deepCopy?): CssStyle

copy constructor

Parameters

Name Type Description
srcStyleSource to copy from
Optional deepCopybooleandeep copy

Returns

CssStyle

this

Inherited from

Style.copyConstructor


dispose

dispose(): void

Dispose.

Returns

void

Inherited from

Style.dispose


getClassName

getClassName(): string

Returns

string

Inherited from

Style.getClassName


getCss

getCss(): string

Return the current CSS string

Returns

string


getProperties

getProperties(context?): Record<string, any>

Gets all the properties pertaining to this object

Parameters

Name Type Description
Optional contextISerializationContextserialization context

Returns

Record<string, any>

properties properties

Inherited from

Style.getProperties


getState

getState(node?, deep?): any

Return a state of node and selected children before applying style

Parameters

Name Type Description
Optional nodeNodenode to apply selectors
Optional deepbooleantrue if state should include node children's state

Returns

any

object with serialized properties to be changed


getTimeStamp

getTimeStamp(): number

Gets time stamp

Returns

number

timeStamp

Inherited from

Style.getTimeStamp


getVariable

getVariable(name): any

Return Variable value

Parameters

Name Type Description
namestringvariable name

Returns

any


getVariables

getVariables(): string[]

Return all existing variables

Returns

string[]


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

Style.hasEventListener


hasVariable

hasVariable(name): boolean

Check if Variable exists

Parameters

Name Type Description
namestringvariable name

Returns

boolean


invalidate

invalidate(): CssStyle

notify the node that the style is invalidated

Returns

CssStyle

this

Inherited from

Style.invalidate


isDisposed

isDisposed(): boolean

Returns whether this object has been disposed

Returns

boolean

Inherited from

Style.isDisposed


isEnabled

isEnabled(): boolean

Returns enable state

Returns

boolean

state


isSilent

isSilent(): boolean

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

Returns

boolean

Inherited from

Style.isSilent


notify

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

Notify listeners

Type parameters

NameType
Eextends string

Parameters

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

Returns

CssStyle

this

Inherited from

Style.notify


off

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

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: CssStyle, args: EventMap[E]) => voidfunction to be called

Returns

CssStyle

this

Inherited from

Style.off


on

on<E>(type, callback): CssStyle

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.

Type parameters

NameType
Eextends string

Parameters

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

Returns

CssStyle

this

Inherited from

Style.on


setEnabled

setEnabled(enabled): CssStyle

Enable / disable applying style If style is disabled it will not be applied for any node

Parameters

Name Type Description
enabledbooleansets the enabled state

Returns

CssStyle

this


setProperties

setProperties(properties?, context?): CssStyle

Sets all the properties pertaining to this object

Parameters

Name Type Description
Optional propertiesRecord<string, any>An object containing the properties to set
Optional contextIDeserializationContextdeserialization context

Returns

CssStyle

this

Inherited from

Style.setProperties


setSilent

setSilent(bool, force?): CssStyle

Set silent mode

Parameters

Name Type Description
boolbooleanflag to enable silent mode
Optional forcebooleantrue if parent should be invalidated immediately

Returns

CssStyle

this

Inherited from

Style.setSilent


setVariable

setVariable(variable, value): CssStyle

Set variable value

Parameters

Name Type Description
variablestringvariable name
valueanyvariable value

Returns

CssStyle

setVariable(variable): CssStyle

Set variable value

Parameters

Name Type Description
variableRecord<string, any> | Map<string, any>variable values

Returns

CssStyle


toString

toString(): string

Returns

string


updateTimeStamp

updateTimeStamp(silent?): CssStyle

Update time stamp to indicate that style has been changed.

Parameters

Name Type Description
Optional silentbooleansilent mode. If this parameter equals to true then style doesn't send invalidate event

Returns

CssStyle

this

Inherited from

Style.updateTimeStamp


fromObject

Static fromObject(object?): CssStyle

Create or get css style from object

Parameters

Name Type Description
Optional objectTypeobject can be in format of constructor of CssStyle

Returns

CssStyle

css style


getClassName

Static getClassName(): string

Returns

string

Inherited from

Style.getClassName


isStyleNotificationEnabled

Static isStyleNotificationEnabled(): boolean

Return status of the global notification for all styles.

Returns

boolean

Inherited from

Style.isStyleNotificationEnabled