JSFiddle - React, Tailwind, and code Playground

by Beardy

JavaScript

$scope.markersArray.forEach(function(location, index) {

    google.maps.event.addListener(location, 'click', function() {

        function close(location) {
            location.iw.close();
            location.infoWindowVisible = false;
            location.iw = null;
        }

        if (location.infoWindowVisible === true) {
            close(location);
        } else {
            $scope.markersArray.forEach(function(loc, index) {
                if (angular.isDefined(loc.iw) && loc.iw !== null) {
                    close(loc);
                }
            });
            var html = "<div class='gm-iw' style='width:227px;'>" + generalService.CheckInfoWindow(location, $scope, 'title', 'div', 'gm-title') + "" + generalService.CheckInfoWindow(location, $scope, 'desc', 'div', 'gm-addr') + "" + generalService.CheckInfoWindow(location, $scope, 'tel', 'div', 'gm-phone') + "" + generalService.CheckInfoWindow(location, $scope, 'email', 'a', 'gm-website') + "" + generalService.CheckInfoWindow(location, $scope, 'web', 'a', 'gm-website') + "</div>";

            location.iw = new google.maps.InfoWindow({
                content: html
            });

            location.iw.open($rootScope.map, location);
            location.infoWindowVisible = true;
        }

    });
    if (location.iw) {
        google.maps.event.addListener(location.iw, "closeclick", function() {
            $scope.markersArray.forEach(function(loc, index) {
                if (angular.isDefined(loc.iw) && loc.iw !== null) {
                    close(loc);
                }
            });
        });
    }
});