{"version":3,"sources":["priory.map.js"],"names":["GoogleMap","[object Object]","el","options","this","scope","buildMap","infoWindow","bindClick","e","target","closest","close","document","removeEventListener","google","maps","Size","Point","infowindow","InfoWindow","content","locations","getMapData","bounds","LatLngBounds","forEach","location","latitude","longitude","loc","LatLng","extend","map","Map","zoom","center","mapTypeControl","streetViewControl","fullscreenControl","zoomControl","fitBounds","panToBounds","length","event","addListenerOnce","setZoom","minZoom","coords","markers","marker","Marker","id","nodeId","position","lat","lng","icon","push","addListener","openInfoWindow","latLong","fetch","then","response","text","data","setContent","open","closeButton","querySelector","addEventListener","directionsButton","LocationBlock","getDirections","setTimeout","openWindow","markerClusterer","MarkerClusterer","locationsList","ids","dataset","json","catch","err","ControlBinders","register"],"mappings":"AAAA,MAAMA,UACJC,YAAYC,EAAIC,GACdC,KAAKC,MAAQH,EACbE,KAAKE,SAASH,GACdC,KAAKG,WACLH,KAAKI,UAAYC,CAAAA,IAC6B,OAAxCA,EAAEC,OAAOC,QAAQ,qBAC2B,OAA1CF,EAAEC,OAAOC,QAAQ,qBACnBP,KAAKG,WAAWK,QAEhBC,SAASC,oBAAoB,QAASV,KAAKI,cAKnDP,eAAeE,GAKC,IAAIY,OAAOC,KAAKC,KAAK,GAAI,IAE7B,IAAIF,OAAOC,KAAKE,MAAM,EAAG,GAEzB,IAAIH,OAAOC,KAAKE,MAAM,GAAI,IARpC,MAWMC,EAAa,IAAIJ,OAAOC,KAAKI,WAAW,CAC5CC,QAAS,KAEX,IAAIC,EAAYnB,GAAWA,EAAQmB,gBAAkBnB,EAAQmB,gBAAkBC,aAC3EC,EAAS,IAAIT,OAAOC,KAAKS,aAC7BH,EAAUA,UAAUI,QAAQC,IAC1B,GAAIA,EAASC,UAAY,IAAMD,EAASC,WAAa,IAAMD,EAASE,WAAa,KAAOF,EAASE,YAAc,IAAK,CAClH,IAAIC,EAAM,IAAIf,OAAOC,KAAKe,OAAOJ,EAASC,SAAUD,EAASE,WAC7DL,EAAOQ,OAAOF,MAG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B,OAAS,EAAG,CACR,IAAIkC,gBAAgBC,gBAAgB,CAClD7B,QAAAA,EACAhB,IAAAA,MAKR,SAASV,aACP,MAAMwD,EAAgBlE,SAASyD,cAAc,oBAC7C,IAAIU,EAAM,GAIV,OAHID,IACFC,EAAMD,EAAcE,QAAQ3D,WAEvBwC,qDAAqDkB,KAAOjB,KAAKC,GAAYA,EAASkB,QAAQnB,KAAKG,GACjGA,GACNiB,MAAMC,GACA,IAGXC,eAAeC,SAAS,aAAcpF,GAAM,IAAIF,UAAUE","sourcesContent":["class GoogleMap {\r\n constructor(el, options) {\r\n this.scope = el;\r\n this.buildMap(options);\r\n this.infoWindow;\r\n this.bindClick = e => {\r\n if (e.target.closest('[role=\"dialog\"]') === null) {\r\n if (e.target.closest('[title=\"map-pin\"]') === null) {\r\n this.infoWindow.close();\r\n } else {\r\n document.removeEventListener(\"click\", this.bindClick);\r\n }\r\n }\r\n };\r\n }\r\n\r\n async buildMap(options) {\r\n \r\n const minZoom = 11;\r\n \r\n const icon = {\r\n url: \"images/map-single-pin.svg\", // url\r\n scaledSize: new google.maps.Size(42, 42), // scaled size\r\n origin: new google.maps.Point(0, 0), // origin\r\n anchor: new google.maps.Point(25, 25) // anchor\r\n };\r\n\r\n const infowindow = new google.maps.InfoWindow({\r\n content: ''\r\n });\r\n let locations = options && options.locations ? await options.locations : await getMapData();\r\n \r\n let bounds = new google.maps.LatLngBounds();\r\n locations.locations.forEach(location => {\r\n if ((location.latitude <= 90 && location.latitude >= -90) && (location.longitude <= 180 && location.longitude >= -180)){\r\n let loc = new google.maps.LatLng(location.latitude, location.longitude);\r\n bounds.extend(loc); \r\n }\r\n });\r\n\r\n let map = new google.maps.Map(\r\n this.scope, {\r\n zoom: minZoom,\r\n center: locations[0],\r\n mapTypeControl: false,\r\n streetViewControl: false,\r\n fullscreenControl: options && options.fullscreenControl ? options.fullscreenControl : false,\r\n zoomControl: options && options.zoomControl ? options.zoomControl : false\r\n });\r\n \r\n map.fitBounds(bounds);\r\n map.panToBounds(bounds);\r\n \r\n //if only 1 location prevent zooming all the way in\r\n locations.locations.length === 1 && google.maps.event.addListenerOnce(map, \"bounds_changed\", function () {\r\n this.setZoom(minZoom+2);\r\n });\r\n \r\n this.infoWindow = infowindow;\r\n\r\n let coords = [];\r\n const markers = locations.locations.map(location => {\r\n const center = [location.latitude, location.longitude];\r\n const marker = new google.maps.Marker({\r\n id: location.nodeId,\r\n position: {lat: location.latitude, lng: location.longitude},\r\n content: location,\r\n map: map,\r\n icon: \"/images/map-single-pin.svg\"\r\n });\r\n coords.push(center);\r\n marker.addListener('click', () => openInfoWindow(marker, center));\r\n return marker;\r\n });\r\n \r\n \r\n const openInfoWindow = (marker, latLong) =>{\r\n fetch('/Umbraco/surface/Locations/GetLocation?id=' + marker.id)\r\n .then(response => response.text())\r\n .then(data => {\r\n infowindow.setContent(data);\r\n infowindow.open(map, marker);\r\n\r\n })\r\n .then(() => {\r\n const closeButton = document.querySelector('.map-info__close');\r\n if (closeButton){\r\n closeButton.addEventListener('click', () => {\r\n infowindow.close();\r\n }); \r\n }\r\n })\r\n .then(() => {\r\n const directionsButton = document.querySelector(\".map-info [data-get-directions]\");\r\n if (directionsButton){\r\n directionsButton.addEventListener('click', () => {\r\n LocationBlock.getDirections(latLong);\r\n }); \r\n }\r\n })\r\n }\r\n setTimeout(()=>{\r\n options && options.openWindow && openInfoWindow(markers[0], coords[0]);\r\n }, 300)\r\n \r\n if(locations.length > 1){\r\n const cluster = new markerClusterer.MarkerClusterer({markers, map});\r\n }\r\n }\r\n}\r\n\r\nfunction getMapData(){\r\n const locationsList = document.querySelector('[data-locations]');\r\n let ids = '';\r\n if (locationsList){\r\n ids = locationsList.dataset.locations;\r\n }\r\n return fetch(`/Umbraco/surface/Locations/GetLocations?ids=${ids}`)\r\n .then(response => response.json())\r\n .then(data => {\r\n return data;\r\n })\r\n .catch(err => {\r\n return [];\r\n });\r\n}\r\n\r\nControlBinders.register(`[data-map]`, el => new GoogleMap(el));"],"file":"priory.map-min.js"}