function initialize_map(){var t=new google.maps.LatLng(42.262284,-71.802063),i=document.getElementById("locationTypeAheadContainer"),n=document.getElementById("location"),r={zoom:9,center:t,mapId:"MAP",mapTypeId:google.maps.MapTypeId.ROADMAP,zoomControlOptions:{style:google.maps.ZoomControlStyle.LARGE},mapTypeControl:!1,fullscreenControl:!1,streetViewControl:!1};Radar.initialize("prj_live_pk_b383b06a0c6dd140d2763e25986e9aa5071ba2c5");google_map=new google.maps.Map(document.getElementById("map_canvas"),r);geocoder=new google.maps.Geocoder;google.maps.event.addListener(google_map,"click",clickMapOrData);google_map.data.addListener("click",clickMapOrData);google_map.controls[google.maps.ControlPosition.TOP_CENTER].push(i);Radar.ui.autocomplete({container:n,responsive:!0,width:"250px",countryCode:"US",onSelection:n=>{goToPlace(n)}});google_map.data.setStyle(function(n){return n.Fg.branch=="Senate"||n.Fg.branch=="NewSenate"?{fillOpacity:.03,fillColor:"#0000ff",strokeColor:"#0000ff",strokeWeight:2,strokeOpacity:.5}:n.Fg.branch=="House"||n.Fg.branch=="NewHouse"?{fillOpacity:.06,fillColor:"#ff143C",strokeColor:"#ff143C",strokeWeight:1,strokeOpacity:.5}:{fillOpacity:.01,fillColor:"#163b1d",strokeColor:"#163b1d",strokeWeight:2,strokeOpacity:.5}});google.maps.event.addListenerOnce(google_map,"tilesloaded",function(){n.style.display="block"});infowindow=new google.maps.InfoWindow;marker=new google.maps.marker.AdvancedMarkerElement({map:google_map,position:t});marker.addListener("click",function(){infowindow.open(google_map,marker)});$(n).val()!=undefined&&$(n).val()!=null&&$(n).val()!=""&&geocoder.geocode({address:$(n).val()},function(t){$(n).val("");t&&t.length>0&&loadPlace(t[0])})}function updateMarkerPosition(n,t){if(marker){const i=new google.maps.LatLng(n,t);marker.position=i}else console.error("Marker is not initialized.")}function goToPlace(n){cleanup();updateMarkerPosition(n.latitude,n.longitude);"Massachusetts"!=n.state&&(infowindow.setContent('<div id="content">No district available &mdash; only Massachusetts addresses supported.<\/div>'),google_map.setCenter(marker.position));infowindow.open(google_map,marker);getDistricts(n.longitude,n.latitude,trimFormattedAddress(n.formattedAddress),!1)}function loadPlace(n){updateMarkerPosition(n.latitude,n.longitude);"massachusetts"!=extractComponentType(n.address_components,"administrative_area_level_1")&&(infowindow.setContent('<div id="content">No district available &mdash; only Massachusetts addresses supported.<\/div>'),google_map.setCenter(marker.position));infowindow.open(google_map,marker);getDistricts(n.geometry.location.lng(),n.geometry.location.lat(),trimFormattedAddress(n.formatted_address),!1)}function clickMapOrData(n){cleanup();google_map.panTo(n.latLng);marker.position=n.latLng;infowindow.open(google_map,marker);reverseGeocode(n.latLng.lng(),n.latLng.lat()).then(function(t){getDistricts(n.latLng.lng(),n.latLng.lat(),t,!0)})}function reverseGeocode(n,t){return new Promise(function(i){geocoder.geocode({location:{lat:t,lng:n}},function(r,u){if(u==="OK"&&r.length){let n="";for(var f=0;f<r.length;f++)if(!r[f].types.find(function(n){return n==="plus_code"||n==="route"})){n=r[f].formatted_address;break}i(trimFormattedAddress(n))}i("at Latitude "+t.toFixed(3)+", Longitude "+n.toFixed(3))})})}function getDistricts(n,t,i,r){var u=window.location.href,f=u.toLowerCase().indexOf("redistricting")>0;$.ajax({url:"/Legislators/GetDistrictByLatLong",type:"Get",cache:!1,data:{latitude:t,longitude:n,isDistrictSearch:f},success:function(u){var o=u.districts,e=u.congressionalHearing,f='<div class="h5">'+i+"<\/div>",s=new google.maps.LatLngBounds;o.length?(o.forEach(function(n){var t=JSON.parse(n.FeatureJson),o,i;if(t.properties.branch=n.Branch,n.Branch==="Congressional"||n.Branch=="NewCongressional"){var i=n.Description,s=n.Congressperson,r="/Redistricting/Index#upcomingHearings",u="See upcoming redistricting hearings";f+='<div class="legDetails">';n.Branch!=="NewCongressional"&&(f+=`<a target="_blank" href="${i}">${s}&nbsp;<span class="fa fa-external-link"></span></a>`);f+=`<em>${n.DistrictName}</em>`;n.Branch!=="NewCongressional"&&(e!=null?(r=`/Events/Hearings/Detail/${e.EventId}`,u=e.Description,f+=`<span>Hearing: <a target="_blank" href=${r}><span>${u}</span></a></span>`):f+=`<a target="_blank" href=${r}><div>${u}</div></a>`);f+="<\/div>";t.id="c"+t.id}else n.Branch==="NewSenate"||n.Branch==="NewHouse"?(o=n.Branch==="NewSenate"?"Senate":"House",f+='<div class="legDetails">'+`<span>${o}</span >`+`<em>${n.DistrictName}</em>`+"<\/div> ",t.id=o+t.id):(i=n.UserMemberCode?"/Legislators/Profile/"+n.UserMemberCode:"/Legislators/District/"+n.DistrictCode,f+='<div class="legDetails">'+`<a target="_blank" href="${i}">${n.LegislatorDisplayName}</a >`+`<em>${n.DistrictName}</em>`+"<\/div> ");google_map.data.addGeoJson(t)}),infowindow.setContent(f),r||google_map.panTo({lat:t,lng:n}),$("#location").addClass("legislatorResults")):infowindow.setContent('<div id="content">No district available &mdash; only Massachusetts addresses supported.<\/div>')},error:function(){var u='<div class="h5">'+i+"<\/div>";infowindow.setContent(u);r||google_map.panTo({lat:t,lng:n});$("#location").addClass("legislatorResults")}})}function centerMapOnPolygon(n,t){var i=n.geometry,r=i.type;"Polygon"==r?extendBoundsToPolygon(i.coordinates,t):i.coordinates.forEach(function(n){extendBoundsToPolygon(n,t)})}function extendBoundsToPolygon(n,t){n.forEach(function(n){n.forEach(function(n){n=new google.maps.LatLng(n[1],n[0]);t.extend(n)})})}function cleanup(){$("#location").val("");infowindow.close();infowindow.setContent('<div id="infowindow-loader">Loading . . .<\/div>');google_map.data.forEach(function(n){google_map.data.remove(n)})}function extractComponentType(n,t){for(var r,f=n.length,u=0,i=0;i<f;i++)if(n[i].types&&(u=n[i].types.length))for(r=0;r<u;r++)if(t==n[i].types[r])return n[i].long_name.toLowerCase()}function trimFormattedAddress(n){return n.replace(/, USA$/,"")}var google_map,marker,infowindow,geocoder