yymap-heatmap
Advanced tools
Comparing version 0.0.5 to 0.0.6
/*! | ||
* yymap-heatmap v0.0.5 | ||
* yymap-heatmap v0.0.6 | ||
* this is extends yymap(require yy.js) | ||
* build by Iverson.hu, more info concat me:hudy@yeyoo.cn | ||
*/ | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("yymap")):"function"==typeof define&&define.amd?define(["exports","yymap"],e):e((t=t||self).yymap=t.YY||{},t.yymap)}(this,function(t,e){"use strict";function r(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}var i,s=(function(t){function e(t){if(!(this instanceof e))return new e(t);this._canvas=t="string"==typeof t?document.getElementById(t):t,this._ctx=t.getContext("2d"),this._width=t.width,this._height=t.height,this._max=1,this._data=[]}(t.exports=e).prototype={defaultRadius:25,defaultGradient:{.4:"blue",.6:"cyan",.7:"lime",.8:"yellow",1:"red"},data:function(t){return this._data=t,this},max:function(t){return this._max=t,this},add:function(t){return this._data.push(t),this},clear:function(){return this._data=[],this},radius:function(t,e){e=void 0===e?15:e;var i=this._circle=this._createCanvas(),a=i.getContext("2d"),r=this._r=t+e;return i.width=i.height=2*r,a.shadowOffsetX=a.shadowOffsetY=2*r,a.shadowBlur=e,a.shadowColor="black",a.beginPath(),a.arc(-r,-r,t,0,2*Math.PI,!0),a.closePath(),a.fill(),this},resize:function(){this._width=this._canvas.width,this._height=this._canvas.height},gradient:function(t){var e=this._createCanvas(),i=e.getContext("2d"),a=i.createLinearGradient(0,0,0,256);for(var r in e.width=1,e.height=256,t)a.addColorStop(+r,t[r]);return i.fillStyle=a,i.fillRect(0,0,1,256),this._grad=i.getImageData(0,0,1,256).data,this},draw:function(t){this._circle||this.radius(this.defaultRadius),this._grad||this.gradient(this.defaultGradient);var e=this._ctx;e.clearRect(0,0,this._width,this._height);for(var i,a=0,r=this._data.length;a<r;a++)i=this._data[a],e.globalAlpha=Math.max(i[2]/this._max,void 0===t?.05:t),e.drawImage(this._circle,i[0]-this._r,i[1]-this._r);var n=e.getImageData(0,0,this._width,this._height);return this._colorize(n.data,this._grad),e.putImageData(n,0,0),this},_colorize:function(t,e){for(var i,a=0,r=t.length;a<r;a+=4)(i=4*t[a+3])&&(t[a]=e[i],t[a+1]=e[1+i],t[a+2]=e[2+i])},_createCanvas:function(){return"undefined"!=typeof document?document.createElement("canvas"):new this._canvas.constructor}}}(i={exports:{}},i.exports),i.exports),a="yymap-heatmap",n="0.0.5",o=function(t,e,i){return e&&h(t.prototype,e),i&&h(t,i),t};function h(t,e){for(var i=0;i<e.length;i++){var a=e[i];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(t,a.key,a)}}function u(t,e,i){null===t&&(t=Function.prototype);var a=Object.getOwnPropertyDescriptor(t,e);if(void 0===a){var r=Object.getPrototypeOf(t);return null===r?void 0:u(r,e,i)}if("value"in a)return a.value;var n=a.get;return void 0!==n?n.call(i):void 0}function c(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)}function d(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?t:e}var P=e.getNamespace().maptalks,l={max:1,gradient:{.4:"blue",.6:"cyan",.7:"lime",.8:"yellow",1:"red"},radius:15,blur:15,minOpacity:.05};function f(t){if(Array.isArray(t[0])){var i=[];return t.forEach(function(t){var e=void 0;e=t instanceof P.Coordinate?[t.x,t.y]:t,i.push(e)}),i}var e=void 0;if(t instanceof P.Coordinate)t.x,t.y;else e=t;return e}var p,_,y=(p=P.Layer,c(v,p),o(v,[{key:"getData",value:function(){return this._heats}},{key:"setData",value:function(t){return t=f(t),this._heats=t||[],this.redraw()}},{key:"addData",value:function(t){return t?((t=f(t))[0]&&Array.isArray(t[0])?P.Util.pushIn(this._heats,t):this._heats.push(t),this.redraw()):this}},{key:"onConfig",value:function(t){for(var e in t)if(l[e])return this.redraw();return this}},{key:"setOpacity",value:function(t){return u(v.prototype.__proto__||Object.getPrototypeOf(v.prototype),"setOpacity",this).call(this,t),this.redraw(),this}},{key:"redraw",value:function(){var t=this._getRenderer();return t&&(t.clearHeatCache(),t.setToRedraw()),this}},{key:"isEmpty",value:function(){return!this._heats.length}},{key:"clear",value:function(){return this._heats=[],this.redraw(),this.fire("clear"),this}},{key:"toJSON",value:function(t){t=t||{};var e={type:this.getJSONType(),id:this.getId(),options:this.config()},i=this.getData();if(t.clipExtent){var a=new P.Extent(t.clipExtent),r=this._getHeatRadius();r&&(a=a._expand(r));for(var n=[],o=0,s=i.length;o<s;o++)a.contains(new P.Coordinate(i[o][0],i[o][1]))&&n.push(i[o]);e.data=n}else e.data=i;return e}},{key:"_getHeatRadius",value:function(){return this._getRenderer()?this._getRenderer()._heatRadius:null}}],[{key:"fromJSON",value:function(t){return t&&"HeatLayer"===t.type?new v(t.id,t.data,t.options):null}}]),v);function v(t,e,i){r(this,v),Array.isArray(e)||(i=e,e=null);var a=d(this,(v.__proto__||Object.getPrototypeOf(v)).call(this,t,i));return a._heats=e||[],a}function g(){return r(this,g),d(this,(g.__proto__||Object.getPrototypeOf(g)).apply(this,arguments))}y.mergeOptions(l),y.registerJSONType("HeatLayer"),y.registerRenderer("canvas",(_=P.renderer.CanvasRenderer,c(g,_),o(g,[{key:"draw",value:function(){var e=this.getMap(),t=this.layer,i=e.getContainerExtent(),a=this.prepareCanvas(),r=i;if(a){if(!(a=a.convertTo(function(t){return e._pointToContainerPoint(t)})).intersects(i))return void this.completeRender();r=i.intersection(a)}this._heater||(this._heater=s(this.canvas)),this._heater.radius(t.options.radius||this._heater.defaultRadius,t.options.blur),t.options.gradient&&this._heater.gradient(t.options.gradient),this._heater.max(t.options.max),this._heatViews||(this._heatViews=[]);var n=t.getData();if(0!==n.length){var o=this._heatData(n,r);0<this._heater._width&&0<this._heater._height&&this._heater.data(o).draw(t.options.minOpacity),this.completeRender()}else this.completeRender()}},{key:"drawOnInteracting",value:function(){this.draw()}},{key:"_heatData",value:function(t,e){var i=this.getMap(),a=this.layer,r=i.getProjection(),n=[],o=this._heater._r,s=void 0===a.options.max?1:a.options.max,h=P.Util.isNil(a.options.maxZoom)?i.getMaxZoom():a.options.maxZoom,u=1/Math.pow(2,Math.max(0,Math.min(h-i.getZoom(),12))),c=o/2,d=[],l=i.offsetPlatform(),f=l.x%c,p=l.y%c,_=void 0,y=void 0,v=void 0,g=void 0,m=void 0,w=void 0;e=e.expand(o).convertTo(function(t){return new P.Point(i._containerPointToPrj(t))}),this._heatRadius=o;for(var x=0,O=t.length;x<O;x++)_=t[x],this._heatViews[x]||(this._heatViews[x]=r.project(new P.Coordinate(_[0],_[1]))),y=this._heatViews[x],e.contains(y)&&(y=i._prjToContainerPoint(y),g=Math.floor((y.x-f)/c)+2,m=Math.floor((y.y-p)/c)+2,w=(void 0!==_.alt?_.alt:void 0!==_[2]?+_[2]:1)*u,d[m]=d[m]||[],(v=d[m][g])?(v[0]=(v[0]*v[2]+y.x*w)/(v[2]+w),v[1]=(v[1]*v[2]+y.y*w)/(v[2]+w),v[2]+=w):d[m][g]=[y.x,y.y,w]);for(var b=0,C=d.length;b<C;b++)if(d[b])for(var R=0,k=d[b].length;R<k;R++)(v=d[b][R])&&n.push([Math.round(v[0]),Math.round(v[1]),Math.min(v[2],s)]);return n}},{key:"onZoomEnd",value:function(){delete this._heatViews,u(g.prototype.__proto__||Object.getPrototypeOf(g.prototype),"onZoomEnd",this).apply(this,arguments)}},{key:"onResize",value:function(){if(this.canvas){var t=this.getMap().getSize(),e=t.width,i=t.height;this._heater._canvas.width=e,this._heater._canvas.height=i,this._heater.resize()}u(g.prototype.__proto__||Object.getPrototypeOf(g.prototype),"onResize",this).apply(this,arguments)}},{key:"onRemove",value:function(){this.clearHeatCache(),delete this._heater}},{key:"clearHeatCache",value:function(){delete this._heatViews}}]),g)),null!=console&&console.log(a+","+n),t.HeatLayer=y,Object.defineProperty(t,"__esModule",{value:!0})}); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("yymap")):"function"==typeof define&&define.amd?define(["exports","yymap"],t):t((e=e||self).yymap=e.YY||{},e.yymap)}(this,function(e,t){"use strict";function n(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var a="yymap-heatmap",r="0.0.6",i=function(e,t,a){return t&&o(e.prototype,t),a&&o(e,a),e};function o(e,t){for(var a=0;a<t.length;a++){var r=t[a];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function s(e,t,a){null===e&&(e=Function.prototype);var r=Object.getOwnPropertyDescriptor(e,t);if(void 0===r){var n=Object.getPrototypeOf(e);return null===n?void 0:s(n,t,a)}if("value"in r)return r.value;var i=r.get;return void 0!==i?i.call(a):void 0}function u(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}function l(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}var b=function(e,t){if(Array.isArray(e))return e;if(Symbol.iterator in Object(e))return function(e,t){var a=[],r=!0,n=!1,i=void 0;try{for(var o,s=e[Symbol.iterator]();!(r=(o=s.next()).done)&&(a.push(o.value),!t||a.length!==t);r=!0);}catch(e){n=!0,i=e}finally{try{!r&&s.return&&s.return()}finally{if(n)throw i}}return a}(e,t);throw new TypeError("Invalid attempt to destructure non-iterable instance")},x=(i(c,[{key:"initPalette",value:function(){var e=this.gradient,t=void 0;"undefined"==typeof document||(t=document.createElement("canvas")),t.width=256,t.height=1;var a=this.paletteCtx=t.getContext("2d"),r=a.createLinearGradient(0,0,256,1);for(var n in e)r.addColorStop(parseFloat(n),e[n]);a.fillStyle=r,a.fillRect(0,0,256,1)}},{key:"getColor",value:function(e){var t=this.max;t<e&&(e=t);var a=4*Math.floor(e/t*255),r=this.paletteCtx.getImageData(0,0,256,1).data;return"rgba("+r[a]+", "+r[1+a]+", "+r[2+a]+", "+r[3+a]/256+")"}},{key:"getSize",value:function(e){var t=this.max;return t<e&&(e=t),e/t*this.maxSize}}]),c);function c(e){n(this,c),e=e||{},this.gradient=e.gradient||{.25:"rgba(0, 0, 255, 1)",.55:"rgba(0, 255, 0, 1)",.85:"rgba(255, 255, 0, 1)",1:"rgba(255, 0, 0, 1)"},this.maxSize=e.maxSize||35,this.max=e.max||100,this.initPalette()}function h(){n(this,h)}var f=new(i(h,[{key:"getImageData",value:function(e){var t=e.gradient||e.defaultGradient,a=void 0;"undefined"==typeof document||(a=document.createElement("canvas"));var r=a.getContext("2d");a.width=256,a.height=1;var n=r.createLinearGradient(0,0,256,1);for(var i in t)n.addColorStop(parseFloat(i),t[i]);return r.fillStyle=n,r.fillRect(0,0,256,1),r.getImageData(0,0,256,1).data}}]),h),d={},O={},k=(i(y,[{key:"createCircle",value:function(e){if(d[e])return d[e];var t=void 0;"undefined"==typeof document||(t=document.createElement("canvas"));var a=t.getContext("2d"),r=e/2,n=e+r;return t.width=t.height=2*n,a.shadowBlur=r,a.shadowColor="black",a.shadowOffsetX=a.shadowOffsetY=1e4,a.beginPath(),a.arc(n-1e4,n-1e4,e,0,2*Math.PI,!0),a.closePath(),a.fill(),d[e]=t}},{key:"colorize",value:function(e,t,a){for(var r,n=a.maxOpacity||.8,i=3,o=e.length;i<o;i+=4)r=4*e[i],e[i]/256>n&&(e[i]=256*n),e[i-3]=t[r],e[i-2]=t[1+r],e[i-1]=t[2+r]}},{key:"drawGray",value:function(e,t,a){var r=a.max||100,n=(a.minOpacity,a.size||13);for(var i in a)e[i]=a[i];var o=JSON.stringify({gradient:a.gradient,max:r}),s=void 0;O[o]?s=O[o]:(s=new x({gradient:a.gradient,max:r}),O[o]=s);for(var u=this.createCircle(n),l={},c=0,h=t.length;c<h;c++){var f=t[c],d=void 0===f.count?1:f.count,y=Math.min(1,d/r).toFixed(2);l[y]=l[y]||[],l[y].push(f)}for(var p in l)if(!isNaN(p)){var v=l[p];a.withoutAlpha||(e.globalAlpha=p);for(var g=0,m=v.length;g<m;g++){var _=v[g],w=_.xy;if("Point"===_.type){var b=void 0===_.count?1:_.count;e.globalAlpha=b/r,e.drawImage(u,w[0]-u.width/2,w[1]-u.height/2)}}}}},{key:"draw",value:function(e,t,a){if(a=a||{},e.save(),this.drawGray(e,t,a),!a.absolute){var r=e.getImageData(0,0,e.canvas.width,e.canvas.height);this.colorize(r.data,f.getImageData({defaultGradient:a.gradient||{.25:"rgba(0, 0, 255, 1)",.55:"rgba(0, 255, 0, 1)",.85:"rgba(255, 255, 0, 1)",1:"rgba(255, 0, 0, 1)"}}),a),e.putImageData(r,0,0),e.restore()}}}]),y);function y(){n(this,y)}var C=t.getNamespace().maptalks,p={max:15,gradient:{.4:"blue",.6:"cyan",.7:"lime",.8:"yellow",1:"red"},radius:15,blur:15,minOpacity:.05,size:10};function v(e){if(Array.isArray(e[0])){var a=[];return e.forEach(function(e){var t=void 0;t=e instanceof C.Coordinate?[e.x,e.y]:e,a.push(t)}),a}var t=void 0;if(e instanceof C.Coordinate)e.x,e.y;else t=e;return t}var g,m,_=(g=C.Layer,u(w,g),i(w,[{key:"getData",value:function(){return this._heats}},{key:"setData",value:function(e){return e=v(e),this._heats=e||[],this.redraw()}},{key:"addData",value:function(e){return e?((e=v(e))[0]&&Array.isArray(e[0])?C.Util.pushIn(this._heats,e):this._heats.push(e),this.redraw()):this}},{key:"onConfig",value:function(e){for(var t in e)if(p[t])return this.redraw();return this}},{key:"setOpacity",value:function(e){return s(w.prototype.__proto__||Object.getPrototypeOf(w.prototype),"setOpacity",this).call(this,e),this.redraw(),this}},{key:"redraw",value:function(){var e=this._getRenderer();return e&&(e.clearHeatCache(),e.setToRedraw()),this}},{key:"isEmpty",value:function(){return!this._heats.length}},{key:"clear",value:function(){return this._heats=[],this.redraw(),this.fire("clear"),this}},{key:"toJSON",value:function(e){e=e||{};var t={type:this.getJSONType(),id:this.getId(),options:this.config()},a=this.getData();if(e.clipExtent){var r=new C.Extent(e.clipExtent),n=this._getHeatRadius();n&&(r=r._expand(n));for(var i=[],o=0,s=a.length;o<s;o++)r.contains(new C.Coordinate(a[o][0],a[o][1]))&&i.push(a[o]);t.data=i}else t.data=a;return t}},{key:"_getHeatRadius",value:function(){return this._getRenderer()?this._getRenderer()._heatRadius:null}}],[{key:"fromJSON",value:function(e){return e&&"HeatLayer"===e.type?new w(e.id,e.data,e.options):null}}]),w);function w(e,t,a){n(this,w),Array.isArray(t)||(a=t,t=null);var r=l(this,(w.__proto__||Object.getPrototypeOf(w)).call(this,e,a));return r._heats=t||[],r}function P(){return n(this,P),l(this,(P.__proto__||Object.getPrototypeOf(P)).apply(this,arguments))}_.mergeOptions(p),_.registerJSONType("HeatLayer"),_.registerRenderer("canvas",(m=C.renderer.CanvasRenderer,u(P,m),i(P,[{key:"draw",value:function(){var t=this.getMap(),e=this.layer,a=t.getContainerExtent(),r=this.prepareCanvas();if(r){if(!(r=r.convertTo(function(e){return t._pointToContainerPoint(e)})).intersects(a))return void this.completeRender();a.intersection(r)}this._heater||(this._heater=new k);var n=e.getData();if(0!==n.length){for(var i=t.getExtent(),o=i.xmin,s=i.ymin,u=i.xmax,l=i.ymax,c=o<u&&s<l,h=t.getSize(),f=h.width,d=h.height,y=[],p=0,v=n.length;p<v;p++){var g=b(n[p],2),m=g[0],_=g[1];if(!c||!(m<o||u<m||_<s||l<_)){n[p]._c||(n[p]._c=new C.Coordinate(n[p]));var w=t.coordToContainerPoint(n[p]._c);w.x<0||w.x>f||w.y<0||w.y>d||y.push({xy:[w.x,w.y],count:n[p][2]||1,type:"Point"})}}this._heater.draw(this.context,y,this.layer.options),this.completeRender()}else this.completeRender()}},{key:"drawOnInteracting",value:function(){this.draw()}},{key:"onZoomEnd",value:function(){delete this._heatViews,s(P.prototype.__proto__||Object.getPrototypeOf(P.prototype),"onZoomEnd",this).apply(this,arguments)}},{key:"onResize",value:function(){if(this.canvas){var e=this.getMap().getSize();e.width,e.height}s(P.prototype.__proto__||Object.getPrototypeOf(P.prototype),"onResize",this).apply(this,arguments)}},{key:"onRemove",value:function(){this.clearHeatCache(),delete this._heater}},{key:"clearHeatCache",value:function(){delete this._heatViews}}]),P)),null!=console&&console.log(a+","+r),e.HeatLayer=_,Object.defineProperty(e,"__esModule",{value:!0})}); |
{ | ||
"name": "yymap-heatmap", | ||
"version": "0.0.5", | ||
"version": "0.0.6", | ||
"description": "A heatmap layer plugin for YYMap.js. ", | ||
@@ -5,0 +5,0 @@ "main": "dist/yymap-heatmap.min.js", |
11904