Adding Loc.add method.
This commit is contained in:
@@ -120,6 +120,22 @@ ol.Loc.prototype.doTransform = function(proj) {
|
|||||||
return new ol.Loc(point['x'], point['y'], this.z_, proj);
|
return new ol.Loc(point['x'], point['y'], this.z_, proj);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds the passed x, y(, z) delta to a new location.
|
||||||
|
*
|
||||||
|
* @param {number} x
|
||||||
|
* @param {number} y
|
||||||
|
* @param {number=} opt_z
|
||||||
|
* @returns {ol.Loc}
|
||||||
|
*/
|
||||||
|
ol.Loc.prototype.add = function(x, y, opt_z) {
|
||||||
|
var newZ;
|
||||||
|
if (goog.isDef(this.z_)) {
|
||||||
|
newZ = (opt_z || 0) + this.z_;
|
||||||
|
}
|
||||||
|
return new ol.Loc(this.x_ + x, this.y_ + y, newZ, this.projection_);
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Clean up.
|
* Clean up.
|
||||||
* @export
|
* @export
|
||||||
|
|||||||
@@ -327,10 +327,9 @@ ol.Map.prototype.setZoom = function(zoom, opt_anchor) {
|
|||||||
var size = this.getSize(),
|
var size = this.getSize(),
|
||||||
anchorLoc = this.getLocForPixel(opt_anchor),
|
anchorLoc = this.getLocForPixel(opt_anchor),
|
||||||
newRes = this.getResolutionForZoom(newZoom);
|
newRes = this.getResolutionForZoom(newZoom);
|
||||||
newCenter = new ol.Loc(
|
newCenter = anchorLoc.add(
|
||||||
anchorLoc.getX() + (size.width/2 - opt_anchor.x) * newRes,
|
(size.width/2 - opt_anchor.x) * newRes,
|
||||||
anchorLoc.getY() - (size.height/2 - opt_anchor.y) * newRes,
|
(opt_anchor.y - size.height/2) * newRes
|
||||||
undefined, this.getProjection()
|
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
newCenter = this.center_;
|
newCenter = this.center_;
|
||||||
|
|||||||
@@ -89,10 +89,9 @@ ol.renderer.MapRenderer.prototype.getLocForPixel = function(pixel) {
|
|||||||
var center = this.renderedCenter_,
|
var center = this.renderedCenter_,
|
||||||
resolution = this.renderedResolution_,
|
resolution = this.renderedResolution_,
|
||||||
size = goog.style.getSize(this.container_);
|
size = goog.style.getSize(this.container_);
|
||||||
return new ol.Loc(
|
return center.add(
|
||||||
center.getX() - (size.width/2 - pixel.x)*resolution,
|
(pixel.x - size.width/2) * resolution,
|
||||||
center.getY() + (size.height/2 - pixel.y)*resolution,
|
(size.height/2 - pixel.y) * resolution
|
||||||
undefined, this.renderedCenter_.getProjection()
|
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user