QUESTION:
How can we render a feature to a canvas using a style but not using a map?
BACKGROUND:
I have a sample which renders a geometry to a canvas honoring the ol3 style but it only runs with the unbuilt version of openlayers (ol-debug.js) and because it makes use of private functions (ol.vec.Mat4).
One alternative is to create a map, add a vector layer, set the style on the feature, add the feature to the layer and remove all the events/controls from the map so it looks like a canvas.
A second is to use goog.vec.Mat4.
let scale = Math.min(canvas.width / ol.extent.getWidth(extent), canvas.height / ol.extent.getHeight(extent));
console.log("scale", scale);
let transform = Mat4.makeTransform2D(identity,
canvas.width / 2, canvas.height / 2, // translate to origin
scale, -scale, //scale
0, // rotation
-center[0], -center[1] // translate back
);
console.log("transform", transform);
let renderer = new ol.render.canvas.Immediate(ctx, 1, extent, transform, 1);
renderer.drawFeature(feature, style);
A third is similar to the second in that I take on the responsibility of transforming the geometry into pixel coordinates before using ol.render.toContext, as demonstrated in this example.
I think that about exhausts it? Or is there another way?
Doh! Found an example right on the openlayers site!
In that sample coordinates are already pixels:
But as the question indicates, translation -> scale -> translation transforms the data:
Here is my TRS logic: