!function(t,i){"object"==typeof exports&&"undefined"!=typeof module?i(exports):"function"==typeof define&&define.amd?define(["exports"],i):i((t="undefined"!=typeof globalThis?globalThis:t||self).draw={})}(this,function(t){"use strict";function s(t,i,e,n,a){!function t(i,e,n,a,o){for(;nthis._maxEntries;)this._split(n,i),i--;this._adjustParentBBoxes(e,n,i)}_split(t,i){const e=t[i];var n=e.children.length,a=this._minEntries;this._chooseSplitAxis(e,a,n);n=this._chooseSplitIndex(e,a,n);const o=g(e.children.splice(n,e.children.length-n));o.height=e.height,o.leaf=e.leaf,l(e,this.toBBox),l(o,this.toBBox),i?t[i-1].children.push(o):this._splitRoot(e,o)}_splitRoot(t,i){this.data=g([t,i]),this.data.height=t.height+1,this.data.leaf=!1,l(this.data,this.toBBox)}_chooseSplitIndex(i,e,n){let a,o=1/0,r=1/0;for(let t=e;t<=n-e;t++){var s=p(i,0,t,this.toBBox),h=p(i,t,n,this.toBBox),m=(c=s,l=h,u=m=_=void 0,_=Math.max(c.minX,l.minX),m=Math.max(c.minY,l.minY),u=Math.min(c.maxX,l.maxX),l=Math.min(c.maxY,l.maxY),Math.max(0,u-_)*Math.max(0,l-m)),h=f(s)+f(h);m=e;t--){var m=i.children[t];c(r,i.leaf?a(m):m),s+=_(r)}return s}_adjustParentBBoxes(i,e,n){for(let t=n;0<=t;t--)c(e[t],i)}_condense(e){for(let t=e.length-1,i;0<=t;t--)0===e[t].children.length?0=t.minX&&i.maxY>=t.minY}function g(t){return{children:t,height:1,leaf:!0,minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0}}function M(t,i,e,n,a){const o=[i,e];for(;o.length;){var r;(e=o.pop())-(i=o.pop())<=n||(s(t,r=i+Math.ceil((e-i)/n/2)*n,i,e,a),o.push(i,r,r,e))}}var i=BM.CanvasMarkerLayer=BM.Layer.extend({options:{zIndex:null,collisionFlg:!1},initialize:function(t){BM.setOptions(this,t),this._layer_id=(new Date).getTime(),this._onClickListeners=[],this._onHoverListeners=[],this._onContextMenuListeners=[],this.drawTooltip=!0,this.minZoom=0,this.font="12px Helvetica Neue",this.fillStyle="#000",this._markers=new r,this._markers.dirty=0,this._markers.total=0,this._containMarkers=new r,this._showMarkers=new r,this._showMarkerBounds=new r},setOptions:function(t){return BM.setOptions(this,t),this.redraw()},redraw:function(){return this._redraw(!0)},getEvents:function(){var t={viewreset:this._reset,zoom:this._onZoom,moveend:this._reset,contextmenu:this._executeListeners,click:this._executeListeners,mousemove:this._executeListeners};return this._zoomAnimated&&(t.zoomanim=this._onAnimZoom),t},addLayer:function(t,i=!0){if("markerPane"==t.options.pane&&t.options.icon){t._bigemap_id_=this._layer_id++,t._map=this._map;var e=t.getLatLng(),n=this._myProject(e),a=t.options.icon.options.iconSize,o=t.options.icon.options.iconAnchor;this._markers.insert({minX:n.x-o[0],minY:n.y-o[1],maxX:n.x+a[0]-o[0],maxY:n.y+a[1]-o[1],data:t}),this._markers.dirty++,this._markers.total++;e=this._map.getBounds().contains(e);return 1==i&&e&&this._redraw(!0),this}console.error("Layer isn't a marker")},addLayers:function(t,i=!0){return t.forEach(t=>{this.addLayer(t,!1)}),i&&this._redraw(!0),this},removeLayer:function(t,i=!0){var e=this,n=(t=t.minX?t.data:t).getLatLng(),a=e._map.getBounds().contains(n),n=this._myProject(n),t={minX:n.x,minY:n.y,maxX:n.x,maxY:n.y,data:t};return e._markers.remove(t,function(t,i){return t.data._bigemap_id_===i.data._bigemap_id_}),e._markers.total--,e._markers.dirty++,!0===a&&!0===i&&e._redraw(!0),this},removeLayers:function(t,e=!0){let n=t.length;return t.map((t,i)=>{i===n?this.removeLayer(t,e):this.removeLayer(t,!1)}),this},clearLayers:function(){this._markers=new r,this._markers.dirty=0,this._markers.total=0,this._containMarkers=new r,this._showMarkers=new r,this._showMarkerBounds=new r,this._redraw(!0)},onAdd:function(t){this._map=t,this.calcZoom=this._map.getZoom(),this._container||this._initCanvas(),(this.options.pane?this.getPane():t._panes.overlayPane).appendChild(this._container),this._update()},onRemove:function(t){(this.options.pane?this.getPane():t.getPanes().overlayPane).removeChild(this._container)},_drawMarker:function(t,i){var e=this;this._imageLookup||(this._imageLookup={});var n=t.options.icon.options,a=i.x-n.iconAnchor[0],o=a+n.iconSize[0],r=i.y-n.iconAnchor[1],n=r+n.iconSize[1];this._showMarkers.insert(Object.assign({},{minX:a,minY:r,maxX:o,maxY:n},{data:t}));var s=t.options.icon.options.iconUrl;t.canvas_img?e._drawImage(t,i):e._imageLookup[s]?(t.canvas_img=e._imageLookup[s][0],!1===e._imageLookup[s][1]?e._imageLookup[s][2].push([t,i]):e._drawImage(t,i)):((n=new Image).src=s,t.canvas_img=n,e._imageLookup[s]=[n,!1,[[t,i]]],n.onload=function(){e._imageLookup[s][1]=!0,e._imageLookup[s][2].forEach(function(t){e._drawImage(t[0],t[1])})})},_drawImage:function(t,i){var e=t.options.icon.options;this._ctx.drawImage(t.canvas_img,i.x-e.iconAnchor[0],i.y-e.iconAnchor[1],e.iconSize[0],e.iconSize[1])},_reset:function(){var t=this._map.containerPointToLayerPoint([0,0]);BM.DomUtil.setPosition(this._container,t);t=this._map.getSize();this._container.width=t.x,this._container.height=t.y,this._update()},_redraw:function(i){this._showMarkerBounds=new r,this._showMarkers=new r;var n=this;if(i&&this._ctx.clearRect(0,0,this._container.width,this._container.height),this._map&&this._markers&&!(this.options.minZoom&&this.options.minZoom>this._map.getZoom())){var e=[];.1<=n._markers.dirty/n._markers.total&&(n._markers.all().forEach(function(t){e.push(t)}),n._markers.clear(),n._markers.load(e),n._markers.dirty=0,e=[]);var a=n._map.getBounds(),i=this._myProject(a.getNorthWest()),a=this._myProject(a.getSouthEast()),a={minX:i.x,minY:i.y,maxX:a.x,maxY:a.y};let t=n._markers.search(a);return this._ctx.beginPath(),this._ctx.font=this.options.font||"12px Helvetica Neue",this._ctx.fillStyle=this.options.fillStyle||"#000",this._ctx.textAlign="center",t.forEach(function(t){var i=n._map.latLngToContainerPoint(t.data.getLatLng());n._drawMarker(t.data,i);let e=t.data.getTooltip();n.options.drawTooltip&&e&&(""!==(t=e.getContent())&&n._ctx.fillText(t,i.x,i.y+10))}),this._ctx.closePath(),this}},_initCanvas:function(){this._container=BM.DomUtil.create("canvas","bigemap-canvas-icon-layer bigemap-layer"),this.options.zIndex&&(this._container.style.zIndex=this.options.zIndex);var t=this._map.getSize();this._container.width=t.x,this._container.height=t.y,this._ctx=this._container.getContext("2d");t=this._map.options.zoomAnimation&&BM.Browser.any3d;BM.DomUtil.addClass(this._container,"bigemap-zoom-"+(t?"animated":"hide"))},addOnClickListener:function(t){this._onClickListeners.push(t)},addOnContextMenuListener:function(t){this._onContextMenuListeners.push(t)},addOnHoverListener:function(t){this._onHoverListeners.push(t)},_myProject(t){let i=this._map.project(t,this.calcZoom);return{x:parseFloat(i.x.toFixed(7)),y:parseFloat(i.y.toFixed(7))}},_executeListeners:function(i){var t,e,n;this._showMarkers&&(n=(t=this)._map.latLngToContainerPoint(i.latlng),t._openToolTip&&(t._openToolTip.closeTooltip(),delete t._openToolTip),(e=this._showMarkers.search({minX:n.x,minY:n.y,maxX:n.x,maxY:n.y}))&&0