class e{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:a,clientId:o,sessionId:i}=t||{};console.log("==============constructor"),console.log(t),console.log(a),this.autoReconnect=n,this.heartbeat=r,this.appId=a,this.clientId=o,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)}}let t;const n=new Uint8Array(16);function s(){if(!t&&(t="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto),!t))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return t(n)}var r=/^(?:[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 a=[];for(let e=0;e<256;++e)a.push((e+256).toString(16).slice(1));function o(e,t=0){return(a[e[t+0]]+a[e[t+1]]+a[e[t+2]]+a[e[t+3]]+"-"+a[e[t+4]]+a[e[t+5]]+"-"+a[e[t+6]]+a[e[t+7]]+"-"+a[e[t+8]]+a[e[t+9]]+"-"+a[e[t+10]]+a[e[t+11]]+a[e[t+12]]+a[e[t+13]]+a[e[t+14]]+a[e[t+15]]).toLowerCase()}function i(e){if(!function(e){return"string"==typeof e&&r.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 c="6ba7b810-9dad-11d1-80b4-00c04fd430c8",l="6ba7b811-9dad-11d1-80b4-00c04fd430c8";function d(e,t,n){function s(e,s,r,a){var c;if("string"==typeof e&&(e=function(e){e=unescape(encodeURIComponent(e));const t=[];for(let n=0;n>>9<<4)+1}function p(e,t){const n=(65535&e)+(65535&t);return(e>>16)+(t>>16)+(n>>16)<<16|65535&n}function u(e,t,n,s,r,a){return p((o=p(p(t,e),p(s,a)))<<(i=r)|o>>>32-i,n);var o,i}function y(e,t,n,s,r,a,o){return u(t&n|~t&s,e,t,r,a,o)}function f(e,t,n,s,r,a,o){return u(t&s|n&~s,e,t,r,a,o)}function k(e,t,n,s,r,a,o){return u(t^n^s,e,t,r,a,o)}function I(e,t,n,s,r,a,o){return u(n^(t|~s),e,t,r,a,o)}d("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,a=parseInt(s.charAt(n>>>4&15)+s.charAt(15&n),16);t.push(a)}return t}(function(e,t){e[t>>5]|=128<>5]|=(255&e[s/8])<>>32-t}d("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=b(o,30)>>>0,o=r,r=a}n[0]=n[0]+r>>>0,n[1]=n[1]+o>>>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 T{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:m(),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:m(),function:"PointController.ShowPointsByType",type:"noCallBack",parameters:{type:e.extendData.layerType}});break;case"terrain":this.socket.sendToEngin({code:m(),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:m(),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:m(),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:m(),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:m(),function:"PointController.HiddenPointsByType",type:"noCallBack",parameters:{type:e.extendData.layerType}};this.socket.sendToEngin(t);break;case"terrain":this.socket.sendToEngin({code:m(),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:m(),function:"MapServerController.RemoveTMSLayer",type:"noCallBack",parameters:{name:e.extendData.layerType}});break;case"wms":this.socket.sendToEngin({code:m(),function:"MapServerController.RemoveWMSLayer",type:"noCallBack",parameters:{name:e.extendData.layerType}});break;case"3dtiles":this.socket.sendToEngin({code:m(),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)}}}class D{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:a,clientId:o,sessionId:i}=t||{};this.autoReconnect=n,this.heartbeat=r,this.appId=a,this.clientId=o,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 D(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)}}export{T as MapServerController,D as Web3DCore,e as web3DCoreSocket}; //# sourceMappingURL=index.esm.js.map