mirror of
https://github.com/jiawanlong/Cesium-Examples.git
synced 2025-07-06 08:17:31 +00:00
1 line
7.0 KiB
JavaScript
1 line
7.0 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(d,o){function e(){return this}var t=d.Point.prototype._round;function r(e,t,i){e=o.VERSION<"7"?e.plugins.interaction:e.events;t?e.destroy():i||(e.autoPreventDefault=!1)}var i={options:{padding:.1,forceCanvas:!1,doubleBuffering:!1,resolution:d.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){d.setOptions(this,i),d.stamp(this),this._drawCallback=e,this._pixiContainer=t,this._rendererOptions={resolution:this.options.resolution,antialias:!0,forceCanvas:this.options.forceCanvas,preserveDrawingBuffer:this.options.preserveDrawingBuffer,clearBeforeRender:this.options.clearBeforeRender},o.VERSION<"6"?this._rendererOptions.transparent=!0:this._rendererOptions.backgroundAlpha=0,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=d.DomUtil.create("div","leaflet-pixi-overlay")).style.position="absolute",this._renderer=o.autoDetectRenderer(this._rendererOptions),r(this._renderer,this.options.destroyInteractionManager,this.options.autoPreventDefault),e.appendChild(this._renderer.view),this._zoomAnimated&&(d.DomUtil.addClass(e,"leaflet-zoom-animated"),this._setContainerStyle()),this._doubleBuffering&&(this._auxRenderer=o.autoDetectRenderer(this._rendererOptions),r(this._auxRenderer,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,n=(this._initialZoom=this.options.projectionZoom(i),this._wgsOrigin=d.latLng([0,0]),this._wgsInitialShift=i.project(this._wgsOrigin,this._initialZoom),this._mapInitialZoom=i.getZoom(),this);this.utils={latLngToLayerPoint:function(e,t){return t=void 0===t?n._initialZoom:t,i.project(d.latLng(e),t)},layerPointToLatLng:function(e,t){t=void 0===t?n._initialZoom:t;e=d.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(){d.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),n=n.multiplyBy(-i).add(o).subtract(this._map._getNewPixelOrigin(e,t));d.Browser.any3d?d.DomUtil.setTransform(this._container,n,i):d.DomUtil.setPosition(this._container,n)},_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;this._map._animatingZoom&&this._bounds||(r=this.options.padding,o=this._map.getSize(),s=this._map.containerPointToLayerPoint(o.multiplyBy(-r)).round(),this._bounds=new d.Bounds(s,s.add(o.multiplyBy(1+2*r)).round()),this._center=this._map.getCenter(),this._zoom=this._map.getZoom(),this._doubleBuffering&&(s=this._renderer,this._renderer=this._auxRenderer,this._auxRenderer=s),t=this._renderer.view,i=this._bounds,n=this._container,o=i.getSize(),this._renderer.size&&this._renderer.size.x===o.x&&this._renderer.size.y===o.y||(this._renderer.gl&&(this._renderer.resolution=this.options.resolution,this._renderer.rootRenderTarget)&&(this._renderer.rootRenderTarget.resolution=this.options.resolution),this._renderer.resize(o.x,o.y),t.style.width=o.x+"px",t.style.height=o.y+"px",this._renderer.gl&&(r=this._renderer.gl).drawingBufferWidth!==this._renderer.width&&(s=this.options.resolution*r.drawingBufferWidth/this._renderer.width,this._renderer.resolution=s,this._renderer.rootRenderTarget&&(this._renderer.rootRenderTarget.resolution=s),this._renderer.resize(o.x,o.y)),this._renderer.size=o),this._doubleBuffering?(a=this,requestAnimationFrame(function(){a._redraw(i.min,e),a._renderer.gl.finish(),t.style.visibility="visible",a._auxRenderer.view.style.visibility="hidden",d.DomUtil.setPosition(n,i.min)})):(this._redraw(i.min,e),d.DomUtil.setPosition(n,i.min)))},_disableLeafletRounding:function(){d.Point.prototype._round=e},_enableLeafletRounding:function(){d.Point.prototype._round=t},redraw:function(e){return this._map&&(this._disableLeafletRounding(),this._drawCallback(this.utils,e),this._enableLeafletRounding()),this},_destroy:function(){this._renderer.destroy(!0),this._doubleBuffering&&this._auxRenderer.destroy(!0)},destroy:function(){this.remove(),this._destroy()}};"1"<=d.version?d.PixiOverlay=d.Layer.extend(i):(d.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)},d.DomUtil.setTransform=function(e,t,i){t=t||new d.Point(0,0);e.style[d.DomUtil.TRANSFORM]=(d.Browser.ie3d?"translate("+t.x+"px,"+t.y+"px)":"translate3d("+t.x+"px,"+t.y+"px,0)")+(i?" scale("+i+")":"")},i.includes=d.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=null;var e,t=this._container.parentNode,i=(t&&t.removeChild(this._container),this.getEvents());for(e in i)this._map.off(e,i[e],this)},i.destroy=function(){var e=this._map||this._mapToAdd;e&&e.removeLayer(this),this._destroy()},d.PixiOverlay=d.Class.extend(i)),d.pixiOverlay=function(e,t,i){return d.Browser.canvas?new d.PixiOverlay(e,t,i):null}}); |