var StaticCanvasMap,ZoomableCanvasMap;!function(){"use strict";function t(t,e){var n=e.geometry.coordinates;"Polygon"===e.geometry.type&&(n=[n]);for(var r=!1,i=0;it[1]!=l>t[1]&&t[0]<(s-i)*(t[1]-o)/(l-o)+i;c&&(e=!e)}return e}function e(t,a){var e=a;return t[0][0]a[1][0]&&(e[1][0]=t[1][0]),t[1][1]>a[1][1]&&(e[1][1]=t[1][1]),e}function n(t,a){t.lookupTree=rbush(4);var e=[];for(var n in t.features.features){var r=a.bounds(t.features.features[n]);e.push([r[0][0].toFixed(0),r[0][1].toFixed(0),Math.ceil(r[1][0]),Math.ceil(r[1][1]),t.features.features[n]])}t.lookupTree.load(e)}function r(t,a,e){e.context.beginPath(),e.path(a),t["static"].paintfeature(e,a)}function i(t,a){if(t["static"]){if(t["static"].prepaint&&t["static"].prepaint(a),t["static"].paintfeature){var e=t.lookupTree.search([a.translate[0],a.translate[1],a.width/a.scale-a.translate[0],a.height/a.scale-a.translate[1]]);for(var n in e)r(t,e[n][4],a)}t["static"].postpaint&&t["static"].postpaint(a)}}function o(t,a){var e=0,n=0,i=null,o=[];this.hasNext=function(){return e<=t.length&&n=t.length&&n>=o.length)){var s=performance.now();if(!i||n>=o.length){for(;e=t.length)return;i=t[e],i["static"].prepaint&&i["static"].prepaint(a),o=i.lookupTree.search([-a.translate[0],-a.translate[1],a.width/a.scale-a.translate[0],a.height/a.scale-a.translate[1]]),n=0,++e}if(i["static"].paintfeature)for(;n!=o.length;++n){var l=o[n][4];if(r(i,l,a),performance.now()-s>10)break}else n=o.length;n==o.length&&i["static"].postpaint&&i["static"].postpaint(a)}},this.finish=function(){if(!(e>=t.length&&n>=o.length))for(n=o.length){for(;!t[e]["static"]&&e=t.length)return;i=t[e],i["static"].prepaint&&i["static"].prepaint(a),o=i.lookupTree.search([-a.translate[0],-a.translate[1],a.width/a.scale-a.translate[0],a.height/a.scale-a.translate[1]]),n=0}if(i["static"].paintfeature)for(;n!=o.length;++n){var s=o[n][4];r(i,s,a)}i["static"].postpaint&&i["static"].postpaint(a)}}}function s(t,a,e){return[t[0]/a-e[0],t[1]/a-e[1]]}function l(t,a){var e={};for(var n in a)e[n]=a[n];for(var n in t)e.hasOwnProperty(n)||(e[n]=t[n]);return e}function c(a){function r(){p=d3.select(u.element).append("canvas"),v=p.node().getContext("2d");var t=window.devicePixelRatio||1,a=v.webkitBackingStorePixelRatio||v.mozBackingStorePixelRatio||v.msBackingStorePixelRatio||v.oBackingStorePixelRatio||v.backingStorePixelRatio||1;u.ratio=t/a,u.area=1/u.projection.scale()/u.ratio/20,p.attr("width",u.width*u.ratio),p.attr("height",u.height*u.ratio),p.style("width",u.width+"px"),p.style("height",u.height+"px"),v.lineJoin="round",v.lineCap="round",w.context(v),v.clearRect(0,0,u.width*u.ratio,u.height*u.ratio),v.save(),v.scale(u.ratio,u.ratio);for(var e in u.data)n(u.data[e],w);u.background=new Image,u.backgroundScale=u.scale,u.backgroundTranslate=u.translate;var r={path:w,context:v,scale:u.scale,translate:u.translate,width:u.width,height:u.height,map:u.map},o=function(){var t=!1,a=!1;for(var e in u.data){var n=u.data[e];t=t||n.events&&n.events.hover,a=a||n.events&&n.events.click,n.dynamic&&n.dynamic.postpaint&&n.dynamic.postpaint(r,null)}v.restore(),a&&p.on("click",c),t&&p.on("mousemove",d).on("mouseleave",h)};for(var e in u.data){var s=u.data[e];s.dynamic&&s.dynamic.prepaint&&s.dynamic.prepaint(r,s.hoverElement)}for(var e in u.data){var s=u.data[e];i(s,r)}u.background.onload=o,u.background.src=p.node().toDataURL(),this.init=function(){}}function o(){v.save(),v.scale(u.scale*u.ratio,u.scale*u.ratio),v.translate(u.translate[0],u.translate[1]),v.clearRect(-u.translate[0],-u.translate[1],u.width*u.ratio,u.height*u.ratio),v.rect(-u.translate[0],-u.translate[1],u.width/u.scale,u.height/u.scale),v.clip();var t={path:w,context:w.context(),scale:u.scale,translate:u.translate,width:u.width,height:u.height,map:u.map};u.area=1/u.projection.scale()/u.scale/u.ratio/20;for(var a in u.data){var e=u.data[a];e.dynamic&&e.dynamic.prepaint&&e.dynamic.prepaint(t,e.hoverElement)}v.drawImage(u.background,0,0,u.width*u.ratio,u.height*u.ratio,-u.backgroundTranslate[0],-u.backgroundTranslate[1],u.width/u.backgroundScale,u.height/u.backgroundScale);for(var a in u.data){var e=u.data[a];e.dynamic&&e.dynamic.postpaint&&e.dynamic.postpaint(t,e.hoverElement)}v.restore()}function c(){var a=s(d3.mouse(this),u.scale,u.translate),e={scale:u.scale,translate:u.translate,width:u.width,height:u.height,map:u.map};for(var n in u.data){var r=u.data[n];if(r.events&&r.events.click){var i=r.lookupTree.search([a[0],a[1],a[0],a[1]]),o=!1;for(var l in i){var c=i[l][4];t(u.projection.invert(a),c)&&(r.events.click(e,c),o=!0)}o||r.events.click(e,null)}}}function h(){var t={scale:u.scale,translate:u.translate,width:u.width,height:u.height,map:u.map};for(var a in u.data){var e=u.data[a];e.events&&e.events.hover&&(e.hoverElement=!1,e.events.hover(t,null))}}function d(){var a=s(d3.mouse(this),u.scale,u.translate),e={scale:u.scale,translate:u.translate,width:u.width,height:u.height,map:u.map};for(var n in u.data){var r=u.data[n];if(r.events&&r.events.hover&&(!r.hoverElement||!t(u.projection.invert(a),r.hoverElement))){r.hoverElement=!1;var i=r.lookupTree.search([a[0],a[1],a[0],a[1]]);for(var o in i){var l=i[o][4];if(t(u.projection.invert(a),l)){r.hoverElement=l;break}}r.events.hover(e,r.hoverElement)}}}var u=l({width:d3.select(a.element).node().getBoundingClientRect().width,ratio:1,area:0,scale:1,translate:[0,0],background:null,backgroundScale:1,backgroundTranslate:[0,0],map:this},a),g=d3.geo.transform({point:function(t,a,e){(!e||e>=u.area)&&this.stream.point(t,a)}}),p=null,v=null;if(!a.projection){var f=[[1/0,1/0],[-(1/0),-(1/0)]];for(var m in u.data)f=e(f,d3.geo.bounds(u.data[m].features));u.projection=d3.geo.mercator().scale(1).center([(f[1][0]+f[0][0])/2,(f[1][1]+f[0][1])/2])}var w=d3.geo.path().projection({stream:function(t){return g.stream(u.projection.stream(t))}}),f=[[1/0,1/0],[-(1/0),-(1/0)]];for(var m in u.data)f=e(f,w.bounds(u.data[m].features));var k=f[1][0]-f[0][0],b=f[1][1]-f[0][1];a.projection?u.height||(u.height=Math.ceil(1*b/.9)):(u.height=u.height||Math.ceil(b*u.width/k),u.projection.scale(.9*(u.width/k)).translate([u.width/2,u.height/2])),d3.select(u.parameters).attr("height",u.height),this.init=r,this.paint=o,this.settings=function(){return u}}function h(t,a){return Math.abs(t-a)0?a[0]:null;for(var r in a){var i=a[r],o=[-i.translate[0],-i.translate[1],e.width/i.scale-i.translate[0],e.height/i.scale-i.translate[1]];o[0]<=t[0]&&o[1]<=t[1]&&o[2]>=t[2]&&o[3]>=t[3]&&(!n||n.scale=r&&this.stream.point(t,a)}}),r=0,i=null,l=null,u=e.settings(),g=d3.geo.path().projection({stream:function(t){return n.stream(u.projection.stream(t))}}),p=new d({width:u.width,height:u.height}),v=!1;u.map=this,u.zoomScale=u.zoomScale||.5,this.init=function(){e.init(),i=d3.select(u.element).append("canvas"),l=i.node().getContext("2d"),r=1/u.projection.scale()/u.ratio/20,i.attr("width",u.width*u.ratio),i.attr("height",u.height*u.ratio),i.style("width",u.width+"px"),i.style("height",u.height+"px"),i.style("display","none"),l.lineJoin="round",l.lineCap="round",g.context(l),p.addImage({image:u.background,scale:u.scale,translate:u.translate})},this.paint=function(){e.paint()},this.zoom=function(t){if(!t)return void a.call(this,1,[0,0]);var e=g.bounds(t),n=e[1][0]-e[0][0],r=e[1][1]-e[0][1],i=(e[0][0]+e[1][0])/2,o=(e[0][1]+e[1][1])/2,s=u.zoomScale*Math.min(u.width/n,u.height/r),l=[-i+u.width/s/2,-o+u.height/s/2];a.call(this,s,l)}}}();