"use strict";Object.defineProperty(exports,"__esModule",{value:!0});let e;const t=new Uint8Array(16);function n(){if(!e&&(e="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto),!e))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return e(t)}var s=/^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i;const r=[];for(let e=0;e<256;++e)r.push((e+256).toString(16).slice(1));function o(e,t=0){return(r[e[t+0]]+r[e[t+1]]+r[e[t+2]]+r[e[t+3]]+"-"+r[e[t+4]]+r[e[t+5]]+"-"+r[e[t+6]]+r[e[t+7]]+"-"+r[e[t+8]]+r[e[t+9]]+"-"+r[e[t+10]]+r[e[t+11]]+r[e[t+12]]+r[e[t+13]]+r[e[t+14]]+r[e[t+15]]).toLowerCase()}function a(e){if(!function(e){return"string"==typeof e&&s.test(e)}(e))throw TypeError("Invalid UUID");let t;const n=new Uint8Array(16);return n[0]=(t=parseInt(e.slice(0,8),16))>>>24,n[1]=t>>>16&255,n[2]=t>>>8&255,n[3]=255&t,n[4]=(t=parseInt(e.slice(9,13),16))>>>8,n[5]=255&t,n[6]=(t=parseInt(e.slice(14,18),16))>>>8,n[7]=255&t,n[8]=(t=parseInt(e.slice(19,23),16))>>>8,n[9]=255&t,n[10]=(t=parseInt(e.slice(24,36),16))/1099511627776&255,n[11]=t/4294967296&255,n[12]=t>>>24&255,n[13]=t>>>16&255,n[14]=t>>>8&255,n[15]=255&t,n}const i="6ba7b810-9dad-11d1-80b4-00c04fd430c8",c="6ba7b811-9dad-11d1-80b4-00c04fd430c8";function l(e,t,n){function s(e,s,r,i){var c;if("string"==typeof e&&(e=function(e){e=unescape(encodeURIComponent(e));const t=[];for(let n=0;n>>9<<4)+1}function h(e,t){const n=(65535&e)+(65535&t);return(e>>16)+(t>>16)+(n>>16)<<16|65535&n}function p(e,t,n,s,r,o){return h((a=h(h(t,e),h(s,o)))<<(i=r)|a>>>32-i,n);var a,i}function u(e,t,n,s,r,o,a){return p(t&n|~t&s,e,t,r,o,a)}function y(e,t,n,s,r,o,a){return p(t&s|n&~s,e,t,r,o,a)}function f(e,t,n,s,r,o,a){return p(t^n^s,e,t,r,o,a)}function k(e,t,n,s,r,o,a){return p(n^(t|~s),e,t,r,o,a)}l("v3",48,(function(e){if("string"==typeof e){const t=unescape(encodeURIComponent(e));e=new Uint8Array(t.length);for(let n=0;n>5]>>>r%32&255,o=parseInt(s.charAt(n>>>4&15)+s.charAt(15&n),16);t.push(o)}return t}(function(e,t){e[t>>5]|=128<>5]|=(255&e[s/8])<>>32-t}l("v5",80,(function(e){const t=[1518500249,1859775393,2400959708,3395469782],n=[1732584193,4023233417,2562383102,271733878,3285377520];if("string"==typeof e){const t=unescape(encodeURIComponent(e));e=[];for(let n=0;n>>0;l=c,c=i,i=v(a,30)>>>0,a=r,r=o}n[0]=n[0]+r>>>0,n[1]=n[1]+a>>>0,n[2]=n[2]+i>>>0,n[3]=n[3]+c>>>0,n[4]=n[4]+l>>>0}return[n[0]>>24&255,n[0]>>16&255,n[0]>>8&255,255&n[0],n[1]>>24&255,n[1]>>16&255,n[1]>>8&255,255&n[1],n[2]>>24&255,n[2]>>16&255,n[2]>>8&255,255&n[2],n[3]>>24&255,n[3]>>16&255,n[3]>>8&255,255&n[3],n[4]>>24&255,n[4]>>16&255,n[4]>>8&255,255&n[4]]}));class b{constructor(e,t){this.socket=null,this.reconnectCount=0,this.delay=null,this.timer=null;const{autoReconnect:n=!0,query:s={},heartbeat:r=!0,appId:o,clientId:a,sessionId:i}=t||{};this.autoReconnect=n,this.heartbeat=r,this.appId=o,this.clientId=a,this.sessionId=i,this.query=s,this.url=e||"ws://test/api"+JSON.stringify(Object.assign({token:""},this.query)),console.log("==============Web3DCore constructor",(new Date).getTime())}static getInstance(e,t){return this.instance||(this.instance=new b(e,t),this.instance.connect()),this.instance}connect(){this.close(),this.socket=new WebSocket(this.url),this.onError(),this.onOpen()}onOpen(){this.socket&&(this.socket.onopen=()=>{this.login(),this.send("ping"),this.heartbeat&&this.startHeartbeat()})}startHeartbeat(){var e,t;const n=(null===(e=this.heartbeat)||void 0===e?void 0:e.message)||"ping",s=(null===(t=this.heartbeat)||void 0===t?void 0:t.interval)||1e7;this.timer=setInterval((()=>{this.send(n)}),s)}onError(){this.socket&&(this.socket.onerror=()=>{var e;const t=(null===(e=this.autoReconnect)||void 0===e?void 0:e.reconnectMaxCount)||3;this.autoReconnect&&this.reconnectCount{try{const n=JSON.parse(t.data);n.data=JSON.parse(n.data),e(n)}catch(n){e(t)}})}sendToEngin(e){var t={appId:this.appId,sessionId:this.sessionId,clientId:this.clientId,action:"2",role:"web",data:e};this.send(t)}sendToWebClient(e){var t={appId:this.appId,sessionId:this.sessionId,clientId:this.clientId,action:"3",role:"web",data:e};this.send(t)}send(e){console.log("=========== send"),console.log(this.socket),this.socket&&(this.socket.readyState===this.socket.OPEN?this.socket.send(JSON.stringify(e)):(this.socket.readyState===this.socket.CONNECTING||this.connect(),this.delay=setTimeout((()=>{var t;null===(t=this.socket)||void 0===t||t.send(JSON.stringify(e))}),1e3)))}login(){var e={appId:this.appId,sessionId:this.sessionId,clientId:this.clientId,action:"1",role:"web"};console.error(e),this.send(e)}}exports.MapServerController=class{constructor(e){this.socket=null,this.socket=e}debugInfo(){var e={appId:this.socket.appId,sessionId:this.socket.sessionId,clientId:this.socket.clientId,action:"100",role:"web",data:""};this.socket.send(e)}createApiServiceLayer(e){if("api"==e.extendData.type){var t={code:g(),function:"",type:"noCallBack",parameters:{layerType:e.extendData.layerType,requestsType:"",requestsContentType:"",url:"",headers:"",paramerts:"",treeStructure:"",fieldMapping:"",fieldType:""}};t.function="PointController.AddPointsFromServerApi",t.parameters.requestsType=e.extendData.requestsType,t.parameters.requestsContentType="json",t.parameters.url=e.extendData.url,t.parameters.headers=e.extendData.haeder,t.parameters.paramerts=e.extendData.params,t.parameters.treeStructure=e.extendData.treeStructure,t.parameters.fieldMapping=e.extendData.fieldMapping,t.parameters.fieldType=e.extendData.fieldType,this.socket.sendToEngin(t)}}showLayer(e){switch(e.extendData.type){case"api":this.socket.sendToEngin({code:g(),function:"PointController.ShowPointsByType",type:"noCallBack",parameters:{type:e.extendData.layerType}});break;case"terrain":this.socket.sendToEngin({code:g(),function:"MapServerController.SetTerrainUrl",type:"noCallBack",parameters:{type:e.extendData.type,icon:"图标路径",name:e.extendData.layerType,serverOrFile:!0,url:e.extendData.url}});break;case"tms":this.socket.sendToEngin({code:g(),function:"MapServerController.AddTMSLayer",type:"noCallBack",parameters:{type:e.extendData.type,icon:"图标路径",name:e.extendData.layerType,serverOrFile:!0,url:e.extendData.url}});break;case"wms":this.socket.sendToEngin({code:g(),function:"MapServerController.AddWMSLayer",type:"noCallBack",parameters:{type:e.extendData.type,icon:"图标路径",name:e.extendData.layerType,serverOrFile:!0,url:e.extendData.url,layer:e.extendData.layer}});break;case"3dtiles":this.socket.sendToEngin({code:g(),function:"MapServerController.Add3DTileLayer",type:"noCallBack",parameters:{type:e.extendData.type,icon:"图标路径",name:e.extendData.layerType,serverOrFile:!0,url:e.extendData.url,layer:e.extendData.layer}});break;case"Point":console.log(e.extendData)}}hideLayer(e){switch(e.extendData.type){case"api":var t={code:g(),function:"PointController.HiddenPointsByType",type:"noCallBack",parameters:{type:e.extendData.layerType}};this.socket.sendToEngin(t);break;case"terrain":this.socket.sendToEngin({code:g(),function:"MapServerController.AddTMSLayer",type:"noCallBack",parameters:{type:e.extendData.type,icon:"图标路径",name:e.extendData.layerType,serverOrFile:!0,url:e.extendData.url}});break;case"tms":this.socket.sendToEngin({code:g(),function:"MapServerController.RemoveTMSLayer",type:"noCallBack",parameters:{name:e.extendData.layerType}});break;case"wms":this.socket.sendToEngin({code:g(),function:"MapServerController.RemoveWMSLayer",type:"noCallBack",parameters:{name:e.extendData.layerType}});break;case"3dtiles":this.socket.sendToEngin({code:g(),function:"MapServerController.Remove3DTileLayer",type:"noCallBack",parameters:{type:e.extendData.type,icon:"图标路径",name:e.extendData.layerType,serverOrFile:!0,url:e.extendData.url,layer:e.extendData.layer}});break;case"Point":console.log(e.extendData)}}},exports.Web3DCore=b,exports.web3DCoreSocket=class{constructor(e,t){this.socket=null,this.reconnectCount=0,this.delay=null,this.timer=null;const{autoReconnect:n=!0,query:s={},heartbeat:r=!0,appId:o,clientId:a,sessionId:i}=t||{};console.log("==============constructor"),console.log(t),console.log(o),this.autoReconnect=n,this.heartbeat=r,this.appId=o,this.clientId=a,this.sessionId=i,this.query=s,this.url=e||"ws://test/api"+JSON.stringify(Object.assign({token:""},this.query)),this.connect()}connect(){this.close(),this.socket=new WebSocket(this.url),this.onError(),this.onOpen()}onOpen(){this.socket&&(this.socket.onopen=()=>{this.login(),this.send("ping"),this.heartbeat&&this.startHeartbeat()})}startHeartbeat(){var e,t;const n=(null===(e=this.heartbeat)||void 0===e?void 0:e.message)||"ping",s=(null===(t=this.heartbeat)||void 0===t?void 0:t.interval)||1e7;this.timer=setInterval((()=>{this.send(n)}),s)}onError(){this.socket&&(this.socket.onerror=()=>{var e;const t=(null===(e=this.autoReconnect)||void 0===e?void 0:e.reconnectMaxCount)||3;this.autoReconnect&&this.reconnectCount{try{const n=JSON.parse(t.data);n.data=JSON.parse(n.data),e(n)}catch(n){e(t)}})}sendToEngin(e){var t={appId:this.appId,sessionId:this.sessionId,clientId:this.clientId,action:"2",role:"web",data:e};this.send(t)}sendToWebClient(e){var t={appId:this.appId,sessionId:this.sessionId,clientId:this.clientId,action:"3",role:"web",data:e};this.send(t)}send(e){this.socket&&(this.socket.readyState===this.socket.OPEN?this.socket.send(JSON.stringify(e)):(this.socket.readyState===this.socket.CONNECTING||this.connect(),this.delay=setTimeout((()=>{var t;null===(t=this.socket)||void 0===t||t.send(JSON.stringify(e))}),1e3)))}login(){var e={appId:this.appId,sessionId:this.sessionId,clientId:this.clientId,action:"1",role:"web"};console.error(e),this.send(e)}}; //# sourceMappingURL=index.cjs.js.map