{"version":3,"sources":["google-maps.js"],"names":["mapApiLoaded","mapApiLoading","mapScrollHandler","throttleDebounce","throttle","cash","isInViewport","loadMapsApi","window","off","tag","document","createElement","firstScriptTag","getElementsByTagName","console","warn","src","instant","settings","googleApiKeyFrontend","parentNode","insertBefore","on","mapElement","map","markers","bounds","geocoder","searchBoxInput","searchBox","searchMarker","getLatLng","location","lat","getValueAsFloat","attr","lng","getZoomAttr","parseInt","getBoolDataValue","attrName","JSON","parse","toLowerCase","getMapStyles","findClosestMapPin","address","log","reduce","previous","current","google","maps","geometry","spherical","computeDistanceBetween","position","createSearchMarker","searchAddress","setMap","Marker","title","formatted_address","setBoundsAndCenterMap","arguments","length","LatLngBounds","i","extend","fitBounds","setCenter","getCenter","initMap","mapElements","allMaps","Geocoder","places","SearchBox","addListener","getPlaces","closestAddress","infoBubble","InfoBubble","minWidth","maxWidth","minHeight","padding","shadowStyle","backgroundColor","undefined","borderRadius","arrowSize","borderWidth","borderColor","disableAutoPan","hideCloseButton","closeSrc","arrowPosition","each","this","locations","find","multipleLocations","cluster","interactive","mapOptions","zoom","draggable","zoomControl","scrollwheel","streetViewControl","disableDoubleClickZoom","mapTypeControl","styles","center","Map","push","name","latLng","LatLng","marker","url","isOpen","get","close","setContent","html","open","event","href","MarkerClusterer","textColor","height","width","data","backgroundPosition","listener","currentZoom","getZoom","setZoom","removeListener","size","getDiv","offsetWidth","offsetHeight","join","addListenerOnce","setValues","_center","trigger","val","geocode","results","status","GeocoderStatus","OK","toast","show","navigator","geolocation","getCurrentPosition","coords","latitude","longitude","x","innerHTML"],"mappings":";AAEA,IAAIA,cAAe,EACjBC,eAAgB,EAChBC,iBAAmBC,iBAAiBC,SAAS,KAAK,WAC3CJ,cAAiBC,gBAAiBI,KAAK,eAAeC,aAAa,MACtEC,iBAYN,SAASA,cACP,IAAKP,eAAiBC,cAAe,CAEnCI,KAAKG,QAAQC,IAAI,SAAUP,kBAE3B,IAAIQ,EAAMC,SAASC,cAAc,UAC/BC,EA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rB","file":"../google-maps.min.js","sourcesContent":["/*! dependencies: infobubble, google-map-cluster */\r\n\r\nvar mapApiLoaded = false,\r\n mapApiLoading = false,\r\n mapScrollHandler = throttleDebounce.throttle(350, function () {\r\n if (!mapApiLoaded && !mapApiLoading && cash('.google-map').isInViewport(500)) {\r\n loadMapsApi();\r\n };\r\n });\r\n\r\n\r\ncash(window).on('load', function () {\r\n //if (!mapApiLoaded && !mapApiLoading && cash('.google-map').isInViewport(0)) {\r\n if (!mapApiLoaded && !mapApiLoading) {\r\n loadMapsApi();\r\n }\r\n});\r\n\r\nfunction loadMapsApi() {\r\n if (!mapApiLoaded && !mapApiLoading) {\r\n\r\n cash(window).off('scroll', mapScrollHandler);\r\n\r\n var tag = document.createElement('script'),\r\n firstScriptTag = document.getElementsByTagName('script')[0];\r\n\r\n console.warn('REMINDER for Tea Solutions developers - Create an API key for google maps in the google developers console: https://console.developers.google.com. Add all the domains, test domains and local domains')\r\n tag.src = 'https://maps.googleapis.com/maps/api/js?key=' + instant.settings.googleApiKeyFrontend + '&callback=initMap&libraries=places,geometry';\r\n firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);\r\n\r\n mapApiLoading = true;\r\n }\r\n}\r\n\r\nvar mapElement = null,\r\n map = null,\r\n markers = [],\r\n bounds = null,\r\n geocoder = null,\r\n searchBoxInput = null,\r\n searchBox = null,\r\n searchMarker = null;\r\n\r\nwindow.initMap = function () {\r\n mapApiLoaded = true;\r\n mapApiLoading = false;\r\n mapElements = cash('.google-map'), allMaps = [];\r\n geocoder = new google.maps.Geocoder();\r\n\r\n searchBoxInput = cash('#search-location-input')[0];\r\n searchBox = new google.maps.places.SearchBox(searchBoxInput);\r\n\r\n searchBox.addListener(\"places_changed\", () => {\r\n var searchAddress = searchBox.getPlaces()[0];\r\n var closestAddress = findClosestMapPin(searchAddress, markers);\r\n\r\n createSearchMarker(searchAddress);\r\n\r\n setBoundsAndCenterMap(searchAddress.geometry.location, closestAddress.position);\r\n });\r\n\r\n if (mapElements[0]) {\r\n var infoBubble = new InfoBubble({\r\n minWidth: 200,\r\n maxWidth: 300,\r\n minHeight: 150,\r\n padding: 15,\r\n shadowStyle: 3,\r\n backgroundColor: undefined,\r\n borderRadius: 7,\r\n arrowSize: 10,\r\n borderWidth: 1,\r\n borderColor: undefined,\r\n disableAutoPan: false,\r\n hideCloseButton: false,\r\n closeSrc: '/images/icons/close-cross.webp',\r\n arrowPosition: 50,\r\n });\r\n\r\n mapElements.each(function () {\r\n var mapElement = this,\r\n locations = cash(mapElement).find('[data-lat][data-lng]'),\r\n multipleLocations = (locations.length > 1),\r\n cluster = getBoolDataValue(mapElement, 'data-cluster'),\r\n interactive = getBoolDataValue(mapElement, 'data-interactive');\r\n\r\n if (multipleLocations) {\r\n bounds = new google.maps.LatLngBounds();\r\n }\r\n\r\n var mapOptions = {\r\n zoom: getZoomAttr(mapElement),\r\n draggable: interactive,\r\n zoomControl: interactive,\r\n scrollwheel: interactive ? undefined : interactive,\r\n streetViewControl: false,\r\n disableDoubleClickZoom: true,\r\n mapTypeControl: false,\r\n styles: getMapStyles()\r\n };\r\n\r\n if (!multipleLocations) {\r\n mapOptions.center = getLatLng(cash(locations[0]));\r\n }\r\n\r\n map = new google.maps.Map(mapElement, mapOptions);\r\n allMaps.push(map);\r\n\r\n locations.each(function () {\r\n var location = cash(this),\r\n name = location.attr('data-name'),\r\n latLng = new google.maps.LatLng(getLatLng(location)),\r\n marker = new google.maps.Marker({\r\n position: latLng,\r\n map: map,\r\n title: name,\r\n url: location.attr('data-url')\r\n });\r\n\r\n markers.push(marker);\r\n\r\n if (getBoolDataValue(mapElement, 'data-hideInfobox') == false) {\r\n marker.addListener('click', function () {\r\n if (!infoBubble.isOpen() || infoBubble.get('anchor') == marker) {\r\n infoBubble.setContent(location.html());\r\n infoBubble.open(map, marker);\r\n } else {\r\n infoBubble.close();\r\n }\r\n });\r\n } else if (marker.url) {\r\n google.maps.event.addListener(marker, 'click', function () {\r\n window.location.href = this.url;\r\n });\r\n }\r\n\r\n if (multipleLocations) {\r\n bounds.extend(latLng);\r\n }\r\n });\r\n\r\n if (cluster) {\r\n new MarkerClusterer(map, markers, {\r\n styles: [\r\n { textColor: 'white', height: 45, width: 45, url: cash(mapElement).data('cluster-icon'), backgroundPosition: 'center center' }\r\n ]\r\n });\r\n }\r\n\r\n if (multipleLocations) {\r\n map.fitBounds(bounds);\r\n //Set zoom level after fitBounds if zoom is lower than fitBounds' zoom level.\r\n var listener = google.maps.event.addListener(map, \"idle\", function () {\r\n var currentZoom = map.getZoom();\r\n var zoom = getZoomAttr(mapElement)\r\n if (zoom != 0 && currentZoom > zoom) {\r\n map.setZoom(zoom);\r\n }\r\n google.maps.event.removeListener(listener);\r\n });\r\n\r\n cash(window).on('resize', function () {\r\n var listener = google.maps.event.addListener(map, \"idle\", function () {\r\n map.fitBounds(bounds);\r\n google.maps.event.removeListener(listener);\r\n });\r\n });\r\n } else {\r\n google.maps.event.addListener(map, 'center_changed', function () {\r\n //a value to determine whether the map has been resized\r\n var size = [this.getDiv().offsetWidth, this.getDiv().offsetHeight].join('x');\r\n\r\n //when the center has changed, but not the size of the map\r\n if (!this.get('size') || size === this.get('size')) {\r\n this.setValues({ size: size, _center: this.getCenter() });\r\n }\r\n //when the map has been resized\r\n else {\r\n google.maps.event.addListenerOnce(this, 'idle', function () {\r\n this.setValues({ size: size, center: this.get('_center') });\r\n });\r\n }\r\n });\r\n //trigger the resize-event to initialize the size and _center-values\r\n google.maps.event.trigger(map, 'center_changed', {});\r\n }\r\n });\r\n }\r\n};\r\n\r\ncash('body').on('click', '#search-location-btn', function () {\r\n var address = cash('#search-location-input').val();\r\n if (!!address && address !== '') {\r\n geocoder.geocode({\r\n 'address': address\r\n }, function (results, status) {\r\n if (status == google.maps.GeocoderStatus.OK) {\r\n var searchAddress = results[0];\r\n var closestAddress = findClosestMapPin(searchAddress, markers);\r\n\r\n createSearchMarker(searchAddress);\r\n\r\n setBoundsAndCenterMap(searchAddress.geometry.location, closestAddress.position);\r\n } else {\r\n instant.toast.show('Geocode was not successful for the following reason: ' + status);\r\n }\r\n });\r\n }\r\n});\r\n\r\ncash('body').on('click', '#use-location-btn', function () {\r\n if (navigator.geolocation) {\r\n navigator.geolocation.getCurrentPosition(function (position) {\r\n var searchAddress = { geometry: { location: { lat: position.coords.latitude, lng: position.coords.longitude } } };\r\n var closestAddress = findClosestMapPin(searchAddress, markers);\r\n\r\n createSearchMarker(searchAddress);\r\n\r\n setBoundsAndCenterMap(searchAddress.geometry.location, closestAddress.position);\r\n });\r\n } else {\r\n x.innerHTML = 'Geolocation is not supported by this browser.';\r\n }\r\n});\r\n\r\nfunction getLatLng(location) {\r\n //console.log(location.attr('data-lng'));\r\n return { lat: getValueAsFloat(location.attr('data-lat')), lng: getValueAsFloat(location.attr('data-lng')) }\r\n}\r\n\r\nfunction getZoomAttr(mapElement) {\r\n return parseInt(cash(mapElement).attr('data-zoom'));\r\n}\r\n\r\nfunction getBoolDataValue(mapElement, attrName) {\r\n return JSON.parse(cash(mapElement).attr(attrName).toLowerCase());\r\n}\r\n\r\nfunction getMapStyles() {\r\n //Check other default styles here & create your own: https://mapstyle.withgoogle.com/\r\n return [];\r\n}\r\n\r\nfunction findClosestMapPin(address, markers) {\r\n console.log('markers:', markers);\r\n\r\n return markers.reduce(function (previous, current) {\r\n var currentPos = google.maps.geometry.spherical.computeDistanceBetween(address.geometry.location, current.position);\r\n var previousPos = google.maps.geometry.spherical.computeDistanceBetween(address.geometry.location, previous.position);\r\n\r\n return currentPos < previousPos ? current : previous;\r\n });\r\n}\r\n\r\nfunction createSearchMarker(searchAddress) {\r\n if (searchMarker != null) {\r\n searchMarker.setMap(null);\r\n searchMarker = null;\r\n }\r\n searchMarker = new google.maps.Marker({\r\n position: searchAddress.geometry.location,\r\n map: map,\r\n title: searchAddress.formatted_address,\r\n //icon: cash(mapElements[0]).data('search-icon'),\r\n });\r\n}\r\n\r\nfunction setBoundsAndCenterMap() {\r\n if (arguments.length > 0) {\r\n if (bounds != null) {\r\n bounds = null;\r\n }\r\n bounds = new google.maps.LatLngBounds();\r\n\r\n for (var i = 0; i < arguments.length; i++) {\r\n bounds.extend(arguments[i]);\r\n }\r\n\r\n map.fitBounds(bounds);\r\n map.setCenter(bounds.getCenter());\r\n }\r\n}\r\n\r\ncash(function () {\r\n cash(window).on('scroll', mapScrollHandler);\r\n});"]}