Skip to content

Commit 3522b08

Browse files
MaxWaldorfSean Eidemillerrsedevnet
authored
Add centered zoom ability (#23)
* Map stays roughly centered when zooming in and out. * Scroll compensation on zoom now happening in the same event loop. (#22) Fix flicker and better centering - Scroll compensation on zoom now happening in the same event loop (no flickering). - Removed vi swap files added accidentally. - Added .gitignore with vi swap files. --------- Co-authored-by: Sean Eidemiller <sean.eidemiller@oracle.com> --------- Co-authored-by: Sean Eidemiller <sean.eidemiller@oracle.com> Co-authored-by: Sean Eidemiller <157770408+rsedevnet@users.noreply.github.com>
1 parent 6b25571 commit 3522b08

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# vi swap files
2+
*.swo
3+
*.swp

common/scripts/map_actions.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1324,6 +1324,29 @@ function scaleView(zoom) {
13241324
var dim_str = dimension.toString() + "px";
13251325
var scale = properties.zoom / last_zoom;
13261326

1327+
var scroll_element = document.scrollingElement;
1328+
var scroll_top = scroll_element.scrollTop;
1329+
var scroll_left = scroll_element.scrollLeft;
1330+
var scroll_height = scroll_element.scrollHeight;
1331+
var scroll_width = scroll_element.scrollWidth;
1332+
var client_height = scroll_element.clientHeight;
1333+
var client_width = scroll_element.clientWidth;
1334+
var scroll_left_ratio = scroll_left / scroll_width;
1335+
var scroll_top_ratio = scroll_top / scroll_height;
1336+
var offset_right = scroll_width - (scroll_left + client_width);
1337+
var offset_bottom = scroll_height - (scroll_top + client_height);
1338+
1339+
scroll_element.scrollTop = scroll_height * scroll_top_ratio * scale;
1340+
scroll_element.scrollLeft = scroll_width * scroll_left_ratio * scale;
1341+
1342+
var new_offset_right = scroll_element.scrollWidth * scale - (scroll_element.scrollLeft + client_width);
1343+
var new_offset_bottom = scroll_element.scrollHeight * scale - (scroll_element.scrollTop + client_height);
1344+
var diff_right = offset_right - new_offset_right;
1345+
var diff_bottom = offset_bottom - new_offset_bottom;
1346+
1347+
scroll_element.scrollTop = scroll_element.scrollTop - (diff_bottom / 2) / 2;
1348+
scroll_element.scrollLeft = scroll_element.scrollLeft - (diff_right / 2) / 2;
1349+
13271350
var base_map = document.getElementById('map');
13281351
base_map.style.height = dim_str;
13291352
base_map.style.width = dim_str;

0 commit comments

Comments
 (0)