Last updated

API / geotoolkit / renderer / RenderingContext / RenderingContext

Class: RenderingContext

renderer.RenderingContext.RenderingContext

Represents context to traverse nodes during picking and rendering

Hierarchy

Table of contents

Constructors
Methods

Contents

Constructors

new RenderingContext(deviceUnit, filters)

Protected new RenderingContext(deviceUnit?, filters?)

Parameters

Name Type Description
Optional deviceUnitstring | AbstractUnitrepresent the {string} name, {string} symbol or {AbstractUnit} unit to be used as unit for device
Optional filters(IFilter | (node: Node, context?: RenderingContext) => boolean)[]an array of filters

Overrides

Graphics.constructor

Methods

addFilter

addFilter(filter): RenderingContext

Add filter to be applied

Parameters

Name Type Description
filterIFilterfilter to add

Returns

RenderingContext


arcTo

Abstract arcTo(x1, y1, x2, y2, radius): RenderingContext

Draws an arc to the target point as part of a path.

Parameters

Name Type Description
x1numbercoordinate of destination
y1numbercoordinate of destination
x2numbercoordinate
y2numbercoordinate
radiusnumberradius of arc

Returns

RenderingContext

this

Inherited from

Graphics.arcTo


beginPath

Abstract beginPath(): RenderingContext

Begin path

Returns

RenderingContext

this

Inherited from

Graphics.beginPath


beginRendering

beginRendering(): RenderingContext

Prepare rendering context. The default implementation blocks notifications from nodes and styles. if you call beginRendering then call the endRendering.

Returns

RenderingContext

this


bezierCurveTo

Abstract bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y): RenderingContext

Draws a cubic B\u00e9zier curve from the current point to the point (x, y), with control points (cp1x, cp1y) and (cp2x, cp2y).

Parameters

Name Type Description
cp1xnumberthe x coordinate of the first control point
cp1ynumberthe y coordinate of the first control point
cp2xnumberthe x coordinate of the second control point
cp2ynumberthe y coordinate of the second control point
xnumberthe x coordinate of the end point
ynumberthe y coordinate of the end point

Returns

RenderingContext

this

Inherited from

Graphics.bezierCurveTo


closePath

Abstract closePath(): RenderingContext

Do nothing if the context has no subpaths. Otherwise, it marks the last subpath as closed, create a new subpath whose first point is the same as the previous subpath's first point, and finally add this new subpath to the path.

Returns

RenderingContext

this

Inherited from

Graphics.closePath


createRenderingState

Abstract createRenderingState(): RenderingState

Creates rendering state

Returns

RenderingState

a new instance of the rendering state


createSurface

Abstract createSurface(width, height, devicePixel?): Surface

Creates a new surface

Parameters

Name Type Description
widthnumberwidth of surface
heightnumberheight of surface
Optional devicePixelbooleanIf set to true, width and height will be used as 'device' pixels.

Returns

Surface

a new instance of surface


drawAnnulusArc

Abstract drawAnnulusArc(x, y, innerRadius, outerRadius, startAngle, endAngle, sweepAngle?): RenderingContext

Draws a portion of an annulus clockwise ranging from startAngle to endAngle. If endAngle exceeds startAngle by Math.PI * 2 or more than annulus is drawn. Will fill in between the two arcs if fillStyle exists.

Parameters

Name Type Description
xnumberx-coordinate of the center of the arc.
ynumbery-coordinate of the center of the arc.
innerRadiusnumberinner radius of the arc
outerRadiusnumberouter radius of the arc
startAnglenumberangle in radians measured from x-axis to the starting point of the arc (clockwise means positive angle; counterclockwise - otherwise).
endAnglenumberAngle in radians measured from x-axis to ending point of the arc.
Optional sweepAnglenumberDefines the sweep of the arc

Returns

RenderingContext

this

Inherited from

Graphics.drawAnnulusArc


drawArc

Abstract drawArc(x, y, width, height, startAngle, endAngle, sweepAngle?, suppressLineToCenter?): RenderingContext

Draws an arc clockwise from startAngle to endAngle. If endAngle exceeds startAngle by Math.PI * 2 or more than ellipse is drawn. If fillStyle is not null, will fill the arc area using a direct line to close the path between start and end of arc. By default, this function renders a "pie" shape, using given fill and stroke style. In order to draw a real arc, set suppressLineToCenter=true.

Parameters

Name Type Description
xnumberx-coordinate of the upper-left corner of the rectangle that bounds the ellipse.
ynumbery-coordinate of the upper-left corner of the rectangle that bounds the ellipse.
widthnumberwidth of the rectangle that bounds the ellipse.
heightnumberheight of the rectangle that bounds the ellipse.
startAnglenumberangle in radians measured clockwise from positive x-axis to the starting point of the arc.
endAnglenumberAngle in radians measured clockwise from positive x-axis to the ending point of the arc.
Optional sweepAnglenumberDefines the sweep of the arc in radians. This parameter used if and only if startAngle == endAngle
Optional suppressLineToCenterbooleanDoes not draw lines from the edges of arc to center point

Returns

RenderingContext

this

Inherited from

Graphics.drawArc


drawEllipse

Abstract drawEllipse(x, y, width, height): RenderingContext

Draw and fill ellipse

Parameters

Name Type Description
xnumberx-coordinate of the upper-left corner of the bounding rectangle that defines the ellipse
ynumbery--coordinate of the upper-left corner of the bounding rectangle that defines the ellipse
widthnumberwidth of the bounding rectangle that defines the ellipse.
heightnumberheight of the bounding rectangle that defines the ellipse.

Returns

RenderingContext

this

Inherited from

Graphics.drawEllipse


drawImage

Abstract drawImage(image, srcX, srcY, srcW?, srcH?, dstX?, dstY?, dstW?, dstH?): RenderingContext

Draw an image onto the graphics context

Example

// Draw image can be used it the three different ways

// Provide only destination x and y
graphics.drawImage(image, dstX, dstY);
// Provide destination x and y and destination width and height
graphics.drawImage(image, dstX, dstY, dstW, dstW);
// Provide source x, y, width, height and destination x and y and destination width and height
graphics.drawImage(image, srcX, srcY, srcW, srcH, dstX, dstY, dstW, dstW);

Parameters

Name Type Description
imageSurface | IBaseImageimage to be rendered
srcXnumberThe x-axis coordinate of the top left corner of the sub-rectangle of the source image to draw into the destination context. Use the 7- or 9-argument syntax to use it as a source or the x-axis coordinate in the destination context at which to place the top-left corner of the source image. Use the 3- or 5-argument syntax to apply this argument as destination position.
srcYnumberThe y-axis coordinate of the top left corner of the sub-rectangle of the source image to draw into the destination context. Use the 7- or 9-argument syntax to use it as a source or the y-axis coordinate in the destination context at which to place the top-left corner of the source image. Use the 3- or 5-argument syntax to apply this argument as destination position.
Optional srcWnumbersource width if 7- or 9-argument is used or image width for other cases
Optional srcHnumbersource height if y-argument | image height for other cases
Optional dstXnumberdestination x position
Optional dstYnumberdestination y position
Optional dstWnumberdestination width This allows scaling of the drawn image. If not specified, the image is not scaled in height when drawn.
Optional dstHnumberdestination height. If not specified, the image is not scaled in height when drawn.

Returns

RenderingContext

this

Inherited from

Graphics.drawImage


drawLine

Abstract drawLine(x1, y1, x2, y2): RenderingContext

Draw line

Parameters

Name Type Description
x1numberx-position of start point
y1numbery-position of start point
x2numberx-position of end point
y2numbery-position of end point

Returns

RenderingContext

this

Inherited from

Graphics.drawLine


drawPath

drawPath(path): RenderingContext

Apply geometry on the rendering context. The method stroke must be called to draw path outlines or fillPath to fill the geometry

Parameters

Name Type Description
pathGraphicsPathpath to draw

Returns

RenderingContext

this

Inherited from

Graphics.drawPath


drawPolygon

Abstract drawPolygon(x, array, start?, end?): RenderingContext

Draw and fill polygon. If fill style is null then it draws outline only.

Parameters

Name Type Description
xnumber[]array of x coordinates of points
arraynumber[]of y coordinates of points
Optional startnumberindex of the first point in the array
Optional endnumberindex of the last point in the array

Returns

RenderingContext

this

Inherited from

Graphics.drawPolygon


drawPolyline

Abstract drawPolyline(x, y, start?, end?, multiDirection?): RenderingContext

Draw polyline

Parameters

Name Type Description
xnumber[]array of x coordinates of points
ynumber[]array of y coordinates of points
Optional startnumberindex of the first point in the array
Optional endnumberindex of the last point in the array
Optional multiDirectionbooleanfalse for one direction array

Returns

RenderingContext

this

Inherited from

Graphics.drawPolyline


drawRectangle

Abstract drawRectangle(x, y?, width?, height?): RenderingContext

Draw and fill rectangle with the current style. If fill style is null then it draws outline only.

Parameters

Name Type Description
xnumber | RectX coordinate of the start point
Optional ynumberY coordinate of the start point
Optional widthnumberWidth of rectangle
Optional heightnumberHeight of rectangle

Returns

RenderingContext

this

Inherited from

Graphics.drawRectangle


drawText

Abstract drawText(x, y, text): RenderingContext

Draw text

Parameters

Name Type Description
xnumberx anchor position
ynumbery anchor position
textstringtext to draw

Returns

RenderingContext

this

Inherited from

Graphics.drawText


endRendering

endRendering(): RenderingContext

End usage ot the rendering context

Returns

RenderingContext

this


fillPath

Abstract fillPath(): RenderingContext

Fill all the subpaths of the current path, using fillStyle, and using the non-zero winding number rule. Open subpaths will be implicitly closed when being filled (without affecting the actual subpaths).

Returns

RenderingContext

this

Inherited from

Graphics.fillPath


filter

filter(node): boolean

Filter node

Parameters

Name Type Description
nodeNodenode to be rendered

Returns

boolean


getContextAt

getContextAt(point): RenderingContext

Gets context with non-deviated transformation at the specified location. The base implementation returns itself.

Parameters

Name Type Description
pointPointpoint to get non-deviated context at

Returns

RenderingContext

context with non-deviated transformation


getDevicePathLength

getDevicePathLength(pt1, pt2): number

Gets path length in device space.
The default implementation returns straight distance between transformed points

Parameters

Name Type Description
pt1Pointfirst model point
pt2Pointsecond model point

Returns

number


getDeviceRect

Abstract getDeviceRect(): Rect

Gets rectangular area (defined in device space) to invalidate

Returns

Rect


getFilters

Protected getFilters(): (IFilter | (node: Node, context?: RenderingContext) => boolean)[]

Gets an array of filters

Returns

(IFilter | (node: Node, context?: RenderingContext) => boolean)[]


getGlobalAlpha

getGlobalAlpha(): number

Gets the alpha (transparency) value that is applied to shapes and images before they are drawn

Returns

number


getGlobalViewPort

getGlobalViewPort(): Rect

Gets "global" view port (defined in device space). The implementation calls for "this.getDeviceRect()"

Returns

Rect


getImageSmoothing

getImageSmoothing(): boolean

Return images smoothing enabled flag if context is supported. By default it returns false

Returns

boolean

enable enable or disable smoothing


getInverseTransformation

Abstract getInverseTransformation(): Transformation

Gets the current transformation, which defines transformation from device coordinates to model coordinates. Note, that inverse transformation can be calculated based on getTransformation() call (and vice versa).

Returns

Transformation


getModelArea

getModelArea(): Area

Returns model area (rect/polygon/etc) of current context.

Returns

Area


getModelRect

Abstract getModelRect(): Rect

Gets rectangular area (defined in model space) to invalidate. Note, that having called getTransformation() (or getInverseTransformation()) model rect can be calculated based on device rect (and vice versa).

Returns

Rect


getTransformation

Abstract getTransformation(): Transformation

Gets the current transformation, which defines transformation from model coordinates to device coordinates

Returns

Transformation


getTransformationAt

getTransformationAt(point): Transformation

Gets non-deviated transformation at the specified location. The base implementation returns "this.getTransformation()".

Parameters

Name Type Description
pointPointpoint to get the transformation

Returns

Transformation

the transformation


isPicking

Abstract isPicking(): this is SelectionContext

Return true if context is doing picking now

Returns

this is SelectionContext

true if this is picking context


lineTo

Abstract lineTo(x, y): RenderingContext

Draw line from the current position to the specified position

Parameters

Name Type Description
xnumberx position
ynumbery position

Returns

RenderingContext

this

Inherited from

Graphics.lineTo


measureLine

measureLine(lineStyle): number

Returns line dimension at the current context

Parameters

Name Type Description
lineStyleLineStylethe line style

Returns

number

the line width


measureText

Abstract measureText(text, textStyle?): TextMetrics

Return text metrics

Parameters

Name Type Description
textstringtext
Optional textStyleTextStylethe text style

Returns

TextMetrics

text metrics


moveTo

Abstract moveTo(x, y): RenderingContext

Move current position to x,y. Create a new subpath with the specified point as its first (and only) point.

Parameters

Name Type Description
xnumberx position
ynumbery position

Returns

RenderingContext

this

Inherited from

Graphics.moveTo


pushTransformation

Abstract pushTransformation(tr): RenderingContext

Creates a new context with concatenated transformation

Parameters

Name Type Description
trTransformationa transformation to concatenate

Returns

RenderingContext

a new context


removeFilter

removeFilter(filter): RenderingContext

Remove an instance of the filter

Parameters

Name Type Description
filterIFilterfilter to remove

Returns

RenderingContext


restore

Abstract restore(): RenderingContext

Restore current state

Returns

RenderingContext

this


save

Abstract save(): RenderingContext

Save the current state

Returns

RenderingContext

this


setClip

Abstract setClip(geometry, operation?, isModel?, evenOdd?): RenderingContext

Sets clipping

Parameters

Name Type Description
geometryRect | GraphicsPath | Regiongeometry to clip
Optional operationGeometryOperationoperation to be applied for a new clipping
Optional isModelbooleanmodel coordinates flag
Optional evenOddbooleanDefines if clipping to apply is even-odd

Returns

RenderingContext

this

Inherited from

Graphics.setClip


setCurrentNode

setCurrentNode(node): RenderingContext

Specify node to be rendered

Parameters

Name Type Description
nodeNodenode to be rendered

Returns

RenderingContext

this


setDeviceRect

Abstract setDeviceRect(rect): RenderingContext

Sets device rectangle area of interest

Parameters

Name Type
rectRect

Returns

RenderingContext

this


setFillPattern

Abstract setFillPattern(pattern): RenderingContext

Set fill pattern

Parameters

Name Type Description
patternPatternpattern to fill the area

Returns

RenderingContext

this

Inherited from

Graphics.setFillPattern


setFillStyle

Abstract setFillStyle(style, area?): RenderingContext

Set fill style

Parameters

Name Type Description
styleFillStylefill style
Optional areaRectarea

Returns

RenderingContext

this

Inherited from

Graphics.setFillStyle


setFilters

Protected setFilters(filters): RenderingContext

Sets an array of filters

Parameters

Name Type Description
filters(IFilter | (node: Node, context?: RenderingContext) => boolean)[]filters

Returns

RenderingContext


setGlobalAlpha

setGlobalAlpha(alpha, mode?): RenderingContext

Specifies the alpha (transparency) value that is applied to shapes and images before they are drawn

Parameters

Name Type Description
alphanumberA number between 0.0 (fully transparent) and 1.0 (fully opaque). Not all implementations can support it
Optional modeBlendModedefines mode to blend opacity

Returns

RenderingContext

this


setGlobalViewPort

setGlobalViewPort(globalViewPort): RenderingContext

Sets "global" view port (defined in device space) The implementation is empty

Parameters

Name Type Description
globalViewPortRect"global" view port

Returns

RenderingContext


setImageSmoothing

setImageSmoothing(enable): RenderingContext

Enable or disable image smoothing if context is supported determines whether scaled images are smoothed. When enlarging images, the default resizing algorithm will blur the pixels. Set this property to false to retain the pixels' sharpness. By default is ignored

Parameters

Name Type Description
enablebooleanenable or disable smoothing

Returns

RenderingContext

this


setLineStyle

Abstract setLineStyle(style, area?): RenderingContext

Set line style

Parameters

Name Type Description
styleLineStyle | GradientStylea line style
Optional areaRectarea to apply fill property of line style

Returns

RenderingContext

this

Inherited from

Graphics.setLineStyle


setModelRect

Abstract setModelRect(rect): RenderingContext

Sets model rectangle

Parameters

Name Type Description
rectRectmodel area of interest

Returns

RenderingContext

this


setTextStyle

Abstract setTextStyle(textStyle): RenderingContext

Set text style

Parameters

Name Type Description
textStyleTextStylestyle

Returns

RenderingContext

this

Inherited from

Graphics.setTextStyle


setTransformation

Abstract setTransformation(transformation): RenderingContext

Sets the current transformation, which defines transformation from model coordinates to device coordinates

Parameters

Name Type Description
transformationTransformationtransformation to be set

Returns

RenderingContext

this


stroke

Abstract stroke(): RenderingContext

Calculate the strokes of all the subpaths of the current path

Returns

RenderingContext

this

Inherited from

Graphics.stroke