1 line
6.7 KiB
JavaScript
1 line
6.7 KiB
JavaScript
|
!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(_,r){function e(){return this}var t=_.Point.prototype._round;function i(e,t,i){t?e.destroy():i||(e.autoPreventDefault=!1)}var n={options:{padding:.1,forceCanvas:!1,doubleBuffering:!1,resolution:_.Browser.retina?2:1,projectionZoom:function(e){return(e.getMaxZoom()+e.getMinZoom())/2},destroyInteractionManager:!1,autoPreventDefault:!0,preserveDrawingBuffer:!1,clearBeforeRender:!0,shouldRedrawOnMove:function(){return!1}},initialize:function(e,t,i){_.setOptions(this,i),_.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=r.utils.isWebGLSupported()&&!this.options.forceCanvas&&this.options.doubleBuffering},_setMap:function(){},_setContainerStyle:function(){},_addContainer:function(){this.getPane().appendChild(this._container)},_setEvents:function(){},onAdd:function(e){if(this._setMap(e),!this._container){var t=this._container=_.DomUtil.create("div","leaflet-pixi-overlay");t.style.position="absolute",this._renderer=r.autoDetectRenderer(this._rendererOptions),i(this._renderer.plugins.interaction,this.options.destroyInteractionManager,this.options.autoPreventDefault),t.appendChild(this._renderer.view),this._zoomAnimated&&(_.DomUtil.addClass(t,"leaflet-zoom-animated"),this._setContainerStyle()),this._doubleBuffering&&(this._auxRenderer=r.autoDetectRenderer(this._rendererOptions),i(this._auxRenderer.plugins.interaction,this.options.destroyInteractionManager,this.options.autoPreventDefault),t.appendChild(this._auxRenderer.view),this._renderer.view.style.position="absolute",this._auxRenderer.view.style.position="absolute")}this._addContainer(),this._setEvents();var n=this._map;this._initialZoom=this.options.projectionZoom(n),this._wgsOrigin=_.latLng([0,0]),this._wgsInitialShift=n.project(this._wgsOrigin,this._initialZoom),this._mapInitialZoom=n.getZoom();var o=this;this.utils={latLngToLayerPoint:function(e,t){return t=void 0===t?o._initialZoom:t,n.project(_.latLng(e),t)},layerPointToLatLng:function(e,t){t=void 0===t?o._initialZoom:t;var i=_.point(e);return n.unproject(i,t)},getScale:function(e){return void 0===e?n.getZoomScale(n.getZoom(),o._initialZoom):n.getZoomScale(e,o._initialZoom)},getRenderer:function(){return o._renderer},getContainer:function(){return o._pixiContainer},getMap:function(){return o._map}},this._update({type:"add"})},onRemove:function(){_.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),r=n.multiplyBy(-i).add(o).subtract(this._map._getNewPixelOrigin(e,t));_.Browser.any3d?_.DomUtil.setTransform(this._container,r,i):_.DomUtil.setPosition(this._container,r)},_redraw:function(e,t){this._disableLeafletRounding();var i=this._map.getZoomScale(this._zoom,this._initialZoom),n=this._map.latLngToLayerPoint(this._wgsOrigin)._subtract(this._wgsInitialShift.multiplyBy(i))._subtract(e);this._pixiContainer.scale.set(i),this._pixiContainer.position.set(n.x,n.y),this._drawCallback(this.utils,t),this._enableLeafletRounding()},_update:function(e){if(!this._map._animatingZoom||!this._bounds){var t=this.options.padding,i=
|