function initMap() {
console.log('Google API Loaded');
}
jQuery(window).on("elementor/frontend/init", function () {
var PremiumMapsHandler = function ($scope, $) {
var $linkedCarouselWidget = null,
mapElement = $scope.find(".premium_maps_map_height"),
mapSettings = mapElement.data("settings"),
mapStyle = mapElement.data("style"),
premiumMapMarkers = [],
premiumMapPopups = [];
var checkGoogleMapsLoaded = setInterval(function () {
if (typeof google !== "undefined" &&
typeof google.maps !== "undefined" &&
typeof google.maps.Map === "function") {
clearInterval(checkGoogleMapsLoaded);
// Once Google API is loaded, trigger the maps handler.
setTimeout(function () {
triggerMap();
}, 150);
}
}, 100);
function triggerMap() {
if (mapSettings.loadScroll) {
var $closestSection = $scope.closest('.elementor-top-section, .e-con');
var eleObserver = new IntersectionObserver(function (entries) {
entries.forEach(function (entry) {
if (entry.isIntersecting) {
premiumMap = newMap(mapElement, mapSettings, mapStyle);
eleObserver.unobserve(entry.target); // to only excecute the callback func once.
}
});
}, {
rootMargin: '-70% 0px 0px 0px'
});
eleObserver.observe($closestSection[0]);
} else {
premiumMap = newMap(mapElement, mapSettings, mapStyle);
}
}
function newMap(map, settings, mapStyle) {
var scrollwheel = settings.scrollwheel,
streetViewControl = settings.streetViewControl,
fullscreenControl = settings.fullScreen,
zoomControl = settings.zoomControl,
mapTypeControl = settings.typeControl,
centerLat = JSON.parse(settings.centerlat),
centerLong = JSON.parse(settings.centerlong),
autoOpen = settings.automaticOpen,
hoverOpen = settings.hoverOpen,
hoverClose = settings.hoverClose,
args = {
mapId: settings.mapId || '',
zoom: settings["zoom"],
mapTypeId: settings["maptype"],
center: { lat: centerLat, lng: centerLong },
scrollwheel: scrollwheel,
streetViewControl: streetViewControl,
fullscreenControl: fullscreenControl,
zoomControl: zoomControl,
mapTypeControl: mapTypeControl,
styles: mapStyle
};
if ("yes" === mapSettings.drag)
args.gestureHandling = "none";
var markers = map.find(".premium-pin");
var map = new google.maps.Map(map[0], args);
//Show the maps when it's ready.
mapElement.removeClass('premium-addons__v-hidden');
map.markers = [];
$linkedCarouselWidget = settings.linkedCarouselId ? $("#" + settings.linkedCarouselId + " .premium-carousel-wrapper") : [];
// add markers
markers.each(function (index) {
addMarker(jQuery(this), map, autoOpen, hoverOpen, hoverClose, index, args.mapId);
});
if ($linkedCarouselWidget.length > 0) {
$linkedCarouselWidget.find(".premium-carousel-inner").on("afterChange", function (event, slick, currentSlide) {
premiumMapPopups.map(function (popup, index) {
popup.close();
});
if (premiumMapPopups[currentSlide])
premiumMapPopups[currentSlide].open(map, map.markers[currentSlide]);
});
}
if (mapSettings.cluster && window.markerClusterer && args.mapId) {
// Initialize MarkerClusterer
new markerClusterer.MarkerClusterer({
map: map,
markers: premiumMapMarkers,
renderer: {
render: function (options) {
var count = options.count;
var position = options.position;
var clusterIcon = document.createElement("div");
var iconSize = mapSettings.cluster_icon_size || 50;
var iconUrl = mapSettings.cluster_icon || "https://developers.google.com/maps/documentation/javascript/examples/markerclusterer/m1.png";
// Customize cluster icon appearance
clusterIcon.innerHTML =
'' +
'