0

我用這libary建立在我的angularjs一個谷歌地圖(V 1.2.15)的webapp: https://angular-ui.github.io/angular-google-maps/#!/api/google-map設置dragend事件角谷歌,地圖

我的目標是捕獲事件當用戶用鼠標繪製地圖。我查了google maps API文檔,發現了dragend事件監聽器:https://developers.google.com/maps/documentation/javascript/reference#Map

我能初始化我的地圖,但由於某種原因,我的dragend事件監聽器不工作。 這裏是我初始化我的地圖與角谷歌 - 地圖libary:

angular.module('appMaps', ['uiGmapgoogle-maps']) 
    .controller('mainCtrl', function($scope, $log, $timeout) { 
    angular.extend($scope, { 
     map: { 
     center: { 
      latitude: 42.3349940452867, 
      longitude: -71.0353168884369 
     }, 
     zoom: 7, 
     events: { 
      dragend: function() { 
      alert('the map was dragged by the user') 
      } 
     }, 
     markers: [], 
     // .. 
     // .. 
    }); 
    }); 

這裏是我的plunkr這裏一切正常,除了dragend聽衆: http://plnkr.co/edit/AjnF4W5TB4cGSb59ete6?p=preview

回答

1

在您的例子dragend事件沒有得到因爲它沒有附加到地圖對象,所以被解僱。要重視事件,你需要利用地圖對象eventsui-gmap-google-map指令的屬性是這樣的:

<ui-gmap-google-map events="map.events" center="map.center" zoom="map.zoom" draggable="true" options="options"> 

其中

.controller('mainCtrl', function ($scope, $log, $timeout) { 
     angular.extend($scope, { 
      map: { 

       events: { 
        dragend: function() { 
         alert('dragend') 
        } 
       }, 
       //the remaining code is omitted for clarity 
      } 
     }); 
    }); 

Modified plunker

+1

感謝你解釋它完美。 – matyas