我正在使用Google的“空闲”事件监听器在地图上上传标记(使用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中有一些值时,我想停止事件监听器。我如何停止事件监听器……
最佳答案
还有一个函数可以同时删除所有侦听器:
clearListeners(instance:Object, eventName:string);
//In your case:
google.maps.event.clearListeners(map, 'idle');
Here's the Google Maps API reference 您可以在其中阅读有关内容的信息。