Classes
Namespaces
Methods
-
ol.render.toContext(context, opt_options){ol.render.canvas.Immediate} experimental
src/ol/render.js, line 31 -
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.
var canvas = document.createElement('canvas'); var render = ol.render.toContext(canvas.getContext('2d'), { size: [100, 100] }); render.setFillStrokeStyle(new ol.style.Fill({ color: blue })); render.drawPolygonGeometry( new ol.geom.Polygon([[[0, 0], [100, 100], [100, 0], [0, 0]]]));
Note that
ol.render.canvas.Immediate#drawAsync
andol.render.canvas.Immediate#drawFeature
cannot be used.Name Type Description context
CanvasRenderingContext2D Canvas context.
options
Options.
Name Type Description size
ol.Size | undefined experimental 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
ol.Size | undefined experimental Pixel ratio (canvas pixel to css pixel ratio) for the canvas. Default is the detected device pixel ratio.
Returns:
Canvas Immediate.