yymap-heatmap
Advanced tools
Comparing version 0.0.7 to 0.0.8
/*! | ||
* yymap-heatmap v0.0.7 | ||
* yymap-heatmap v0.0.8 | ||
* this is extends yymap(require yy.js) | ||
* build by Iverson.hu, more info concat me:hudy@yeyoo.cn | ||
* build by Iverson.hu, more info concat me:mehudeyi@163.com | ||
*/ | ||
!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.7",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 w=v[g],_=w.xy;if("Point"===w.type){var b=void 0===w.count?1:w.count;e.globalAlpha=b/r,e.drawImage(u,_[0]-u.width/2,_[1]-u.height/2)}}}}},{key:"draw",value:function(e,t,a){var r=e.canvas;if(r&&0!==r.width&&0!==r.height&&(a=a||{},e.save(),this.drawGray(e,t,a),!a.absolute)){var n=e.getImageData(0,0,e.canvas.width,e.canvas.height);this.colorize(n.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(n,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,w=(g=C.Layer,u(_,g),i(_,[{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(_.prototype.__proto__||Object.getPrototypeOf(_.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 _(e.id,e.data,e.options):null}}]),_);function _(e,t,a){n(this,_),Array.isArray(t)||(a=t,t=null);var r=l(this,(_.__proto__||Object.getPrototypeOf(_)).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))}w.mergeOptions(p),w.registerJSONType("HeatLayer"),w.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],w=g[1];if(!c||!(m<o||u<m||w<s||l<w)){n[p]._c||(n[p]._c=new C.Coordinate(n[p]));var _=t.coordToContainerPoint(n[p]._c);_.x<0||_.x>f||_.y<0||_.y>d||y.push({xy:[_.x,_.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=w,Object.defineProperty(e,"__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.8",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 w=v[g],_=w.xy;if("Point"===w.type){var b=void 0===w.count?1:w.count;e.globalAlpha=b/r,e.drawImage(u,_[0]-u.width/2,_[1]-u.height/2)}}}}},{key:"draw",value:function(e,t,a){var r=e.canvas;if(r&&0!==r.width&&0!==r.height&&(a=a||{},e.save(),this.drawGray(e,t,a),!a.absolute)){var n=e.getImageData(0,0,e.canvas.width,e.canvas.height);this.colorize(n.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(n,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,hitDetect:!1};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,w=(g=C.Layer,u(_,g),i(_,[{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(_.prototype.__proto__||Object.getPrototypeOf(_.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 _(e.id,e.data,e.options):null}}]),_);function _(e,t,a){n(this,_),Array.isArray(t)||(a=t,t=null);var r=l(this,(_.__proto__||Object.getPrototypeOf(_)).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))}w.mergeOptions(p),w.registerJSONType("HeatLayer"),w.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],w=g[1];if(!c||!(m<o||u<m||w<s||l<w)){n[p]._c||(n[p]._c=new C.Coordinate(n[p]));var _=t.coordToContainerPoint(n[p]._c);_.x<0||_.x>f||_.y<0||_.y>d||y.push({xy:[_.x,_.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=w,Object.defineProperty(e,"__esModule",{value:!0})}); |
{ | ||
"name": "yymap-heatmap", | ||
"version": "0.0.7", | ||
"version": "0.0.8", | ||
"description": "A heatmap layer plugin for YYMap.js. ", | ||
@@ -5,0 +5,0 @@ "main": "dist/yymap-heatmap.min.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
11967