@daishu10000/leaflet-heat 0.2.1 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -8,4 +8,4 @@
8
8
  Leaflet.heat, a tiny and fast heatmap plugin for Leaflet.
9
9
  https://github.com/Leaflet/Leaflet.heat
10
10
  */
11
- L.HeatLayer=(L.Layer?L.Layer:L.Class).extend({initialize:function(t,i){this._latlngs=t,L.setOptions(this,i)},setLatLngs:function(t){return this._latlngs=t,this.redraw()},addLatLng:function(t){return this._latlngs.push(t),this.redraw()},setOptions:function(t){return L.setOptions(this,t),this._heat&&this._updateOptions(),this.redraw()},redraw:function(){return!this._heat||this._frame||this._map._animating||(this._frame=L.Util.requestAnimFrame(this._redraw,this)),this},onAdd:function(t){this._map=t,this._canvas||this._initCanvas(),t._panes.overlayPane.appendChild(this._canvas),t.on("moveend",this._reset,this),t.options.zoomAnimation&&L.Browser.any3d&&t.on("zoomanim",this._animateZoom,this),this._reset()},onRemove:function(t){t.getPanes().overlayPane.removeChild(this._canvas),t.off("moveend",this._reset,this),t.options.zoomAnimation&&t.off("zoomanim",this._animateZoom,this)},addTo:function(t){return t.addLayer(this),this},_initCanvas:function(){var t=this._canvas=L.DomUtil.create("canvas","leaflet-heatmap-layer leaflet-layer"),i=L.DomUtil.testProp(["transformOrigin","WebkitTransformOrigin","msTransformOrigin"]);t.style[i]="50% 50%";var a=this._map.getSize();t.width=a.x,t.height=a.y;var s=this._map.options.zoomAnimation&&L.Browser.any3d;L.DomUtil.addClass(t,"leaflet-zoom-"+(s?"animated":"hide")),this._heat=simpleheat(t),this._updateOptions()},_updateOptions:function(){this._heat.radius(this.options.radius||this._heat.defaultRadius,this.options.blur),this.options.gradient&&this._heat.gradient(this.options.gradient),this.options.max&&this._heat.max(this.options.max)},_reset:function(){var t=this._map.containerPointToLayerPoint([0,0]);L.DomUtil.setPosition(this._canvas,t);var i=this._map.getSize();this._heat._width!==i.x&&(this._canvas.width=this._heat._width=i.x),this._heat._height!==i.y&&(this._canvas.height=this._heat._height=i.y),this._redraw()},_redraw:function(){var t,i,a,s,e,n,h,o,r,d=[],_=this._heat._r,l=this._map.getSize(),m=new L.Bounds(L.point([-_,-_]),l.add([_,_])),c=void 0===this.options.max?1:this.options.max,u=void 0===this.options.maxZoom?this._map.getMaxZoom():this.options.maxZoom,f=1/Math.pow(2,Math.max(0,Math.min(u-this._map.getZoom(),12))),g=_/2,p=[],v=this._map._getMapPanePos(),w=v.x%g,y=v.y%g;for(t=0,i=this._latlngs.length;i>t;t++)if(a=this._map.latLngToContainerPoint(this._latlngs[t]),m.contains(L.point(a.x,a.y))){e=Math.floor((a.x-w)/g)+2,n=Math.floor((a.y-y)/g)+2;var x=void 0!==this._latlngs[t].alt?this._latlngs[t].alt:void 0!==this._latlngs[t][2]?+this._latlngs[t][2]:1;r=x*f,p[n]=p[n]||[],s=p[n][e],s?(s[0]=(s[0]*s[2]+a.x*r)/(s[2]+r),s[1]=(s[1]*s[2]+a.y*r)/(s[2]+r),s[2]+=r):p[n][e]=[a.x,a.y,r]}for(t=0,i=p.length;i>t;t++)if(p[t])for(h=0,o=p[t].length;o>h;h++)s=p[t][h],s&&d.push([Math.round(s[0]),Math.round(s[1]),Math.min(s[2],c)]);this._heat.data(d).draw(this.options.minOpacity),this._frame=null},_animateZoom:function(t){var i=this._map.getZoomScale(t.zoom),a=this._map._getCenterOffset(t.center)._multiplyBy(-i).subtract(this._map._getMapPanePos());L.DomUtil.setTransform?L.DomUtil.setTransform(this._canvas,a,i):this._canvas.style[L.DomUtil.TRANSFORM]=L.DomUtil.getTranslateString(a)+" scale("+i+")"}}),L.heatLayer=function(t,i){return new L.HeatLayer(t,i)};
11
+ L.HeatLayer=(L.Layer?L.Layer:L.Class).extend({initialize:function(t,i){this._latlngs=t,L.setOptions(this,i)},setLatLngs:function(t){return this._latlngs=t,this.redraw()},addLatLng:function(t){return this._latlngs.push(t),this.redraw()},setOptions:function(t){return L.setOptions(this,t),this._heat&&this._updateOptions(),this.redraw()},redraw:function(){return!this._heat||this._frame||this._map._animating||(this._frame=L.Util.requestAnimFrame(this._redraw,this)),this},onAdd:function(t){this._map=t,this._canvas||this._initCanvas(),t._panes.overlayPane.appendChild(this._canvas),t.on("moveend",this._reset,this),t.options.zoomAnimation&&L.Browser.any3d&&t.on("zoomanim",this._animateZoom,this),this._reset()},onRemove:function(t){t.getPanes().overlayPane.removeChild(this._canvas),t.off("moveend",this._reset,this),t.options.zoomAnimation&&t.off("zoomanim",this._animateZoom,this)},addTo:function(t){return t.addLayer(this),this},_initCanvas:function(){var t=this._canvas=L.DomUtil.create("canvas","leaflet-heatmap-layer leaflet-layer"),i=L.DomUtil.testProp(["transformOrigin","WebkitTransformOrigin","msTransformOrigin"]);t.style[i]="50% 50%";var a=this._map.getSize();t.width=a.x,t.height=a.y;var s=this._map.options.zoomAnimation&&L.Browser.any3d;L.DomUtil.addClass(t,"leaflet-zoom-"+(s?"animated":"hide")),this._heat=simpleheat(t),this._updateOptions()},_updateOptions:function(){this._heat.radius(this.options.radius||this._heat.defaultRadius,this.options.blur),this.options.gradient&&this._heat.gradient(this.options.gradient),this.options.max&&this._heat.max(this.options.max)},_reset:function(){var t=this._map.containerPointToLayerPoint([0,0]);L.DomUtil.setPosition(this._canvas,t);var i=this._map.getSize();this._heat._width!==i.x&&(this._canvas.width=this._heat._width=i.x),this._heat._height!==i.y&&(this._canvas.height=this._heat._height=i.y),this._redraw()},_redraw:function(){var t,i,a,s,e,n,h,o,r,d=[],_=this._heat._r,l=this._map.getSize(),m=new L.Bounds(L.point([-_,-_]),l.add([_,_])),c=void 0===this.options.max?1:this.options.max,u=void 0===this.options.maxZoom?this._map.getMaxZoom():this.options.maxZoom,f=1/Math.pow(2,Math.max(0,Math.min(u-this._map.getZoom(),12))),g=_/2,p=[],v=this._map._getMapPanePos(),w=v.x%g,y=v.y%g;for(t=0,i=this._latlngs.length;i>t;t++)if(a=this._map.latLngToContainerPoint(this._latlngs[t]),m.contains(L.point(a.x,a.y))){e=Math.floor((a.x-w)/g)+2,n=Math.floor((a.y-y)/g)+2;var x=void 0!==this._latlngs[t].alt?this._latlngs[t].alt:void 0!==this._latlngs[t][2]?+this._latlngs[t][2]:1;r=x*f,p[n]=p[n]||[],s=p[n][e],s?(s[0]=(s[0]*s[2]+a.x*r)/(s[2]+r),s[1]=(s[1]*s[2]+a.y*r)/(s[2]+r),s[2]+=r):p[n][e]=[a.x,a.y,r]}for(t=0,i=p.length;i>t;t++)if(p[t])for(h=0,o=p[t].length;o>h;h++)s=p[t][h],s&&d.push([Math.round(s[0]),Math.round(s[1]),Math.min(s[2],c)]);this._heat.max(c*f),this._heat.data(d).draw(this.options.minOpacity),this._frame=null},_animateZoom:function(t){var i=this._map.getZoomScale(t.zoom),a=this._map._getCenterOffset(t.center)._multiplyBy(-i).subtract(this._map._getMapPanePos());L.DomUtil.setTransform?L.DomUtil.setTransform(this._canvas,a,i):this._canvas.style[L.DomUtil.TRANSFORM]=L.DomUtil.getTranslateString(a)+" scale("+i+")"}}),L.heatLayer=function(t,i){return new L.HeatLayer(t,i)};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@daishu10000/leaflet-heat",
3
- "version": "0.2.1",
3
+ "version": "0.2.2",
4
4
  "description": "A tiny and fast Leaflet heatmap plugin (community bugfix fork).",
5
5
  "homepage": "https://github.com/Leaflet/Leaflet.heat",
6
6
  "keywords": [
package/src/HeatLayer.js CHANGED
@@ -193,6 +193,7 @@ L.HeatLayer = (L.Layer ? L.Layer : L.Class).extend({
193
193
  }
194
194
  // console.timeEnd('process');
195
195
 
196
+ this._heat.max(max * v);
196
197
  // console.time('draw ' + data.length);
197
198
  this._heat.data(data).draw(this.options.minOpacity);
198
199
  // console.timeEnd('draw ' + data.length);
package/PUBLISH_TO_NPM.md DELETED
@@ -1,127 +0,0 @@
1
- # 将修复版 Leaflet.heat 发布到 npm
2
-
3
- 原仓库长期未维护,你可以把自己的修复版本以**新包名**发布到 npm,这样别人可以通过 `npm install 你的包名` 使用。
4
-
5
- ## 一、两种发布方式
6
-
7
- ### 方式 A:Scoped 包(推荐)
8
-
9
- 用你的 npm 用户名做命名空间,例如:`@你的用户名/leaflet-heat`。
10
-
11
- - **优点**:不会和原包 `leaflet.heat` 冲突,名字清晰,安装:`npm i @你的用户名/leaflet-heat`
12
- - **缺点**:安装时要用 scoped 名
13
-
14
- ### 方式 B:全新包名
15
-
16
- 例如:`leaflet-heat-fixed`、`leaflet-heat-bugfix` 等。
17
-
18
- - **优点**:名字好记,安装:`npm i leaflet-heat-fixed`
19
- - **缺点**:需要先到 https://www.npmjs.com 搜一下名字是否已被占用
20
-
21
- ---
22
-
23
- ## 二、发布前修改 package.json
24
-
25
- 在项目根目录打开 `package.json`,至少改这两处:
26
-
27
- 1. **改包名**(二选一)
28
- - Scoped:`"name": "@你的npm用户名/leaflet-heat"`
29
- - 新名字:`"name": "leaflet-heat-fixed"`(或你喜欢的未被占用的名字)
30
-
31
- 2. **升版本**(便于和原版区分):
32
- - 例如:`"version": "0.2.1"`
33
-
34
- 如果你把代码放到了自己的 GitHub,可以顺便改:
35
-
36
- - `"repository": { "type": "git", "url": "https://github.com/你的用户名/Leaflet.heat.git" }`
37
- - `"homepage": "https://github.com/你的用户名/Leaflet.heat#readme"`
38
-
39
- ---
40
-
41
- ## 三、发布步骤
42
-
43
- 1. **注册 npm 账号**(若还没有)
44
- - 打开 https://www.npmjs.com/signup 注册。
45
-
46
- 2. **在项目根目录登录**
47
- ```bash
48
- cd 你的/Leaflet.heat/ 路径
49
- npm login
50
- ```
51
- 按提示输入用户名、密码、邮箱(和一次性验证码)。
52
-
53
- 3. **确认要发布的内容**
54
- - 发布前会打包当前目录(受 `.gitignore` / `.npmignore` 影响)。
55
- - 默认会包含 `dist/`、`package.json`、`README.md`、`LICENSE` 等;若有 `files` 字段则只发布 `files` 里列出的。
56
- - 建议:保持 `main: "dist/leaflet-heat.js"`,确保 `dist/leaflet-heat.js` 已构建好(你本地修复后重新 build 一次)。
57
-
58
- 4. **发布**
59
- - 若包名是 **scoped**(如 `@xxx/leaflet-heat`),首次发布需加 `--access public`(否则会变成私有包):
60
- ```bash
61
- npm publish --access public
62
- ```
63
- - 若包名是**普通名**(如 `leaflet-heat-fixed`):
64
- ```bash
65
- npm publish
66
- ```
67
-
68
- 5. **验证**
69
- - 到 https://www.npmjs.com 搜索你的包名,能看到说明发布成功。
70
- - 在空目录里执行:
71
- ```bash
72
- npm init -y
73
- npm i @你的用户名/leaflet-heat
74
- # 或
75
- npm i leaflet-heat-fixed
76
- ```
77
- 确认 `node_modules` 里存在且引用的是 `dist/leaflet-heat.js`。
78
-
79
- ---
80
-
81
- ## 四、以后更新版本
82
-
83
- 修改代码后:
84
-
85
- 1. 在 `package.json` 里把 `version` 改成更大(如 `0.2.2`)。
86
- 2. 若你有 `prepublish` 脚本,先本地构建:
87
- ```bash
88
- npm run prepublish
89
- ```
90
- 或直接生成 `dist/leaflet-heat.js`。
91
- 3. 再执行:
92
- ```bash
93
- npm publish
94
- ```
95
- 即可更新 npm 上的版本。
96
-
97
- ---
98
-
99
- ## 五、别人怎么用你的包
100
-
101
- 安装:
102
-
103
- ```bash
104
- npm install @你的用户名/leaflet-heat
105
- # 或
106
- npm install leaflet-heat-fixed
107
- ```
108
-
109
- 在项目里和原版一样用(入口仍是 Leaflet 热力图 API):
110
-
111
- ```javascript
112
- import 'leaflet'
113
- import 'leaflet.heat' // 若包 main 指向 dist/leaflet-heat.js,且会挂到 L.heatLayer
114
- // 或
115
- require('leaflet');
116
- require('@你的用户名/leaflet-heat');
117
- ```
118
-
119
- 若你的包没有自动把 `L.heatLayer` 挂到全局 `L`,就需要按你打包方式(例如 dist 是 UMD)在页面上先引入 Leaflet 再引入你的 heat 脚本。
120
-
121
- ---
122
-
123
- ## 六、可选:在 README 里说明
124
-
125
- 建议在 `README.md` 开头加一小段,说明这是原 Leaflet.heat 的社区修复版、修复了哪些问题、安装方式(你的包名),并保留原作者的 license 和致谢。这样别人搜索时更容易发现你的版本。
126
-
127
- 完成以上步骤后,你的修改版本就稳定地发布在 npm 上了,不依赖原仓库是否维护。