Rotate map canvas after composition
This commit is contained in:
@@ -2,6 +2,44 @@
|
||||
|
||||
### v3.14.0
|
||||
|
||||
#### Layer pre-/postcompose event changes
|
||||
|
||||
It is the responsibility of the application to undo any canvas transform changes at the end of a layer 'precompose' or 'postcompose' handler. Previously, it was ok to set a null transform. The API now guarantees a device pixel coordinate system on the canvas with its origin in the top left corner of the map. However, applications should not rely on the underlying canvas being the same size as the visible viewport.
|
||||
|
||||
Old code:
|
||||
```js
|
||||
layer.on('precompose', function(e) {
|
||||
// rely on canvas dimensions to move coordinate origin to center
|
||||
e.context.translate(e.context.canvas.width / 2, e.context.canvas.height / 2);
|
||||
e.context.scale(3, 3);
|
||||
// draw an x in the center of the viewport
|
||||
e.context.moveTo(-20, -20);
|
||||
e.context.lineTo(20, 20);
|
||||
e.context.moveTo(-20, 20);
|
||||
e.context.lineTo(20, -20);
|
||||
// rely on the canvas having a null transform
|
||||
e.context.setTransform(1, 0, 0, 1, 0, 0);
|
||||
});
|
||||
```
|
||||
New code:
|
||||
```js
|
||||
layer.on('precompose', function(e) {
|
||||
// use map size and pixel ratio to move coordinate origin to center
|
||||
var size = map.getSize();
|
||||
var pixelRatio = e.frameState.pixelRatio;
|
||||
e.context.translate(size[0] / 2 * pixelRatio, size[1] / 2 * pixelRatio);
|
||||
e.context.scale(3, 3);
|
||||
// draw an x in the center of the viewport
|
||||
e.context.moveTo(-20, -20);
|
||||
e.context.lineTo(20, 20);
|
||||
e.context.moveTo(-20, 20);
|
||||
e.context.lineTo(20, -20);
|
||||
// undo all transforms
|
||||
e.context.scale(1 / 3, 1 / 3);
|
||||
e.context.translate(-size[0] / 2 * pixelRatio, -size[1] / 2 * pixelRatio);
|
||||
});
|
||||
```
|
||||
|
||||
### v3.13.0
|
||||
|
||||
#### `proj4js` integration
|
||||
|
||||
Reference in New Issue
Block a user