{ "version": 3, "sources": ["../../node_modules/debounce/index.js", "../../src/js/map.js"], "sourcesContent": ["/**\n * Returns a function, that, as long as it continues to be invoked, will not\n * be triggered. The function will be called after it stops being called for\n * N milliseconds. If `immediate` is passed, trigger the function on the\n * leading edge, instead of the trailing. The function also has a property 'clear' \n * that is a function which will clear the timer to prevent previously scheduled executions. \n *\n * @source underscore.js\n * @see http://unscriptable.com/2009/03/20/debouncing-javascript-methods/\n * @param {Function} function to wrap\n * @param {Number} timeout in ms (`100`)\n * @param {Boolean} whether to execute at the beginning (`false`)\n * @api public\n */\nfunction debounce(func, wait, immediate){\n var timeout, args, context, timestamp, result;\n if (null == wait) wait = 100;\n\n function later() {\n var last = Date.now() - timestamp;\n\n if (last < wait && last >= 0) {\n timeout = setTimeout(later, wait - last);\n } else {\n timeout = null;\n if (!immediate) {\n result = func.apply(context, args);\n context = args = null;\n }\n }\n };\n\n var debounced = function(){\n context = this;\n args = arguments;\n timestamp = Date.now();\n var callNow = immediate && !timeout;\n if (!timeout) timeout = setTimeout(later, wait);\n if (callNow) {\n result = func.apply(context, args);\n context = args = null;\n }\n\n return result;\n };\n\n debounced.clear = function() {\n if (timeout) {\n clearTimeout(timeout);\n timeout = null;\n }\n };\n \n debounced.flush = function() {\n if (timeout) {\n result = func.apply(context, args);\n context = args = null;\n \n clearTimeout(timeout);\n timeout = null;\n }\n };\n\n return debounced;\n};\n\n// Adds compatibility for ES modules\ndebounce.debounce = debounce;\n\nmodule.exports = debounce;\n", "import debounce from 'debounce'\n\nconst mapEl = document.getElementById('map')\nif (mapEl) {\n\twindow.addEventListener('load', initMap)\n}\n\nfunction initMap() {\n\tconst markers = _mapMarkers\n\tmarkers.forEach(marker => {\n\t\tlet markerObj = {\n\t\t\tlat: parseFloat(marker.map_marker_location.latitude),\n\t\t\tlng: parseFloat(marker.map_marker_location.longitude),\n\t\t}\n\t\tmarker['markerObj'] = markerObj\n\t})\n\n\t// Find center of multiple markers\n\tfunction findCenter(markers) {\n\t\tif (markers.length <= 1) {\n\t\t\treturn markers[0].markerObj\n\t\t}\n\t\tconst lats = markers.map(m => m.markerObj.lat)\n\t\tconst lngs = markers.map(m => m.markerObj.lng)\n\t\treturn {\n\t\t\tlat: (Math.min(...lats) + Math.max(...lats)) / 2,\n\t\t\tlng: (Math.min(...lngs) + Math.max(...lngs)) / 2,\n\t\t}\n\t}\n\tconst centerPosition = findCenter(markers)\n\n\tvar bounds = new google.maps.LatLngBounds()\n\tmarkers?.forEach(m => {\n\t\tbounds.extend(new google.maps.LatLng(m.markerObj.lat, m.markerObj.lng))\n\t})\n\n\tlet zoomLevel\n\tif (window.innerWidth >= 1200) {\n\t\tzoomLevel = 15\n\t} else if (window.innerWidth >= 992) {\n\t\tzoomLevel = 14\n\t} else {\n\t\tzoomLevel = 13\n\t}\n\n\tconst map = new google.maps.Map(document.getElementById('map'), {\n\t\tcenter: centerPosition,\n\t\tzoom: zoomLevel,\n\t\tmapId: 'f22f4f193b90ef3f',\n\t\tstreetViewControl: false,\n\t\tmapTypeControl: false,\n\t\tfullscreenControl: false,\n\t})\n\n\t// map.setOptions({draggable: false, zoomControl: false, scrollwheel: false, disableDoubleClickZoom: true});\n\tmap.setOptions({ scrollwheel: false })\n\n\tconst image = {\n\t\turl: '/wp-content/themes/custom-theme/assets/img/logo-map-marker.svg',\n\t\tsize: new google.maps.Size(54, 41),\n\t\torigin: new google.maps.Point(0, 0),\n\t\tanchor: new google.maps.Point(27, 20),\n\t}\n\n\tfor (let i = 0; i < markers.length; i++) {\n\t\tlet m = markers[i]\n\t\tconst contentString = `

${m.location_name}

${m.address}

`\n\n\t\tconst infowindow = new google.maps.InfoWindow({\n\t\t\tcontent: contentString,\n\t\t})\n\n\t\tlet mrkr = new google.maps.Marker({\n\t\t\tposition: m.markerObj,\n\t\t\tmap,\n\t\t\ticon: image,\n\t\t})\n\n\t\tmrkr.addListener('click', () => {\n\t\t\tinfowindow.open({\n\t\t\t\tanchor: mrkr,\n\t\t\t\tmap,\n\t\t\t\tshouldFocus: false,\n\t\t\t})\n\t\t})\n\t}\n\n\tconst refreshCenter = debounce(() => {\n\t\t// TODO: This is slightly annoying/unsightly when resizing the screen, clean it up if we have time\n\t\tmap.setCenter(centerPosition)\n\n\t\tif (window.innerWidth < 992) {\n\t\t\treturn\n\t\t}\n\t\t// retrieve the lat lng for the far extremities of the (visible) map\n\t\tvar latLngBounds = map.getBounds()\n\t\tvar neBound = latLngBounds.getNorthEast()\n\t\tvar swBound = latLngBounds.getSouthWest()\n\n\t\t// convert the bounds in pixels\n\t\tvar neBoundInPx = map.getProjection().fromLatLngToPoint(neBound)\n\t\tvar swBoundInPx = map.getProjection().fromLatLngToPoint(swBound)\n\n\t\tvar offset\n\t\tif (window.innerWidth >= 1900) {\n\t\t\toffset = (neBoundInPx.x - swBoundInPx.x) * 0.25\n\t\t} else if (window.innerWidth >= 992) {\n\t\t\toffset = (neBoundInPx.x - swBoundInPx.x) * 0.29\n\t\t}\n\n\t\tvar center = map.getCenter()\n\t\tvar centerPoint = map.getProjection().fromLatLngToPoint(center)\n\t\tcenterPoint.x -= offset\n\t\tmap.setCenter(map.getProjection().fromPointToLatLng(centerPoint))\n\t}, 100)\n\n\tconst refreshBounds = () => {\n\t\t// TODO: This doesn't work properly when the map is partially obstructed by the contact card.\n\t\t// This also doesn't work properly with the centering function, as markers sometimes get pushed off screen\n\t\t// I think it has to do with the fact that centering is happening after the bounds are updated, and they don't take each other into account\n\t\tif (window.innerWidth <= 767) {\n\t\t\tif (markers.length > 1) map.fitBounds(bounds, 70)\n\t\t} else {\n\t\t\tif (markers.length > 1)\n\t\t\t\tmap.fitBounds(bounds, {\n\t\t\t\t\ttop: 120,\n\t\t\t\t\tright: 120,\n\t\t\t\t\tbottom: 120,\n\t\t\t\t\tleft: window.innerWidth / 2 + 120,\n\t\t\t\t})\n\t\t}\n\t}\n\n\tmap.addListener('projection_changed', () => {\n\t\trefreshBounds()\n\t\trefreshCenter()\n\t})\n\n\twindow.addEventListener('resize', () => {\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