Add ol.control.MousePosition.setProjection

This commit is contained in:
Frederic Junod
2013-05-06 11:46:48 +02:00
parent 153fea538a
commit 916dde0045
4 changed files with 36 additions and 23 deletions

View File

@@ -86,15 +86,9 @@ ol.control.MousePosition = function(opt_options) {
/**
* @private
* @type {ol.TransformFunction}
* @type {?ol.TransformFunction}
*/
this.transform_ = ol.proj.identityTransform;
/**
* @private
* @type {ol.Projection}
*/
this.renderedProjection_ = null;
this.transform_ = null;
/**
* @private
@@ -114,7 +108,10 @@ ol.control.MousePosition.prototype.handleMapPostrender = function(mapEvent) {
if (goog.isNull(frameState)) {
this.mapProjection_ = null;
} else {
this.mapProjection_ = frameState.view2DState.projection;
if (this.mapProjection_ != frameState.view2DState.projection) {
this.mapProjection_ = frameState.view2DState.projection;
this.transform_ = null;
}
}
this.updateHTML_(this.lastMouseMovePixel_);
};
@@ -160,6 +157,15 @@ ol.control.MousePosition.prototype.setMap = function(map) {
};
/**
* @param {ol.ProjectionLike} projection Projection.
*/
ol.control.MousePosition.prototype.setProjection = function(projection) {
this.projection_ = ol.proj.get(projection);
this.transform_ = null;
};
/**
* @param {?ol.Pixel} pixel Pixel.
* @private
@@ -167,14 +173,13 @@ ol.control.MousePosition.prototype.setMap = function(map) {
ol.control.MousePosition.prototype.updateHTML_ = function(pixel) {
var html = this.undefinedHTML_;
if (!goog.isNull(pixel)) {
if (this.renderedProjection_ != this.mapProjection_) {
if (goog.isNull(this.transform_)) {
if (!goog.isNull(this.projection_)) {
this.transform_ = ol.proj.getTransformFromProjections(
this.mapProjection_, this.projection_);
} else {
this.transform_ = ol.proj.identityTransform;
}
this.renderedProjection_ = this.mapProjection_;
}
var map = this.getMap();
var coordinate = map.getCoordinateFromPixel(pixel);