/**
 * Skipped minification because the original files appears to be already minified.
 * Original file: /npm/@vuemap/three-layer@0.0.12/dist/index.js
 *
 * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files
 */
(function(d,h){typeof exports=="object"&&typeof module!="undefined"?h(exports,require("three"),require("three/examples/jsm/loaders/GLTFLoader.js")):typeof define=="function"&&define.amd?define(["exports","three","three/examples/jsm/loaders/GLTFLoader.js"],h):(d=typeof globalThis!="undefined"?globalThis:d||self,h(d.AMap=d.AMap||{},d.THREE,d.THREE))})(this,function(d,h,b){"use strict";class _{constructor(){this._listeners={}}on(e,t,s){this._listeners[e]?this._listeners[e].push({callback:t,isOnce:s}):this._listeners[e]=[{callback:t,isOnce:s}]}off(e,t){if(!t)throw new Error("\u53D6\u6D88\u4E8B\u4EF6\u65F6\u9700\u8981\u4F20\u5165\u539F\u56DE\u8C03\u51FD\u6570");const s=this._listeners[e];if(s&&s.length>0){for(let i=0;i<s.length;i++)if(s[i].callback===t){s.splice(i,1);break}}}emit(e,t){const s=this._listeners[e];if(s&&s.length>0)for(let i=0;i<s.length;i++){const o=s[i];o.callback.call(this,t),o.isOnce&&(s.splice(i,1),i--)}}}function E(l){l.traverse(e=>{C(e)})}function C(l){const e=s=>{s.geometry&&s.geometry.dispose(),s.material&&s.material.dispose&&s.material.dispose(),s.material.texture&&s.material.texture.dispose&&s.material.texture.dispose()},t=s=>{let i=s.children.filter(o=>o);i.forEach(o=>{o.children.length?t(o):o.isMesh&&e(o)}),i=null};t(l)}var j=Object.defineProperty,L=Object.getOwnPropertySymbols,M=Object.prototype.hasOwnProperty,R=Object.prototype.propertyIsEnumerable,T=(l,e,t)=>e in l?j(l,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):l[e]=t,A=(l,e)=>{for(var t in e||(e={}))M.call(e,t)&&T(l,t,e[t]);if(L)for(var t of L(e))R.call(e,t)&&T(l,t,e[t]);return l};class z extends _{constructor(e,t){super(),this.frameTimer=-1,this.needsUpdate=!1,t=t||{},this.customCoords=e.customCoords,this.center=t.customCoordsCenter||e.getCenter().toArray(),this.customCoords.lngLatsToCoords([this.center]);const s={zooms:[2,20],opacity:1,alpha:!1,antialias:!1,visible:!0,zIndex:120,createCanvas:!1,webGLRendererParameters:{}};this.options=Object.assign({},s,t),this.map=e,this.init()}init(){this.options.createCanvas?this.createCustomCanvasLayer():this.createGlCustomLayer(),this._updateSizeFn=()=>{this.updateRendererSize()},this.map.on("resize",this._updateSizeFn)}updateRendererSize(){var e;const t=this.map.getContainer(),s=t.offsetWidth,i=t.offsetHeight;(e=this.renderer)===null||e===void 0||e.setSize(s,i),this.map.getView().type==="3D"&&(this.camera.aspect=s/i)}createGlCustomLayer(){const e=this.options,t=this.map,s={zooms:e.zooms,opacity:e.opacity,visible:e.visible,zIndex:e.zIndex,init:i=>{const o=t.getContainer(),n=o.offsetWidth,r=o.offsetHeight;let c;t.getView().type==="3D"?c=new h.PerspectiveCamera(60,n/r,100,1<<30):c=new h.OrthographicCamera(n/-2,n/2,r/2,r/-2,1,1e3);const m=new h.WebGLRenderer(A({context:i,alpha:e.alpha,antialias:e.antialias},e.webGLRendererParameters));m.setSize(n,r),m.autoClear=!1;const p=new h.Scene;this.camera=c,this.renderer=m,this.scene=p,e.onInit&&e.onInit(m,p,c),this.animate(),this.emit("complete")},render:()=>{var i,o,n;(i=this.renderer)===null||i===void 0||i.resetState(),this.customCoords.setCenter(this.center);const r=this.camera;if(t.getView().type==="3D"){const{near:c,far:m,fov:p,up:u,lookAt:a,position:f}=this.customCoords.getCameraParams();r.near=c,r.far=m,r.fov=p,r.position.set(...f),r.up.set(...u),r.lookAt(...a),r.updateProjectionMatrix()}else{const{top:c,bottom:m,left:p,right:u,position:a}=this.customCoords.getCameraParams();r.top=c,r.bottom=m,r.left=p,r.right=u,r.position.set(...a),r.updateProjectionMatrix()}this.camera=r,e.onRender?e.onRender(this.renderer,this.scene,this.camera):(o=this.renderer)===null||o===void 0||o.render(this.scene,r),(n=this.renderer)===null||n===void 0||n.resetState()}};this.layer=new AMap.GLCustomLayer(s),this.layer.setMap(t)}createCustomCanvasLayer(){const e=this.options,t=this.map,s=document.createElement("canvas");this.canvas=s;const i=t.getContainer(),o=i.offsetWidth,n=i.offsetHeight;let r;t.getView().type==="3D"?r=new h.PerspectiveCamera(60,o/n,100,1<<30):r=new h.OrthographicCamera(o/-2,o/2,n/2,n/-2,1,1e3);const c=new h.WebGLRenderer(A({alpha:e.alpha,antialias:e.antialias,canvas:s},e.webGLRendererParameters));c.setSize(o,n),c.setPixelRatio(window.devicePixelRatio);const m=new h.Scene;this.camera=r,this.renderer=c,c.setClearColor(0,0),this.scene=m;const p={zooms:e.zooms,opacity:e.opacity,visible:e.visible,zIndex:e.zIndex,alwaysRender:!0,render:()=>{var u;this.customCoords.setCenter(this.center);const a=this.camera;if(t.getView().type==="3D"){const{near:f,far:y,fov:g,up:v,lookAt:w,position:H}=this.customCoords.getCameraParams();a.near=f,a.far=y,a.fov=g,a.position.set(...H),a.up.set(...v),a.lookAt(...w),a.updateProjectionMatrix()}else{const{top:f,bottom:y,left:g,right:v,position:w}=this.customCoords.getCameraParams();a.top=f,a.bottom=y,a.left=g,a.right=v,a.position.set(...w),a.updateProjectionMatrix()}this.camera=a,e.onRender?e.onRender(this.renderer,this.scene,this.camera):(u=this.renderer)===null||u===void 0||u.render(this.scene,a)}};this.layer=new AMap.CustomLayer(s,p),this.layer.setMap(t),setTimeout(()=>{e.onInit&&e.onInit(c,m,r),this.animate(),this.emit("complete")},10)}update(){this.needsUpdate=!0}animate(){var e;this.needsUpdate&&(this.options.createCanvas?this.options.onRender?this.options.onRender(this.renderer,this.scene,this.camera):(e=this.renderer)===null||e===void 0||e.render(this.scene,this.camera):this.refreshMap(),this.needsUpdate=!1),this.frameTimer=requestAnimationFrame(()=>{this.animate()})}refreshMap(){this.map&&this.map.render()}convertLngLat(e){return this.customCoords.setCenter(this.center),this.customCoords.lngLatsToCoords([e])[0]}add(e){var t;(t=this.scene)===null||t===void 0||t.add(e),this.refreshMap()}remove(e){var t;(t=this.scene)===null||t===void 0||t.remove(e),this.refreshMap()}getScene(){return this.scene}getCamera(){return this.camera}getRender(){return this.renderer}destroy(){var e;cancelAnimationFrame(this.frameTimer),this.map.off("resize",this._updateSizeFn),this._updateSizeFn=void 0,this.layer.setMap(null),this.customCoords=null,E(this.scene),this.scene=void 0,this.camera=void 0,(e=this.renderer)===null||e===void 0||e.dispose(),this.renderer=void 0,this.layer=null,this.map=null,h.Cache.clear(),this.options=null}getMap(){return this.map?this.map:null}getOpacity(){return this.layer.getOpacity()}setOpacity(e){this.layer.setOpacity(e)}getZooms(){return this.layer.getZooms()}setZooms(e){this.layer.setZooms(e)}getzIndex(){return this.layer.getzIndex()}setzIndex(e){this.layer.setzIndex(e)}show(){this.layer.show()}hide(){this.layer.hide()}}class F extends _{constructor(e,t){super(),this.linerAnimationFrame=-1,this.layer=e,t=Object.assign({},{url:"",position:[0,0],height:0,rotation:{x:0,y:0,z:0},scale:1,angle:0,useModelCache:!1},t),this.init(t)}init(e){if(e.useModelCache)if(window._THREE_GLTF_CACHE=window._THREE_GLTF_CACHE||{},window._THREE_GLTF_CACHE[e.url])if(window._THREE_GLTF_CACHE[e.url].loaded){const t=window._THREE_GLTF_CACHE[e.url].model;this._loadModel(t.scene.clone(!0),t.animations.map(s=>s.clone()),e)}else this.getModelTimer=setTimeout(()=>{this.init(e)},10);else{window._THREE_GLTF_CACHE[e.url]={loaded:!1};const t=new b.GLTFLoader;e.configLoader&&e.configLoader(t),t.load(e.url,s=>{window._THREE_GLTF_CACHE[e.url].model=s,window._THREE_GLTF_CACHE[e.url].loaded=!0,this._loadModel(s.scene.clone(!0),s.animations.map(i=>i.clone()),e)})}else{const t=new b.GLTFLoader;e.configLoader&&e.configLoader(t),t.load(e.url,s=>{this._loadModel(s.scene,s.animations,e)})}}_loadModel(e,t,s){this.layer.add(e),this.object=e,this.animations=t,this.setScale(s.scale),this.setRotation(s.rotation),this.setAngle(s.angle),this.setPosition(s.position),this.setHeight(s.height),s.onLoaded&&s.onLoaded(e,t),this.emit("complete",{target:e,animations:t})}setScale(e){let t;typeof e=="number"?t={x:e,y:e,z:e}:t=e,this.object.scale.set(t.x,t.y,t.z),this.refresh()}setPosition(e){const t=this.layer.convertLngLat(e);this.object.position.setX(t[0]),this.object.position.setY(t[1]),this.refresh()}setRotation(e){if(e){const t=Math.PI/180*(e.x||0),s=Math.PI/180*(e.y||0),i=Math.PI/180*(e.z||0);this.object.rotation.set(t,s,i),this.refresh()}}setAngle(e){const t=this.object.rotation.x,s=this.object.rotation.z,i=Math.PI/180*e;this.object.rotation.set(t,i,s),this.refresh()}setHeight(e){e!==void 0&&(this.object.position.setZ(e),this.refresh())}getAnimations(){return this.animations}getObject(){return this.object}refresh(){this.layer.update()}show(){this.object.visible=!0,this.refresh()}hide(){this.object.visible=!1,this.refresh()}animate(e){this.linerAnimationFrame=requestAnimationFrame(()=>{this.animate(e)}),e()}startAnimations(){if(this.animations){const e=this.animations,t=new h.AnimationMixer(this.object),s={};for(let o=0;o<e.length;o++){const n=e[o];s[n.name]=t.clipAction(n)}const i=new h.Clock;for(const o in s)s[o].play();this.animate(()=>{const o=i.getDelta();t&&t.update(o),this.refresh()})}}stopAnimations(){cancelAnimationFrame(this.linerAnimationFrame)}remove(){this.object&&this.layer.remove(this.object)}destroy(){this.stopAnimations(),this.object&&(C(this.object),this.object=null,this.layer=null)}static clearAllModelCache(){window._THREE_GLTF_CACHE&&(Object.values(window._THREE_GLTF_CACHE).forEach(e=>{e.model&&C(e.model.scene)}),window._THREE_GLTF_CACHE={})}}d.ThreeGltf=F,d.ThreeLayer=z,d.clearGroup=C,d.clearScene=E,Object.defineProperty(d,"__esModule",{value:!0})});
//# sourceMappingURL=index.js.map
