{"version":3,"file":"../MapScripts.js","names":["Promise","resolve","reject","fetch","body","JSON","stringify","method","headers","Accept","then","response","json","catch","error","result","console","log","initMap","markerClickedEvent","e","isMain","features","properties","firmId","prom","searchParams","MemberFirmID","toString","GetFirmData","document","getElementById","classList","remove","innerHTML","htmlResults","calculateHeight","applyClicks","scrollToAnchorIDVanilla","jurisdictionId","jurisdictionID","GetFirmDataByJurisdiction","apiData","mapboxgl","supported","accessToken","mapData","data","newData","type","offices","forEach","item","officeLat","officeLng","push","geometry","coordinates","id","officeId","title","officeCity","officeCountry","city","country","secondaryLocations","lat","lng","jurisdictionName","secondaryOffices","organiseDataIntoGeoJson","map","Map","container","style","center","zoom","maxZoom","minZoom","renderWorldCopies","attributionControl","cooperativeGestures","dragRotate","disable","touchZoomRotate","disableRotation","nav","NavigationControl","showCompass","addControl","fullscreen","FullscreenControl","selectedStateId","on","addSource","addLayer","source","paint","popup","Popup","closeButton","closeOnClick","maxWidth","offset","setFeatureState","selected","add","getCanvas","cursor","slice","description","setLngLat","setHTML","addTo","length","listData","main","secondary","office","allOffices","concat","sortedData","_","orderBy","lettersArray","lettersObject","letter","items","currentLetter","toLowerCase","find","firm","officeFirmName","firmUrl","isSecondary","sortDataIntoLettersArray","elList","elListHtmlString","group","state","querySelectorAll","header","addEventListener","targetId","target","getAttribute","toggle"],"sources":["MapScripts.js"],"sourcesContent":["(() => {\r\n\r\n let apiData = null;\r\n let firmData = null;\r\n //const partialView = \"LexDirectoryResultRows\";\r\n const partialView = \"FirmResultBlock\";\r\n\r\n\r\n /*******************************/\r\n /**** CRAIG - DYNAMIC FETCH ****/\r\n /*******************************/\r\n const GetMapData = () => {\r\n return new Promise(function (resolve, reject) {\r\n\r\n\t\t\tconst searchParams = {};\r\n\t\t//\tfetch('/Umbraco/Surface/DirectorySearch/GetOffices', {\r\n\t\t\t\tfetch('/Umbraco/Surface/DirectorySearch/GetPrimarySecondaryOffices', {\r\n body: JSON.stringify(searchParams), method: 'post', headers: { 'Accept': 'application/json', 'Content-Type': 'application/json' },\r\n })\r\n .then(function (response) {\r\n //console.log('response : %o', response.json());\r\n resolve(response.json());\r\n })\r\n .catch(error => {\r\n //console.log('Failed', error);\r\n reject(error);\r\n });\r\n });\r\n };\r\n\t//\r\n const GetFirmData = (firmId) => { \r\n let searchParams = { MemberFirmID: firmId.toString() };\r\n //console.log('GetFirmData : %o', searchParams);\r\n return new Promise(function (resolve, reject) {\r\n\r\n fetch('/Umbraco/Surface/DirectorySearch/GetFirmDetailsPartial', {\r\n body: JSON.stringify(searchParams), method: 'post', headers: { 'Accept': 'application/json', 'Content-Type': 'application/json' },\r\n })\r\n .then(function (response) {\r\n //console.log('response : %o', response.json());\r\n resolve(response.json());\r\n })\r\n .catch(error => {\r\n //console.log('Failed', error);\r\n reject(error);\r\n });\r\n });\r\n\t};\r\n\tconst GetFirmDataByJurisdiction = (jurisdictionId) => {\r\n\t\tlet searchParams = { jurisdictionID: jurisdictionId.toString() };\r\n\t\t//console.log('GetFirmData : %o', searchParams);\r\n\t\treturn new Promise(function (resolve, reject) {\r\n\t\t\tfetch('/Umbraco/Surface/DirectorySearch/GetFirmDetailsByJurisdictionPartial', {\r\n\t\t\t\tbody: JSON.stringify(searchParams), method: 'post', headers: { 'Accept': 'application/json', 'Content-Type': 'application/json' },\r\n\t\t\t})\r\n\t\t\t\t.then(function (response) {\r\n\t\t\t\t\t//console.log('response : %o', response.json());\r\n\t\t\t\t\tresolve(response.json());\r\n\t\t\t\t})\r\n\t\t\t\t.catch(error => {\r\n\t\t\t\t\t//console.log('Failed', error);\r\n\t\t\t\t\treject(error);\r\n\t\t\t\t});\r\n\t\t});\r\n\t};\r\n // Fetch map data \r\n const prom = GetMapData();\r\n prom.then(\r\n (result) => {\r\n console.log('Raw map data : %o', result);\r\n initMap(result);\r\n }\r\n );\r\n\r\n\r\n\r\n\r\n\r\n\t/*************************/\r\n\t/*** SORT DATA HELPERS ***/\r\n\t/*************************/\r\n\tconst sortDataIntoLettersArray = (data) => {\r\n\t//\tconst sortedData = _.orderBy(data.Offices, ['OfficeCountry', 'OfficeCity'], ['asc']);\r\n\t\tvar main = data.offices; \r\n\t\tvar secondary = data.secondaryLocations;\r\n\t\tvar secondaryOffices = [];\r\n\t\r\n\t\tsecondary.forEach((item) => {\r\n\t\t\tvar items = item.secondaryOffices;\r\n\t\t\titems.forEach((office) => {\r\n\t\t\t\tsecondaryOffices.push(office);\r\n\t\t\t});\r\n\t\t});\r\n\t\tconst allOffices = main.concat(secondaryOffices);\r\n\t\tconst sortedData = _.orderBy(allOffices, ['officeCountry', 'officeCity'], ['asc']);\r\n\t\tconsole.log(\"SECONDARY OFFICES: %o\", secondaryOffices);\r\n\t\tconst lettersString = 'abcdefghijklmnopqrstuvwxyz';\r\n\t\tconst lettersArray = [...lettersString];\r\n\t\tconst lettersObject = [];\r\n\r\n\t\tlettersArray.forEach((letter) => {\r\n\t\t\tlettersObject.push({\r\n\t\t\t\tletter,\r\n\t\t\t\titems: [],\r\n\t\t\t});\r\n\t\t});\r\n\r\n\t\tsortedData.forEach((item) => {\r\n\t\t\tconst currentLetter = item.officeCountry.slice(0, 1).toLowerCase();\r\n\t\t\tconst currentLetterObject = _.find(lettersObject, ['letter', currentLetter]);\r\n\t\t\tcurrentLetterObject.items.push({\r\n\t\t\t\tid: item.officeId,\r\n\t\t\t\tcountry: item.officeCountry,\r\n\t\t\t\tfirm: item.officeFirmName,\r\n\t\t\t\tcity: item.officeCity,\r\n\t\t\t\tfirmUrl: item.firmUrl,\r\n\t\t\t\tisSecondary: item.isSecondary \r\n //,state: item.State\r\n\t\t\t});\r\n\t\t});\r\n\r\n\t\treturn lettersObject;\r\n\t};\r\n\r\n\tconst organiseDataIntoGeoJson = (data) => {\r\n\t\tconst newData = {\r\n\t\t\ttype: 'FeatureCollection',\r\n\t\t\tfeatures: [],\r\n\t\t};\r\n\r\n\t\tdata.offices.forEach((item) => {\r\n\t\t\tif (!item.officeLat || !item.officeLng) {\r\n\t\t\t\treturn;\r\n\t\t\t}\r\n\t\t\tnewData.features.push({\r\n\t\t\t\ttype: 'Feature',\r\n\t\t\t\tgeometry: { \r\n\t\t\t\t\ttype: 'Point',\r\n\t\t\t\t\tcoordinates: [item.officeLng, item.officeLat],\r\n\t\t\t\t},\r\n\t\t\t\tid: item.officeId,\r\n\t\t\t\tproperties: {\r\n\t\t\t\t\ttitle: `${item.officeCity} ${item.officeCountry}`,\r\n\t\t\t\t\tcity: item.officeCity,\r\n country: item.officeCountry,\r\n\t\t\t\t\tfirmId: item.firmId,\r\n\t\t\t\t\tisMain : true\r\n\t\t\t\t},\r\n\t\t\t});\r\n\t\t});\r\n\t\tdata.secondaryLocations.forEach((item) => {\r\n\t\t\r\n\t\t\tif (!item.lat || !item.lng) {\r\n\t\t\t\treturn;\r\n\t\t\t}\r\n\t\t\tnewData.features.push({\r\n\t\t\t\ttype: 'Feature',\r\n\t\t\t\tgeometry: {\r\n\t\t\t\t\ttype: 'Point',\r\n\t\t\t\t\tcoordinates: [item.lng, item.lat],\r\n\t\t\t\t},\r\n\t\t\t\tid: item.officeId,\r\n\t\t\t\tproperties: {\r\n\t\t\t\t\ttitle: `${item.jurisdictionName}`,\r\n\t\t\t\t\tcity: \"City\",\r\n\t\t\t\t\tcountry: \"Country\",\r\n\t\t\t\t\tjurisdictionId: item.jurisdictionId,\r\n\t\t\t\t\tisMain: false,\r\n\t\t\t\t\toffices: item.secondaryOffices\r\n\t\t\t\t},\r\n\t\t\t});\r\n\t\t});\r\n\r\n\t\treturn newData;\r\n\t};\r\n\r\n\t/*************************/\r\n\t/**** MAP CLICK EVENTS ***/\r\n\t/*************************/\r\n\tconst mapClickedEvent = () => {\r\n\t\t//console.log('Clicked: Map');\r\n const elSelectedMarker = document.getElementById('marker-selected');\r\n elSelectedMarker.classList.add('hidden');\r\n\r\n //const elResults = document.getElementById('result-rows');\r\n //elResults.innerHTML = '';\r\n\t};\r\n\r\n const markerClickedEvent = (e) => {\r\n //console.log('Clicked: Marker : %o', e.features[0].properties );\r\n //elSelectedMarker.innerHTML = `