!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e(t.mapv=t.mapv||{})}(this,function(t){"use strict";function E(t){t&&t.clearRect&&t.clearRect(0,0,t.canvas.width,t.canvas.height)}function n(){this._subscribers={}}n.prototype.on=function(t,e){var n=this._subscribers[t];n||(n=[],this._subscribers[t]=n),n.push({callback:e})},n.prototype.off=function(t,e){var n=this._subscribers[t];if(n)for(var i=0;il&&(t[p]=256*l),t[p]/25680*n){i=a=t[0],o=r=t[1];for(var d=n;da.x?o.x>r.x?o.x:r.x:a.x>r.x?a.x:r.x,u=o.y>a.y?o.y>r.y?o.y:r.y:a.y>r.y?a.y:r.y,c=$(s,h,e,n,i),p=$(l,u,e,n,i),v=t.nextZ;v&&v.z<=p;){if(v!==t.prev&&v!==t.next&&Y(o.x,o.y,a.x,a.y,r.x,r.y,v.x,v.y)&&0<=G(v.prev,v,v.next))return!1;v=v.nextZ}for(v=t.prevZ;v&&v.z>=c;){if(v!==t.prev&&v!==t.next&&Y(o.x,o.y,a.x,a.y,r.x,r.y,v.x,v.y)&&0<=G(v.prev,v,v.next))return!1;v=v.prevZ}return!0}function N(t,e,n){var i=t;do{var o=i.prev,a=i.next.next;!J(o,a)&&Q(o,i,i.next,a)&&X(o,a)&&X(a,o)&&(e.push(o.i/n),e.push(i.i/n),e.push(a.i/n),et(i),et(i.next),i=t=a),i=i.next}while(i!==t);return i}function W(t,e,n,i,o,a){var r,s,h=t;do{for(var l=h.next.next;l!==h.prev;){if(h.i!==l.i&&(s=l,(r=h).next.i!==s.i&&r.prev.i!==s.i&&!function(t,e){var n=t;do{if(n.i!==t.i&&n.next.i!==t.i&&n.i!==e.i&&n.next.i!==e.i&&Q(n,n.next,t,e))return!0;n=n.next}while(n!==t);return!1}(r,s)&&X(r,s)&&X(s,r)&&function(t,e){var n=t,i=!1,o=(t.x+e.x)/2,a=(t.y+e.y)/2;for(;n.y>a!=n.next.y>a&&o<(n.next.x-n.x)*(a-n.y)/(n.next.y-n.y)+n.x&&(i=!i),n=n.next,n!==t;);return i}(r,s))){var u=K(h,l);return h=B(h,h.next),u=B(u,u.next),U(h,e,n,i,o,a),void U(u,e,n,i,o,a)}l=l.next}h=h.next}while(h!==t)}function H(t,e){return t.x-e.x}function q(t,e){if(e=function(t,e){var n,i=e,o=t.x,a=t.y,r=-1/0;do{if(a<=i.y&&a>=i.next.y){var s=i.x+(a-i.y)*(i.next.x-i.x)/(i.next.y-i.y);if(s<=o&&r=i.x&&i.x>=u&&Y(an.x)&&X(i,t)&&(n=i,p=h),i=i.next;return n}(t,e)){var n=K(e,t);B(n,n.next)}}function $(t,e,n,i,o){return(t=1431655765&((t=858993459&((t=252645135&((t=16711935&((t=32767*(t-n)/o)|t<<8))|t<<4))|t<<2))|t<<1))|(e=1431655765&((e=858993459&((e=252645135&((e=16711935&((e=32767*(e-i)/o)|e<<8))|e<<4))|e<<2))|e<<1))<<1}function V(t){for(var e=t,n=t;e.x'+o+"";return n.innerHTML=i,n},ct.prototype.get=function(t){for(var e=this.splitList,n=!1,i=0;i=e[i].start)&&(void 0===e[i].end||void 0!==e[i].end&&t>1;!function t(e,n,i,o,a,r){for(;od&&It(e,n,o,a);gd;)f--}n[2*o+r]===d?It(e,n,o,f):It(e,n,++f,a),f<=i&&(o=f+1),i<=f&&(a=f-1)}}(t,e,r,i,o,a%2),Ot(t,e,n,i,r-1,a+1),Ot(t,e,n,1+r,o,a+1)}}function It(t,e,n,i){Tt(t,n,i),Tt(e,2*n,2*i),Tt(e,2*n+1,2*i+1)}function Tt(t,e,n){var i=t[e];t[e]=t[n],t[n]=i}function Dt(t,e,n,i){var o=t-n,a=e-i;return o*o+a*a}function Ft(t){return t[0]}function Bt(t){return t[1]}function Ut(t,e,n,i,o){void 0===e&&(e=Ft),void 0===n&&(n=Bt),void 0===i&&(i=64),void 0===o&&(o=Float64Array),this.nodeSize=i;for(var a=(this.points=t).length<65536?Uint16Array:Uint32Array,r=this.ids=new a(t.length),s=this.coords=new o(2*t.length),h=0;he&&(d+=y.numPoints||1)}if(s<=d){for(var x=u.x*v,_=u.y*v,w=r&&1>5},Zt.prototype._getOriginZoom=function(t){return(t-this.points.length)%32},Zt.prototype._map=function(t,e){if(t.numPoints)return e?$t({},t.properties):t.properties;var n=this.points[t.index].properties,i=this.options.map(n);return e&&i===n?$t({},i):i},"undefined"!=typeof window&&requestAnimationFrame(function t(e){requestAnimationFrame(t);xt.update(e)});var Gt=(e(Jt,[{key:"refreshCluster",value:function(t){t=t||this.options,this.supercluster=new Zt({maxZoom:t.maxZoom||19,radius:t.clusterRadius||100,minPoints:t.minPoints||2,extent:t.extent||512}),this.supercluster.load(this.dataSet.get()),this.supercluster.trees.forEach(function(t){var e=0,n=1/0;t.points.forEach(function(t){e=Math.max(t.numPoints||0,e),n=Math.min(t.numPoints||1/0,n)}),t.max=e,t.min=n}),this.clusterDataSet=new T}},{key:"getDefaultContextConfig",value:function(){return{globalAlpha:1,globalCompositeOperation:"source-over",imageSmoothingEnabled:!0,strokeStyle:"#000000",fillStyle:"#000000",shadowOffsetX:0,shadowOffsetY:0,shadowBlur:0,shadowColor:"rgba(0, 0, 0, 0)",lineWidth:1,lineCap:"butt",lineJoin:"miter",miterLimit:10,lineDashOffset:0,font:"10px sans-serif",textAlign:"start",textBaseline:"alphabetic"}}},{key:"initDataRange",value:function(){var t=this;if(t.intensity=new D({maxSize:t.options.maxSize,minSize:t.options.minSize,gradient:t.options.gradient,max:t.options.max||this.dataSet.getMax("count")}),t.category=new ut(t.options.splitList),t.choropleth=new ct(t.options.splitList),void 0===t.options.splitList&&t.category.generateByDataSet(this.dataSet,t.options.color),void 0===t.options.splitList){var e=t.options.min||this.dataSet.getMin("count"),n=t.options.max||this.dataSet.getMax("count");t.choropleth.generateByMinMax(e,n)}}},{key:"getLegend",value:function(t){return this.options.draw,"intensity"==this.options.draw||"heatmap"==this.options.draw?this.intensity.getLegend(t):"category"==this.options.draw?this.category.getLegend(t):void 0}},{key:"processData",value:function(t){var e=this,n=e.options.draw;if("bubble"==n||"intensity"==n||"category"==n||"choropleth"==n||"simple"==n)for(var i=0;i=this.getZoom())?this.clusterDataSet.get():this.dataSet.get();for(var i=0;io&&(e[i]._size=a),t.lineWidth=1,t.strokeStyle=e[i].strokeStyle||e[i]._strokeStyle||n.strokeStyle||"yellow",t.stroke(),(l=e[i].fillStyle||e[i]._fillStyle||n.fillStyle)&&(t.fillStyle=l,t.fill())}else if("LineString"===e[i].geometry.type){t.beginPath();var r=e[i].size||this.options.size||5;a=e[i].minSize||this.options.minSize||0,void 0===e[i]._index&&(e[i]._index=0);var s=e[i]._index;t.arc(e[i].geometry._coordinates[s][0],e[i].geometry._coordinates[s][1],r,0,2*Math.PI,!0),t.closePath(),e[i]._index++,e[i]._index>=e[i].geometry._coordinates.length&&(e[i]._index=0);var h=e[i].strokeStyle||n.strokeStyle,l=e[i].fillStyle||n.fillStyle||"yellow";t.fillStyle=l,t.fill(),h&&n.lineWidth&&(t.lineWidth=n.lineWidth||1,t.strokeStyle=h,t.stroke())}t.restore()}}},{key:"animate",value:function(){this.drawAnimation();var t=this.options.animateTime||100;this.timeout=setTimeout(this.animate.bind(this),t)}},{key:"start",value:function(){this.stop(),this.animate()}},{key:"stop",value:function(){clearTimeout(this.timeout)}},{key:"unbindEvent",value:function(){}},{key:"hide",value:function(){this.canvasLayer.hide(),this.stop()}},{key:"show",value:function(){this.start()}},{key:"clearData",value:function(){this.dataSet&&this.dataSet.clear(),this.update({options:null})}},{key:"destroy",value:function(){this.stop(),this.unbindEvent(),this.clearData(),this.map.removeOverlay(this.canvasLayer),this.canvasLayer=null}}]),te);function te(t,e,n){s(this,te);var i=u(this,(te.__proto__||Object.getPrototypeOf(te)).call(this,t,e,n));i.map=t,i.options=n||{},i.dataSet=e;var o=new dt({map:t,zIndex:i.options.zIndex,update:i._canvasUpdate.bind(i)});i.init(i.options),i.canvasLayer=o,i.transferToMercator();var a=i;return e.on("change",function(){a.transferToMercator(),o.draw()}),i.ctx=o.canvas.getContext("2d"),i.start(),i}var ee="undefined"==typeof window?{}:window,ne=ee.BMap||ee.BMapGL,ie=(l(oe,Gt),e(oe,[{key:"clickEvent",value:function(t){var e=t.pixel;h(oe.prototype.__proto__||Object.getPrototypeOf(oe.prototype),"clickEvent",this).call(this,e,t)}},{key:"mousemoveEvent",value:function(t){var e=t.pixel;h(oe.prototype.__proto__||Object.getPrototypeOf(oe.prototype),"mousemoveEvent",this).call(this,e,t)}},{key:"tapEvent",value:function(t){var e=t.pixel;h(oe.prototype.__proto__||Object.getPrototypeOf(oe.prototype),"tapEvent",this).call(this,e,t)}},{key:"bindEvent",value:function(){this.unbindEvent();var t=this.map,e=0,n=this;this.options.methods&&(this.options.methods.click&&(t.setDefaultCursor("default"),t.addEventListener("click",this.clickEvent)),this.options.methods.mousemove&&t.addEventListener("mousemove",this.mousemoveEvent),"ontouchend"in window.document&&this.options.methods.tap&&(t.addEventListener("touchstart",function(t){e=new Date}),t.addEventListener("touchend",function(t){new Date-e<300&&n.tapEvent(t)})))}},{key:"unbindEvent",value:function(){var t=this.map;this.options.methods&&(this.options.methods.click&&t.removeEventListener("click",this.clickEvent),this.options.methods.mousemove&&t.removeEventListener("mousemove",this.mousemoveEvent))}},{key:"transferToMercator",value:function(t){t=t||this.dataSet;var n,i=this.map,e=i.getMapType();if(n=e.getProjection?e.getProjection():{lngLatToPoint:function(t){var e=i.lnglatToMercator(t.lng,t.lat);return{x:e[0],y:e[1]}}},"bd09mc"!==this.options.coordType){var o=t.get();o=t.transferCoordinate(o,function(t){if(t[0]<-180||180this.options.maxZoom)){var u=1;"2d"!=this.context&&(u=this.canvasLayer.devicePixelRatio);var c,p={fromColumn:"bd09mc"==this.options.coordType?"coordinates":"coordinates_mercator",transferCoordinate:function(t){return[(t[0]-s.x)/i*u,(s.y-t[1])/i*u]}};void 0!==n&&(p.filter=function(t){var e=a.trails||10;return!!(n&&t.time>n-e&&t.time=v)){var d=this.map.getBounds(),g=d.getNorthEast(),f=d.getSouthWest(),m=this.supercluster.getClusters([f.lng,f.lat,g.lng,g.lat],v);this.pointCountMax=this.supercluster.trees[v].max,this.pointCountMin=this.supercluster.trees[v].min;var y={},x=null,_=null;this.pointCountMax===this.pointCountMin?(x=this.options.fillStyle,_=this.options.minSize||8):y=new D({min:this.pointCountMin,max:this.pointCountMax,minSize:this.options.minSize||8,maxSize:this.options.maxSize||30,gradient:this.options.gradient});for(var w=0;wt.options.maxZoom)){var a=1;"2d"!=this.context&&(a=this.canvasLayer.devicePixelRatio);var r=this.map,s=r.getProjection(),h=(a=Math.pow(2,r.zoom)*resolutionScale,s.fromLatLngToPoint(this.canvasLayer.getTopLeft())),l={transferCoordinate:function(t){var e=new google.maps.LatLng(t[1],t[0]),n=s.fromLatLngToPoint(e),i={x:(n.x-h.x)*a,y:(n.y-h.y)*a};return[i.x,i.y]}};void 0!==n&&(l.filter=function(t){var e=i.trails||10;return!!(n&&t.time>n-e&&t.timen-e&&t.timen-e&&t.timen-e&&t.timei.options.maxZoom)){var r=a.getBounds(),s=r.getEast()-r.getWest(),h=r.getNorth()-r.getSouth(),l=a.getSize(),u=s/l.x,c=h/l.y,p=this.canvasLayer.getTopLeft(),v=a.latLngToContainerPoint(p),d={transferCoordinate:function(t){var e,n={x:(e="2d"===i.context?a.latLngToContainerPoint(L.latLng(t[1],t[0])):{x:(t[0]-p.lng)/u,y:(p.lat-t[1])/c}).x-v.x,y:e.y-v.y};return[n.x,n.y]}};void 0!==n&&(d.filter=function(t){var e=o.trails||10;return n&&t.time>n-e&&t.timen-e&&t.timeh||Math.abs(r.y)>h){var s=1/Math.pow((n={source:y[o[a]][e],target:y[t][e]},Math.sqrt(Math.pow(n.source.x-n.target.x,2)+Math.pow(n.source.y-n.target.y,2))),1);i.x+=r.x*s,i.y+=r.y*s}}return i}function E(t,e,n){for(var i,o,a,r,s,h,l,u,c=x/(_(m[t])*(e+1)),p=[{x:0,y:0}],v=1;v=g&&(l[t].push(e),l[e].push(t)));var n,i}();for(var i=0;i