1 |
- !function(e){if("function"==typeof define&&define.amd)define(["leaflet","pixi.js"],e);else if("undefined"!=typeof module)module.exports=e(require("leaflet"),require("pixi.js"));else{if(void 0===window.L)throw new Error("Leaflet must be loaded first");if(void 0===window.PIXI)throw new Error("Pixi.js must be loaded first");e(window.L,window.PIXI)}}(function(h,o){function e(){return this}var t=h.Point.prototype._round;function r(e,t,i){t?e.destroy():i||(e.autoPreventDefault=!1)}var i={options:{padding:.1,forceCanvas:!1,doubleBuffering:!1,resolution:h.Browser.retina?2:1,projectionZoom:function(e){var t=e.getMaxZoom(),e=e.getMinZoom();return t===1/0?e+8:(t+e)/2},destroyInteractionManager:!1,autoPreventDefault:!0,preserveDrawingBuffer:!1,clearBeforeRender:!0,shouldRedrawOnMove:function(){return!1}},initialize:function(e,t,i){h.setOptions(this,i),h.stamp(this),this._drawCallback=e,this._pixiContainer=t,this._rendererOptions={transparent:!0,resolution:this.options.resolution,antialias:!0,forceCanvas:this.options.forceCanvas,preserveDrawingBuffer:this.options.preserveDrawingBuffer,clearBeforeRender:this.options.clearBeforeRender},this._doubleBuffering=o.utils.isWebGLSupported()&&!this.options.forceCanvas&&this.options.doubleBuffering},_setMap:function(){},_setContainerStyle:function(){},_addContainer:function(){this.getPane().appendChild(this._container)},_setEvents:function(){},onAdd:function(e){this._setMap(e),this._container||((e=this._container=h.DomUtil.create("div","leaflet-pixi-overlay")).style.position="absolute",this._renderer=o.autoDetectRenderer(this._rendererOptions),r(this._renderer.plugins.interaction,this.options.destroyInteractionManager,this.options.autoPreventDefault),e.appendChild(this._renderer.view),this._zoomAnimated&&(h.DomUtil.addClass(e,"leaflet-zoom-animated"),this._setContainerStyle()),this._doubleBuffering&&(this._auxRenderer=o.autoDetectRenderer(this._rendererOptions),r(this._auxRenderer.plugins.interaction,this.options.destroyInteractionManager,this.options.autoPreventDefault),e.appendChild(this._auxRenderer.view),this._renderer.view.style.position="absolute",this._auxRenderer.view.style.position="absolute")),this._addContainer(),this._setEvents();var i=this._map;this._initialZoom=this.options.projectionZoom(i),this._wgsOrigin=h.latLng([0,0]),this._wgsInitialShift=i.project(this._wgsOrigin,this._initialZoom),this._mapInitialZoom=i.getZoom();var n=this;this.utils={latLngToLayerPoint:function(e,t){return t=void 0===t?n._initialZoom:t,i.project(h.latLng(e),t)},layerPointToLatLng:function(e,t){t=void 0===t?n._initialZoom:t;e=h.point(e);return i.unproject(e,t)},getScale:function(e){return void 0===e?i.getZoomScale(i.getZoom(),n._initialZoom):i.getZoomScale(e,n._initialZoom)},getRenderer:function(){return n._renderer},getContainer:function(){return n._pixiContainer},getMap:function(){return n._map}},this._update({type:"add"})},onRemove:function(){h.DomUtil.remove(this._container)},getEvents:function(){var e={zoom:this._onZoom,move:this._onMove,moveend:this._update};return this._zoomAnimated&&(e.zoomanim=this._onAnimZoom),e},_onZoom:function(){this._updateTransform(this._map.getCenter(),this._map.getZoom())},_onAnimZoom:function(e){this._updateTransform(e.center,e.zoom)},_onMove:function(e){this.options.shouldRedrawOnMove(e)&&this._update(e)},_updateTransform:function(e,t){var i=this._map.getZoomScale(t,this._zoom),n=this._map.getSize().multiplyBy(.5+this.options.padding),o=this._map.project(this._center,t),t=n.multiplyBy(-i).add(o).subtract(this._map._getNewPixelOrigin(e,t));h.Browser.any3d?h.DomUtil.setTransform(this._container,t,i):h.DomUtil.setPosition(this._container,t)},_redraw:function(e,t){this._disableLeafletRounding();var i=this._map.getZoomScale(this._zoom,this._initialZoom),e=this._map.latLngToLayerPoint(this._wgsOrigin)._subtract(this._wgsInitialShift.multiplyBy(i))._subtract(e);this._pixiContainer.scale.set(i),this._pixiContainer.position.set(e.x,e.y),this._drawCallback(this.utils,t),this._enableLeafletRounding()},_update:function(e){var t,i,n,o,r,s,a,d;this._map._animatingZoom&&this._bounds||(s=this.options.padding,t=this._map.getSize(),i=this._map.containerPointToLayerPoint(t.multiplyBy(-s)).round(),this._bounds=new h.Bounds(i,i.add(t.multiplyBy(1+2*s)).round()),this._center=this._map.getCenter(),this._zoom=this._map.getZoom(),this._doubleBuffering&&(a=this._renderer,this._renderer=this._auxRenderer,this._auxRenderer=a),n=this._renderer.view,o=this._bounds,r=this._container,s=o.getSize(),this._renderer.size&&this._renderer.size.x===s.x&&this._renderer.size.y===s.y||(this._renderer.gl&&(this._renderer.resolution=this.options.resolution,this._renderer.rootRenderTarget&&(this._renderer.rootRenderTarget.resolution=this.options.resolution)),this._renderer.resize(s.x,s.y),n.style.width=s.x+"px",n.style.height=s.y+"px",!this._renderer.gl||(a=this._renderer.gl).drawingBufferWidth!==this._renderer.width&&(a=this.options.resolution*a.drawingBufferWidth/this._renderer.width,this._renderer.resolution=a,this._renderer.rootRenderTarget&&(this._renderer.rootRenderTarget.resolution=a),this._renderer.resize(s.x,s.y)),this._renderer.size=s),this._doubleBuffering?(d=this,requestAnimationFrame(function(){d._redraw(o.min,e),d._renderer.gl.finish(),n.style.visibility="visible",d._auxRenderer.view.style.visibility="hidden",h.DomUtil.setPosition(r,o.min)})):(this._redraw(o.min,e),h.DomUtil.setPosition(r,o.min)))},_disableLeafletRounding:function(){h.Point.prototype._round=e},_enableLeafletRounding:function(){h.Point.prototype._round=t},redraw:function(e){return this._map&&(this._disableLeafletRounding(),this._drawCallback(this.utils,e),this._enableLeafletRounding()),this}};"1"<=h.version?h.PixiOverlay=h.Layer.extend(i):(h.Map.prototype.getZoomScale=function(e,t){var i=this.options.crs;return t=void 0===t?this._zoom:t,i.scale(e)/i.scale(t)},h.DomUtil.setTransform=function(e,t,i){t=t||new h.Point(0,0);e.style[h.DomUtil.TRANSFORM]=(h.Browser.ie3d?"translate("+t.x+"px,"+t.y+"px)":"translate3d("+t.x+"px,"+t.y+"px,0)")+(i?" scale("+i+")":"")},i.includes=h.Mixin.Events,i.addTo=function(e){return e.addLayer(this),this},i._setMap=function(e){this._map=e,this._zoomAnimated=e._zoomAnimated},i._setContainerStyle=function(){var t=this;["-webkit-transform-origin","-ms-transform-origin","transform-origin"].forEach(function(e){t._container.style[e]="0 0"})},i._addContainer=function(){this._map.getPanes()[this.options.pane||"overlayPane"].appendChild(this._container)},i._setEvents=function(){var e,t=this.getEvents();for(e in t)this._map.on(e,t[e],this)},i.onRemove=function(){this._map.getPanes()[this.options.pane||"overlayPane"].removeChild(this._container);var e,t=this.getEvents();for(e in t)this._map.off(e,t[e],this)},h.PixiOverlay=h.Class.extend(i)),h.pixiOverlay=function(e,t,i){return h.Browser.canvas?new h.PixiOverlay(e,t,i):null}});
|