Skip to content

Commit

Permalink
Add listeners to close infowindow when another is opened (#628)
Browse files Browse the repository at this point in the history
  • Loading branch information
piercebb committed Jun 28, 2020
1 parent d5fee11 commit 6c95b14
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions app/javascript/packs/lib/maps.js.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const circleMarkerImage = "<%= helpers.image_path('marker-circle.png') %>";
const showMarkerImage = "<%= helpers.image_path('show-icon.png') %>";
let map;
let lastOpenedInfoWindow;
function initMap(x, y, image, draggable, callback){
image = typeof image !== 'undefined' ? image : currentLocationImage;
Expand Down Expand Up @@ -81,8 +82,20 @@ function placeMarker(lat, lng, content, number){
});

marker.addListener('click', function() {
closeLastOpenedInfoWindow();
infoWindow.open(map, marker);
lastOpenedInfoWindow = infoWindow;
});

google.maps.event.addListener(map, 'click', function(event) {
infoWindow.close();
});
}

function closeLastOpenedInfoWindow() {
if (lastOpenedInfoWindow) {
lastOpenedInfoWindow.close();
}
}

function generateContent(data){
Expand Down

0 comments on commit 6c95b14

Please sign in to comment.