@2gis/markerdrawer
Advanced tools
Comparing version 0.0.4 to 0.0.5
@@ -1,2 +0,2 @@ | ||
!function(t,i){"object"==typeof exports&&"object"==typeof module?module.exports=i():"function"==typeof define&&define.amd?define([],i):"object"==typeof exports?exports.MarkerDrawer=i():t.MarkerDrawer=i()}(this,function(){return function(t){function i(n){if(e[n])return e[n].exports;var r=e[n]={i:n,l:!1,exports:{}};return t[n].call(r.exports,r,r.exports,i),r.l=!0,r.exports}var e={};return i.m=t,i.c=e,i.i=function(t){return t},i.d=function(t,e,n){i.o(t,e)||Object.defineProperty(t,e,{configurable:!1,enumerable:!0,get:n})},i.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return i.d(e,"a",e),e},i.o=function(t,i){return Object.prototype.hasOwnProperty.call(t,i)},i.p="/dist/",i(i.s=7)}([function(t,i,e){"use strict";e.d(i,"a",function(){return r});var n=e(2),r=(e.n(n),function(){function t(t){var i=this;this.sprites=[],this._promise=Promise.all(t.map(function(t){return i._imageLoad(t.image)})).then(function(){return i._createSprite(t)})}return t.prototype.whenReady=function(){return this._promise},t.prototype._imageLoad=function(t){return t.complete?Promise.resolve():new Promise(function(i){t.addEventListener("load",i)})},t.prototype._createSprite=function(t){var i=t.map(function(t){var i=[t.image.width,t.image.height],e=t.size||i;return{width:e[0]+4,height:e[1]+4,image:t.image,anchor:t.anchor||[.5,.5],size:e,imageSize:i,pixelDensity:t.pixelDensity||1}}),e=n(i,{inPlace:!0});this.size=[e.width,e.height],this.sprites=i.map(function(t){return{position:[t.x+2,t.y+2],size:t.size,anchor:t.anchor,pixelDensity:t.pixelDensity}});var r=this.image=document.createElement("canvas"),a=r.getContext("2d");a&&(r.width=e.width,r.height=e.height,a.shadowColor="transparent",a.shadowBlur=0,i.forEach(function(t){a.drawImage(t.image,0,0,t.imageSize[0],t.imageSize[1],t.x+2,t.y+2,t.size[0],t.size[1])}))},t}())},function(t,i,e){"use strict";e.d(i,"a",function(){return a});var n=e(6),r=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,i){t.__proto__=i}||function(t,i){for(var e in i)i.hasOwnProperty(e)&&(t[e]=i[e])};return function(i,e){function n(){this.constructor=i}t(i,e),i.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}}(),a=function(t){function i(i,e){void 0===e&&(e={});var r=t.call(this)||this;return r._onClick=function(t){var i=r._getMousePosition(t),e=r._renderer.search(i);if(e.length){t.stopPropagation();var n={originalEvent:t,markers:e};r.fire("click",n)}},r._atlas=i,r._markers=[],r._renderer=new n.a(r._atlas,e.debugDrawing||!1,void 0!==e.bufferFactor?e.bufferFactor:.5,e.zIndex),r}return r(i,t),i.prototype.setMarkers=function(t){this._markers=t,this._renderer.setMarkers(t)},i.prototype.update=function(){this._renderer.update()},i.prototype.addTo=function(t){return t.addLayer(this),this},i.prototype.onAdd=function(){var t=this;return this._map?(this._pane=this._map.getPane("overlayPane"),this._renderer.onAddToMap(this._map),this._pane.addEventListener("click",this._onClick),this._pane.appendChild(this._renderer.container),this._atlas.whenReady().then(function(){t._renderer.update()}),this):this},i.prototype.remove=function(){return this._map&&this._map.removeLayer(this),this},i.prototype.onRemove=function(){return this._pane.removeChild(this._renderer.container),this._renderer.onRemoveFromMap(),this._renderer.container.removeEventListener("click",this._onClick),this},i.prototype.setDebugDrawing=function(t){this._renderer.setDebugDrawing(t)},i.prototype._getMousePosition=function(t){var i=this._map,e=i.getContainer(),n=e.getBoundingClientRect();return[t.clientX-n.left-e.clientLeft,t.clientY-n.top-e.clientTop]},i}(L.Layer)},function(t,i,e){"use strict";var n=e(3);t.exports=function(t,i){i=i||{};var e=new n,r=i.inPlace||!1,a=t.map(function(t){return r?t:{width:t.width,height:t.height,item:t}});a=a.sort(function(t,i){return i.width*i.height-t.width*t.height}),e.fit(a);var o=a.reduce(function(t,i){return Math.max(t,i.x+i.width)},0),h=a.reduce(function(t,i){return Math.max(t,i.y+i.height)},0),s={width:o,height:h};return r||(s.items=a),s}},function(t,i){var e=function(){};e.prototype={fit:function(t){var i,e,n,r,a=t.length,o=a>0?t[0].width:0,h=a>0?t[0].height:0;for(this.root={x:0,y:0,width:o,height:h},i=0;i<a;i++)n=t[i],(e=this.findNode(this.root,n.width,n.height))?(r=this.splitNode(e,n.width,n.height),n.x=r.x,n.y=r.y):(r=this.growNode(n.width,n.height),n.x=r.x,n.y=r.y)},findNode:function(t,i,e){return t.used?this.findNode(t.right,i,e)||this.findNode(t.down,i,e):i<=t.width&&e<=t.height?t:null},splitNode:function(t,i,e){return t.used=!0,t.down={x:t.x,y:t.y+e,width:t.width,height:t.height-e},t.right={x:t.x+i,y:t.y,width:t.width-i,height:e},t},growNode:function(t,i){var e=t<=this.root.width,n=i<=this.root.height,r=n&&this.root.height>=this.root.width+t,a=e&&this.root.width>=this.root.height+i;return r?this.growRight(t,i):a?this.growDown(t,i):n?this.growRight(t,i):e?this.growDown(t,i):null},growRight:function(t,i){this.root={used:!0,x:0,y:0,width:this.root.width+t,height:this.root.height,down:this.root,right:{x:this.root.width,y:0,width:t,height:this.root.height}};var e;return(e=this.findNode(this.root,t,i))?this.splitNode(e,t,i):null},growDown:function(t,i){this.root={used:!0,x:0,y:0,width:this.root.width,height:this.root.height+i,down:{x:0,y:this.root.height,width:this.root.width,height:i},right:this.root};var e;return(e=this.findNode(this.root,t,i))?this.splitNode(e,t,i):null}},t.exports=e},function(t,i,e){"use strict";function n(t,i,e,o,h){for(e=e||0,o=o||t.length-1,h=h||a;o>e;){if(o-e>600){var s=o-e+1,u=i-e+1,c=Math.log(s),d=.5*Math.exp(2*c/3),f=.5*Math.sqrt(c*d*(s-d)/s)*(u-s/2<0?-1:1);n(t,i,Math.max(e,Math.floor(i-u*d/s+f)),Math.min(o,Math.floor(i+(s-u)*d/s+f)),h)}var m=t[i],l=e,p=o;for(r(t,e,i),h(t[o],m)>0&&r(t,e,o);l<p;){for(r(t,l,p),l++,p--;h(t[l],m)<0;)l++;for(;h(t[p],m)>0;)p--}0===h(t[e],m)?r(t,e,p):(p++,r(t,p,o)),p<=i&&(e=p+1),i<=p&&(o=p-1)}}function r(t,i,e){var n=t[i];t[i]=t[e],t[e]=n}function a(t,i){return t<i?-1:t>i?1:0}t.exports=n},function(t,i,e){"use strict";function n(t,i){if(!(this instanceof n))return new n(t,i);this._maxEntries=Math.max(4,t||9),this._minEntries=Math.max(2,Math.ceil(.4*this._maxEntries)),i&&this._initFormat(i),this.clear()}function r(t,i,e){if(!e)return i.indexOf(t);for(var n=0;n<i.length;n++)if(e(t,i[n]))return n;return-1}function a(t,i){o(t,0,t.children.length,i,t)}function o(t,i,e,n,r){r||(r=_(null)),r.minX=1/0,r.minY=1/0,r.maxX=-1/0,r.maxY=-1/0;for(var a,o=i;o<e;o++)a=t.children[o],h(r,t.leaf?n(a):a);return r}function h(t,i){return t.minX=Math.min(t.minX,i.minX),t.minY=Math.min(t.minY,i.minY),t.maxX=Math.max(t.maxX,i.maxX),t.maxY=Math.max(t.maxY,i.maxY),t}function s(t,i){return t.minX-i.minX}function u(t,i){return t.minY-i.minY}function c(t){return(t.maxX-t.minX)*(t.maxY-t.minY)}function d(t){return t.maxX-t.minX+(t.maxY-t.minY)}function f(t,i){return(Math.max(i.maxX,t.maxX)-Math.min(i.minX,t.minX))*(Math.max(i.maxY,t.maxY)-Math.min(i.minY,t.minY))}function m(t,i){var e=Math.max(t.minX,i.minX),n=Math.max(t.minY,i.minY),r=Math.min(t.maxX,i.maxX),a=Math.min(t.maxY,i.maxY);return Math.max(0,r-e)*Math.max(0,a-n)}function l(t,i){return t.minX<=i.minX&&t.minY<=i.minY&&i.maxX<=t.maxX&&i.maxY<=t.maxY}function p(t,i){return i.minX<=t.maxX&&i.minY<=t.maxY&&i.maxX>=t.minX&&i.maxY>=t.minY}function _(t){return{children:t,height:1,leaf:!0,minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0}}function g(t,i,e,n,r){for(var a,o=[i,e];o.length;)e=o.pop(),i=o.pop(),e-i<=n||(a=i+Math.ceil((e-i)/n/2)*n,x(t,a,i,e,r),o.push(i,a,a,e))}t.exports=n;var x=e(4);n.prototype={all:function(){return this._all(this.data,[])},search:function(t){var i=this.data,e=[],n=this.toBBox;if(!p(t,i))return e;for(var r,a,o,h,s=[];i;){for(r=0,a=i.children.length;r<a;r++)o=i.children[r],h=i.leaf?n(o):o,p(t,h)&&(i.leaf?e.push(o):l(t,h)?this._all(o,e):s.push(o));i=s.pop()}return e},collides:function(t){var i=this.data,e=this.toBBox;if(!p(t,i))return!1;for(var n,r,a,o,h=[];i;){for(n=0,r=i.children.length;n<r;n++)if(a=i.children[n],o=i.leaf?e(a):a,p(t,o)){if(i.leaf||l(t,o))return!0;h.push(a)}i=h.pop()}return!1},load:function(t){if(!t||!t.length)return this;if(t.length<this._minEntries){for(var i=0,e=t.length;i<e;i++)this.insert(t[i]);return this}var n=this._build(t.slice(),0,t.length-1,0);if(this.data.children.length)if(this.data.height===n.height)this._splitRoot(this.data,n);else{if(this.data.height<n.height){var r=this.data;this.data=n,n=r}this._insert(n,this.data.height-n.height-1,!0)}else this.data=n;return this},insert:function(t){return t&&this._insert(t,this.data.height-1),this},clear:function(){return this.data=_([]),this},remove:function(t,i){if(!t)return this;for(var e,n,a,o,h=this.data,s=this.toBBox(t),u=[],c=[];h||u.length;){if(h||(h=u.pop(),n=u[u.length-1],e=c.pop(),o=!0),h.leaf&&-1!==(a=r(t,h.children,i)))return h.children.splice(a,1),u.push(h),this._condense(u),this;o||h.leaf||!l(h,s)?n?(e++,h=n.children[e],o=!1):h=null:(u.push(h),c.push(e),e=0,n=h,h=h.children[0])}return this},toBBox:function(t){return t},compareMinX:s,compareMinY:u,toJSON:function(){return this.data},fromJSON:function(t){return this.data=t,this},_all:function(t,i){for(var e=[];t;)t.leaf?i.push.apply(i,t.children):e.push.apply(e,t.children),t=e.pop();return i},_build:function(t,i,e,n){var r,o=e-i+1,h=this._maxEntries;if(o<=h)return r=_(t.slice(i,e+1)),a(r,this.toBBox),r;n||(n=Math.ceil(Math.log(o)/Math.log(h)),h=Math.ceil(o/Math.pow(h,n-1))),r=_([]),r.leaf=!1,r.height=n;var s,u,c,d,f=Math.ceil(o/h),m=f*Math.ceil(Math.sqrt(h));for(g(t,i,e,m,this.compareMinX),s=i;s<=e;s+=m)for(c=Math.min(s+m-1,e),g(t,s,c,f,this.compareMinY),u=s;u<=c;u+=f)d=Math.min(u+f-1,c),r.children.push(this._build(t,u,d,n-1));return a(r,this.toBBox),r},_chooseSubtree:function(t,i,e,n){for(var r,a,o,h,s,u,d,m;;){if(n.push(i),i.leaf||n.length-1===e)break;for(d=m=1/0,r=0,a=i.children.length;r<a;r++)o=i.children[r],s=c(o),u=f(t,o)-s,u<m?(m=u,d=s<d?s:d,h=o):u===m&&s<d&&(d=s,h=o);i=h||i.children[0]}return i},_insert:function(t,i,e){var n=this.toBBox,r=e?t:n(t),a=[],o=this._chooseSubtree(r,this.data,i,a);for(o.children.push(t),h(o,r);i>=0&&a[i].children.length>this._maxEntries;)this._split(a,i),i--;this._adjustParentBBoxes(r,a,i)},_split:function(t,i){var e=t[i],n=e.children.length,r=this._minEntries;this._chooseSplitAxis(e,r,n);var o=this._chooseSplitIndex(e,r,n),h=_(e.children.splice(o,e.children.length-o));h.height=e.height,h.leaf=e.leaf,a(e,this.toBBox),a(h,this.toBBox),i?t[i-1].children.push(h):this._splitRoot(e,h)},_splitRoot:function(t,i){this.data=_([t,i]),this.data.height=t.height+1,this.data.leaf=!1,a(this.data,this.toBBox)},_chooseSplitIndex:function(t,i,e){var n,r,a,h,s,u,d,f;for(u=d=1/0,n=i;n<=e-i;n++)r=o(t,0,n,this.toBBox),a=o(t,n,e,this.toBBox),h=m(r,a),s=c(r)+c(a),h<u?(u=h,f=n,d=s<d?s:d):h===u&&s<d&&(d=s,f=n);return f},_chooseSplitAxis:function(t,i,e){var n=t.leaf?this.compareMinX:s,r=t.leaf?this.compareMinY:u;this._allDistMargin(t,i,e,n)<this._allDistMargin(t,i,e,r)&&t.children.sort(n)},_allDistMargin:function(t,i,e,n){t.children.sort(n);var r,a,s=this.toBBox,u=o(t,0,i,s),c=o(t,e-i,e,s),f=d(u)+d(c);for(r=i;r<e-i;r++)a=t.children[r],h(u,t.leaf?s(a):a),f+=d(u);for(r=e-i-1;r>=i;r--)a=t.children[r],h(c,t.leaf?s(a):a),f+=d(c);return f},_adjustParentBBoxes:function(t,i,e){for(var n=e;n>=0;n--)h(i[n],t)},_condense:function(t){for(var i,e=t.length-1;e>=0;e--)0===t[e].children.length?e>0?(i=t[e-1].children,i.splice(i.indexOf(t[e]),1)):this.clear():a(t[e],this.toBBox)},_initFormat:function(t){var i=["return a"," - b",";"];this.compareMinX=new Function("a","b",i.join(t[0])),this.compareMinY=new Function("a","b",i.join(t[1])),this.toBBox=new Function("a","return {minX: a"+t[0]+", minY: a"+t[1]+", maxX: a"+t[2]+", maxY: a"+t[3]+"};")}}},function(t,i,e){"use strict";e.d(i,"a",function(){return a});var n=e(5),r=(e.n(n),e(8)),a=function(){function t(t,i,n,a){var o=this;this.update=function(){if(o._map){if(o._isRendering||o._isZooming)return void(o._needUpdate=!0);o._zoom=o._map.getZoom();var t=o._map.getCenter();e.i(r.a)(o._origin,[t.lng,t.lat],o._zoom),o._origin[0]-=o._mapSize[0]/2,o._origin[1]-=o._mapSize[1]/2;var i=o._map.containerPointToLayerPoint([-o._bufferOffset[0],-o._bufferOffset[1]]).round();L.DomUtil.setPosition(o._hiddenFrame.canvas,i),o._render()}},this._onResize=function(){if(o._map){var t=o._map.getSize();o._pixelRatio=window.devicePixelRatio,o._bufferOffset=[Math.round(t.x*o._bufferFactor),Math.round(t.y*o._bufferFactor)];var i=o._size=[t.x+2*o._bufferOffset[0],t.y+2*o._bufferOffset[1]];o._mapSize=[t.x,t.y],o._currentFrame.canvas.width=i[0]*o._pixelRatio,o._currentFrame.canvas.height=i[1]*o._pixelRatio,o._currentFrame.canvas.style.width=i[0]+"px",o._currentFrame.canvas.style.height=i[1]+"px",o._hiddenFrame.canvas.width=i[0]*o._pixelRatio,o._hiddenFrame.canvas.height=i[1]*o._pixelRatio,o._hiddenFrame.canvas.style.width=i[0]+"px",o._hiddenFrame.canvas.style.height=i[1]+"px"}},this._onZoomStart=function(){o.clear(),o._isZooming=!0},this._onMoveEnd=function(){o._isZooming=!1,o.update()},this._renderLoop=function(){var t=o._lastRenderedMarker,i=Math.min(t+o._markersPerFrame,o._markers.length);if(t===i)return void o._renderFinish();var n=e.i(r.b)();o._renderPart(t,i),o._lastRenderedMarker=i;var a=e.i(r.b)()-n,h=a/(i-t);0!==h&&(o._markersPerFrame=Math.max(Math.floor((o._markersPerFrame+o._timePerFrame/h)/2),100)),i!==o._markers.length?o._requestAnimationFrameId=requestAnimationFrame(o._renderLoop):o._renderFinish()},this._atlas=t,this._markers=[],this._markersData=[],this._isZooming=!1,this._debugDrawing=i,this._bufferFactor=n,this._markersPerFrame=5e3,this._timePerFrame=10,this._origin=e.i(r.c)(),this._vec=e.i(r.c)(),this._lastRenderedMarker=0,this._needUpdate=!1,this.container=document.createElement("div"),a&&(this.container.style["z-index"]=a),this.container.style.position="absolute",this._currentFrame=this._createFrame(),this._hiddenFrame=this._createFrame()}return t.prototype.setMarkers=function(t){if(this._needUpdate=!1,this._isRendering&&(cancelAnimationFrame(this._requestAnimationFrameId),this._isRendering=!1),t.length>this._markersData.length){for(var i=[],e=0;e<t.length;e++)i[e]={index:e};this._markersData=i}this._markers=t,this.update()},t.prototype.onAddToMap=function(t){this._map=t,t.on({viewreset:this.update,moveend:this._onMoveEnd,zoomstart:this._onZoomStart,resize:this._onResize}),this._onResize()},t.prototype.onRemoveFromMap=function(){this._map&&(this._map.off({viewreset:this.update,moveend:this._onMoveEnd,zoomstart:this._onZoomStart,resize:this._onResize}),this._map=void 0,this._markersData=[],this._markers=[])},t.prototype.clear=function(){this._map&&(this._currentFrame.ctx.clearRect(0,0,this._size[0]*this._pixelRatio,this._size[1]*this._pixelRatio),this._currentFrame.tree.clear(),this._needUpdate=!1,this._isRendering&&(cancelAnimationFrame(this._requestAnimationFrameId),this._isRendering=!1))},t.prototype.search=function(t){var i=(t[0]+this._bufferOffset[0])*this._pixelRatio,e=(t[1]+this._bufferOffset[1])*this._pixelRatio;return this._currentFrame.tree.search({minX:i,minY:e,maxX:i,maxY:e}).map(function(t){return t.index})},t.prototype.setDebugDrawing=function(t){this._debugDrawing=t},t.prototype._render=function(){this._map&&(this._hiddenFrame.tree.clear(),this._hiddenFrame.ctx.clearRect(0,0,this._size[0]*this._pixelRatio,this._size[1]*this._pixelRatio),this._isRendering=!0,this._lastRenderedMarker=0,this._renderLoop())},t.prototype._renderFinish=function(){this._isRendering=!1,this._switchFrames(),this._needUpdate&&(this._needUpdate=!1,this.update())},t.prototype._renderPart=function(t,i){var n=this._markers,a=this._markersData,o=this._atlas,h=this._debugDrawing,s=this._pixelRatio,u=this._size,c=this._hiddenFrame.ctx,d=this._vec,f=this._zoom,m=this._origin,l=this._bufferOffset;if(o.image){this._lastRenderedMarker=i;for(var p=[],_=t;_<i;_++){var g=n[_],x=a[_],v=o.sprites[g.iconIndex||0];if(v){var w=s/v.pixelDensity;e.i(r.a)(d,g.position,f),d[0]=Math.round(d[0]),d[1]=Math.round(d[1]),d[0]=Math.round(d[0]-m[0])+l[0],d[1]=Math.round(d[1]-m[1])+l[1],d[0]=Math.round(d[0]*s-v.size[0]*w*v.anchor[0]),d[1]=Math.round(d[1]*s-v.size[1]*w*v.anchor[1]),d[0]<0||d[0]+v.size[0]*w>u[0]*s||d[1]<0||d[1]+v.size[1]*w>u[1]*s||(x.minX=d[0],x.minY=d[1],x.maxX=d[0]+v.size[0]*w,x.maxY=d[1]+v.size[1]*w,p.push(x),c.drawImage(o.image,v.position[0],v.position[1],v.size[0],v.size[1],d[0],d[1],v.size[0]*w,v.size[1]*w),h&&this._debugDraw(g,d,v.size))}}this._hiddenFrame.tree.load(p)}},t.prototype._debugDraw=function(t,i,e){var n=this._hiddenFrame.ctx,r=["#000000","#ff0000","#00ff00","#0000ff"],a=t.drawingOffsets;if(a)for(var o=0;o<a.length;o++){var h=a[o];n.beginPath(),n.strokeStyle=r[o],n.rect(i[0]-h,i[1]-h,e[0]+2*h,e[1]+2*h),n.stroke()}},t.prototype._createFrame=function(){var t=document.createElement("canvas");t.style.display="none",t.style.position="initial";var i=t.getContext("2d"),e=n();return this.container.appendChild(t),{canvas:t,ctx:i,tree:e}},t.prototype._switchFrames=function(){if(this._map){this._currentFrame.canvas.style.display="none",this._hiddenFrame.canvas.style.display="block";var t=this._currentFrame;this._currentFrame=this._hiddenFrame,this._hiddenFrame=t}},t}()},function(t,i,e){"use strict";Object.defineProperty(i,"__esModule",{value:!0});var n=e(1);e.d(i,"MarkerDrawer",function(){return n.a});var r=e(0);e.d(i,"Atlas",function(){return r.a})},function(t,i,e){"use strict";function n(){return new Float64Array(2)}function r(t,i,e){o(t,i),a(t,t,e)}function a(t,i,e){var n=256*Math.pow(2,e),r=.5/(Math.PI*h);t[0]=n*(r*i[0]+.5),t[1]=n*(-r*i[1]+.5)}function o(t,i){var e=Math.PI/180,n=Math.max(Math.min(s,i[1]),-s),r=Math.sin(n*e);t[0]=h*i[0]*e,t[1]=h*Math.log((1+r)/(1-r))/2}i.c=n,i.a=r,e.d(i,"b",function(){return u});var h=6378137,s=85.0511287798,u=window.performance?performance.now.bind(performance):Date.now.bind(Date)}])}); | ||
!function(t,i){"object"==typeof exports&&"object"==typeof module?module.exports=i():"function"==typeof define&&define.amd?define([],i):"object"==typeof exports?exports.MarkerDrawer=i():t.MarkerDrawer=i()}(this,function(){return function(t){function i(n){if(e[n])return e[n].exports;var r=e[n]={i:n,l:!1,exports:{}};return t[n].call(r.exports,r,r.exports,i),r.l=!0,r.exports}var e={};return i.m=t,i.c=e,i.i=function(t){return t},i.d=function(t,e,n){i.o(t,e)||Object.defineProperty(t,e,{configurable:!1,enumerable:!0,get:n})},i.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return i.d(e,"a",e),e},i.o=function(t,i){return Object.prototype.hasOwnProperty.call(t,i)},i.p="/dist/",i(i.s=7)}([function(t,i,e){"use strict";e.d(i,"a",function(){return r});var n=e(2),r=(e.n(n),function(){function t(t){var i=this;this.sprites=[],this._promise=Promise.all(t.map(function(t){return i._imageLoad(t.image)})).then(function(){return i._createSprite(t)})}return t.prototype.whenReady=function(){return this._promise},t.prototype._imageLoad=function(t){return t.complete?Promise.resolve():new Promise(function(i){t.addEventListener("load",i)})},t.prototype._createSprite=function(t){var i=t.map(function(t){var i=[t.image.width,t.image.height],e=t.size||i;return{width:e[0]+4,height:e[1]+4,image:t.image,anchor:t.anchor||[.5,.5],size:e,imageSize:i,pixelDensity:t.pixelDensity||1}}),e=n(i,{inPlace:!0});this.size=[e.width,e.height],this.sprites=i.map(function(t){return{position:[t.x+2,t.y+2],size:t.size,anchor:t.anchor,pixelDensity:t.pixelDensity}});var r=this.image=document.createElement("canvas"),a=r.getContext("2d");a&&(r.width=e.width,r.height=e.height,a.shadowColor="transparent",a.shadowBlur=0,i.forEach(function(t){a.drawImage(t.image,0,0,t.imageSize[0],t.imageSize[1],t.x+2,t.y+2,t.size[0],t.size[1])}))},t}())},function(t,i,e){"use strict";e.d(i,"a",function(){return a});var n=e(6),r=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,i){t.__proto__=i}||function(t,i){for(var e in i)i.hasOwnProperty(e)&&(t[e]=i[e])};return function(i,e){function n(){this.constructor=i}t(i,e),i.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}}(),a=function(t){function i(i,e){void 0===e&&(e={});var r=t.call(this)||this;return r._onClick=function(t){var i=r._getMousePosition(t),e=r._renderer.search(i);if(e.length){t.stopPropagation();var n={originalEvent:t,markers:e};r.fire("click",n)}},r._atlas=i,r._markers=[],r._renderer=new n.a(r._atlas,e.debugDrawing||!1,void 0!==e.bufferFactor?e.bufferFactor:.5,e.zIndex),r}return r(i,t),i.prototype.setMarkers=function(t){this._markers=t,this._renderer.setMarkers(t)},i.prototype.update=function(){this._renderer.update()},i.prototype.addTo=function(t){return t.addLayer(this),this},i.prototype.onAdd=function(){var t=this;return this._map?(this._pane=this._map.getPane("overlayPane"),this._renderer.onAddToMap(this._map),this._pane.addEventListener("click",this._onClick),this._pane.appendChild(this._renderer.container),this._atlas.whenReady().then(function(){t._renderer.update()}),this):this},i.prototype.remove=function(){return this._map&&this._map.removeLayer(this),this},i.prototype.onRemove=function(){return this._pane.removeChild(this._renderer.container),this._renderer.onRemoveFromMap(),this._pane.removeEventListener("click",this._onClick),this},i.prototype.setDebugDrawing=function(t){this._renderer.setDebugDrawing(t)},i.prototype._getMousePosition=function(t){var i=this._map,e=i.getContainer(),n=e.getBoundingClientRect();return[t.clientX-n.left-e.clientLeft,t.clientY-n.top-e.clientTop]},i}(L.Layer)},function(t,i,e){"use strict";var n=e(3);t.exports=function(t,i){i=i||{};var e=new n,r=i.inPlace||!1,a=t.map(function(t){return r?t:{width:t.width,height:t.height,item:t}});a=a.sort(function(t,i){return i.width*i.height-t.width*t.height}),e.fit(a);var o=a.reduce(function(t,i){return Math.max(t,i.x+i.width)},0),h=a.reduce(function(t,i){return Math.max(t,i.y+i.height)},0),s={width:o,height:h};return r||(s.items=a),s}},function(t,i){var e=function(){};e.prototype={fit:function(t){var i,e,n,r,a=t.length,o=a>0?t[0].width:0,h=a>0?t[0].height:0;for(this.root={x:0,y:0,width:o,height:h},i=0;i<a;i++)n=t[i],(e=this.findNode(this.root,n.width,n.height))?(r=this.splitNode(e,n.width,n.height),n.x=r.x,n.y=r.y):(r=this.growNode(n.width,n.height),n.x=r.x,n.y=r.y)},findNode:function(t,i,e){return t.used?this.findNode(t.right,i,e)||this.findNode(t.down,i,e):i<=t.width&&e<=t.height?t:null},splitNode:function(t,i,e){return t.used=!0,t.down={x:t.x,y:t.y+e,width:t.width,height:t.height-e},t.right={x:t.x+i,y:t.y,width:t.width-i,height:e},t},growNode:function(t,i){var e=t<=this.root.width,n=i<=this.root.height,r=n&&this.root.height>=this.root.width+t,a=e&&this.root.width>=this.root.height+i;return r?this.growRight(t,i):a?this.growDown(t,i):n?this.growRight(t,i):e?this.growDown(t,i):null},growRight:function(t,i){this.root={used:!0,x:0,y:0,width:this.root.width+t,height:this.root.height,down:this.root,right:{x:this.root.width,y:0,width:t,height:this.root.height}};var e;return(e=this.findNode(this.root,t,i))?this.splitNode(e,t,i):null},growDown:function(t,i){this.root={used:!0,x:0,y:0,width:this.root.width,height:this.root.height+i,down:{x:0,y:this.root.height,width:this.root.width,height:i},right:this.root};var e;return(e=this.findNode(this.root,t,i))?this.splitNode(e,t,i):null}},t.exports=e},function(t,i,e){"use strict";function n(t,i,e,o,h){for(e=e||0,o=o||t.length-1,h=h||a;o>e;){if(o-e>600){var s=o-e+1,u=i-e+1,c=Math.log(s),d=.5*Math.exp(2*c/3),f=.5*Math.sqrt(c*d*(s-d)/s)*(u-s/2<0?-1:1);n(t,i,Math.max(e,Math.floor(i-u*d/s+f)),Math.min(o,Math.floor(i+(s-u)*d/s+f)),h)}var m=t[i],l=e,p=o;for(r(t,e,i),h(t[o],m)>0&&r(t,e,o);l<p;){for(r(t,l,p),l++,p--;h(t[l],m)<0;)l++;for(;h(t[p],m)>0;)p--}0===h(t[e],m)?r(t,e,p):(p++,r(t,p,o)),p<=i&&(e=p+1),i<=p&&(o=p-1)}}function r(t,i,e){var n=t[i];t[i]=t[e],t[e]=n}function a(t,i){return t<i?-1:t>i?1:0}t.exports=n},function(t,i,e){"use strict";function n(t,i){if(!(this instanceof n))return new n(t,i);this._maxEntries=Math.max(4,t||9),this._minEntries=Math.max(2,Math.ceil(.4*this._maxEntries)),i&&this._initFormat(i),this.clear()}function r(t,i,e){if(!e)return i.indexOf(t);for(var n=0;n<i.length;n++)if(e(t,i[n]))return n;return-1}function a(t,i){o(t,0,t.children.length,i,t)}function o(t,i,e,n,r){r||(r=_(null)),r.minX=1/0,r.minY=1/0,r.maxX=-1/0,r.maxY=-1/0;for(var a,o=i;o<e;o++)a=t.children[o],h(r,t.leaf?n(a):a);return r}function h(t,i){return t.minX=Math.min(t.minX,i.minX),t.minY=Math.min(t.minY,i.minY),t.maxX=Math.max(t.maxX,i.maxX),t.maxY=Math.max(t.maxY,i.maxY),t}function s(t,i){return t.minX-i.minX}function u(t,i){return t.minY-i.minY}function c(t){return(t.maxX-t.minX)*(t.maxY-t.minY)}function d(t){return t.maxX-t.minX+(t.maxY-t.minY)}function f(t,i){return(Math.max(i.maxX,t.maxX)-Math.min(i.minX,t.minX))*(Math.max(i.maxY,t.maxY)-Math.min(i.minY,t.minY))}function m(t,i){var e=Math.max(t.minX,i.minX),n=Math.max(t.minY,i.minY),r=Math.min(t.maxX,i.maxX),a=Math.min(t.maxY,i.maxY);return Math.max(0,r-e)*Math.max(0,a-n)}function l(t,i){return t.minX<=i.minX&&t.minY<=i.minY&&i.maxX<=t.maxX&&i.maxY<=t.maxY}function p(t,i){return i.minX<=t.maxX&&i.minY<=t.maxY&&i.maxX>=t.minX&&i.maxY>=t.minY}function _(t){return{children:t,height:1,leaf:!0,minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0}}function g(t,i,e,n,r){for(var a,o=[i,e];o.length;)e=o.pop(),i=o.pop(),e-i<=n||(a=i+Math.ceil((e-i)/n/2)*n,x(t,a,i,e,r),o.push(i,a,a,e))}t.exports=n;var x=e(4);n.prototype={all:function(){return this._all(this.data,[])},search:function(t){var i=this.data,e=[],n=this.toBBox;if(!p(t,i))return e;for(var r,a,o,h,s=[];i;){for(r=0,a=i.children.length;r<a;r++)o=i.children[r],h=i.leaf?n(o):o,p(t,h)&&(i.leaf?e.push(o):l(t,h)?this._all(o,e):s.push(o));i=s.pop()}return e},collides:function(t){var i=this.data,e=this.toBBox;if(!p(t,i))return!1;for(var n,r,a,o,h=[];i;){for(n=0,r=i.children.length;n<r;n++)if(a=i.children[n],o=i.leaf?e(a):a,p(t,o)){if(i.leaf||l(t,o))return!0;h.push(a)}i=h.pop()}return!1},load:function(t){if(!t||!t.length)return this;if(t.length<this._minEntries){for(var i=0,e=t.length;i<e;i++)this.insert(t[i]);return this}var n=this._build(t.slice(),0,t.length-1,0);if(this.data.children.length)if(this.data.height===n.height)this._splitRoot(this.data,n);else{if(this.data.height<n.height){var r=this.data;this.data=n,n=r}this._insert(n,this.data.height-n.height-1,!0)}else this.data=n;return this},insert:function(t){return t&&this._insert(t,this.data.height-1),this},clear:function(){return this.data=_([]),this},remove:function(t,i){if(!t)return this;for(var e,n,a,o,h=this.data,s=this.toBBox(t),u=[],c=[];h||u.length;){if(h||(h=u.pop(),n=u[u.length-1],e=c.pop(),o=!0),h.leaf&&-1!==(a=r(t,h.children,i)))return h.children.splice(a,1),u.push(h),this._condense(u),this;o||h.leaf||!l(h,s)?n?(e++,h=n.children[e],o=!1):h=null:(u.push(h),c.push(e),e=0,n=h,h=h.children[0])}return this},toBBox:function(t){return t},compareMinX:s,compareMinY:u,toJSON:function(){return this.data},fromJSON:function(t){return this.data=t,this},_all:function(t,i){for(var e=[];t;)t.leaf?i.push.apply(i,t.children):e.push.apply(e,t.children),t=e.pop();return i},_build:function(t,i,e,n){var r,o=e-i+1,h=this._maxEntries;if(o<=h)return r=_(t.slice(i,e+1)),a(r,this.toBBox),r;n||(n=Math.ceil(Math.log(o)/Math.log(h)),h=Math.ceil(o/Math.pow(h,n-1))),r=_([]),r.leaf=!1,r.height=n;var s,u,c,d,f=Math.ceil(o/h),m=f*Math.ceil(Math.sqrt(h));for(g(t,i,e,m,this.compareMinX),s=i;s<=e;s+=m)for(c=Math.min(s+m-1,e),g(t,s,c,f,this.compareMinY),u=s;u<=c;u+=f)d=Math.min(u+f-1,c),r.children.push(this._build(t,u,d,n-1));return a(r,this.toBBox),r},_chooseSubtree:function(t,i,e,n){for(var r,a,o,h,s,u,d,m;;){if(n.push(i),i.leaf||n.length-1===e)break;for(d=m=1/0,r=0,a=i.children.length;r<a;r++)o=i.children[r],s=c(o),u=f(t,o)-s,u<m?(m=u,d=s<d?s:d,h=o):u===m&&s<d&&(d=s,h=o);i=h||i.children[0]}return i},_insert:function(t,i,e){var n=this.toBBox,r=e?t:n(t),a=[],o=this._chooseSubtree(r,this.data,i,a);for(o.children.push(t),h(o,r);i>=0&&a[i].children.length>this._maxEntries;)this._split(a,i),i--;this._adjustParentBBoxes(r,a,i)},_split:function(t,i){var e=t[i],n=e.children.length,r=this._minEntries;this._chooseSplitAxis(e,r,n);var o=this._chooseSplitIndex(e,r,n),h=_(e.children.splice(o,e.children.length-o));h.height=e.height,h.leaf=e.leaf,a(e,this.toBBox),a(h,this.toBBox),i?t[i-1].children.push(h):this._splitRoot(e,h)},_splitRoot:function(t,i){this.data=_([t,i]),this.data.height=t.height+1,this.data.leaf=!1,a(this.data,this.toBBox)},_chooseSplitIndex:function(t,i,e){var n,r,a,h,s,u,d,f;for(u=d=1/0,n=i;n<=e-i;n++)r=o(t,0,n,this.toBBox),a=o(t,n,e,this.toBBox),h=m(r,a),s=c(r)+c(a),h<u?(u=h,f=n,d=s<d?s:d):h===u&&s<d&&(d=s,f=n);return f},_chooseSplitAxis:function(t,i,e){var n=t.leaf?this.compareMinX:s,r=t.leaf?this.compareMinY:u;this._allDistMargin(t,i,e,n)<this._allDistMargin(t,i,e,r)&&t.children.sort(n)},_allDistMargin:function(t,i,e,n){t.children.sort(n);var r,a,s=this.toBBox,u=o(t,0,i,s),c=o(t,e-i,e,s),f=d(u)+d(c);for(r=i;r<e-i;r++)a=t.children[r],h(u,t.leaf?s(a):a),f+=d(u);for(r=e-i-1;r>=i;r--)a=t.children[r],h(c,t.leaf?s(a):a),f+=d(c);return f},_adjustParentBBoxes:function(t,i,e){for(var n=e;n>=0;n--)h(i[n],t)},_condense:function(t){for(var i,e=t.length-1;e>=0;e--)0===t[e].children.length?e>0?(i=t[e-1].children,i.splice(i.indexOf(t[e]),1)):this.clear():a(t[e],this.toBBox)},_initFormat:function(t){var i=["return a"," - b",";"];this.compareMinX=new Function("a","b",i.join(t[0])),this.compareMinY=new Function("a","b",i.join(t[1])),this.toBBox=new Function("a","return {minX: a"+t[0]+", minY: a"+t[1]+", maxX: a"+t[2]+", maxY: a"+t[3]+"};")}}},function(t,i,e){"use strict";e.d(i,"a",function(){return a});var n=e(5),r=(e.n(n),e(8)),a=function(){function t(t,i,n,a){var o=this;this.update=function(){if(o._map){if(o._isRendering||o._isZooming)return void(o._needUpdate=!0);o._zoom=o._map.getZoom();var t=o._map.getCenter();e.i(r.a)(o._origin,[t.lng,t.lat],o._zoom),o._origin[0]-=o._mapSize[0]/2,o._origin[1]-=o._mapSize[1]/2;var i=o._map.containerPointToLayerPoint([-o._bufferOffset[0],-o._bufferOffset[1]]).round();L.DomUtil.setPosition(o._hiddenFrame.canvas,i),o._render()}},this._onResize=function(){if(o._map){var t=o._map.getSize();o._pixelRatio=window.devicePixelRatio,o._bufferOffset=[Math.round(t.x*o._bufferFactor),Math.round(t.y*o._bufferFactor)];var i=o._size=[t.x+2*o._bufferOffset[0],t.y+2*o._bufferOffset[1]];o._mapSize=[t.x,t.y],o._currentFrame.canvas.width=i[0]*o._pixelRatio,o._currentFrame.canvas.height=i[1]*o._pixelRatio,o._currentFrame.canvas.style.width=i[0]+"px",o._currentFrame.canvas.style.height=i[1]+"px",o._hiddenFrame.canvas.width=i[0]*o._pixelRatio,o._hiddenFrame.canvas.height=i[1]*o._pixelRatio,o._hiddenFrame.canvas.style.width=i[0]+"px",o._hiddenFrame.canvas.style.height=i[1]+"px"}},this._onZoomStart=function(){o.clear(),o._isZooming=!0},this._onMoveEnd=function(){o._isZooming=!1,o.update()},this._renderLoop=function(){var t=o._lastRenderedMarker,i=Math.min(t+o._markersPerFrame,o._markers.length);if(t===i)return void o._renderFinish();var n=e.i(r.b)();o._renderPart(t,i),o._lastRenderedMarker=i;var a=e.i(r.b)()-n,h=a/(i-t);0!==h&&(o._markersPerFrame=Math.max(Math.floor((o._markersPerFrame+o._timePerFrame/h)/2),100)),i!==o._markers.length?o._requestAnimationFrameId=requestAnimationFrame(o._renderLoop):o._renderFinish()},this._atlas=t,this._markers=[],this._markersData=[],this._isZooming=!1,this._debugDrawing=i,this._bufferFactor=n,this._markersPerFrame=5e3,this._timePerFrame=10,this._origin=e.i(r.c)(),this._vec=e.i(r.c)(),this._lastRenderedMarker=0,this._needUpdate=!1,this.container=document.createElement("div"),a&&(this.container.style["z-index"]=a),this.container.style.position="absolute",this._currentFrame=this._createFrame(),this._hiddenFrame=this._createFrame()}return t.prototype.setMarkers=function(t){if(this._needUpdate=!1,this._isRendering&&(cancelAnimationFrame(this._requestAnimationFrameId),this._isRendering=!1),t.length>this._markersData.length){for(var i=[],e=0;e<t.length;e++)i[e]={index:e};this._markersData=i}this._markers=t,this.update()},t.prototype.onAddToMap=function(t){this._map=t,t.on({viewreset:this.update,moveend:this._onMoveEnd,zoomstart:this._onZoomStart,resize:this._onResize}),this._onResize()},t.prototype.onRemoveFromMap=function(){this._map&&(this._map.off({viewreset:this.update,moveend:this._onMoveEnd,zoomstart:this._onZoomStart,resize:this._onResize}),this._map=void 0,this._markersData=[],this._markers=[])},t.prototype.clear=function(){this._map&&(this._currentFrame.ctx.clearRect(0,0,this._size[0]*this._pixelRatio,this._size[1]*this._pixelRatio),this._currentFrame.tree.clear(),this._needUpdate=!1,this._isRendering&&(cancelAnimationFrame(this._requestAnimationFrameId),this._isRendering=!1))},t.prototype.search=function(t){var i=(t[0]+this._bufferOffset[0])*this._pixelRatio,e=(t[1]+this._bufferOffset[1])*this._pixelRatio;return this._currentFrame.tree.search({minX:i,minY:e,maxX:i,maxY:e}).map(function(t){return t.index})},t.prototype.setDebugDrawing=function(t){this._debugDrawing=t},t.prototype._render=function(){this._map&&(this._hiddenFrame.tree.clear(),this._hiddenFrame.ctx.clearRect(0,0,this._size[0]*this._pixelRatio,this._size[1]*this._pixelRatio),this._isRendering=!0,this._lastRenderedMarker=0,this._renderLoop())},t.prototype._renderFinish=function(){this._isRendering=!1,this._switchFrames(),this._needUpdate&&(this._needUpdate=!1,this.update())},t.prototype._renderPart=function(t,i){var n=this._markers,a=this._markersData,o=this._atlas,h=this._debugDrawing,s=this._pixelRatio,u=this._size,c=this._hiddenFrame.ctx,d=this._vec,f=this._zoom,m=this._origin,l=this._bufferOffset;if(o.image){this._lastRenderedMarker=i;for(var p=[],_=t;_<i;_++){var g=n[_],x=a[_],v=o.sprites[g.iconIndex||0];if(v){var w=s/v.pixelDensity;e.i(r.a)(d,g.position,f),d[0]=Math.round(d[0]),d[1]=Math.round(d[1]),d[0]=Math.round(d[0]-m[0])+l[0],d[1]=Math.round(d[1]-m[1])+l[1],d[0]=Math.round(d[0]*s-v.size[0]*w*v.anchor[0]),d[1]=Math.round(d[1]*s-v.size[1]*w*v.anchor[1]),d[0]<0||d[0]+v.size[0]*w>u[0]*s||d[1]<0||d[1]+v.size[1]*w>u[1]*s||(x.minX=d[0],x.minY=d[1],x.maxX=d[0]+v.size[0]*w,x.maxY=d[1]+v.size[1]*w,p.push(x),c.drawImage(o.image,v.position[0],v.position[1],v.size[0],v.size[1],d[0],d[1],v.size[0]*w,v.size[1]*w),h&&this._debugDraw(g,d,v.size))}}this._hiddenFrame.tree.load(p)}},t.prototype._debugDraw=function(t,i,e){var n=this._hiddenFrame.ctx,r=["#000000","#ff0000","#00ff00","#0000ff"],a=t.drawingOffsets;if(a)for(var o=0;o<a.length;o++){var h=a[o];n.beginPath(),n.strokeStyle=r[o],n.rect(i[0]-h,i[1]-h,e[0]+2*h,e[1]+2*h),n.stroke()}},t.prototype._createFrame=function(){var t=document.createElement("canvas");t.style.display="none",t.style.position="initial";var i=t.getContext("2d"),e=n();return this.container.appendChild(t),{canvas:t,ctx:i,tree:e}},t.prototype._switchFrames=function(){if(this._map){this._currentFrame.canvas.style.display="none",this._hiddenFrame.canvas.style.display="block";var t=this._currentFrame;this._currentFrame=this._hiddenFrame,this._hiddenFrame=t}},t}()},function(t,i,e){"use strict";Object.defineProperty(i,"__esModule",{value:!0});var n=e(1);e.d(i,"MarkerDrawer",function(){return n.a});var r=e(0);e.d(i,"Atlas",function(){return r.a})},function(t,i,e){"use strict";function n(){return new Float64Array(2)}function r(t,i,e){o(t,i),a(t,t,e)}function a(t,i,e){var n=256*Math.pow(2,e),r=.5/(Math.PI*h);t[0]=n*(r*i[0]+.5),t[1]=n*(-r*i[1]+.5)}function o(t,i){var e=Math.PI/180,n=Math.max(Math.min(s,i[1]),-s),r=Math.sin(n*e);t[0]=h*i[0]*e,t[1]=h*Math.log((1+r)/(1-r))/2}i.c=n,i.a=r,e.d(i,"b",function(){return u});var h=6378137,s=85.0511287798,u=window.performance?performance.now.bind(performance):Date.now.bind(Date)}])}); | ||
//# sourceMappingURL=markerdrawer.js.map |
{ | ||
"name": "@2gis/markerdrawer", | ||
"version": "0.0.4", | ||
"version": "0.0.5", | ||
"description": "Library for fast drawing a huge amount of markers", | ||
@@ -5,0 +5,0 @@ "author": { |
@@ -78,3 +78,3 @@ import { Atlas } from './Atlas'; | ||
this._renderer.onRemoveFromMap(); | ||
this._renderer.container.removeEventListener('click', this._onClick); | ||
this._pane.removeEventListener('click', this._onClick); | ||
@@ -81,0 +81,0 @@ return this; |
Sorry, the diff of this file is not supported yet
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
276342