function makeMap(t,e){var a,n,r,o;n=e[0].height?e[0].height:430,o=e[0].scale?e[0].scale:1,(a=(a=d3.select("#"+t).style("width")).substring(0,a.length-2))<400?r=3e3*o:a>=400&&a<500?r=4200*o:a>=500&&a<550?r=5100*o:a>=550&&a<700?r=5600*o:a>=700&&a<1e3?r=6200*o:a>=1e3&&a<1500?r=6500*o:a>=1500&&(r=6700*o);var s=d3.geo.conicConformal().rotate([120.5,0]).center([0,47.25]).parallels([45.83,47.33]).scale(r).translate([a/2,n/2]).precision(.1),l=d3.geo.path().projection(s),i=d3.select("#"+t).append("svg").attr("class",t).attr("width",a).attr("height",n),p=i.append("g"),c=queue(),u=["error"];e.forEach(function(t){var e=t.link.split(".");u.push(e[0]),c.defer(d3.json,"https://s3-us-west-2.amazonaws.com/geolpublist/json/"+t.link)}),c.await(function(r){if(r)throw r;for(var o=0;o<arguments.length;o++)if(0!==o){var c=arguments[o],d=u[o];if(d=d.replace(/[0-9]/g,""),"poly"==e[o-1].type){if(p.append("g").selectAll("path").data(topojson.feature(c,c.objects[d]).features).enter().append("path").attr("d",l).attr("class",function(t){return e[o-1].hasOwnProperty("button")?d+" "+t.properties.label:t.properties.status?"Published"===t.properties.status?"fourpub":"fourprep":d+" poly"}).on("mouseup",function(a){for(var n=!1,r=!1,o=!1,s=0;s<e.length;s++)e[s].tip&&(n=!0),e[s].table&&(r=e[s].table),e[s].zoom&&(o=!0);n&&(b.style("opacity","1"),a.properties.PHONE?x.html("<strong>"+a.properties.label+"</strong><br>"+a.properties.PHONE+"<br><a href=mailto:"+a.properties.URL+" target="_blank">Email</a>"):a.properties.date&&a.properties.spanish?x.html("<strong>"+a.properties.label+"</strong><br>Last updated: "+a.properties.date+"<br><a href="+a.properties.URL+" target="_blank">English</a><span> | </span><a href="+a.properties.spanish+" target="_blank">Spanish</a>"):a.properties.date&&!a.properties.spanish?x.html("<strong>"+a.properties.label+"</strong><br>Last updated: "+a.properties.date+"<br><a href="+a.properties.URL+" target="_blank">English </a>"):a.properties.status?x.html("<strong>"+a.properties.label+"</strong><br>Status: "+a.properties.status):a.properties.URL?x.html("<strong>"+a.properties.label+"</strong><br><a href="+a.properties.URL+" target="_blank">Download</a>"):x.html("<strong>"+a.properties.label+"</strong>"),createTip(b,this,t,!!o)),r&&tabulate(r,a.properties.label,!1,y,g)}),e[o-1].force&&forceLabel(a,n,topojson.feature(c,c.objects[d]).features,t,l,i),e[o-1].label&&p.append("g").selectAll("."+t+" .anno").data(topojson.feature(c,c.objects[d]).features).enter().append("text").text(function(t){return t.properties.label}).attr("class",t+" anno").attr("transform",function(t){var e=l.centroid(t),a=e[0],n=e[1]-.2,r=s.rotate();return r=r[0]+180,"translate("+a+","+n+")rotate("+r+")"}).call(wrap,e[o-1].lWidth,e[o-1].label),e[o-1].legend){var f=i.append("g");f.append("rect").attr("class","fourlegend").attr("width",165).attr("height",120).attr("fill","white").attr("stroke","black").attr("transform","translate(10 290)"),f.append("rect").attr("class","fourpub").attr("width","30px").attr("height","45px").attr("transform","translate(15 300)"),f.append("rect").attr("class","fourprep").attr("width","30px").attr("height","45px").attr("transform","translate(15 360)"),f.append("text").text("Map has been published").attr("font-size","11px").attr("font-family","arial, sans-serif").attr("transform","translate(50 320)"),f.append("text").text("Map is in preparation").attr("font-size","11px").attr("font-family","arial, sans-serif").attr("transform","translate(50 380)")}}else if("point"==e[o-1].type){var h;h=e[o-1].force?5:3,p.append("g").selectAll("path").data(topojson.feature(c,c.objects[d]).features).enter().append("path").attr("d",l.pointRadius(h)).attr("class",function(){return e[o-1].tip?d+" click":d+" point"}).on("mouseup",function(a){for(var n=!1,r=!1,o=0;o<e.length;o++)e[o].tip&&"point"===e[o].type&&(n=!0),e[o].zoom&&(r=!0);n&&(b.style("opacity","1"),x.html("<strong>"+a.properties.label+"</strong><br><a href="+a.properties.URL+" target="_blank">Download</a>"),createTip(b,this,t,!!r))}),e[o-1].force?forceLabel(a,n,topojson.feature(c,c.objects[d]).features,t,l,i):p.append("g").selectAll("."+d+" .labels").data(topojson.feature(c,c.objects[d]).features).enter().append("text").attr("transform",function(t){return"translate("+s(t.geometry.coordinates)+")"}).attr("dy",3).attr("dx",3).text(function(t){return t.properties.label}).attr("class",d+" labels")}}for(o=0;o<e.length;o++){if(e[o].zoom&&zoom_zoom(a,n,l,i,p,t),e[o].table){var m=d3.select("#"+t).append("table"),g=m.append("thead"),y=m.append("tbody");tabulate(e[o].table,null,!0,y,g,t)}if(e[o].tip){var b=d3.select("#"+t).append("div").attr("class","tip "+t).style("opacity",0);b.append("div").attr("class","close").html("X");var x=b.append("div");break}}}),tip()}function wrap(t,e,a){t.each(function(){for(var t,n=d3.select(this),r=n.text().split(/\s+/).reverse(),o=[],s=0,l=n.attr("y"),i=n.text(null).append("tspan").attr("x",0).attr("y",l);t=r.pop();)o.push(t),i.text(o.join(" ")),i.node().getComputedTextLength()>e&&(o.pop(),i.text(o.join(" ")),o=[t],i=n.append("tspan").attr("x",0).attr("y",++s*a+"em").text(t))})}function tip(){d3.select(window).on("scroll",function(){d3.selectAll(".tip").style("opacity",0).style("pointer-events","none")}).on("hashchange",function(){d3.selectAll(".tip").style("opacity",0).style("pointer-events","none")})}function createTip(t,e,a,n){d3.selectAll("."+a).style("pointer-events","all");var r=0,o=0;n||(r=(r=t.style("width")).substring(0,r.length-2),o=(o=t.style("height")).substring(0,o.length-2));var s=d3.mouse(e),l=s[0]-r/2,i=s[1]-o/2,p=e.getScreenCTM().translate(l,i);t.transition().style("left",p.e+"px").style("top",p.f+"px"),d3.selectAll(".tip").selectAll(".close").on("mousedown",function(){d3.selectAll(".tip").transition().style("opacity",0).style("pointer-events","none")})}function zoom_zoom(t,e,a,n,r,o){n.classed("zoom",!0),n.append("rect").attr("class","overlay").attr("width",t).attr("height",e);var s=[t/2,e/2],l=d3.behavior.zoom().scaleExtent([1,45]).on("zoom",p),i=n.selectAll(".button").data(["zoom_in","zoom_out"]).enter().append("g").attr("class","button").attr("transform",function(t,e){return"translate(5,"+3*e+"5)"});function p(n){if(n)r.attr("transform","translate("+l.translate()+")scale("+l.scale()+")");else{var o=d3.event.translate,s=d3.event.scale,i=e/4;o[0]=Math.min(t/e*(s-1),Math.max(t*(1-s),o[0])),o[1]=Math.min(i*(s-1)+i*s,Math.max(e*(1-s)-i*s,o[1])),l.translate(o),r.attr("transform","translate("+o+")scale("+s+")")}r.selectAll(".poly").style("stroke-width",.5/l.scale()+"px"),r.selectAll(".labels").style("font-size",12/l.scale()+"px").attr("dy",-5/l.scale()).attr("dx",-2/l.scale()),r.selectAll(".nodeLabels").style("font-size",12/l.scale()+"px"),r.selectAll(".link").style("stroke-width",2/l.scale()+"px"),r.selectAll(".point").attr("d",a.pointRadius(2/l.scale()))}i.append("rect").attr("width",30).attr("height",30).attr("class",function(t){return t}),i.append("text").attr("x",9).attr("y",20).style("pointer-events","none").style("font-weight","bold").style("font-size","20px").text(function(t,e){return e?"--":"+"}),n.call(l).call(l.event).on("dblclick.zoom",null);var c=!1;function u(){n.on("mousedown.zoom",null).on("touchstart.zoom",null).on("touchmove.zoom",null).on("touchend.zoom",null)}function d(t){var e=l.scale(),a=l.scaleExtent(),n=l.translate(),r=n[0],o=n[1],i=t?1.3:1/1.3,u=e*i,f=Math.max(a[0],Math.min(a[1],u));f!=u&&(i=(u=f)/e),r=(r-s[0])*i+s[0],o=(o-s[1])*i+s[1],d3.transition().duration(100).tween("zoom",function(){var t=d3.interpolate(e,u),a=d3.interpolate(n,[r,o]);return function(e){l.scale(t(e)).translate(a(e)),p(!0)}}).each("end",function(){c&&d(t)})}n.select(".zoom_in").on("mousedown",function(){d3.event.preventDefault(),c=!0,u(),d(!0)}).on("mouseup",function(){c=!1}).on("mouseout",function(){c=!1}),n.select(".zoom_in, .zoom_out").on("mouseup",function(){c=!1,n.call(l).call(l.event)}),n.select(".zoom_out").on("mousedown",function(){d3.event.preventDefault(),c=!0,u(),d(!1)}).on("mouseup",function(){c=!1}).on("mouseout",function(){c=!1}),n.select(".zoom_out").on("mouseup",function(){c=!1,n.call(l).call(l.event)})}function tabulate(t,e,a,n,r,o){d3.text("https://s3-us-west-2.amazonaws.com/geolpublist/text/"+t,function(t){var r,s,l,i=d3.csv.parse(t);r=i.reduce(function(t,e){return t.concat(d3.keys(e))},[]).reduce(function(t,e){return t.set(e,0),t},d3.map()).keys(),e&&(i=i.filter(function(t,a){var n=i[a];if(n.Quadrangle===e||n.County===e||n.Location===e)return t})),a&&d3.select("#"+o).selectAll("thead").selectAll("tr").data(r).enter().append("th").attr("class",function(t){return t}).text(function(t){return t}),(s=n.selectAll("tr").data(i)).enter().append("tr"),(l=s.selectAll("td").data(function(t){return r.map(function(e){return t[e]})})).html(function(t){return t}).style("opacity",0).transition().duration(300).style("opacity",1),l.enter().append("td").html(function(t){return t}).style("opacity",0).transition().duration(300).style("opacity",1),s.exit().transition().duration(200).style("opacity",0).remove(),l.exit().remove(),d3.selectAll("a").attr("target","_blank")})}function forceLabel(t,e,a,n,r){for(var o=[],s=[],l=0;l<a.length;l++){var i=r.centroid(a[l].geometry);l%2==0;var p={label:a[l].properties.label,x:i[0],y:i[1],fixed:!0},c={label:a[l].properties.label,x:i[0],y:i[1]};o.push(p),o.push(c)}for(l=0;l<o.length;l++)l%2==0&&s.push({source:l,target:l+1});var u=d3.layout.force().size([t,e]).nodes(o).links(s).gravity(0).linkDistance(1).linkStrength(1).charge(-20);u.start();var d=d3.selectAll("."+n).select("g").append("g").selectAll("nodeLinks").data(u.links());d.enter().append("line").attr("class","link").attr("x1",function(t){return t.source.x}).attr("y1",function(t){return t.source.y}).attr("x2",function(t){return t.target.x}).attr("y2",function(t){return t.target.y});var f=d3.selectAll("."+n).select("g").append("g").selectAll("nodeLabels").data(u.nodes());f.enter().append("text").attr("class","nodeLabels").attr("transform",function(t){return"translate("+t.x+","+t.y+")"}).text(function(t,e){return e%2==0?"":t.label}).style("fill","#555").style("font-family","Arial").style("font-size",12);var h=0;function m(){f.transition().attr("transform",function(t){return"translate("+t.x+","+t.y+")"}).attr("dx",-5)}function g(){d.transition().attr("x1",function(t){return t.source.x}).attr("y1",function(t){return t.source.y}).attr("x2",function(t){return t.target.x}).attr("y2",function(t){return t.target.y})}u.on("tick",function(){++h%5==0&&(m(),g())}),u.on("end",function(){m(),g()})}