I use Google Maps for AngularJS to put some markers with infoWindow. It can open infoWindow when a marker is clicked. But it cannot close the opened infoWindow when another marker is clicked.
<div id="map" ng-controller="MapCtrl">
<google-map
center="map.center"
zoom="map.zoom"
draggable="true"
dragging="map.dragging"
events="map.events"
control="map.control"
refresh="true">
<markers models="map.markers" coords="'self'" icon="'icon'" click="'onClicked'">
<windows show="'showWindow'" closeClick="'closeClick'" ng-cloak>
<img ng-non-bindable src="{{url}}" width="200px;" class="img-responsive" />
</windows>
</markers>
</google-map>
</div>
Here is the controller.js
var mapControllers = angular.module('mapControllers', ['google-maps']);
mapControllers.controller('MapCtrl', function($scope, $http) {
var onMarkerClicked = function (marker) {
_.each($scope.map.markers, function (mker) {
mker.showWindow = false;
});
$scope.$apply();
marker.showWindow = true;
};
$scope.map = {
current_marker: {},
control:{},
markers: [],
center: {
latitude: 35.4138,
longitude: 139.4505
},
zoom: 6,
dragging: true
};
$http.get('/v1/tweets').success(function(data) {
for (var i = 0; i < data.length; i++) {
var marker = {
latitude: data[i].lat,
longitude: data[i].lon,
text: data[i].text,
url: data[i].url,
icon: '/assets/flower.png',
showWindow: false
};
marker.closeClick = function () {
marker.showWindow = false;
$scope.$apply();
};
marker.onClicked = function () {
onMarkerClicked(marker);
};
$scope.map.markers.push(marker);
}
});
});
How can I change this code ?