import"leaflet/src/control/index.js";import"leaflet/src/layer/Tooltip.js";import"leaflet/src/layer/vector/Renderer.getRenderer.js";import{Layer as t,setOptions as i,Util as s,Browser as a,DomUtil as e,Bounds as n,point as h}from"leaflet/src/Leaflet.js";import{Simpleheat as o}from"./simpleheat.js";const r=t.extend({initialize(t,s){this._latlngs=t,i(this,s)},setLatLngs(t){return this._latlngs=t,this.redraw()},addLatLng(t){return this._latlngs.push(t),this.redraw()},setOptions(t){return i(this,t),this._heat&&this._updateOptions(),this.redraw()},redraw(){return this._heat&&!this._frame&&this._map&&!this._map._animating&&(this._frame=s.requestAnimFrame(this._redraw,this)),this},onAdd(t){this._map=t,this._canvas||this._initCanvas(),this.options.pane?this.getPane().appendChild(this._canvas):t._panes.overlayPane.appendChild(this._canvas),t.on("moveend",this._reset,this),t.options.zoomAnimation&&a.any3d&&t.on("zoomanim",this._animateZoom,this),this._reset()},onRemove(t){this.options.pane?this.getPane().removeChild(this._canvas):t.getPanes().overlayPane.removeChild(this._canvas),t.off("moveend",this._reset,this),t.options.zoomAnimation&&t.off("zoomanim",this._animateZoom,this)},addTo(t){return t.addLayer(this),this},_initCanvas(){const t=this._canvas=e.create("canvas","leaflet-heatmap-layer leaflet-layer"),i=e.testProp(["transformOrigin","WebkitTransformOrigin","msTransformOrigin"]);t.style[i]="50% 50%";const s=this._map.getSize();t.width=s.x,t.height=s.y;const n=this._map.options.zoomAnimation&&a.any3d;e.addClass(t,"leaflet-zoom-"+(n?"animated":"hide")),this._heat=new o(t),this._updateOptions()},_updateOptions(){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(){const t=this._map.containerPointToLayerPoint([0,0]);e.setPosition(this._canvas,t);const 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(){if(!this._map)return;const t=[],i=this._heat._r,s=this._map.getSize(),a=new n(h([-i,-i]),s.add([i,i])),e=null==this.options.max?1:this.options.max,o=null==this.options.maxZoom?this._map.getMaxZoom():this.options.maxZoom,r=1/Math.pow(2,Math.max(0,Math.min(o-this._map.getZoom(),12))),_=i/2,m=[],l=this._map._getMapPanePos(),p=l.x%_,d=l.y%_;let g,c,f,u,v,y,x,w,P;for(g=0,c=this._latlngs.length;g<c;g++)if(f=this._map.latLngToContainerPoint(this._latlngs[g]),a.contains(f)){v=Math.floor((f.x-p)/_)+2,y=Math.floor((f.y-d)/_)+2;P=this._getAlt(g)*r,m[y]=m[y]||[],u=m[y][v],u?(u[0]=(u[0]*u[2]+f.x*P)/(u[2]+P),u[1]=(u[1]*u[2]+f.y*P)/(u[2]+P),u[2]+=P):m[y][v]=[f.x,f.y,P]}for(g=0,c=m.length;g<c;g++)if(m[g])for(x=0,w=m[g].length;x<w;x++)u=m[g][x],u&&t.push([Math.round(u[0]),Math.round(u[1]),Math.min(u[2],e)]);this._heat.data(t).draw(this.options.minOpacity),this._frame=null},_getAlt(t){return null!=this._latlngs[t].alt?this._latlngs[t].alt:null!=this._latlngs[t][2]?+this._latlngs[t][2]:1},_animateZoom(t){const i=this._map.getZoomScale(t.zoom),s=this._map._getCenterOffset(t.center)._multiplyBy(-i).subtract(this._map._getMapPanePos());e.setTransform(this._canvas,s,i)}});export{r as HeatLayer};
//# sourceMappingURL=leaflet-heat.js.map
