2015-09-06 72 views
0

我正在使用谷歌'空閒'事件監聽器來上傳地圖上的標記(使用angularjs)。我的代碼是停止谷歌地圖空閒事件監聽器

$scope.LoadSearchPropertyOnPortFolioSales = function (PropertyName) { 

if(PropertyName == ''){ 
google.maps.event.addListener(map, 'idle', function() { 
      var PropertyList = PropertyService.GetSearchPropertyForPortfolio($scope.PortfolioId, $scope.PropertyName, this.center.lat(), this.center.lng(), 0.005, 0.005); 
        PropertyList.then(function (pl) { 
         DrawPropertyOnPortFolioSale(pl.data, $scope.PropertyName); 
        }, 
      }); 
} 

else 
{ 
    //Stop event listener 
} 
} 

我希望事件偵聽器只有在傳遞的PropertyName沒有值時纔有效。但是當PropertyName有一些值時,我想停止事件監聽器。如何阻止事件監聽器......

回答

2

還有一個功能,刪除所有聽衆在同一時間:

clearListeners(instance:Object, eventName:string); 
//In your case: 
google.maps.event.clearListeners(map, 'idle'); 

Here's the Google Maps API reference在那裏你可以讀到它。