Skip to content
This repository

Smoother zooming out when resizing the map #198

Open
wants to merge 1 commit into from

1 participant

Lukáš Lalinský
Lukáš Lalinský

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.

Lukáš Lalinský 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Apr 02, 2013
Lukáš Lalinský 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
This page is out of date. Refresh to see the latest.

Showing 1 changed file with 4 additions and 3 deletions. Show diff stats Hide diff stats

  1. 7  lib/world-map.js
7  lib/world-map.js
@@ -171,7 +171,7 @@ jvm.WorldMap.prototype = {
171 171
   },
172 172
 
173 173
   resize: function() {
174  
-    var curBaseScale = this.baseScale;
  174
+    var curBaseScale = this.baseScale, curScale = this.scale, zoomStep;
175 175
     if (this.width / this.height > this.defaultWidth / this.defaultHeight) {
176 176
       this.baseScale = this.height / this.defaultHeight;
177 177
       this.baseTransX = Math.abs(this.width - this.defaultWidth * this.baseScale) / (2 * this.baseScale);
@@ -180,8 +180,9 @@ jvm.WorldMap.prototype = {
180 180
       this.baseTransY = Math.abs(this.height - this.defaultHeight * this.baseScale) / (2 * this.baseScale);
181 181
     }
182 182
     this.scale *= this.baseScale / curBaseScale;
183  
-    this.transX *= this.baseScale / curBaseScale;
184  
-    this.transY *= this.baseScale / curBaseScale;
  183
+    zoomStep = this.scale / curScale;
  184
+    this.transX -= (zoomStep - 1) / this.scale * (this.width / 2);
  185
+    this.transY -= (zoomStep - 1) / this.scale * (this.height / 2);
185 186
   },
186 187
 
187 188
   /**
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.