(function($) {
    $(window).on('elementor/frontend/init', function () {
        elementorFrontend.hooks.addAction('frontend/element_ready/ignition-google-maps.default', function($scope) {
            var $maps = $($scope).find('.ignition-google-map');

            $maps.each(function() {
                var $this = $(this);

                if ( typeof google === 'undefined' ) {
                    var map  =$this;
                    var text = map.data('error');
                    $(map.get(0)).after( text );
                }
        
                initMap();
                function initMap() {
                    var map = $this;
                    var lat = map.data('latitude');
                    var long = map.data('longitude');
                    var style = map.data('style');
                    var scroll = map.data('scroll');
                    var location = {lat: lat, lng: long};
                    var icon = map.data('icon');
                    var info = map.data('info');
                    var map = new google.maps.Map(document.getElementById(map.attr('id')), {
                        zoom: map.data('zoom'),
                        center: location,
                        scrollwheel: scroll,
                        draggable: scroll,
                        styles: style
                    });
                    var infowindow = new google.maps.InfoWindow({
                        content: info
                    });
                    var marker = new google.maps.Marker({
                        position: location,
                        icon: icon,
                        map: map
                    });
                    if ( info ) {
                        marker.addListener('click', function() {
                            infowindow.open(map, marker);
                        });
                    }
                }
            });

        });
    });
})( jQuery );