Add rotation infrastructure

This commit is contained in:
Tom Payne
2012-07-29 16:58:08 +02:00
parent f9aa8d2e6c
commit 9f3c02757d
+50 -2
View File
@@ -3,7 +3,6 @@
// FIXME add change resolution by zoom step function // FIXME add change resolution by zoom step function
// FIXME recheck layer/map projection compatability when projection changes // FIXME recheck layer/map projection compatability when projection changes
// FIXME layer renderers should skip when they can't reproject // FIXME layer renderers should skip when they can't reproject
// FIXME add rotation
// FIXME add tilt and height? // FIXME add tilt and height?
// FIXME split out renderer // FIXME split out renderer
// FIXME add renderer selection strategy // FIXME add renderer selection strategy
@@ -22,6 +21,7 @@ goog.require('goog.events.KeyHandler.EventType');
goog.require('goog.events.MouseWheelEvent'); goog.require('goog.events.MouseWheelEvent');
goog.require('goog.events.MouseWheelHandler'); goog.require('goog.events.MouseWheelHandler');
goog.require('goog.events.MouseWheelHandler.EventType'); goog.require('goog.events.MouseWheelHandler.EventType');
goog.require('goog.functions');
goog.require('goog.fx.DragEvent'); goog.require('goog.fx.DragEvent');
goog.require('goog.fx.Dragger'); goog.require('goog.fx.Dragger');
goog.require('goog.fx.anim'); goog.require('goog.fx.anim');
@@ -244,6 +244,12 @@ ol.Map.prototype.animate_ = function() {
}; };
/**
* @return {boolean} Can rotate.
*/
ol.Map.prototype.canRotate = goog.functions.FALSE;
/** /**
* @param {ol.Layer} layer Layer. * @param {ol.Layer} layer Layer.
* @protected * @protected
@@ -270,6 +276,9 @@ ol.Map.prototype.fitExtent = function(extent) {
this.withFrozenRendering(function() { this.withFrozenRendering(function() {
this.setCenter(extent.getCenter()); this.setCenter(extent.getCenter());
this.setResolution(this.getResolutionForExtent(extent)); this.setResolution(this.getResolutionForExtent(extent));
if (this.canRotate()) {
this.setRotation(0);
}
}, this); }, this);
}; };
@@ -434,6 +443,31 @@ ol.Map.prototype.getResolutionForExtent = function(extent) {
}; };
/**
* @return {ol.Extent} Rotated extent.
*/
ol.Map.prototype.getRotatedExtent = function() {
goog.asserts.assert(this.isDef());
var center = /** @type {!ol.Coordinate} */ this.getCenter();
var resolution = this.getResolution();
var rotation = this.getRotation() || 0;
var size = this.getSize();
var xScale = resolution * size.width / 2;
var yScale = resolution * size.height / 2;
var corners = [
new ol.Coordinate(-xScale, -yScale),
new ol.Coordinate(-xScale, yScale),
new ol.Coordinate(xScale, -yScale),
new ol.Coordinate(xScale, yScale)
];
goog.array.forEach(corners, function(corner) {
corner.rotate(rotation);
corner.add(center);
});
return ol.Extent.boundingExtent.apply(null, corners);
};
/** /**
* @return {number|undefined} Rotation. * @return {number|undefined} Rotation.
*/ */
@@ -797,7 +831,7 @@ ol.Map.prototype.setResolution = function(resolution) {
/** /**
* @param {number} rotation Rotation. * @param {number|undefined} rotation Rotation.
*/ */
ol.Map.prototype.setRotation = function(rotation) { ol.Map.prototype.setRotation = function(rotation) {
this.set(ol.MapProperty.ROTATION, rotation); this.set(ol.MapProperty.ROTATION, rotation);
@@ -860,6 +894,13 @@ ol.Map.prototype.updateMatrices_ = function() {
1 / resolution, 1 / resolution,
-1 / resolution, -1 / resolution,
1); 1);
if (this.canRotate() && goog.isDef(rotation)) {
goog.vec.Mat4.rotate(this.coordinateToPixelMatrix_,
rotation,
0,
0,
1);
}
goog.vec.Mat4.translate(this.coordinateToPixelMatrix_, goog.vec.Mat4.translate(this.coordinateToPixelMatrix_,
-center.x, -center.x,
-center.y, -center.y,
@@ -870,6 +911,13 @@ ol.Map.prototype.updateMatrices_ = function() {
center.x, center.x,
center.y, center.y,
0); 0);
if (this.canRotate() && goog.isDef(rotation)) {
goog.vec.Mat4.rotate(this.coordinateToPixelMatrix_,
-rotation,
0,
0,
1);
}
goog.vec.Mat4.scale(this.pixelToCoordinateMatrix_, goog.vec.Mat4.scale(this.pixelToCoordinateMatrix_,
resolution, resolution,
-resolution, -resolution,