@aibee/crc-bmap 0.0.16 → 0.0.17
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.
- package/example/index.html +1 -0
- package/example/src/main.ts +69 -2
- package/lib/bmap.cjs.min.js +2 -2
- package/lib/bmap.cjs.min.js.map +3 -3
- package/lib/bmap.esm.js +42 -6
- package/lib/bmap.esm.js.map +2 -2
- package/lib/bmap.esm.min.js +2 -2
- package/lib/bmap.esm.min.js.map +3 -3
- package/lib/bmap.min.js +2 -2
- package/lib/bmap.min.js.map +3 -3
- package/lib/src/bmap.d.ts +8 -4
- package/lib/src/types/index.d.ts +1 -1
- package/package.json +1 -1
package/example/index.html
CHANGED
package/example/src/main.ts
CHANGED
|
@@ -19,7 +19,14 @@ const bmap = new BMap(document.getElementById('app')!, {
|
|
|
19
19
|
ts: "2023-11-29"
|
|
20
20
|
});
|
|
21
21
|
// 切换楼层
|
|
22
|
-
bmap.switchFloor(
|
|
22
|
+
bmap.switchFloor({
|
|
23
|
+
brand: "crc",
|
|
24
|
+
project: "1402A001",
|
|
25
|
+
phase: "themixccitysy01",
|
|
26
|
+
building: "A",
|
|
27
|
+
floor: "B1",
|
|
28
|
+
ts: "2023-11-29"
|
|
29
|
+
})
|
|
23
30
|
})();
|
|
24
31
|
|
|
25
32
|
// 图元点击
|
|
@@ -97,6 +104,59 @@ document.getElementById("createPoi")?.addEventListener('click', () => {
|
|
|
97
104
|
// }
|
|
98
105
|
// })
|
|
99
106
|
})
|
|
107
|
+
// 删除在创建
|
|
108
|
+
document.getElementById("deleteAnCreateGraphic")?.addEventListener('click', () => {
|
|
109
|
+
const graphic = bmap.getFloorAllGraphics().find(item => item.options.geometry.type === "polygon")!
|
|
110
|
+
console.log(graphic)
|
|
111
|
+
bmap.deleteGraphic(graphic)
|
|
112
|
+
setTimeout(() => {
|
|
113
|
+
bmap.createGraphicByOptions({
|
|
114
|
+
"id": "aba7a3fe",
|
|
115
|
+
"height": 3,
|
|
116
|
+
"airHeight": 0,
|
|
117
|
+
"area": 188822033.8,
|
|
118
|
+
"group": "graph",
|
|
119
|
+
"fillColor": "#fbbd7c",
|
|
120
|
+
"fillOpacity": 1,
|
|
121
|
+
"strokeColor": "#787889",
|
|
122
|
+
"strokeOpacity": 1,
|
|
123
|
+
"locked": false,
|
|
124
|
+
"visible": true,
|
|
125
|
+
"doors": [],
|
|
126
|
+
"geometry": {
|
|
127
|
+
"type": "polygon",
|
|
128
|
+
"cds": [
|
|
129
|
+
[
|
|
130
|
+
[
|
|
131
|
+
12966588.093999969,
|
|
132
|
+
4904266.882862748
|
|
133
|
+
],
|
|
134
|
+
[
|
|
135
|
+
12949046.292594986,
|
|
136
|
+
4891239.93653766
|
|
137
|
+
],
|
|
138
|
+
[
|
|
139
|
+
12979032.972936476,
|
|
140
|
+
4891980.499462258
|
|
141
|
+
],
|
|
142
|
+
[
|
|
143
|
+
12966588.093999969,
|
|
144
|
+
4904266.882862748
|
|
145
|
+
]
|
|
146
|
+
]
|
|
147
|
+
],
|
|
148
|
+
"curveCpt": [],
|
|
149
|
+
"curveIndex": [
|
|
150
|
+
0,
|
|
151
|
+
1,
|
|
152
|
+
2
|
|
153
|
+
]
|
|
154
|
+
},
|
|
155
|
+
"layerType": "graph",
|
|
156
|
+
"zIndex": 2001,
|
|
157
|
+
})
|
|
158
|
+
}, 1000)
|
|
159
|
+
})
|
|
100
160
|
// 获取全部图元
|
|
101
161
|
document.getElementById("getAllGraphics")?.addEventListener('click', () => {
|
|
102
162
|
console.log(bmap.getFloorAllGraphics())
|
|
@@ -112,7 +172,14 @@ document.getElementById("switchFloor")?.addEventListener('click', async () => {
|
|
|
112
172
|
ts: "2023-11-28"
|
|
113
173
|
});
|
|
114
174
|
// 切换楼层
|
|
115
|
-
bmap.switchFloor(
|
|
175
|
+
bmap.switchFloor({
|
|
176
|
+
brand: "crc",
|
|
177
|
+
project: "0202A501",
|
|
178
|
+
phase: "themixctd01",
|
|
179
|
+
building: "A",
|
|
180
|
+
floor: "B1",
|
|
181
|
+
ts: "2023-11-28"
|
|
182
|
+
})
|
|
116
183
|
})
|
|
117
184
|
// hover显示覆盖物
|
|
118
185
|
document.getElementById("hoverShowOverlay")?.addEventListener('click', async () => {
|
package/lib/bmap.cjs.min.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
"use strict";var it=Object.defineProperty;var Yt=Object.getOwnPropertyDescriptor;var qt=Object.getOwnPropertyNames,Dt=Object.getOwnPropertySymbols;var St=Object.prototype.hasOwnProperty,Zt=Object.prototype.propertyIsEnumerable;var G=Math.pow,pt=(o,r,t)=>r in o?it(o,r,{enumerable:!0,configurable:!0,writable:!0,value:t}):o[r]=t,nt=(o,r)=>{for(var t in r||(r={}))St.call(r,t)&&pt(o,t,r[t]);if(Dt)for(var t of Dt(r))Zt.call(r,t)&&pt(o,t,r[t]);return o};var Nt=(o,r)=>{for(var t in r)it(o,t,{get:r[t],enumerable:!0})},Qt=(o,r,t,e)=>{if(r&&typeof r=="object"||typeof r=="function")for(let i of qt(r))!St.call(o,i)&&i!==t&&it(o,i,{get:()=>r[i],enumerable:!(e=Yt(r,i))||e.enumerable});return o};var Jt=o=>Qt(it({},"__esModule",{value:!0}),o);var s=(o,r,t)=>(pt(o,typeof r!="symbol"?r+"":r,t),t);var H=(o,r,t)=>new Promise((e,i)=>{var n=p=>{try{c(t.next(p))}catch(h){i(h)}},a=p=>{try{c(t.throw(p))}catch(h){i(h)}},c=p=>p.done?e(p.value):Promise.resolve(p.value).then(n,a);c((t=t.apply(o,r)).next())});var ne={};Nt(ne,{BMap:()=>Gt,BaseSvg:()=>M,Context:()=>et,Floor:()=>Z,Graphic:()=>w,GraphicLayer:()=>W,HeatmapElement:()=>q,HoverHelper:()=>tt,Layer:()=>k,Overlay:()=>_,Poi:()=>z,PoiLayer:()=>Y,Selection:()=>J,Shadow:()=>X,SvgLine:()=>N,SvgPolygon:()=>Q,Timer:()=>A,clearCanvas:()=>Et,clearTextTexture:()=>bt,createCanvas:()=>Ft,createCircle:()=>B,createLine:()=>K,createRect:()=>Ct,createSvg:()=>wt,createSvgElement:()=>$,defaultConfig:()=>jt,dispose:()=>L,getCenter:()=>Pt,getConfig:()=>Lt,getTextureByText:()=>te,hasChinese:()=>xt,initCamera:()=>dt,initCanvas:()=>Ot,initControl:()=>gt,initDirectionalLight:()=>ft,initLight:()=>ut,initRenderer:()=>mt,initScene:()=>lt,initShape:()=>vt,isContain:()=>rt,proxyOptions:()=>U,setCirclePosition:()=>D,setLineStartEnd:()=>E,setRectPosition:()=>st,timeoutPromise:()=>j,vector3ToDevice:()=>v});module.exports=Jt(ne);var $t=require("three");var A=class{constructor(){s(this,"tasks",{requestAnimation:new Set,timeout:new Set,interval:new Set})}requestAnimationFrame(r){let t=window.requestAnimationFrame(()=>{this.tasks.requestAnimation.delete(t),r()});return this.tasks.requestAnimation.add(t),t}cancelAnimationFrame(r){this.tasks.requestAnimation.delete(r),window.cancelAnimationFrame(r)}setTimeout(r,t){let e=window.setTimeout(()=>{this.tasks.timeout.delete(e),r()},t);return this.tasks.timeout.add(e),e}clearTimeout(r){this.tasks.timeout.delete(r),window.clearTimeout(r)}setInterval(r,t){let e=window.setInterval(()=>{this.tasks.interval.delete(e),r()},t);return this.tasks.interval.add(e),e}clearInterval(r){this.tasks.interval.delete(r),window.clearInterval(r)}dispose(){this.tasks.requestAnimation.forEach(r=>{window.cancelAnimationFrame(r)}),this.tasks.requestAnimation.clear(),this.tasks.timeout.forEach(r=>{window.clearTimeout(r)}),this.tasks.timeout.clear(),this.tasks.interval.forEach(r=>{window.clearInterval(r)}),this.tasks.interval.clear()}};var m=require("three"),At=require("three/examples/jsm/controls/MapControls");function lt(){let o=new m.Scene;return o.background=new m.Color(16777215),o}function mt(){let o=new m.WebGLRenderer({antialias:!0});return o.setClearColor(16777215),o.setPixelRatio(window.devicePixelRatio),o.shadowMap.enabled=!0,o.shadowMap.autoUpdate=!0,o.shadowMap.type=m.PCFSoftShadowMap,o}function dt(o,r){let t=new m.OrthographicCamera(-o/2,o/2,r/2,-r/2,-1e3,5e3);return t.up.set(0,0,1),t.position.set(0,0,100),t.lookAt(0,0,0),t}function ut(){let o=new m.Group,r=new m.HemisphereLight(16777215,15658734,1);r.intensity=1,r.position.set(0,0,10),r.up.set(0,0,1),o.add(r);let t=new m.AmbientLight(16777215);return o.add(t),o}function gt(o,r){let t=new At.MapControls(o,r);return t.enableDamping=!1,t.maxPolarAngle=0,t.minPolarAngle=0,t.maxAzimuthAngle=0,t.minAzimuthAngle=0,t}function vt(o,r=[]){let t=new m.Shape(o.map(e=>new m.Vector2(...e)));return r.length&&r.forEach(e=>{var i=new m.Path(e.map(n=>new m.Vector2(...n)));t.holes.push(i)}),t}function ft(o=16777215,r=1){let t=new m.DirectionalLight(o,r);return t.castShadow=!0,t.shadow.radius=8,t.shadow.bias=-.001,t.shadow.mapSize.set(256,256),t.shadow.camera.left=-200,t.shadow.camera.right=200,t.shadow.camera.top=200,t.shadow.camera.bottom=-200,t}function L(o,r){var t;if(r&&o.children&&o.children.length&&o.children.forEach(e=>{L(e,r)}),o.isMesh){let e=o;e.geometry&&e.geometry.dispose(),e.material&&(Array.isArray(e.material)?e.material.forEach(i=>{i.dispose()}):e.material.dispose())}o.isLight&&((t=o.dispose)==null||t.call(o))}function xt(o){return/[\u4E00-\u9FA5]+/g.test(o)}var F=require("three");var ot=new Map;function Ot(){let o=document.createElement("canvas");o.width=1024,o.height=64;let r=o.getContext("2d",{willReadFrequently:!0});return r.font="54px sans-serif",r.textBaseline="hanging",r.lineWidth=12,r.fillStyle="rgba(0,0,0,1)",r.strokeStyle="white",{canvas:o,ctx:r}}var yt,O;function Ft(){if(!yt){let{canvas:o,ctx:r}=Ot();yt=o,O=r}}function te(o){if(ot.has(o))return ot.get(o);Ft(),O.clearRect(0,0,1024,64);let r=xt(o)?4:8;O.strokeText(o,2,r),O.fillText(o,2,r);let t=Math.ceil(O.measureText(o).width);t=t%2===0?t:t+1,t+=2;let e=O.getImageData(0,0,t,64),i=new F.DataTexture(Uint8Array.from(e.data),t,64,F.RGBAFormat);return i.flipY=!0,i.minFilter=F.LinearFilter,i.magFilter=F.LinearFilter,ot.set(o,i),i}function bt(){ot.clear()}function Et(){O=null,yt=null}var R=require("@turf/turf");function v(o,r,t,e){let i=o.clone().project(r),n=t/2,a=e/2,c=Math.round(i.x*n+n),p=Math.round(-i.y*a+a);return{x:c,y:p}}function Pt(o){let r=(0,R.featureCollection)(o.map(e=>(0,R.point)(e)));return(0,R.center)(r).geometry.coordinates}function rt(o,r,t){return o.x>=r.x&&o.x<=t.x&&o.y>=r.y&&o.y<=t.y}function U(o,r){return new Proxy(o,{get:(t,e,i)=>Reflect.get(t,e,i),set:(t,e,i,n)=>{let a=Reflect.set(t,e,i,n);return r.dispatchEvent({type:`change-${e}`,value:i}),a}})}function j(o,r){return Promise.race([o,new Promise((t,e)=>{setTimeout(()=>e(new Error("Promise timeout")),r)})])}function $(o){return document.createElementNS("http://www.w3.org/2000/svg",o)}function wt(o,r){let t=$("svg");return t.setAttribute("width",o),t.setAttribute("height",r),t.style.cssText="position: absolute; left: 0; top: 0; pointer-events: none;",t}function B(o="2",r){let t=$("circle");return t.setAttribute("r",o),t.setAttribute("fill",r),t}function K(o){let r=$("line");return r.setAttribute("stroke",o),r}function Ct(o,r){let t=$("rect");return t.setAttribute("stroke",o),t.setAttribute("fill",r),t}function D(o,r,t){o.setAttribute("cx",`${r}`),o.setAttribute("cy",`${t}`)}function E(o,r,t){r&&(o.setAttribute("x1",`${r.x}`),o.setAttribute("y1",`${r.y}`)),t&&(o.setAttribute("x2",`${t.x}`),o.setAttribute("y2",`${t.y}`))}function st(o,r,t,e,i){o.setAttribute("x",`${r}`),o.setAttribute("y",`${t}`),o.setAttribute("width",`${e}`),o.setAttribute("height",`${i}`)}var u=require("three"),V=require("@tweenjs/tween.js");var Vt=require("three");var d=require("three");var Tt=require("lodash");var ee={id:"",height:.1,airHeight:0,area:0,group:"",fillColor:"#EFF4FB",strokeColor:"#ffffff",fillOpacity:1,strokeOpacity:1,doors:[],locked:!1,visible:!0,geometry:{type:"polygon",cds:[],curveCpt:[],curveIndex:[]},layerType:"",zIndex:0},w=class extends d.Object3D{constructor(t,e){super();this.context=t;s(this,"geometry");s(this,"material");s(this,"mesh");s(this,"line");s(this,"options");if(this.options=U((0,Tt.merge)({},ee,e),this),this.options.geometry.type==="point"){let[i,n]=this.options.geometry.cds;return this.position.set(i,n,this.options.height+this.options.airHeight),console.log(this.options),this}this.init(),this.visible=this.options.visible,this.addEventListener("change-fillColor",({value:i})=>{this.material.color=new d.Color(i)}),this.addEventListener("change-fillOpacity",({value:i})=>{this.material.opacity=i}),this.addEventListener("change-height",({value:i})=>{this.dispose(),this.init()}),this.addEventListener("change-strokeColor",({value:i})=>{this.line.material.color=new d.Color(i)}),this.addEventListener("change-strokeOpacity",({value:i})=>{this.line.material.opacity=i}),this.addEventListener("change-airHeight",({value:i})=>{this.position.z=i}),this.addEventListener("change-visible",({value:i})=>{this.visible=i})}getCenter(){if(this.options.geometry.type==="point")return this.position;let t=new d.Vector3,e=new d.Box3;return e.setFromObject(this),e.getCenter(t),t}getSize(){if(this.options.geometry.type==="point")return new d.Vector3(0,0,0);let t=new d.Box3,e=new d.Vector3;return t.setFromObject(this),t.getSize(e),e}getPosition(){return this.getCenter()}init(){this.geometry=this.initGeometry(),this.material=this.initMaterial(),this.mesh=this.initMesh(),this.mesh.position.z=this.options.airHeight+this.options.height/2,this.mesh.castShadow=!0,this.add(this.mesh),this.line=this.createBorder(),this.add(this.line)}initGeometry(){let t=vt(this.options.geometry.cds[0],this.options.geometry.cds.slice(1));return new d.ExtrudeGeometry(t,{steps:1,bevelEnabled:!1,depth:this.options.height,curveSegments:4})}initMaterial(){return new d.MeshStandardMaterial({color:this.options.fillColor,roughness:1,transparent:!0,opacity:this.options.fillOpacity,depthWrite:!0})}initLineMaterial(){return new d.LineBasicMaterial({color:this.options.strokeColor,opacity:this.options.strokeOpacity,transparent:!0,depthWrite:!0})}initMesh(){return new d.Mesh(this.geometry,this.material)}createBorder(){let t=this.initLineMaterial(),e=new d.EdgesGeometry(this.geometry),i=new d.LineSegments(e,t);return i.position.z=this.options.airHeight+this.options.height/2,i}raycast(t){if(!this.visible||this.options.geometry.type==="point")return!1;let e=t.intersectObject(this.mesh);if(e[0]){let{point:i,distance:n}=e[0];return{position:i,distance:n}}return!1}dispose(){L(this),this.clear()}};var P=require("three");var X=class extends P.Object3D{constructor(){super();s(this,"directionalLight");s(this,"plane");s(this,"basicOpacity",.39);this.directionalLight=this.initLight(),this.initPlane()}initLight(){let t=ft(16777215,1);return t.position.set(0,0,100),this.add(t),t}changeLightCamera(t){let e=t.x,i=t.y;this.directionalLight.shadow.camera.left=-e,this.directionalLight.shadow.camera.right=e,this.directionalLight.shadow.camera.top=i,this.directionalLight.shadow.camera.bottom=-i,this.directionalLight.shadow.camera.near=.5,this.directionalLight.shadow.camera.far=Math.max(e,i)}changeLightColor(t){this.directionalLight.color=new P.Color(t)}setPosition(t){this.position.copy(t),this.directionalLight.position.set(-t.x/2,-t.y/2,100)}initPlane(t=1e3,e=1e3){let i=new P.PlaneGeometry(t,e),n=new P.ShadowMaterial({transparent:!0,opacity:0,side:P.DoubleSide}),a=new P.Mesh(i,n);return a.receiveShadow=!0,a.position.z=-5,this.add(a),this.plane=a,a}setTarget(t){this.directionalLight.target=t}transformOpacity(t){return t*this.basicOpacity}setOpacity(t){this.plane.material.opacity=this.transformOpacity(t)}dispose(){L(this,!0)}};var kt=require("three"),Ht=require("lodash");var T=require("three");var _=class extends T.EventDispatcher{constructor(t){super();this.context=t;s(this,"div");s(this,"element");s(this,"position",new T.Vector3);s(this,"onUpdate",()=>{let t=this.getPosition(),{clientWidth:e,clientHeight:i}=this.context.container,{x:n,y:a}=v(t,this.context.camera,e,i);this.div.style.left=`${n}px`,this.div.style.top=`${a}px`});this.registryEvent(),this.div=this.initDiv(),this.context.container.appendChild(this.div)}initDiv(){let t=document.createElement("div");return t.style.position="absolute",t}bindElement(t){this.element=t}unBindElement(){this.element=void 0}setVisible(t,e="block"){this.div.style.display=t?e:"none"}setOpacity(t){this.div.style.opacity=`${t}`}getPosition(){return this.element?typeof this.element.getPosition=="function"?this.element.getPosition():new T.Box3().setFromObject(this.element).getCenter(new T.Vector3):this.position}registryEvent(){this.context.addEventListener("update",this.onUpdate)}unRegistryEvent(){this.context.removeEventListener("update",this.onUpdate)}dispose(){this.unRegistryEvent(),this.unBindElement(),this.context.container.removeChild(this.div),this.div=null}};var ie={text:"",level:1,collision_enable:!0,opacity:1},z=class extends kt.Object3D{constructor(t,e){super();this.context=t;s(this,"textDiv");s(this,"img");s(this,"overlay");s(this,"options");s(this,"_changePosition",()=>{this.overlay.div.style.transform=`translate3d(-50%, ${this.options.icon?"-100%":"-50%"}, 0)`});this.options=U((0,Ht.merge)({},ie,e),this),this.overlay=new _(this.context),this.overlay.bindElement(this),this._changePosition(),this.registryEvent(),this.initDiv(),this.addEventListener("change-icon",({value:i})=>{i?this.img?this.img.setAttribute("src",i):this.overlay.div.appendChild(this.initIcon()):(this.img&&this.overlay.div.removeChild(this.img),this.img=void 0)}),this.addEventListener("change-text",({value:i})=>{this.overlay.div.removeChild(this.textDiv),this.overlay.div.appendChild(this.initText())}),this.addEventListener("change-opacity",({value:i})=>{this.overlay.setOpacity(i)})}initDiv(){let t=this.overlay.div;return t.appendChild(this.initText()),this.options.icon&&t.appendChild(this.initIcon()),t.style.fontSize="12px",t.style.display="flex",t.style.flexDirection="column",t.style.justifyContent="center",t.style.alignItems="center",t.style.pointerEvents="none",t}getPosition(){return this.position}initText(){let t=document.createElement("div");return t.appendChild(this.createTextFragment()),t.style.background="rgba(255, 255, 255, .7)",t.style.padding="2px",t.style.borderRadius="4px",this.textDiv=t,t}createTextFragment(){let t=document.createDocumentFragment();return this.options.text.split(`\r
|
|
2
|
-
`).forEach(e=>{let i=document.createElement("div");i.style.whiteSpace="nowrap",i.textContent=e,t.appendChild(i)}),t}initIcon(){var e,i;let t=document.createElement("img");return t.setAttribute("src",this.options.icon),t.style.width=`${((e=this.options.icon_size)==null?void 0:e[0])||32}px`,t.style.height=`${((i=this.options.icon_size)==null?void 0:i[1])||32}px`,this.img=t,t}registryEvent(){this.context.addEventListener("update",this._changePosition)}unRegistryEvent(){this.context.removeEventListener("update",this._changePosition)}setVisible(t){this.overlay.setVisible(t,"flex")}getBox(){return this.overlay.div.getBoundingClientRect()}isContain(t,e){let i=this.getBox();return t>=i.left&&t<=i.right&&e>=i.top&&e<=i.bottom}dispose(){this.unRegistryEvent(),this.textDiv=null,this.img=void 0,this.overlay.dispose()}};var C=require("three");var at=require("three");var Rt=require("three");var k=class extends Rt.Object3D{constructor(t){super();this.context=t}dispose(){L(this),this.clear()}};var W=class extends k{constructor(t){super(t);s(this,"graphicMap",new Map)}getCenter(){return new at.Box3().setFromObject(this).getCenter(new at.Vector3)}createGraphic(t){let e=new w(this.context,t);return this.add(e),this.graphicMap.set(t.id,e),e}getGraphicByRaycaster(t){let e={distance:1e4,graphic:null,position:null},i=this.children.reduce((n,a)=>{if(a instanceof w){let c=a.raycast(t);if(c){let{distance:p}=c;if(p<n.distance)return{distance:n.distance,position:n.position,graphic:a}}return n}else return n},e);return i===e?{graphics:[],position:null}:{graphics:[i.graphic],position:i.position}}};var Y=class extends k{constructor(t){super(t);s(this,"pois",[]);s(this,"onUpdate",()=>{this.collisionDetection()});this.registryEvent()}createPoi(t){let e=new z(this.context,t);return this.add(e),this.pushPoi(e),e.addEventListener("change-level",()=>this.changePoiLevelOrCollisionEnable(e)),e.addEventListener("change-collision_enable",()=>this.changePoiLevelOrCollisionEnable(e)),e}changePoiLevelOrCollisionEnable(t){let e=this.pois.findIndex(i=>i===t);e!==-1&&(this.pois.splice(e,1),this.pushPoi(t))}removePoi(t){let e=this.pois.findIndex(i=>i===t);e!==-1&&(this.pois.splice(e,1),this.remove(t),t.dispose())}pushPoi(t){if(!t.options.collision_enable){this.pois.unshift(t);return}if(t.options.level===1){this.pois.push(t);return}for(let e=0;e<this.pois.length;e++){let i=this.pois[e];if(i.options.collision_enable&&i.options.level<=t.options.level){this.pois.splice(e,0,t);return}}this.pois.push(t)}getPoiByDeviceXy(t,e){return this.children.filter(n=>n instanceof z&&n.isContain(t,e))}collisionDetection(){let t=[];this.pois.forEach((e,i)=>{e.setVisible(!0);let{left:n,right:a,top:c,bottom:p}=e.getBox();if(i===0){t.push({left:n,right:a,top:c,bottom:p});return}let h=t.some(l=>{let x=a<l.left||n>l.right,g=c>l.bottom||p<l.top;return x||g});e.setVisible(h)})}registryEvent(){this.context.addEventListener("update",this.onUpdate)}unRegistryEvent(){this.context.removeEventListener("update",this.onUpdate)}dispose(){super.dispose(),this.unRegistryEvent(),this.pois.forEach(t=>t.dispose()),this.pois.length=0}};var f=require("three"),Bt=require("@mars3d/heatmap.js"),S=require("@turf/turf");var q=class extends f.Object3D{constructor(t){super();this.context=t;s(this,"heatmap");s(this,"div");s(this,"plane");this.div=document.createElement("div")}clearHeatmap(){this.div.firstChild&&this.div.removeChild(this.div.firstChild),this.heatmap=void 0}loadData(t){this.clearHeatmap();let{width:e,height:i,leftTop:n,center:a}=this.getBox(t);this.heatmap=(0,Bt.create)(nt({width:e,height:i,container:this.div},this.context.config.heatMap)),this.heatmap.setData(this.transformData(t,n)),this.initPlane(e,i),this.position.set(a[0],a[1],this.position.z)}initPlane(t,e){this.plane&&this.remove(this.plane);let i=new f.PlaneGeometry(t,e),n=new f.Texture(this.div.firstChild);n.needsUpdate=!0;let a=new f.MeshBasicMaterial({transparent:!0,side:f.DoubleSide,map:n});a.needsUpdate=!0,this.plane=new f.Mesh(i,a),this.add(this.plane)}getTransMatrix({x:t,y:e}){return new f.Matrix3().makeScale(1,-1).multiply(new f.Matrix3().makeTranslation(0-t,0-e))}transformData(t,e){let i=this.getTransMatrix(e);return{data:t.data.map(a=>{let c=new f.Vector2(a.x,a.y).applyMatrix3(i);return{x:c.x,y:c.y,value:a.value}}),max:t.max,min:t.min}}getBox(t){let e=(0,S.featureCollection)(t.data.map(h=>(0,S.point)([h.x,h.y]))),i=(0,S.bbox)(e),n=i[2]-i[0],a=i[3]-i[1],c={x:i[0],y:i[3]},p=(0,S.center)(e);return{width:n,height:a,leftTop:c,center:p.geometry.coordinates}}dispose(){this.div=null,this.heatmap=void 0}};var Z=class extends C.Object3D{constructor(t){super();this.context=t;s(this,"graphicLayer");s(this,"poiLayer");s(this,"grounds",new Set);s(this,"shadow",new X);s(this,"heatmap");s(this,"groundUpper",new C.Object3D);this.graphicLayer=new W(this.context),this.poiLayer=new Y(this.context),this.groundUpper.add(this.graphicLayer),this.groundUpper.add(this.poiLayer),this.add(this.groundUpper)}addGrounds(t){t.forEach(e=>{this.grounds.has(e)||(this.grounds.add(e),this.groundUpper.add(e))})}get hasElement(){return!!(this.grounds.size||this.graphicLayer.children.length)}getCenter(){return new C.Box3().setFromObject(this.groundUpper).getCenter(new C.Vector3)}addShadow(){let t=new C.Box3().setFromObject(this.groundUpper),e=t.getCenter(new C.Vector3),i=t.getSize(new C.Vector3);this.shadow.setPosition(e),this.shadow.changeLightCamera(i),this.add(this.shadow)}addGraphic(t){return this.graphicLayer.createGraphic(t)}addPoi(t){return this.poiLayer.createPoi(t)}addHeatmap(t){this.heatmap||(this.heatmap=new q(this.context),this.add(this.heatmap)),this.heatmap.loadData(t);let e=new C.Box3().setFromObject(this.graphicLayer);return this.heatmap.position.setZ(e.max.z),this.heatmap}removeHeatMap(){this.heatmap&&(this.remove(this.heatmap),this.heatmap.dispose(),this.heatmap=void 0)}setShadowOpacity(t){this.shadow.setOpacity(t)}setShadowVisible(t){this.shadow.visible=t}dispose(){var t;this.shadow.dispose(),this.graphicLayer.dispose(),this.poiLayer.dispose(),this.grounds.forEach(e=>e.dispose()),(t=this.heatmap)==null||t.dispose(),this.groundUpper.clear(),this.clear()}};var ct=require("three");var M=class extends ct.EventDispatcher{constructor(t){super();this.context=t;s(this,"points",[]);s(this,"svg");s(this,"enable",!0);this.svg=wt(`${t.container.clientWidth}`,`${t.container.clientHeight}`),t.container.appendChild(this.svg)}setEnable(t){this.enable=t,t?this.svg.style.display="block":this.svg.style.display="none"}getIntersectByPointerEvent(t){let{camera:e,renderer:i}=this.context,{offsetX:n,offsetY:a}=t,{clientWidth:c,clientHeight:p}=i.domElement,h=n/c*2-1,l=1-a/p*2;return new ct.Vector3(h,l,0).unproject(e)}getSvgCoordinate(t){let{camera:e,container:i}=this.context;return v(t,e,i.clientWidth,i.clientHeight)}dispose(){this.context.container.removeChild(this.svg),this.svg=null}};var N=class extends M{constructor(t){super(t);this.context=t;s(this,"circles");s(this,"line");s(this,"onUpdate",()=>{if(this.points[0]){let t=this.getSvgCoordinate(this.points[0]);D(this.circles[0],t.x,t.y),E(this.line,t)}if(this.points[1]){let t=this.getSvgCoordinate(this.points[1]);D(this.circles[1],t.x,t.y),E(this.line,void 0,t)}});s(this,"onPointermove",t=>{this.points.length===1&&(this.line.style.display="block",E(this.line,void 0,{x:t.offsetX,y:t.offsetY}))});s(this,"onPointerleave",()=>{this.points[1]||(this.line.style.display="none")});s(this,"onPointerdown",t=>{if(this.points[1])return;let e=this.getIntersectByPointerEvent(t);if(e){let{offsetX:i,offsetY:n}=t,a=this.circles[this.points.length];D(a,i,n),this.points.length||E(this.line,{x:i,y:n},{x:i,y:n}),this.addPoint(e)}});let{config:{svg:{circle:e,line:i}}}=t;this.circles=[B(e.radius,e.fill),B(e.radius,e.fill)],this.line=K(i.stroke),this.svg.appendChild(this.circles[0]),this.svg.appendChild(this.circles[1]),this.svg.appendChild(this.line),this.registryEvent()}setEnable(t){super.setEnable(t),t?this.registryEvent():this.unRegistryEvent()}registryEvent(){this.context.container.addEventListener("pointerenter",this.onPointermove),this.context.container.addEventListener("pointermove",this.onPointermove),this.context.container.addEventListener("pointerleave",this.onPointerleave),this.context.container.addEventListener("pointerdown",this.onPointerdown),this.context.addEventListener("update",this.onUpdate)}unRegistryEvent(){this.context.container.removeEventListener("pointerenter",this.onPointermove),this.context.container.removeEventListener("pointermove",this.onPointermove),this.context.container.removeEventListener("pointerleave",this.onPointerleave),this.context.container.removeEventListener("pointerdown",this.onPointerdown),this.context.removeEventListener("update",this.onUpdate)}addPoint(t){if(this.points.push(t),this.points.length>=2){let e=this.calculatedDistance();this.dispatchEvent({type:"distance",distance:e})}}calculatedDistance(){let[{x:t,y:e},{x:i,y:n}]=this.points;return Math.sqrt(G(i-t,2)+G(n-e,2))}dispose(){super.dispose(),this.unRegistryEvent(),this.line=null,this.circles=[]}};var Q=class extends M{constructor(t){super(t);s(this,"circles",[]);s(this,"lines",[]);s(this,"isClose",!1);s(this,"onUpdate",()=>{this.points.length&&this.points.forEach((t,e)=>{let i=this.getSvgCoordinate(t);this.circles[e]&&D(this.circles[e],i.x,i.y),e!==0&&E(this.lines[e-1],void 0,i),this.lines[e]&&E(this.lines[e],i)})});s(this,"onPointermove",t=>{!this.lastLine||this.isClose||(this.lastLine.style.display="block",E(this.lastLine,void 0,{x:t.offsetX,y:t.offsetY}))});s(this,"onPointerleave",()=>{this.isClose||(this.lastLine.style.display="none")});s(this,"onPointerdown",t=>{if(this.isClose)return;let e=this.getIntersectByPointerEvent(t);if(e){let{offsetX:i,offsetY:n}=t;this.checkAdsorb(i,n)?(this.isClose=!0,this.addPoint(this.points[0])):this.addPoint(e);let{circle:{fill:a,radius:c},line:{stroke:p}}=this.context.config.svg;if(!this.isClose){let h=B(c,a);D(h,i,n),this.addCircle(h)}if(this.lines.length&&E(this.lastLine,void 0,{x:i,y:n}),!this.isClose){let h=K(p);E(h,{x:i,y:n},{x:i,y:n}),this.addLine(h)}}});this.registryEvent()}setEnable(t){super.setEnable(t),t?this.registryEvent():this.unRegistryEvent()}get lastLine(){return this.lines.slice(-1)[0]}addCircle(t){this.circles.push(t),this.svg.appendChild(t)}addLine(t){this.lines.push(t),this.svg.appendChild(t)}registryEvent(){this.context.container.addEventListener("pointerenter",this.onPointermove),this.context.container.addEventListener("pointermove",this.onPointermove),this.context.container.addEventListener("pointerleave",this.onPointerleave),this.context.container.addEventListener("pointerdown",this.onPointerdown),this.context.addEventListener("update",this.onUpdate)}unRegistryEvent(){this.context.container.removeEventListener("pointerenter",this.onPointermove),this.context.container.removeEventListener("pointermove",this.onPointermove),this.context.container.removeEventListener("pointerleave",this.onPointerleave),this.context.container.removeEventListener("pointerdown",this.onPointerdown),this.context.removeEventListener("update",this.onUpdate)}checkAdsorb(t,e){if(this.points.length<3)return!1;let i=this.circles[0],n=+i.getAttribute("cx"),a=+i.getAttribute("cy");return Math.sqrt(G(t-n,2)+G(e-a,2))<=5}addPoint(t){if(this.points.push(t),this.isClose){let e=this.calculatedArea();this.dispatchEvent({type:"area",area:e})}}calculatedArea(){let t=this.points.map(n=>[n.x,n.y]),e=0,i=t.length;for(let n=0;n<i;n++){let a=(n+1)%i;e+=t[n][0]*t[a][1]-t[a][0]*t[n][1]}return Math.abs(e/2)}dispose(){super.dispose(),this.unRegistryEvent(),this.lines=[],this.circles=[]}};var zt=require("three");var ht=class extends M{constructor(t){super(t);s(this,"startPoint");s(this,"endPoint");s(this,"rect");s(this,"frustum",new zt.Frustum);s(this,"onPointerDown",t=>{if(!this.enable)return;let e=this.getIntersectByPointerEvent(t);e&&(this.startPoint=e),this.endPoint=void 0});s(this,"onPointerMove",t=>{if(!this.enable||!this.startPoint)return;let e=this.getIntersectByPointerEvent(t);e&&(this.endPoint=e)});s(this,"onPointerUp",t=>{if(!this.enable)return;let e=this.getIntersectByPointerEvent(t);e&&(this.endPoint=e),this.doSelect(),this.startPoint=void 0});s(this,"onUpdate",()=>{if(this.startPoint){let t=this.getSvgCoordinate(this.startPoint),e=nt({},t);this.endPoint&&(e=this.getSvgCoordinate(this.endPoint));let i={x:Math.min(t.x,e.x),y:Math.min(t.y,e.y)},n=Math.abs(e.x-t.x),a=Math.abs(e.y-t.y);st(this.rect,i.x,i.y,n,a)}});let{config:{selectBox:{fill:e,stroke:i}}}=t;this.rect=Ct(i,e),this.svg.appendChild(this.rect),this.registryEvent()}setEnable(t){super.setEnable(t),st(this.rect,0,0,0,0)}registryEvent(){this.context.container.addEventListener("pointerdown",this.onPointerDown),this.context.container.addEventListener("pointermove",this.onPointerMove),this.context.container.addEventListener("pointerup",this.onPointerUp),this.context.addEventListener("update",this.onUpdate)}unRegistryEvent(){this.context.container.removeEventListener("pointerdown",this.onPointerDown),this.context.container.removeEventListener("pointermove",this.onPointerMove),this.context.container.removeEventListener("pointerup",this.onPointerUp),this.context.removeEventListener("update",this.onUpdate)}doSelect(){if(this.startPoint&&this.endPoint){if(this.startPoint.distanceTo(this.endPoint)<.1)return;let{context:{camera:e,container:{clientWidth:i,clientHeight:n}}}=this,a=v(this.startPoint,e,i,n),c=v(this.endPoint,e,i,n),p={x:Math.min(a.x,c.x),y:Math.min(a.y,c.y)},h={x:Math.max(a.x,c.x),y:Math.max(a.y,c.y)},l=this.searchMapInFrustum(p,h);this.dispatchEvent({type:"selected",list:l})}}searchMapInFrustum(t,e){var n;let{context:i}=this;return((n=i.currentFloor)==null?void 0:n.graphicLayer.children.filter(a=>a instanceof w&&this.searchChildInFrustum(a,t,e)))||[]}searchChildInFrustum(t,e,i){let{context:{camera:n,container:{clientWidth:a,clientHeight:c}}}=this;if(!t)return!1;t.mesh.geometry.boundingBox||t.mesh.geometry.computeBoundingBox();let p=t.mesh.geometry.boundingBox;if(!p)return!1;let{min:h,max:l}=p,x=v(h,n,a,c),g=v(l,n,a,c);return!(!rt(x,e,i)||!rt(g,e,i))}dispose(){this.unRegistryEvent()}};var J=class extends Vt.EventDispatcher{constructor(t){super();this.context=t;s(this,"_list",new Set);s(this,"boxSelection");s(this,"prevPanStatus");s(this,"onPointerDown",t=>{let{graphics:e}=this.context.getGraphicsByDeviceXy(t.offsetX,t.offsetY);t.ctrlKey||this._list.clear(),e.forEach(i=>this._list.add(i)),this.selectEnd()});s(this,"onKeyDown",t=>{t.key==="Control"&&(this.boxSelection.setEnable(!0),this.prevPanStatus=this.context.control.enablePan,this.context.control.enablePan=!1)});s(this,"onKeyUp",t=>{t.key==="Control"&&(this.boxSelection.setEnable(!1),this.context.control.enablePan=!!this.prevPanStatus)});s(this,"onBoxSelected",({list:t})=>{this._list.clear(),t.forEach(e=>{this._list.add(e)}),this.selectEnd()});this.boxSelection=new ht(t),this.boxSelection.setEnable(!1),this.registryEvent()}get list(){return this._list}selectEnd(){this.dispatchEvent({type:"select",graphics:[...this._list]})}registryEvent(){this.context.container.addEventListener("pointerdown",this.onPointerDown),window.addEventListener("keydown",this.onKeyDown),window.addEventListener("keyup",this.onKeyUp),this.boxSelection.addEventListener("selected",this.onBoxSelected)}unRegistryEvent(){this.context.container.removeEventListener("pointerdown",this.onPointerDown),window.removeEventListener("keydown",this.onKeyDown),window.removeEventListener("keyup",this.onKeyUp),this.boxSelection.removeEventListener("selected",this.onBoxSelected)}dispose(){this.unRegistryEvent()}};var It=require("three");var tt=class extends It.EventDispatcher{constructor(t){super();this.context=t;s(this,"curGraphics",new Set);s(this,"timer",new A);s(this,"graphicTimerMap",new Map);s(this,"onPointerMove",({graphics:t})=>{if(!t.length&&this.curGraphics.size){this.curGraphics.clear(),this.handleHoverGraphicsChange();return}let{time:e}=this.context.config.hover;t.forEach(n=>{if(this.graphicTimerMap.get(n)||this.curGraphics.has(n))return;let a=this.timer.setTimeout(()=>{this.curGraphics.add(n),this.handleHoverGraphicsChange()},e);this.graphicTimerMap.set(n,a)}),this.graphicTimerMap.forEach((n,a)=>{t.includes(a)||(this.timer.clearTimeout(n),this.graphicTimerMap.delete(a))});let i=this.curGraphics.size;this.curGraphics.forEach(n=>{t.includes(n)||this.curGraphics.delete(n)}),i!==this.curGraphics.size&&this.handleHoverGraphicsChange()});s(this,"onPointerLevel",()=>{this.curGraphics.clear(),this.handleHoverGraphicsChange()});this.registryEvent()}handleHoverGraphicsChange(t=this.curGraphics){this.dispatchEvent({type:"hover-change",graphics:Array.from(this.curGraphics)})}registryEvent(){this.context.addEventListener("pointer-over",this.onPointerMove),this.context.addEventListener("pointer-move",this.onPointerMove),this.context.addEventListener("pointer-level",this.onPointerLevel)}unRegistryEvent(){this.context.removeEventListener("pointer-over",this.onPointerMove),this.context.removeEventListener("pointer-move",this.onPointerMove),this.context.removeEventListener("pointer-level",this.onPointerLevel)}dispose(){this.unRegistryEvent(),this.timer.dispose()}};var et=class extends u.EventDispatcher{constructor(t,e){super();this.container=t;this.config=e;s(this,"scene",lt());s(this,"renderer",mt());s(this,"camera");s(this,"control");s(this,"lights",ut());s(this,"timer",new A);s(this,"tweenGroup",new V.Group);s(this,"currentFloor");s(this,"selection");s(this,"hoverHelper");s(this,"basicRatio");s(this,"onWindowResize",()=>{let{container:t,camera:e,renderer:i}=this,{clientWidth:n,clientHeight:a}=t;e.left=-n/2,e.right=n/2,e.top=a/2,e.bottom=-a/2,e.updateProjectionMatrix(),i.setSize(n,a)});s(this,"onClick",t=>{let{graphics:e,position:i}=this.getGraphicsByDeviceXy(t.offsetX,t.offsetY);e.length&&this.dispatchEvent({type:"graphic-click",graphics:e,position:i});let n=this.getPoisByDeviceXy(t.clientX,t.clientY);n.length&&this.dispatchEvent({type:"poi-click",pois:n})});s(this,"onPointerover",t=>{let{graphics:e,position:i}=this.getGraphicsByDeviceXy(t.offsetX,t.offsetY),n=this.getPoisByDeviceXy(t.clientX,t.clientY);this.dispatchEvent({type:"pointer-over",graphics:e,pois:n,position:i})});s(this,"onPointermove",t=>{let{graphics:e,position:i}=this.getGraphicsByDeviceXy(t.offsetX,t.offsetY),n=this.getPoisByDeviceXy(t.clientX,t.clientY);this.dispatchEvent({type:"pointer-move",graphics:e,pois:n,position:i})});s(this,"onPointerleave",()=>{this.dispatchEvent({type:"pointer-level"})});s(this,"onSelectionSelect",({graphics:t})=>{this.dispatchEvent({type:"select-graphic",graphics:t})});s(this,"onHoverChange",({graphics:t})=>{this.dispatchEvent({type:"hover",graphics:t})});this.container.style.position="relative",this.container.style.overflow="hidden",this.init(),this.selection=new J(this),this.hoverHelper=new tt(this),this.registryEvent()}init(){let{clientWidth:t,clientHeight:e}=this.container;this.camera=dt(t,e),this.renderer.setSize(t,e),this.control=gt(this.camera,this.renderer.domElement),this.container.appendChild(this.renderer.domElement),this.scene.add(this.lights),this.basicRatio=this.getRatio(),this.control.addEventListener("change",()=>{var n;let i=this.control.getPolarAngle();(n=this.currentFloor)==null||n.setShadowOpacity(i/this.config.control.maxPolar),this.dispatchEvent({type:"change-ratio",px:(this.basicRatio||0)*this.camera.zoom})})}getRatio(t=new u.Vector3(0,0,0),e=new u.Vector3(100,0,0)){let{clientWidth:i,clientHeight:n}=this.container,a=v(t,this.camera,i,n),c=v(e,this.camera,i,n);return Math.ceil(Math.sqrt(G(c.x-a.x,2)+G(c.y-a.y,2)))}changeAmbientLightColor(t){this.lights.children.forEach(e=>{e instanceof u.AmbientLight&&(e.color=new u.Color(t))})}switchFloor(t){this.currentFloor&&(this.scene.remove(this.currentFloor),this.currentFloor.dispose()),this.currentFloor=t,this.scene.add(t);let e=t.getCenter();e&&(this.lights.position.x=e.x,this.lights.position.y=e.y)}getGraphicsByDeviceXy(t,e){var c;let i=new u.Vector2;i.x=t/this.container.clientWidth*2-1,i.y=e/this.container.clientHeight*-2+1;let n=new u.Raycaster;return n.setFromCamera(i,this.camera),((c=this.currentFloor)==null?void 0:c.graphicLayer.getGraphicByRaycaster(n))||{graphics:[],position:null}}getPoisByDeviceXy(t,e){var n;return((n=this.currentFloor)==null?void 0:n.poiLayer.getPoiByDeviceXy(t,e))||[]}registryEvent(){window.addEventListener("resize",this.onWindowResize),this.container.addEventListener("click",this.onClick),this.container.addEventListener("pointerover",this.onPointerover),this.container.addEventListener("pointermove",this.onPointermove),this.container.addEventListener("pointerleave",this.onPointerleave),this.selection.addEventListener("select",this.onSelectionSelect),this.hoverHelper.addEventListener("hover-change",this.onHoverChange)}unRegistryEvent(){window.removeEventListener("resize",this.onWindowResize),this.container.removeEventListener("click",this.onClick),this.container.removeEventListener("pointerover",this.onPointerover),this.container.removeEventListener("pointermove",this.onPointermove),this.container.removeEventListener("pointerleave",this.onPointerleave),this.selection.removeEventListener("select",this.onSelectionSelect),this.hoverHelper.removeEventListener("hover-change",this.onHoverChange)}setPolarAngle(t,e=500){return j(new Promise(i=>{let n={polar:this.control.getPolarAngle()},a={polar:t},c=new V.Tween(n,this.tweenGroup).to(a,e).onUpdate(()=>{this.control.maxPolarAngle=n.polar,this.control.minPolarAngle=n.polar,this.control.update()}).onComplete(()=>{this.control.enabled=!0,this.tweenGroup.remove(c),i(!0)}).onStart(()=>{this.control.enabled=!1}).start()}),e+500)}getCameraLookAt(){return new u.Vector3().subVectors(this.control.target,this.camera.position)}setZoom(t,e,i=500){return j(new Promise(n=>{let a={zoom:this.camera.zoom,target:this.control.target.clone()},c=this.getCameraLookAt(),p=new V.Tween(a,this.tweenGroup).to({zoom:t,target:e},i).onUpdate(()=>{this.camera.position.copy(a.target.clone().sub(c)),this.control.target.copy(a.target),this.camera.zoom=a.zoom,this.control.update()}).onComplete(()=>{this.tweenGroup.remove(p),this.control.enabled=!0,n(!0)}).onStart(()=>{this.control.enabled=!1}).start()}),i+500)}fitCameraToObject(t,e=[20,20,20,20],i=500){let[n,a,c,p]=e,{clientWidth:h,clientHeight:l}=this.container,x=new u.Box3().setFromObject(t),{max:g,min:y}=x,b=v(g,this.camera,h,l),I=v(y,this.camera,h,l),Mt=new u.Box2().setFromPoints([new u.Vector2(b.x,b.y),new u.Vector2(I.x,I.y)]).getSize(new u.Vector2),Kt=(h-a-p)/Mt.x,Xt=(l-n-c)/Mt.y,_t=Math.min(Kt,Xt),Wt=new u.Vector3((g.x+y.x)/2,(g.y+y.y)/2,g.z);return this.setZoom(_t*this.camera.zoom,Wt,i)}fitCameraToGround(t=[20,20,20,20],e=500){return this.currentFloor&&this.currentFloor.hasElement?this.fitCameraToObject(this.currentFloor.groundUpper,t,e):Promise.resolve(!1)}setCameraPosition(t,e){return j(new Promise(i=>{let n=this.camera.position.clone(),a=this.getCameraLookAt(),c=new V.Tween(n,this.tweenGroup).to(t,e).onUpdate(()=>{this.camera.position.copy(n),this.control.target.copy(t.clone().add(a))}).onComplete(()=>{this.tweenGroup.remove(c),this.control.update(),this.control.enabled=!0,i(!0)}).onStart(()=>{this.control.enabled=!1}).start()}),e+500)}render(){this.renderer.render(this.scene,this.camera),this.dispatchEvent({type:"update"}),this.timer.requestAnimationFrame(()=>{this.render()}),this.tweenGroup.update()}dispose(){this.selection.dispose(),this.hoverHelper.dispose(),this.tweenGroup.getAll().forEach(t=>t.stop()),this.tweenGroup.removeAll(),this.unRegistryEvent(),this.container.removeChild(this.renderer.domElement),this.timer.dispose(),this.renderer.dispose(),this.lights.children.forEach(t=>t.dispose()),L(this.scene)}};var Ut=require("lodash"),jt={apiDomain:"",apiInfo:{},apiPath:{floorGraphic:"/api/inception-map/floor/get",floorRange:"/api/inception-map/range/get"},heatMap:{radius:50,gradient:{0:"#8F9FCD",.5:"#6284FF",1:"#F95D5D"}},useFloorCache:!0,control:{maxPolar:1.2},svg:{circle:{radius:"2",fill:"#1CADFF"},line:{stroke:"#1CADFF"}},selectBox:{stroke:"#1CADFF",fill:"rgba(28, 173, 255, 0.3)"},hover:{time:500}};function Lt(o){return(0,Ut.merge)({},jt,o)}var Gt=class extends $t.EventDispatcher{constructor(t,e={}){super();this.container=t;s(this,"config");s(this,"context");s(this,"polarKeys",[]);s(this,"azimuthalKeys",[]);s(this,"svgLine");s(this,"svgPolygon");s(this,"basicZoom",1);s(this,"floorDataMap",new Map);s(this,"onKeydown",t=>{this.polarKeys.includes(t.code)&&(this.context.control.maxPolarAngle=this.config.control.maxPolar,this.context.control.minPolarAngle=0),this.azimuthalKeys.includes(t.code)&&(this.context.control.maxAzimuthAngle=1/0,this.context.control.minAzimuthAngle=1/0)});s(this,"onKeyUp",t=>{if(this.polarKeys.includes(t.code)){let e=this.context.control.getPolarAngle();this.context.control.maxPolarAngle=e,this.context.control.minPolarAngle=e}if(this.azimuthalKeys.includes(t.code)){let e=this.context.control.getAzimuthalAngle();this.context.control.maxAzimuthAngle=e,this.context.control.minAzimuthAngle=e}});this.config=Lt(e),this.context=new et(t,this.config),this.registryEvent(),this.context.render()}loadGraphics(p){return H(this,arguments,function*({brand:t,project:e,phase:i,building:n,floor:a,ts:c}){let{apiDomain:h,apiPath:{floorGraphic:l},apiInfo:x}=this.config,g=`${h}${l}?brand=${t}&project=${e}&phase=${i}&building=${n}&floor=${a}&ts=${c}&resource_type_list=`;return yield fetch(g,x).then(b=>b.json()).then(b=>b.data).then(b=>((b||[]).map(I=>I.info=JSON.parse(I.info)),b||[]))})}loadBuildingGround(a){return H(this,arguments,function*({brand:t,project:e,phase:i,building:n}){let{apiDomain:c,apiPath:{floorRange:p},apiInfo:h}=this.config,l=`${c}${p}?brand=${t}&project=${e}&phase=${i}&building=${n}`;return yield fetch(l,h).then(g=>g.json()).then(g=>g.data).then(g=>{let y=(g||[])[0];return y&&(y.info=JSON.parse(y.info)),y})})}load(p){return H(this,arguments,function*({brand:t,project:e,phase:i,building:n,floor:a,ts:c}){if(this.floorDataMap.get(a))return;let[h,l]=yield Promise.all([this.loadGraphics({brand:t,project:e,phase:i,building:n,floor:a,ts:c}),this.loadBuildingGround({brand:t,project:e,phase:i,building:n})]);if(l){let x=Pt(l.info.geometry.cds[0]);h.forEach(g=>{if(g.info.geometry.type==="polygon")g.info.geometry.cds.map(y=>{Array.isArray(y)&&y.forEach(b=>{b[0]-=x[0],b[1]-=x[1]})});else{let[y,b]=g.info.geometry.cds;g.info.geometry.cds=[y-x[0],b-x[1]]}})}return this.config.useFloorCache||this.floorDataMap.clear(),this.floorDataMap.set(a,h),h})}createFloor(t){let e=new Z(this.context);if(!t.length)return{curFloor:e,graphics:[]};let n=t.filter(h=>h.info.group==="ground").map(h=>new w(this.context,h.info));e.addGrounds(n);let a=t.filter(h=>h.info.group!=="ground"),c=new Map,p=a.map(h=>{let l=e.addGraphic(h.info);return l.userData.data=h,c.set(h.legacy_id,l),l});return e.addShadow(),e.userData.legacyToGraphicMap=c,{curFloor:e,graphics:p}}switchFloor(t){return H(this,null,function*(){let e=this.floorDataMap.get(t);if(e){let i=this.createFloor(e);i?(this.context.switchFloor(i.curFloor),yield this.context.fitCameraToGround(void 0,0),this.basicZoom=this.context.camera.zoom,this.context.control.minZoom=this.basicZoom,this.context.control.maxZoom=this.basicZoom*25):console.warn("[switchFloor error] ["+t+"] \u697C\u5C42\u6CA1\u6709\u6570\u636E")}else console.warn("[switchFloor error] \u6CA1\u6709\u8FD9\u4E2A\u697C\u5C42\uFF0C\u8BF7\u5148\u8C03\u7528load\u65B9\u6CD5\u52A0\u8F7D\u697C\u5C42")})}addHeatmap(t){var e;return(e=this.context.currentFloor)==null?void 0:e.addHeatmap(t)}getLegacyToGraphicMap(){var t;return((t=this.context.currentFloor)==null?void 0:t.userData.legacyToGraphicMap)||new Map}getFloorAllGraphics(){var t;return((t=this.context.currentFloor)==null?void 0:t.graphicLayer.children.filter(e=>e instanceof w))||[]}createGraphicPoi(t,e){if(this.context.currentFloor){let i=this.context.currentFloor.addPoi(e),n=t.getCenter();return n.z+=t.options.height/2,i.position.copy(n),i.position.z=i.position.z+t.options.height/2,i}return null}removeHeatMap(){var t;(t=this.context.currentFloor)==null||t.removeHeatMap()}translateElementToCenter(t,e=500){let i=t.position.clone().setFromMatrixPosition(t.matrixWorld);return this.context.setCameraPosition(i,e)}getElementDeviceCoordinate(t){let e=t.position.clone(),{clientWidth:i,clientHeight:n}=this.container;return v(e,this.context.camera,i,n)}changeMapType(t,e=500){t==="2d"?this.context.setPolarAngle(0):this.context.setPolarAngle(1.2)}reduceMap(t=.5,e=500){let i=this.context.camera.zoom;return this.context.setZoom(i-t,this.context.control.target,e)}enlargeMap(t=.5,e=500){let i=this.context.camera.zoom;return this.context.setZoom(i+t,this.context.control.target,e)}registryEvent(){window.addEventListener("keydown",this.onKeydown),window.addEventListener("keyup",this.onKeyUp)}unRegistryEvent(){window.removeEventListener("keydown",this.onKeydown),window.removeEventListener("keyup",this.onKeyUp)}configurePolarShortcutKeys(t){this.polarKeys=t}configureAzimuthalShortcutKeys(t){this.azimuthalKeys=t}rotateMap(t=.1){let e=this.context.control.getAzimuthalAngle();this.context.control.maxAzimuthAngle=e+t,this.context.control.minAzimuthAngle=e+t,this.context.control.update()}measureDistance(){return H(this,null,function*(){return this.cancelDistance(),new Promise((t,e)=>{this.changeMapType("2d",0),this.context.control.enableRotate=!1,this.svgLine=new N(this.context);let i=this.svgLine.dispose.bind(this.svgLine);this.svgLine.dispose=function(){i(),e("cancel")},this.svgLine.addEventListener("distance",({distance:n})=>{t(n)})})})}cancelDistance(){this.svgLine&&(this.svgLine.dispose(),this.svgLine=void 0,this.context.control.enableRotate=!0)}measureArea(){return this.cancelArea(),new Promise((t,e)=>{this.changeMapType("2d",0),this.context.control.enableRotate=!1,this.svgPolygon=new Q(this.context);let i=this.svgPolygon.dispose.bind(this.svgPolygon);this.svgPolygon.dispose=function(){i(),e("cancel")},this.svgPolygon.addEventListener("area",({area:n})=>{t(n)})})}cancelArea(){this.svgPolygon&&(this.svgPolygon.dispose(),this.svgPolygon=void 0,this.context.control.enableRotate=!0)}getGraphicByNodeId(t){return this.context.currentFloor&&this.context.currentFloor.graphicLayer.graphicMap.get(t)||null}deleteGraphic(t){this.context.currentFloor&&(this.context.currentFloor.graphicLayer.remove(t),t.dispose(),this.context.currentFloor.graphicLayer.graphicMap.delete(t.options.id))}createGraphicByOptions(t){var e;return(e=this.context.currentFloor)==null?void 0:e.graphicLayer.createGraphic(t)}dispose(){this.context.dispose(),bt(),Et(),this.unRegistryEvent()}};
|
|
1
|
+
"use strict";var it=Object.defineProperty;var Yt=Object.getOwnPropertyDescriptor;var Zt=Object.getOwnPropertyNames,Dt=Object.getOwnPropertySymbols;var St=Object.prototype.hasOwnProperty,qt=Object.prototype.propertyIsEnumerable;var M=Math.pow,lt=(o,r,t)=>r in o?it(o,r,{enumerable:!0,configurable:!0,writable:!0,value:t}):o[r]=t,nt=(o,r)=>{for(var t in r||(r={}))St.call(r,t)&<(o,t,r[t]);if(Dt)for(var t of Dt(r))qt.call(r,t)&<(o,t,r[t]);return o};var Qt=(o,r)=>{for(var t in r)it(o,t,{get:r[t],enumerable:!0})},Nt=(o,r,t,e)=>{if(r&&typeof r=="object"||typeof r=="function")for(let i of Zt(r))!St.call(o,i)&&i!==t&&it(o,i,{get:()=>r[i],enumerable:!(e=Yt(r,i))||e.enumerable});return o};var Jt=o=>Nt(it({},"__esModule",{value:!0}),o);var s=(o,r,t)=>(lt(o,typeof r!="symbol"?r+"":r,t),t);var B=(o,r,t)=>new Promise((e,i)=>{var n=p=>{try{c(t.next(p))}catch(h){i(h)}},a=p=>{try{c(t.throw(p))}catch(h){i(h)}},c=p=>p.done?e(p.value):Promise.resolve(p.value).then(n,a);c((t=t.apply(o,r)).next())});var ne={};Qt(ne,{BMap:()=>Gt,BaseSvg:()=>D,Context:()=>et,Floor:()=>q,Graphic:()=>w,GraphicLayer:()=>W,HeatmapElement:()=>Z,HoverHelper:()=>tt,Layer:()=>H,Overlay:()=>_,Poi:()=>V,PoiLayer:()=>Y,Selection:()=>J,Shadow:()=>X,SvgLine:()=>Q,SvgPolygon:()=>N,Timer:()=>O,clearCanvas:()=>Pt,clearTextTexture:()=>Et,createCanvas:()=>Ft,createCircle:()=>z,createLine:()=>j,createRect:()=>Ct,createSvg:()=>wt,createSvgElement:()=>U,defaultConfig:()=>Kt,dispose:()=>G,getCenter:()=>rt,getConfig:()=>Lt,getTextureByText:()=>te,hasChinese:()=>xt,initCamera:()=>ut,initCanvas:()=>Ot,initControl:()=>vt,initDirectionalLight:()=>yt,initLight:()=>gt,initRenderer:()=>dt,initScene:()=>mt,initShape:()=>ft,isContain:()=>st,proxyOptions:()=>$,setCirclePosition:()=>S,setLineStartEnd:()=>E,setRectPosition:()=>at,timeoutPromise:()=>K,vector3ToDevice:()=>f});module.exports=Jt(ne);var Ut=require("three");var O=class{constructor(){s(this,"tasks",{requestAnimation:new Set,timeout:new Set,interval:new Set})}requestAnimationFrame(r){let t=window.requestAnimationFrame(()=>{this.tasks.requestAnimation.delete(t),r()});return this.tasks.requestAnimation.add(t),t}cancelAnimationFrame(r){this.tasks.requestAnimation.delete(r),window.cancelAnimationFrame(r)}setTimeout(r,t){let e=window.setTimeout(()=>{this.tasks.timeout.delete(e),r()},t);return this.tasks.timeout.add(e),e}clearTimeout(r){this.tasks.timeout.delete(r),window.clearTimeout(r)}setInterval(r,t){let e=window.setInterval(()=>{this.tasks.interval.delete(e),r()},t);return this.tasks.interval.add(e),e}clearInterval(r){this.tasks.interval.delete(r),window.clearInterval(r)}dispose(){this.tasks.requestAnimation.forEach(r=>{window.cancelAnimationFrame(r)}),this.tasks.requestAnimation.clear(),this.tasks.timeout.forEach(r=>{window.clearTimeout(r)}),this.tasks.timeout.clear(),this.tasks.interval.forEach(r=>{window.clearInterval(r)}),this.tasks.interval.clear()}};var m=require("three"),At=require("three/examples/jsm/controls/MapControls");function mt(){let o=new m.Scene;return o.background=new m.Color(16777215),o}function dt(){let o=new m.WebGLRenderer({antialias:!0});return o.setClearColor(16777215),o.setPixelRatio(window.devicePixelRatio),o.shadowMap.enabled=!0,o.shadowMap.autoUpdate=!0,o.shadowMap.type=m.PCFSoftShadowMap,o}function ut(o,r){let t=new m.OrthographicCamera(-o/2,o/2,r/2,-r/2,-1e3,5e3);return t.up.set(0,0,1),t.position.set(0,0,100),t.lookAt(0,0,0),t}function gt(){let o=new m.Group,r=new m.HemisphereLight(16777215,15658734,1);r.intensity=1,r.position.set(0,0,10),r.up.set(0,0,1),o.add(r);let t=new m.AmbientLight(16777215);return o.add(t),o}function vt(o,r){let t=new At.MapControls(o,r);return t.enableDamping=!1,t.maxPolarAngle=0,t.minPolarAngle=0,t.maxAzimuthAngle=0,t.minAzimuthAngle=0,t}function ft(o,r=[]){let t=new m.Shape(o.map(e=>new m.Vector2(...e)));return r.length&&r.forEach(e=>{var i=new m.Path(e.map(n=>new m.Vector2(...n)));t.holes.push(i)}),t}function yt(o=16777215,r=1){let t=new m.DirectionalLight(o,r);return t.castShadow=!0,t.shadow.radius=8,t.shadow.bias=-.001,t.shadow.mapSize.set(256,256),t.shadow.camera.left=-200,t.shadow.camera.right=200,t.shadow.camera.top=200,t.shadow.camera.bottom=-200,t}function G(o,r){var t;if(r&&o.children&&o.children.length&&o.children.forEach(e=>{G(e,r)}),o.isMesh){let e=o;e.geometry&&e.geometry.dispose(),e.material&&(Array.isArray(e.material)?e.material.forEach(i=>{i.dispose()}):e.material.dispose())}o.isLight&&((t=o.dispose)==null||t.call(o))}function xt(o){return/[\u4E00-\u9FA5]+/g.test(o)}var T=require("three");var ot=new Map;function Ot(){let o=document.createElement("canvas");o.width=1024,o.height=64;let r=o.getContext("2d",{willReadFrequently:!0});return r.font="54px sans-serif",r.textBaseline="hanging",r.lineWidth=12,r.fillStyle="rgba(0,0,0,1)",r.strokeStyle="white",{canvas:o,ctx:r}}var bt,F;function Ft(){if(!bt){let{canvas:o,ctx:r}=Ot();bt=o,F=r}}function te(o){if(ot.has(o))return ot.get(o);Ft(),F.clearRect(0,0,1024,64);let r=xt(o)?4:8;F.strokeText(o,2,r),F.fillText(o,2,r);let t=Math.ceil(F.measureText(o).width);t=t%2===0?t:t+1,t+=2;let e=F.getImageData(0,0,t,64),i=new T.DataTexture(Uint8Array.from(e.data),t,64,T.RGBAFormat);return i.flipY=!0,i.minFilter=T.LinearFilter,i.magFilter=T.LinearFilter,ot.set(o,i),i}function Et(){ot.clear()}function Pt(){F=null,bt=null}var R=require("@turf/turf");function f(o,r,t,e){let i=o.clone().project(r),n=t/2,a=e/2,c=Math.round(i.x*n+n),p=Math.round(-i.y*a+a);return{x:c,y:p}}function rt(o){let r=(0,R.featureCollection)(o.map(e=>(0,R.point)(e)));return(0,R.center)(r).geometry.coordinates}function st(o,r,t){return o.x>=r.x&&o.x<=t.x&&o.y>=r.y&&o.y<=t.y}function $(o,r){return new Proxy(o,{get:(t,e,i)=>Reflect.get(t,e,i),set:(t,e,i,n)=>{let a=Reflect.set(t,e,i,n);return r.dispatchEvent({type:`change-${e}`,value:i}),a}})}function K(o,r){return Promise.race([o,new Promise((t,e)=>{setTimeout(()=>e(new Error("Promise timeout")),r)})])}function U(o){return document.createElementNS("http://www.w3.org/2000/svg",o)}function wt(o,r){let t=U("svg");return t.setAttribute("width",o),t.setAttribute("height",r),t.style.cssText="position: absolute; left: 0; top: 0; pointer-events: none;",t}function z(o="2",r){let t=U("circle");return t.setAttribute("r",o),t.setAttribute("fill",r),t}function j(o){let r=U("line");return r.setAttribute("stroke",o),r}function Ct(o,r){let t=U("rect");return t.setAttribute("stroke",o),t.setAttribute("fill",r),t}function S(o,r,t){o.setAttribute("cx",`${r}`),o.setAttribute("cy",`${t}`)}function E(o,r,t){r&&(o.setAttribute("x1",`${r.x}`),o.setAttribute("y1",`${r.y}`)),t&&(o.setAttribute("x2",`${t.x}`),o.setAttribute("y2",`${t.y}`))}function at(o,r,t,e,i){o.setAttribute("x",`${r}`),o.setAttribute("y",`${t}`),o.setAttribute("width",`${e}`),o.setAttribute("height",`${i}`)}var u=require("three"),I=require("@tweenjs/tween.js");var Vt=require("three");var d=require("three");var Tt=require("lodash");var ee={id:"",height:.1,airHeight:0,area:0,group:"",fillColor:"#EFF4FB",strokeColor:"#ffffff",fillOpacity:1,strokeOpacity:1,doors:[],locked:!1,visible:!0,geometry:{type:"polygon",cds:[],curveCpt:[],curveIndex:[]},layerType:"",zIndex:0},w=class extends d.Object3D{constructor(t,e){super();this.context=t;s(this,"geometry");s(this,"material");s(this,"mesh");s(this,"line");s(this,"options");if(this.options=$((0,Tt.merge)({},ee,e),this),this.options.geometry.type==="point"){let[i,n]=this.options.geometry.cds;return this.position.set(i,n,this.options.height+this.options.airHeight),this}this.init(),this.visible=this.options.visible,this.addEventListener("change-fillColor",({value:i})=>{this.material.color=new d.Color(i)}),this.addEventListener("change-fillOpacity",({value:i})=>{this.material.opacity=i}),this.addEventListener("change-height",({value:i})=>{this.dispose(),this.init()}),this.addEventListener("change-strokeColor",({value:i})=>{this.line.material.color=new d.Color(i)}),this.addEventListener("change-strokeOpacity",({value:i})=>{this.line.material.opacity=i}),this.addEventListener("change-airHeight",({value:i})=>{this.position.z=i}),this.addEventListener("change-visible",({value:i})=>{this.visible=i})}getCenter(){if(this.options.geometry.type==="point")return this.position;let t=new d.Vector3,e=new d.Box3;return e.setFromObject(this),e.getCenter(t),t}getSize(){if(this.options.geometry.type==="point")return new d.Vector3(0,0,0);let t=new d.Box3,e=new d.Vector3;return t.setFromObject(this),t.getSize(e),e}getPosition(){return this.getCenter()}init(){this.geometry=this.initGeometry(),this.material=this.initMaterial(),this.mesh=this.initMesh(),this.mesh.position.z=this.options.airHeight+this.options.height/2,this.mesh.castShadow=!0,this.add(this.mesh),this.line=this.createBorder(),this.add(this.line)}initGeometry(){let t=ft(this.options.geometry.cds[0],this.options.geometry.cds.slice(1));return new d.ExtrudeGeometry(t,{steps:1,bevelEnabled:!1,depth:this.options.height,curveSegments:4})}initMaterial(){return new d.MeshStandardMaterial({color:this.options.fillColor,roughness:1,transparent:!0,opacity:this.options.fillOpacity,depthWrite:!0})}initLineMaterial(){return new d.LineBasicMaterial({color:this.options.strokeColor,opacity:this.options.strokeOpacity,transparent:!0,depthWrite:!0})}initMesh(){return new d.Mesh(this.geometry,this.material)}createBorder(){let t=this.initLineMaterial(),e=new d.EdgesGeometry(this.geometry),i=new d.LineSegments(e,t);return i.position.z=this.options.airHeight+this.options.height/2,i}raycast(t){if(!this.visible||this.options.geometry.type==="point")return!1;let e=t.intersectObject(this.mesh);if(e[0]){let{point:i,distance:n}=e[0];return{position:i,distance:n}}return!1}dispose(){G(this),this.clear()}};var P=require("three");var X=class extends P.Object3D{constructor(){super();s(this,"directionalLight");s(this,"plane");s(this,"basicOpacity",.39);this.directionalLight=this.initLight(),this.initPlane()}initLight(){let t=yt(16777215,1);return t.position.set(0,0,100),this.add(t),t}changeLightCamera(t){let e=t.x,i=t.y;this.directionalLight.shadow.camera.left=-e,this.directionalLight.shadow.camera.right=e,this.directionalLight.shadow.camera.top=i,this.directionalLight.shadow.camera.bottom=-i,this.directionalLight.shadow.camera.near=.5,this.directionalLight.shadow.camera.far=Math.max(e,i)}changeLightColor(t){this.directionalLight.color=new P.Color(t)}setPosition(t){this.position.copy(t),this.directionalLight.position.set(-t.x/2,-t.y/2,100)}initPlane(t=1e3,e=1e3){let i=new P.PlaneGeometry(t,e),n=new P.ShadowMaterial({transparent:!0,opacity:0,side:P.DoubleSide}),a=new P.Mesh(i,n);return a.receiveShadow=!0,a.position.z=-5,this.add(a),this.plane=a,a}setTarget(t){this.directionalLight.target=t}transformOpacity(t){return t*this.basicOpacity}setOpacity(t){this.plane.material.opacity=this.transformOpacity(t)}dispose(){G(this,!0)}};var kt=require("three"),Ht=require("lodash");var k=require("three");var _=class extends k.EventDispatcher{constructor(t){super();this.context=t;s(this,"div");s(this,"element");s(this,"position",new k.Vector3);s(this,"onUpdate",()=>{let t=this.getPosition(),{clientWidth:e,clientHeight:i}=this.context.container,{x:n,y:a}=f(t,this.context.camera,e,i);this.div.style.left=`${n}px`,this.div.style.top=`${a}px`});this.registryEvent(),this.div=this.initDiv(),this.context.container.appendChild(this.div)}initDiv(){let t=document.createElement("div");return t.style.position="absolute",t}bindElement(t){this.element=t}unBindElement(){this.element=void 0}setVisible(t,e="block"){this.div.style.display=t?e:"none"}setOpacity(t){this.div.style.opacity=`${t}`}getPosition(){return this.element?typeof this.element.getPosition=="function"?this.element.getPosition():new k.Box3().setFromObject(this.element).getCenter(new k.Vector3):this.position}registryEvent(){this.context.addEventListener("update",this.onUpdate)}unRegistryEvent(){this.context.removeEventListener("update",this.onUpdate)}dispose(){this.unRegistryEvent(),this.unBindElement(),this.context.container.removeChild(this.div),this.div=null}};var ie={text:"",level:1,collision_enable:!0,opacity:1},V=class extends kt.Object3D{constructor(t,e){super();this.context=t;s(this,"textDiv");s(this,"img");s(this,"overlay");s(this,"options");s(this,"_changePosition",()=>{this.overlay.div.style.transform=`translate3d(-50%, ${this.options.icon?"-100%":"-50%"}, 0)`});this.options=$((0,Ht.merge)({},ie,e),this),this.overlay=new _(this.context),this.overlay.bindElement(this),this._changePosition(),this.registryEvent(),this.initDiv(),this.addEventListener("change-icon",({value:i})=>{i?this.img?this.img.setAttribute("src",i):this.overlay.div.appendChild(this.initIcon()):(this.img&&this.overlay.div.removeChild(this.img),this.img=void 0)}),this.addEventListener("change-text",({value:i})=>{this.overlay.div.removeChild(this.textDiv),this.overlay.div.appendChild(this.initText())}),this.addEventListener("change-opacity",({value:i})=>{this.overlay.setOpacity(i)})}initDiv(){let t=this.overlay.div;return t.appendChild(this.initText()),this.options.icon&&t.appendChild(this.initIcon()),t.style.fontSize="12px",t.style.display="flex",t.style.flexDirection="column",t.style.justifyContent="center",t.style.alignItems="center",t.style.pointerEvents="none",t}getPosition(){return this.position}initText(){let t=document.createElement("div");return t.appendChild(this.createTextFragment()),t.style.background="rgba(255, 255, 255, .7)",t.style.padding="2px",t.style.borderRadius="4px",this.textDiv=t,t}createTextFragment(){let t=document.createDocumentFragment();return this.options.text.split(`\r
|
|
2
|
+
`).forEach(e=>{let i=document.createElement("div");i.style.whiteSpace="nowrap",i.textContent=e,t.appendChild(i)}),t}initIcon(){var e,i;let t=document.createElement("img");return t.setAttribute("src",this.options.icon),t.style.width=`${((e=this.options.icon_size)==null?void 0:e[0])||32}px`,t.style.height=`${((i=this.options.icon_size)==null?void 0:i[1])||32}px`,this.img=t,t}registryEvent(){this.context.addEventListener("update",this._changePosition)}unRegistryEvent(){this.context.removeEventListener("update",this._changePosition)}setVisible(t){this.overlay.setVisible(t,"flex")}getBox(){return this.overlay.div.getBoundingClientRect()}isContain(t,e){let i=this.getBox();return t>=i.left&&t<=i.right&&e>=i.top&&e<=i.bottom}dispose(){this.unRegistryEvent(),this.textDiv=null,this.img=void 0,this.overlay.dispose()}};var C=require("three");var ct=require("three");var Bt=require("three");var H=class extends Bt.Object3D{constructor(t){super();this.context=t}dispose(){G(this),this.clear()}};var W=class extends H{constructor(t){super(t);s(this,"graphicMap",new Map)}getCenter(){return new ct.Box3().setFromObject(this).getCenter(new ct.Vector3)}createGraphic(t){let e=new w(this.context,t);return this.add(e),this.graphicMap.set(t.id,e),e}getGraphicByRaycaster(t){let e={distance:1e4,graphic:null,position:null},i=this.children.reduce((n,a)=>{if(a instanceof w){let c=a.raycast(t);if(c){let{distance:p}=c;if(p<n.distance)return{distance:n.distance,position:n.position,graphic:a}}return n}else return n},e);return i===e?{graphics:[],position:null}:{graphics:[i.graphic],position:i.position}}};var Y=class extends H{constructor(t){super(t);s(this,"pois",[]);s(this,"onUpdate",()=>{this.collisionDetection()});this.registryEvent()}createPoi(t){let e=new V(this.context,t);return this.add(e),this.pushPoi(e),e.addEventListener("change-level",()=>this.changePoiLevelOrCollisionEnable(e)),e.addEventListener("change-collision_enable",()=>this.changePoiLevelOrCollisionEnable(e)),e}changePoiLevelOrCollisionEnable(t){let e=this.pois.findIndex(i=>i===t);e!==-1&&(this.pois.splice(e,1),this.pushPoi(t))}removePoi(t){let e=this.pois.findIndex(i=>i===t);e!==-1&&(this.pois.splice(e,1),this.remove(t),t.dispose())}pushPoi(t){if(!t.options.collision_enable){this.pois.unshift(t);return}if(t.options.level===1){this.pois.push(t);return}for(let e=0;e<this.pois.length;e++){let i=this.pois[e];if(i.options.collision_enable&&i.options.level<=t.options.level){this.pois.splice(e,0,t);return}}this.pois.push(t)}getPoiByDeviceXy(t,e){return this.children.filter(n=>n instanceof V&&n.isContain(t,e))}collisionDetection(){let t=[];this.pois.forEach((e,i)=>{e.setVisible(!0);let{left:n,right:a,top:c,bottom:p}=e.getBox();if(i===0){t.push({left:n,right:a,top:c,bottom:p});return}let h=t.some(l=>{let x=a<l.left||n>l.right,g=c>l.bottom||p<l.top;return x||g});e.setVisible(h)})}registryEvent(){this.context.addEventListener("update",this.onUpdate)}unRegistryEvent(){this.context.removeEventListener("update",this.onUpdate)}dispose(){super.dispose(),this.unRegistryEvent(),this.pois.forEach(t=>t.dispose()),this.pois.length=0}};var y=require("three"),Rt=require("@mars3d/heatmap.js"),A=require("@turf/turf");var Z=class extends y.Object3D{constructor(t){super();this.context=t;s(this,"heatmap");s(this,"div");s(this,"plane");this.div=document.createElement("div")}clearHeatmap(){this.div.firstChild&&this.div.removeChild(this.div.firstChild),this.heatmap=void 0}loadData(t){this.clearHeatmap();let{width:e,height:i,leftTop:n,center:a}=this.getBox(t);this.heatmap=(0,Rt.create)(nt({width:e,height:i,container:this.div},this.context.config.heatMap)),this.heatmap.setData(this.transformData(t,n)),this.initPlane(e,i),this.position.set(a[0],a[1],this.position.z)}initPlane(t,e){this.plane&&this.remove(this.plane);let i=new y.PlaneGeometry(t,e),n=new y.Texture(this.div.firstChild);n.needsUpdate=!0;let a=new y.MeshBasicMaterial({transparent:!0,side:y.DoubleSide,map:n});a.needsUpdate=!0,this.plane=new y.Mesh(i,a),this.add(this.plane)}getTransMatrix({x:t,y:e}){return new y.Matrix3().makeScale(1,-1).multiply(new y.Matrix3().makeTranslation(0-t,0-e))}transformData(t,e){let i=this.getTransMatrix(e);return{data:t.data.map(a=>{let c=new y.Vector2(a.x,a.y).applyMatrix3(i);return{x:c.x,y:c.y,value:a.value}}),max:t.max,min:t.min}}getBox(t){let e=(0,A.featureCollection)(t.data.map(h=>(0,A.point)([h.x,h.y]))),i=(0,A.bbox)(e),n=i[2]-i[0],a=i[3]-i[1],c={x:i[0],y:i[3]},p=(0,A.center)(e);return{width:n,height:a,leftTop:c,center:p.geometry.coordinates}}dispose(){this.div=null,this.heatmap=void 0}};var q=class extends C.Object3D{constructor(t){super();this.context=t;s(this,"graphicLayer");s(this,"poiLayer");s(this,"grounds",new Set);s(this,"shadow",new X);s(this,"heatmap");s(this,"groundUpper",new C.Object3D);this.graphicLayer=new W(this.context),this.poiLayer=new Y(this.context),this.groundUpper.add(this.graphicLayer),this.groundUpper.add(this.poiLayer),this.add(this.groundUpper)}addGrounds(t){t.forEach(e=>{this.grounds.has(e)||(this.grounds.add(e),this.groundUpper.add(e))})}get hasElement(){return!!(this.grounds.size||this.graphicLayer.children.length)}getCenter(){return new C.Box3().setFromObject(this.groundUpper).getCenter(new C.Vector3)}addShadow(){let t=new C.Box3().setFromObject(this.groundUpper),e=t.getCenter(new C.Vector3),i=t.getSize(new C.Vector3);this.shadow.setPosition(e),this.shadow.changeLightCamera(i),this.add(this.shadow)}addGraphic(t){return this.graphicLayer.createGraphic(t)}addPoi(t){return this.poiLayer.createPoi(t)}addHeatmap(t){this.heatmap||(this.heatmap=new Z(this.context),this.add(this.heatmap)),this.heatmap.loadData(t);let e=new C.Box3().setFromObject(this.graphicLayer);return this.heatmap.position.setZ(e.max.z),this.heatmap}removeHeatMap(){this.heatmap&&(this.remove(this.heatmap),this.heatmap.dispose(),this.heatmap=void 0)}setShadowOpacity(t){this.shadow.setOpacity(t)}setShadowVisible(t){this.shadow.visible=t}dispose(){var t;this.shadow.dispose(),this.graphicLayer.dispose(),this.poiLayer.dispose(),this.grounds.forEach(e=>e.dispose()),(t=this.heatmap)==null||t.dispose(),this.groundUpper.clear(),this.clear()}};var ht=require("three");var D=class extends ht.EventDispatcher{constructor(t){super();this.context=t;s(this,"points",[]);s(this,"svg");s(this,"enable",!0);this.svg=wt(`${t.container.clientWidth}`,`${t.container.clientHeight}`),t.container.appendChild(this.svg)}setEnable(t){this.enable=t,t?this.svg.style.display="block":this.svg.style.display="none"}getIntersectByPointerEvent(t){let{camera:e,renderer:i}=this.context,{offsetX:n,offsetY:a}=t,{clientWidth:c,clientHeight:p}=i.domElement,h=n/c*2-1,l=1-a/p*2;return new ht.Vector3(h,l,0).unproject(e)}getSvgCoordinate(t){let{camera:e,container:i}=this.context;return f(t,e,i.clientWidth,i.clientHeight)}dispose(){this.context.container.removeChild(this.svg),this.svg=null}};var Q=class extends D{constructor(t){super(t);this.context=t;s(this,"circles");s(this,"line");s(this,"onUpdate",()=>{if(this.points[0]){let t=this.getSvgCoordinate(this.points[0]);S(this.circles[0],t.x,t.y),E(this.line,t)}if(this.points[1]){let t=this.getSvgCoordinate(this.points[1]);S(this.circles[1],t.x,t.y),E(this.line,void 0,t)}});s(this,"onPointermove",t=>{this.points.length===1&&(this.line.style.display="block",E(this.line,void 0,{x:t.offsetX,y:t.offsetY}))});s(this,"onPointerleave",()=>{this.points[1]||(this.line.style.display="none")});s(this,"onPointerdown",t=>{if(this.points[1])return;let e=this.getIntersectByPointerEvent(t);if(e){let{offsetX:i,offsetY:n}=t,a=this.circles[this.points.length];S(a,i,n),this.points.length||E(this.line,{x:i,y:n},{x:i,y:n}),this.addPoint(e)}});let{config:{svg:{circle:e,line:i}}}=t;this.circles=[z(e.radius,e.fill),z(e.radius,e.fill)],this.line=j(i.stroke),this.svg.appendChild(this.circles[0]),this.svg.appendChild(this.circles[1]),this.svg.appendChild(this.line),this.registryEvent()}setEnable(t){super.setEnable(t),t?this.registryEvent():this.unRegistryEvent()}registryEvent(){this.context.container.addEventListener("pointerenter",this.onPointermove),this.context.container.addEventListener("pointermove",this.onPointermove),this.context.container.addEventListener("pointerleave",this.onPointerleave),this.context.container.addEventListener("pointerdown",this.onPointerdown),this.context.addEventListener("update",this.onUpdate)}unRegistryEvent(){this.context.container.removeEventListener("pointerenter",this.onPointermove),this.context.container.removeEventListener("pointermove",this.onPointermove),this.context.container.removeEventListener("pointerleave",this.onPointerleave),this.context.container.removeEventListener("pointerdown",this.onPointerdown),this.context.removeEventListener("update",this.onUpdate)}addPoint(t){if(this.points.push(t),this.points.length>=2){let e=this.calculatedDistance();this.dispatchEvent({type:"distance",distance:e})}}calculatedDistance(){let[{x:t,y:e},{x:i,y:n}]=this.points;return Math.sqrt(M(i-t,2)+M(n-e,2))}dispose(){super.dispose(),this.unRegistryEvent(),this.line=null,this.circles=[]}};var N=class extends D{constructor(t){super(t);s(this,"circles",[]);s(this,"lines",[]);s(this,"isClose",!1);s(this,"onUpdate",()=>{this.points.length&&this.points.forEach((t,e)=>{let i=this.getSvgCoordinate(t);this.circles[e]&&S(this.circles[e],i.x,i.y),e!==0&&E(this.lines[e-1],void 0,i),this.lines[e]&&E(this.lines[e],i)})});s(this,"onPointermove",t=>{!this.lastLine||this.isClose||(this.lastLine.style.display="block",E(this.lastLine,void 0,{x:t.offsetX,y:t.offsetY}))});s(this,"onPointerleave",()=>{this.isClose||(this.lastLine.style.display="none")});s(this,"onPointerdown",t=>{if(this.isClose)return;let e=this.getIntersectByPointerEvent(t);if(e){let{offsetX:i,offsetY:n}=t;this.checkAdsorb(i,n)?(this.isClose=!0,this.addPoint(this.points[0])):this.addPoint(e);let{circle:{fill:a,radius:c},line:{stroke:p}}=this.context.config.svg;if(!this.isClose){let h=z(c,a);S(h,i,n),this.addCircle(h)}if(this.lines.length&&E(this.lastLine,void 0,{x:i,y:n}),!this.isClose){let h=j(p);E(h,{x:i,y:n},{x:i,y:n}),this.addLine(h)}}});this.registryEvent()}setEnable(t){super.setEnable(t),t?this.registryEvent():this.unRegistryEvent()}get lastLine(){return this.lines.slice(-1)[0]}addCircle(t){this.circles.push(t),this.svg.appendChild(t)}addLine(t){this.lines.push(t),this.svg.appendChild(t)}registryEvent(){this.context.container.addEventListener("pointerenter",this.onPointermove),this.context.container.addEventListener("pointermove",this.onPointermove),this.context.container.addEventListener("pointerleave",this.onPointerleave),this.context.container.addEventListener("pointerdown",this.onPointerdown),this.context.addEventListener("update",this.onUpdate)}unRegistryEvent(){this.context.container.removeEventListener("pointerenter",this.onPointermove),this.context.container.removeEventListener("pointermove",this.onPointermove),this.context.container.removeEventListener("pointerleave",this.onPointerleave),this.context.container.removeEventListener("pointerdown",this.onPointerdown),this.context.removeEventListener("update",this.onUpdate)}checkAdsorb(t,e){if(this.points.length<3)return!1;let i=this.circles[0],n=+i.getAttribute("cx"),a=+i.getAttribute("cy");return Math.sqrt(M(t-n,2)+M(e-a,2))<=5}addPoint(t){if(this.points.push(t),this.isClose){let e=this.calculatedArea();this.dispatchEvent({type:"area",area:e})}}calculatedArea(){let t=this.points.map(n=>[n.x,n.y]),e=0,i=t.length;for(let n=0;n<i;n++){let a=(n+1)%i;e+=t[n][0]*t[a][1]-t[a][0]*t[n][1]}return Math.abs(e/2)}dispose(){super.dispose(),this.unRegistryEvent(),this.lines=[],this.circles=[]}};var zt=require("three");var pt=class extends D{constructor(t){super(t);s(this,"startPoint");s(this,"endPoint");s(this,"rect");s(this,"frustum",new zt.Frustum);s(this,"onPointerDown",t=>{if(!this.enable)return;let e=this.getIntersectByPointerEvent(t);e&&(this.startPoint=e),this.endPoint=void 0});s(this,"onPointerMove",t=>{if(!this.enable||!this.startPoint)return;let e=this.getIntersectByPointerEvent(t);e&&(this.endPoint=e)});s(this,"onPointerUp",t=>{if(!this.enable)return;let e=this.getIntersectByPointerEvent(t);e&&(this.endPoint=e),this.doSelect(),this.startPoint=void 0});s(this,"onUpdate",()=>{if(this.startPoint){let t=this.getSvgCoordinate(this.startPoint),e=nt({},t);this.endPoint&&(e=this.getSvgCoordinate(this.endPoint));let i={x:Math.min(t.x,e.x),y:Math.min(t.y,e.y)},n=Math.abs(e.x-t.x),a=Math.abs(e.y-t.y);at(this.rect,i.x,i.y,n,a)}});let{config:{selectBox:{fill:e,stroke:i}}}=t;this.rect=Ct(i,e),this.svg.appendChild(this.rect),this.registryEvent()}setEnable(t){super.setEnable(t),at(this.rect,0,0,0,0)}registryEvent(){this.context.container.addEventListener("pointerdown",this.onPointerDown),this.context.container.addEventListener("pointermove",this.onPointerMove),this.context.container.addEventListener("pointerup",this.onPointerUp),this.context.addEventListener("update",this.onUpdate)}unRegistryEvent(){this.context.container.removeEventListener("pointerdown",this.onPointerDown),this.context.container.removeEventListener("pointermove",this.onPointerMove),this.context.container.removeEventListener("pointerup",this.onPointerUp),this.context.removeEventListener("update",this.onUpdate)}doSelect(){if(this.startPoint&&this.endPoint){if(this.startPoint.distanceTo(this.endPoint)<.1)return;let{context:{camera:e,container:{clientWidth:i,clientHeight:n}}}=this,a=f(this.startPoint,e,i,n),c=f(this.endPoint,e,i,n),p={x:Math.min(a.x,c.x),y:Math.min(a.y,c.y)},h={x:Math.max(a.x,c.x),y:Math.max(a.y,c.y)},l=this.searchMapInFrustum(p,h);this.dispatchEvent({type:"selected",list:l})}}searchMapInFrustum(t,e){var n;let{context:i}=this;return((n=i.currentFloor)==null?void 0:n.graphicLayer.children.filter(a=>a instanceof w&&this.searchChildInFrustum(a,t,e)))||[]}searchChildInFrustum(t,e,i){let{context:{camera:n,container:{clientWidth:a,clientHeight:c}}}=this;if(!t)return!1;t.mesh.geometry.boundingBox||t.mesh.geometry.computeBoundingBox();let p=t.mesh.geometry.boundingBox;if(!p)return!1;let{min:h,max:l}=p,x=f(h,n,a,c),g=f(l,n,a,c);return!(!st(x,e,i)||!st(g,e,i))}dispose(){this.unRegistryEvent()}};var J=class extends Vt.EventDispatcher{constructor(t){super();this.context=t;s(this,"_list",new Set);s(this,"boxSelection");s(this,"prevPanStatus");s(this,"onPointerDown",t=>{let{graphics:e}=this.context.getGraphicsByDeviceXy(t.offsetX,t.offsetY);t.ctrlKey||this._list.clear(),e.forEach(i=>this._list.add(i)),this.selectEnd()});s(this,"onKeyDown",t=>{t.key==="Control"&&(this.boxSelection.setEnable(!0),this.prevPanStatus=this.context.control.enablePan,this.context.control.enablePan=!1)});s(this,"onKeyUp",t=>{t.key==="Control"&&(this.boxSelection.setEnable(!1),this.context.control.enablePan=!!this.prevPanStatus)});s(this,"onBoxSelected",({list:t})=>{this._list.clear(),t.forEach(e=>{this._list.add(e)}),this.selectEnd()});this.boxSelection=new pt(t),this.boxSelection.setEnable(!1),this.registryEvent()}get list(){return this._list}selectEnd(){this.dispatchEvent({type:"select",graphics:[...this._list]})}registryEvent(){this.context.container.addEventListener("pointerdown",this.onPointerDown),window.addEventListener("keydown",this.onKeyDown),window.addEventListener("keyup",this.onKeyUp),this.boxSelection.addEventListener("selected",this.onBoxSelected)}unRegistryEvent(){this.context.container.removeEventListener("pointerdown",this.onPointerDown),window.removeEventListener("keydown",this.onKeyDown),window.removeEventListener("keyup",this.onKeyUp),this.boxSelection.removeEventListener("selected",this.onBoxSelected)}dispose(){this.unRegistryEvent()}};var It=require("three");var tt=class extends It.EventDispatcher{constructor(t){super();this.context=t;s(this,"curGraphics",new Set);s(this,"timer",new O);s(this,"graphicTimerMap",new Map);s(this,"onPointerMove",({graphics:t})=>{if(!t.length&&this.curGraphics.size){this.curGraphics.clear(),this.handleHoverGraphicsChange();return}let{time:e}=this.context.config.hover;t.forEach(n=>{if(this.graphicTimerMap.get(n)||this.curGraphics.has(n))return;let a=this.timer.setTimeout(()=>{this.curGraphics.add(n),this.handleHoverGraphicsChange()},e);this.graphicTimerMap.set(n,a)}),this.graphicTimerMap.forEach((n,a)=>{t.includes(a)||(this.timer.clearTimeout(n),this.graphicTimerMap.delete(a))});let i=this.curGraphics.size;this.curGraphics.forEach(n=>{t.includes(n)||this.curGraphics.delete(n)}),i!==this.curGraphics.size&&this.handleHoverGraphicsChange()});s(this,"onPointerLevel",()=>{this.curGraphics.clear(),this.handleHoverGraphicsChange()});this.registryEvent()}handleHoverGraphicsChange(t=this.curGraphics){this.dispatchEvent({type:"hover-change",graphics:Array.from(this.curGraphics)})}registryEvent(){this.context.addEventListener("pointer-over",this.onPointerMove),this.context.addEventListener("pointer-move",this.onPointerMove),this.context.addEventListener("pointer-level",this.onPointerLevel)}unRegistryEvent(){this.context.removeEventListener("pointer-over",this.onPointerMove),this.context.removeEventListener("pointer-move",this.onPointerMove),this.context.removeEventListener("pointer-level",this.onPointerLevel)}dispose(){this.unRegistryEvent(),this.timer.dispose()}};var et=class extends u.EventDispatcher{constructor(t,e){super();this.container=t;this.config=e;s(this,"scene",mt());s(this,"renderer",dt());s(this,"camera");s(this,"control");s(this,"lights",gt());s(this,"timer",new O);s(this,"tweenGroup",new I.Group);s(this,"currentFloor");s(this,"selection");s(this,"hoverHelper");s(this,"basicRatio");s(this,"onWindowResize",()=>{let{container:t,camera:e,renderer:i}=this,{clientWidth:n,clientHeight:a}=t;e.left=-n/2,e.right=n/2,e.top=a/2,e.bottom=-a/2,e.updateProjectionMatrix(),i.setSize(n,a)});s(this,"onClick",t=>{let{graphics:e,position:i}=this.getGraphicsByDeviceXy(t.offsetX,t.offsetY);e.length&&this.dispatchEvent({type:"graphic-click",graphics:e,position:i});let n=this.getPoisByDeviceXy(t.clientX,t.clientY);n.length&&this.dispatchEvent({type:"poi-click",pois:n})});s(this,"onPointerover",t=>{let{graphics:e,position:i}=this.getGraphicsByDeviceXy(t.offsetX,t.offsetY),n=this.getPoisByDeviceXy(t.clientX,t.clientY);this.dispatchEvent({type:"pointer-over",graphics:e,pois:n,position:i})});s(this,"onPointermove",t=>{let{graphics:e,position:i}=this.getGraphicsByDeviceXy(t.offsetX,t.offsetY),n=this.getPoisByDeviceXy(t.clientX,t.clientY);this.dispatchEvent({type:"pointer-move",graphics:e,pois:n,position:i})});s(this,"onPointerleave",()=>{this.dispatchEvent({type:"pointer-level"})});s(this,"onSelectionSelect",({graphics:t})=>{this.dispatchEvent({type:"select-graphic",graphics:t})});s(this,"onHoverChange",({graphics:t})=>{this.dispatchEvent({type:"hover",graphics:t})});this.container.style.position="relative",this.container.style.overflow="hidden",this.init(),this.selection=new J(this),this.hoverHelper=new tt(this),this.registryEvent()}init(){let{clientWidth:t,clientHeight:e}=this.container;this.camera=ut(t,e),this.renderer.setSize(t,e),this.control=vt(this.camera,this.renderer.domElement),this.container.appendChild(this.renderer.domElement),this.scene.add(this.lights),this.basicRatio=this.getRatio(),this.control.addEventListener("change",()=>{var n;let i=this.control.getPolarAngle();(n=this.currentFloor)==null||n.setShadowOpacity(i/this.config.control.maxPolar),this.dispatchEvent({type:"change-ratio",px:(this.basicRatio||0)*this.camera.zoom})})}getRatio(t=new u.Vector3(0,0,0),e=new u.Vector3(100,0,0)){let{clientWidth:i,clientHeight:n}=this.container,a=f(t,this.camera,i,n),c=f(e,this.camera,i,n);return Math.ceil(Math.sqrt(M(c.x-a.x,2)+M(c.y-a.y,2)))}changeAmbientLightColor(t){this.lights.children.forEach(e=>{e instanceof u.AmbientLight&&(e.color=new u.Color(t))})}switchFloor(t){this.currentFloor&&(this.scene.remove(this.currentFloor),this.currentFloor.dispose()),this.currentFloor=t,this.scene.add(t);let e=t.getCenter();e&&(this.lights.position.x=e.x,this.lights.position.y=e.y)}getGraphicsByDeviceXy(t,e){var c;let i=new u.Vector2;i.x=t/this.container.clientWidth*2-1,i.y=e/this.container.clientHeight*-2+1;let n=new u.Raycaster;return n.setFromCamera(i,this.camera),((c=this.currentFloor)==null?void 0:c.graphicLayer.getGraphicByRaycaster(n))||{graphics:[],position:null}}getPoisByDeviceXy(t,e){var n;return((n=this.currentFloor)==null?void 0:n.poiLayer.getPoiByDeviceXy(t,e))||[]}registryEvent(){window.addEventListener("resize",this.onWindowResize),this.container.addEventListener("click",this.onClick),this.container.addEventListener("pointerover",this.onPointerover),this.container.addEventListener("pointermove",this.onPointermove),this.container.addEventListener("pointerleave",this.onPointerleave),this.selection.addEventListener("select",this.onSelectionSelect),this.hoverHelper.addEventListener("hover-change",this.onHoverChange)}unRegistryEvent(){window.removeEventListener("resize",this.onWindowResize),this.container.removeEventListener("click",this.onClick),this.container.removeEventListener("pointerover",this.onPointerover),this.container.removeEventListener("pointermove",this.onPointermove),this.container.removeEventListener("pointerleave",this.onPointerleave),this.selection.removeEventListener("select",this.onSelectionSelect),this.hoverHelper.removeEventListener("hover-change",this.onHoverChange)}setPolarAngle(t,e=500){return K(new Promise(i=>{let n={polar:this.control.getPolarAngle()},a={polar:t},c=new I.Tween(n,this.tweenGroup).to(a,e).onUpdate(()=>{this.control.maxPolarAngle=n.polar,this.control.minPolarAngle=n.polar,this.control.update()}).onComplete(()=>{this.control.enabled=!0,this.tweenGroup.remove(c),i(!0)}).onStart(()=>{this.control.enabled=!1}).start()}),e+500)}getCameraLookAt(){return new u.Vector3().subVectors(this.control.target,this.camera.position)}setZoom(t,e,i=500){return K(new Promise(n=>{let a={zoom:this.camera.zoom,target:this.control.target.clone()},c=this.getCameraLookAt(),p=new I.Tween(a,this.tweenGroup).to({zoom:t,target:e},i).onUpdate(()=>{this.camera.position.copy(a.target.clone().sub(c)),this.control.target.copy(a.target),this.camera.zoom=a.zoom,this.control.update()}).onComplete(()=>{this.tweenGroup.remove(p),this.control.enabled=!0,n(!0)}).onStart(()=>{this.control.enabled=!1}).start()}),i+500)}fitCameraToObject(t,e=[20,20,20,20],i=500){let[n,a,c,p]=e,{clientWidth:h,clientHeight:l}=this.container,x=new u.Box3().setFromObject(t),{max:g,min:b}=x,v=f(g,this.camera,h,l),L=f(b,this.camera,h,l),Mt=new u.Box2().setFromPoints([new u.Vector2(v.x,v.y),new u.Vector2(L.x,L.y)]).getSize(new u.Vector2),jt=(h-a-p)/Mt.x,Xt=(l-n-c)/Mt.y,_t=Math.min(jt,Xt),Wt=new u.Vector3((g.x+b.x)/2,(g.y+b.y)/2,g.z);return this.setZoom(_t*this.camera.zoom,Wt,i)}fitCameraToGround(t=[20,20,20,20],e=500){return this.currentFloor&&this.currentFloor.hasElement?this.fitCameraToObject(this.currentFloor.groundUpper,t,e):Promise.resolve(!1)}setCameraPosition(t,e){return K(new Promise(i=>{let n=this.camera.position.clone(),a=this.getCameraLookAt(),c=new I.Tween(n,this.tweenGroup).to(t,e).onUpdate(()=>{this.camera.position.copy(n),this.control.target.copy(t.clone().add(a))}).onComplete(()=>{this.tweenGroup.remove(c),this.control.update(),this.control.enabled=!0,i(!0)}).onStart(()=>{this.control.enabled=!1}).start()}),e+500)}render(){this.renderer.render(this.scene,this.camera),this.dispatchEvent({type:"update"}),this.timer.requestAnimationFrame(()=>{this.render()}),this.tweenGroup.update()}dispose(){this.selection.dispose(),this.hoverHelper.dispose(),this.tweenGroup.getAll().forEach(t=>t.stop()),this.tweenGroup.removeAll(),this.unRegistryEvent(),this.container.removeChild(this.renderer.domElement),this.timer.dispose(),this.renderer.dispose(),this.lights.children.forEach(t=>t.dispose()),G(this.scene)}};var $t=require("lodash"),Kt={apiDomain:"",apiInfo:{},apiPath:{floorGraphic:"/api/inception-map/floor/get",floorRange:"/api/inception-map/range/get"},heatMap:{radius:50,gradient:{0:"#8F9FCD",.5:"#6284FF",1:"#F95D5D"}},useFloorCache:!0,control:{maxPolar:1.2},svg:{circle:{radius:"2",fill:"#1CADFF"},line:{stroke:"#1CADFF"}},selectBox:{stroke:"#1CADFF",fill:"rgba(28, 173, 255, 0.3)"},hover:{time:500}};function Lt(o){return(0,$t.merge)({},Kt,o)}var Gt=class extends Ut.EventDispatcher{constructor(t,e={}){super();this.container=t;s(this,"config");s(this,"context");s(this,"polarKeys",[]);s(this,"azimuthalKeys",[]);s(this,"svgLine");s(this,"svgPolygon");s(this,"basicZoom",1);s(this,"floorDataMap",new Map);s(this,"buildingGroundMap",new Map);s(this,"currentBuildGround",null);s(this,"onKeydown",t=>{this.polarKeys.includes(t.code)&&(this.context.control.maxPolarAngle=this.config.control.maxPolar,this.context.control.minPolarAngle=0),this.azimuthalKeys.includes(t.code)&&(this.context.control.maxAzimuthAngle=1/0,this.context.control.minAzimuthAngle=1/0)});s(this,"onKeyUp",t=>{if(this.polarKeys.includes(t.code)){let e=this.context.control.getPolarAngle();this.context.control.maxPolarAngle=e,this.context.control.minPolarAngle=e}if(this.azimuthalKeys.includes(t.code)){let e=this.context.control.getAzimuthalAngle();this.context.control.maxAzimuthAngle=e,this.context.control.minAzimuthAngle=e}});this.config=Lt(e),this.context=new et(t,this.config),this.registryEvent(),this.context.render()}loadGraphics(p){return B(this,arguments,function*({brand:t,project:e,phase:i,building:n,floor:a,ts:c}){let{apiDomain:h,apiPath:{floorGraphic:l},apiInfo:x}=this.config,g=`${h}${l}?brand=${t}&project=${e}&phase=${i}&building=${n}&floor=${a}&ts=${c}&resource_type_list=`;return yield fetch(g,x).then(v=>v.json()).then(v=>v.data).then(v=>((v||[]).map(L=>L.info=JSON.parse(L.info)),v||[]))})}getBuildingKey({brand:t,project:e,phase:i,building:n}){return`${t}-${e}-${i}-${n}`}loadBuildingGround(a){return B(this,arguments,function*({brand:t,project:e,phase:i,building:n}){let c=this.getBuildingKey({brand:t,project:e,phase:i,building:n});if(this.buildingGroundMap.get(c))return this.buildingGroundMap.get(c)||null;let{apiDomain:p,apiPath:{floorRange:h},apiInfo:l}=this.config,x=`${p}${h}?brand=${t}&project=${e}&phase=${i}&building=${n}`,g=yield fetch(x,l).then(b=>b.json()).then(b=>b.data).then(b=>{let v=(b||[])[0];return v&&(v.info=JSON.parse(v.info)),v});return this.buildingGroundMap.set(c,g),g})}getFloorKey({brand:t,project:e,phase:i,building:n,floor:a,ts:c}){return`${t}-${e}-${i}-${n}-${a}-${c}`}load(p){return B(this,arguments,function*({brand:t,project:e,phase:i,building:n,floor:a,ts:c}){let h=this.getFloorKey({brand:t,project:e,phase:i,building:n,floor:a,ts:c});if(this.floorDataMap.get(h))return;let[l,x]=yield Promise.all([this.loadGraphics({brand:t,project:e,phase:i,building:n,floor:a,ts:c}),this.loadBuildingGround({brand:t,project:e,phase:i,building:n})]);if(x){let g=rt(x.info.geometry.cds[0]);l.forEach(b=>{if(b.info.geometry.type==="polygon")b.info.geometry.cds.map(v=>{Array.isArray(v)&&v.forEach(L=>{L[0]-=g[0],L[1]-=g[1]})});else{let[v,L]=b.info.geometry.cds;b.info.geometry.cds=[v-g[0],L-g[1]]}})}return this.config.useFloorCache||this.floorDataMap.clear(),this.floorDataMap.set(h,l),l})}createFloor(t){let e=new q(this.context);if(!t.length)return{curFloor:e,graphics:[]};let n=t.filter(h=>h.info.group==="ground").map(h=>new w(this.context,h.info));e.addGrounds(n);let a=t.filter(h=>h.info.group!=="ground"),c=new Map,p=a.map(h=>{let l=e.addGraphic(h.info);return l.userData.data=h,c.set(h.legacy_id,l),l});return e.addShadow(),e.userData.legacyToGraphicMap=c,{curFloor:e,graphics:p}}switchFloor(p){return B(this,arguments,function*({brand:t,project:e,phase:i,building:n,floor:a,ts:c}){let h=this.getFloorKey({brand:t,project:e,phase:i,building:n,floor:a,ts:c}),l=this.floorDataMap.get(h);if(l){let x=this.getBuildingKey({brand:t,project:e,phase:i,building:n});this.currentBuildGround=this.buildingGroundMap.get(x)||null;let g=this.createFloor(l);g?(this.context.switchFloor(g.curFloor),this.context.control.minZoom=0,this.context.control.maxZoom=1/0,yield this.context.fitCameraToGround(void 0,0),this.basicZoom=this.context.camera.zoom,this.context.control.minZoom=this.basicZoom,this.context.control.maxZoom=this.basicZoom*25):console.warn("[switchFloor error] ["+a+"] \u697C\u5C42\u6CA1\u6709\u6570\u636E")}else console.warn("[switchFloor error] \u6CA1\u6709\u8FD9\u4E2A\u697C\u5C42\uFF0C\u8BF7\u5148\u8C03\u7528load\u65B9\u6CD5\u52A0\u8F7D\u697C\u5C42")})}addHeatmap(t){var e;return(e=this.context.currentFloor)==null?void 0:e.addHeatmap(t)}getLegacyToGraphicMap(){var t;return((t=this.context.currentFloor)==null?void 0:t.userData.legacyToGraphicMap)||new Map}getFloorAllGraphics(){var t;return((t=this.context.currentFloor)==null?void 0:t.graphicLayer.children.filter(e=>e instanceof w))||[]}createGraphicPoi(t,e){if(this.context.currentFloor){let i=this.context.currentFloor.addPoi(e),n=t.getCenter();return n.z+=t.options.height/2,i.position.copy(n),i.position.z=i.position.z+t.options.height/2,i}return null}removeHeatMap(){var t;(t=this.context.currentFloor)==null||t.removeHeatMap()}translateElementToCenter(t,e=500){let i=t.position.clone().setFromMatrixPosition(t.matrixWorld);return this.context.setCameraPosition(i,e)}getElementDeviceCoordinate(t){let e=t.position.clone(),{clientWidth:i,clientHeight:n}=this.container;return f(e,this.context.camera,i,n)}changeMapType(t,e=500){t==="2d"?this.context.setPolarAngle(0):this.context.setPolarAngle(1.2)}reduceMap(t=.5,e=500){let i=this.context.camera.zoom;return this.context.setZoom(i-t,this.context.control.target,e)}enlargeMap(t=.5,e=500){let i=this.context.camera.zoom;return this.context.setZoom(i+t,this.context.control.target,e)}registryEvent(){window.addEventListener("keydown",this.onKeydown),window.addEventListener("keyup",this.onKeyUp)}unRegistryEvent(){window.removeEventListener("keydown",this.onKeydown),window.removeEventListener("keyup",this.onKeyUp)}configurePolarShortcutKeys(t){this.polarKeys=t}configureAzimuthalShortcutKeys(t){this.azimuthalKeys=t}rotateMap(t=.1){let e=this.context.control.getAzimuthalAngle();this.context.control.maxAzimuthAngle=e+t,this.context.control.minAzimuthAngle=e+t,this.context.control.update()}measureDistance(){return B(this,null,function*(){return this.cancelDistance(),new Promise((t,e)=>{this.changeMapType("2d",0),this.context.control.enableRotate=!1,this.svgLine=new Q(this.context);let i=this.svgLine.dispose.bind(this.svgLine);this.svgLine.dispose=function(){i(),e("cancel")},this.svgLine.addEventListener("distance",({distance:n})=>{t(n)})})})}cancelDistance(){this.svgLine&&(this.svgLine.dispose(),this.svgLine=void 0,this.context.control.enableRotate=!0)}measureArea(){return this.cancelArea(),new Promise((t,e)=>{this.changeMapType("2d",0),this.context.control.enableRotate=!1,this.svgPolygon=new N(this.context);let i=this.svgPolygon.dispose.bind(this.svgPolygon);this.svgPolygon.dispose=function(){i(),e("cancel")},this.svgPolygon.addEventListener("area",({area:n})=>{t(n)})})}cancelArea(){this.svgPolygon&&(this.svgPolygon.dispose(),this.svgPolygon=void 0,this.context.control.enableRotate=!0)}getGraphicByNodeId(t){return this.context.currentFloor&&this.context.currentFloor.graphicLayer.graphicMap.get(t)||null}deleteGraphic(t){this.context.currentFloor&&(this.context.currentFloor.graphicLayer.remove(t),t.dispose(),this.context.currentFloor.graphicLayer.graphicMap.delete(t.options.id))}createGraphicByOptions(t){var e;if(this.currentBuildGround){let i=rt(this.currentBuildGround.info.geometry.cds[0]);if(t.geometry.type==="polygon")t.geometry.cds.map(n=>{Array.isArray(n)&&n.forEach(a=>{a[0]-=i[0],a[1]-=i[1]})});else{let[n,a]=t.geometry.cds;t.geometry.cds=[n-i[0],a-i[1]]}}return(e=this.context.currentFloor)==null?void 0:e.graphicLayer.createGraphic(t)}dispose(){this.context.dispose(),Et(),Pt(),this.unRegistryEvent()}};
|
|
3
3
|
//# sourceMappingURL=bmap.cjs.min.js.map
|