Merge pull request #4523 from ahocevar/render-to-context

Allow rendering geometries to an arbitrary canvas
This commit is contained in:
Andreas Hocevar
2015-12-07 19:13:47 +01:00
6 changed files with 155 additions and 14 deletions

View File

@@ -0,0 +1,9 @@
---
layout: example.html
title: Render geometries to a canvas
shortdesc: Example of rendering geometries to an arbitrary canvas.
docs: >
This example shows how to render geometries to an arbitrary canvas.
tags: "render, geometry, canvas"
---
<canvas id="canvas"></canvas>

View File

@@ -0,0 +1,25 @@
goog.require('ol.geom.LineString');
goog.require('ol.geom.Point');
goog.require('ol.geom.Polygon');
goog.require('ol.render');
goog.require('ol.style.Circle');
goog.require('ol.style.Fill');
goog.require('ol.style.Stroke');
var canvas = document.getElementById('canvas');
var render = ol.render.toContext(canvas.getContext('2d'), {size: [100, 100]});
var fill = new ol.style.Fill({ color: 'blue' });
var stroke = new ol.style.Stroke({ color: 'black' });
render.setFillStrokeStyle(fill, stroke);
render.setImageStyle(new ol.style.Circle({
radius: 10,
fill: fill,
stroke: stroke
}));
render.drawLineStringGeometry(new ol.geom.LineString([[10, 10], [90, 90]]));
render.drawPolygonGeometry(
new ol.geom.Polygon([[[2, 2], [98, 2], [2, 98], [2, 2]]]));
render.drawPointGeometry(new ol.geom.Point([88, 88]));