Skip to content

Commit 123675d

Browse files
Fix lack of map refocus on window orientation / size change.
Added on window resize event to initMap function to refocus map contents when browser size changes or user switches from portrait to landscape mode on a mobile / tablet device.
1 parent 6bcea33 commit 123675d

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

static/js/on_load.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
// Put here code required to be present before DOM is loaded (for map generation so far).
2+
// Please note that locations variable is a global variable generated using Liquid.
3+
// See locations_variable_generator.html to check how it is constructed.
24

35
function initMap() {
46
var infowindow = new google.maps.InfoWindow();
@@ -41,11 +43,16 @@ function initMap() {
4143
}
4244
);
4345
}
46+
function focusMap() {
47+
map.fitBounds(bounds);
48+
}
49+
4450
if (locations.length === 1) {
4551
var latLng = marker.getPosition();
4652
map.setCenter(latLng);
4753
map.zoom = 17;
4854
} else {
49-
map.fitBounds(bounds);
55+
focusMap();
5056
}
51-
}
57+
window.addEventListener("resize", focusMap);
58+
}

0 commit comments

Comments
 (0)