Methods
-
module:ol/render.toContext(context, opt_options){module:ol/render/canvas/Immediate~CanvasImmediateRenderer}
render.js, line 65 -
Binds a Canvas Immediate API to a canvas context, to allow drawing geometries to the context's canvas.
The units for geometry coordinates are css pixels relative to the top left corner of the canvas element.
import {toContext} from 'ol/render'; import Fill from 'ol/style/Fill'; import Polygon from 'ol/geom/Polygon'; var canvas = document.createElement('canvas'); var render = toContext(canvas.getContext('2d'), { size: [100, 100] }); render.setFillStrokeStyle(new Fill({ color: blue })); render.drawPolygon( new Polygon([[[0, 0], [100, 100], [100, 0], [0, 0]]]));
Name Type Description context
CanvasRenderingContext2D Canvas context.
options
Options.
Name Type Default Description size
module:ol/size~Size Desired size of the canvas in css pixels. When provided, both canvas and css size will be set according to the
pixelRatio
. If not provided, the current canvas and css sizes will not be altered.pixelRatio
number window.devicePixelRatio Pixel ratio (canvas pixel to css pixel ratio) for the canvas.
Returns:
Canvas Immediate.
Type Definitions
-
OrderFunction()
render.js, line 21 -
A function to be used when sorting features before rendering. It takes two instances of
module:ol/Feature
ormodule:ol/render/Feature
and returns a{number}
. -
State{Object}
-
Properties:
Name Type Description context
CanvasRenderingContext2D Canvas context that the layer is being rendered to.
feature
module:ol/Feature~FeatureLike geometry
module:ol/geom/SimpleGeometry~SimpleGeometry pixelRatio
number Pixel ratio used by the layer renderer.
resolution
number Resolution that the render batch was created and optimized for. This is not the view's resolution that is being rendered.
rotation
number Rotation of the rendered layer in radians.
-
ToContextOptions{Object}
-
Properties:
Name Type Argument Default Description size
module:ol/size~Size <optional>
Desired size of the canvas in css pixels. When provided, both canvas and css size will be set according to the
pixelRatio
. If not provided, the current canvas and css sizes will not be altered.pixelRatio
number <optional>
window.devicePixelRatio Pixel ratio (canvas pixel to css pixel ratio) for the canvas.