Fix zoom to anchor
This commit is contained in:
@@ -88,23 +88,13 @@ ol.Control.prototype.setResolution = function(map, resolution) {
|
|||||||
*/
|
*/
|
||||||
ol.Control.prototype.zoom = function(map, resolution, delta, opt_anchor) {
|
ol.Control.prototype.zoom = function(map, resolution, delta, opt_anchor) {
|
||||||
if (goog.isDefAndNotNull(opt_anchor)) {
|
if (goog.isDefAndNotNull(opt_anchor)) {
|
||||||
|
var anchor = opt_anchor;
|
||||||
var mapCenter = /** @type {!ol.Coordinate} */ map.getCenter();
|
var mapCenter = /** @type {!ol.Coordinate} */ map.getCenter();
|
||||||
var mapResolution = map.getResolution();
|
var mapResolution = map.getResolution();
|
||||||
resolution = this.constraints.resolution(resolution, delta);
|
resolution = this.constraints.resolution(resolution, delta);
|
||||||
var center;
|
var x = anchor.x - resolution * (anchor.x - mapCenter.x) / mapResolution;
|
||||||
if (resolution < mapResolution) {
|
var y = anchor.y - resolution * (anchor.y - mapCenter.y) / mapResolution;
|
||||||
center = opt_anchor.clone();
|
var center = new ol.Coordinate(x, y);
|
||||||
center.subtract(mapCenter);
|
|
||||||
center.scale(resolution / mapResolution);
|
|
||||||
center.add(mapCenter);
|
|
||||||
} else if (resolution == mapResolution) {
|
|
||||||
center = mapCenter;
|
|
||||||
} else {
|
|
||||||
center = mapCenter.clone();
|
|
||||||
center.subtract(opt_anchor);
|
|
||||||
center.scale(resolution / mapResolution);
|
|
||||||
center.add(opt_anchor);
|
|
||||||
}
|
|
||||||
center = this.constraints.center(center, resolution, ol.Coordinate.ZERO);
|
center = this.constraints.center(center, resolution, ol.Coordinate.ZERO);
|
||||||
map.withFrozenRendering(function() {
|
map.withFrozenRendering(function() {
|
||||||
map.setCenter(center);
|
map.setCenter(center);
|
||||||
|
|||||||
Reference in New Issue
Block a user