var jekyllMaps = (function () { 'use strict'; return { data: [], maps: [], initializeMap: initializeMap, initializeCluster: initializeCluster, register: register, render: render, processCluster: processCluster }; /** * Setup Google Maps options and call renderer. */ function initializeMap() { this.options = { mapTypeId: google.maps.MapTypeId.ROADMAP, center: new google.maps.LatLng(0, 0), zoom: 12 } this.mapReady = true; this.render(); } /** * Register map data to be rendered once Google Maps API is loaded. * * @param String id * @param Array locations * @param Boolean useCluster */ function register(id, locations, useCluster) { this.data.push({id: id, locations: locations, useCluster: useCluster}); this.render(); } /** * Render maps data if Google Maps API is loaded. */ function render() { if (!this.mapReady) return; while (this.data.length > 0) { var data = this.data.pop(), bounds = new google.maps.LatLngBounds(), options = this.options, map = new google.maps.Map(document.getElementById(data.id), options), infoWindow = new google.maps.InfoWindow(), markers = data.locations.map(createMarker); map.fitBounds(bounds); google.maps.event.addListenerOnce(map, 'bounds_changed', onBoundsChanged); if (data.useCluster) { this.maps.push({map: map, markers: markers}); this.processCluster(); } } function createMarker(location) { var position = new google.maps.LatLng(location.latitude, location.longitude), marker = new google.maps.Marker({ position: position, title: location.title, image: location.image, url: location.url, map: map }); bounds.extend(position); marker.addListener('click', function () { var contentString = '