Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Smoother zooming out when resizing the map #198

Open
wants to merge 1 commit into from

2 participants

@lalinsky

When resizing the map, the viewport is currently moving to one size. That
means that if you have the map centered on some country, resize the map to
make it smaller, than resize it to the original size and you are centered
on a different country.

With this patch, it tries to keep the viewport at the same point, so that
resizing the map has little effect on what you see on the map.

@lalinsky lalinsky Smoother zooming out when resizing the map
When resizing the map, the viewport is currently moving to one size. That
means that if you have the map centered on some country, resize the map to
make it smaller, than resize it to the original size and you are centered
on a different country.

With this patch, it tries to keep the viewport at the same point, so that
resizing the map has little effect on what you see on the map.
2460640
@bjornd bjornd added this to the 2.0 milestone
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Apr 2, 2013
  1. @lalinsky

    Smoother zooming out when resizing the map

    lalinsky authored
    When resizing the map, the viewport is currently moving to one size. That
    means that if you have the map centered on some country, resize the map to
    make it smaller, than resize it to the original size and you are centered
    on a different country.
    
    With this patch, it tries to keep the viewport at the same point, so that
    resizing the map has little effect on what you see on the map.
This page is out of date. Refresh to see the latest.
Showing with 4 additions and 3 deletions.
  1. +4 −3 lib/world-map.js
View
7 lib/world-map.js
@@ -171,7 +171,7 @@ jvm.WorldMap.prototype = {
},
resize: function() {
- var curBaseScale = this.baseScale;
+ var curBaseScale = this.baseScale, curScale = this.scale, zoomStep;
if (this.width / this.height > this.defaultWidth / this.defaultHeight) {
this.baseScale = this.height / this.defaultHeight;
this.baseTransX = Math.abs(this.width - this.defaultWidth * this.baseScale) / (2 * this.baseScale);
@@ -180,8 +180,9 @@ jvm.WorldMap.prototype = {
this.baseTransY = Math.abs(this.height - this.defaultHeight * this.baseScale) / (2 * this.baseScale);
}
this.scale *= this.baseScale / curBaseScale;
- this.transX *= this.baseScale / curBaseScale;
- this.transY *= this.baseScale / curBaseScale;
+ zoomStep = this.scale / curScale;
+ this.transX -= (zoomStep - 1) / this.scale * (this.width / 2);
+ this.transY -= (zoomStep - 1) / this.scale * (this.height / 2);
},
/**
Something went wrong with that request. Please try again.