0

我正在使用ui-gmap-google-map AngularJs指令和ui-gmap-marker用ng-repeat和click事件調用控制器中的函數。 一切似乎工作。當我點擊每個標記時,Map首次加載標記和標記,點擊所有標記。但從第二次嘗試任何點擊標記不會觸發點擊事件。標記點擊事件不在谷歌地圖中第二次發射

以下是代碼片段

<ui-gmap-google-map center="map.center" zoom="map.zoom"> 
    <!--<ui-gmap-markers models="map.markers" fit="true" coords="'self'" icon="'icon'" idkey="map.marker.id" click="selectMarker()">--> 
    <ui-gmap-markers models="map.markers" fit="true" coords="'self'" icon="'icon'" idkey='m.id'> 
     <ui-gmap-marker ng-repeat="m in map.markers" coords="m" icon="m.icon" ng-click='onMarkerClicked(m.sequenceId)' idkey='m.id'> 

     </ui-gmap-marker> 
    </ui-gmap-markers> 
</ui-gmap-google-map> 

.....用於 '點擊' 和 'NG-click' 事件 相同的結果..

$scope.generateMarkers = function (referencePoints) { 
      $scope.map.markers.length = 0; 
      //var bounds = new google.maps.LatLngBounds(); 
      for (i = 0; i < referencePoints.length; i++) { 
       var record = referencePoints[i]; 
       var marker = { 
        latitude: record.Lat, 
        longitude: record.Long, 
        title: record.RoadName, 
        id: record.ID, 
        icon: { url: '/content/images/roundcyan.png' },//pin_url(record.ID)// 
        sequenceId:i 
       }; 
       //var position = new google.maps.LatLng(record.Lat,record.Long); 
       //bounds.extend(position); 
       $scope.map.markers.push(marker); 
      } 
      //$scope.map.fitBounds(bounds); 

     }; 

.... ..

$scope.onMarkerClicked = function (sequenceId) { 
    if ($scope.selectedSequenceId >=0) { 
     $scope.map.markers[$scope.selectedSequenceId].icon = { url: 'http://localhost:xxxxx/content/images/roundcyan.png' }; 
    } 
    $scope.selectedSequenceId = sequenceId; 
    $scope.map.markers[sequenceId].icon = { url: 'http://localhost:xxxxx/content/images/roundcyanplus.png' }; 
    $scope.$apply(); 
}; 
+0

使用的版本是;版本:AngularJS v1.2.8,angular-google-maps 2.1.0 – Hasteq

+0

你的'sequenceId'有問題我猜測。看看是否把'sequenceId:i ++'放在'ng-click'中解決它。 – KayAnn

回答

0

你可能要取消該事件傳播

ng-click="onMarkerClicked(); $event.stopPropagation()" 
+0

要麼在函數之前,要麼像我在例子中給出的那樣 –

相關問題