Move pixel/coordinate matrices into frame state, remove canRotate
This commit is contained in:
@@ -54,24 +54,6 @@ ol.renderer.Map = function(container, map) {
|
||||
*/
|
||||
this.viewPropertyListenerKey_ = null;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {goog.vec.Mat4.Number}
|
||||
*/
|
||||
this.coordinateToPixelMatrix_ = goog.vec.Mat4.createNumber();
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {goog.vec.Mat4.Number}
|
||||
*/
|
||||
this.pixelToCoordinateMatrix_ = goog.vec.Mat4.createNumber();
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {boolean}
|
||||
*/
|
||||
this.matricesDirty_ = true;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {Array.<number>}
|
||||
@@ -109,9 +91,35 @@ ol.renderer.Map.prototype.addLayer = function(layer) {
|
||||
|
||||
|
||||
/**
|
||||
* @return {boolean} Can rotate.
|
||||
* @param {ol.FrameState} frameState FrameState.
|
||||
* @protected
|
||||
*/
|
||||
ol.renderer.Map.prototype.canRotate = goog.functions.FALSE;
|
||||
ol.renderer.Map.prototype.calculateMatrices2D = function(frameState) {
|
||||
|
||||
var view2DState = frameState.view2DState;
|
||||
var coordinateToPixelMatrix = frameState.coordinateToPixelMatrix;
|
||||
|
||||
goog.vec.Mat4.makeIdentity(coordinateToPixelMatrix);
|
||||
goog.vec.Mat4.translate(coordinateToPixelMatrix,
|
||||
frameState.size.width / 2,
|
||||
frameState.size.height / 2,
|
||||
0);
|
||||
goog.vec.Mat4.scale(coordinateToPixelMatrix,
|
||||
1 / view2DState.resolution,
|
||||
-1 / view2DState.resolution,
|
||||
1);
|
||||
goog.vec.Mat4.rotateZ(coordinateToPixelMatrix,
|
||||
-view2DState.rotation);
|
||||
goog.vec.Mat4.translate(coordinateToPixelMatrix,
|
||||
-view2DState.center.x,
|
||||
-view2DState.center.y,
|
||||
0);
|
||||
|
||||
var inverted = goog.vec.Mat4.invert(
|
||||
coordinateToPixelMatrix, frameState.pixelToCoordinateMatrix);
|
||||
goog.asserts.assert(inverted);
|
||||
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
@@ -140,18 +148,6 @@ ol.renderer.Map.prototype.disposeInternal = function() {
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {ol.Pixel} pixel Pixel.
|
||||
* @return {ol.Coordinate} Coordinate.
|
||||
*/
|
||||
ol.renderer.Map.prototype.getCoordinateFromPixel = function(pixel) {
|
||||
this.updateMatrices_();
|
||||
var vec3 = [pixel.x, pixel.y, 0];
|
||||
goog.vec.Mat4.multVec3(this.pixelToCoordinateMatrix_, vec3, vec3);
|
||||
return new ol.Coordinate(vec3[0], vec3[1]);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {ol.layer.Layer} layer Layer.
|
||||
* @protected
|
||||
@@ -173,18 +169,6 @@ ol.renderer.Map.prototype.getMap = function() {
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {ol.Coordinate} coordinate Coordinate.
|
||||
* @return {ol.Pixel} Pixel.
|
||||
*/
|
||||
ol.renderer.Map.prototype.getPixelFromCoordinate = function(coordinate) {
|
||||
this.updateMatrices_();
|
||||
var vec3 = [coordinate.x, coordinate.y, 0];
|
||||
goog.vec.Mat4.multVec3(this.coordinateToPixelMatrix_, vec3, vec3);
|
||||
return new ol.Pixel(vec3[0], vec3[1]);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Handle background color changed.
|
||||
*/
|
||||
@@ -237,17 +221,13 @@ ol.renderer.Map.prototype.handleLayersRemove = function(collectionEvent) {
|
||||
/**
|
||||
* @protected
|
||||
*/
|
||||
ol.renderer.Map.prototype.handleViewPropertyChanged = function() {
|
||||
this.matricesDirty_ = true;
|
||||
};
|
||||
ol.renderer.Map.prototype.handleViewPropertyChanged = goog.nullFunction;
|
||||
|
||||
|
||||
/**
|
||||
* @protected
|
||||
*/
|
||||
ol.renderer.Map.prototype.handleSizeChanged = function() {
|
||||
this.matricesDirty_ = true;
|
||||
};
|
||||
ol.renderer.Map.prototype.handleSizeChanged = goog.nullFunction;
|
||||
|
||||
|
||||
/**
|
||||
@@ -310,45 +290,3 @@ ol.renderer.Map.prototype.setLayerRenderer = function(layer, layerRenderer) {
|
||||
goog.asserts.assert(!(key in this.layerRenderers));
|
||||
this.layerRenderers[key] = layerRenderer;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
ol.renderer.Map.prototype.updateMatrices_ = function() {
|
||||
|
||||
if (this.matricesDirty_) {
|
||||
|
||||
var map = this.map;
|
||||
var view = map.getView().getView2D();
|
||||
var center = /** @type {!ol.Coordinate} */ (view.getCenter());
|
||||
var resolution = /** @type {number} */ (view.getResolution());
|
||||
var rotation = view.getRotation();
|
||||
var size = /** @type {!ol.Size} */ (map.getSize());
|
||||
|
||||
goog.vec.Mat4.makeIdentity(this.coordinateToPixelMatrix_);
|
||||
goog.vec.Mat4.translate(this.coordinateToPixelMatrix_,
|
||||
size.width / 2,
|
||||
size.height / 2,
|
||||
0);
|
||||
goog.vec.Mat4.scale(this.coordinateToPixelMatrix_,
|
||||
1 / resolution,
|
||||
-1 / resolution,
|
||||
1);
|
||||
if (this.canRotate() && goog.isDef(rotation)) {
|
||||
goog.vec.Mat4.rotateZ(this.coordinateToPixelMatrix_, -rotation);
|
||||
}
|
||||
goog.vec.Mat4.translate(this.coordinateToPixelMatrix_,
|
||||
-center.x,
|
||||
-center.y,
|
||||
0);
|
||||
|
||||
var inverted = goog.vec.Mat4.invert(
|
||||
this.coordinateToPixelMatrix_, this.pixelToCoordinateMatrix_);
|
||||
goog.asserts.assert(inverted);
|
||||
|
||||
this.matricesDirty_ = false;
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user