From 7bb3d5d1850e0a6fde88dadfa8befb007632d021 Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Fri, 11 Apr 2014 19:45:49 +0000 Subject: [PATCH] wait for google maps to be loaded --- source/Ox.UI/js/Map/Map.js | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/source/Ox.UI/js/Map/Map.js b/source/Ox.UI/js/Map/Map.js index 793bb29a..2de70efe 100644 --- a/source/Ox.UI/js/Map/Map.js +++ b/source/Ox.UI/js/Map/Map.js @@ -714,14 +714,20 @@ Ox.Map = function(options, self) { } function getMapBounds(callback) { - // get initial map bounds - self.options.places({}, function(result) { - var area = result.data.area; - callback(new google.maps.LatLngBounds( - new google.maps.LatLng(area.south, area.west), - new google.maps.LatLng(area.north, area.east) - )); - }); + if (!self.loaded) { + setTimeout(function() { + getMapBounds(callback); + }, 100); + } else { + // get initial map bounds + self.options.places({}, function(result) { + var area = result.data.area; + callback(new google.maps.LatLngBounds( + new google.maps.LatLng(area.south, area.west), + new google.maps.LatLng(area.north, area.east) + )); + }); + } } function getMapHeight() { @@ -1426,7 +1432,13 @@ Ox.Map = function(options, self) { } function zoom(z) { - self.map.setZoom(self.map.getZoom() + z); + if (!self.loaded) { + setTimeout(function() { + zoom(z); + }, 100); + } else { + self.map.setZoom(self.map.getZoom() + z); + } } function zoomChanged() {