@vsleem-realsee-viewer/shared 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1 @@
1
+ (function(f,m){typeof exports=="object"&&typeof module<"u"?m(exports):typeof define=="function"&&define.amd?define(["exports"],m):(f=typeof globalThis<"u"?globalThis:f||self,m(f.Shared={}))})(this,function(f){"use strict";var At=Object.defineProperty;var Rt=(f,m,E)=>m in f?At(f,m,{enumerable:!0,configurable:!0,writable:!0,value:E}):f[m]=E;var r=(f,m,E)=>Rt(f,typeof m!="symbol"?m+"":m,E);var m=(i=>(i[i.CADModel=5]="CADModel",i[i.BimfaceModel=6]="BimfaceModel",i[i.ForgeModel=7]="ForgeModel",i[i.ThreeDModel=8]="ThreeDModel",i[i.SkyMapModel=9]="SkyMapModel",i[i.ScaleModel=10]="ScaleModel",i))(m||{}),E=(i=>(i[i.Global=0]="Global",i))(E||{}),x=(i=>(i[i.Space=0]="Space",i[i.Model=1]="Model",i[i.Data=2]="Data",i))(x||{}),I=(i=>(i[i.Used=0]="Used",i[i.Enabled=1]="Enabled",i[i.Disabled=2]="Disabled",i))(I||{}),j=(i=>(i[i.SUCCESS=200]="SUCCESS",i[i.ERROR=-1]="ERROR",i[i.TIMEOUT=401]="TIMEOUT",i))(j||{}),g=(i=>(i.GET="GET",i.POST="POST",i))(g||{}),C=(i=>(i.JSON="application/json",i.FORM_URLENCODED="application/x-www-form-urlencoded;charset=UTF-8",i.FORM_DATA="multipart/form-data;charset=UTF-8",i.OCTET_STREAM="'application/octet-stream",i))(C||{});const W={baseUrl:"https://vsleem.com/api"},Q={isTransformResponse:!0,joinBaseUrl:!0,withAuthorize:!0},K={url:"",method:g.GET,headers:{}},k={...W};function tt(i){Object.assign(k,i)}async function b(i,t){const e={...Q,...t},s={...K,...i};try{const n=et(s,e),{url:o,...a}=n,c=await(await window.fetch(o,a)).json();return st(c,e)}catch(n){return it(n)}}function et(i,t){const{baseUrl:e,authorizeCode:s}=k,{joinBaseUrl:n,withAuthorize:o}=t;let{url:a,method:h,headers:c={},params:u,data:d}=i;n&&e&&(a=`${e}${a}`),h=h==null?void 0:h.toUpperCase();const l={...c};if(o&&s&&(l.Authorization=`Bearer ${s}`),h===g.POST&&!l["Content-Type"]&&(l["Content-Type"]=C.JSON),h===g.GET&&u){const T=new URLSearchParams(u);a+=`?${T.toString()}`}let y;return h===g.POST&&(y=l["Content-Type"]===C.JSON?JSON.stringify(d||{}):d),{url:a,method:h,headers:l,body:y}}function st(i,t){if(!t.isTransformResponse)return i;if(!i)throw new Error("Request no return data!");const{code:e,data:s,msg:n}=i;if(e===j.SUCCESS)return s;throw new Error(n||"Request error!")}function it(i){throw i instanceof Error?i:new Error(typeof i=="string"?i:"Unknown request error")}const nt=Object.freeze(Object.defineProperty({__proto__:null,request:b,setRequestGlobalConfig:tt},Symbol.toStringTag,{value:"Module"}));function X(i,t){return b({url:"/project/jssdk/cs/list",method:g.GET,params:i},t)}function F(i,t){return b({url:"/project/jssdk/cs/bind",method:g.POST,data:i},t)}function L(i,t){return b({url:"/project/jssdk/cs/save",method:g.POST,data:i},t)}function Y(i,t){return b({url:"/project/jssdk/cs/delete",method:g.POST,data:i},t)}function _(i,t){return b({url:"/project/jssdk/cs/mapping",method:g.POST,data:i},t)}function B(i,t){return b({url:"/project/jssdk/cs/mapping/query",method:g.GET,params:i},t)}function rt(i,t={isTransformResponse:!1,joinBaseUrl:!1,withAuthorize:!1}){return b({url:i,method:g.GET},t)}const ot=Object.freeze(Object.defineProperty({__proto__:null,bindCoordinate:F,getCoordinateList:X,getImageInfo:rt,getMappingRelation:B,mapingCoordinate:_,removeCoordinate:Y,saveCoordinate:L},Symbol.toStringTag,{value:"Module"})),at=typeof window<"u",ht=Object.prototype.toString;function v(i,t){return ht.call(i)===`[object ${t}]`}function U(i){return typeof i<"u"}function q(i){return!U(i)}function N(i){return i!==null&&v(i,"Object")}function G(i){return i===null}function ct(i){return v(i,"Date")}function lt(i){return v(i,"String")}function A(i){return typeof i=="function"}function ut(i){return v(i,"Boolean")}function dt(i){return v(i,"RegExp")}function D(i){return i&&Array.isArray(i)}function ft(i){return typeof window<"u"&&v(i,"Window")}function mt(i){return N(i)&&!!i.tagName}function yt(i){return typeof i=="number"||/^\d+(\.\d+)?$/.test(i)}function z(i){return v(Number(i),"Number")}function wt(i,t){return JSON.stringify(i)===JSON.stringify(t)}function pt(i){return q(i)||G(i)}function gt(i){return v(i,"Promise")&&N(i)&&A(i.then)&&A(i.catch)}function $(i){return O(i,new WeakMap)}function O(i,t){if(typeof i!="object"||i===null)return i;if(t.has(i))return t.get(i);let e;if(i instanceof Date)return e=new Date(i),t.set(i,e),e;if(i instanceof RegExp)return e=new RegExp(i),t.set(i,e),e;if(i instanceof Map)return e=new Map,t.set(i,e),i.forEach((n,o)=>{e.set(o,O(n,t))}),e;if(i instanceof Set)return e=new Set,t.set(i,e),i.forEach(n=>{e.add(O(n,t))}),e;if(ArrayBuffer.isView(i))return e=new i.constructor(i.buffer.slice(0),i.byteOffset,i.byteLength),t.set(i,e),e;if(i instanceof ArrayBuffer)return e=i.slice(0),t.set(i,e),e;if(Array.isArray(i)){e=[],t.set(i,e);for(let n=0;n<i.length;n++)n in i&&(e[n]=O(i[n],t));return e}e=Object.create(Object.getPrototypeOf(i)),t.set(i,e);for(const n in i)Object.prototype.hasOwnProperty.call(i,n)&&(e[n]=O(i[n],t));const s=Object.getOwnPropertySymbols(i);for(const n of s)Object.prototype.propertyIsEnumerable.call(i,n)&&(e[n]=O(i[n],t));return e}function Mt(i,t,e=!1){let s;const n=function(...o){const a=this,h=e&&!s;s&&clearTimeout(s),s=setTimeout(()=>{s=void 0,e||i.apply(a,o)},t),h&&i.apply(a,o)};return n.cancel=()=>{s&&clearTimeout(s),s=void 0},n}function xt(i,t,e=!1){let s,n;const o=function(...a){const h=this;n?(clearTimeout(s),s=setTimeout(()=>{Date.now()-n>=t&&(i.apply(h,a),n=Date.now())},t-(Date.now()-n))):(e&&i.apply(h,a),n=Date.now())};return o.cancel=()=>{clearTimeout(s),s=void 0,n=void 0},o}function vt(i,t={}){return new Promise((e,s)=>{const n=R(i);if(bt(n)){e(!0);return}const o=document.createElement("script");o.src=i,Object.entries(t).forEach(([a,h])=>{h!==!1&&o.setAttribute(a,h===!0?"":String(h))}),o.onload=()=>{e(!0)},o.onerror=()=>{document.head.removeChild(o),s(new Error(`Failed to load script: ${i}`))},document.head.appendChild(o)})}function bt(i){const t=R(i);return Array.from(document.scripts).some(e=>R(e.src)===t)}function R(i){try{const t=new URL(i,window.location.href);return`${t.origin}${t.pathname}`}catch{return i}}function Tt(i,t,e,s){const n=Math.min(i/e,t/s),o=e*n,a=s*n;return{scale:n,x:(i-o)/2,y:(t-a)/2,sw:o,sh:a}}function St(i,t,e){return{x:i*e.scale+e.x,y:t*e.scale+e.y}}function Et(i,t,e){return{x:(i-e.x)/e.scale,y:(t-e.y)/e.scale}}const Dt=Object.freeze(Object.defineProperty({__proto__:null,cloneDeep:$,debounce:Mt,getImageTransform:Tt,inBrowser:at,is:v,isArray:D,isBoolean:ut,isDate:ct,isDef:U,isElement:mt,isFunction:A,isNull:G,isNullOrUnDef:pt,isNumber:z,isNumeric:yt,isObject:N,isPromise:gt,isRegExp:dt,isSameValue:wt,isString:lt,isUnDef:q,isWindow:ft,loadScript:vt,throttle:xt,toCanvasCoord:St,toModelCoord:Et},Symbol.toStringTag,{value:"Module"}));class w{constructor(t){r(this,"x",0);r(this,"y",0);r(this,"z",0);r(this,"lat",0);r(this,"lon",0);r(this,"alt",0);r(this,"yaw",0);r(this,"pitch",0);r(this,"roll",0);r(this,"hasXYZ",!1);r(this,"hasGeo",!1);r(this,"hasAngle",!1);r(this,"plane","xy");const{x:e,y:s,z:n,lat:o,lon:a,alt:h,yaw:c,pitch:u,roll:d,plane:l="xy"}=t||{};z(e)&&z(s)&&(this.x=Number(e)||0,this.y=Number(s)||0,this.z=Number(n)||0,this.plane=l,this.hasXYZ=!0),z(o)&&z(a)&&Number(o)!==0&&Number(a)!==0&&(this.lat=Number(o)||0,this.lon=Number(a)||0,this.alt=Number(h)||0,this.hasGeo=!0),(c!==void 0||u!==void 0||d!==void 0)&&(this.yaw=Number(c)||0,this.pitch=Number(u)||0,this.roll=Number(d)||0,this.hasAngle=!0)}static dist(t,e){return Math.sqrt((t.x-e.x)**2+(t.y-e.y)**2+(t.z-e.z)**2)}static distXZ(t,e){return Math.sqrt((t.x-e.x)**2+(t.z-e.z)**2)}static distXY(t,e){return Math.sqrt((t.x-e.x)**2+(t.y-e.y)**2)}static toRadians(t){return(Number(t)||0)*Math.PI/180}static toDegrees(t){return(Number(t)||0)*180/Math.PI}static angleXZ(t,e,s){const n={x:t.x-e.x,z:t.z-e.z},o={x:s.x-e.x,z:s.z-e.z},a=n.x*o.x+n.z*o.z,h=Math.sqrt(n.x**2+n.z**2),c=Math.sqrt(o.x**2+o.z**2),u=Math.max(-1,Math.min(1,a/(h*c))),l=Math.acos(u)*180/Math.PI;return Math.min(l,360-l)}static JSONParse(t){if(t){const e=t==null?void 0:t.split(",").map(s=>Number(s)||0);return new w({x:e[0],y:e[1],z:e[2]})}}static JSONStringify(t){return t?`${t.x},${t.y},${t.z}`:""}projection(t,e,s){try{if((e==null?void 0:e.id)===(s==null?void 0:s.id))return new w(this);if((e==null?void 0:e.modelType)===m.SkyMapModel){const{refPoint:n}=(e==null?void 0:e.relativeMap)||{};if(this.hasGeo&&n){const o=P.LLHToXYZ(this,n);return this.x=o.x,this.y=o.y,this.z=o.z,this.hasXYZ=!0,this.project(t)}else throw new Error("没有完成gis与其他空间的映射")}else if((s==null?void 0:s.modelType)===m.SkyMapModel){const{refPoint:n}=(s==null?void 0:s.relativeMap)||{},o=this.project(t);if(o!=null&&o.hasXYZ&&n){const a=P.XYZToLLH(o,n);return o.lat=a.lat,o.lon=a.lon,o.alt=a.alt,o.hasGeo=!0,o}else throw new Error("没有完成gis与其他空间的映射")}else return this.project(t)}catch{}}project(t){if(this.hasXYZ){if(this.plane==="xz")return this.projectXZ(t);if(this.plane==="xy")return this.projectXY(t);throw new Error("plane should be xz or xy")}}projectXZ(t){const e=new w(this);e.x*=t.scale,e.y*=t.scale,e.z*=t.scale,e.yaw!==void 0&&(e.yaw+=t.yaw);const s=e.x*Math.cos(t.yaw)-e.z*Math.sin(t.yaw),n=e.x*Math.sin(t.yaw)+e.z*Math.cos(t.yaw);return e.x=s+t.x,e.y+=t.y,e.z=n+t.z,e}projectXY(t){const e=new w(this);e.x*=t.scale,e.y*=t.scale,e.z*=t.scale,e.yaw!==void 0&&(e.yaw+=t.yaw);const s=e.x*Math.cos(t.yaw)-e.y*Math.sin(t.yaw),n=e.x*Math.sin(t.yaw)+e.y*Math.cos(t.yaw);return e.x=s+t.x,e.y=n+t.y,e.z+=t.z,e}}class P{constructor(t){r(this,"lat",0);r(this,"lon",0);r(this,"alt",0);const{lat:e=0,lon:s=0,alt:n=0}=t||{};this.lat=e,this.lon=s,this.alt=n}static XYZToLLH(t,e){const n=.0033528106647474805,o=n*(2-n),a=w.toRadians(e.lat),h=6378137/Math.sqrt(1-o*Math.sin(a)**2)+e.alt;let c,u,d;if(t.plane==="xz"){const l=t.x/1e3/(h*Math.cos(a)),y=t.z/1e3/h;c=e.lon+w.toDegrees(l),u=e.lat-w.toDegrees(y),d=e.alt+t.y/1e3}else if(t.plane==="xy"){const l=t.x/1e3/(h*Math.cos(a)),y=t.y/1e3/h;c=e.lon+w.toDegrees(l),u=e.lat-w.toDegrees(y),d=e.alt+t.z/1e3}else throw new Error("Point's plane should be xz or xy");return new P({lat:u,lon:c,alt:d})}static LLHToXYZ(t,e){const n=.0033528106647474805,o=n*(2-n),a=w.toRadians(e.lat),h=6378137/Math.sqrt(1-o*Math.sin(a)**2)+e.alt,c=w.toRadians(t.lon-e.lon),u=w.toRadians(e.lat-t.lat),d=h*c*Math.cos(a),l=h*u;if(t.plane==="xz")return new w({x:d*1e3,y:(t.alt-e.alt)*1e3,z:l*1e3,plane:"xz"});if(t.plane==="xy")return new w({x:d*1e3,y:l*1e3,z:(t.alt-e.alt)*1e3,plane:"xy"});throw new Error("Point's plane must be xz or xy")}}class M{constructor(t){r(this,"scale",1);r(this,"yaw",0);r(this,"x",0);r(this,"y",0);r(this,"z",0);r(this,"start",0);r(this,"end",-1);r(this,"plane","xy");r(this,"refPoint");const{refPoint:e,...s}=t||{};e&&(this.refPoint=new P(e)),Object.assign(this,s)}static addRelativeMap(t,e){if(t.plane!==e.plane)throw new Error("The plane of two relative maps should be the same");const s=t.scale*e.scale,n=t.yaw+e.yaw,o=Math.cos(e.yaw),a=Math.sin(e.yaw);let h=0,c=0,u=0;if(t.plane==="xz"){const d=t.x*o-t.z*a,l=t.y,y=t.x*a+t.z*o;h=e.x+d*e.scale,c=e.y+l*e.scale,u=e.z+y*e.scale}else if(t.plane==="xy"){const d=t.x*o-t.y*a,l=t.x*a+t.y*o,y=t.z;h=e.x+d*e.scale,c=e.y+l*e.scale,u=e.z+y*e.scale}else throw new Error("plane should be xz or xy");return new M({scale:s,yaw:n,x:h,y:c,z:u,start:t.start,end:t.end,plane:t.plane})}static inverseRelativeMap(t){const e=1/t.scale,s=-t.yaw,n=Math.cos(-s),o=Math.sin(-s);let a=0,h=0,c=0;if(t.plane==="xz")a=-(t.x*n+t.z*o)*e,h=-t.y*e,c=-(t.z*n-t.x*o)*e;else if(t.plane==="xy")a=-(t.x*n+t.y*o)*e,h=-(t.y*n-t.x*o)*e,c=-t.z*e;else throw new Error("plane should be xz or xy");return new M({scale:e,yaw:s,x:a,y:h,z:c,start:t.start,end:t.end,plane:t.plane})}static JSONParse(t){try{let e=t?JSON.parse(t):void 0;const{reference_point:s}=e||{};return s&&(e={refPoint:s}),e?new M(e):void 0}catch{return}}static JSONStringify(t){return t?JSON.stringify(t):void 0}}class p{static async getCoordinateTree(t){const e=await X({projectId:t});if(e.length){const s=p.handleCoordinateList(e);return p.buildCoordinateTree(s,0)}}static async addCoordinate(t,e){const{projectId:s,id:n}=t,o=e.map(h=>{const{type:c,modelType:u,relativeMap:d,level:l,...y}=h,T=d?JSON.stringify(d):void 0;return{...y,projectId:s,parentId:n,coordinateType:c,renderType:u,relativePosition:T}}),a=await L(o);return p.handleCoordinateList(a)}static async removeCoordinate(t,e){const s=e.map(n=>n.id??-1);return await Y(s)}static async updateCoordinate(t,e){const{projectId:s,id:n}=t,o=e.map(h=>{const{type:c,relativeMap:u,level:d,...l}=h,y=M.JSONStringify(u);return{...l,relativePosition:y,projectId:s,parentId:n}}),a=await L(o);return p.handleCoordinateList(a)}static async bindCoordinate(t,e){const{projectId:s,id:n}=t,o=e.map(h=>{const{modelId:c}=h;return{modelId:c,parentId:n,projectId:s}}),a=await F(o);return p.handleCoordinateList(a)}static handleCoordinateList(t){return t==null?void 0:t.map(e=>{const{coordinateType:s,modelKey:n,renderType:o,relativePosition:a,...h}=e,c=M.JSONParse(a);return new J({...h,type:s,modelType:o,modelValue:n,relativeMap:c})})}static buildCoordinateTree(t,e){const s=new Map,n=[];return t.forEach(o=>{s.set(String(o.id),o)}),t.forEach(o=>{var h;const a=s.get(String(o.id));if(a)if(o.parentId===e)a.level=0,n.push(a);else{const c=s.get(String(o.parentId??-1));c&&(a.level=(Number(c.level)||0)+1,a.parent=c,(h=c.children)==null||h.push(a))}}),n.forEach(p.sortCoordinateTree),n[0]}static sortCoordinateTree(t){t.children&&(t.children.sort((e,s)=>{var n,o;if(e.type===x.Space){const a=Number((n=s==null?void 0:s.relativeMap)==null?void 0:n.z)-Number((o=e==null?void 0:e.relativeMap)==null?void 0:o.z);return a!==0?a:Number(s.createTime)-Number(e.createTime)}else return e.status===0&&s.status!==0?-1:s.status===0&&e.status!==0?1:Number(s.createTime)-Number(e.createTime)}),t.children.forEach(p.sortCoordinateTree))}static filterSpaceTree(t){const e=[];return t.forEach(s=>{const n=p.filterSpaceTree(s.children);s.children=n,s.disabled=s.disabled??!1,s.type!==x.Model&&e.push(s)}),e}}class J{constructor(t){r(this,"id",0);r(this,"type",0);r(this,"level");r(this,"relativeMap");r(this,"no");r(this,"name");r(this,"shortName");r(this,"status");r(this,"modelId");r(this,"modelType");r(this,"modelValue");r(this,"projectId");r(this,"parentId");r(this,"parent");r(this,"groupUuid");r(this,"children",[]);r(this,"z");r(this,"disabled");r(this,"createTime");const{relativeMap:e,parent:s,children:n,...o}=t||{};e&&(this.relativeMap=new M(e)),s&&(this.parent=s),n!=null&&n.length&&(this.children=n),Object.assign(this,o)}get spaceList(){return this.children.filter(t=>t.type===x.Space)}get modelList(){return this.children.filter(t=>t.type===x.Model)}get fullName(){const t=this.name?`(${this.name})`:"";return this.shortName?`${this.shortName}${t}`:this.name??""}async addChild(t){const e=D(t)?t:[t],s=await p.addCoordinate(this,e);this.mergeChild(s)}async removeChild(t){const e=D(t)?t:[t];await p.removeCoordinate(this,e);for(const s of e){const n=this.children.findIndex(o=>o.id===s.id);n!==-1&&this.children.splice(n,1)}}async updateChild(t){const e=D(t)?t:[t],s=await p.updateCoordinate(this,e);this.mergeChild(s)}async bindChild(t){const e=D(t)?t:[t],s=await p.bindCoordinate(this,e);this.mergeChild(s)}async mergeChild(t){t!=null&&t.length&&t.forEach(e=>{const s=this.children.find(n=>n.id===e.id);if(s){const{relativeMap:n,no:o,name:a,shortName:h,status:c,modelId:u,modelValue:d}=e;Object.assign(s,{relativeMap:n,no:o,name:a,shortName:h,status:c,modelId:u,modelValue:d})}else this.id===e.parentId&&(e.parent=this,this.children.unshift(e))})}async mappingTo(t){await _(t)}async fromMapping(){const t=await B({srcCsId:this.id});return t[t.length-1]}findRoot(t=!1){let e=this;for(;e.parent&&!(t&&!e.relativeMap);)e=e.parent;return e}findChildModel(t=[m.CADModel,m.SkyMapModel],e=!0){var h,c;const s=D(t)?t:[t];if(s.includes(this.modelType??-1)&&this.status!==I.Disabled)return this;const o=[x.Data,x.Model].includes(this.type)?this.findParentSpace():this,a=(c=(h=o==null?void 0:o.modelList)==null?void 0:h.filter(u=>s.includes(this.modelType??-1)?e?!!u.relativeMap:!0:!1))==null?void 0:c.sort((u,d)=>Number(u.status)-Number(d.status));return a==null?void 0:a[0]}findLatestModel(t=m.CADModel,e){var u;const s=new Set;for(const d of e??[])s.add(String(d.id));const n=[{node:this,distance:0}],o=D(t)?t:[t],a=new Set;let h,c=1/0;for(;n.length>0;){const d=n.shift();if(!d)break;const{node:l,distance:y}=d;if(s.has(String(l.id)))continue;if(o.includes(l.modelType??-1)){if(y<c&&(h=l,c=y,y<=1))break;continue}a.add(l);const T=[];if((u=l.parent)!=null&&u.children)for(const S of l.parent.children)S!==l&&!a.has(S)&&T.push(S);if(l.children)for(const S of l.children)a.has(S)||T.push(S);l.parent&&!a.has(l.parent)&&T.push(l.parent);for(const S of T)n.push({node:S,distance:y+1})}return h}findParentSpace(){let t=this;for(;t&&t.type!==x.Space;)t=t.parent;return t}findParentSpaceNames(t=2){const e=[];let s=this;for(;s&&t>0;)s.type===x.Space&&(e.unshift(s.fullName),t--),s=s.parent;return e}findCsGroup(){var s;const{groupUuid:t,parent:e}=this;return t?((s=e==null?void 0:e.children)==null?void 0:s.filter(n=>n.groupUuid===t))||[]:[this]}findCsByLevel(t){if(this.level===t)return this;if(this.children.length)for(const e of this.children){const s=e.findCsByLevel(t);if(s)return s}}findCsById(t){if(t){if(this.id===t)return this;for(const e of this.children){const s=e.findCsById(t);if(s)return s}}}getCsRoutes(t=!1){let e=this;const s=[e];for(;e!=null&&e.parent&&!(t&&!e.relativeMap);)e=e.parent,e&&s.push(e);return s}getMappedCsTree(){function t(n){var o;return(o=n.children)!=null&&o.length&&(n.children=n.children.filter(a=>!!(a!=null&&a.relativeMap)&&a.status!==I.Disabled).map(a=>t(a))),n}const e=$(this.findRoot(!0)),s=t(e);return s.parentId=0,s.parent=void 0,s}getDestRelativeMap(t){var o;if(this.id===t.id)return new M;const e=this.getRelativeMaps(),s=t.getRelativeMaps();let n=new M;return e==null||e.forEach(a=>{n=M.addRelativeMap(n,a)}),(o=s==null?void 0:s.reverse())==null||o.forEach(a=>{n=M.addRelativeMap(n,M.inverseRelativeMap(a))}),n}getRelativeMaps(){let t=this;const e=[];for(;t!=null&&t.parent&&t.relativeMap;)e.push(t.relativeMap),t=t.parent;return e}}class Ot{constructor(t){r(this,"canvas");r(this,"ctx");r(this,"options");r(this,"offset",{x:0,y:0});r(this,"curOffset",{x:0,y:0});r(this,"mousePosition",{x:-1,y:-1});r(this,"MAX_SCALE",60);r(this,"MIN_SCALE",1);r(this,"STEP_SCALE",.5);r(this,"scale",1);r(this,"preScale",1);r(this,"width",0);r(this,"height",0);r(this,"x",0);r(this,"y",0);r(this,"timeout",0);r(this,"lastTouch");r(this,"initialDistance",0);r(this,"touchMode",0);r(this,"isMouseover",!1);r(this,"isBindEvent",!0);r(this,"isDrawAssist",!1);r(this,"customDrawAssist");r(this,"isMoveRedrawing");r(this,"afterDraw");r(this,"screenPos",{screenX:0,screenY:0});const{container:e,width:s=300,height:n=300,isBindEvent:o=!0,isDrawAssist:a=!1,isMoveRedrawing:h,customDrawAssist:c,afterDraw:u,...d}=t;this.canvas=e,this.ctx=this.canvas.getContext("2d"),this.width=s,this.height=n,this.canvas.width=s,this.canvas.height=n,this.isBindEvent=o,this.isDrawAssist=a,this.customDrawAssist=c,this.isMoveRedrawing=h??a,this.options=d,this.onMousedown=this.onMousedown.bind(this),this.onMousemove=this.onMousemove.bind(this),this.onMousemoveTemp=this.onMousemoveTemp.bind(this),this.onMouseup=this.onMouseup.bind(this),this.onMousewheel=this.onMousewheel.bind(this),this.onDblclick=this.onDblclick.bind(this),this.onTouchstart=this.onTouchstart.bind(this),this.onTouchmove=this.onTouchmove.bind(this),this.onTouchend=this.onTouchend.bind(this),this.onMouseout=this.onMouseout.bind(this),this.afterDraw=this.afterDraw,o&&(this.canvas.addEventListener("DOMMouseScroll",this.onMousewheel),this.canvas.addEventListener("mousewheel",this.onMousewheel),this.canvas.addEventListener("mousedown",this.onMousedown),this.canvas.addEventListener("mousemove",this.onMousemove),this.canvas.addEventListener("mouseout",this.onMouseout),this.canvas.addEventListener("dblclick",this.onDblclick),this.canvas.addEventListener("touchstart",this.onTouchstart))}onClick(t){const{screenX:e,screenY:s}=t;this.timeout&&clearTimeout(this.timeout);const n=this.getPos(t);this.x=n.x,this.y=n.y,this.screenPos={screenX:e,screenY:s},this.options.onClick&&(this.timeout=setTimeout(()=>{const o=parseFloat(((this.x-this.offset.x)/this.scale).toFixed(2)),a=parseFloat(((this.y-this.offset.y)/this.scale).toFixed(2));this.options.onClick(o,a)},200))}onMouseout(t){this.isMouseover=!1,this.draw()}onTouchstart(t){t.preventDefault(),t.touches.length==1?this.touchMode===0&&(this.touchMode=1):t.touches.length>=2&&this.touchMode<2&&(this.touchMode=2),this.touchMode==1&&t.touches.length==1?this.onTouch(t.touches[0]):this.touchMode==2&&t.touches.length==2&&this.onBothTouchstart(t),this.canvas.addEventListener("touchmove",this.onTouchmove),this.canvas.addEventListener("touchend",this.onTouchend)}onMousedown(t){this.onClick(t),this.canvas.addEventListener("mousemove",this.onMousemoveTemp),this.canvas.addEventListener("mouseup",this.onMouseup)}onBothTouchstart(t){t.preventDefault();const e={x:t.touches[0].clientX,y:t.touches[0].clientY},s={x:t.touches[1].clientX,y:t.touches[1].clientY},n=this.getPos({clientX:(e.x+s.x)/2,clientY:(e.y+s.y)/2});this.x=n.x,this.y=n.y,this.curOffset.x=this.offset.x,this.curOffset.y=this.offset.y,this.initialDistance=Math.sqrt(Math.pow(s.x-e.x,2)+Math.pow(s.y-e.y,2))}onTouchmove(t){t.preventDefault(),this.touchMode==1&&t.touches.length==1?(this.onMousemoveTemp(t.touches[0]),this.onMousemove(t.touches[0])):this.touchMode==2&&t.touches.length==2&&this.onBothTouchmove(t)}onMousemove(t){const e=this.getPos(t);this.mousePosition.x=e.x,this.mousePosition.y=e.y,this.isMouseover=!0,this.isMoveRedrawing&&this.draw()}onMousemoveTemp(t){const{screenX:e,screenY:s}=this.screenPos;(Math.abs(e-t.screenX)>10||Math.abs(s-t.screenY)>10)&&(this.timeout&&clearTimeout(this.timeout),this.offset.x=this.curOffset.x+(this.mousePosition.x-this.x),this.offset.y=this.curOffset.y+(this.mousePosition.y-this.y),!this.isMoveRedrawing&&this.draw())}onBothTouchmove(t){if(t.preventDefault(),this.initialDistance){const e={x:t.touches[0].clientX,y:t.touches[0].clientY},s={x:t.touches[1].clientX,y:t.touches[1].clientY},n=Math.sqrt(Math.pow(s.x-e.x,2)+Math.pow(s.y-e.y,2));if(this.scale+=(n-this.initialDistance)/30*this.STEP_SCALE,this.initialDistance=n,this.scale>this.MAX_SCALE){this.scale=this.MAX_SCALE;return}if(this.scale<this.MIN_SCALE){this.scale=this.MIN_SCALE;return}this.zoom()}}onTouchend(){this.touchMode=0,this.onMouseup()}onMouseup(){this.curOffset.x=this.offset.x,this.curOffset.y=this.offset.y,this.canvas.removeEventListener("mousemove",this.onMousemoveTemp),this.canvas.removeEventListener("mouseup",this.onMouseup),this.canvas.removeEventListener("touchmove",this.onTouchmove),this.canvas.removeEventListener("touchend",this.onTouchend)}onMousewheel(t){this.timeout&&clearTimeout(this.timeout),t.preventDefault();const e=this.getPos(t);this.x=e.x,this.y=e.y;const s=t.wheelDelta>0||t.detail<0?this.STEP_SCALE:-this.STEP_SCALE;if(this.scale=parseFloat((this.scale+s).toFixed(2)),this.scale>this.MAX_SCALE){this.scale=this.MAX_SCALE;return}if(this.scale<this.MIN_SCALE){this.scale=this.MIN_SCALE;return}this.zoom()}onTouch(t){const e=Date.now(),{lastTouchTime:s=0,lastTouchX:n=0,lastTouchY:o=0}=this.lastTouch||{};e-s<300&&Math.abs(t.clientX-n)<30&&Math.abs(t.clientY-o)<30?(this.onDblclick(t),this.lastTouch={lastTouchTime:0,lastTouchX:0,lastTouchY:0}):(this.onClick(t),this.lastTouch={lastTouchTime:e,lastTouchX:t.clientX,lastTouchY:t.clientY})}onDblclick(t){this.timeout&&clearTimeout(this.timeout),this.reset(),this.draw()}zoom(){this.offset.x=this.x-(this.x-this.offset.x)*this.scale/this.preScale,this.offset.y=this.y-(this.y-this.offset.y)*this.scale/this.preScale,this.draw(),this.preScale=this.scale,this.curOffset.x=this.offset.x,this.curOffset.y=this.offset.y}reset(t){const{width:e=this.width,height:s=this.height,scale:n=1,preScale:o=1,offset:a={x:0,y:0},curOffset:h={x:0,y:0}}=t||{};this.width=e,this.height=s,this.canvas.width=e,this.canvas.height=s,this.scale=n,this.preScale=o,this.offset=a,this.curOffset=h}drawAssist(){const t=this.ctx;t.save(),t.beginPath(),t.lineWidth=1,t.strokeStyle="#C656D5",t.moveTo(0,this.mousePosition.y),t.lineTo(this.width,this.mousePosition.y),t.closePath(),t.stroke(),t.beginPath(),t.moveTo(this.mousePosition.x,0),t.lineTo(this.mousePosition.x,this.height),t.closePath(),t.stroke(),t.restore()}draw(){var t;this.ctx.clearRect(0,0,this.width,this.height),this.ctx.save(),this.ctx.translate(this.offset.x,this.offset.y),this.ctx.scale(this.scale,this.scale),this.options.draw(this.ctx,this),this.ctx.restore(),this.isDrawAssist&&this.isMouseover&&(this.customDrawAssist?this.customDrawAssist():this.drawAssist()),(t=this.afterDraw)==null||t.call(this,this.ctx,this)}getPos(t){const e=this.canvas.getBoundingClientRect();let s=parseFloat((t.clientX-e.left).toFixed(2)),n=parseFloat((t.clientY-e.top).toFixed(2));return s=s<0?0:s,n=n<0?0:n,{x:s,y:n}}unBindEvent(){this.isBindEvent&&(this.canvas.removeEventListener("mousemove",this.onMousemove),this.canvas.removeEventListener("DOMMouseScroll",this.onMousewheel),this.canvas.removeEventListener("mousewheel",this.onMousewheel),this.canvas.removeEventListener("mousedown",this.onMousedown),this.canvas.removeEventListener("mouseout",this.onMouseout),this.canvas.removeEventListener("dblclick",this.onDblclick))}}const Z={};class Pt{constructor(t){r(this,"type","image");r(this,"x");r(this,"y");r(this,"width");r(this,"height");r(this,"img");r(this,"src");r(this,"redraw");this.x=t.x||0,this.y=t.y||0,this.width=t.width||0,this.height=t.height||0,this.src=t.src,this.redraw=t.redraw,this.img=this.loadImage(t.onload)}loadImage(t){const e=Z[this.src];if(e)return queueMicrotask(()=>{var s;t==null||t(e),(s=this.redraw)==null||s.call(this)}),e;{const s=new Image;return s.crossOrigin="anonymous",s.src=this.src,s.onload=()=>{var n;Z[this.src]=s,t==null||t(s),(n=this.redraw)==null||n.call(this)},s}}draw(t){try{if(!this.img.complete)return;t.save(),t.drawImage(this.img,this.x,this.y,this.width,this.height),t.restore()}catch(e){console.error(e)}}}class zt{constructor(t){r(this,"id","");r(this,"type","point");r(this,"x");r(this,"y");r(this,"r");r(this,"text");r(this,"backgroundColor");r(this,"index");r(this,"pIndex");r(this,"parentId");this.id=t.id,this.x=t.x,this.y=t.y,this.r=t.r||15,this.text=t.text||"",this.index=t.index,this.pIndex=t.pIndex,this.parentId=t.parentId,this.backgroundColor=t.backgroundColor||"rgba(91, 179, 111, 0.8)"}draw(t,e){t.save();const s=1/e.scale;t.beginPath(),t.arc(this.x,this.y,this.r*s,0,2*Math.PI),t.fillStyle=this.backgroundColor,t.fill(),t.font=`${this.r*s}px Microsoft YaHei`,t.textAlign="center",t.fillStyle="#FFFFFF",t.fillText(this.text,this.x,this.y+this.r*s/3),t.restore()}}const H={};class It{constructor(t){r(this,"id","");r(this,"type","issue");r(this,"x");r(this,"y");r(this,"width");r(this,"height");r(this,"src");r(this,"img");r(this,"index");r(this,"pIndex");r(this,"parentId");r(this,"count");r(this,"badgeR");r(this,"redraw");this.id=t.id,this.x=t.x,this.y=t.y,this.width=t.width||0,this.height=t.height||0,this.index=t.index,this.pIndex=t.pIndex,this.parentId=t.parentId,this.count=t.count||0,this.badgeR=3,this.src=t.src,this.redraw=t.redraw,this.img=this.loadImage(t.onload)}loadImage(t){const e=H[this.src];if(e)return queueMicrotask(()=>{var s;t==null||t(e),(s=this.redraw)==null||s.call(this)}),e;{const s=new Image;return s.src=this.src,s.crossOrigin="anonymous",s.onload=()=>{var n;H[this.src]=s,t==null||t(s),(n=this.redraw)==null||n.call(this)},s}}draw(t,e){if(!this.img.complete)return;const s=1/e.scale,n=this.width*s,o=this.height*s,a=this.x-n/2,h=this.y-o,c=this.badgeR*s,u=c*1.5;t.save(),t.drawImage(this.img,a,h,n,o),t.beginPath(),this.count>1&&(t.arc(this.x+n*.3,this.y-o*.8,c,0,2*Math.PI),t.fillStyle="red",t.fill(),t.font=`${u}px Microsoft YaHei`,t.textAlign="center",t.fillStyle="#FFFFFF",t.fillText(this.count.toString(),this.x+n*.3,this.y-o*.8+c/2)),t.restore()}}const V={};class Ct{constructor(t){r(this,"type","marker");r(this,"x");r(this,"y");r(this,"url");r(this,"width");r(this,"height");r(this,"anchor");r(this,"img");r(this,"scale");r(this,"redraw");r(this,"beforeDraw");this.x=t.x,this.y=t.y,this.url=t.url,this.width=t.width??0,this.height=t.height??0,this.anchor=t.anchor,this.scale=t.scale??1,t.redraw&&(this.redraw=t.redraw),t.beforeDraw&&(this.beforeDraw=t.beforeDraw),this.img=this.loadImage(t.onload)}loadImage(t){const e=V[this.url];if(e)return queueMicrotask(()=>{var s;t==null||t(e),(s=this.redraw)==null||s.call(this)}),e;{const s=new Image;return s.src=this.url,s.crossOrigin="anonymous",s.onload=()=>{var n;V[this.url]=s,t==null||t(s),(n=this.redraw)==null||n.call(this)},s}}calculateIconPosition(){var s,n;const t=((s=this.anchor)==null?void 0:s.x)??this.width/2,e=((n=this.anchor)==null?void 0:n.y)??this.height/2;return{iconStartX:this.x-t*this.scale,iconStartY:this.y-e*this.scale}}draw(t,e){var o,a;if((o=this.beforeDraw)==null||o.call(this,t,e),!((a=this.img)!=null&&a.complete))return;const{iconStartX:s,iconStartY:n}=this.calculateIconPosition();t.save();try{t.drawImage(this.img,s,n,this.width*this.scale,this.height*this.scale)}catch(h){console.error("绘制标记时出错:",h)}finally{t.restore()}}}class Lt{constructor(t){r(this,"type","radar");r(this,"x");r(this,"y");r(this,"r");r(this,"angle");r(this,"text");r(this,"hFov",90);r(this,"beforeDraw");this.x=t.x,this.y=t.y,this.r=t.r||15,this.angle=t.angle||0,this.text=t.text||"",this.hFov=t.fovh||90,this.beforeDraw=t.beforeDraw}draw(t,e){var h;(h=this.beforeDraw)==null||h.call(this,t,e);const s=1/e.scale,[n,o]=[(this.angle-this.hFov/2)/180*Math.PI,(this.angle+this.hFov/2)/180*Math.PI];t.save();const a=t.createRadialGradient(this.x,this.y,0,this.x,this.y,this.r*s);a.addColorStop(0,"rgba(180, 42, 42, 1)"),a.addColorStop(1,"rgba(180, 42, 42, 0.5)"),t.beginPath(),t.moveTo(this.x,this.y),t.arc(this.x,this.y,this.r*s,n,o),t.closePath(),t.fillStyle=a,t.fill(),t.restore()}}class Nt{constructor(t){r(this,"type","region");r(this,"x");r(this,"y");r(this,"shape");r(this,"areaPoints");r(this,"backgroundColor");if(this.x=t.x,this.y=t.y,this.shape=t.shape||"",this.backgroundColor=t.backgroundColor,t.areaPoints.length===2){const[{x:e,y:s},{},{x:n,y:o}]=t.areaPoints;this.areaPoints=[{x:Math.min(e,n),y:Math.min(s,o)},{x:Math.max(e,n),y:Math.min(s,o)},{x:Math.max(e,n),y:Math.max(s,o)},{x:Math.min(e,n),y:Math.max(s,o)}]}else this.areaPoints=t.areaPoints}draw(t,e){if(t.save(),t.beginPath(),t.globalAlpha=.3,t.fillStyle=this.backgroundColor,this.shape==="circle"){const[{x:s,y:n},{},{x:o,y:a}]=this.areaPoints,h=Math.abs(o-s)/2,c=s+(o-s)/2,u=n+(a-n)/2;t.arc(c,u,h,0,2*Math.PI)}else this.areaPoints.forEach((s,n)=>{const{x:o,y:a}=s;n===0?t.moveTo(o,a):t.lineTo(o,a)});t.fill(),t.restore()}}f.CanvasElement=Ot,f.CanvasImageElement=Pt,f.CanvasIssueElement=It,f.CanvasMarkerElement=Ct,f.CanvasPointElement=zt,f.CanvasRadarElement=Lt,f.CanvasRegionElement=Nt,f.Coordinate=J,f.CoordinateLevel=E,f.CoordinateModelType=m,f.CoordinateStatus=I,f.CoordinateType=x,f.DataSource=p,f.GeoPoint=P,f.Point=w,f.RelativeMap=M,f.RequestEnum=g,f.api=ot,f.http=nt,f.utils=Dt,Object.defineProperty(f,Symbol.toStringTag,{value:"Module"})});
package/package.json ADDED
@@ -0,0 +1,25 @@
1
+ {
2
+ "name": "@vsleem-realsee-viewer/shared",
3
+ "version": "1.0.0",
4
+ "private": false,
5
+ "description": "Shared utilities for VSLeem RealSee Viewer",
6
+ "main": "./dist/index.umd.js",
7
+ "module": "./dist/index.mjs",
8
+ "types": "./dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "development": "./src/index.ts",
12
+ "production": "./dist/index.mjs",
13
+ "types": "./dist/index.d.ts",
14
+ "import": "./dist/index.mjs",
15
+ "require": "./dist/index.umd.js",
16
+ "default": "./dist/index.mjs"
17
+ }
18
+ },
19
+ "files": [
20
+ "dist"
21
+ ],
22
+ "scripts": {
23
+ "build": "vite build"
24
+ }
25
+ }