/*! * Copyright (c) 2016, Baidu, Inc. All rights reserved. * mapv.(http://mapv.baidu.com) * github: https://github.com/huiyan-fe/mapv * license: BSD 3-clause "New" or "Revised" * version: 2.0.20 */ !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";var e=function(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;in&&(n=o)}return n}},g.prototype.getSum=function(t){var e=this._data;if(e&&!(e.length<=0)){for(var n=0,i=0;in&&(t=n),te&&(t=e),to&&(t[a]=256*o),t[a-3]=e[i],t[a-2]=e[i+1],t[a-1]=e[i+2]}(l.data,s.getImageData(),n),t.putImageData(l,0,0),t.restore()}s=null,o=null}}},x={draw:function(t,e,n){t.save();for(var i=e instanceof g?e.get():e,o={},a=n._size||n.size||50,r=n.offset||{x:0,y:0},s=0;s1){var x=d-y,_=y+(db*b+S*S&&(y=_+(1&f?1:-1)/2,f=w)}var M=y+"-"+f,C=h[M];C?C.push(i[u]):((C=h[M]=[i[u]]).i=y,C.j=f,C.x=(y+(1&f?.5:0))*s,C.y=f*l)}var A,L,P,k,E=new v({max:n.max||100,maxSize:r,gradient:n.gradient});for(var o in h){var z=h[o];t.beginPath();for(var F=0;F<6;F++){var R=(A={x:z.x+a.x,y:z.y+a.y},L=r,void 0,void 0,P=60*F+30,k=Math.PI/180*P,[A.x+L*Math.cos(k),A.y+L*Math.sin(k)]);t.lineTo(R[0],R[1])}t.closePath();var I=0;for(u=0;u1||f<-1||f>1||(h.push(p,f),u++)}var v=new Float32Array(h),d=u,y=t.createBuffer();t.bindBuffer(t.ARRAY_BUFFER,y),t.bufferData(t.ARRAY_BUFFER,v,t.STATIC_DRAW),t.vertexAttribPointer(o,2,t.FLOAT,!1,0,0),t.enableVertexAttribArray(o),t.vertexAttrib1f(a,n._size);var m=S(n.fillStyle||"red");t.uniform4f(r,m[0]/255,m[1]/255,m[2]/255,m[3]/255),t.drawArrays(t.POINTS,0,d)}}};function z(t,e,n){n=n||2;var i,o,a,r,s,l,h,u=e&&e.length,g=u?e[0]*n:t.length,c=F(t,0,g,n,!0),p=[];if(!c)return p;if(u&&(c=function(t,e,n,i){var o,a,r,s,l,h=[];for(o=0,a=e.length;o80*n){i=a=t[0],o=r=t[1];for(var f=n;fa&&(a=s),l>r&&(r=l);h=Math.max(a-i,r-o)}return I(c,p,n,i,o,h),p}function F(t,e,n,i,o){var a,r;if(o===K(t,e,n,i)>0)for(a=e;a=e;a-=i)r=V(a,t[a],t[a+1],r);return r&&q(r,r.next)&&(Q(r),r=r.next),r}function R(t,e){if(!t)return t;e||(e=t);var n,i=t;do{if(n=!1,i.steiner||!q(i,i.next)&&0!==H(i.prev,i,i.next))i=i.next;else{if(Q(i),(i=e=i.prev)===i.next)return null;n=!0}}while(n||i!==e);return e}function I(t,e,n,i,o,a,r){if(t){!r&&a&&function(t,e,n,i){var o=t;do{null===o.z&&(o.z=Z(o.x,o.y,e,n,i)),o.prevZ=o.prev,o.nextZ=o.next,o=o.next}while(o!==t);o.prevZ.nextZ=null,o.prevZ=null,function(t){var e,n,i,o,a,r,s,l,h=1;do{for(n=t,t=null,a=null,r=0;n;){for(r++,i=n,s=0,e=0;e0||l>0&&i;)0===s?(o=i,i=i.nextZ,l--):0!==l&&i?n.z<=i.z?(o=n,n=n.nextZ,s--):(o=i,i=i.nextZ,l--):(o=n,n=n.nextZ,s--),a?a.nextZ=o:t=o,o.prevZ=a,a=o;n=i}a.nextZ=null,h*=2}while(r>1)}(o)}(t,i,o,a);for(var s,l,h=t;t.prev!==t.next;)if(s=t.prev,l=t.next,a?O(t,i,o,a):T(t))e.push(s.i/n),e.push(t.i/n),e.push(l.i/n),Q(t),t=l.next,h=l.next;else if((t=l)===h){r?1===r?I(t=B(t,e,n),e,n,i,o,a,2):2===r&&D(t,e,n,i,o,a):I(R(t),e,n,i,o,a,1);break}}}function T(t){var e=t.prev,n=t,i=t.next;if(H(e,n,i)>=0)return!1;for(var o=t.next.next;o!==t.prev;){if(W(e.x,e.y,n.x,n.y,i.x,i.y,o.x,o.y)&&H(o.prev,o,o.next)>=0)return!1;o=o.next}return!0}function O(t,e,n,i){var o=t.prev,a=t,r=t.next;if(H(o,a,r)>=0)return!1;for(var s=o.xa.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,g=Z(s,l,e,n,i),c=Z(h,u,e,n,i),p=t.nextZ;p&&p.z<=c;){if(p!==t.prev&&p!==t.next&&W(o.x,o.y,a.x,a.y,r.x,r.y,p.x,p.y)&&H(p.prev,p,p.next)>=0)return!1;p=p.nextZ}for(p=t.prevZ;p&&p.z>=g;){if(p!==t.prev&&p!==t.next&&W(o.x,o.y,a.x,a.y,r.x,r.y,p.x,p.y)&&H(p.prev,p,p.next)>=0)return!1;p=p.prevZ}return!0}function B(t,e,n){var i=t;do{var o=i.prev,a=i.next.next;!q(o,a)&&Y(o,i,i.next,a)&&G(o,a)&&G(a,o)&&(e.push(o.i/n),e.push(i.i/n),e.push(a.i/n),Q(i),Q(i.next),i=t=a),i=i.next}while(i!==t);return i}function D(t,e,n,i,o,a){var r,s,l=t;do{for(var h=l.next.next;h!==l.prev;){if(l.i!==h.i&&(s=h,(r=l).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&&Y(n,n.next,t,e))return!0;n=n.next}while(n!==t);return!1}(r,s)&&G(r,s)&&G(s,r)&&function(t,e){var n=t,i=!1,o=(t.x+e.x)/2,a=(t.y+e.y)/2;do{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}while(n!==t);return i}(r,s))){var u=J(l,h);return l=R(l,l.next),u=R(u,u.next),I(l,e,n,i,o,a),void I(u,e,n,i,o,a)}h=h.next}l=l.next}while(l!==t)}function N(t,e){return t.x-e.x}function U(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&&s>r){if(r=s,s===o){if(a===i.y)return i;if(a===i.next.y)return i.next}n=i.x=i.x&&i.x>=u&&W(an.x)&&G(i,t)&&(n=i,c=l),i=i.next;return n}(t,e)){var n=J(e,t);R(n,n.next)}}function Z(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 j(t){var e=t,n=t;do{e.x=0&&(t-r)*(i-s)-(n-r)*(e-s)>=0&&(n-r)*(a-s)-(o-r)*(i-s)>=0}function H(t,e,n){return(e.y-t.y)*(n.x-e.x)-(e.x-t.x)*(n.y-e.y)}function q(t,e){return t.x===e.x&&t.y===e.y}function Y(t,e,n,i){return!!(q(t,e)&&q(n,i)||q(t,i)&&q(n,e))||H(t,e,n)>0!=H(t,e,i)>0&&H(n,i,t)>0!=H(n,i,e)>0}function G(t,e){return H(t.prev,t,t.next)<0?H(t,e,t.next)>=0&&H(t,t.prev,e)>=0:H(t,e,t.prev)<0||H(t,t.next,e)<0}function J(t,e){var n=new X(t.i,t.x,t.y),i=new X(e.i,e.x,e.y),o=t.next,a=e.prev;return t.next=e,e.prev=t,n.next=o,o.prev=n,i.next=n,n.prev=i,a.next=i,i.prev=a,i}function V(t,e,n,i){var o=new X(t,e,n);return i?(o.next=i.next,o.prev=i,i.next.prev=o,i.next=o):(o.prev=o,o.next=o),o}function Q(t){t.next.prev=t.prev,t.prev.next=t.next,t.prevZ&&(t.prevZ.nextZ=t.nextZ),t.nextZ&&(t.nextZ.prevZ=t.prevZ)}function X(t,e,n){this.i=t,this.x=e,this.y=n,this.prev=null,this.next=null,this.z=null,this.prevZ=null,this.nextZ=null,this.steiner=!1}function K(t,e,n,i){for(var o=0,a=e,r=n-i;a0&&(i+=t[o-1].length,n.holes.push(i))}return n};var $=["attribute vec4 a_Position;","void main() {","gl_Position = a_Position;","gl_PointSize = 30.0;","}"].join(""),tt=["precision mediump float;","uniform vec4 u_FragColor;","void main() {","gl_FragColor = u_FragColor;","}"].join("");var et={draw:function(t,e,n){if(e){t.clear(t.COLOR_BUFFER_BIT),t.viewport(0,0,t.canvas.width,t.canvas.height);var i=b(t,$,tt);t.enable(t.BLEND),t.blendFunc(t.SRC_ALPHA,t.ONE);var o=t.canvas.width/2,a=t.canvas.height/2;t.bindBuffer(t.ARRAY_BUFFER,t.createBuffer()),t.bindBuffer(t.ELEMENT_ARRAY_BUFFER,t.createBuffer());var r=t.getAttribLocation(i,"a_Position");t.vertexAttribPointer(r,2,t.FLOAT,!1,0,0),t.enableVertexAttribArray(r);var s=t.getUniformLocation(i,"u_FragColor"),l=S(n.fillStyle||"red");t.uniform4f(s,l[0]/255,l[1]/255,l[2]/255,l[3]/255),t.lineWidth(n.lineWidth||1);for(var h=[],u=[],g=0,c=0,p=e.length;c65536&&(t.bufferData(t.ARRAY_BUFFER,new Float32Array(h),t.STATIC_DRAW),t.bufferData(t.ELEMENT_ARRAY_BUFFER,new Uint16Array(u),t.STATIC_DRAW),t.drawElements(t.TRIANGLES,u.length,t.UNSIGNED_SHORT,0),h.length=0,u.length=0,g=0),d=0;d0&&("LineString"==i[0].geometry.type?A.draw(t,i,n):"Polygon"==i[0].geometry.type||"MultiPolygon"==i[0].geometry.type?et.draw(t,i,n):E.draw(t,i,n))}};function it(t,e,n){if(!t||!e)return null;var i,o,a,r,s,l,h=function(t){return 1-2*t+t*t},u=function(t){return 2*t-2*t*t},g=function(t){return t*t},c=[],p=(n=n||40,0),f=0;if(void 0!==e){var v=parseFloat(t.lat),d=parseFloat(e.lat),y=parseFloat(t.lng),m=parseFloat(e.lng);for(m>y&&parseFloat(m-y)>180&&y<0&&(y=parseFloat(360+y)),y>m&&parseFloat(y-m)>180&&m<0&&(m=parseFloat(360+m)),0,l=0,d==v?(i=0,o=y-m):m==y?(i=Math.PI/2,o=v-d):(i=Math.atan((d-v)/(m-y)),o=(d-v)/Math.sin(i)),0==l&&(l=i+Math.PI/5),s=(a=o/2)*Math.cos(l)+y,r=a*Math.sin(l)+v,p=0;p0&&(n=n.concat(o))}return n}};function at(t){this.splitList=t||{other:1}}function rt(t){this.splitList=t||[{start:0,value:"red"}]}at.prototype.get=function(t){var e=this.splitList,n=e.other;for(var i in e)if(t==i){n=e[i];break}return n},at.prototype.generateByDataSet=function(t,e){var n=e||["rgba(255, 255, 0, 0.8)","rgba(253, 98, 104, 0.8)","rgba(255, 146, 149, 0.8)","rgba(255, 241, 193, 0.8)","rgba(110, 176, 253, 0.8)","rgba(52, 139, 251, 0.8)","rgba(17, 102, 252, 0.8)"],i=t.get();this.splitList={};for(var o=0,a=0;a=n.length-1));a++);this.splitList.other=n[n.length-1]},at.prototype.getLegend=function(t){var e=this.splitList,n=document.createElement("div");n.style.cssText="background:#fff; padding: 5px; border: 1px solid #ccc;";var i="";for(var o in e)i+='
'+o+"
";return n.innerHTML=i,n},rt.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&&t1?1:_);for(h in o)if(void 0!==i[h]){var b=i[h]||0,S=o[h];S instanceof Array?n[h]=f(S,w):("string"==typeof S&&(S="+"===S.charAt(0)||"-"===S.charAt(0)?b+parseFloat(S):parseFloat(S)),"number"==typeof S&&(n[h]=b+(S-b)*w))}if(null!==m&&m.call(n,w),1===_){if(s>0){isFinite(s)&&s--;for(h in a){if("string"==typeof o[h]&&(a[h]=a[h]+parseFloat(o[h])),l){var M=a[h];a[h]=o[h],o[h]=M}i[h]=a[h]}return l&&(u=!u),c=void 0!==e?t+e:t+g,!0}null!==x&&x.call(n,n);for(var C=0,A=v.length;C1?a(t[n],t[n-1],n-i):a(t[o],t[o+1>n?n:o+1],i-o)},Bezier:function(t,e){for(var n=0,i=t.length-1,o=Math.pow,a=ct.Interpolation.Utils.Bernstein,r=0;r<=i;r++)n+=o(1-e,i-r)*o(e,r)*t[r]*a(i,r);return n},CatmullRom:function(t,e){var n=t.length-1,i=n*e,o=Math.floor(i),a=ct.Interpolation.Utils.CatmullRom;return t[0]===t[n]?(e<0&&(o=Math.floor(i=n*(1+e))),a(t[(o-1+n)%n],t[o],t[(o+1)%n],t[(o+2)%n],i-o)):e<0?t[0]-(a(t[0],t[0],t[1],t[1],-i)-t[0]):e>1?t[n]-(a(t[n],t[n],t[n-1],t[n-1],i-n)-t[n]):a(t[o?o-1:0],t[o],t[n1;n--)e*=n;return gt[t]=e,e}),CatmullRom:function(t,e,n,i,o){var a=.5*(n-t),r=.5*(i-e),s=o*o;return(2*e-2*n+a+r)*(o*s)+(-3*e+3*n-2*a-r)*s+a*o+e}}};var pt=function(t,e,n){var i=e instanceof g?e.get():e;t.save();for(var o in n)t[o]=n[o];var a=n.offset||{x:0,y:0},r=[],s=n._size||n.size;s?t.font="bold "+s+"px Arial":s=12;var l=n.textKey||"text";if(n.textAlign||(t.textAlign="center"),n.textBaseline||(t.textBaseline="middle"),n.avoid)for(var h=0,u=i.length;ho&&i>a}var dt=function(t,e,n){var i=e instanceof g?e.get():e;t.fillStyle="white",t.textAlign="center",t.textBaseline="middle";for(var o=n.offset||{x:0,y:0},a=0,r=i.length;ao&&(e[i]._size=a),t.lineWidth=1,t.strokeStyle=e[i].strokeStyle||e[i]._strokeStyle||n.strokeStyle||"yellow",t.stroke(),(h=e[i].fillStyle||e[i]._fillStyle||n.fillStyle)&&(t.fillStyle=h,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 l=e[i].strokeStyle||n.strokeStyle,h=e[i].fillStyle||n.fillStyle||"yellow";t.fillStyle=h,t.fill(),l&&n.lineWidth&&(t.lineWidth=n.lineWidth||1,t.strokeStyle=l,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()}}]),n}(),xt=function(t){function n(t,e,i){r(this,n);var o=u(this,(n.__proto__||Object.getPrototypeOf(n)).call(this,t,e,i)),a=o;i=i||{},o.clickEvent=o.clickEvent.bind(o),o.mousemoveEvent=o.mousemoveEvent.bind(o),a.init(i),a.argCheck(i),a.transferToMercator();var s=o.canvasLayer=new lt({map:t,context:o.context,paneName:i.paneName,mixBlendMode:i.mixBlendMode,enableMassClear:i.enableMassClear,zIndex:i.zIndex,update:function(){a._canvasUpdate()}});return e.on("change",function(){a.transferToMercator(),s.draw()}),o}return h(n,yt),s(n,[{key:"clickEvent",value:function(t){var e=t.pixel;l(n.prototype.__proto__||Object.getPrototypeOf(n.prototype),"clickEvent",this).call(this,e,t)}},{key:"mousemoveEvent",value:function(t){var e=t.pixel;l(n.prototype.__proto__||Object.getPrototypeOf(n.prototype),"mousemoveEvent",this).call(this,e,t)}},{key:"bindEvent",value:function(t){this.unbindEvent();var e=this.map;this.options.methods&&(this.options.methods.click&&(e.setDefaultCursor("default"),e.addEventListener("click",this.clickEvent)),this.options.methods.mousemove&&e.addEventListener("mousemove",this.mousemoveEvent))}},{key:"unbindEvent",value:function(t){var e=this.map;this.options.methods&&(this.options.methods.click&&e.removeEventListener("click",this.clickEvent),this.options.methods.mousemove&&e.removeEventListener("mousemove",this.mousemoveEvent))}},{key:"transferToMercator",value:function(){var t=this.map.getMapType().getProjection();if("bd09mc"!==this.options.coordType){var e=this.dataSet.get();e=this.dataSet.transferCoordinate(e,function(e){var n=t.lngLatToPoint({lng:e[0],lat:e[1]});return[n.x,n.y]},"coordinates","coordinates_mercator"),this.dataSet._set(e)}}},{key:"getContext",value:function(){return this.canvasLayer.canvas.getContext(this.context)}},{key:"_canvasUpdate",value:function(t){if(this.canvasLayer){var n=this,i=n.options.animation,o=this.canvasLayer._map,a=Math.pow(2,18-o.getZoom()),r=o.getMapType().getProjection().lngLatToPoint(o.getCenter()),s=new BMap.Pixel(r.x-o.getSize().width/2*a,r.y+o.getSize().height/2*a),l=this.getContext();if(n.isEnabledTime()){if(void 0===t)return void e(l);"2d"==this.context&&(l.save(),l.globalCompositeOperation="destination-out",l.fillStyle="rgba(0, 0, 0, .1)",l.fillRect(0,0,l.canvas.width,l.canvas.height),l.restore())}else e(l);if("2d"==this.context)for(var h in n.options)l[h]=n.options[h];else l.clear(l.COLOR_BUFFER_BIT);if(!(n.options.minZoom&&o.getZoom()n.options.maxZoom)){var u=1;"2d"!=this.context&&(u=this.canvasLayer.devicePixelRatio);var g={fromColumn:"bd09mc"==n.options.coordType?"coordinates":"coordinates_mercator",transferCoordinate:function(t){return[(t[0]-s.x)/a*u,(s.y-t[1])/a*u]}};void 0!==t&&(g.filter=function(e){var n=i.trails||10;return!!(t&&e.time>t-n&&e.timen.options.maxZoom)){var r=1;"2d"!=this.context&&(r=this.canvasLayer.devicePixelRatio);var s=this.map,l=s.getProjection(),h=(r=Math.pow(2,s.zoom)*resolutionScale,l.fromLatLngToPoint(this.canvasLayer.getTopLeft())),u={transferCoordinate:function(t){var e=new google.maps.LatLng(t[1],t[0]),n=l.fromLatLngToPoint(e),i={x:(n.x-h.x)*r,y:(n.y-h.y)*r};return[i.x,i.y]}};void 0!==t&&(u.filter=function(e){var n=i.trails||10;return!!(t&&e.time>t-n&&e.timec||Math.abs(h.y)>c){var u=1/Math.pow((a={source:i[s[l]][e],target:i[t][e]},Math.sqrt(Math.pow(a.source.x-a.target.x,2)+Math.pow(a.source.y-a.target.y,2))),1);r.x+=h.x*u,r.y+=h.y*u}}return r}function x(t,n,a){for(var r,s,l,h,u,g,c,p,v=o/(f(e[t])*(n+1)),d=[{x:0,y:0}],y=1;yr;){var u=r/h,g=i[o][l-1].x,c=i[o][l-1].y;g+=u*(i[o][l].x-i[o][l-1].x),c+=u*(i[o][l].y-i[o][l-1].y),s.push({x:g,y:c}),h-=r,r=a}r-=h}s.push(t[e[o].target]),i[o]=s}var p}function w(e,n){var i=y(t[n.source],{source:t[e.source],target:t[e.target]}),o=y(t[n.target],{source:t[e.source],target:t[e.target]}),a={x:(i.x+o.x)/2,y:(i.y+o.y)/2},r={x:(t[e.source].x+t[e.target].x)/2,y:(t[e.source].y+t[e.target].y)/2};return Math.max(0,1-2*d(r,a)/d(i,o))}function b(e,n){var i,o,a,r,s,l,h,u,g,c,v,y;return g=e,c=n,Math.abs((v=p(g),y=p(c),(v.x*y.x+v.y*y.y)/(f(g)*f(c))))*(h=n,2/((u=(f(l=e)+f(h))/2)/Math.min(f(l),f(h))+Math.max(f(l),f(h))/u))*(r=n,(s=(f(a=e)+f(r))/2)/(s+d({x:(t[a.source].x+t[a.target].x)/2,y:(t[a.source].y+t[a.target].y)/2},{x:(t[r.source].x+t[r.target].x)/2,y:(t[r.source].y+t[r.target].y)/2})))*(i=e,o=n,Math.min(w(i,o),w(o,i)))}var S=function(){var o=a,s=h,c=r;!function(){for(var n=0;n=g&&(n[t].push(i),n[i].push(t)));var o,a}();for(var p=0;p