/* global google */ /* global MarkerClusterer */ // eslint-disable-next-line no-unused-vars var jekyllMaps = (function() { 'use strict' var clusterSettings = {} var clusterReady = false var mapReady = false var options = {} var data = [] var maps = [] return { initializeMap: initializeMap, initializeCluster: initializeCluster, register: register } /** * Setup Google Maps options and call renderer. */ function initializeMap() { options = { mapTypeId: google.maps.MapTypeId.ROADMAP, center: new google.maps.LatLng(0, 0) } mapReady = true render() } /** * Register map data to be rendered once Google Maps API is loaded. * * @param string id * @param Array locations * @param Object settings */ function register(id, locations, options) { data.push({ id: id, locations: locations, options: options }) render() } /** * Render maps data if Google Maps API is loaded. */ function render() { if (!mapReady) return while (data.length > 0) { var item = data.pop() var bounds = new google.maps.LatLngBounds() var mapOptions = Object.assign({}, options, item.options) var map = new google.maps.Map( document.getElementById(item.id), mapOptions ) var infoWindow = new google.maps.InfoWindow() var markers = item.locations.map(createMarker) map.fitBounds(bounds) google.maps.event.addListenerOnce(map, 'idle', function() { if (this.customZoom) this.setZoom(this.customZoom) }) if (mapOptions.useCluster) { maps.push({ map: map, markers: markers }) processCluster() } } function createMarker(location) { var position = new google.maps.LatLng( location.latitude, location.longitude ) bounds.extend(position) if (!mapOptions.showMarker) return false var marker = new google.maps.Marker({ position: position, title: location.title, image: location.image, url: location.url.length > 0 ? mapOptions.baseUrl + location.url : '', map: map }) if (mapOptions.showMarkerPopup) marker.addListener('click', markerPopup) return marker } function markerPopup() { var contentHtml = '