[英]marker click event not firing second time in google maps
我正在使用ui-gmap-google-map AngularJs指令和ui-gmap-marker对带有ng-repeat和单击事件的标记进行调用,该事件在控制器中调用了函数。 一切似乎都正常。 当我单击每个标记时,地图会为所有标记首次加载标记和标记单击触发。 但是,从第二次尝试对任何标记单击就不会触发click事件。
这是代码片段
<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>
.....'click'和'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();
};
您可能必须取消事件传播
ng-click="onMarkerClicked(); $event.stopPropagation()"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.