我正在将loading_gif添加到我的Google地图中,并使用google.maps.event.addListener()确定何时完成地图加载,并更新变量以停止加载微调器。看起来一切都按预期进行,并且我看到变量已更新,但微调框仍然显示。
我的加载微调器:
<div style="position:absolute;z-index:99;top:85px;left:38%;" ng-if="mapLoader==0">
<p style="text-align:center;">
LOADING MAP...
<br><img style="height:100px;" ng-src="img/ajax_loading.gif">
</p>
</div>
应用程序启动,加载开始,地图在后台加载,但微调框永远不会消失。在控制台中,我看到所有控制台消息都已打印出来-包括表示地图已完成加载并设置$scope.mapLoader = 1
的消息,这将停止带有加载gif的DIV隐藏。
我的控制器:
.controller('MapCtrl', function($scope,$ionicModal,$ionicPopover,$ionicSlideBoxDelegate,$rootScope,$state,constants,apiService) {
$scope.mapLoader = 0 ;
$scope.mapTrigger = 0 ;
// recursive function to test for maps finished loading
//setMap is a global variable set elsewhere.
function checkLoader() {
console.log("CHECKING LOADER") ;
if ($scope.mapLoader == 0) {
if (setMap && $scope.mapTrigger == 0) {
$scope.mapTrigger = 1 ;
google.maps.event.addListenerOnce(setMap,'tilesloaded', (function() {
console.log("\tMAP LOADED") ; // These two successfully print out
$scope.mapLoader = 1 ; // this should stop the DIV from displaying.
console.log($scope.mapLoader) ; // These two successfully print out
})) ;
}
setTimeout(function() {
console.log("\tChecking Map") ;
checkLoader() ; // repeat function again
},500) ; // 1/2 second intervals
}
}
if ($scope.mapLoader == 0) {
checkLoader() ;
} else {
$scope.mapLoader = 1 ;
}
})
打印到控制台:
CHECKING LOADER
Checking Map
CHECKING LOADER
Checking Map
CHECKING LOADER
Checking Map
CHECKING LOADER
MAP LOADED
1
Checking Map
CHECKING LOADER