@aibee/crc-bmap 0.14.6 → 0.14.7

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/lib/index.cjs CHANGED
@@ -505,7 +505,7 @@
505
505
  top: 0;
506
506
  left: 0;
507
507
  z-index: 9999;
508
- `,document.body.appendChild(a.canvas)}setAngle(t){if(console.log("angle",t),a.textureMap.has(t))this._initIcon(a.textureMap.get(t));else{this.draw(t);let e=this.getTexture(this.getImageData());a.textureMap.set(t,e),this._initIcon(e),this._initScale({zoom:this.bmap.context.camera.zoom})}}_initIcon(t){if(this.spriteIcon)this.spriteIcon.material.map=t,t.needsUpdate=!0;else{let e=new Jt.Sprite(new Jt.SpriteMaterial({map:t,transparent:!0,alphaTest:.2,depthTest:this.options.depth_test,rotation:this.options.icon_rotate/180*Math.PI}));e.renderOrder=1e5+this.options.level,t.needsUpdate=!0,this.add(e),e.center.set(.5,.5),this.spriteIcon=e}}initSize(){this.spriteIcon&&this.spriteIcon.center.set(.5,.5)}draw(t){let{ctx:e}=a,{config:{size:i}}=this,s=i[0]/2,o=i[1]/2,n=4,r=1,h=n+r;if(e.clearRect(0,0,i[0],i[1]),e.setLineDash([10,10]),e.strokeStyle="#fff",e.lineWidth=2,e.beginPath(),e.arc(s,o,o-h,-Math.PI/2,Math.PI*2-Math.PI/2,t<Math.PI),e.stroke(),e.strokeStyle="#0A7AFF",t<Math.PI){let c=-Math.PI/2,l=c-t;e.beginPath(),e.arc(s,o,o-h,c,l,!0)}else{let c=-Math.PI/2,l=c+Math.PI*2-t;e.beginPath(),e.arc(s,o,o-h,c,l,!1)}e.stroke(),e.clearRect(s-h*2,0,h*4,h*4),e.beginPath(),e.arc(s,h,n,0,Math.PI*2),e.fillStyle="#0A7AFF",e.fill(),e.setLineDash([10,0]),e.strokeStyle="#fff",e.lineWidth=r,e.stroke(),e.clearRect(0,o-5,10,10),e.clearRect(s-5,i[1]-10,10,10),e.clearRect(i[0]-10,o-5,10,10),t>Math.PI/2&&t<Math.PI?e.fillStyle="#0A7AFF":e.fillStyle="#fff",e.fillRect(0,o-1,10,2),e.fillStyle="#fff",e.fillRect(s-1,i[1]-10,2,10),t>Math.PI&&t<Math.PI/2*3?e.fillStyle="#0A7AFF":e.fillStyle="#fff",e.fillRect(i[0]-10,o-1,10,2)}getImageData(){let{ctx:t}=a,{config:{size:e}}=this;return t.getImageData(0,0,e[0],e[1])}getTexture(t){let{config:{size:e}}=this,i=new Jt.DataTexture(Uint8Array.from(t.data),e[0],e[1],Jt.RGBAFormat);return i.format=Jt.RGBAFormat,i.magFilter=Jt.LinearFilter,i.minFilter=Jt.LinearFilter,i.colorSpace="srgb",i.flipY=!0,i}dispose(){var t;super.dispose(),(t=this.spriteIcon)==null||t.material.dispose()}static dispose(){this.textureMap.forEach(t=>{t.dispose()}),this.textureMap.clear(),this.ctx=null,this.canvas=null}constructor(t,e){super(t.context,{icon_size:e.size,collision_enable:!1,level:2}),this.bmap=t,this.config=e,a.canvas.width=e.size[0],a.canvas.height=e.size[1]}};Se.canvas=document.createElement("canvas");Se.ctx=Se.canvas.getContext("2d",{willReadFrequently:!0});Se.textureMap=new Map;var Xh={path:{},cheapMaximumDistance:20,needStartPoi:!1,startPoi:{},positionNavigation:{},offsetY:150,directionEmitThreshold:5,disablePathAnimation:!1,disablePathRotate:!1,disablePathShorten:!1,speed:1,roadData:[],runAnimationMaxTime:1,navigationCameraBasic:45,canBack:!1},pn=class extends X{get curFloorPathLength(){var t,e;return(e=(t=this.curFloorPath)==null?void 0:t.distance)!=null?e:0}get curFloorPathPoints(){var t,e;return(e=(t=this.curFloorPath)==null?void 0:t.points)!=null?e:[]}registryEvent(){this.bmap.context.addEventListener("update",this.onUpdate),this.bmap.addEventListener(yt.SWITCH_FLOOR_GROUND,this.onSwitchFloor),this.positionNavigation.addEventListener("navigation-info",this.onNavigationInfo),this.bmap.context.addEventListener("control-change",this.onControlChangeForStartPoi)}setRoadData(t){this.options.roadData=t,this.positionNavigation.setRoadData(t)}showStartRotateHelperPoi(){var t;if(this.needStartRotateHelperPoi=!0,!this.startPoi||this.startRotateHelperPoi)return;let e=this.startPoi.options.icon_size;this.startRotateHelperPoi=new Se(this.bmap,{size:[e[0]+20,e[1]+20]}),this.startRotateHelperPoi.setAngle(0),this.startRotateHelperPoi.position.setZ(.51),(t=this.bmap.context.currentFloor)==null||t.poiLayer2.pushPoi(this.startRotateHelperPoi)}hideStartRotateHelperPoi(){if(this.needStartRotateHelperPoi=!1,this.startRotateHelperPoi){var t;(t=this.bmap.context.currentFloor)==null||t.poiLayer2.removePoi(this.startRotateHelperPoi),this.startRotateHelperPoi=null}}setStartPoiPosition(t,e){this.startPoi&&(this.startPoi.position.setX(t).setY(e),this.startRotateHelperPoi&&this.startRotateHelperPoi.position.setX(t).setY(e),this.detachLine&&this.detachLine.setPosition(this.startPoi.position,this.detachStartPoi.position))}resetStatus(){this.pauseAnimation(),this.positionNavigation.resetStatus(this.paths),this.movedDistance=0,this.startPoi&&this.translatePath&&this.setStartPoiPosition(this.translatePath[0][0],this.translatePath[0][1])}toPositionByTask(t){var e;let s=(e=this.taskQueue.getTasks().find(n=>n.meta.type==="toPosition"))==null?void 0:e.tid,o={run:()=>this.toPositionBySpeed(t,this.options.speed),meta:{type:"toPosition"}};s?this.taskQueue.replace(s,o):this.taskQueue.add(o)}pauseAnimation(){this.taskQueue.clear(),this.positionNavigation.pause(),this.tweenUtil.pause()}continueAnimation(){this.tweenUtil.continue(),this.positionNavigation.continue()}clearTween(){this.tweenUtil.clear(),this.taskQueue.clear(),this.bmap.context.control.enabled=!0}unRegistryEvent(){this.bmap.context.removeEventListener("update",this.onUpdate),this.bmap.removeEventListener(yt.SWITCH_FLOOR_GROUND,this.onSwitchFloor),this.positionNavigation.removeEventListener("navigation-info",this.onNavigationInfo),this.bmap.context.removeEventListener("control-change",this.onControlChangeForStartPoi)}clearPath(){if(this.resetStatus(),this.path&&(this.bmap.context.scene.remove(this.path),this.path.dispose(),this.path=null,this.clearTween()),this.startPoi){var t;if((t=this.bmap.context.currentFloor)==null||t.poiLayer2.removePoi(this.startPoi),this.startPoi=null,this.startRotateHelperPoi){var e;(e=this.bmap.context.currentFloor)==null||e.poiLayer2.removePoi(this.startRotateHelperPoi),this.startRotateHelperPoi=null}}if(this.detachStartPoi){var i;(i=this.bmap.context.currentFloor)==null||i.removePoi2(this.detachStartPoi),this.detachStartPoi=null}this.detachLine&&(this.bmap.context.scene.remove(this.detachLine),this.detachLine.dispose(),this.detachLine=null),this.translatePath=null}setCurFloorPath(t){t===null?(this.curFloorPath=null,this.currentPathPosition=null,this.toPointPosition=null):(this.curFloorPath=t,this.currentPathPosition=t.points[0],this.toPointPosition=t.points[0]),this.movedDistance=0,this.clearTween()}setCurPathIndex(t){var e,i;this.curPathIndex=t,((e=this.paths[t])==null?void 0:e.floor)===((i=this.bmap.context.currentFloor)==null?void 0:i.name)?(this.setCurFloorPath(this.paths[t]),this.renderPath(this.translatePoints(this.curFloorPathPoints))):this.clearPath()}addPath(t,e){e===void 0&&(e=0);var i;this.paths=t,this.curPathIndex=e,this.clearTween(),this.clearPath();let s=(i=this.bmap.context.currentFloor)==null?void 0:i.name,o=t[e];if(s&&(o==null?void 0:o.floor)===s)if(this.setCurFloorPath(o),this.bmap.currentBuildGround)this.renderPath(this.translatePoints(o.points));else{let n=()=>{this.bmap.removeEventListener("center-change",n),this.renderPath(this.translatePoints(o.points))};this.bmap.addEventListener("center-change",n)}this.dispatchEvent({type:"add-path",paths:t})}translatePoints(t){let[e,i]=this.bmap.buildingCenter;return t.map(s=>[s[0]-e,s[1]-i])}renderPath(t){this.translatePath=t;let e=this.catmullRomCurve3(t);if(this.cPath=e,this.animationPathOptions={cPathIndex:0},this.pathStart=e[0],this.path?this.path.updatePoints(e):(this.path=new Qs(this,this.options.path),this.path.create(e),this.path.position.z=this.bmap.context.currentFloor.groundMaxHeight+.5,this.bmap.context.scene.add(this.path)),this.path.movePath(0),this.startPoi){var i;if((i=this.bmap.context.currentFloor)==null||i.poiLayer2.removePoi(this.startPoi),this.startPoi=null,this.startRotateHelperPoi){var s;(s=this.bmap.context.currentFloor)==null||s.poiLayer2.removePoi(this.startRotateHelperPoi),this.startRotateHelperPoi=null}}if(this.removeDetachStart(),this.showDetachStartState&&this.options.detachStartPoi){var o;this.detachStartPoi=new tt(this.bmap.context,w({},this.options.detachStartPoi,{id:"navigation_detach_start_poi",position:{x:e[0][0],y:e[0][1],z:.51},collision_enable:!1}))||null,(o=this.bmap.context.currentFloor)==null||o.poiLayer2.pushPoi(this.detachStartPoi),this.detachLine=new ai(this.bmap.context,new At.Vector3(e[0][0],e[0][1],.51),new At.Vector3(e[0][0],e[0][1],.51)),this.bmap.context.scene.add(this.detachLine)}if(this.options.needStartPoi){var n;this.startPoi=new tt(this.bmap.context,w({},this.options.startPoi,{id:"navigation_start_poi",position:{x:e[0][0],y:e[0][1],z:.51},collision_enable:!1}))||null,(n=this.bmap.context.currentFloor)==null||n.poiLayer2.pushPoi(this.startPoi),this.needStartRotateHelperPoi&&this.showStartRotateHelperPoi(),console.log(this.startRotateHelperPoi)}this.dispatchEvent({type:"render-path",path:this.path})}catmullRomCurve3(t){return Di(t,!1,!0,.1,170,2.5)}getPathDirection(){if(!this.curFloorPath||!this.currentPathPosition||this.curFloorPathPoints.length<2)return null;let t=ce(this.curFloorPathPoints,this.currentPathPosition),e=this.curFloorPathPoints[t],i=this.curFloorPathPoints[t+1],s=new At.Vector3(i[0]-e[0],i[1]-e[1],0).normalize(),o=new At.Vector3(0,1,0).normalize(),n=s.angleTo(o),r=new At.Vector3().crossVectors(o,s);return(Object.is(r.y,0)?-1:1)*n}getPathDirection2(){if(!this.curFloorPath||!this.toPointPosition||this.curFloorPathPoints.length<2)return null;let t=ce(this.curFloorPathPoints,this.toPointPosition),e=this.curFloorPathPoints[t],i=this.curFloorPathPoints[t+1];return(new At.Vector2(i[0]-e[0],i[1]-e[1]).normalize().angle()*180/Math.PI-90+360)%360}changeCameraToPathUp(t){return f(this,null,function*(){t===void 0&&(t=100);let e=this.getPathDirection();if(e===null)return;let i=this.bmap.context.control.getAzimuthalAngle();Math.abs(i-e)>Math.PI&&(i>0?e=Math.PI*2+e:e=e-Math.PI*2);let s=Math.abs(e-this.bmap.context.control.getAzimuthalAngle());if(s<.01)return;let{control:o}=this.bmap.context,n=t/Math.PI*6*s;return Ft(new Promise(r=>{let h={azimuthal:o.getAzimuthalAngle()},c={azimuthal:e},l=o.getPolarAngle(),{maxPolarAngle:p,minPolarAngle:d}=o;o.maxPolarAngle=l,o.minPolarAngle=l;let u=new fi.Tween(h,this.tweenUtil.group).to(c,n).easing(fi.Easing.Quadratic.InOut).onUpdate(()=>f(this,null,function*(){this.startPoi&&o.target.copy(this.startPoi.position),o.setAzimuthalAngle(h.azimuthal,!0),o.setTargetByOffset(this.options.offsetY)})).onComplete(()=>{o.enabled=!0,this.tweenUtil.remove(u),o.maxPolarAngle=p,o.minPolarAngle=d,r(!0)}).onStart(()=>{o.enabled=!1}).start()}),n+500).finally(()=>{this.bmap.context.control.enabled=!0})})}initNavigationCamera(t){return f(this,null,function*(){t===void 0&&(t=1e3);var e;let s=(e=this.taskQueue.getTasks().find(n=>n.meta.type==="initNavigationCamera"))==null?void 0:e.tid,o={run:()=>Ft(f(this,null,function*(){yield this.initCameraZoom(t/2),this.options.disablePathRotate||(yield this.changeCameraToPathUp(t/4)),yield this.translateCameraToStartPoi(t/(this.options.disablePathRotate?2:4))}),t+500).finally(()=>{this.bmap.context.control.enabled=!0}),meta:{type:"initNavigationCamera"}};s?this.taskQueue.replace(s,o):this.taskQueue.add(o)})}translateCameraToStartPoi(t){return f(this,null,function*(){if(t===void 0&&(t=100),!this.startPoi)return;let{clientSize:{width:e,height:i},camera:s,control:o}=this.bmap.context,n=Math.round(e/2),r=Math.round(i/2),h=o.target.clone(),c=D(this.startPoi.position,s,e,i),l=c.x-n,p=r-c.y+this.options.offsetY;if(!(Math.abs(l)<=1&&Math.abs(p)<=1)){if(Math.abs(l)>=1){let d=new At.Vector3;d.setFromMatrixColumn(s.matrix,0),d.normalize(),d.multiplyScalar(l/s.zoom),h.add(new At.Vector3(d.x,d.y,0))}if(Math.abs(p)>=1){let d=new At.Vector3;d.setFromMatrixColumn(s.matrix,1),d.normalize(),d.multiplyScalar(p/s.zoom),h.add(new At.Vector3(d.x,d.y,0))}return Ft(new Promise(d=>{let u=o.target.clone();console.log(u,h,t);let m=new fi.Tween(u,this.tweenUtil.group).to(h,t).onUpdate(()=>{this.bmap.context.control.setCameraPositionByTarget(u,0)}).onComplete(()=>{this.bmap.context.control.setCameraPositionByTarget(h,0),this.tweenUtil.remove(m),this.bmap.context.control.enabled=!0,d(!0)}).onStart(()=>{this.bmap.context.control.enabled=!1}).start()}),t+500).then(()=>{this.bmap.context.control.enabled=!0})}})}initCameraZoom(t){return f(this,null,function*(){if(t===void 0&&(t=100),!this.startPoi)return;let{clientSize:{width:e,height:i},currentFloor:s}=this.bmap.context,{max:o,min:n}=s.box,h=Math.min(e/(o.x-n.x),i/(o.y-n.y))*(o.x-n.x)/this.options.navigationCameraBasic;return this.bmap.context.setZoom(h,this.startPoi.position,t).finally(()=>{this.bmap.context.control.enabled=!0})})}toPosition(t,e){if(this.paths[this.curPathIndex]&&this.paths[this.curPathIndex].floor===t&&this.detachStartPoi){let i=this.translatePoints([e]);this.detachStartPoi.position.setX(i[0][0]),this.detachStartPoi.position.setY(i[0][1]),this.detachLine&&this.startPoi&&this.detachLine.setPosition(this.startPoi.position,this.detachStartPoi.position)}this.options.canBack&&(this.positionNavigation.pointIndex=0,this.positionNavigation.position=this.paths[this.curPathIndex].points[0]),this.positionNavigation.toPosition(t,e)}startSimulation(){this.positionNavigation.startSimulation()}setSimulationSpeed(t){this.positionNavigation.changeSimulationSpeed(t)}toPositionBySpeed(t,e){return f(this,null,function*(){let{currentPathPosition:i,curFloorPath:s,curFloorPathPoints:o}=this;if(!s||!i)return null;let n=this.movedDistance,r=Do(o,t);if(n===-1||r===-1||!this.options.canBack&&r<=n)return null;let h=r-n;if(!h)return;let c=Math.min(Math.abs(h)/e,this.options.runAnimationMaxTime);return this.pathTween&&this.clearTween(),Ft(new Promise(l=>{let p=this.pathTween=new fi.Tween({distance:0},this.tweenUtil.group).to({distance:h},c*1e3).onUpdate(d=>f(this,null,function*(){this.moveDistance(d.distance+n,p)})).onComplete(()=>{this.tweenUtil.remove(p),l(!0)}).start()}),c*1e3+500).finally(()=>{this.bmap.context.control.enabled=!0})})}moveDistance(t,e){return f(this,null,function*(){if(this.movedDistance=t,!this.options.disablePathShorten){var i;(i=this.path)==null||i.movePath(this.movedDistance/this.curFloorPathLength)}let s=Ze(this.curFloorPathPoints,this.movedDistance);if(s===null)return;this.currentPathPosition=s;let o=this.translatePoints([s])[0];this.startPoi&&(this.setStartPoiPosition(o[0],o[1]),this.options.disablePathAnimation||this.bmap.context.control.setTargetByOffset(this.options.offsetY,this.startPoi.position.clone())),!this.options.disablePathAnimation&&!this.options.disablePathRotate&&(e==null||e.pause(),yield this.changeCameraToPathUp(500/this.options.speed),e==null||e.resume())})}removeDetachStart(){if(this.detachLine&&(this.bmap.context.scene.remove(this.detachLine),this.detachLine.dispose(),this.detachLine=null),this.detachStartPoi){var t;(t=this.bmap.context.currentFloor)==null||t.poiLayer2.removePoi(this.detachStartPoi),this.detachStartPoi=null}}hideDetachStart(){this.showDetachStartState=!1,this.removeDetachStart()}showDetachStart(){if(!this.detachStartPoi&&(this.showDetachStartState=!0,this.path&&this.startPoi&&this.options.detachStartPoi)){var t;let e=this.startPoi.position;this.detachStartPoi=new tt(this.bmap.context,w({},this.options.detachStartPoi,{id:"navigation_detach_start_poi",position:e,collision_enable:!1}))||null,(t=this.bmap.context.currentFloor)==null||t.poiLayer2.pushPoi(this.detachStartPoi),this.detachLine=new ai(this.bmap.context,new At.Vector3(e.x,e.y,.51),new At.Vector3(e.x,e.y,.51)),this.bmap.context.scene.add(this.detachLine)}}setStartPoiRotate(t){this.startPoiRotate=t;let i=(this.bmap.context.control.getAzimuthalAngle()*180/Math.PI+360)%360,s=(360-t-i)%360;this.detachStartPoi&&(this.detachStartPoi.options.icon_rotate=s),this.startPoi&&(this.startPoi.options.icon_rotate=s,this.startRotateHelperPoi&&this.startRotateHelperPoi.setAngle(s))}dispose(){var t;if(this.path&&(this.bmap.context.scene.remove(this.path),this.path.dispose()),this.hideDetachStart(),this.startPoi){var e;(e=this.bmap.context.currentFloor)==null||e.poiLayer2.removePoi(this.startPoi),this.startPoi=null}this.tweenUtil.dispose(),this.unRegistryEvent(),(t=this.startRotateHelperPoi)==null||t.dispose(),Se.dispose(),this.positionNavigation.dispose(),this.startRotateHelperPoi=null,super.dispose()}constructor(t,e={},i){super(t),this.path=null,this.fetchRoadStatus=!1,this.paths=[],this.curPathIndex=0,this.curFloorPath=null,this.translatePath=null,this.currentPathPosition=null,this.toPointPosition=null,this.pathTween=null,this.startPoi=null,this.detachStartPoi=null,this.detachLine=null,this.startPoiRotate=null,this.startRotateHelperPoi=null,this.needStartRotateHelperPoi=!1,this.showDetachStartState=!0,this.movedDistance=0,this.pathStart=[0,0],this.tweenUtil=new Pe,this.taskQueue=new Ve,this.animationPathOptions={cPathIndex:0},this.cPath=[],this.onNavigationInfo=s=>{let{info:o}=s;if(this.dispatchEvent({type:"navigation-info",info:o}),!o.offset){if(o.routeIndex!==this.curPathIndex)return;this.toPointPosition=o.pos,this.toPositionByTask(o.pos)}},this.onUpdate=()=>{this.tweenUtil.update()},this.onSwitchFloor=s=>{let{data:{curFloor:o}}=s;if(this.clearTween(),this.paths[this.curPathIndex]){let n=this.paths[this.curPathIndex];this.setCurFloorPath(n!=null?n:null),n?this.renderPath(this.translatePoints(n.points)):this.clearPath()}else this.clearPath()},this.onControlChangeForStartPoi=()=>{this.startPoi&&this.startPoiRotate!==null&&this.setStartPoiRotate(this.startPoiRotate)},!i&&typeof e=="object"&&(i=e),this.options=Object.assign({},Xh,i),this.positionNavigation=new to(this,w({simulationSpeed:this.options.speed},this.options.positionNavigation),this.options.roadData),this.registryEvent()}};var rM=require("core-js/modules/web.dom-collections.iterator.js");var ms=require("three"),dn=class extends X{show(t,e){let i=0;t.forEach(n=>{n.onAddToScene("mulFloors"),n.position.z=i,i+=n.userData.height,n.poiLayer2.pois.forEach(r=>{r.options.depth_test=!0})});let{scene:s,currentFloor:o}=this.bmap.context;s.background=new ms.Color((e==null?void 0:e.backgroundColor)||"#f1f7f6"),o&&(s.remove(o),o.dispose()),this.group.add(...t),s.add(this.group),this.floors=t,this.fitCamera(),this.bmap.context.cameraBound.updateBox(),this.showStatus=!0,this.bmap.context.forceUpdate()}showStep(t,e){return this.show(t,e)}hide(){let{scene:t}=this.bmap.context;t.remove(this.group),this.floors.forEach(e=>{e.dispose()}),this.floors=[],this.group.clear(),this.showStatus=!1}showByNotDispose(t,e,i){i===void 0&&(i=()=>!0);let s=0;t.forEach(r=>{[...r.poiLayer2.pois].forEach(h=>{if(!i(h)){h.visible=!1;return}h.options.depth_test=!0}),r.position.z=s,s+=r.userData.height,r.onAddToScene("mulFloors")});let{scene:o,currentFloor:n}=this.bmap.context;o.background=new ms.Color((e==null?void 0:e.backgroundColor)||"#f1f7f6"),n&&o.remove(n),this.group.add(...t),o.add(this.group),this.floors=t,this.fitCamera(),this.bmap.context.cameraBound.updateBox(),this.showStatus=!0,this.bmap.context.forceUpdate()}hideByNotDispose(){let{scene:t}=this.bmap.context;t.remove(this.group),this.floors.forEach(e=>{e.poiLayer2.pois.forEach(i=>{i.visible=!0,i.options.depth_test=!1})}),this.floors.forEach(e=>{e.position.z=0,e.onRemoveFromScene()}),this.group.clear(),this.showStatus=!1}fitCamera(){let{context:t,config:e}=this.bmap;t.cameraBound.setEnable(!1),t.control.minZoom=0,t.control.maxZoom=1/0,t.camera.zoom=1,t.setAzimuthalAngle(e.control.defaultAzimuthal,0),t.setPolarAngle(e.control.defaultPolar,0),t.fitCameraToObject(this.group,e.defaultPadding,0,!1);let i=t.camera.zoom;t.control.minZoom=i,t.control.maxZoom=i*e.control.maxZoomScale,this.bmap.basicZoom=t.camera.zoom,t.control.addEventListener("change",this.bmap.onControlChange),this.bmap.onControlChange(),t.cameraBound.setEnable(!0)}dispose(){this.floors.forEach(t=>t.dispose()),this.floors=[],super.dispose()}constructor(t){super(t),this.floors=[],this.group=new ms.Group,this.showStatus=!1,this.group.name="mul-floor-group"}};var ma=require("three");var Yh={};function un(){return new Worker(new URL("./worker/path.worker-C7N3AIZ3.js",Yh.url))}var fs=class extends ma.EventDispatcher{setLiftPriority(t){return Z(this.worker,"onSetLiftPriority",t)}loaded(){return new Promise(t=>{if(this.initRoadStatus)t(!0);else{let e=i=>{let{status:s}=i;s&&(this.removeEventListener("init-road-status",e),t(!0))};this.addEventListener("init-road-status",e)}})}setRoadData(t,e){return f(this,null,function*(){this.initRoadStatus=!1,this.dispatchEvent({type:"init-road-status",status:!1}),yield Z(this.worker,"set_road_info",{roadData:t,facilities:e}),this.initRoadStatus=!0,this.dispatchEvent({type:"init-road-status",status:!0})})}getPath(t,e,i,s,o,n){return f(this,null,function*(){return i===void 0&&(i=""),new Promise((r,h)=>{let c=()=>{Z(this.worker,"get_path",{start:t,end:e,type:i,permission:s,travelDirection:o,options:n}).then(l=>{l?typeof l=="string"?h(l):r(l):h("no-path")})};if(this.initRoadStatus)c();else{let l=p=>{let{status:d}=p;d&&(this.removeEventListener("init-road-status",l),c())};this.addEventListener("init-road-status",l)}})})}getDirectionPath(t){return Z(this.worker,"get_direction_path",t)}dispose(){return f(this,null,function*(){Z(this.worker,"clear",""),this.worker.terminate()})}constructor(){super(),this.worker=un(),this.initRoadStatus=!1}};var fa=require("three");var qh={};function mn(){return new Worker(new URL("./worker/cr-path.worker-RCWZ3ILJ.js",qh.url))}var fn=class extends fa.EventDispatcher{setRoadData(t){return f(this,null,function*(){this.initRoadStatus=!1,this.dispatchEvent({type:"init-road-status",status:!1}),yield Z(this.worker,"set_road_info",{roadData:t}),this.initRoadStatus=!0,this.dispatchEvent({type:"init-road-status",status:!0})})}getPath(t,e,i){return f(this,null,function*(){return i===void 0&&(i=""),new Promise((s,o)=>{let n=()=>{Z(this.worker,"get_path",{start:t,end:e,type:i}).then(r=>{r?typeof r=="string"?o(r):s(r):o("no-path")})};if(this.initRoadStatus)n();else{let r=h=>{let{status:c}=h;c&&(this.removeEventListener("init-road-status",r),n())};this.addEventListener("init-road-status",r)}})})}getDirectionPath(t){return Z(this.worker,"get_direction_path",t)}dispose(){return f(this,null,function*(){Z(this.worker,"clear",""),this.worker.terminate()})}constructor(){super(),this.worker=mn(),this.initRoadStatus=!1}};var bM=require("core-js/modules/web.dom-collections.iterator.js"),SM=require("core-js/modules/es.set.difference.v2.js"),EM=require("core-js/modules/es.set.intersection.v2.js"),LM=require("core-js/modules/es.set.is-disjoint-from.v2.js"),CM=require("core-js/modules/es.set.is-subset-of.v2.js"),TM=require("core-js/modules/es.set.is-superset-of.v2.js"),kM=require("core-js/modules/es.set.symmetric-difference.v2.js"),DM=require("core-js/modules/es.set.union.v2.js"),AM=require("core-js/modules/es.array.push.js");var ga=require("three"),eo=class extends Wt{setEnable(t){super.setEnable(t),bt(this.rect,0,0,0,0),t?this.registryEvent():(this.startPoint=void 0,this.unRegistryEvent())}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:s}}}=this,o=D(this.startPoint,e,i,s),n=D(this.endPoint,e,i,s),r={x:Math.min(o.x,n.x),y:Math.min(o.y,n.y)},h={x:Math.max(o.x,n.x),y:Math.max(o.y,n.y)},c=this.searchMapInFrustum(r,h);this.dispatchEvent({type:"selected",list:c})}}searchMapInFrustum(t,e){var i;let{context:s}=this;return((i=s.currentFloor)==null?void 0:i.graphicLayer.children.filter(o=>o instanceof lt&&this.searchChildInFrustum(o,t,e)))||[]}searchChildInFrustum(t,e,i){let{context:{camera:s,container:{clientWidth:o,clientHeight:n}}}=this;if(!t)return!1;if(!t.mesh){let d=t.getPosition();if(d){let u=D(d,s,o,n);return Me(u,e,i)}return!1}t.mesh.geometry.boundingBox||t.mesh.geometry.computeBoundingBox();let r=t.mesh.geometry.boundingBox;if(!r)return!1;let{min:h,max:c}=r,l=D(h,s,o,n),p=D(c,s,o,n);return!(!Me(l,e,i)||!Me(p,e,i))}dispose(){super.dispose(),this.rect=null,this.unRegistryEvent()}constructor(t){super(t),this.frustum=new ga.Frustum,this.onPointerDown=s=>{if(!this.enable)return;let o=this.getIntersectByPointerEvent(s);o&&(this.startPoint=o),this.endPoint=void 0},this.onPointerMove=s=>{if(!this.enable||!this.startPoint)return;let o=this.getIntersectByPointerEvent(s);o&&(this.endPoint=o)},this.onPointerUp=s=>{if(!this.enable)return;let o=this.getIntersectByPointerEvent(s);o&&(this.endPoint=o),this.doSelect(),this.startPoint=void 0},this.onUpdate=()=>{if(this.startPoint){let s=this.getSvgCoordinate(this.startPoint),o=w({},s);this.endPoint&&(o=this.getSvgCoordinate(this.endPoint));let n={x:Math.min(s.x,o.x),y:Math.min(s.y,o.y)},r=Math.abs(o.x-s.x),h=Math.abs(o.y-s.y);bt(this.rect,n.x,n.y,r,h)}else bt(this.rect,0,0,0,0)};let{config:{selectBox:{fill:e,stroke:i}}}=t;this.rect=_e(i,e),this.svg.appendChild(this.rect),this.registryEvent()}};var $h={boxSelection:!1,elements:["graphic","poi"]},gn=class extends X{get list(){return this._list}enableBoxSelection(){this.isMultipleSelect||!this.options.boxSelection||(this.isMultipleSelect=!0,this.boxSelection.setEnable(!0),this.prevPanStatus=this.bmap.context.control.enablePan,this.prevRotateStatus=this.bmap.context.control.enableRotate,this.bmap.context.control.enablePan=!1,this.bmap.context.control.enableRotate=!1)}disableBoxSelection(){this.isMultipleSelect&&(this.isMultipleSelect=!1,this.boxSelection.setEnable(!1),this.bmap.context.control.enablePan=!!this.prevPanStatus,this.bmap.context.control.enableRotate=!!this.prevRotateStatus)}selectEnd(){this.dispatchEvent({type:"select",graphics:[...this._list],pois:[...this._poiList],isMultipleSelect:this.isMultipleSelect})}registryEvent(){this.bmap.context.container.addEventListener("pointerdown",this.onPointerDown),this.bmap.context.container.addEventListener("pointerup",this.onPointerUp),this.bmap.context.container.addEventListener("pointerout",this.onPointerOut),this.bmap.context.container.addEventListener("pointercancel",this.onPointerOut),window.addEventListener("keydown",this.onKeyDown),window.addEventListener("keyup",this.onKeyUp),this.boxSelection.addEventListener("selected",this.onBoxSelected)}unRegistryEvent(){this.bmap.context.container.removeEventListener("pointerdown",this.onPointerDown),this.bmap.context.container.removeEventListener("pointerup",this.onPointerUp),this.bmap.context.container.removeEventListener("pointerout",this.onPointerOut),this.bmap.context.container.removeEventListener("pointercancel",this.onPointerOut),window.removeEventListener("keydown",this.onKeyDown),window.removeEventListener("keyup",this.onKeyUp),this.boxSelection.removeEventListener("selected",this.onBoxSelected)}clear(){this._list.clear()}remove(t){this._list.delete(t)}dispose(){this.unRegistryEvent(),super.dispose()}constructor(t,e={}){super(t),this._list=new Set,this._poiList=new Set,this.downPoint=null,this.isMultipleSelect=!1,this.onPointerDown=i=>{this.downPoint={x:i.offsetX,y:i.offsetY}},this.onPointerUp=i=>{if(!this.downPoint)return;let{offsetX:s,offsetY:o}=i,{x:n,y:r}=this.downPoint;if(Math.sqrt((n-s)**2+(r-o)**2)>3)return;let h=new Set,c=[],l=[];if(this.options.elements.includes("graphic")){let{graphics:p}=this.bmap.context.getGraphicsByDeviceXy(s,o);p.map(d=>h.add(d.options.id)),c.push(...p)}if(this.options.elements.includes("poi")){let p=this.bmap.context.getPoisByDeviceXy(s,o);l.push(...p),p.forEach(d=>{if(!h.has(d.options.id)){var u;let m=((u=this.bmap.context.currentFloor)==null?void 0:u.graphicLayer.graphicMap.get(d.options.id))||null;m&&(h.add(d.options.id),c.push(m))}})}(!this.options.boxSelection||!(He?i.metaKey:i.ctrlKey))&&(this._list.clear(),this._poiList.clear()),c.forEach(p=>this._list.add(p)),l.forEach(p=>this._poiList.add(p)),this.selectEnd(),this.downPoint=null},this.onPointerOut=i=>{this.disableBoxSelection()},this.onKeyDown=i=>{Ne(i.key)&&this.enableBoxSelection()},this.onKeyUp=i=>{Ne(i.key)&&this.disableBoxSelection()},this.onBoxSelected=i=>{let{list:s}=i;this._list.clear(),this._poiList.clear(),s.forEach(o=>{if(this.options.elements.includes("graphic")&&this._list.add(o),this.options.elements.includes("poi")){let n=this.bmap.getPoiById(o.options.id);n&&this._poiList.add(n)}}),this.selectEnd()},this.options=w({},$h,e),this.boxSelection=new eo(this.bmap.context),this.boxSelection.setEnable(!1),this.registryEvent()}};var BM=require("core-js/modules/es.array.push.js"),Ot=require("lodash");var F=function(a){return a.COMPASS="compass",a.DEVICE_MOTION="deviceMotion",a.ACCELERATION="acceleration",a.GPS="gps",a}({});var Jh={time:1e3,elements:[F.COMPASS,F.DEVICE_MOTION,F.ACCELERATION,F.GPS]},gs=class extends st{start(){this.options.elements.some(t=>[F.DEVICE_MOTION,F.COMPASS].includes(t))&&this.listenDeviceOrientation(),this.options.elements.includes(F.ACCELERATION)&&this.listenAcceleration(),this.options.elements.includes(F.GPS)&&this.listenGps(),this.dispatchEvent({type:"start"}),this.dispatchTimer=this.timer.setInterval(()=>{this.dispatchEvent({type:"sensor-data",data:(0,Ot.cloneDeep)(this.data)}),this.data=[]},this.options.time)}addDataItem(t){this.data.push(t),this.dispatchEvent({type:"add-data-item",item:t})}listenDeviceOrientation(){pe?window.addEventListener("deviceorientation",this.deviceOrientationAbsHandler,!1):window.addEventListener("deviceorientationabsolute",this.deviceOrientationAbsHandler,{absolute:!0})}listenAcceleration(){window.addEventListener("devicemotion",this.handleAcceleration,!1)}listenGps(){this.gpsTimer=navigator.geolocation.watchPosition(t=>{console.log("watch gps",t.coords),this.addDataItem({type:F.GPS,timestamp:Date.now(),res:[t.coords.longitude,t.coords.latitude,t.coords.accuracy]})},t=>{console.log("\u83B7\u53D6gps\u5931\u8D25",t)},{enableHighAccuracy:!0})}checkSensor(){return f(this,null,function*(){return{deviceOrientation:yield this.checkDeviceOrientation()}})}checkDeviceOrientation(){return f(this,null,function*(){var t;if(!pe)return!0;if(typeof window.DeviceOrientationEvent!="undefined"&&typeof((t=window.DeviceOrientationEvent)==null?void 0:t.requestPermission)=="function")try{var e;return(yield(e=window.DeviceOrientationEvent)==null?void 0:e.requestPermission())==="granted"}catch(i){return!1}return!1})}stop(){window.removeEventListener("devicemotion",this.handleAcceleration,!1),pe?window.removeEventListener("deviceorientation",this.deviceOrientationAbsHandler,!1):window.removeEventListener("deviceorientationabsolute",this.deviceOrientationAbsHandler,{absolute:!0}),(0,Ot.isNil)(this.gpsTimer)||navigator.geolocation.clearWatch(this.gpsTimer),this.dispatchTimer&&this.timer.clearInterval(this.dispatchTimer),this.data=[],this.dispatchEvent({type:"stop"})}constructor(t={}){super(),this.gpsTimer=null,this.data=[],this.timer=new j,this.dispatchTimer=null,this.addAcceleration=(0,Ot.throttle)(e=>{this.addDataItem(e)},20),this.deviceOrientationAbsHandler=(0,Ot.throttle)(e=>{let i=Date.now(),{alpha:s,beta:o,gamma:n}=e;if((0,Ot.isNil)(s)||(0,Ot.isNil)(o)||(0,Ot.isNil)(n))return;let r;pe?r=e.webkitCompassHeading:r=360-s,this.options.elements.includes(F.DEVICE_MOTION)&&this.addDataItem({type:F.DEVICE_MOTION,timestamp:i,res:[s,o,n]}),this.options.elements.includes(F.COMPASS)&&this.addDataItem({type:F.COMPASS,timestamp:i,res:r})},200),this.handleAcceleration=e=>{let i=e.accelerationIncludingGravity;(0,Ot.isNil)(i)||(0,Ot.isNil)(i.x)||(0,Ot.isNil)(i.y)||(0,Ot.isNil)(i.z)||this.addAcceleration({type:F.ACCELERATION,timestamp:Date.now(),res:[i.x,i.y,i.z]})},this.options=w({},Jh,t)}};var n_=require("core-js/modules/web.dom-collections.iterator.js");var QM=require("core-js/modules/es.array.push.js");var jM=require("core-js/modules/es.array.push.js"),VM=require("core-js/modules/web.dom-collections.iterator.js");function io(a,t){return 1/Math.sqrt(2*Math.PI*Math.pow(t,2))*Math.exp(-Math.pow(a,2)/(2*Math.pow(t,2)))}function ys(a){return(a+360)%360}function ya(a,t){let i=6378137*a*Math.PI/180,s=6378137*Math.log(Math.tan(Math.PI/4+t*Math.PI/180/2));return{x:i,y:s}}function gi(a,t,e,i){return Math.sqrt(Math.pow(Math.abs(a-e),2)+Math.pow(Math.abs(t-i),2))}var so=class{motionModelRotYaw(t){if(!(Math.abs(t)<.001)){this.last_yaw_compass=ys(this.last_yaw_compass+t);for(let e=0;e<this.NumParticle;e++){let i=Math.random()*this.yaw_noise_sigma;this.particleX[2][e]=this.particleX[2][e]+t+i,this.particleX[2][e]=ys(this.particleX[2][e])}}}motionModelStepLength(t,e){if(t===0)return;for(let s=0;s<this.NumParticle;s++){let o=Math.random()*this.step_noise_sigma;this.particleX[0][s]+=(.65+o)*Math.sin(-this.particleX[2][s]/180*Math.PI),this.particleX[1][s]+=(.65+o)*Math.cos(this.particleX[2][s]/180*Math.PI),e(this.particleX[0][s],this.particleX[1][s])||(this.particleWeight[0][s]*=this.unaccess_weight)}let i=this.particleWeight[0].reduce((s,o)=>s+o,0);this.particleWeight[0]=this.particleWeight[0].map(s=>s/i)}motionModelCompassYaw(t,e){if(e-this.last_compass_time>this.compass_update_interval){let i=360-t;i+=this.delta_yaw,i=ys(i),Math.abs(i-this.last_yaw_compass)>60?this.compass_consecutive_offset_count++:this.compass_consecutive_offset_count=0;for(let o=0;o<this.NumParticle;o++){let n=Math.abs(this.particleX[2][o]-i);n>180&&(n=360-n),this.particleWeight[0][o]*=io(n,this.sigmaCompass)}let s=this.particleWeight[0].reduce((o,n)=>o+n,0);this.particleWeight[0]=this.particleWeight[0].map(o=>o/s),this.setLastCompassTime(e)}}resampling(){if(1/this.particleWeight[0].reduce((e,i)=>e+i*i,0)<this.reSampNumParticle){let e=this.particleWeight[0].reduce((r,h,c)=>r.concat(r[c]+h),[0]),s=this.particleWeight[0].map(()=>1/this.NumParticle).map((r,h)=>r+Math.random()/this.NumParticle),o=[],n=0;for(let r=0;r<this.NumParticle;r++){for(;s[r]>e[n];)n++;o.push(n)}this.particleX=this.particleX.map((r,h)=>o.map(c=>r[c])),this.particleWeight[0]=Array(this.NumParticle).fill(1/this.NumParticle)}}update(t,e){for(let s=0;s<this.NumParticle;s++){let o=gi(this.particleX[0][s],this.particleX[1][s],t.x,t.y);this.particleWeight[0][s]=Math.max(1e-7,this.particleWeight[0][s]*io(o,e))}let i=this.particleWeight[0].reduce((s,o)=>s+o,0);this.particleWeight[0]=this.particleWeight[0].map(s=>s/i)}updateCar(t,e){let i=t.x-this.xEst[0][0],s=t.y-this.xEst[1][0];for(let n=0;n<this.NumParticle;n++){let r=gi(this.particleX[0][n],this.particleX[1][n],t.x,t.y);this.particleWeight[0][n]=Math.max(1e-7,this.particleWeight[0][n]*io(r,e)),this.particleX[0][n]+=i,this.particleX[1][n]+=s}let o=this.particleWeight[0].reduce((n,r)=>n+r,0);this.particleWeight[0]=this.particleWeight[0].map(n=>n/o)}getPosInitFlag(){return this.particle_PosInitFlag}getYawInitFlag(){return this.particle_yawInitFlag}setPosInitFlag(t){this.particle_PosInitFlag=t}setYawInitFlag(t){this.particle_yawInitFlag=t}getResultX(){let t=[0,0,0];for(let e=0;e<3;e++)for(let i=0;i<this.NumParticle;i++)t[e]+=this.particleX[e][i]*this.particleWeight[0][i];return this.xEst=t.map(e=>[e]),this.xEst[0][0]}getResultY(){return this.xEst[1][0]}getResultYaw(){let t=this.particleWeight[0].indexOf(Math.max(...this.particleWeight[0]));return this.particleX[2][t]}getEstConfidence(){let t=this.particleWeight[0].indexOf(Math.max(...this.particleWeight[0])),e=this.particleWeight[0].indexOf(Math.min(...this.particleWeight[0])),i=[this.particleX[0][t],this.particleX[1][t]],s=[this.particleX[0][e],this.particleX[1][e]],o=gi(i[0],i[1],s[0],s[1]),n=o*.67;return console.log(o,n),n}getParticleNum(){return this.NumParticle}getParticleX(){return this.particleX}setLastCompassTime(t){this.last_compass_time=t}getLastCompassTime(){return this.last_compass_time}initParticlesByPos(t,e,i){if(!this.particle_PosInitFlag){this.particleWeight[0]=Array(this.NumParticle).fill(1/this.NumParticle);let s=0;for(;s<this.NumParticle;){let n=(2*Math.random()-1)*this.initial_xy_uncertainty,r=(2*Math.random()-1)*this.initial_xy_uncertainty;i(t+n,e+r)||(this.particleWeight[0][s]*=this.unaccess_weight),this.particleX[0][s]=t+n,this.particleX[1][s]=e+r,s++}let o=this.particleWeight[0].reduce((n,r)=>n+r,0);this.particleWeight[0]=this.particleWeight[0].map(n=>n/o),this.particle_PosInitFlag=!0,this.xEst[0][0]=t,this.xEst[1][0]=e,this.xEst[2][0]=0}}initParticlesByCompass(t){console.log("Init compass: "+t);let e=360-t;e+=this.delta_yaw,e=ys(e),console.log("Init Yaw: "+e);for(let i=0;i<this.NumParticle;i++){let s=(2*Math.random()-1)*this.initial_yaw_uncertainty;this.particleX[2][i]=e+s}this.particle_yawInitFlag=!0,this.xEst[2][0]=e,this.last_yaw_compass=e,this.compass_consecutive_offset_count=0}constructor(t){this.last_yaw_compass=0,this.compass_consecutive_offset_count=0,this.NumParticle=t.NumParticle,this.reSampNumParticle=t.reSampNumParticle,this.initial_xy_uncertainty=t.initial_xy_uncertainty,this.initial_yaw_uncertainty=t.initial_yaw_uncertainty,this.step_noise_sigma=t.step_noise_sigma,this.yaw_noise_sigma=t.yaw_noise_sigma,this.compass_update_interval=t.compass_update_interval,this.sigmaCompass=t.sigmaCompass,this.delta_yaw=t.delta_yaw,this.sigmaBeacon=t.sigmaBeacon,this.unaccess_weight=t.unaccess_weight,this.particle_PosInitFlag=!1,this.particle_yawInitFlag=!1,this.xEst=[[0],[0],[0]],this.particleX=Array.from({length:3},()=>Array(this.NumParticle).fill(0)),this.particleWeight=Array.from({length:1},()=>Array(this.NumParticle).fill(1/this.NumParticle)),this.last_compass_time=0}};var YM=require("core-js/modules/es.array.push.js"),qM=require("core-js/modules/web.dom-collections.iterator.js");var oo=class{init(){this.fre=100,this.accH_fifo=[],this.accH_time_fifo=[],this.accH_fifo_len=Math.floor(1*this.fre)+1,this.step_count=0,this.state_count=0,this.last_valley_time=0,this.last_peak_time=0,this.last_step_time=0,this.min_step_time=.3,this.max_step_time=1,this.min_peak=10+.5,this.max_valley=10-.5,this.peak_num=0,this.valley_num=0,this.fft_min_amp=.3,this.fft_min_fre=0,this.fft_max_fre=4,this.last_fft_amp=0,this.abnor_start_time=0,this.abnor_fft_detected=!1,this.abnor_peak_time=0,this.abnor_peak_accH=0,this.const_step_length=.65,this.last_rot=[0,0,0],this.delta_rot=[0,0,0],this.last_yaw=0,this.delta_yaw=null,this.delta_rot_sum_fifo=[],this.delta_rot_sum_time_fifo=[],this.delta_yaw_accum=0,this.delta_yaw_accum_timestamp=0,this.delta_yaw_time_threshold=.5,this.last_px=0,this.last_py=0,this.delta_px=0,this.delta_py=0,this.is_moving=!1,this.currentMotionState="UNKNOWN",this.previousMotionState="UNKNOWN",this.acc_variance_buffer=[],this.rot_variance_buffer=[],this.acc_buffer=[],this.walkingCount=0,this.stationaryCount=0,this.phoneUseCount=0,this.stateCounter=0}reset(){this.init()}setInitPose(t){t===void 0&&(t=[0,0]),this.last_px=t[0],this.last_py=t[1],console.info("pdr init pos: "+this.last_px+", "+this.last_py)}setInitYaw(t){t===void 0&&(t=0),this.last_yaw=t}getPos(t,e,i){let s=0;return i.length===3&&(this.delta_yaw=this.getDeltaYawFromRot(t,i)),e.length===3&&(s=this.getStepLength(t,e)),s!==0&&(this.last_px+=this.delta_px,this.last_py+=this.delta_py),[this.last_px,this.last_py]}getDeltaPose(){return[this.delta_px,this.delta_py]}getMotionState(){return this.currentMotionState}getStepLength(t,e){if(e.length<3)return console.warn("acc data less than 3"),0;let i=!1,s=Math.sqrt(Math.pow(e[0],2)+Math.pow(e[1],2)+Math.pow(e[2],2));if(this.accH_fifo.push(s),this.accH_time_fifo.push(t),this.imuFreUpdate(),!this.isMoving(e,this.last_rot))return 0;if(this.accH_fifo.length<this.accH_fifo_len+1)i=!1;else{for(;this.accH_fifo.length>=this.accH_fifo_len+1;)this.accH_fifo.shift(),this.accH_time_fifo.shift();let n=this.PVStepDetec(),r=this.FFTStepDetec(),h=this.recheckState(),c=this.accH_time_fifo[Math.floor(this.accH_time_fifo.length*3/4)];Math.abs(this.abnor_start_time)<.001&&this.abnor_fft_detected?this.abnor_start_time=c:this.abnor_fft_detected||(this.abnor_start_time=0),n&&r&&h?(this.step_count+=1,this.last_step_time=c,i=!0):Math.abs(this.abnor_start_time)>.001&&this.abnor_peak_time-this.abnor_start_time>this.abnor_time_threshold&&this.step_count>1&&this.abnor_peak_time-this.last_step_time>1?(this.step_count+=1,this.last_step_time=c,i=!0):(c-this.last_step_time>2&&(this.state_count=0),i=!1)}if(i){let n=this.last_yaw/180*Math.PI;return this.delta_px=this.const_step_length*Math.cos(n),this.delta_py=this.const_step_length*Math.sin(n),this.const_step_length}else return 0}imuFreUpdate(){if(this.accH_time_fifo.length>2&&(this.accH_time_fifo[this.accH_time_fifo.length-1]-this.accH_time_fifo[this.accH_time_fifo.length-2]<0||this.accH_time_fifo[this.accH_time_fifo.length-1]-this.accH_time_fifo[this.accH_time_fifo.length-2]>10||this.accH_time_fifo[this.accH_time_fifo.length-1]===this.accH_time_fifo[0])&&(console.warn("pdr reset last one time "+this.accH_time_fifo[this.accH_time_fifo.length-1]+" last two time "+this.accH_time_fifo[this.accH_time_fifo.length-2]),this.reset()),this.accH_fifo.length>9||this.fre<15){let t=(this.accH_fifo.length-1)/(this.accH_time_fifo[this.accH_time_fifo.length-1]-this.accH_time_fifo[0]);Math.abs(this.fre-t)>8&&(this.fre=Math.round((t-3)/10)*10,(this.fre<=10||this.fre>=100)&&(console.warn("Frequency Error "+this.fre),this.fre=100),console.debug("Frequency change to "+this.fre),this.accH_fifo_len=Math.floor(1*this.fre)+1)}}recheckState(){return!0}PVStepDetec(){let t=!1,e=this.accH_fifo.slice(Math.floor(this.accH_fifo_len/2)),i=this.accH_time_fifo.slice(Math.floor(this.accH_fifo_len/2)),s=e[Math.floor(e.length/2)],o=i[Math.floor(i.length/2)],n=Math.max(...e),r=Math.min(...e),h=!1,c=!1;return Math.abs(s-r)<.01&&s<this.max_valley&&this.valley_num<=this.peak_num&&(this.last_valley_time===0?c=!0:c=o-this.last_valley_time>this.min_step_time,c&&(this.last_valley_time=o,this.valley_num+=1)),Math.abs(s-n)<.01&&s>this.min_peak&&this.peak_num<=this.valley_num&&(this.last_peak_time===0?h=!0:h=o-this.last_peak_time>this.min_step_time,h&&(this.last_peak_time=o,this.peak_num+=1)),s===n&&s>this.min_peak&&(this.abnor_peak_time=o,this.abnor_peak_accH=s),this.peak_num===this.valley_num&&(h||c)&&(t=!0),t}FFTStepDetec(){return!0}isMoving(t,e){if(t.length<3||e.length<3)return!1;this.acc_buffer.push([...t]),this.acc_buffer.length>this.static_window_size&&this.acc_buffer.shift();let i=Math.sqrt(Math.pow(t[0],2)+Math.pow(t[1],2)+Math.pow(t[2],2));this.acc_variance_buffer.push(i),this.acc_variance_buffer.length>this.static_window_size&&this.acc_variance_buffer.shift();let s=Math.abs(e[0])+Math.abs(e[1])+Math.abs(e[2]);if(this.rot_variance_buffer.push(s),this.rot_variance_buffer.length>this.static_window_size&&this.rot_variance_buffer.shift(),this.acc_variance_buffer.length<10)return this.is_moving;let o=this.acc_variance_buffer.slice(-10),n=this.rot_variance_buffer.slice(-10),r=this.calculateMean(o),h=this.calculateStdDeviation(o),c=this.calculateMean(n),l=this.calculateStdDeviation(n),p;return r>this.walkingThreshold&&h>.5?(this.walkingCount++,this.stationaryCount=0,this.phoneUseCount=0,p="WALKING"):r<this.phoneUseThreshold&&c>this.rotationThreshold?(this.phoneUseCount++,this.walkingCount=0,this.stationaryCount=0,p="USING_PHONE"):c<.5?(this.stationaryCount++,this.walkingCount=0,this.phoneUseCount=0,p="STATIONARY"):p="UNKNOWN",p!==this.currentMotionState?(this.stateCounter++,this.stateCounter>=this.stateChangeThreshold&&(this.previousMotionState=this.currentMotionState,this.currentMotionState=p,this.stateCounter=0,console.debug("Motion state changed: "+this.previousMotionState+" -> "+this.currentMotionState),console.debug("Stats: avgAcc="+r.toFixed(2)+", accStdDev="+h.toFixed(2)+", avgRot="+c.toFixed(2)+", rotStdDev="+l.toFixed(2)))):this.stateCounter=0,this.is_moving=this.currentMotionState==="WALKING",this.is_moving}calculateMean(t){return t.length===0?0:t.reduce((e,i)=>e+i,0)/t.length}calculateStdDeviation(t){if(t.length<2)return 0;let e=this.calculateMean(t),s=t.map(o=>{let n=o-e;return n*n}).reduce((o,n)=>o+n,0)/t.length;return Math.sqrt(s)}getMotionStatistics(){let t=this.acc_variance_buffer.slice(-10),e=this.rot_variance_buffer.slice(-10),i=this.calculateMean(t),s=this.calculateMean(e),o=this.calculateStdDeviation(t),n=this.calculateStdDeviation(e);return console.debug("\u8FD0\u52A8\u68C0\u6D4B: avgAcc="+i.toFixed(2)+", accStdDev="+o.toFixed(2)+", avgRot="+s.toFixed(2)+", rotStdDev="+n.toFixed(2)),console.debug("\u72B6\u6001\u5224\u65AD\u6761\u4EF6: \u884C\u8D70(avgAcc>"+this.walkingThreshold+", accStdDev>0.5), \u9759\u6B62(avgRot<0.5), \u624B\u673A(avgAcc<"+this.phoneUseThreshold+", avgRot>"+this.rotationThreshold+")"),console.debug("\u5F53\u524D\u72B6\u6001: "+this.currentMotionState+", \u8BA1\u6570: \u884C\u8D70="+this.walkingCount+", \u9759\u6B62="+this.stationaryCount+", \u624B\u673A="+this.phoneUseCount),{currentState:this.currentMotionState,avgAcceleration:i,avgRotation:s,accStdDeviation:o,rotStdDeviation:n,walkingCount:this.walkingCount,stationaryCount:this.stationaryCount,phoneUseCount:this.phoneUseCount,dataPoints:this.acc_variance_buffer.length,isMoving:this.is_moving}}getDeltaYawFromRot(t,e){if(e.length<3)return console.warn("rot data less than 3"),0;let i=[0,0,0];this.last_rot.length===3&&(i=e.map((r,h)=>r-this.last_rot[h]));for(let r=0;r<e.length;r++)i[r]<-180?i[r]+=360:i[r]>180&&(i[r]-=360);let s=.2;this.delta_rot.length===3?this.delta_rot=this.delta_rot.map((r,h)=>s*r+(1-s)*i[h]):this.delta_rot=i,this.last_rot=e,this.delta_yaw=this.delta_rot[0],this.last_yaw+=this.delta_yaw,this.last_yaw=this.limitYaw(this.last_yaw);let o=this.delta_rot.reduce((r,h)=>r+Math.abs(h),0);this.delta_rot_sum_fifo.push(o),this.delta_rot_sum_time_fifo.push(t),Math.abs(this.delta_rot_sum_time_fifo[this.delta_rot_sum_time_fifo.length-1]-this.delta_rot_sum_time_fifo[0])>1&&(this.delta_rot_sum_fifo.shift(),this.delta_rot_sum_time_fifo.shift()),this.delta_yaw_accum+=this.delta_yaw;let n=0;return Math.abs(this.delta_yaw_accum_timestamp-t)>this.delta_yaw_time_threshold?(n=this.delta_yaw_accum,this.delta_yaw_accum=0,this.delta_yaw_accum_timestamp=t,n):null}limitYaw(t){for(;t<-180;)t+=360;for(;t>180;)t-=360;return t}constructor(){this.fre=100,this.accH_fifo=[],this.accH_time_fifo=[],this.accH_fifo_len=Math.floor(1*this.fre)+1,this.step_count=0,this.state_count=0,this.last_valley_time=0,this.last_peak_time=0,this.last_step_time=0,this.min_step_time=.3,this.max_step_time=1,this.min_peak=10.5,this.max_valley=9.5,this.peak_num=0,this.valley_num=0,this.fft_min_amp=.3,this.fft_min_fre=0,this.fft_max_fre=4,this.last_fft_amp=0,this.abnor_start_time=0,this.abnor_fft_detected=!1,this.abnor_time_threshold=4,this.abnor_peak_time=0,this.abnor_peak_accH=0,this.const_step_length=.85,this.last_rot=[],this.delta_rot=[],this.last_yaw=0,this.delta_yaw=null,this.delta_rot_sum_fifo=[],this.delta_rot_sum_time_fifo=[],this.delta_yaw_accum=0,this.delta_yaw_accum_timestamp=0,this.delta_yaw_time_threshold=.5,this.last_px=0,this.last_py=0,this.delta_px=0,this.delta_py=0,this.is_moving=!1,this.currentMotionState="UNKNOWN",this.previousMotionState="UNKNOWN",this.walkingThreshold=1,this.stationaryThreshold=.6,this.phoneUseThreshold=.7,this.rotationThreshold=.8,this.walkingCount=0,this.stationaryCount=0,this.phoneUseCount=0,this.stateCounter=0,this.stateChangeThreshold=3,this.static_window_size=20,this.acc_variance_buffer=[],this.rot_variance_buffer=[],this.acc_buffer=[]}};var Qh={using_gps:!0,gps_max_horizontalAccuracy:20,initial_gps_delay_time:3e3},no=class{pfFusionPDRiBeacon(t){let{type:e,timestamp:i,res:s}=t,o=!1;if(this.cacheSensorData.push(t),this.particleFilter.getPosInitFlag()&&this.particleFilter.getYawInitFlag()){if(e===F.ACCELERATION){let n=s,r=this.pdr.getStepLength(i/1e3,n);r!==0&&(this.particleFilter.motionModelStepLength(r,()=>!0),this.particleFilter.resampling(),this.position_count+=1,o=!0)}if(this.using_gps&&e===F.GPS)if(this.last_beacon_time===null||i-this.last_beacon_time>5e3){let n=this.getGpsPosition(s);o=n!==null,n&&(this.particleFilter.update(n,this.gps_horizontalAccuracy),this.resetParticleFilterDist(n,"gps",s[2]),this.particleFilter.resampling(),this.position_count+=1,this.cacheSensorData.length=0)}else return[!1,0,0];if(e===F.DEVICE_MOTION){let n=this.pdr.getDeltaYawFromRot(i/1e3,s);n!==null&&this.particleFilter.motionModelRotYaw(n)}e===F.COMPASS&&this.particleFilter.motionModelCompassYaw(s,i),this.last_pos_time&&i-this.last_pos_time>500&&(this.position_count+=1,o=!0)}else if(!this.particleFilter.getPosInitFlag()&&this.using_gps&&e===F.GPS)if(this.startTime&&Date.now()-this.startTime>this.options.initial_gps_delay_time){let n=this.getGpsPosition(s);o=n!==null,console.log("gps_pos",n,s),n?(this.particleFilter.initParticlesByPos(n.x,n.y,()=>!0),this.last_pos_time=i,console.log("init Pos by gps success time "+i),this.cacheSensorData.length=0):console.log("init Pos by gps fail time "+i)}else this.startTime||(this.startTime=i);else if(!this.particleFilter.getYawInitFlag()&&e===F.COMPASS){let n=s;this.particleFilter.initParticlesByCompass(n),this.particleFilter.setLastCompassTime(i),console.log("init yaw by compass success time "+i)}return o&&(this.last_pos_time=i),[o,this.particleFilter.getResultX(),this.particleFilter.getResultY()]}setBeaconPosition(t,e){if(this.last_beacon_time=e,this.particleFilter.getPosInitFlag())this.particleFilter.update(t,this.sigmaBeacon);else{this.particleFilter.initParticlesByPos(t.x,t.y,()=>!0);let i=this.cacheSensorData.filter(s=>s.timestamp>e);console.log("\u521D\u59CBsensorData",i),i.map(s=>this.pfFusionPDRiBeacon(s))}return this.resetParticleFilterDist(t),this.particleFilter.resampling(),this.position_count+=1,this.cacheSensorData.length=0,[this.particleFilter.getResultX(),this.particleFilter.getResultY()]}getGpsPosition(t){return t[2]>this.gps_max_horizontalAccuracy?null:ya(t[0],t[1])}resetParticleFilterDist(t,e,i){let s=this.particleFilter.getResultX(),o=this.particleFilter.getResultY(),n=gi(s,o,t.x,t.y);(e==="gps"?i&&n>i||n>this.GpsMaxEstimateErr:n>this.MaxEstimateErr)?(this.outTrustRegionNum+=1,this.outTrustRegionNum>=this.TrustNum&&(console.info("\u8D85\u51FA\u53EF\u4FE1\u533A\u57DF\uFF0C\u91CD\u7F6E\u7C92\u5B50\u8FC7\u6EE4\u5668\u5230: "+t.x+", "+t.y),this.particleFilter.setPosInitFlag(!1),this.particleFilter.setYawInitFlag(!1),this.outTrustRegionNum=0,this.startTime=Date.now())):this.outTrustRegionNum=0}constructor(t){this.sigmaBeacon=5,this.gps_horizontalAccuracy=10,this.using_gps=!0,this.last_beacon_time=Date.now(),this.position_count=0,this.gps_max_horizontalAccuracy=20,this.MaxEstimateErr=5,this.GpsMaxEstimateErr=30,this.outTrustRegionNum=0,this.TrustNum=4,this.cacheSensorData=[],this.startTime=null;let e=w({},Qh,t);this.options=e,this.using_gps=e.using_gps,this.gps_max_horizontalAccuracy=e.gps_max_horizontalAccuracy,this.particleFilter=new so({NumParticle:200,reSampNumParticle:.65,initial_xy_uncertainty:12,initial_yaw_uncertainty:100,step_noise_sigma:.5,yaw_noise_sigma:2,compass_update_interval:3e3,sigmaCompass:80,delta_yaw:2,sigmaBeacon:5,unaccess_weight:.7}),this.pdr=new oo}};var ro=require("@turf/turf"),vs=class extends st{checkSensor(){return this.sensor.checkSensor()}setSensor(t){this.sensor=t}start(){this.sensor.start(),this.pdr.startTime=Date.now(),this.sensor.addEventListener("add-data-item",t=>{let{item:e}=t;this.getPositionBySensorItem(e,!this._pause)})}pause(){this._pause=!0}continue(){this._pause=!1}getPositionBySensorItem(t,e){e===void 0&&(e=!0);let[i,s,o]=this.pdr.pfFusionPDRiBeacon(t);return i&&e&&(0,ro.booleanPointInPolygon)((0,ro.point)([s,o]),this.bmap.context.range)&&this.dispatchEvent({type:"position",x:s,y:o,_type:t.type===F.GPS?"gps":"pdr"}),[i,s,o]}setBeaconPosition(t,e){let[i,s]=this.pdr.setBeaconPosition(t,e);this.dispatchEvent({type:"position",x:i,y:s,_type:"beacon"})}dispose(){this.sensor.stop()}constructor(t,e={}){super(),this.bmap=t,this._pause=!1,this.sensor=new gs(e.sensor),this.pdr=new no(e.pdr||{})}};var E_=require("core-js/modules/web.dom-collections.iterator.js"),L_=require("core-js/modules/es.array.push.js");var d_=require("core-js/modules/web.dom-collections.iterator.js"),u_=require("core-js/modules/es.array.push.js"),m_=require("core-js/modules/es.array.flat.js"),f_=require("core-js/modules/es.array.unscopables.flat.js"),ft=require("three");var mt=require("three");mt.UniformsLib["custom-line"]={linewidth:{value:1},resolution:{value:new mt.Vector2(1,1)},dashScale:{value:1},dashSize:{value:1},gapSize:{value:1},repeat:{value:new mt.Vector2(1,1)},allDistance:{value:1}};mt.ShaderLib["custom-line"]={uniforms:mt.UniformsUtils.merge([mt.UniformsLib.common,mt.UniformsLib.fog,mt.UniformsLib["custom-line"]]),vertexShader:`
508
+ `,document.body.appendChild(a.canvas)}setAngle(t){if(console.log("angle",t),a.textureMap.has(t))this._initIcon(a.textureMap.get(t));else{this.draw(t);let e=this.getTexture(this.getImageData());a.textureMap.set(t,e),this._initIcon(e),this._initScale({zoom:this.bmap.context.camera.zoom})}}_initIcon(t){if(this.spriteIcon)this.spriteIcon.material.map=t,t.needsUpdate=!0;else{let e=new Jt.Sprite(new Jt.SpriteMaterial({map:t,transparent:!0,alphaTest:.2,depthTest:this.options.depth_test,rotation:this.options.icon_rotate/180*Math.PI}));e.renderOrder=1e5+this.options.level,t.needsUpdate=!0,this.add(e),e.center.set(.5,.5),this.spriteIcon=e}}initSize(){this.spriteIcon&&this.spriteIcon.center.set(.5,.5)}draw(t){let{ctx:e}=a,{config:{size:i}}=this,s=i[0]/2,o=i[1]/2,n=4,r=1,h=n+r;if(e.clearRect(0,0,i[0],i[1]),e.setLineDash([10,10]),e.strokeStyle="#fff",e.lineWidth=2,e.beginPath(),e.arc(s,o,o-h,-Math.PI/2,Math.PI*2-Math.PI/2,t<Math.PI),e.stroke(),e.strokeStyle="#0A7AFF",t<Math.PI){let c=-Math.PI/2,l=c-t;e.beginPath(),e.arc(s,o,o-h,c,l,!0)}else{let c=-Math.PI/2,l=c+Math.PI*2-t;e.beginPath(),e.arc(s,o,o-h,c,l,!1)}e.stroke(),e.clearRect(s-h*2,0,h*4,h*4),e.beginPath(),e.arc(s,h,n,0,Math.PI*2),e.fillStyle="#0A7AFF",e.fill(),e.setLineDash([10,0]),e.strokeStyle="#fff",e.lineWidth=r,e.stroke(),e.clearRect(0,o-5,10,10),e.clearRect(s-5,i[1]-10,10,10),e.clearRect(i[0]-10,o-5,10,10),t>Math.PI/2&&t<Math.PI?e.fillStyle="#0A7AFF":e.fillStyle="#fff",e.fillRect(0,o-1,10,2),e.fillStyle="#fff",e.fillRect(s-1,i[1]-10,2,10),t>Math.PI&&t<Math.PI/2*3?e.fillStyle="#0A7AFF":e.fillStyle="#fff",e.fillRect(i[0]-10,o-1,10,2)}getImageData(){let{ctx:t}=a,{config:{size:e}}=this;return t.getImageData(0,0,e[0],e[1])}getTexture(t){let{config:{size:e}}=this,i=new Jt.DataTexture(Uint8Array.from(t.data),e[0],e[1],Jt.RGBAFormat);return i.format=Jt.RGBAFormat,i.magFilter=Jt.LinearFilter,i.minFilter=Jt.LinearFilter,i.colorSpace="srgb",i.flipY=!0,i}dispose(){var t;super.dispose(),(t=this.spriteIcon)==null||t.material.dispose()}static dispose(){this.textureMap.forEach(t=>{t.dispose()}),this.textureMap.clear(),this.ctx=null,this.canvas=null}constructor(t,e){super(t.context,{icon_size:e.size,collision_enable:!1,level:2}),this.bmap=t,this.config=e,a.canvas.width=e.size[0],a.canvas.height=e.size[1]}};Se.canvas=document.createElement("canvas");Se.ctx=Se.canvas.getContext("2d",{willReadFrequently:!0});Se.textureMap=new Map;var Xh={path:{},cheapMaximumDistance:20,needStartPoi:!1,startPoi:{},positionNavigation:{},offsetY:150,directionEmitThreshold:5,disablePathAnimation:!1,disablePathRotate:!1,disablePathShorten:!1,speed:1,roadData:[],runAnimationMaxTime:1,navigationCameraBasic:45,canBack:!1},pn=class extends X{get curFloorPathLength(){var t,e;return(e=(t=this.curFloorPath)==null?void 0:t.distance)!=null?e:0}get curFloorPathPoints(){var t,e;return(e=(t=this.curFloorPath)==null?void 0:t.points)!=null?e:[]}registryEvent(){this.bmap.context.addEventListener("update",this.onUpdate),this.bmap.addEventListener(yt.SWITCH_FLOOR_GROUND,this.onSwitchFloor),this.positionNavigation.addEventListener("navigation-info",this.onNavigationInfo),this.bmap.context.addEventListener("control-change",this.onControlChangeForStartPoi)}setRoadData(t){this.options.roadData=t,this.positionNavigation.setRoadData(t)}showStartRotateHelperPoi(){var t;if(this.needStartRotateHelperPoi=!0,!this.startPoi||this.startRotateHelperPoi)return;let e=this.startPoi.options.icon_size;this.startRotateHelperPoi=new Se(this.bmap,{size:[e[0]+20,e[1]+20]}),this.startRotateHelperPoi.setAngle(0),this.startRotateHelperPoi.position.setZ(.51),(t=this.bmap.context.currentFloor)==null||t.poiLayer2.pushPoi(this.startRotateHelperPoi)}hideStartRotateHelperPoi(){if(this.needStartRotateHelperPoi=!1,this.startRotateHelperPoi){var t;(t=this.bmap.context.currentFloor)==null||t.poiLayer2.removePoi(this.startRotateHelperPoi),this.startRotateHelperPoi=null}}setStartPoiPosition(t,e){this.startPoi&&(this.startPoi.position.setX(t).setY(e),this.startRotateHelperPoi&&this.startRotateHelperPoi.position.setX(t).setY(e),this.detachLine&&this.detachLine.setPosition(this.startPoi.position,this.detachStartPoi.position))}resetStatus(){this.pauseAnimation(),this.positionNavigation.resetStatus(this.paths),this.movedDistance=0,this.startPoi&&this.translatePath&&this.setStartPoiPosition(this.translatePath[0][0],this.translatePath[0][1])}toPositionByTask(t){var e;let s=(e=this.taskQueue.getTasks().find(n=>n.meta.type==="toPosition"))==null?void 0:e.tid,o={run:()=>this.toPositionBySpeed(t,this.options.speed),meta:{type:"toPosition"}};s?this.taskQueue.replace(s,o):this.taskQueue.add(o)}pauseAnimation(){this.taskQueue.clear(),this.positionNavigation.pause(),this.tweenUtil.pause()}continueAnimation(){this.tweenUtil.continue(),this.positionNavigation.continue()}clearTween(){this.tweenUtil.clear(),this.taskQueue.clear(),this.bmap.context.control.enabled=!0}unRegistryEvent(){this.bmap.context.removeEventListener("update",this.onUpdate),this.bmap.removeEventListener(yt.SWITCH_FLOOR_GROUND,this.onSwitchFloor),this.positionNavigation.removeEventListener("navigation-info",this.onNavigationInfo),this.bmap.context.removeEventListener("control-change",this.onControlChangeForStartPoi)}clearPath(){if(this.resetStatus(),this.path&&(this.bmap.context.scene.remove(this.path),this.path.dispose(),this.path=null,this.clearTween()),this.startPoi){var t;if((t=this.bmap.context.currentFloor)==null||t.poiLayer2.removePoi(this.startPoi),this.startPoi=null,this.startRotateHelperPoi){var e;(e=this.bmap.context.currentFloor)==null||e.poiLayer2.removePoi(this.startRotateHelperPoi),this.startRotateHelperPoi=null}}if(this.detachStartPoi){var i;(i=this.bmap.context.currentFloor)==null||i.removePoi2(this.detachStartPoi),this.detachStartPoi=null}this.detachLine&&(this.bmap.context.scene.remove(this.detachLine),this.detachLine.dispose(),this.detachLine=null),this.translatePath=null}setCurFloorPath(t){t===null?(this.curFloorPath=null,this.currentPathPosition=null,this.toPointPosition=null):(this.curFloorPath=t,this.currentPathPosition=t.points[0],this.toPointPosition=t.points[0]),this.movedDistance=0,this.clearTween()}setCurPathIndex(t){var e,i;this.curPathIndex=t,((e=this.paths[t])==null?void 0:e.floor)===((i=this.bmap.context.currentFloor)==null?void 0:i.name)?(this.setCurFloorPath(this.paths[t]),this.renderPath(this.translatePoints(this.curFloorPathPoints))):this.clearPath()}addPath(t,e){e===void 0&&(e=0);var i;this.paths=t,this.curPathIndex=e,this.clearTween(),this.clearPath();let s=(i=this.bmap.context.currentFloor)==null?void 0:i.name,o=t[e];if(s&&(o==null?void 0:o.floor)===s)if(this.setCurFloorPath(o),this.bmap.currentBuildGround)this.renderPath(this.translatePoints(o.points));else{let n=()=>{this.bmap.removeEventListener("center-change",n),this.renderPath(this.translatePoints(o.points))};this.bmap.addEventListener("center-change",n)}this.dispatchEvent({type:"add-path",paths:t})}translatePoints(t){let[e,i]=this.bmap.buildingCenter;return t.map(s=>[s[0]-e,s[1]-i])}renderPath(t){this.translatePath=t;let e=this.catmullRomCurve3(t);if(this.cPath=e,this.animationPathOptions={cPathIndex:0},this.pathStart=e[0],this.path?this.path.updatePoints(e):(this.path=new Qs(this,this.options.path),this.path.create(e),this.path.position.z=this.bmap.context.currentFloor.groundMaxHeight+.5,this.bmap.context.scene.add(this.path)),this.path.movePath(0),this.startPoi){var i;if((i=this.bmap.context.currentFloor)==null||i.poiLayer2.removePoi(this.startPoi),this.startPoi=null,this.startRotateHelperPoi){var s;(s=this.bmap.context.currentFloor)==null||s.poiLayer2.removePoi(this.startRotateHelperPoi),this.startRotateHelperPoi=null}}if(this.removeDetachStart(),this.showDetachStartState&&this.options.detachStartPoi){var o;this.detachStartPoi=new tt(this.bmap.context,w({},this.options.detachStartPoi,{id:"navigation_detach_start_poi",position:{x:e[0][0],y:e[0][1],z:.51},collision_enable:!1}))||null,(o=this.bmap.context.currentFloor)==null||o.poiLayer2.pushPoi(this.detachStartPoi),this.detachLine=new ai(this.bmap.context,new At.Vector3(e[0][0],e[0][1],.51),new At.Vector3(e[0][0],e[0][1],.51)),this.bmap.context.scene.add(this.detachLine)}if(this.options.needStartPoi){var n;this.startPoi=new tt(this.bmap.context,w({},this.options.startPoi,{id:"navigation_start_poi",position:{x:e[0][0],y:e[0][1],z:.51},collision_enable:!1}))||null,(n=this.bmap.context.currentFloor)==null||n.poiLayer2.pushPoi(this.startPoi),this.needStartRotateHelperPoi&&this.showStartRotateHelperPoi(),console.log(this.startRotateHelperPoi)}this.dispatchEvent({type:"render-path",path:this.path})}catmullRomCurve3(t){return Di(t,!1,!0,.1,170,2.5)}getPathDirection(){if(!this.curFloorPath||!this.currentPathPosition||this.curFloorPathPoints.length<2)return null;let t=ce(this.curFloorPathPoints,this.currentPathPosition),e=this.curFloorPathPoints[t],i=this.curFloorPathPoints[t+1],s=new At.Vector3(i[0]-e[0],i[1]-e[1],0).normalize(),o=new At.Vector3(0,1,0).normalize(),n=s.angleTo(o),r=new At.Vector3().crossVectors(o,s);return(Object.is(r.y,0)?-1:1)*n}getPathDirection2(){if(!this.curFloorPath||!this.toPointPosition||this.curFloorPathPoints.length<2)return null;let t=ce(this.curFloorPathPoints,this.toPointPosition),e=this.curFloorPathPoints[t],i=this.curFloorPathPoints[t+1];return(new At.Vector2(i[0]-e[0],i[1]-e[1]).normalize().angle()*180/Math.PI-90+360)%360}changeCameraToPathUp(t){return f(this,null,function*(){t===void 0&&(t=100);let e=this.getPathDirection();if(e===null)return;let i=this.bmap.context.control.getAzimuthalAngle();Math.abs(i-e)>Math.PI&&(i>0?e=Math.PI*2+e:e=e-Math.PI*2);let s=Math.abs(e-this.bmap.context.control.getAzimuthalAngle());if(s<.01)return;let{control:o}=this.bmap.context,n=t/Math.PI*6*s;return Ft(new Promise(r=>{let h={azimuthal:o.getAzimuthalAngle()},c={azimuthal:e},l=o.getPolarAngle(),{maxPolarAngle:p,minPolarAngle:d}=o;o.maxPolarAngle=l,o.minPolarAngle=l;let u=new fi.Tween(h,this.tweenUtil.group).to(c,n).easing(fi.Easing.Quadratic.InOut).onUpdate(()=>f(this,null,function*(){this.startPoi&&o.target.copy(this.startPoi.position),o.setAzimuthalAngle(h.azimuthal,!0),o.setTargetByOffset(this.options.offsetY)})).onComplete(()=>{o.enabled=!0,this.tweenUtil.remove(u),o.maxPolarAngle=p,o.minPolarAngle=d,r(!0)}).onStart(()=>{o.enabled=!1}).start()}),n+500).finally(()=>{this.bmap.context.control.enabled=!0})})}initNavigationCamera(t){return f(this,null,function*(){t===void 0&&(t=1e3);var e;let s=(e=this.taskQueue.getTasks().find(n=>n.meta.type==="initNavigationCamera"))==null?void 0:e.tid,o={run:()=>Ft(f(this,null,function*(){yield this.initCameraZoom(t/2),this.options.disablePathRotate||(yield this.changeCameraToPathUp(t/4)),yield this.translateCameraToStartPoi(t/(this.options.disablePathRotate?2:4))}),t+500).finally(()=>{this.bmap.context.control.enabled=!0}),meta:{type:"initNavigationCamera"}};s?this.taskQueue.replace(s,o):this.taskQueue.add(o)})}translateCameraToStartPoi(t){return f(this,null,function*(){if(t===void 0&&(t=100),!this.startPoi)return;let{clientSize:{width:e,height:i},camera:s,control:o}=this.bmap.context,n=Math.round(e/2),r=Math.round(i/2),h=o.target.clone(),c=D(this.startPoi.position,s,e,i),l=c.x-n,p=r-c.y+this.options.offsetY;if(!(Math.abs(l)<=1&&Math.abs(p)<=1)){if(Math.abs(l)>=1){let d=new At.Vector3;d.setFromMatrixColumn(s.matrix,0),d.normalize(),d.multiplyScalar(l/s.zoom),h.add(new At.Vector3(d.x,d.y,0))}if(Math.abs(p)>=1){let d=new At.Vector3;d.setFromMatrixColumn(s.matrix,1),d.normalize(),d.multiplyScalar(p/s.zoom),h.add(new At.Vector3(d.x,d.y,0))}return Ft(new Promise(d=>{let u=o.target.clone();console.log(u,h,t);let m=new fi.Tween(u,this.tweenUtil.group).to(h,t).onUpdate(()=>{this.bmap.context.control.setCameraPositionByTarget(u,0)}).onComplete(()=>{this.bmap.context.control.setCameraPositionByTarget(h,0),this.tweenUtil.remove(m),this.bmap.context.control.enabled=!0,d(!0)}).onStart(()=>{this.bmap.context.control.enabled=!1}).start()}),t+500).then(()=>{this.bmap.context.control.enabled=!0})}})}initCameraZoom(t){return f(this,null,function*(){if(t===void 0&&(t=100),!this.startPoi)return;let{clientSize:{width:e,height:i},currentFloor:s}=this.bmap.context,{max:o,min:n}=s.box,h=Math.min(e/(o.x-n.x),i/(o.y-n.y))*(o.x-n.x)/this.options.navigationCameraBasic;return this.bmap.context.setZoom(h,this.startPoi.position,t).finally(()=>{this.bmap.context.control.enabled=!0})})}toPosition(t,e){if(this.paths[this.curPathIndex]&&this.paths[this.curPathIndex].floor===t&&this.detachStartPoi){let i=this.translatePoints([e]);this.detachStartPoi.position.setX(i[0][0]),this.detachStartPoi.position.setY(i[0][1]),this.detachLine&&this.startPoi&&this.detachLine.setPosition(this.startPoi.position,this.detachStartPoi.position)}this.options.canBack&&(this.positionNavigation.pointIndex=0,this.positionNavigation.position=this.paths[this.curPathIndex].points[0]),this.positionNavigation.toPosition(t,e)}startSimulation(){this.positionNavigation.startSimulation()}setSimulationSpeed(t){this.positionNavigation.changeSimulationSpeed(t)}toPositionBySpeed(t,e){return f(this,null,function*(){let{currentPathPosition:i,curFloorPath:s,curFloorPathPoints:o}=this;if(!s||!i)return null;let n=this.movedDistance,r=Do(o,t);if(n===-1||r===-1||!this.options.canBack&&r<=n)return null;let h=r-n;if(!h)return;let c=Math.min(Math.abs(h)/e,this.options.runAnimationMaxTime);return this.pathTween&&this.clearTween(),Ft(new Promise(l=>{let p=this.pathTween=new fi.Tween({distance:0},this.tweenUtil.group).to({distance:h},c*1e3).onUpdate(d=>f(this,null,function*(){this.moveDistance(d.distance+n,p)})).onComplete(()=>{this.tweenUtil.remove(p),l(!0)}).start()}),c*1e3+500).finally(()=>{this.bmap.context.control.enabled=!0})})}moveDistance(t,e){return f(this,null,function*(){if(this.movedDistance=t,!this.options.disablePathShorten){var i;(i=this.path)==null||i.movePath(this.movedDistance/this.curFloorPathLength)}let s=Ze(this.curFloorPathPoints,this.movedDistance);if(s===null)return;this.currentPathPosition=s;let o=this.translatePoints([s])[0];this.startPoi&&(this.setStartPoiPosition(o[0],o[1]),this.options.disablePathAnimation||this.bmap.context.control.setTargetByOffset(this.options.offsetY,this.startPoi.position.clone())),!this.options.disablePathAnimation&&!this.options.disablePathRotate&&(e==null||e.pause(),yield this.changeCameraToPathUp(500/this.options.speed),e==null||e.resume())})}removeDetachStart(){if(this.detachLine&&(this.bmap.context.scene.remove(this.detachLine),this.detachLine.dispose(),this.detachLine=null),this.detachStartPoi){var t;(t=this.bmap.context.currentFloor)==null||t.poiLayer2.removePoi(this.detachStartPoi),this.detachStartPoi=null}}hideDetachStart(){this.showDetachStartState=!1,this.removeDetachStart()}showDetachStart(){if(!this.detachStartPoi&&(this.showDetachStartState=!0,this.path&&this.startPoi&&this.options.detachStartPoi)){var t;let e=this.startPoi.position;this.detachStartPoi=new tt(this.bmap.context,w({},this.options.detachStartPoi,{id:"navigation_detach_start_poi",position:e,collision_enable:!1}))||null,(t=this.bmap.context.currentFloor)==null||t.poiLayer2.pushPoi(this.detachStartPoi),this.detachLine=new ai(this.bmap.context,new At.Vector3(e.x,e.y,.51),new At.Vector3(e.x,e.y,.51)),this.bmap.context.scene.add(this.detachLine)}}setStartPoiRotate(t){this.startPoiRotate=t;let i=(this.bmap.context.control.getAzimuthalAngle()*180/Math.PI+360)%360,s=(360-t-i)%360;this.detachStartPoi&&(this.detachStartPoi.options.icon_rotate=s),this.startPoi&&(this.startPoi.options.icon_rotate=s,this.startRotateHelperPoi&&this.startRotateHelperPoi.setAngle(s))}dispose(){var t;if(this.path&&(this.bmap.context.scene.remove(this.path),this.path.dispose()),this.hideDetachStart(),this.startPoi){var e;(e=this.bmap.context.currentFloor)==null||e.poiLayer2.removePoi(this.startPoi),this.startPoi=null}this.tweenUtil.dispose(),this.unRegistryEvent(),(t=this.startRotateHelperPoi)==null||t.dispose(),Se.dispose(),this.positionNavigation.dispose(),this.startRotateHelperPoi=null,super.dispose()}constructor(t,e={},i){super(t),this.path=null,this.fetchRoadStatus=!1,this.paths=[],this.curPathIndex=0,this.curFloorPath=null,this.translatePath=null,this.currentPathPosition=null,this.toPointPosition=null,this.pathTween=null,this.startPoi=null,this.detachStartPoi=null,this.detachLine=null,this.startPoiRotate=null,this.startRotateHelperPoi=null,this.needStartRotateHelperPoi=!1,this.showDetachStartState=!0,this.movedDistance=0,this.pathStart=[0,0],this.tweenUtil=new Pe,this.taskQueue=new Ve,this.animationPathOptions={cPathIndex:0},this.cPath=[],this.onNavigationInfo=s=>{let{info:o}=s;if(this.dispatchEvent({type:"navigation-info",info:o}),!o.offset){if(o.routeIndex!==this.curPathIndex)return;this.toPointPosition=o.pos,this.toPositionByTask(o.pos)}},this.onUpdate=()=>{this.tweenUtil.update()},this.onSwitchFloor=s=>{let{data:{curFloor:o}}=s;if(this.clearTween(),this.paths[this.curPathIndex]){let n=this.paths[this.curPathIndex];this.setCurFloorPath(n!=null?n:null),n?this.renderPath(this.translatePoints(n.points)):this.clearPath()}else this.clearPath()},this.onControlChangeForStartPoi=()=>{this.startPoi&&this.startPoiRotate!==null&&this.setStartPoiRotate(this.startPoiRotate)},!i&&typeof e=="object"&&(i=e),this.options=Object.assign({},Xh,i),this.positionNavigation=new to(this,w({simulationSpeed:this.options.speed},this.options.positionNavigation),this.options.roadData),this.registryEvent()}};var rM=require("core-js/modules/web.dom-collections.iterator.js");var ms=require("three"),dn=class extends X{show(t,e){let i=0;t.forEach(n=>{n.onAddToScene("mulFloors"),n.position.z=i,i+=n.userData.height,n.poiLayer2.pois.forEach(r=>{r.options.depth_test=!0})});let{scene:s,currentFloor:o}=this.bmap.context;s.background=new ms.Color((e==null?void 0:e.backgroundColor)||"#f1f7f6"),o&&(s.remove(o),o.dispose()),this.group.add(...t),s.add(this.group),this.floors=t,this.fitCamera(),this.bmap.context.cameraBound.updateBox(),this.showStatus=!0,this.bmap.context.forceUpdate()}showStep(t,e){return this.show(t,e)}hide(){let{scene:t}=this.bmap.context;t.remove(this.group),this.floors.forEach(e=>{e.dispose()}),this.floors=[],this.group.clear(),this.showStatus=!1}showByNotDispose(t,e,i){i===void 0&&(i=()=>!0);let s=0;t.forEach(r=>{[...r.poiLayer2.pois].forEach(h=>{if(!i(h)){h.visible=!1;return}h.options.depth_test=!0}),r.position.z=s,s+=r.userData.height,r.onAddToScene("mulFloors")});let{scene:o,currentFloor:n}=this.bmap.context;o.background=new ms.Color((e==null?void 0:e.backgroundColor)||"#f1f7f6"),n&&o.remove(n),this.group.add(...t),o.add(this.group),this.floors=t,this.fitCamera(),this.bmap.context.cameraBound.updateBox(),this.showStatus=!0,this.bmap.context.forceUpdate()}hideByNotDispose(){let{scene:t}=this.bmap.context;t.remove(this.group),this.floors.forEach(e=>{e.poiLayer2.pois.forEach(i=>{i.visible=!0,i.options.depth_test=!1})}),this.floors.forEach(e=>{e.position.z=0,e.onRemoveFromScene()}),this.group.clear(),this.showStatus=!1}fitCamera(){let{context:t,config:e}=this.bmap;t.cameraBound.setEnable(!1),t.control.minZoom=0,t.control.maxZoom=1/0,t.camera.zoom=1,t.setAzimuthalAngle(e.control.defaultAzimuthal,0),t.setPolarAngle(e.control.defaultPolar,0),t.fitCameraToObject(this.group,e.defaultPadding,0,!1);let i=t.camera.zoom;t.control.minZoom=i,t.control.maxZoom=i*e.control.maxZoomScale,this.bmap.basicZoom=t.camera.zoom,t.control.addEventListener("change",this.bmap.onControlChange),this.bmap.onControlChange(),t.cameraBound.setEnable(!0)}dispose(){this.floors.forEach(t=>t.dispose()),this.floors=[],super.dispose()}constructor(t){super(t),this.floors=[],this.group=new ms.Group,this.showStatus=!1,this.group.name="mul-floor-group"}};var ma=require("three");var Yh={};function un(){return new Worker(new URL("./worker/path.worker-C7N3AIZ3.js",Yh.url))}var fs=class extends ma.EventDispatcher{setLiftPriority(t){return Z(this.worker,"onSetLiftPriority",t)}loaded(){return new Promise(t=>{if(this.initRoadStatus)t(!0);else{let e=i=>{let{status:s}=i;s&&(this.removeEventListener("init-road-status",e),t(!0))};this.addEventListener("init-road-status",e)}})}setRoadData(t,e){return f(this,null,function*(){this.initRoadStatus=!1,this.dispatchEvent({type:"init-road-status",status:!1}),yield Z(this.worker,"set_road_info",{roadData:t,facilities:e}),this.initRoadStatus=!0,this.dispatchEvent({type:"init-road-status",status:!0})})}getPath(t,e,i,s,o,n){return f(this,null,function*(){return i===void 0&&(i=""),new Promise((r,h)=>{let c=()=>{Z(this.worker,"get_path",{start:t,end:e,type:i,permission:s,travelDirection:o,options:n}).then(l=>{l?typeof l=="string"?h(l):r(l):h("no-path")})};if(this.initRoadStatus)c();else{let l=p=>{let{status:d}=p;d&&(this.removeEventListener("init-road-status",l),c())};this.addEventListener("init-road-status",l)}})})}getDirectionPath(t){return Z(this.worker,"get_direction_path",t)}dispose(){return f(this,null,function*(){Z(this.worker,"clear",""),this.worker.terminate()})}constructor(){super(),this.worker=un(),this.initRoadStatus=!1}};var fa=require("three");var qh={};function mn(){return new Worker(new URL("./worker/cr-path.worker-RCWZ3ILJ.js",qh.url))}var fn=class extends fa.EventDispatcher{setRoadData(t){return f(this,null,function*(){this.initRoadStatus=!1,this.dispatchEvent({type:"init-road-status",status:!1}),yield Z(this.worker,"set_road_info",{roadData:t}),this.initRoadStatus=!0,this.dispatchEvent({type:"init-road-status",status:!0})})}getPath(t,e,i){return f(this,null,function*(){return i===void 0&&(i=""),new Promise((s,o)=>{let n=()=>{Z(this.worker,"get_path",{start:t,end:e,type:i}).then(r=>{r?typeof r=="string"?o(r):s(r):o("no-path")})};if(this.initRoadStatus)n();else{let r=h=>{let{status:c}=h;c&&(this.removeEventListener("init-road-status",r),n())};this.addEventListener("init-road-status",r)}})})}getDirectionPath(t){return Z(this.worker,"get_direction_path",t)}dispose(){return f(this,null,function*(){Z(this.worker,"clear",""),this.worker.terminate()})}constructor(){super(),this.worker=mn(),this.initRoadStatus=!1}};var bM=require("core-js/modules/web.dom-collections.iterator.js"),SM=require("core-js/modules/es.set.difference.v2.js"),EM=require("core-js/modules/es.set.intersection.v2.js"),LM=require("core-js/modules/es.set.is-disjoint-from.v2.js"),CM=require("core-js/modules/es.set.is-subset-of.v2.js"),TM=require("core-js/modules/es.set.is-superset-of.v2.js"),kM=require("core-js/modules/es.set.symmetric-difference.v2.js"),DM=require("core-js/modules/es.set.union.v2.js"),AM=require("core-js/modules/es.array.push.js");var ga=require("three"),eo=class extends Wt{setEnable(t){super.setEnable(t),bt(this.rect,0,0,0,0),t?this.registryEvent():(this.startPoint=void 0,this.unRegistryEvent())}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:s}}}=this,o=D(this.startPoint,e,i,s),n=D(this.endPoint,e,i,s),r={x:Math.min(o.x,n.x),y:Math.min(o.y,n.y)},h={x:Math.max(o.x,n.x),y:Math.max(o.y,n.y)},c=this.searchMapInFrustum(r,h);this.dispatchEvent({type:"selected",list:c})}}searchMapInFrustum(t,e){var i;let{context:s}=this;return((i=s.currentFloor)==null?void 0:i.graphicLayer.children.filter(o=>o instanceof lt&&this.searchChildInFrustum(o,t,e)))||[]}searchChildInFrustum(t,e,i){let{context:{camera:s,container:{clientWidth:o,clientHeight:n}}}=this;if(!t)return!1;if(!t.mesh){let d=t.getPosition();if(d){let u=D(d,s,o,n);return Me(u,e,i)}return!1}t.mesh.geometry.boundingBox||t.mesh.geometry.computeBoundingBox();let r=t.mesh.geometry.boundingBox;if(!r)return!1;let{min:h,max:c}=r,l=D(h,s,o,n),p=D(c,s,o,n);return!(!Me(l,e,i)||!Me(p,e,i))}dispose(){super.dispose(),this.rect=null,this.unRegistryEvent()}constructor(t){super(t),this.frustum=new ga.Frustum,this.onPointerDown=s=>{if(!this.enable)return;let o=this.getIntersectByPointerEvent(s);o&&(this.startPoint=o),this.endPoint=void 0},this.onPointerMove=s=>{if(!this.enable||!this.startPoint)return;let o=this.getIntersectByPointerEvent(s);o&&(this.endPoint=o)},this.onPointerUp=s=>{if(!this.enable)return;let o=this.getIntersectByPointerEvent(s);o&&(this.endPoint=o),this.doSelect(),this.startPoint=void 0},this.onUpdate=()=>{if(this.startPoint){let s=this.getSvgCoordinate(this.startPoint),o=w({},s);this.endPoint&&(o=this.getSvgCoordinate(this.endPoint));let n={x:Math.min(s.x,o.x),y:Math.min(s.y,o.y)},r=Math.abs(o.x-s.x),h=Math.abs(o.y-s.y);bt(this.rect,n.x,n.y,r,h)}else bt(this.rect,0,0,0,0)};let{config:{selectBox:{fill:e,stroke:i}}}=t;this.rect=_e(i,e),this.svg.appendChild(this.rect),this.registryEvent()}};var $h={boxSelection:!1,elements:["graphic","poi"]},gn=class extends X{get list(){return this._list}enableBoxSelection(){this.isMultipleSelect||!this.options.boxSelection||(this.isMultipleSelect=!0,this.boxSelection.setEnable(!0),this.prevPanStatus=this.bmap.context.control.enablePan,this.prevRotateStatus=this.bmap.context.control.enableRotate,this.bmap.context.control.enablePan=!1,this.bmap.context.control.enableRotate=!1)}disableBoxSelection(){this.isMultipleSelect&&(this.isMultipleSelect=!1,this.boxSelection.setEnable(!1),this.bmap.context.control.enablePan=!!this.prevPanStatus,this.bmap.context.control.enableRotate=!!this.prevRotateStatus)}selectEnd(){this.dispatchEvent({type:"select",graphics:[...this._list],pois:[...this._poiList],isMultipleSelect:this.isMultipleSelect})}registryEvent(){this.bmap.context.container.addEventListener("pointerdown",this.onPointerDown),this.bmap.context.container.addEventListener("pointerup",this.onPointerUp),this.bmap.context.container.addEventListener("pointerout",this.onPointerOut),this.bmap.context.container.addEventListener("pointercancel",this.onPointerOut),window.addEventListener("keydown",this.onKeyDown),window.addEventListener("keyup",this.onKeyUp),this.boxSelection.addEventListener("selected",this.onBoxSelected)}unRegistryEvent(){this.bmap.context.container.removeEventListener("pointerdown",this.onPointerDown),this.bmap.context.container.removeEventListener("pointerup",this.onPointerUp),this.bmap.context.container.removeEventListener("pointerout",this.onPointerOut),this.bmap.context.container.removeEventListener("pointercancel",this.onPointerOut),window.removeEventListener("keydown",this.onKeyDown),window.removeEventListener("keyup",this.onKeyUp),this.boxSelection.removeEventListener("selected",this.onBoxSelected)}clear(){this._list.clear()}remove(t){this._list.delete(t)}dispose(){this.unRegistryEvent(),super.dispose()}constructor(t,e={}){super(t),this._list=new Set,this._poiList=new Set,this.downPoint=null,this.isMultipleSelect=!1,this.onPointerDown=i=>{this.downPoint={x:i.offsetX,y:i.offsetY}},this.onPointerUp=i=>{if(!this.downPoint)return;let{offsetX:s,offsetY:o}=i,{x:n,y:r}=this.downPoint;if(Math.sqrt((n-s)**2+(r-o)**2)>3)return;let h=new Set,c=[],l=[];if(this.options.elements.includes("graphic")){let{graphics:p}=this.bmap.context.getGraphicsByDeviceXy(s,o);p.map(d=>h.add(d.options.id)),c.push(...p)}if(this.options.elements.includes("poi")){let p=this.bmap.context.getPoisByDeviceXy(s,o);l.push(...p),p.forEach(d=>{if(!h.has(d.options.id)){var u;let m=((u=this.bmap.context.currentFloor)==null?void 0:u.graphicLayer.graphicMap.get(d.options.id))||null;m&&(h.add(d.options.id),c.push(m))}})}(!this.options.boxSelection||!(He?i.metaKey:i.ctrlKey))&&(this._list.clear(),this._poiList.clear()),c.forEach(p=>this._list.add(p)),l.forEach(p=>this._poiList.add(p)),this.selectEnd(),this.downPoint=null},this.onPointerOut=i=>{this.disableBoxSelection()},this.onKeyDown=i=>{Ne(i.key)&&this.enableBoxSelection()},this.onKeyUp=i=>{Ne(i.key)&&this.disableBoxSelection()},this.onBoxSelected=i=>{let{list:s}=i;this._list.clear(),this._poiList.clear(),s.forEach(o=>{if(this.options.elements.includes("graphic")&&this._list.add(o),this.options.elements.includes("poi")){let n=this.bmap.getPoiById(o.options.id);n&&this._poiList.add(n)}}),this.selectEnd()},this.options=w({},$h,e),this.boxSelection=new eo(this.bmap.context),this.boxSelection.setEnable(!1),this.registryEvent()}};var BM=require("core-js/modules/es.array.push.js"),Ot=require("lodash");var F=function(a){return a.COMPASS="compass",a.DEVICE_MOTION="deviceMotion",a.ACCELERATION="acceleration",a.GPS="gps",a}({});var Jh={time:1e3,elements:[F.COMPASS,F.DEVICE_MOTION,F.ACCELERATION,F.GPS]},gs=class extends st{start(){this.options.elements.some(t=>[F.DEVICE_MOTION,F.COMPASS].includes(t))&&this.listenDeviceOrientation(),this.options.elements.includes(F.ACCELERATION)&&this.listenAcceleration(),this.options.elements.includes(F.GPS)&&this.listenGps(),this.dispatchEvent({type:"start"}),this.dispatchTimer=this.timer.setInterval(()=>{this.dispatchEvent({type:"sensor-data",data:(0,Ot.cloneDeep)(this.data)}),this.data=[]},this.options.time)}addDataItem(t){this.data.push(t),this.dispatchEvent({type:"add-data-item",item:t})}listenDeviceOrientation(){pe?window.addEventListener("deviceorientation",this.deviceOrientationAbsHandler,!1):window.addEventListener("deviceorientationabsolute",this.deviceOrientationAbsHandler,{absolute:!0})}listenAcceleration(){window.addEventListener("devicemotion",this.handleAcceleration,!1)}listenGps(){this.gpsTimer=navigator.geolocation.watchPosition(t=>{console.log("watch gps",t.coords),this.addDataItem({type:F.GPS,timestamp:Date.now(),res:[t.coords.longitude,t.coords.latitude,t.coords.accuracy]})},t=>{console.log("\u83B7\u53D6gps\u5931\u8D25",t)},{enableHighAccuracy:!0})}checkSensor(){return f(this,null,function*(){return{deviceOrientation:yield this.checkDeviceOrientation()}})}checkDeviceOrientation(){return f(this,null,function*(){var t;if(!pe)return!0;if(typeof window.DeviceOrientationEvent!="undefined"&&typeof((t=window.DeviceOrientationEvent)==null?void 0:t.requestPermission)=="function")try{var e;return(yield(e=window.DeviceOrientationEvent)==null?void 0:e.requestPermission())==="granted"}catch(i){return!1}return!1})}stop(){window.removeEventListener("devicemotion",this.handleAcceleration,!1),pe?window.removeEventListener("deviceorientation",this.deviceOrientationAbsHandler,!1):window.removeEventListener("deviceorientationabsolute",this.deviceOrientationAbsHandler,{absolute:!0}),(0,Ot.isNil)(this.gpsTimer)||navigator.geolocation.clearWatch(this.gpsTimer),this.dispatchTimer&&this.timer.clearInterval(this.dispatchTimer),this.data=[],this.dispatchEvent({type:"stop"})}constructor(t={}){super(),this.gpsTimer=null,this.data=[],this.timer=new j,this.dispatchTimer=null,this.addAcceleration=(0,Ot.throttle)(e=>{this.addDataItem(e)},20),this.deviceOrientationAbsHandler=(0,Ot.throttle)(e=>{let i=Date.now(),{alpha:s,beta:o,gamma:n}=e;if((0,Ot.isNil)(s)||(0,Ot.isNil)(o)||(0,Ot.isNil)(n))return;let r;pe?r=e.webkitCompassHeading:r=360-s,this.options.elements.includes(F.DEVICE_MOTION)&&this.addDataItem({type:F.DEVICE_MOTION,timestamp:i,res:[s,o,n]}),this.options.elements.includes(F.COMPASS)&&this.addDataItem({type:F.COMPASS,timestamp:i,res:r})},200),this.handleAcceleration=e=>{let i=e.accelerationIncludingGravity;(0,Ot.isNil)(i)||(0,Ot.isNil)(i.x)||(0,Ot.isNil)(i.y)||(0,Ot.isNil)(i.z)||this.addAcceleration({type:F.ACCELERATION,timestamp:Date.now(),res:[i.x,i.y,i.z]})},this.options=w({},Jh,t)}};var n_=require("core-js/modules/web.dom-collections.iterator.js");var QM=require("core-js/modules/es.array.push.js");var jM=require("core-js/modules/es.array.push.js"),VM=require("core-js/modules/web.dom-collections.iterator.js");function io(a,t){return 1/Math.sqrt(2*Math.PI*Math.pow(t,2))*Math.exp(-Math.pow(a,2)/(2*Math.pow(t,2)))}function ys(a){return(a+360)%360}function ya(a,t){let i=6378137*a*Math.PI/180,s=6378137*Math.log(Math.tan(Math.PI/4+t*Math.PI/180/2));return{x:i,y:s}}function gi(a,t,e,i){return Math.sqrt(Math.pow(Math.abs(a-e),2)+Math.pow(Math.abs(t-i),2))}var so=class{motionModelRotYaw(t){if(!(Math.abs(t)<.001)){this.last_yaw_compass=ys(this.last_yaw_compass+t);for(let e=0;e<this.NumParticle;e++){let i=Math.random()*this.yaw_noise_sigma;this.particleX[2][e]=this.particleX[2][e]+t+i,this.particleX[2][e]=ys(this.particleX[2][e])}}}motionModelStepLength(t,e){if(t===0)return;for(let s=0;s<this.NumParticle;s++){let o=Math.random()*this.step_noise_sigma;this.particleX[0][s]+=(.65+o)*Math.sin(-this.particleX[2][s]/180*Math.PI),this.particleX[1][s]+=(.65+o)*Math.cos(this.particleX[2][s]/180*Math.PI),e(this.particleX[0][s],this.particleX[1][s])||(this.particleWeight[0][s]*=this.unaccess_weight)}let i=this.particleWeight[0].reduce((s,o)=>s+o,0);this.particleWeight[0]=this.particleWeight[0].map(s=>s/i)}motionModelCompassYaw(t,e){if(e-this.last_compass_time>this.compass_update_interval){let i=360-t;i+=this.delta_yaw,i=ys(i),Math.abs(i-this.last_yaw_compass)>60?this.compass_consecutive_offset_count++:this.compass_consecutive_offset_count=0;for(let o=0;o<this.NumParticle;o++){let n=Math.abs(this.particleX[2][o]-i);n>180&&(n=360-n),this.particleWeight[0][o]*=io(n,this.sigmaCompass)}let s=this.particleWeight[0].reduce((o,n)=>o+n,0);this.particleWeight[0]=this.particleWeight[0].map(o=>o/s),this.setLastCompassTime(e)}}resampling(){if(1/this.particleWeight[0].reduce((e,i)=>e+i*i,0)<this.reSampNumParticle){let e=this.particleWeight[0].reduce((r,h,c)=>r.concat(r[c]+h),[0]),s=this.particleWeight[0].map(()=>1/this.NumParticle).map((r,h)=>r+Math.random()/this.NumParticle),o=[],n=0;for(let r=0;r<this.NumParticle;r++){for(;s[r]>e[n];)n++;o.push(n)}this.particleX=this.particleX.map((r,h)=>o.map(c=>r[c])),this.particleWeight[0]=Array(this.NumParticle).fill(1/this.NumParticle)}}update(t,e){for(let s=0;s<this.NumParticle;s++){let o=gi(this.particleX[0][s],this.particleX[1][s],t.x,t.y);this.particleWeight[0][s]=Math.max(1e-7,this.particleWeight[0][s]*io(o,e))}let i=this.particleWeight[0].reduce((s,o)=>s+o,0);this.particleWeight[0]=this.particleWeight[0].map(s=>s/i)}updateCar(t,e){let i=t.x-this.xEst[0][0],s=t.y-this.xEst[1][0];for(let n=0;n<this.NumParticle;n++){let r=gi(this.particleX[0][n],this.particleX[1][n],t.x,t.y);this.particleWeight[0][n]=Math.max(1e-7,this.particleWeight[0][n]*io(r,e)),this.particleX[0][n]+=i,this.particleX[1][n]+=s}let o=this.particleWeight[0].reduce((n,r)=>n+r,0);this.particleWeight[0]=this.particleWeight[0].map(n=>n/o)}getPosInitFlag(){return this.particle_PosInitFlag}getYawInitFlag(){return this.particle_yawInitFlag}setPosInitFlag(t){this.particle_PosInitFlag=t}setYawInitFlag(t){this.particle_yawInitFlag=t}getResultX(){let t=[0,0,0];for(let e=0;e<3;e++)for(let i=0;i<this.NumParticle;i++)t[e]+=this.particleX[e][i]*this.particleWeight[0][i];return this.xEst=t.map(e=>[e]),this.xEst[0][0]}getResultY(){return this.xEst[1][0]}getResultYaw(){let t=this.particleWeight[0].indexOf(Math.max(...this.particleWeight[0]));return this.particleX[2][t]}getEstConfidence(){let t=this.particleWeight[0].indexOf(Math.max(...this.particleWeight[0])),e=this.particleWeight[0].indexOf(Math.min(...this.particleWeight[0])),i=[this.particleX[0][t],this.particleX[1][t]],s=[this.particleX[0][e],this.particleX[1][e]],o=gi(i[0],i[1],s[0],s[1]),n=o*.67;return console.log(o,n),n}getParticleNum(){return this.NumParticle}getParticleX(){return this.particleX}setLastCompassTime(t){this.last_compass_time=t}getLastCompassTime(){return this.last_compass_time}initParticlesByPos(t,e,i){if(!this.particle_PosInitFlag){this.particleWeight[0]=Array(this.NumParticle).fill(1/this.NumParticle);let s=0;for(;s<this.NumParticle;){let n=(2*Math.random()-1)*this.initial_xy_uncertainty,r=(2*Math.random()-1)*this.initial_xy_uncertainty;i(t+n,e+r)||(this.particleWeight[0][s]*=this.unaccess_weight),this.particleX[0][s]=t+n,this.particleX[1][s]=e+r,s++}let o=this.particleWeight[0].reduce((n,r)=>n+r,0);this.particleWeight[0]=this.particleWeight[0].map(n=>n/o),this.particle_PosInitFlag=!0,this.xEst[0][0]=t,this.xEst[1][0]=e,this.xEst[2][0]=0}}initParticlesByCompass(t){console.log("Init compass: "+t);let e=360-t;e+=this.delta_yaw,e=ys(e),console.log("Init Yaw: "+e);for(let i=0;i<this.NumParticle;i++){let s=(2*Math.random()-1)*this.initial_yaw_uncertainty;this.particleX[2][i]=e+s}this.particle_yawInitFlag=!0,this.xEst[2][0]=e,this.last_yaw_compass=e,this.compass_consecutive_offset_count=0}constructor(t){this.last_yaw_compass=0,this.compass_consecutive_offset_count=0,this.NumParticle=t.NumParticle,this.reSampNumParticle=t.reSampNumParticle,this.initial_xy_uncertainty=t.initial_xy_uncertainty,this.initial_yaw_uncertainty=t.initial_yaw_uncertainty,this.step_noise_sigma=t.step_noise_sigma,this.yaw_noise_sigma=t.yaw_noise_sigma,this.compass_update_interval=t.compass_update_interval,this.sigmaCompass=t.sigmaCompass,this.delta_yaw=t.delta_yaw,this.sigmaBeacon=t.sigmaBeacon,this.unaccess_weight=t.unaccess_weight,this.particle_PosInitFlag=!1,this.particle_yawInitFlag=!1,this.xEst=[[0],[0],[0]],this.particleX=Array.from({length:3},()=>Array(this.NumParticle).fill(0)),this.particleWeight=Array.from({length:1},()=>Array(this.NumParticle).fill(1/this.NumParticle)),this.last_compass_time=0}};var YM=require("core-js/modules/es.array.push.js"),qM=require("core-js/modules/web.dom-collections.iterator.js");var oo=class{init(){this.fre=100,this.accH_fifo=[],this.accH_time_fifo=[],this.accH_fifo_len=Math.floor(1*this.fre)+1,this.step_count=0,this.state_count=0,this.last_valley_time=0,this.last_peak_time=0,this.last_step_time=0,this.min_step_time=.3,this.max_step_time=1,this.min_peak=10+.5,this.max_valley=10-.5,this.peak_num=0,this.valley_num=0,this.fft_min_amp=.3,this.fft_min_fre=0,this.fft_max_fre=4,this.last_fft_amp=0,this.abnor_start_time=0,this.abnor_fft_detected=!1,this.abnor_peak_time=0,this.abnor_peak_accH=0,this.const_step_length=.65,this.last_rot=[0,0,0],this.delta_rot=[0,0,0],this.last_yaw=0,this.delta_yaw=null,this.delta_rot_sum_fifo=[],this.delta_rot_sum_time_fifo=[],this.delta_yaw_accum=0,this.delta_yaw_accum_timestamp=0,this.delta_yaw_time_threshold=.5,this.last_px=0,this.last_py=0,this.delta_px=0,this.delta_py=0,this.is_moving=!1,this.currentMotionState="UNKNOWN",this.previousMotionState="UNKNOWN",this.acc_variance_buffer=[],this.rot_variance_buffer=[],this.acc_buffer=[],this.walkingCount=0,this.stationaryCount=0,this.phoneUseCount=0,this.stateCounter=0}reset(){this.init()}setInitPose(t){t===void 0&&(t=[0,0]),this.last_px=t[0],this.last_py=t[1],console.info("pdr init pos: "+this.last_px+", "+this.last_py)}setInitYaw(t){t===void 0&&(t=0),this.last_yaw=t}getPos(t,e,i){let s=0;return i.length===3&&(this.delta_yaw=this.getDeltaYawFromRot(t,i)),e.length===3&&(s=this.getStepLength(t,e)),s!==0&&(this.last_px+=this.delta_px,this.last_py+=this.delta_py),[this.last_px,this.last_py]}getDeltaPose(){return[this.delta_px,this.delta_py]}getMotionState(){return this.currentMotionState}getStepLength(t,e){if(e.length<3)return console.warn("acc data less than 3"),0;let i=!1,s=Math.sqrt(Math.pow(e[0],2)+Math.pow(e[1],2)+Math.pow(e[2],2));if(this.accH_fifo.push(s),this.accH_time_fifo.push(t),this.imuFreUpdate(),!this.isMoving(e,this.last_rot))return 0;if(this.accH_fifo.length<this.accH_fifo_len+1)i=!1;else{for(;this.accH_fifo.length>=this.accH_fifo_len+1;)this.accH_fifo.shift(),this.accH_time_fifo.shift();let n=this.PVStepDetec(),r=this.FFTStepDetec(),h=this.recheckState(),c=this.accH_time_fifo[Math.floor(this.accH_time_fifo.length*3/4)];Math.abs(this.abnor_start_time)<.001&&this.abnor_fft_detected?this.abnor_start_time=c:this.abnor_fft_detected||(this.abnor_start_time=0),n&&r&&h?(this.step_count+=1,this.last_step_time=c,i=!0):Math.abs(this.abnor_start_time)>.001&&this.abnor_peak_time-this.abnor_start_time>this.abnor_time_threshold&&this.step_count>1&&this.abnor_peak_time-this.last_step_time>1?(this.step_count+=1,this.last_step_time=c,i=!0):(c-this.last_step_time>2&&(this.state_count=0),i=!1)}if(i){let n=this.last_yaw/180*Math.PI;return this.delta_px=this.const_step_length*Math.cos(n),this.delta_py=this.const_step_length*Math.sin(n),this.const_step_length}else return 0}imuFreUpdate(){if(this.accH_time_fifo.length>2&&(this.accH_time_fifo[this.accH_time_fifo.length-1]-this.accH_time_fifo[this.accH_time_fifo.length-2]<0||this.accH_time_fifo[this.accH_time_fifo.length-1]-this.accH_time_fifo[this.accH_time_fifo.length-2]>10||this.accH_time_fifo[this.accH_time_fifo.length-1]===this.accH_time_fifo[0])&&(console.warn("pdr reset last one time "+this.accH_time_fifo[this.accH_time_fifo.length-1]+" last two time "+this.accH_time_fifo[this.accH_time_fifo.length-2]),this.reset()),this.accH_fifo.length>9||this.fre<15){let t=(this.accH_fifo.length-1)/(this.accH_time_fifo[this.accH_time_fifo.length-1]-this.accH_time_fifo[0]);Math.abs(this.fre-t)>8&&(this.fre=Math.round((t-3)/10)*10,(this.fre<=10||this.fre>=100)&&(console.warn("Frequency Error "+this.fre),this.fre=100),console.debug("Frequency change to "+this.fre),this.accH_fifo_len=Math.floor(1*this.fre)+1)}}recheckState(){return!0}PVStepDetec(){let t=!1,e=this.accH_fifo.slice(Math.floor(this.accH_fifo_len/2)),i=this.accH_time_fifo.slice(Math.floor(this.accH_fifo_len/2)),s=e[Math.floor(e.length/2)],o=i[Math.floor(i.length/2)],n=Math.max(...e),r=Math.min(...e),h=!1,c=!1;return Math.abs(s-r)<.01&&s<this.max_valley&&this.valley_num<=this.peak_num&&(this.last_valley_time===0?c=!0:c=o-this.last_valley_time>this.min_step_time,c&&(this.last_valley_time=o,this.valley_num+=1)),Math.abs(s-n)<.01&&s>this.min_peak&&this.peak_num<=this.valley_num&&(this.last_peak_time===0?h=!0:h=o-this.last_peak_time>this.min_step_time,h&&(this.last_peak_time=o,this.peak_num+=1)),s===n&&s>this.min_peak&&(this.abnor_peak_time=o,this.abnor_peak_accH=s),this.peak_num===this.valley_num&&(h||c)&&(t=!0),t}FFTStepDetec(){return!0}isMoving(t,e){if(t.length<3||e.length<3)return!1;this.acc_buffer.push([...t]),this.acc_buffer.length>this.static_window_size&&this.acc_buffer.shift();let i=Math.sqrt(Math.pow(t[0],2)+Math.pow(t[1],2)+Math.pow(t[2],2));this.acc_variance_buffer.push(i),this.acc_variance_buffer.length>this.static_window_size&&this.acc_variance_buffer.shift();let s=Math.abs(e[0])+Math.abs(e[1])+Math.abs(e[2]);if(this.rot_variance_buffer.push(s),this.rot_variance_buffer.length>this.static_window_size&&this.rot_variance_buffer.shift(),this.acc_variance_buffer.length<10)return this.is_moving;let o=this.acc_variance_buffer.slice(-10),n=this.rot_variance_buffer.slice(-10),r=this.calculateMean(o),h=this.calculateStdDeviation(o),c=this.calculateMean(n),l=this.calculateStdDeviation(n),p;return r>this.walkingThreshold&&h>.5?(this.walkingCount++,this.stationaryCount=0,this.phoneUseCount=0,p="WALKING"):r<this.phoneUseThreshold&&c>this.rotationThreshold?(this.phoneUseCount++,this.walkingCount=0,this.stationaryCount=0,p="USING_PHONE"):c<.5?(this.stationaryCount++,this.walkingCount=0,this.phoneUseCount=0,p="STATIONARY"):p="UNKNOWN",p!==this.currentMotionState?(this.stateCounter++,this.stateCounter>=this.stateChangeThreshold&&(this.previousMotionState=this.currentMotionState,this.currentMotionState=p,this.stateCounter=0,console.debug("Motion state changed: "+this.previousMotionState+" -> "+this.currentMotionState),console.debug("Stats: avgAcc="+r.toFixed(2)+", accStdDev="+h.toFixed(2)+", avgRot="+c.toFixed(2)+", rotStdDev="+l.toFixed(2)))):this.stateCounter=0,this.is_moving=this.currentMotionState==="WALKING",this.is_moving}calculateMean(t){return t.length===0?0:t.reduce((e,i)=>e+i,0)/t.length}calculateStdDeviation(t){if(t.length<2)return 0;let e=this.calculateMean(t),s=t.map(o=>{let n=o-e;return n*n}).reduce((o,n)=>o+n,0)/t.length;return Math.sqrt(s)}getMotionStatistics(){let t=this.acc_variance_buffer.slice(-10),e=this.rot_variance_buffer.slice(-10),i=this.calculateMean(t),s=this.calculateMean(e),o=this.calculateStdDeviation(t),n=this.calculateStdDeviation(e);return console.debug("\u8FD0\u52A8\u68C0\u6D4B: avgAcc="+i.toFixed(2)+", accStdDev="+o.toFixed(2)+", avgRot="+s.toFixed(2)+", rotStdDev="+n.toFixed(2)),console.debug("\u72B6\u6001\u5224\u65AD\u6761\u4EF6: \u884C\u8D70(avgAcc>"+this.walkingThreshold+", accStdDev>0.5), \u9759\u6B62(avgRot<0.5), \u624B\u673A(avgAcc<"+this.phoneUseThreshold+", avgRot>"+this.rotationThreshold+")"),console.debug("\u5F53\u524D\u72B6\u6001: "+this.currentMotionState+", \u8BA1\u6570: \u884C\u8D70="+this.walkingCount+", \u9759\u6B62="+this.stationaryCount+", \u624B\u673A="+this.phoneUseCount),{currentState:this.currentMotionState,avgAcceleration:i,avgRotation:s,accStdDeviation:o,rotStdDeviation:n,walkingCount:this.walkingCount,stationaryCount:this.stationaryCount,phoneUseCount:this.phoneUseCount,dataPoints:this.acc_variance_buffer.length,isMoving:this.is_moving}}getDeltaYawFromRot(t,e){if(e.length<3)return console.warn("rot data less than 3"),0;let i=[0,0,0];this.last_rot.length===3&&(i=e.map((r,h)=>r-this.last_rot[h]));for(let r=0;r<e.length;r++)i[r]<-180?i[r]+=360:i[r]>180&&(i[r]-=360);let s=.2;this.delta_rot.length===3?this.delta_rot=this.delta_rot.map((r,h)=>s*r+(1-s)*i[h]):this.delta_rot=i,this.last_rot=e,this.delta_yaw=this.delta_rot[0],this.last_yaw+=this.delta_yaw,this.last_yaw=this.limitYaw(this.last_yaw);let o=this.delta_rot.reduce((r,h)=>r+Math.abs(h),0);this.delta_rot_sum_fifo.push(o),this.delta_rot_sum_time_fifo.push(t),Math.abs(this.delta_rot_sum_time_fifo[this.delta_rot_sum_time_fifo.length-1]-this.delta_rot_sum_time_fifo[0])>1&&(this.delta_rot_sum_fifo.shift(),this.delta_rot_sum_time_fifo.shift()),this.delta_yaw_accum+=this.delta_yaw;let n=0;return Math.abs(this.delta_yaw_accum_timestamp-t)>this.delta_yaw_time_threshold?(n=this.delta_yaw_accum,this.delta_yaw_accum=0,this.delta_yaw_accum_timestamp=t,n):null}limitYaw(t){for(;t<-180;)t+=360;for(;t>180;)t-=360;return t}constructor(){this.fre=100,this.accH_fifo=[],this.accH_time_fifo=[],this.accH_fifo_len=Math.floor(1*this.fre)+1,this.step_count=0,this.state_count=0,this.last_valley_time=0,this.last_peak_time=0,this.last_step_time=0,this.min_step_time=.3,this.max_step_time=1,this.min_peak=10.5,this.max_valley=9.5,this.peak_num=0,this.valley_num=0,this.fft_min_amp=.3,this.fft_min_fre=0,this.fft_max_fre=4,this.last_fft_amp=0,this.abnor_start_time=0,this.abnor_fft_detected=!1,this.abnor_time_threshold=4,this.abnor_peak_time=0,this.abnor_peak_accH=0,this.const_step_length=.85,this.last_rot=[],this.delta_rot=[],this.last_yaw=0,this.delta_yaw=null,this.delta_rot_sum_fifo=[],this.delta_rot_sum_time_fifo=[],this.delta_yaw_accum=0,this.delta_yaw_accum_timestamp=0,this.delta_yaw_time_threshold=.5,this.last_px=0,this.last_py=0,this.delta_px=0,this.delta_py=0,this.is_moving=!1,this.currentMotionState="UNKNOWN",this.previousMotionState="UNKNOWN",this.walkingThreshold=1,this.stationaryThreshold=.6,this.phoneUseThreshold=.7,this.rotationThreshold=.8,this.walkingCount=0,this.stationaryCount=0,this.phoneUseCount=0,this.stateCounter=0,this.stateChangeThreshold=3,this.static_window_size=20,this.acc_variance_buffer=[],this.rot_variance_buffer=[],this.acc_buffer=[]}};var Qh={using_gps:!0,gps_max_horizontalAccuracy:20,initial_gps_delay_time:3e3},no=class{pfFusionPDRiBeacon(t){let{type:e,timestamp:i,res:s}=t,o=!1;if(this.cacheSensorData.push(t),this.particleFilter.getPosInitFlag()&&this.particleFilter.getYawInitFlag()){if(e===F.ACCELERATION){let n=s,r=this.pdr.getStepLength(i/1e3,n);r!==0&&(this.particleFilter.motionModelStepLength(r,()=>!0),this.particleFilter.resampling(),this.position_count+=1,o=!0)}if(this.using_gps&&e===F.GPS)if(this.last_beacon_time===null||i-this.last_beacon_time>5e3){let n=this.getGpsPosition(s);o=n!==null,n&&(this.particleFilter.update(n,this.gps_horizontalAccuracy),this.resetParticleFilterDist(n,"gps",s[2]),this.particleFilter.resampling(),this.position_count+=1,this.cacheSensorData.length=0)}else return[!1,0,0];if(e===F.DEVICE_MOTION){let n=this.pdr.getDeltaYawFromRot(i/1e3,s);n!==null&&this.particleFilter.motionModelRotYaw(n)}e===F.COMPASS&&this.particleFilter.motionModelCompassYaw(s,i),this.last_pos_time&&i-this.last_pos_time>500&&(this.position_count+=1,o=!0)}else if(!this.particleFilter.getPosInitFlag()&&this.using_gps&&e===F.GPS)if(this.startTime&&Date.now()-this.startTime>this.options.initial_gps_delay_time){let n=this.getGpsPosition(s);o=n!==null,console.log("gps_pos",n,s),n?(this.particleFilter.initParticlesByPos(n.x,n.y,()=>!0),this.last_pos_time=i,console.log("init Pos by gps success time "+i),this.cacheSensorData.length=0):console.log("init Pos by gps fail time "+i)}else this.startTime||(this.startTime=i);else if(!this.particleFilter.getYawInitFlag()&&e===F.COMPASS){let n=s;this.particleFilter.initParticlesByCompass(n),this.particleFilter.setLastCompassTime(i),console.log("init yaw by compass success time "+i)}return o&&(this.last_pos_time=i),[o,this.particleFilter.getResultX(),this.particleFilter.getResultY()]}setBeaconPosition(t,e){if(this.last_beacon_time=e,this.particleFilter.getPosInitFlag())this.particleFilter.update(t,this.sigmaBeacon);else{this.particleFilter.initParticlesByPos(t.x,t.y,()=>!0);let i=this.cacheSensorData.filter(s=>s.timestamp>e);console.log("\u521D\u59CBsensorData",i),i.map(s=>this.pfFusionPDRiBeacon(s))}return this.resetParticleFilterDist(t),this.particleFilter.resampling(),this.position_count+=1,this.cacheSensorData.length=0,[this.particleFilter.getResultX(),this.particleFilter.getResultY()]}getGpsPosition(t){return t[2]>this.gps_max_horizontalAccuracy?null:ya(t[0],t[1])}resetParticleFilterDist(t,e,i){let s=this.particleFilter.getResultX(),o=this.particleFilter.getResultY(),n=gi(s,o,t.x,t.y);(e==="gps"?i&&n>i||n>this.GpsMaxEstimateErr:n>this.MaxEstimateErr)?(this.outTrustRegionNum+=1,this.outTrustRegionNum>=this.TrustNum&&(console.info("\u8D85\u51FA\u53EF\u4FE1\u533A\u57DF\uFF0C\u91CD\u7F6E\u7C92\u5B50\u8FC7\u6EE4\u5668\u5230: "+t.x+", "+t.y),this.particleFilter.setPosInitFlag(!1),this.particleFilter.setYawInitFlag(!1),this.outTrustRegionNum=0,this.startTime=Date.now())):this.outTrustRegionNum=0}constructor(t){this.sigmaBeacon=5,this.gps_horizontalAccuracy=10,this.using_gps=!0,this.last_beacon_time=Date.now(),this.position_count=0,this.gps_max_horizontalAccuracy=20,this.MaxEstimateErr=5,this.GpsMaxEstimateErr=30,this.outTrustRegionNum=0,this.TrustNum=1,this.cacheSensorData=[],this.startTime=null;let e=w({},Qh,t);this.options=e,this.using_gps=e.using_gps,this.gps_max_horizontalAccuracy=e.gps_max_horizontalAccuracy,this.particleFilter=new so({NumParticle:200,reSampNumParticle:.65,initial_xy_uncertainty:12,initial_yaw_uncertainty:100,step_noise_sigma:.5,yaw_noise_sigma:2,compass_update_interval:3e3,sigmaCompass:80,delta_yaw:2,sigmaBeacon:5,unaccess_weight:.7}),this.pdr=new oo}};var ro=require("@turf/turf"),vs=class extends st{checkSensor(){return this.sensor.checkSensor()}setSensor(t){this.sensor=t}start(){this.sensor.start(),this.pdr.startTime=Date.now(),this.sensor.addEventListener("add-data-item",t=>{let{item:e}=t;this.getPositionBySensorItem(e,!this._pause)})}pause(){this._pause=!0}continue(){this._pause=!1}getPositionBySensorItem(t,e){e===void 0&&(e=!0);let[i,s,o]=this.pdr.pfFusionPDRiBeacon(t);return i&&e&&(0,ro.booleanPointInPolygon)((0,ro.point)([s,o]),this.bmap.context.range)&&this.dispatchEvent({type:"position",x:s,y:o,_type:t.type===F.GPS?"gps":"pdr"}),[i,s,o]}setBeaconPosition(t,e){let[i,s]=this.pdr.setBeaconPosition(t,e);this.dispatchEvent({type:"position",x:i,y:s,_type:"beacon"})}dispose(){this.sensor.stop()}constructor(t,e={}){super(),this.bmap=t,this._pause=!1,this.sensor=new gs(e.sensor),this.pdr=new no(e.pdr||{})}};var E_=require("core-js/modules/web.dom-collections.iterator.js"),L_=require("core-js/modules/es.array.push.js");var d_=require("core-js/modules/web.dom-collections.iterator.js"),u_=require("core-js/modules/es.array.push.js"),m_=require("core-js/modules/es.array.flat.js"),f_=require("core-js/modules/es.array.unscopables.flat.js"),ft=require("three");var mt=require("three");mt.UniformsLib["custom-line"]={linewidth:{value:1},resolution:{value:new mt.Vector2(1,1)},dashScale:{value:1},dashSize:{value:1},gapSize:{value:1},repeat:{value:new mt.Vector2(1,1)},allDistance:{value:1}};mt.ShaderLib["custom-line"]={uniforms:mt.UniformsUtils.merge([mt.UniformsLib.common,mt.UniformsLib.fog,mt.UniformsLib["custom-line"]]),vertexShader:`
509
509
  #include <common>
510
510
  #include <color_pars_vertex>
511
511
  #include <fog_pars_vertex>
@@ -505,7 +505,7 @@ var ra=Object.create;var Gs=Object.defineProperty;var aa=Object.getOwnPropertyDe
505
505
  top: 0;
506
506
  left: 0;
507
507
  z-index: 9999;
508
- `,document.body.appendChild(a.canvas)}setAngle(t){if(console.log("angle",t),a.textureMap.has(t))this._initIcon(a.textureMap.get(t));else{this.draw(t);let e=this.getTexture(this.getImageData());a.textureMap.set(t,e),this._initIcon(e),this._initScale({zoom:this.bmap.context.camera.zoom})}}_initIcon(t){if(this.spriteIcon)this.spriteIcon.material.map=t,t.needsUpdate=!0;else{let e=new ld(new pd({map:t,transparent:!0,alphaTest:.2,depthTest:this.options.depth_test,rotation:this.options.icon_rotate/180*Math.PI}));e.renderOrder=1e5+this.options.level,t.needsUpdate=!0,this.add(e),e.center.set(.5,.5),this.spriteIcon=e}}initSize(){this.spriteIcon&&this.spriteIcon.center.set(.5,.5)}draw(t){let{ctx:e}=a,{config:{size:i}}=this,s=i[0]/2,o=i[1]/2,n=4,r=1,h=n+r;if(e.clearRect(0,0,i[0],i[1]),e.setLineDash([10,10]),e.strokeStyle="#fff",e.lineWidth=2,e.beginPath(),e.arc(s,o,o-h,-Math.PI/2,Math.PI*2-Math.PI/2,t<Math.PI),e.stroke(),e.strokeStyle="#0A7AFF",t<Math.PI){let c=-Math.PI/2,l=c-t;e.beginPath(),e.arc(s,o,o-h,c,l,!0)}else{let c=-Math.PI/2,l=c+Math.PI*2-t;e.beginPath(),e.arc(s,o,o-h,c,l,!1)}e.stroke(),e.clearRect(s-h*2,0,h*4,h*4),e.beginPath(),e.arc(s,h,n,0,Math.PI*2),e.fillStyle="#0A7AFF",e.fill(),e.setLineDash([10,0]),e.strokeStyle="#fff",e.lineWidth=r,e.stroke(),e.clearRect(0,o-5,10,10),e.clearRect(s-5,i[1]-10,10,10),e.clearRect(i[0]-10,o-5,10,10),t>Math.PI/2&&t<Math.PI?e.fillStyle="#0A7AFF":e.fillStyle="#fff",e.fillRect(0,o-1,10,2),e.fillStyle="#fff",e.fillRect(s-1,i[1]-10,2,10),t>Math.PI&&t<Math.PI/2*3?e.fillStyle="#0A7AFF":e.fillStyle="#fff",e.fillRect(i[0]-10,o-1,10,2)}getImageData(){let{ctx:t}=a,{config:{size:e}}=this;return t.getImageData(0,0,e[0],e[1])}getTexture(t){let{config:{size:e}}=this,i=new cd(Uint8Array.from(t.data),e[0],e[1],Er);return i.format=Er,i.magFilter=Sr,i.minFilter=Sr,i.colorSpace="srgb",i.flipY=!0,i}dispose(){var t;super.dispose(),(t=this.spriteIcon)==null||t.material.dispose()}static dispose(){this.textureMap.forEach(t=>{t.dispose()}),this.textureMap.clear(),this.ctx=null,this.canvas=null}constructor(t,e){super(t.context,{icon_size:e.size,collision_enable:!1,level:2}),this.bmap=t,this.config=e,a.canvas.width=e.size[0],a.canvas.height=e.size[1]}};Vt.canvas=document.createElement("canvas");Vt.ctx=Vt.canvas.getContext("2d",{willReadFrequently:!0});Vt.textureMap=new Map;var md={path:{},cheapMaximumDistance:20,needStartPoi:!1,startPoi:{},positionNavigation:{},offsetY:150,directionEmitThreshold:5,disablePathAnimation:!1,disablePathRotate:!1,disablePathShorten:!1,speed:1,roadData:[],runAnimationMaxTime:1,navigationCameraBasic:45,canBack:!1},Lr=class extends B{get curFloorPathLength(){var t,e;return(e=(t=this.curFloorPath)==null?void 0:t.distance)!=null?e:0}get curFloorPathPoints(){var t,e;return(e=(t=this.curFloorPath)==null?void 0:t.points)!=null?e:[]}registryEvent(){this.bmap.context.addEventListener("update",this.onUpdate),this.bmap.addEventListener(it.SWITCH_FLOOR_GROUND,this.onSwitchFloor),this.positionNavigation.addEventListener("navigation-info",this.onNavigationInfo),this.bmap.context.addEventListener("control-change",this.onControlChangeForStartPoi)}setRoadData(t){this.options.roadData=t,this.positionNavigation.setRoadData(t)}showStartRotateHelperPoi(){var t;if(this.needStartRotateHelperPoi=!0,!this.startPoi||this.startRotateHelperPoi)return;let e=this.startPoi.options.icon_size;this.startRotateHelperPoi=new Vt(this.bmap,{size:[e[0]+20,e[1]+20]}),this.startRotateHelperPoi.setAngle(0),this.startRotateHelperPoi.position.setZ(.51),(t=this.bmap.context.currentFloor)==null||t.poiLayer2.pushPoi(this.startRotateHelperPoi)}hideStartRotateHelperPoi(){if(this.needStartRotateHelperPoi=!1,this.startRotateHelperPoi){var t;(t=this.bmap.context.currentFloor)==null||t.poiLayer2.removePoi(this.startRotateHelperPoi),this.startRotateHelperPoi=null}}setStartPoiPosition(t,e){this.startPoi&&(this.startPoi.position.setX(t).setY(e),this.startRotateHelperPoi&&this.startRotateHelperPoi.position.setX(t).setY(e),this.detachLine&&this.detachLine.setPosition(this.startPoi.position,this.detachStartPoi.position))}resetStatus(){this.pauseAnimation(),this.positionNavigation.resetStatus(this.paths),this.movedDistance=0,this.startPoi&&this.translatePath&&this.setStartPoiPosition(this.translatePath[0][0],this.translatePath[0][1])}toPositionByTask(t){var e;let s=(e=this.taskQueue.getTasks().find(n=>n.meta.type==="toPosition"))==null?void 0:e.tid,o={run:()=>this.toPositionBySpeed(t,this.options.speed),meta:{type:"toPosition"}};s?this.taskQueue.replace(s,o):this.taskQueue.add(o)}pauseAnimation(){this.taskQueue.clear(),this.positionNavigation.pause(),this.tweenUtil.pause()}continueAnimation(){this.tweenUtil.continue(),this.positionNavigation.continue()}clearTween(){this.tweenUtil.clear(),this.taskQueue.clear(),this.bmap.context.control.enabled=!0}unRegistryEvent(){this.bmap.context.removeEventListener("update",this.onUpdate),this.bmap.removeEventListener(it.SWITCH_FLOOR_GROUND,this.onSwitchFloor),this.positionNavigation.removeEventListener("navigation-info",this.onNavigationInfo),this.bmap.context.removeEventListener("control-change",this.onControlChangeForStartPoi)}clearPath(){if(this.resetStatus(),this.path&&(this.bmap.context.scene.remove(this.path),this.path.dispose(),this.path=null,this.clearTween()),this.startPoi){var t;if((t=this.bmap.context.currentFloor)==null||t.poiLayer2.removePoi(this.startPoi),this.startPoi=null,this.startRotateHelperPoi){var e;(e=this.bmap.context.currentFloor)==null||e.poiLayer2.removePoi(this.startRotateHelperPoi),this.startRotateHelperPoi=null}}if(this.detachStartPoi){var i;(i=this.bmap.context.currentFloor)==null||i.removePoi2(this.detachStartPoi),this.detachStartPoi=null}this.detachLine&&(this.bmap.context.scene.remove(this.detachLine),this.detachLine.dispose(),this.detachLine=null),this.translatePath=null}setCurFloorPath(t){t===null?(this.curFloorPath=null,this.currentPathPosition=null,this.toPointPosition=null):(this.curFloorPath=t,this.currentPathPosition=t.points[0],this.toPointPosition=t.points[0]),this.movedDistance=0,this.clearTween()}setCurPathIndex(t){var e,i;this.curPathIndex=t,((e=this.paths[t])==null?void 0:e.floor)===((i=this.bmap.context.currentFloor)==null?void 0:i.name)?(this.setCurFloorPath(this.paths[t]),this.renderPath(this.translatePoints(this.curFloorPathPoints))):this.clearPath()}addPath(t,e){e===void 0&&(e=0);var i;this.paths=t,this.curPathIndex=e,this.clearTween(),this.clearPath();let s=(i=this.bmap.context.currentFloor)==null?void 0:i.name,o=t[e];if(s&&(o==null?void 0:o.floor)===s)if(this.setCurFloorPath(o),this.bmap.currentBuildGround)this.renderPath(this.translatePoints(o.points));else{let n=()=>{this.bmap.removeEventListener("center-change",n),this.renderPath(this.translatePoints(o.points))};this.bmap.addEventListener("center-change",n)}this.dispatchEvent({type:"add-path",paths:t})}translatePoints(t){let[e,i]=this.bmap.buildingCenter;return t.map(s=>[s[0]-e,s[1]-i])}renderPath(t){this.translatePath=t;let e=this.catmullRomCurve3(t);if(this.cPath=e,this.animationPathOptions={cPathIndex:0},this.pathStart=e[0],this.path?this.path.updatePoints(e):(this.path=new fs(this,this.options.path),this.path.create(e),this.path.position.z=this.bmap.context.currentFloor.groundMaxHeight+.5,this.bmap.context.scene.add(this.path)),this.path.movePath(0),this.startPoi){var i;if((i=this.bmap.context.currentFloor)==null||i.poiLayer2.removePoi(this.startPoi),this.startPoi=null,this.startRotateHelperPoi){var s;(s=this.bmap.context.currentFloor)==null||s.poiLayer2.removePoi(this.startRotateHelperPoi),this.startRotateHelperPoi=null}}if(this.removeDetachStart(),this.showDetachStartState&&this.options.detachStartPoi){var o;this.detachStartPoi=new j(this.bmap.context,w({},this.options.detachStartPoi,{id:"navigation_detach_start_poi",position:{x:e[0][0],y:e[0][1],z:.51},collision_enable:!1}))||null,(o=this.bmap.context.currentFloor)==null||o.poiLayer2.pushPoi(this.detachStartPoi),this.detachLine=new $e(this.bmap.context,new bt(e[0][0],e[0][1],.51),new bt(e[0][0],e[0][1],.51)),this.bmap.context.scene.add(this.detachLine)}if(this.options.needStartPoi){var n;this.startPoi=new j(this.bmap.context,w({},this.options.startPoi,{id:"navigation_start_poi",position:{x:e[0][0],y:e[0][1],z:.51},collision_enable:!1}))||null,(n=this.bmap.context.currentFloor)==null||n.poiLayer2.pushPoi(this.startPoi),this.needStartRotateHelperPoi&&this.showStartRotateHelperPoi(),console.log(this.startRotateHelperPoi)}this.dispatchEvent({type:"render-path",path:this.path})}catmullRomCurve3(t){return mi(t,!1,!0,.1,170,2.5)}getPathDirection(){if(!this.curFloorPath||!this.currentPathPosition||this.curFloorPathPoints.length<2)return null;let t=Bt(this.curFloorPathPoints,this.currentPathPosition),e=this.curFloorPathPoints[t],i=this.curFloorPathPoints[t+1],s=new bt(i[0]-e[0],i[1]-e[1],0).normalize(),o=new bt(0,1,0).normalize(),n=s.angleTo(o),r=new bt().crossVectors(o,s);return(Object.is(r.y,0)?-1:1)*n}getPathDirection2(){if(!this.curFloorPath||!this.toPointPosition||this.curFloorPathPoints.length<2)return null;let t=Bt(this.curFloorPathPoints,this.toPointPosition),e=this.curFloorPathPoints[t],i=this.curFloorPathPoints[t+1];return(new ud(i[0]-e[0],i[1]-e[1]).normalize().angle()*180/Math.PI-90+360)%360}changeCameraToPathUp(t){return f(this,null,function*(){t===void 0&&(t=100);let e=this.getPathDirection();if(e===null)return;let i=this.bmap.context.control.getAzimuthalAngle();Math.abs(i-e)>Math.PI&&(i>0?e=Math.PI*2+e:e=e-Math.PI*2);let s=Math.abs(e-this.bmap.context.control.getAzimuthalAngle());if(s<.01)return;let{control:o}=this.bmap.context,n=t/Math.PI*6*s;return ft(new Promise(r=>{let h={azimuthal:o.getAzimuthalAngle()},c={azimuthal:e},l=o.getPolarAngle(),{maxPolarAngle:p,minPolarAngle:d}=o;o.maxPolarAngle=l,o.minPolarAngle=l;let u=new Mo(h,this.tweenUtil.group).to(c,n).easing(dd.Quadratic.InOut).onUpdate(()=>f(this,null,function*(){this.startPoi&&o.target.copy(this.startPoi.position),o.setAzimuthalAngle(h.azimuthal,!0),o.setTargetByOffset(this.options.offsetY)})).onComplete(()=>{o.enabled=!0,this.tweenUtil.remove(u),o.maxPolarAngle=p,o.minPolarAngle=d,r(!0)}).onStart(()=>{o.enabled=!1}).start()}),n+500).finally(()=>{this.bmap.context.control.enabled=!0})})}initNavigationCamera(t){return f(this,null,function*(){t===void 0&&(t=1e3);var e;let s=(e=this.taskQueue.getTasks().find(n=>n.meta.type==="initNavigationCamera"))==null?void 0:e.tid,o={run:()=>ft(f(this,null,function*(){yield this.initCameraZoom(t/2),this.options.disablePathRotate||(yield this.changeCameraToPathUp(t/4)),yield this.translateCameraToStartPoi(t/(this.options.disablePathRotate?2:4))}),t+500).finally(()=>{this.bmap.context.control.enabled=!0}),meta:{type:"initNavigationCamera"}};s?this.taskQueue.replace(s,o):this.taskQueue.add(o)})}translateCameraToStartPoi(t){return f(this,null,function*(){if(t===void 0&&(t=100),!this.startPoi)return;let{clientSize:{width:e,height:i},camera:s,control:o}=this.bmap.context,n=Math.round(e/2),r=Math.round(i/2),h=o.target.clone(),c=C(this.startPoi.position,s,e,i),l=c.x-n,p=r-c.y+this.options.offsetY;if(!(Math.abs(l)<=1&&Math.abs(p)<=1)){if(Math.abs(l)>=1){let d=new bt;d.setFromMatrixColumn(s.matrix,0),d.normalize(),d.multiplyScalar(l/s.zoom),h.add(new bt(d.x,d.y,0))}if(Math.abs(p)>=1){let d=new bt;d.setFromMatrixColumn(s.matrix,1),d.normalize(),d.multiplyScalar(p/s.zoom),h.add(new bt(d.x,d.y,0))}return ft(new Promise(d=>{let u=o.target.clone();console.log(u,h,t);let m=new Mo(u,this.tweenUtil.group).to(h,t).onUpdate(()=>{this.bmap.context.control.setCameraPositionByTarget(u,0)}).onComplete(()=>{this.bmap.context.control.setCameraPositionByTarget(h,0),this.tweenUtil.remove(m),this.bmap.context.control.enabled=!0,d(!0)}).onStart(()=>{this.bmap.context.control.enabled=!1}).start()}),t+500).then(()=>{this.bmap.context.control.enabled=!0})}})}initCameraZoom(t){return f(this,null,function*(){if(t===void 0&&(t=100),!this.startPoi)return;let{clientSize:{width:e,height:i},currentFloor:s}=this.bmap.context,{max:o,min:n}=s.box,h=Math.min(e/(o.x-n.x),i/(o.y-n.y))*(o.x-n.x)/this.options.navigationCameraBasic;return this.bmap.context.setZoom(h,this.startPoi.position,t).finally(()=>{this.bmap.context.control.enabled=!0})})}toPosition(t,e){if(this.paths[this.curPathIndex]&&this.paths[this.curPathIndex].floor===t&&this.detachStartPoi){let i=this.translatePoints([e]);this.detachStartPoi.position.setX(i[0][0]),this.detachStartPoi.position.setY(i[0][1]),this.detachLine&&this.startPoi&&this.detachLine.setPosition(this.startPoi.position,this.detachStartPoi.position)}this.options.canBack&&(this.positionNavigation.pointIndex=0,this.positionNavigation.position=this.paths[this.curPathIndex].points[0]),this.positionNavigation.toPosition(t,e)}startSimulation(){this.positionNavigation.startSimulation()}setSimulationSpeed(t){this.positionNavigation.changeSimulationSpeed(t)}toPositionBySpeed(t,e){return f(this,null,function*(){let{currentPathPosition:i,curFloorPath:s,curFloorPathPoints:o}=this;if(!s||!i)return null;let n=this.movedDistance,r=sn(o,t);if(n===-1||r===-1||!this.options.canBack&&r<=n)return null;let h=r-n;if(!h)return;let c=Math.min(Math.abs(h)/e,this.options.runAnimationMaxTime);return this.pathTween&&this.clearTween(),ft(new Promise(l=>{let p=this.pathTween=new Mo({distance:0},this.tweenUtil.group).to({distance:h},c*1e3).onUpdate(d=>f(this,null,function*(){this.moveDistance(d.distance+n,p)})).onComplete(()=>{this.tweenUtil.remove(p),l(!0)}).start()}),c*1e3+500).finally(()=>{this.bmap.context.control.enabled=!0})})}moveDistance(t,e){return f(this,null,function*(){if(this.movedDistance=t,!this.options.disablePathShorten){var i;(i=this.path)==null||i.movePath(this.movedDistance/this.curFloorPathLength)}let s=ve(this.curFloorPathPoints,this.movedDistance);if(s===null)return;this.currentPathPosition=s;let o=this.translatePoints([s])[0];this.startPoi&&(this.setStartPoiPosition(o[0],o[1]),this.options.disablePathAnimation||this.bmap.context.control.setTargetByOffset(this.options.offsetY,this.startPoi.position.clone())),!this.options.disablePathAnimation&&!this.options.disablePathRotate&&(e==null||e.pause(),yield this.changeCameraToPathUp(500/this.options.speed),e==null||e.resume())})}removeDetachStart(){if(this.detachLine&&(this.bmap.context.scene.remove(this.detachLine),this.detachLine.dispose(),this.detachLine=null),this.detachStartPoi){var t;(t=this.bmap.context.currentFloor)==null||t.poiLayer2.removePoi(this.detachStartPoi),this.detachStartPoi=null}}hideDetachStart(){this.showDetachStartState=!1,this.removeDetachStart()}showDetachStart(){if(!this.detachStartPoi&&(this.showDetachStartState=!0,this.path&&this.startPoi&&this.options.detachStartPoi)){var t;let e=this.startPoi.position;this.detachStartPoi=new j(this.bmap.context,w({},this.options.detachStartPoi,{id:"navigation_detach_start_poi",position:e,collision_enable:!1}))||null,(t=this.bmap.context.currentFloor)==null||t.poiLayer2.pushPoi(this.detachStartPoi),this.detachLine=new $e(this.bmap.context,new bt(e.x,e.y,.51),new bt(e.x,e.y,.51)),this.bmap.context.scene.add(this.detachLine)}}setStartPoiRotate(t){this.startPoiRotate=t;let i=(this.bmap.context.control.getAzimuthalAngle()*180/Math.PI+360)%360,s=(360-t-i)%360;this.detachStartPoi&&(this.detachStartPoi.options.icon_rotate=s),this.startPoi&&(this.startPoi.options.icon_rotate=s,this.startRotateHelperPoi&&this.startRotateHelperPoi.setAngle(s))}dispose(){var t;if(this.path&&(this.bmap.context.scene.remove(this.path),this.path.dispose()),this.hideDetachStart(),this.startPoi){var e;(e=this.bmap.context.currentFloor)==null||e.poiLayer2.removePoi(this.startPoi),this.startPoi=null}this.tweenUtil.dispose(),this.unRegistryEvent(),(t=this.startRotateHelperPoi)==null||t.dispose(),Vt.dispose(),this.positionNavigation.dispose(),this.startRotateHelperPoi=null,super.dispose()}constructor(t,e={},i){super(t),this.path=null,this.fetchRoadStatus=!1,this.paths=[],this.curPathIndex=0,this.curFloorPath=null,this.translatePath=null,this.currentPathPosition=null,this.toPointPosition=null,this.pathTween=null,this.startPoi=null,this.detachStartPoi=null,this.detachLine=null,this.startPoiRotate=null,this.startRotateHelperPoi=null,this.needStartRotateHelperPoi=!1,this.showDetachStartState=!0,this.movedDistance=0,this.pathStart=[0,0],this.tweenUtil=new Qt,this.taskQueue=new we,this.animationPathOptions={cPathIndex:0},this.cPath=[],this.onNavigationInfo=s=>{let{info:o}=s;if(this.dispatchEvent({type:"navigation-info",info:o}),!o.offset){if(o.routeIndex!==this.curPathIndex)return;this.toPointPosition=o.pos,this.toPositionByTask(o.pos)}},this.onUpdate=()=>{this.tweenUtil.update()},this.onSwitchFloor=s=>{let{data:{curFloor:o}}=s;if(this.clearTween(),this.paths[this.curPathIndex]){let n=this.paths[this.curPathIndex];this.setCurFloorPath(n!=null?n:null),n?this.renderPath(this.translatePoints(n.points)):this.clearPath()}else this.clearPath()},this.onControlChangeForStartPoi=()=>{this.startPoi&&this.startPoiRotate!==null&&this.setStartPoiRotate(this.startPoiRotate)},!i&&typeof e=="object"&&(i=e),this.options=Object.assign({},md,i),this.positionNavigation=new gs(this,w({simulationSpeed:this.options.speed},this.options.positionNavigation),this.options.roadData),this.registryEvent()}};import"core-js/modules/web.dom-collections.iterator.js";import{Group as fd,Color as Cr}from"three";var Tr=class extends B{show(t,e){let i=0;t.forEach(n=>{n.onAddToScene("mulFloors"),n.position.z=i,i+=n.userData.height,n.poiLayer2.pois.forEach(r=>{r.options.depth_test=!0})});let{scene:s,currentFloor:o}=this.bmap.context;s.background=new Cr((e==null?void 0:e.backgroundColor)||"#f1f7f6"),o&&(s.remove(o),o.dispose()),this.group.add(...t),s.add(this.group),this.floors=t,this.fitCamera(),this.bmap.context.cameraBound.updateBox(),this.showStatus=!0,this.bmap.context.forceUpdate()}showStep(t,e){return this.show(t,e)}hide(){let{scene:t}=this.bmap.context;t.remove(this.group),this.floors.forEach(e=>{e.dispose()}),this.floors=[],this.group.clear(),this.showStatus=!1}showByNotDispose(t,e,i){i===void 0&&(i=()=>!0);let s=0;t.forEach(r=>{[...r.poiLayer2.pois].forEach(h=>{if(!i(h)){h.visible=!1;return}h.options.depth_test=!0}),r.position.z=s,s+=r.userData.height,r.onAddToScene("mulFloors")});let{scene:o,currentFloor:n}=this.bmap.context;o.background=new Cr((e==null?void 0:e.backgroundColor)||"#f1f7f6"),n&&o.remove(n),this.group.add(...t),o.add(this.group),this.floors=t,this.fitCamera(),this.bmap.context.cameraBound.updateBox(),this.showStatus=!0,this.bmap.context.forceUpdate()}hideByNotDispose(){let{scene:t}=this.bmap.context;t.remove(this.group),this.floors.forEach(e=>{e.poiLayer2.pois.forEach(i=>{i.visible=!0,i.options.depth_test=!1})}),this.floors.forEach(e=>{e.position.z=0,e.onRemoveFromScene()}),this.group.clear(),this.showStatus=!1}fitCamera(){let{context:t,config:e}=this.bmap;t.cameraBound.setEnable(!1),t.control.minZoom=0,t.control.maxZoom=1/0,t.camera.zoom=1,t.setAzimuthalAngle(e.control.defaultAzimuthal,0),t.setPolarAngle(e.control.defaultPolar,0),t.fitCameraToObject(this.group,e.defaultPadding,0,!1);let i=t.camera.zoom;t.control.minZoom=i,t.control.maxZoom=i*e.control.maxZoomScale,this.bmap.basicZoom=t.camera.zoom,t.control.addEventListener("change",this.bmap.onControlChange),this.bmap.onControlChange(),t.cameraBound.setEnable(!0)}dispose(){this.floors.forEach(t=>t.dispose()),this.floors=[],super.dispose()}constructor(t){super(t),this.floors=[],this.group=new fd,this.showStatus=!1,this.group.name="mul-floor-group"}};import{EventDispatcher as gd}from"three";function _o(){return new Worker(new URL("./worker/path.worker-C7N3AIZ3.js",import.meta.url))}var ys=class extends gd{setLiftPriority(t){return F(this.worker,"onSetLiftPriority",t)}loaded(){return new Promise(t=>{if(this.initRoadStatus)t(!0);else{let e=i=>{let{status:s}=i;s&&(this.removeEventListener("init-road-status",e),t(!0))};this.addEventListener("init-road-status",e)}})}setRoadData(t,e){return f(this,null,function*(){this.initRoadStatus=!1,this.dispatchEvent({type:"init-road-status",status:!1}),yield F(this.worker,"set_road_info",{roadData:t,facilities:e}),this.initRoadStatus=!0,this.dispatchEvent({type:"init-road-status",status:!0})})}getPath(t,e,i,s,o,n){return f(this,null,function*(){return i===void 0&&(i=""),new Promise((r,h)=>{let c=()=>{F(this.worker,"get_path",{start:t,end:e,type:i,permission:s,travelDirection:o,options:n}).then(l=>{l?typeof l=="string"?h(l):r(l):h("no-path")})};if(this.initRoadStatus)c();else{let l=p=>{let{status:d}=p;d&&(this.removeEventListener("init-road-status",l),c())};this.addEventListener("init-road-status",l)}})})}getDirectionPath(t){return F(this.worker,"get_direction_path",t)}dispose(){return f(this,null,function*(){F(this.worker,"clear",""),this.worker.terminate()})}constructor(){super(),this.worker=_o(),this.initRoadStatus=!1}};import{EventDispatcher as yd}from"three";function Po(){return new Worker(new URL("./worker/cr-path.worker-RCWZ3ILJ.js",import.meta.url))}var kr=class extends yd{setRoadData(t){return f(this,null,function*(){this.initRoadStatus=!1,this.dispatchEvent({type:"init-road-status",status:!1}),yield F(this.worker,"set_road_info",{roadData:t}),this.initRoadStatus=!0,this.dispatchEvent({type:"init-road-status",status:!0})})}getPath(t,e,i){return f(this,null,function*(){return i===void 0&&(i=""),new Promise((s,o)=>{let n=()=>{F(this.worker,"get_path",{start:t,end:e,type:i}).then(r=>{r?typeof r=="string"?o(r):s(r):o("no-path")})};if(this.initRoadStatus)n();else{let r=h=>{let{status:c}=h;c&&(this.removeEventListener("init-road-status",r),n())};this.addEventListener("init-road-status",r)}})})}getDirectionPath(t){return F(this.worker,"get_direction_path",t)}dispose(){return f(this,null,function*(){F(this.worker,"clear",""),this.worker.terminate()})}constructor(){super(),this.worker=Po(),this.initRoadStatus=!1}};import"core-js/modules/web.dom-collections.iterator.js";import"core-js/modules/es.set.difference.v2.js";import"core-js/modules/es.set.intersection.v2.js";import"core-js/modules/es.set.is-disjoint-from.v2.js";import"core-js/modules/es.set.is-subset-of.v2.js";import"core-js/modules/es.set.is-superset-of.v2.js";import"core-js/modules/es.set.symmetric-difference.v2.js";import"core-js/modules/es.set.union.v2.js";import"core-js/modules/es.array.push.js";import{Frustum as vd}from"three";var vs=class extends vt{setEnable(t){super.setEnable(t),ot(this.rect,0,0,0,0),t?this.registryEvent():(this.startPoint=void 0,this.unRegistryEvent())}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:s}}}=this,o=C(this.startPoint,e,i,s),n=C(this.endPoint,e,i,s),r={x:Math.min(o.x,n.x),y:Math.min(o.y,n.y)},h={x:Math.max(o.x,n.x),y:Math.max(o.y,n.y)},c=this.searchMapInFrustum(r,h);this.dispatchEvent({type:"selected",list:c})}}searchMapInFrustum(t,e){var i;let{context:s}=this;return((i=s.currentFloor)==null?void 0:i.graphicLayer.children.filter(o=>o instanceof J&&this.searchChildInFrustum(o,t,e)))||[]}searchChildInFrustum(t,e,i){let{context:{camera:s,container:{clientWidth:o,clientHeight:n}}}=this;if(!t)return!1;if(!t.mesh){let d=t.getPosition();if(d){let u=C(d,s,o,n);return Yt(u,e,i)}return!1}t.mesh.geometry.boundingBox||t.mesh.geometry.computeBoundingBox();let r=t.mesh.geometry.boundingBox;if(!r)return!1;let{min:h,max:c}=r,l=C(h,s,o,n),p=C(c,s,o,n);return!(!Yt(l,e,i)||!Yt(p,e,i))}dispose(){super.dispose(),this.rect=null,this.unRegistryEvent()}constructor(t){super(t),this.frustum=new vd,this.onPointerDown=s=>{if(!this.enable)return;let o=this.getIntersectByPointerEvent(s);o&&(this.startPoint=o),this.endPoint=void 0},this.onPointerMove=s=>{if(!this.enable||!this.startPoint)return;let o=this.getIntersectByPointerEvent(s);o&&(this.endPoint=o)},this.onPointerUp=s=>{if(!this.enable)return;let o=this.getIntersectByPointerEvent(s);o&&(this.endPoint=o),this.doSelect(),this.startPoint=void 0},this.onUpdate=()=>{if(this.startPoint){let s=this.getSvgCoordinate(this.startPoint),o=w({},s);this.endPoint&&(o=this.getSvgCoordinate(this.endPoint));let n={x:Math.min(s.x,o.x),y:Math.min(s.y,o.y)},r=Math.abs(o.x-s.x),h=Math.abs(o.y-s.y);ot(this.rect,n.x,n.y,r,h)}else ot(this.rect,0,0,0,0)};let{config:{selectBox:{fill:e,stroke:i}}}=t;this.rect=qt(i,e),this.svg.appendChild(this.rect),this.registryEvent()}};var xd={boxSelection:!1,elements:["graphic","poi"]},Dr=class extends B{get list(){return this._list}enableBoxSelection(){this.isMultipleSelect||!this.options.boxSelection||(this.isMultipleSelect=!0,this.boxSelection.setEnable(!0),this.prevPanStatus=this.bmap.context.control.enablePan,this.prevRotateStatus=this.bmap.context.control.enableRotate,this.bmap.context.control.enablePan=!1,this.bmap.context.control.enableRotate=!1)}disableBoxSelection(){this.isMultipleSelect&&(this.isMultipleSelect=!1,this.boxSelection.setEnable(!1),this.bmap.context.control.enablePan=!!this.prevPanStatus,this.bmap.context.control.enableRotate=!!this.prevRotateStatus)}selectEnd(){this.dispatchEvent({type:"select",graphics:[...this._list],pois:[...this._poiList],isMultipleSelect:this.isMultipleSelect})}registryEvent(){this.bmap.context.container.addEventListener("pointerdown",this.onPointerDown),this.bmap.context.container.addEventListener("pointerup",this.onPointerUp),this.bmap.context.container.addEventListener("pointerout",this.onPointerOut),this.bmap.context.container.addEventListener("pointercancel",this.onPointerOut),window.addEventListener("keydown",this.onKeyDown),window.addEventListener("keyup",this.onKeyUp),this.boxSelection.addEventListener("selected",this.onBoxSelected)}unRegistryEvent(){this.bmap.context.container.removeEventListener("pointerdown",this.onPointerDown),this.bmap.context.container.removeEventListener("pointerup",this.onPointerUp),this.bmap.context.container.removeEventListener("pointerout",this.onPointerOut),this.bmap.context.container.removeEventListener("pointercancel",this.onPointerOut),window.removeEventListener("keydown",this.onKeyDown),window.removeEventListener("keyup",this.onKeyUp),this.boxSelection.removeEventListener("selected",this.onBoxSelected)}clear(){this._list.clear()}remove(t){this._list.delete(t)}dispose(){this.unRegistryEvent(),super.dispose()}constructor(t,e={}){super(t),this._list=new Set,this._poiList=new Set,this.downPoint=null,this.isMultipleSelect=!1,this.onPointerDown=i=>{this.downPoint={x:i.offsetX,y:i.offsetY}},this.onPointerUp=i=>{if(!this.downPoint)return;let{offsetX:s,offsetY:o}=i,{x:n,y:r}=this.downPoint;if(Math.sqrt((n-s)**2+(r-o)**2)>3)return;let h=new Set,c=[],l=[];if(this.options.elements.includes("graphic")){let{graphics:p}=this.bmap.context.getGraphicsByDeviceXy(s,o);p.map(d=>h.add(d.options.id)),c.push(...p)}if(this.options.elements.includes("poi")){let p=this.bmap.context.getPoisByDeviceXy(s,o);l.push(...p),p.forEach(d=>{if(!h.has(d.options.id)){var u;let m=((u=this.bmap.context.currentFloor)==null?void 0:u.graphicLayer.graphicMap.get(d.options.id))||null;m&&(h.add(d.options.id),c.push(m))}})}(!this.options.boxSelection||!(ge?i.metaKey:i.ctrlKey))&&(this._list.clear(),this._poiList.clear()),c.forEach(p=>this._list.add(p)),l.forEach(p=>this._poiList.add(p)),this.selectEnd(),this.downPoint=null},this.onPointerOut=i=>{this.disableBoxSelection()},this.onKeyDown=i=>{ye(i.key)&&this.enableBoxSelection()},this.onKeyUp=i=>{ye(i.key)&&this.disableBoxSelection()},this.onBoxSelected=i=>{let{list:s}=i;this._list.clear(),this._poiList.clear(),s.forEach(o=>{if(this.options.elements.includes("graphic")&&this._list.add(o),this.options.elements.includes("poi")){let n=this.bmap.getPoiById(o.options.id);n&&this._poiList.add(n)}}),this.selectEnd()},this.options=w({},xd,e),this.boxSelection=new vs(this.bmap.context),this.boxSelection.setEnable(!1),this.registryEvent()}};import"core-js/modules/es.array.push.js";import{cloneDeep as wd,isNil as ee,throttle as Ar}from"lodash";var O=function(a){return a.COMPASS="compass",a.DEVICE_MOTION="deviceMotion",a.ACCELERATION="acceleration",a.GPS="gps",a}({});var Md={time:1e3,elements:[O.COMPASS,O.DEVICE_MOTION,O.ACCELERATION,O.GPS]},xs=class extends X{start(){this.options.elements.some(t=>[O.DEVICE_MOTION,O.COMPASS].includes(t))&&this.listenDeviceOrientation(),this.options.elements.includes(O.ACCELERATION)&&this.listenAcceleration(),this.options.elements.includes(O.GPS)&&this.listenGps(),this.dispatchEvent({type:"start"}),this.dispatchTimer=this.timer.setInterval(()=>{this.dispatchEvent({type:"sensor-data",data:wd(this.data)}),this.data=[]},this.options.time)}addDataItem(t){this.data.push(t),this.dispatchEvent({type:"add-data-item",item:t})}listenDeviceOrientation(){Ut?window.addEventListener("deviceorientation",this.deviceOrientationAbsHandler,!1):window.addEventListener("deviceorientationabsolute",this.deviceOrientationAbsHandler,{absolute:!0})}listenAcceleration(){window.addEventListener("devicemotion",this.handleAcceleration,!1)}listenGps(){this.gpsTimer=navigator.geolocation.watchPosition(t=>{console.log("watch gps",t.coords),this.addDataItem({type:O.GPS,timestamp:Date.now(),res:[t.coords.longitude,t.coords.latitude,t.coords.accuracy]})},t=>{console.log("\u83B7\u53D6gps\u5931\u8D25",t)},{enableHighAccuracy:!0})}checkSensor(){return f(this,null,function*(){return{deviceOrientation:yield this.checkDeviceOrientation()}})}checkDeviceOrientation(){return f(this,null,function*(){var t;if(!Ut)return!0;if(typeof window.DeviceOrientationEvent!="undefined"&&typeof((t=window.DeviceOrientationEvent)==null?void 0:t.requestPermission)=="function")try{var e;return(yield(e=window.DeviceOrientationEvent)==null?void 0:e.requestPermission())==="granted"}catch(i){return!1}return!1})}stop(){window.removeEventListener("devicemotion",this.handleAcceleration,!1),Ut?window.removeEventListener("deviceorientation",this.deviceOrientationAbsHandler,!1):window.removeEventListener("deviceorientationabsolute",this.deviceOrientationAbsHandler,{absolute:!0}),ee(this.gpsTimer)||navigator.geolocation.clearWatch(this.gpsTimer),this.dispatchTimer&&this.timer.clearInterval(this.dispatchTimer),this.data=[],this.dispatchEvent({type:"stop"})}constructor(t={}){super(),this.gpsTimer=null,this.data=[],this.timer=new z,this.dispatchTimer=null,this.addAcceleration=Ar(e=>{this.addDataItem(e)},20),this.deviceOrientationAbsHandler=Ar(e=>{let i=Date.now(),{alpha:s,beta:o,gamma:n}=e;if(ee(s)||ee(o)||ee(n))return;let r;Ut?r=e.webkitCompassHeading:r=360-s,this.options.elements.includes(O.DEVICE_MOTION)&&this.addDataItem({type:O.DEVICE_MOTION,timestamp:i,res:[s,o,n]}),this.options.elements.includes(O.COMPASS)&&this.addDataItem({type:O.COMPASS,timestamp:i,res:r})},200),this.handleAcceleration=e=>{let i=e.accelerationIncludingGravity;ee(i)||ee(i.x)||ee(i.y)||ee(i.z)||this.addAcceleration({type:O.ACCELERATION,timestamp:Date.now(),res:[i.x,i.y,i.z]})},this.options=w({},Md,t)}};import"core-js/modules/web.dom-collections.iterator.js";import"core-js/modules/es.array.push.js";import"core-js/modules/es.array.push.js";import"core-js/modules/web.dom-collections.iterator.js";function ws(a,t){return 1/Math.sqrt(2*Math.PI*Math.pow(t,2))*Math.exp(-Math.pow(a,2)/(2*Math.pow(t,2)))}function ii(a){return(a+360)%360}function Or(a,t){let i=6378137*a*Math.PI/180,s=6378137*Math.log(Math.tan(Math.PI/4+t*Math.PI/180/2));return{x:i,y:s}}function Re(a,t,e,i){return Math.sqrt(Math.pow(Math.abs(a-e),2)+Math.pow(Math.abs(t-i),2))}var Ms=class{motionModelRotYaw(t){if(!(Math.abs(t)<.001)){this.last_yaw_compass=ii(this.last_yaw_compass+t);for(let e=0;e<this.NumParticle;e++){let i=Math.random()*this.yaw_noise_sigma;this.particleX[2][e]=this.particleX[2][e]+t+i,this.particleX[2][e]=ii(this.particleX[2][e])}}}motionModelStepLength(t,e){if(t===0)return;for(let s=0;s<this.NumParticle;s++){let o=Math.random()*this.step_noise_sigma;this.particleX[0][s]+=(.65+o)*Math.sin(-this.particleX[2][s]/180*Math.PI),this.particleX[1][s]+=(.65+o)*Math.cos(this.particleX[2][s]/180*Math.PI),e(this.particleX[0][s],this.particleX[1][s])||(this.particleWeight[0][s]*=this.unaccess_weight)}let i=this.particleWeight[0].reduce((s,o)=>s+o,0);this.particleWeight[0]=this.particleWeight[0].map(s=>s/i)}motionModelCompassYaw(t,e){if(e-this.last_compass_time>this.compass_update_interval){let i=360-t;i+=this.delta_yaw,i=ii(i),Math.abs(i-this.last_yaw_compass)>60?this.compass_consecutive_offset_count++:this.compass_consecutive_offset_count=0;for(let o=0;o<this.NumParticle;o++){let n=Math.abs(this.particleX[2][o]-i);n>180&&(n=360-n),this.particleWeight[0][o]*=ws(n,this.sigmaCompass)}let s=this.particleWeight[0].reduce((o,n)=>o+n,0);this.particleWeight[0]=this.particleWeight[0].map(o=>o/s),this.setLastCompassTime(e)}}resampling(){if(1/this.particleWeight[0].reduce((e,i)=>e+i*i,0)<this.reSampNumParticle){let e=this.particleWeight[0].reduce((r,h,c)=>r.concat(r[c]+h),[0]),s=this.particleWeight[0].map(()=>1/this.NumParticle).map((r,h)=>r+Math.random()/this.NumParticle),o=[],n=0;for(let r=0;r<this.NumParticle;r++){for(;s[r]>e[n];)n++;o.push(n)}this.particleX=this.particleX.map((r,h)=>o.map(c=>r[c])),this.particleWeight[0]=Array(this.NumParticle).fill(1/this.NumParticle)}}update(t,e){for(let s=0;s<this.NumParticle;s++){let o=Re(this.particleX[0][s],this.particleX[1][s],t.x,t.y);this.particleWeight[0][s]=Math.max(1e-7,this.particleWeight[0][s]*ws(o,e))}let i=this.particleWeight[0].reduce((s,o)=>s+o,0);this.particleWeight[0]=this.particleWeight[0].map(s=>s/i)}updateCar(t,e){let i=t.x-this.xEst[0][0],s=t.y-this.xEst[1][0];for(let n=0;n<this.NumParticle;n++){let r=Re(this.particleX[0][n],this.particleX[1][n],t.x,t.y);this.particleWeight[0][n]=Math.max(1e-7,this.particleWeight[0][n]*ws(r,e)),this.particleX[0][n]+=i,this.particleX[1][n]+=s}let o=this.particleWeight[0].reduce((n,r)=>n+r,0);this.particleWeight[0]=this.particleWeight[0].map(n=>n/o)}getPosInitFlag(){return this.particle_PosInitFlag}getYawInitFlag(){return this.particle_yawInitFlag}setPosInitFlag(t){this.particle_PosInitFlag=t}setYawInitFlag(t){this.particle_yawInitFlag=t}getResultX(){let t=[0,0,0];for(let e=0;e<3;e++)for(let i=0;i<this.NumParticle;i++)t[e]+=this.particleX[e][i]*this.particleWeight[0][i];return this.xEst=t.map(e=>[e]),this.xEst[0][0]}getResultY(){return this.xEst[1][0]}getResultYaw(){let t=this.particleWeight[0].indexOf(Math.max(...this.particleWeight[0]));return this.particleX[2][t]}getEstConfidence(){let t=this.particleWeight[0].indexOf(Math.max(...this.particleWeight[0])),e=this.particleWeight[0].indexOf(Math.min(...this.particleWeight[0])),i=[this.particleX[0][t],this.particleX[1][t]],s=[this.particleX[0][e],this.particleX[1][e]],o=Re(i[0],i[1],s[0],s[1]),n=o*.67;return console.log(o,n),n}getParticleNum(){return this.NumParticle}getParticleX(){return this.particleX}setLastCompassTime(t){this.last_compass_time=t}getLastCompassTime(){return this.last_compass_time}initParticlesByPos(t,e,i){if(!this.particle_PosInitFlag){this.particleWeight[0]=Array(this.NumParticle).fill(1/this.NumParticle);let s=0;for(;s<this.NumParticle;){let n=(2*Math.random()-1)*this.initial_xy_uncertainty,r=(2*Math.random()-1)*this.initial_xy_uncertainty;i(t+n,e+r)||(this.particleWeight[0][s]*=this.unaccess_weight),this.particleX[0][s]=t+n,this.particleX[1][s]=e+r,s++}let o=this.particleWeight[0].reduce((n,r)=>n+r,0);this.particleWeight[0]=this.particleWeight[0].map(n=>n/o),this.particle_PosInitFlag=!0,this.xEst[0][0]=t,this.xEst[1][0]=e,this.xEst[2][0]=0}}initParticlesByCompass(t){console.log("Init compass: "+t);let e=360-t;e+=this.delta_yaw,e=ii(e),console.log("Init Yaw: "+e);for(let i=0;i<this.NumParticle;i++){let s=(2*Math.random()-1)*this.initial_yaw_uncertainty;this.particleX[2][i]=e+s}this.particle_yawInitFlag=!0,this.xEst[2][0]=e,this.last_yaw_compass=e,this.compass_consecutive_offset_count=0}constructor(t){this.last_yaw_compass=0,this.compass_consecutive_offset_count=0,this.NumParticle=t.NumParticle,this.reSampNumParticle=t.reSampNumParticle,this.initial_xy_uncertainty=t.initial_xy_uncertainty,this.initial_yaw_uncertainty=t.initial_yaw_uncertainty,this.step_noise_sigma=t.step_noise_sigma,this.yaw_noise_sigma=t.yaw_noise_sigma,this.compass_update_interval=t.compass_update_interval,this.sigmaCompass=t.sigmaCompass,this.delta_yaw=t.delta_yaw,this.sigmaBeacon=t.sigmaBeacon,this.unaccess_weight=t.unaccess_weight,this.particle_PosInitFlag=!1,this.particle_yawInitFlag=!1,this.xEst=[[0],[0],[0]],this.particleX=Array.from({length:3},()=>Array(this.NumParticle).fill(0)),this.particleWeight=Array.from({length:1},()=>Array(this.NumParticle).fill(1/this.NumParticle)),this.last_compass_time=0}};import"core-js/modules/es.array.push.js";import"core-js/modules/web.dom-collections.iterator.js";var _s=class{init(){this.fre=100,this.accH_fifo=[],this.accH_time_fifo=[],this.accH_fifo_len=Math.floor(1*this.fre)+1,this.step_count=0,this.state_count=0,this.last_valley_time=0,this.last_peak_time=0,this.last_step_time=0,this.min_step_time=.3,this.max_step_time=1,this.min_peak=10+.5,this.max_valley=10-.5,this.peak_num=0,this.valley_num=0,this.fft_min_amp=.3,this.fft_min_fre=0,this.fft_max_fre=4,this.last_fft_amp=0,this.abnor_start_time=0,this.abnor_fft_detected=!1,this.abnor_peak_time=0,this.abnor_peak_accH=0,this.const_step_length=.65,this.last_rot=[0,0,0],this.delta_rot=[0,0,0],this.last_yaw=0,this.delta_yaw=null,this.delta_rot_sum_fifo=[],this.delta_rot_sum_time_fifo=[],this.delta_yaw_accum=0,this.delta_yaw_accum_timestamp=0,this.delta_yaw_time_threshold=.5,this.last_px=0,this.last_py=0,this.delta_px=0,this.delta_py=0,this.is_moving=!1,this.currentMotionState="UNKNOWN",this.previousMotionState="UNKNOWN",this.acc_variance_buffer=[],this.rot_variance_buffer=[],this.acc_buffer=[],this.walkingCount=0,this.stationaryCount=0,this.phoneUseCount=0,this.stateCounter=0}reset(){this.init()}setInitPose(t){t===void 0&&(t=[0,0]),this.last_px=t[0],this.last_py=t[1],console.info("pdr init pos: "+this.last_px+", "+this.last_py)}setInitYaw(t){t===void 0&&(t=0),this.last_yaw=t}getPos(t,e,i){let s=0;return i.length===3&&(this.delta_yaw=this.getDeltaYawFromRot(t,i)),e.length===3&&(s=this.getStepLength(t,e)),s!==0&&(this.last_px+=this.delta_px,this.last_py+=this.delta_py),[this.last_px,this.last_py]}getDeltaPose(){return[this.delta_px,this.delta_py]}getMotionState(){return this.currentMotionState}getStepLength(t,e){if(e.length<3)return console.warn("acc data less than 3"),0;let i=!1,s=Math.sqrt(Math.pow(e[0],2)+Math.pow(e[1],2)+Math.pow(e[2],2));if(this.accH_fifo.push(s),this.accH_time_fifo.push(t),this.imuFreUpdate(),!this.isMoving(e,this.last_rot))return 0;if(this.accH_fifo.length<this.accH_fifo_len+1)i=!1;else{for(;this.accH_fifo.length>=this.accH_fifo_len+1;)this.accH_fifo.shift(),this.accH_time_fifo.shift();let n=this.PVStepDetec(),r=this.FFTStepDetec(),h=this.recheckState(),c=this.accH_time_fifo[Math.floor(this.accH_time_fifo.length*3/4)];Math.abs(this.abnor_start_time)<.001&&this.abnor_fft_detected?this.abnor_start_time=c:this.abnor_fft_detected||(this.abnor_start_time=0),n&&r&&h?(this.step_count+=1,this.last_step_time=c,i=!0):Math.abs(this.abnor_start_time)>.001&&this.abnor_peak_time-this.abnor_start_time>this.abnor_time_threshold&&this.step_count>1&&this.abnor_peak_time-this.last_step_time>1?(this.step_count+=1,this.last_step_time=c,i=!0):(c-this.last_step_time>2&&(this.state_count=0),i=!1)}if(i){let n=this.last_yaw/180*Math.PI;return this.delta_px=this.const_step_length*Math.cos(n),this.delta_py=this.const_step_length*Math.sin(n),this.const_step_length}else return 0}imuFreUpdate(){if(this.accH_time_fifo.length>2&&(this.accH_time_fifo[this.accH_time_fifo.length-1]-this.accH_time_fifo[this.accH_time_fifo.length-2]<0||this.accH_time_fifo[this.accH_time_fifo.length-1]-this.accH_time_fifo[this.accH_time_fifo.length-2]>10||this.accH_time_fifo[this.accH_time_fifo.length-1]===this.accH_time_fifo[0])&&(console.warn("pdr reset last one time "+this.accH_time_fifo[this.accH_time_fifo.length-1]+" last two time "+this.accH_time_fifo[this.accH_time_fifo.length-2]),this.reset()),this.accH_fifo.length>9||this.fre<15){let t=(this.accH_fifo.length-1)/(this.accH_time_fifo[this.accH_time_fifo.length-1]-this.accH_time_fifo[0]);Math.abs(this.fre-t)>8&&(this.fre=Math.round((t-3)/10)*10,(this.fre<=10||this.fre>=100)&&(console.warn("Frequency Error "+this.fre),this.fre=100),console.debug("Frequency change to "+this.fre),this.accH_fifo_len=Math.floor(1*this.fre)+1)}}recheckState(){return!0}PVStepDetec(){let t=!1,e=this.accH_fifo.slice(Math.floor(this.accH_fifo_len/2)),i=this.accH_time_fifo.slice(Math.floor(this.accH_fifo_len/2)),s=e[Math.floor(e.length/2)],o=i[Math.floor(i.length/2)],n=Math.max(...e),r=Math.min(...e),h=!1,c=!1;return Math.abs(s-r)<.01&&s<this.max_valley&&this.valley_num<=this.peak_num&&(this.last_valley_time===0?c=!0:c=o-this.last_valley_time>this.min_step_time,c&&(this.last_valley_time=o,this.valley_num+=1)),Math.abs(s-n)<.01&&s>this.min_peak&&this.peak_num<=this.valley_num&&(this.last_peak_time===0?h=!0:h=o-this.last_peak_time>this.min_step_time,h&&(this.last_peak_time=o,this.peak_num+=1)),s===n&&s>this.min_peak&&(this.abnor_peak_time=o,this.abnor_peak_accH=s),this.peak_num===this.valley_num&&(h||c)&&(t=!0),t}FFTStepDetec(){return!0}isMoving(t,e){if(t.length<3||e.length<3)return!1;this.acc_buffer.push([...t]),this.acc_buffer.length>this.static_window_size&&this.acc_buffer.shift();let i=Math.sqrt(Math.pow(t[0],2)+Math.pow(t[1],2)+Math.pow(t[2],2));this.acc_variance_buffer.push(i),this.acc_variance_buffer.length>this.static_window_size&&this.acc_variance_buffer.shift();let s=Math.abs(e[0])+Math.abs(e[1])+Math.abs(e[2]);if(this.rot_variance_buffer.push(s),this.rot_variance_buffer.length>this.static_window_size&&this.rot_variance_buffer.shift(),this.acc_variance_buffer.length<10)return this.is_moving;let o=this.acc_variance_buffer.slice(-10),n=this.rot_variance_buffer.slice(-10),r=this.calculateMean(o),h=this.calculateStdDeviation(o),c=this.calculateMean(n),l=this.calculateStdDeviation(n),p;return r>this.walkingThreshold&&h>.5?(this.walkingCount++,this.stationaryCount=0,this.phoneUseCount=0,p="WALKING"):r<this.phoneUseThreshold&&c>this.rotationThreshold?(this.phoneUseCount++,this.walkingCount=0,this.stationaryCount=0,p="USING_PHONE"):c<.5?(this.stationaryCount++,this.walkingCount=0,this.phoneUseCount=0,p="STATIONARY"):p="UNKNOWN",p!==this.currentMotionState?(this.stateCounter++,this.stateCounter>=this.stateChangeThreshold&&(this.previousMotionState=this.currentMotionState,this.currentMotionState=p,this.stateCounter=0,console.debug("Motion state changed: "+this.previousMotionState+" -> "+this.currentMotionState),console.debug("Stats: avgAcc="+r.toFixed(2)+", accStdDev="+h.toFixed(2)+", avgRot="+c.toFixed(2)+", rotStdDev="+l.toFixed(2)))):this.stateCounter=0,this.is_moving=this.currentMotionState==="WALKING",this.is_moving}calculateMean(t){return t.length===0?0:t.reduce((e,i)=>e+i,0)/t.length}calculateStdDeviation(t){if(t.length<2)return 0;let e=this.calculateMean(t),s=t.map(o=>{let n=o-e;return n*n}).reduce((o,n)=>o+n,0)/t.length;return Math.sqrt(s)}getMotionStatistics(){let t=this.acc_variance_buffer.slice(-10),e=this.rot_variance_buffer.slice(-10),i=this.calculateMean(t),s=this.calculateMean(e),o=this.calculateStdDeviation(t),n=this.calculateStdDeviation(e);return console.debug("\u8FD0\u52A8\u68C0\u6D4B: avgAcc="+i.toFixed(2)+", accStdDev="+o.toFixed(2)+", avgRot="+s.toFixed(2)+", rotStdDev="+n.toFixed(2)),console.debug("\u72B6\u6001\u5224\u65AD\u6761\u4EF6: \u884C\u8D70(avgAcc>"+this.walkingThreshold+", accStdDev>0.5), \u9759\u6B62(avgRot<0.5), \u624B\u673A(avgAcc<"+this.phoneUseThreshold+", avgRot>"+this.rotationThreshold+")"),console.debug("\u5F53\u524D\u72B6\u6001: "+this.currentMotionState+", \u8BA1\u6570: \u884C\u8D70="+this.walkingCount+", \u9759\u6B62="+this.stationaryCount+", \u624B\u673A="+this.phoneUseCount),{currentState:this.currentMotionState,avgAcceleration:i,avgRotation:s,accStdDeviation:o,rotStdDeviation:n,walkingCount:this.walkingCount,stationaryCount:this.stationaryCount,phoneUseCount:this.phoneUseCount,dataPoints:this.acc_variance_buffer.length,isMoving:this.is_moving}}getDeltaYawFromRot(t,e){if(e.length<3)return console.warn("rot data less than 3"),0;let i=[0,0,0];this.last_rot.length===3&&(i=e.map((r,h)=>r-this.last_rot[h]));for(let r=0;r<e.length;r++)i[r]<-180?i[r]+=360:i[r]>180&&(i[r]-=360);let s=.2;this.delta_rot.length===3?this.delta_rot=this.delta_rot.map((r,h)=>s*r+(1-s)*i[h]):this.delta_rot=i,this.last_rot=e,this.delta_yaw=this.delta_rot[0],this.last_yaw+=this.delta_yaw,this.last_yaw=this.limitYaw(this.last_yaw);let o=this.delta_rot.reduce((r,h)=>r+Math.abs(h),0);this.delta_rot_sum_fifo.push(o),this.delta_rot_sum_time_fifo.push(t),Math.abs(this.delta_rot_sum_time_fifo[this.delta_rot_sum_time_fifo.length-1]-this.delta_rot_sum_time_fifo[0])>1&&(this.delta_rot_sum_fifo.shift(),this.delta_rot_sum_time_fifo.shift()),this.delta_yaw_accum+=this.delta_yaw;let n=0;return Math.abs(this.delta_yaw_accum_timestamp-t)>this.delta_yaw_time_threshold?(n=this.delta_yaw_accum,this.delta_yaw_accum=0,this.delta_yaw_accum_timestamp=t,n):null}limitYaw(t){for(;t<-180;)t+=360;for(;t>180;)t-=360;return t}constructor(){this.fre=100,this.accH_fifo=[],this.accH_time_fifo=[],this.accH_fifo_len=Math.floor(1*this.fre)+1,this.step_count=0,this.state_count=0,this.last_valley_time=0,this.last_peak_time=0,this.last_step_time=0,this.min_step_time=.3,this.max_step_time=1,this.min_peak=10.5,this.max_valley=9.5,this.peak_num=0,this.valley_num=0,this.fft_min_amp=.3,this.fft_min_fre=0,this.fft_max_fre=4,this.last_fft_amp=0,this.abnor_start_time=0,this.abnor_fft_detected=!1,this.abnor_time_threshold=4,this.abnor_peak_time=0,this.abnor_peak_accH=0,this.const_step_length=.85,this.last_rot=[],this.delta_rot=[],this.last_yaw=0,this.delta_yaw=null,this.delta_rot_sum_fifo=[],this.delta_rot_sum_time_fifo=[],this.delta_yaw_accum=0,this.delta_yaw_accum_timestamp=0,this.delta_yaw_time_threshold=.5,this.last_px=0,this.last_py=0,this.delta_px=0,this.delta_py=0,this.is_moving=!1,this.currentMotionState="UNKNOWN",this.previousMotionState="UNKNOWN",this.walkingThreshold=1,this.stationaryThreshold=.6,this.phoneUseThreshold=.7,this.rotationThreshold=.8,this.walkingCount=0,this.stationaryCount=0,this.phoneUseCount=0,this.stateCounter=0,this.stateChangeThreshold=3,this.static_window_size=20,this.acc_variance_buffer=[],this.rot_variance_buffer=[],this.acc_buffer=[]}};var _d={using_gps:!0,gps_max_horizontalAccuracy:20,initial_gps_delay_time:3e3},Ps=class{pfFusionPDRiBeacon(t){let{type:e,timestamp:i,res:s}=t,o=!1;if(this.cacheSensorData.push(t),this.particleFilter.getPosInitFlag()&&this.particleFilter.getYawInitFlag()){if(e===O.ACCELERATION){let n=s,r=this.pdr.getStepLength(i/1e3,n);r!==0&&(this.particleFilter.motionModelStepLength(r,()=>!0),this.particleFilter.resampling(),this.position_count+=1,o=!0)}if(this.using_gps&&e===O.GPS)if(this.last_beacon_time===null||i-this.last_beacon_time>5e3){let n=this.getGpsPosition(s);o=n!==null,n&&(this.particleFilter.update(n,this.gps_horizontalAccuracy),this.resetParticleFilterDist(n,"gps",s[2]),this.particleFilter.resampling(),this.position_count+=1,this.cacheSensorData.length=0)}else return[!1,0,0];if(e===O.DEVICE_MOTION){let n=this.pdr.getDeltaYawFromRot(i/1e3,s);n!==null&&this.particleFilter.motionModelRotYaw(n)}e===O.COMPASS&&this.particleFilter.motionModelCompassYaw(s,i),this.last_pos_time&&i-this.last_pos_time>500&&(this.position_count+=1,o=!0)}else if(!this.particleFilter.getPosInitFlag()&&this.using_gps&&e===O.GPS)if(this.startTime&&Date.now()-this.startTime>this.options.initial_gps_delay_time){let n=this.getGpsPosition(s);o=n!==null,console.log("gps_pos",n,s),n?(this.particleFilter.initParticlesByPos(n.x,n.y,()=>!0),this.last_pos_time=i,console.log("init Pos by gps success time "+i),this.cacheSensorData.length=0):console.log("init Pos by gps fail time "+i)}else this.startTime||(this.startTime=i);else if(!this.particleFilter.getYawInitFlag()&&e===O.COMPASS){let n=s;this.particleFilter.initParticlesByCompass(n),this.particleFilter.setLastCompassTime(i),console.log("init yaw by compass success time "+i)}return o&&(this.last_pos_time=i),[o,this.particleFilter.getResultX(),this.particleFilter.getResultY()]}setBeaconPosition(t,e){if(this.last_beacon_time=e,this.particleFilter.getPosInitFlag())this.particleFilter.update(t,this.sigmaBeacon);else{this.particleFilter.initParticlesByPos(t.x,t.y,()=>!0);let i=this.cacheSensorData.filter(s=>s.timestamp>e);console.log("\u521D\u59CBsensorData",i),i.map(s=>this.pfFusionPDRiBeacon(s))}return this.resetParticleFilterDist(t),this.particleFilter.resampling(),this.position_count+=1,this.cacheSensorData.length=0,[this.particleFilter.getResultX(),this.particleFilter.getResultY()]}getGpsPosition(t){return t[2]>this.gps_max_horizontalAccuracy?null:Or(t[0],t[1])}resetParticleFilterDist(t,e,i){let s=this.particleFilter.getResultX(),o=this.particleFilter.getResultY(),n=Re(s,o,t.x,t.y);(e==="gps"?i&&n>i||n>this.GpsMaxEstimateErr:n>this.MaxEstimateErr)?(this.outTrustRegionNum+=1,this.outTrustRegionNum>=this.TrustNum&&(console.info("\u8D85\u51FA\u53EF\u4FE1\u533A\u57DF\uFF0C\u91CD\u7F6E\u7C92\u5B50\u8FC7\u6EE4\u5668\u5230: "+t.x+", "+t.y),this.particleFilter.setPosInitFlag(!1),this.particleFilter.setYawInitFlag(!1),this.outTrustRegionNum=0,this.startTime=Date.now())):this.outTrustRegionNum=0}constructor(t){this.sigmaBeacon=5,this.gps_horizontalAccuracy=10,this.using_gps=!0,this.last_beacon_time=Date.now(),this.position_count=0,this.gps_max_horizontalAccuracy=20,this.MaxEstimateErr=5,this.GpsMaxEstimateErr=30,this.outTrustRegionNum=0,this.TrustNum=4,this.cacheSensorData=[],this.startTime=null;let e=w({},_d,t);this.options=e,this.using_gps=e.using_gps,this.gps_max_horizontalAccuracy=e.gps_max_horizontalAccuracy,this.particleFilter=new Ms({NumParticle:200,reSampNumParticle:.65,initial_xy_uncertainty:12,initial_yaw_uncertainty:100,step_noise_sigma:.5,yaw_noise_sigma:2,compass_update_interval:3e3,sigmaCompass:80,delta_yaw:2,sigmaBeacon:5,unaccess_weight:.7}),this.pdr=new _s}};import{booleanPointInPolygon as Pd,point as bd}from"@turf/turf";var bs=class extends X{checkSensor(){return this.sensor.checkSensor()}setSensor(t){this.sensor=t}start(){this.sensor.start(),this.pdr.startTime=Date.now(),this.sensor.addEventListener("add-data-item",t=>{let{item:e}=t;this.getPositionBySensorItem(e,!this._pause)})}pause(){this._pause=!0}continue(){this._pause=!1}getPositionBySensorItem(t,e){e===void 0&&(e=!0);let[i,s,o]=this.pdr.pfFusionPDRiBeacon(t);return i&&e&&Pd(bd([s,o]),this.bmap.context.range)&&this.dispatchEvent({type:"position",x:s,y:o,_type:t.type===O.GPS?"gps":"pdr"}),[i,s,o]}setBeaconPosition(t,e){let[i,s]=this.pdr.setBeaconPosition(t,e);this.dispatchEvent({type:"position",x:i,y:s,_type:"beacon"})}dispose(){this.sensor.stop()}constructor(t,e={}){super(),this.bmap=t,this._pause=!1,this.sensor=new xs(e.sensor),this.pdr=new Ps(e.pdr||{})}};import"core-js/modules/web.dom-collections.iterator.js";import"core-js/modules/es.array.push.js";import"core-js/modules/web.dom-collections.iterator.js";import"core-js/modules/es.array.push.js";import"core-js/modules/es.array.flat.js";import"core-js/modules/es.array.unscopables.flat.js";import{Object3D as Ed,TextureLoader as Ld,Color as Cd,Vector2 as bo,Vector3 as Td,NormalBlending as kd,RepeatWrapping as Dd,Box3 as Ad}from"three";import{ShaderLib as Ss,ShaderMaterial as Sd,UniformsLib as Es,UniformsUtils as Rr,Vector2 as Ir}from"three";Es["custom-line"]={linewidth:{value:1},resolution:{value:new Ir(1,1)},dashScale:{value:1},dashSize:{value:1},gapSize:{value:1},repeat:{value:new Ir(1,1)},allDistance:{value:1}};Ss["custom-line"]={uniforms:Rr.merge([Es.common,Es.fog,Es["custom-line"]]),vertexShader:`
508
+ `,document.body.appendChild(a.canvas)}setAngle(t){if(console.log("angle",t),a.textureMap.has(t))this._initIcon(a.textureMap.get(t));else{this.draw(t);let e=this.getTexture(this.getImageData());a.textureMap.set(t,e),this._initIcon(e),this._initScale({zoom:this.bmap.context.camera.zoom})}}_initIcon(t){if(this.spriteIcon)this.spriteIcon.material.map=t,t.needsUpdate=!0;else{let e=new ld(new pd({map:t,transparent:!0,alphaTest:.2,depthTest:this.options.depth_test,rotation:this.options.icon_rotate/180*Math.PI}));e.renderOrder=1e5+this.options.level,t.needsUpdate=!0,this.add(e),e.center.set(.5,.5),this.spriteIcon=e}}initSize(){this.spriteIcon&&this.spriteIcon.center.set(.5,.5)}draw(t){let{ctx:e}=a,{config:{size:i}}=this,s=i[0]/2,o=i[1]/2,n=4,r=1,h=n+r;if(e.clearRect(0,0,i[0],i[1]),e.setLineDash([10,10]),e.strokeStyle="#fff",e.lineWidth=2,e.beginPath(),e.arc(s,o,o-h,-Math.PI/2,Math.PI*2-Math.PI/2,t<Math.PI),e.stroke(),e.strokeStyle="#0A7AFF",t<Math.PI){let c=-Math.PI/2,l=c-t;e.beginPath(),e.arc(s,o,o-h,c,l,!0)}else{let c=-Math.PI/2,l=c+Math.PI*2-t;e.beginPath(),e.arc(s,o,o-h,c,l,!1)}e.stroke(),e.clearRect(s-h*2,0,h*4,h*4),e.beginPath(),e.arc(s,h,n,0,Math.PI*2),e.fillStyle="#0A7AFF",e.fill(),e.setLineDash([10,0]),e.strokeStyle="#fff",e.lineWidth=r,e.stroke(),e.clearRect(0,o-5,10,10),e.clearRect(s-5,i[1]-10,10,10),e.clearRect(i[0]-10,o-5,10,10),t>Math.PI/2&&t<Math.PI?e.fillStyle="#0A7AFF":e.fillStyle="#fff",e.fillRect(0,o-1,10,2),e.fillStyle="#fff",e.fillRect(s-1,i[1]-10,2,10),t>Math.PI&&t<Math.PI/2*3?e.fillStyle="#0A7AFF":e.fillStyle="#fff",e.fillRect(i[0]-10,o-1,10,2)}getImageData(){let{ctx:t}=a,{config:{size:e}}=this;return t.getImageData(0,0,e[0],e[1])}getTexture(t){let{config:{size:e}}=this,i=new cd(Uint8Array.from(t.data),e[0],e[1],Er);return i.format=Er,i.magFilter=Sr,i.minFilter=Sr,i.colorSpace="srgb",i.flipY=!0,i}dispose(){var t;super.dispose(),(t=this.spriteIcon)==null||t.material.dispose()}static dispose(){this.textureMap.forEach(t=>{t.dispose()}),this.textureMap.clear(),this.ctx=null,this.canvas=null}constructor(t,e){super(t.context,{icon_size:e.size,collision_enable:!1,level:2}),this.bmap=t,this.config=e,a.canvas.width=e.size[0],a.canvas.height=e.size[1]}};Vt.canvas=document.createElement("canvas");Vt.ctx=Vt.canvas.getContext("2d",{willReadFrequently:!0});Vt.textureMap=new Map;var md={path:{},cheapMaximumDistance:20,needStartPoi:!1,startPoi:{},positionNavigation:{},offsetY:150,directionEmitThreshold:5,disablePathAnimation:!1,disablePathRotate:!1,disablePathShorten:!1,speed:1,roadData:[],runAnimationMaxTime:1,navigationCameraBasic:45,canBack:!1},Lr=class extends B{get curFloorPathLength(){var t,e;return(e=(t=this.curFloorPath)==null?void 0:t.distance)!=null?e:0}get curFloorPathPoints(){var t,e;return(e=(t=this.curFloorPath)==null?void 0:t.points)!=null?e:[]}registryEvent(){this.bmap.context.addEventListener("update",this.onUpdate),this.bmap.addEventListener(it.SWITCH_FLOOR_GROUND,this.onSwitchFloor),this.positionNavigation.addEventListener("navigation-info",this.onNavigationInfo),this.bmap.context.addEventListener("control-change",this.onControlChangeForStartPoi)}setRoadData(t){this.options.roadData=t,this.positionNavigation.setRoadData(t)}showStartRotateHelperPoi(){var t;if(this.needStartRotateHelperPoi=!0,!this.startPoi||this.startRotateHelperPoi)return;let e=this.startPoi.options.icon_size;this.startRotateHelperPoi=new Vt(this.bmap,{size:[e[0]+20,e[1]+20]}),this.startRotateHelperPoi.setAngle(0),this.startRotateHelperPoi.position.setZ(.51),(t=this.bmap.context.currentFloor)==null||t.poiLayer2.pushPoi(this.startRotateHelperPoi)}hideStartRotateHelperPoi(){if(this.needStartRotateHelperPoi=!1,this.startRotateHelperPoi){var t;(t=this.bmap.context.currentFloor)==null||t.poiLayer2.removePoi(this.startRotateHelperPoi),this.startRotateHelperPoi=null}}setStartPoiPosition(t,e){this.startPoi&&(this.startPoi.position.setX(t).setY(e),this.startRotateHelperPoi&&this.startRotateHelperPoi.position.setX(t).setY(e),this.detachLine&&this.detachLine.setPosition(this.startPoi.position,this.detachStartPoi.position))}resetStatus(){this.pauseAnimation(),this.positionNavigation.resetStatus(this.paths),this.movedDistance=0,this.startPoi&&this.translatePath&&this.setStartPoiPosition(this.translatePath[0][0],this.translatePath[0][1])}toPositionByTask(t){var e;let s=(e=this.taskQueue.getTasks().find(n=>n.meta.type==="toPosition"))==null?void 0:e.tid,o={run:()=>this.toPositionBySpeed(t,this.options.speed),meta:{type:"toPosition"}};s?this.taskQueue.replace(s,o):this.taskQueue.add(o)}pauseAnimation(){this.taskQueue.clear(),this.positionNavigation.pause(),this.tweenUtil.pause()}continueAnimation(){this.tweenUtil.continue(),this.positionNavigation.continue()}clearTween(){this.tweenUtil.clear(),this.taskQueue.clear(),this.bmap.context.control.enabled=!0}unRegistryEvent(){this.bmap.context.removeEventListener("update",this.onUpdate),this.bmap.removeEventListener(it.SWITCH_FLOOR_GROUND,this.onSwitchFloor),this.positionNavigation.removeEventListener("navigation-info",this.onNavigationInfo),this.bmap.context.removeEventListener("control-change",this.onControlChangeForStartPoi)}clearPath(){if(this.resetStatus(),this.path&&(this.bmap.context.scene.remove(this.path),this.path.dispose(),this.path=null,this.clearTween()),this.startPoi){var t;if((t=this.bmap.context.currentFloor)==null||t.poiLayer2.removePoi(this.startPoi),this.startPoi=null,this.startRotateHelperPoi){var e;(e=this.bmap.context.currentFloor)==null||e.poiLayer2.removePoi(this.startRotateHelperPoi),this.startRotateHelperPoi=null}}if(this.detachStartPoi){var i;(i=this.bmap.context.currentFloor)==null||i.removePoi2(this.detachStartPoi),this.detachStartPoi=null}this.detachLine&&(this.bmap.context.scene.remove(this.detachLine),this.detachLine.dispose(),this.detachLine=null),this.translatePath=null}setCurFloorPath(t){t===null?(this.curFloorPath=null,this.currentPathPosition=null,this.toPointPosition=null):(this.curFloorPath=t,this.currentPathPosition=t.points[0],this.toPointPosition=t.points[0]),this.movedDistance=0,this.clearTween()}setCurPathIndex(t){var e,i;this.curPathIndex=t,((e=this.paths[t])==null?void 0:e.floor)===((i=this.bmap.context.currentFloor)==null?void 0:i.name)?(this.setCurFloorPath(this.paths[t]),this.renderPath(this.translatePoints(this.curFloorPathPoints))):this.clearPath()}addPath(t,e){e===void 0&&(e=0);var i;this.paths=t,this.curPathIndex=e,this.clearTween(),this.clearPath();let s=(i=this.bmap.context.currentFloor)==null?void 0:i.name,o=t[e];if(s&&(o==null?void 0:o.floor)===s)if(this.setCurFloorPath(o),this.bmap.currentBuildGround)this.renderPath(this.translatePoints(o.points));else{let n=()=>{this.bmap.removeEventListener("center-change",n),this.renderPath(this.translatePoints(o.points))};this.bmap.addEventListener("center-change",n)}this.dispatchEvent({type:"add-path",paths:t})}translatePoints(t){let[e,i]=this.bmap.buildingCenter;return t.map(s=>[s[0]-e,s[1]-i])}renderPath(t){this.translatePath=t;let e=this.catmullRomCurve3(t);if(this.cPath=e,this.animationPathOptions={cPathIndex:0},this.pathStart=e[0],this.path?this.path.updatePoints(e):(this.path=new fs(this,this.options.path),this.path.create(e),this.path.position.z=this.bmap.context.currentFloor.groundMaxHeight+.5,this.bmap.context.scene.add(this.path)),this.path.movePath(0),this.startPoi){var i;if((i=this.bmap.context.currentFloor)==null||i.poiLayer2.removePoi(this.startPoi),this.startPoi=null,this.startRotateHelperPoi){var s;(s=this.bmap.context.currentFloor)==null||s.poiLayer2.removePoi(this.startRotateHelperPoi),this.startRotateHelperPoi=null}}if(this.removeDetachStart(),this.showDetachStartState&&this.options.detachStartPoi){var o;this.detachStartPoi=new j(this.bmap.context,w({},this.options.detachStartPoi,{id:"navigation_detach_start_poi",position:{x:e[0][0],y:e[0][1],z:.51},collision_enable:!1}))||null,(o=this.bmap.context.currentFloor)==null||o.poiLayer2.pushPoi(this.detachStartPoi),this.detachLine=new $e(this.bmap.context,new bt(e[0][0],e[0][1],.51),new bt(e[0][0],e[0][1],.51)),this.bmap.context.scene.add(this.detachLine)}if(this.options.needStartPoi){var n;this.startPoi=new j(this.bmap.context,w({},this.options.startPoi,{id:"navigation_start_poi",position:{x:e[0][0],y:e[0][1],z:.51},collision_enable:!1}))||null,(n=this.bmap.context.currentFloor)==null||n.poiLayer2.pushPoi(this.startPoi),this.needStartRotateHelperPoi&&this.showStartRotateHelperPoi(),console.log(this.startRotateHelperPoi)}this.dispatchEvent({type:"render-path",path:this.path})}catmullRomCurve3(t){return mi(t,!1,!0,.1,170,2.5)}getPathDirection(){if(!this.curFloorPath||!this.currentPathPosition||this.curFloorPathPoints.length<2)return null;let t=Bt(this.curFloorPathPoints,this.currentPathPosition),e=this.curFloorPathPoints[t],i=this.curFloorPathPoints[t+1],s=new bt(i[0]-e[0],i[1]-e[1],0).normalize(),o=new bt(0,1,0).normalize(),n=s.angleTo(o),r=new bt().crossVectors(o,s);return(Object.is(r.y,0)?-1:1)*n}getPathDirection2(){if(!this.curFloorPath||!this.toPointPosition||this.curFloorPathPoints.length<2)return null;let t=Bt(this.curFloorPathPoints,this.toPointPosition),e=this.curFloorPathPoints[t],i=this.curFloorPathPoints[t+1];return(new ud(i[0]-e[0],i[1]-e[1]).normalize().angle()*180/Math.PI-90+360)%360}changeCameraToPathUp(t){return f(this,null,function*(){t===void 0&&(t=100);let e=this.getPathDirection();if(e===null)return;let i=this.bmap.context.control.getAzimuthalAngle();Math.abs(i-e)>Math.PI&&(i>0?e=Math.PI*2+e:e=e-Math.PI*2);let s=Math.abs(e-this.bmap.context.control.getAzimuthalAngle());if(s<.01)return;let{control:o}=this.bmap.context,n=t/Math.PI*6*s;return ft(new Promise(r=>{let h={azimuthal:o.getAzimuthalAngle()},c={azimuthal:e},l=o.getPolarAngle(),{maxPolarAngle:p,minPolarAngle:d}=o;o.maxPolarAngle=l,o.minPolarAngle=l;let u=new Mo(h,this.tweenUtil.group).to(c,n).easing(dd.Quadratic.InOut).onUpdate(()=>f(this,null,function*(){this.startPoi&&o.target.copy(this.startPoi.position),o.setAzimuthalAngle(h.azimuthal,!0),o.setTargetByOffset(this.options.offsetY)})).onComplete(()=>{o.enabled=!0,this.tweenUtil.remove(u),o.maxPolarAngle=p,o.minPolarAngle=d,r(!0)}).onStart(()=>{o.enabled=!1}).start()}),n+500).finally(()=>{this.bmap.context.control.enabled=!0})})}initNavigationCamera(t){return f(this,null,function*(){t===void 0&&(t=1e3);var e;let s=(e=this.taskQueue.getTasks().find(n=>n.meta.type==="initNavigationCamera"))==null?void 0:e.tid,o={run:()=>ft(f(this,null,function*(){yield this.initCameraZoom(t/2),this.options.disablePathRotate||(yield this.changeCameraToPathUp(t/4)),yield this.translateCameraToStartPoi(t/(this.options.disablePathRotate?2:4))}),t+500).finally(()=>{this.bmap.context.control.enabled=!0}),meta:{type:"initNavigationCamera"}};s?this.taskQueue.replace(s,o):this.taskQueue.add(o)})}translateCameraToStartPoi(t){return f(this,null,function*(){if(t===void 0&&(t=100),!this.startPoi)return;let{clientSize:{width:e,height:i},camera:s,control:o}=this.bmap.context,n=Math.round(e/2),r=Math.round(i/2),h=o.target.clone(),c=C(this.startPoi.position,s,e,i),l=c.x-n,p=r-c.y+this.options.offsetY;if(!(Math.abs(l)<=1&&Math.abs(p)<=1)){if(Math.abs(l)>=1){let d=new bt;d.setFromMatrixColumn(s.matrix,0),d.normalize(),d.multiplyScalar(l/s.zoom),h.add(new bt(d.x,d.y,0))}if(Math.abs(p)>=1){let d=new bt;d.setFromMatrixColumn(s.matrix,1),d.normalize(),d.multiplyScalar(p/s.zoom),h.add(new bt(d.x,d.y,0))}return ft(new Promise(d=>{let u=o.target.clone();console.log(u,h,t);let m=new Mo(u,this.tweenUtil.group).to(h,t).onUpdate(()=>{this.bmap.context.control.setCameraPositionByTarget(u,0)}).onComplete(()=>{this.bmap.context.control.setCameraPositionByTarget(h,0),this.tweenUtil.remove(m),this.bmap.context.control.enabled=!0,d(!0)}).onStart(()=>{this.bmap.context.control.enabled=!1}).start()}),t+500).then(()=>{this.bmap.context.control.enabled=!0})}})}initCameraZoom(t){return f(this,null,function*(){if(t===void 0&&(t=100),!this.startPoi)return;let{clientSize:{width:e,height:i},currentFloor:s}=this.bmap.context,{max:o,min:n}=s.box,h=Math.min(e/(o.x-n.x),i/(o.y-n.y))*(o.x-n.x)/this.options.navigationCameraBasic;return this.bmap.context.setZoom(h,this.startPoi.position,t).finally(()=>{this.bmap.context.control.enabled=!0})})}toPosition(t,e){if(this.paths[this.curPathIndex]&&this.paths[this.curPathIndex].floor===t&&this.detachStartPoi){let i=this.translatePoints([e]);this.detachStartPoi.position.setX(i[0][0]),this.detachStartPoi.position.setY(i[0][1]),this.detachLine&&this.startPoi&&this.detachLine.setPosition(this.startPoi.position,this.detachStartPoi.position)}this.options.canBack&&(this.positionNavigation.pointIndex=0,this.positionNavigation.position=this.paths[this.curPathIndex].points[0]),this.positionNavigation.toPosition(t,e)}startSimulation(){this.positionNavigation.startSimulation()}setSimulationSpeed(t){this.positionNavigation.changeSimulationSpeed(t)}toPositionBySpeed(t,e){return f(this,null,function*(){let{currentPathPosition:i,curFloorPath:s,curFloorPathPoints:o}=this;if(!s||!i)return null;let n=this.movedDistance,r=sn(o,t);if(n===-1||r===-1||!this.options.canBack&&r<=n)return null;let h=r-n;if(!h)return;let c=Math.min(Math.abs(h)/e,this.options.runAnimationMaxTime);return this.pathTween&&this.clearTween(),ft(new Promise(l=>{let p=this.pathTween=new Mo({distance:0},this.tweenUtil.group).to({distance:h},c*1e3).onUpdate(d=>f(this,null,function*(){this.moveDistance(d.distance+n,p)})).onComplete(()=>{this.tweenUtil.remove(p),l(!0)}).start()}),c*1e3+500).finally(()=>{this.bmap.context.control.enabled=!0})})}moveDistance(t,e){return f(this,null,function*(){if(this.movedDistance=t,!this.options.disablePathShorten){var i;(i=this.path)==null||i.movePath(this.movedDistance/this.curFloorPathLength)}let s=ve(this.curFloorPathPoints,this.movedDistance);if(s===null)return;this.currentPathPosition=s;let o=this.translatePoints([s])[0];this.startPoi&&(this.setStartPoiPosition(o[0],o[1]),this.options.disablePathAnimation||this.bmap.context.control.setTargetByOffset(this.options.offsetY,this.startPoi.position.clone())),!this.options.disablePathAnimation&&!this.options.disablePathRotate&&(e==null||e.pause(),yield this.changeCameraToPathUp(500/this.options.speed),e==null||e.resume())})}removeDetachStart(){if(this.detachLine&&(this.bmap.context.scene.remove(this.detachLine),this.detachLine.dispose(),this.detachLine=null),this.detachStartPoi){var t;(t=this.bmap.context.currentFloor)==null||t.poiLayer2.removePoi(this.detachStartPoi),this.detachStartPoi=null}}hideDetachStart(){this.showDetachStartState=!1,this.removeDetachStart()}showDetachStart(){if(!this.detachStartPoi&&(this.showDetachStartState=!0,this.path&&this.startPoi&&this.options.detachStartPoi)){var t;let e=this.startPoi.position;this.detachStartPoi=new j(this.bmap.context,w({},this.options.detachStartPoi,{id:"navigation_detach_start_poi",position:e,collision_enable:!1}))||null,(t=this.bmap.context.currentFloor)==null||t.poiLayer2.pushPoi(this.detachStartPoi),this.detachLine=new $e(this.bmap.context,new bt(e.x,e.y,.51),new bt(e.x,e.y,.51)),this.bmap.context.scene.add(this.detachLine)}}setStartPoiRotate(t){this.startPoiRotate=t;let i=(this.bmap.context.control.getAzimuthalAngle()*180/Math.PI+360)%360,s=(360-t-i)%360;this.detachStartPoi&&(this.detachStartPoi.options.icon_rotate=s),this.startPoi&&(this.startPoi.options.icon_rotate=s,this.startRotateHelperPoi&&this.startRotateHelperPoi.setAngle(s))}dispose(){var t;if(this.path&&(this.bmap.context.scene.remove(this.path),this.path.dispose()),this.hideDetachStart(),this.startPoi){var e;(e=this.bmap.context.currentFloor)==null||e.poiLayer2.removePoi(this.startPoi),this.startPoi=null}this.tweenUtil.dispose(),this.unRegistryEvent(),(t=this.startRotateHelperPoi)==null||t.dispose(),Vt.dispose(),this.positionNavigation.dispose(),this.startRotateHelperPoi=null,super.dispose()}constructor(t,e={},i){super(t),this.path=null,this.fetchRoadStatus=!1,this.paths=[],this.curPathIndex=0,this.curFloorPath=null,this.translatePath=null,this.currentPathPosition=null,this.toPointPosition=null,this.pathTween=null,this.startPoi=null,this.detachStartPoi=null,this.detachLine=null,this.startPoiRotate=null,this.startRotateHelperPoi=null,this.needStartRotateHelperPoi=!1,this.showDetachStartState=!0,this.movedDistance=0,this.pathStart=[0,0],this.tweenUtil=new Qt,this.taskQueue=new we,this.animationPathOptions={cPathIndex:0},this.cPath=[],this.onNavigationInfo=s=>{let{info:o}=s;if(this.dispatchEvent({type:"navigation-info",info:o}),!o.offset){if(o.routeIndex!==this.curPathIndex)return;this.toPointPosition=o.pos,this.toPositionByTask(o.pos)}},this.onUpdate=()=>{this.tweenUtil.update()},this.onSwitchFloor=s=>{let{data:{curFloor:o}}=s;if(this.clearTween(),this.paths[this.curPathIndex]){let n=this.paths[this.curPathIndex];this.setCurFloorPath(n!=null?n:null),n?this.renderPath(this.translatePoints(n.points)):this.clearPath()}else this.clearPath()},this.onControlChangeForStartPoi=()=>{this.startPoi&&this.startPoiRotate!==null&&this.setStartPoiRotate(this.startPoiRotate)},!i&&typeof e=="object"&&(i=e),this.options=Object.assign({},md,i),this.positionNavigation=new gs(this,w({simulationSpeed:this.options.speed},this.options.positionNavigation),this.options.roadData),this.registryEvent()}};import"core-js/modules/web.dom-collections.iterator.js";import{Group as fd,Color as Cr}from"three";var Tr=class extends B{show(t,e){let i=0;t.forEach(n=>{n.onAddToScene("mulFloors"),n.position.z=i,i+=n.userData.height,n.poiLayer2.pois.forEach(r=>{r.options.depth_test=!0})});let{scene:s,currentFloor:o}=this.bmap.context;s.background=new Cr((e==null?void 0:e.backgroundColor)||"#f1f7f6"),o&&(s.remove(o),o.dispose()),this.group.add(...t),s.add(this.group),this.floors=t,this.fitCamera(),this.bmap.context.cameraBound.updateBox(),this.showStatus=!0,this.bmap.context.forceUpdate()}showStep(t,e){return this.show(t,e)}hide(){let{scene:t}=this.bmap.context;t.remove(this.group),this.floors.forEach(e=>{e.dispose()}),this.floors=[],this.group.clear(),this.showStatus=!1}showByNotDispose(t,e,i){i===void 0&&(i=()=>!0);let s=0;t.forEach(r=>{[...r.poiLayer2.pois].forEach(h=>{if(!i(h)){h.visible=!1;return}h.options.depth_test=!0}),r.position.z=s,s+=r.userData.height,r.onAddToScene("mulFloors")});let{scene:o,currentFloor:n}=this.bmap.context;o.background=new Cr((e==null?void 0:e.backgroundColor)||"#f1f7f6"),n&&o.remove(n),this.group.add(...t),o.add(this.group),this.floors=t,this.fitCamera(),this.bmap.context.cameraBound.updateBox(),this.showStatus=!0,this.bmap.context.forceUpdate()}hideByNotDispose(){let{scene:t}=this.bmap.context;t.remove(this.group),this.floors.forEach(e=>{e.poiLayer2.pois.forEach(i=>{i.visible=!0,i.options.depth_test=!1})}),this.floors.forEach(e=>{e.position.z=0,e.onRemoveFromScene()}),this.group.clear(),this.showStatus=!1}fitCamera(){let{context:t,config:e}=this.bmap;t.cameraBound.setEnable(!1),t.control.minZoom=0,t.control.maxZoom=1/0,t.camera.zoom=1,t.setAzimuthalAngle(e.control.defaultAzimuthal,0),t.setPolarAngle(e.control.defaultPolar,0),t.fitCameraToObject(this.group,e.defaultPadding,0,!1);let i=t.camera.zoom;t.control.minZoom=i,t.control.maxZoom=i*e.control.maxZoomScale,this.bmap.basicZoom=t.camera.zoom,t.control.addEventListener("change",this.bmap.onControlChange),this.bmap.onControlChange(),t.cameraBound.setEnable(!0)}dispose(){this.floors.forEach(t=>t.dispose()),this.floors=[],super.dispose()}constructor(t){super(t),this.floors=[],this.group=new fd,this.showStatus=!1,this.group.name="mul-floor-group"}};import{EventDispatcher as gd}from"three";function _o(){return new Worker(new URL("./worker/path.worker-C7N3AIZ3.js",import.meta.url))}var ys=class extends gd{setLiftPriority(t){return F(this.worker,"onSetLiftPriority",t)}loaded(){return new Promise(t=>{if(this.initRoadStatus)t(!0);else{let e=i=>{let{status:s}=i;s&&(this.removeEventListener("init-road-status",e),t(!0))};this.addEventListener("init-road-status",e)}})}setRoadData(t,e){return f(this,null,function*(){this.initRoadStatus=!1,this.dispatchEvent({type:"init-road-status",status:!1}),yield F(this.worker,"set_road_info",{roadData:t,facilities:e}),this.initRoadStatus=!0,this.dispatchEvent({type:"init-road-status",status:!0})})}getPath(t,e,i,s,o,n){return f(this,null,function*(){return i===void 0&&(i=""),new Promise((r,h)=>{let c=()=>{F(this.worker,"get_path",{start:t,end:e,type:i,permission:s,travelDirection:o,options:n}).then(l=>{l?typeof l=="string"?h(l):r(l):h("no-path")})};if(this.initRoadStatus)c();else{let l=p=>{let{status:d}=p;d&&(this.removeEventListener("init-road-status",l),c())};this.addEventListener("init-road-status",l)}})})}getDirectionPath(t){return F(this.worker,"get_direction_path",t)}dispose(){return f(this,null,function*(){F(this.worker,"clear",""),this.worker.terminate()})}constructor(){super(),this.worker=_o(),this.initRoadStatus=!1}};import{EventDispatcher as yd}from"three";function Po(){return new Worker(new URL("./worker/cr-path.worker-RCWZ3ILJ.js",import.meta.url))}var kr=class extends yd{setRoadData(t){return f(this,null,function*(){this.initRoadStatus=!1,this.dispatchEvent({type:"init-road-status",status:!1}),yield F(this.worker,"set_road_info",{roadData:t}),this.initRoadStatus=!0,this.dispatchEvent({type:"init-road-status",status:!0})})}getPath(t,e,i){return f(this,null,function*(){return i===void 0&&(i=""),new Promise((s,o)=>{let n=()=>{F(this.worker,"get_path",{start:t,end:e,type:i}).then(r=>{r?typeof r=="string"?o(r):s(r):o("no-path")})};if(this.initRoadStatus)n();else{let r=h=>{let{status:c}=h;c&&(this.removeEventListener("init-road-status",r),n())};this.addEventListener("init-road-status",r)}})})}getDirectionPath(t){return F(this.worker,"get_direction_path",t)}dispose(){return f(this,null,function*(){F(this.worker,"clear",""),this.worker.terminate()})}constructor(){super(),this.worker=Po(),this.initRoadStatus=!1}};import"core-js/modules/web.dom-collections.iterator.js";import"core-js/modules/es.set.difference.v2.js";import"core-js/modules/es.set.intersection.v2.js";import"core-js/modules/es.set.is-disjoint-from.v2.js";import"core-js/modules/es.set.is-subset-of.v2.js";import"core-js/modules/es.set.is-superset-of.v2.js";import"core-js/modules/es.set.symmetric-difference.v2.js";import"core-js/modules/es.set.union.v2.js";import"core-js/modules/es.array.push.js";import{Frustum as vd}from"three";var vs=class extends vt{setEnable(t){super.setEnable(t),ot(this.rect,0,0,0,0),t?this.registryEvent():(this.startPoint=void 0,this.unRegistryEvent())}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:s}}}=this,o=C(this.startPoint,e,i,s),n=C(this.endPoint,e,i,s),r={x:Math.min(o.x,n.x),y:Math.min(o.y,n.y)},h={x:Math.max(o.x,n.x),y:Math.max(o.y,n.y)},c=this.searchMapInFrustum(r,h);this.dispatchEvent({type:"selected",list:c})}}searchMapInFrustum(t,e){var i;let{context:s}=this;return((i=s.currentFloor)==null?void 0:i.graphicLayer.children.filter(o=>o instanceof J&&this.searchChildInFrustum(o,t,e)))||[]}searchChildInFrustum(t,e,i){let{context:{camera:s,container:{clientWidth:o,clientHeight:n}}}=this;if(!t)return!1;if(!t.mesh){let d=t.getPosition();if(d){let u=C(d,s,o,n);return Yt(u,e,i)}return!1}t.mesh.geometry.boundingBox||t.mesh.geometry.computeBoundingBox();let r=t.mesh.geometry.boundingBox;if(!r)return!1;let{min:h,max:c}=r,l=C(h,s,o,n),p=C(c,s,o,n);return!(!Yt(l,e,i)||!Yt(p,e,i))}dispose(){super.dispose(),this.rect=null,this.unRegistryEvent()}constructor(t){super(t),this.frustum=new vd,this.onPointerDown=s=>{if(!this.enable)return;let o=this.getIntersectByPointerEvent(s);o&&(this.startPoint=o),this.endPoint=void 0},this.onPointerMove=s=>{if(!this.enable||!this.startPoint)return;let o=this.getIntersectByPointerEvent(s);o&&(this.endPoint=o)},this.onPointerUp=s=>{if(!this.enable)return;let o=this.getIntersectByPointerEvent(s);o&&(this.endPoint=o),this.doSelect(),this.startPoint=void 0},this.onUpdate=()=>{if(this.startPoint){let s=this.getSvgCoordinate(this.startPoint),o=w({},s);this.endPoint&&(o=this.getSvgCoordinate(this.endPoint));let n={x:Math.min(s.x,o.x),y:Math.min(s.y,o.y)},r=Math.abs(o.x-s.x),h=Math.abs(o.y-s.y);ot(this.rect,n.x,n.y,r,h)}else ot(this.rect,0,0,0,0)};let{config:{selectBox:{fill:e,stroke:i}}}=t;this.rect=qt(i,e),this.svg.appendChild(this.rect),this.registryEvent()}};var xd={boxSelection:!1,elements:["graphic","poi"]},Dr=class extends B{get list(){return this._list}enableBoxSelection(){this.isMultipleSelect||!this.options.boxSelection||(this.isMultipleSelect=!0,this.boxSelection.setEnable(!0),this.prevPanStatus=this.bmap.context.control.enablePan,this.prevRotateStatus=this.bmap.context.control.enableRotate,this.bmap.context.control.enablePan=!1,this.bmap.context.control.enableRotate=!1)}disableBoxSelection(){this.isMultipleSelect&&(this.isMultipleSelect=!1,this.boxSelection.setEnable(!1),this.bmap.context.control.enablePan=!!this.prevPanStatus,this.bmap.context.control.enableRotate=!!this.prevRotateStatus)}selectEnd(){this.dispatchEvent({type:"select",graphics:[...this._list],pois:[...this._poiList],isMultipleSelect:this.isMultipleSelect})}registryEvent(){this.bmap.context.container.addEventListener("pointerdown",this.onPointerDown),this.bmap.context.container.addEventListener("pointerup",this.onPointerUp),this.bmap.context.container.addEventListener("pointerout",this.onPointerOut),this.bmap.context.container.addEventListener("pointercancel",this.onPointerOut),window.addEventListener("keydown",this.onKeyDown),window.addEventListener("keyup",this.onKeyUp),this.boxSelection.addEventListener("selected",this.onBoxSelected)}unRegistryEvent(){this.bmap.context.container.removeEventListener("pointerdown",this.onPointerDown),this.bmap.context.container.removeEventListener("pointerup",this.onPointerUp),this.bmap.context.container.removeEventListener("pointerout",this.onPointerOut),this.bmap.context.container.removeEventListener("pointercancel",this.onPointerOut),window.removeEventListener("keydown",this.onKeyDown),window.removeEventListener("keyup",this.onKeyUp),this.boxSelection.removeEventListener("selected",this.onBoxSelected)}clear(){this._list.clear()}remove(t){this._list.delete(t)}dispose(){this.unRegistryEvent(),super.dispose()}constructor(t,e={}){super(t),this._list=new Set,this._poiList=new Set,this.downPoint=null,this.isMultipleSelect=!1,this.onPointerDown=i=>{this.downPoint={x:i.offsetX,y:i.offsetY}},this.onPointerUp=i=>{if(!this.downPoint)return;let{offsetX:s,offsetY:o}=i,{x:n,y:r}=this.downPoint;if(Math.sqrt((n-s)**2+(r-o)**2)>3)return;let h=new Set,c=[],l=[];if(this.options.elements.includes("graphic")){let{graphics:p}=this.bmap.context.getGraphicsByDeviceXy(s,o);p.map(d=>h.add(d.options.id)),c.push(...p)}if(this.options.elements.includes("poi")){let p=this.bmap.context.getPoisByDeviceXy(s,o);l.push(...p),p.forEach(d=>{if(!h.has(d.options.id)){var u;let m=((u=this.bmap.context.currentFloor)==null?void 0:u.graphicLayer.graphicMap.get(d.options.id))||null;m&&(h.add(d.options.id),c.push(m))}})}(!this.options.boxSelection||!(ge?i.metaKey:i.ctrlKey))&&(this._list.clear(),this._poiList.clear()),c.forEach(p=>this._list.add(p)),l.forEach(p=>this._poiList.add(p)),this.selectEnd(),this.downPoint=null},this.onPointerOut=i=>{this.disableBoxSelection()},this.onKeyDown=i=>{ye(i.key)&&this.enableBoxSelection()},this.onKeyUp=i=>{ye(i.key)&&this.disableBoxSelection()},this.onBoxSelected=i=>{let{list:s}=i;this._list.clear(),this._poiList.clear(),s.forEach(o=>{if(this.options.elements.includes("graphic")&&this._list.add(o),this.options.elements.includes("poi")){let n=this.bmap.getPoiById(o.options.id);n&&this._poiList.add(n)}}),this.selectEnd()},this.options=w({},xd,e),this.boxSelection=new vs(this.bmap.context),this.boxSelection.setEnable(!1),this.registryEvent()}};import"core-js/modules/es.array.push.js";import{cloneDeep as wd,isNil as ee,throttle as Ar}from"lodash";var O=function(a){return a.COMPASS="compass",a.DEVICE_MOTION="deviceMotion",a.ACCELERATION="acceleration",a.GPS="gps",a}({});var Md={time:1e3,elements:[O.COMPASS,O.DEVICE_MOTION,O.ACCELERATION,O.GPS]},xs=class extends X{start(){this.options.elements.some(t=>[O.DEVICE_MOTION,O.COMPASS].includes(t))&&this.listenDeviceOrientation(),this.options.elements.includes(O.ACCELERATION)&&this.listenAcceleration(),this.options.elements.includes(O.GPS)&&this.listenGps(),this.dispatchEvent({type:"start"}),this.dispatchTimer=this.timer.setInterval(()=>{this.dispatchEvent({type:"sensor-data",data:wd(this.data)}),this.data=[]},this.options.time)}addDataItem(t){this.data.push(t),this.dispatchEvent({type:"add-data-item",item:t})}listenDeviceOrientation(){Ut?window.addEventListener("deviceorientation",this.deviceOrientationAbsHandler,!1):window.addEventListener("deviceorientationabsolute",this.deviceOrientationAbsHandler,{absolute:!0})}listenAcceleration(){window.addEventListener("devicemotion",this.handleAcceleration,!1)}listenGps(){this.gpsTimer=navigator.geolocation.watchPosition(t=>{console.log("watch gps",t.coords),this.addDataItem({type:O.GPS,timestamp:Date.now(),res:[t.coords.longitude,t.coords.latitude,t.coords.accuracy]})},t=>{console.log("\u83B7\u53D6gps\u5931\u8D25",t)},{enableHighAccuracy:!0})}checkSensor(){return f(this,null,function*(){return{deviceOrientation:yield this.checkDeviceOrientation()}})}checkDeviceOrientation(){return f(this,null,function*(){var t;if(!Ut)return!0;if(typeof window.DeviceOrientationEvent!="undefined"&&typeof((t=window.DeviceOrientationEvent)==null?void 0:t.requestPermission)=="function")try{var e;return(yield(e=window.DeviceOrientationEvent)==null?void 0:e.requestPermission())==="granted"}catch(i){return!1}return!1})}stop(){window.removeEventListener("devicemotion",this.handleAcceleration,!1),Ut?window.removeEventListener("deviceorientation",this.deviceOrientationAbsHandler,!1):window.removeEventListener("deviceorientationabsolute",this.deviceOrientationAbsHandler,{absolute:!0}),ee(this.gpsTimer)||navigator.geolocation.clearWatch(this.gpsTimer),this.dispatchTimer&&this.timer.clearInterval(this.dispatchTimer),this.data=[],this.dispatchEvent({type:"stop"})}constructor(t={}){super(),this.gpsTimer=null,this.data=[],this.timer=new z,this.dispatchTimer=null,this.addAcceleration=Ar(e=>{this.addDataItem(e)},20),this.deviceOrientationAbsHandler=Ar(e=>{let i=Date.now(),{alpha:s,beta:o,gamma:n}=e;if(ee(s)||ee(o)||ee(n))return;let r;Ut?r=e.webkitCompassHeading:r=360-s,this.options.elements.includes(O.DEVICE_MOTION)&&this.addDataItem({type:O.DEVICE_MOTION,timestamp:i,res:[s,o,n]}),this.options.elements.includes(O.COMPASS)&&this.addDataItem({type:O.COMPASS,timestamp:i,res:r})},200),this.handleAcceleration=e=>{let i=e.accelerationIncludingGravity;ee(i)||ee(i.x)||ee(i.y)||ee(i.z)||this.addAcceleration({type:O.ACCELERATION,timestamp:Date.now(),res:[i.x,i.y,i.z]})},this.options=w({},Md,t)}};import"core-js/modules/web.dom-collections.iterator.js";import"core-js/modules/es.array.push.js";import"core-js/modules/es.array.push.js";import"core-js/modules/web.dom-collections.iterator.js";function ws(a,t){return 1/Math.sqrt(2*Math.PI*Math.pow(t,2))*Math.exp(-Math.pow(a,2)/(2*Math.pow(t,2)))}function ii(a){return(a+360)%360}function Or(a,t){let i=6378137*a*Math.PI/180,s=6378137*Math.log(Math.tan(Math.PI/4+t*Math.PI/180/2));return{x:i,y:s}}function Re(a,t,e,i){return Math.sqrt(Math.pow(Math.abs(a-e),2)+Math.pow(Math.abs(t-i),2))}var Ms=class{motionModelRotYaw(t){if(!(Math.abs(t)<.001)){this.last_yaw_compass=ii(this.last_yaw_compass+t);for(let e=0;e<this.NumParticle;e++){let i=Math.random()*this.yaw_noise_sigma;this.particleX[2][e]=this.particleX[2][e]+t+i,this.particleX[2][e]=ii(this.particleX[2][e])}}}motionModelStepLength(t,e){if(t===0)return;for(let s=0;s<this.NumParticle;s++){let o=Math.random()*this.step_noise_sigma;this.particleX[0][s]+=(.65+o)*Math.sin(-this.particleX[2][s]/180*Math.PI),this.particleX[1][s]+=(.65+o)*Math.cos(this.particleX[2][s]/180*Math.PI),e(this.particleX[0][s],this.particleX[1][s])||(this.particleWeight[0][s]*=this.unaccess_weight)}let i=this.particleWeight[0].reduce((s,o)=>s+o,0);this.particleWeight[0]=this.particleWeight[0].map(s=>s/i)}motionModelCompassYaw(t,e){if(e-this.last_compass_time>this.compass_update_interval){let i=360-t;i+=this.delta_yaw,i=ii(i),Math.abs(i-this.last_yaw_compass)>60?this.compass_consecutive_offset_count++:this.compass_consecutive_offset_count=0;for(let o=0;o<this.NumParticle;o++){let n=Math.abs(this.particleX[2][o]-i);n>180&&(n=360-n),this.particleWeight[0][o]*=ws(n,this.sigmaCompass)}let s=this.particleWeight[0].reduce((o,n)=>o+n,0);this.particleWeight[0]=this.particleWeight[0].map(o=>o/s),this.setLastCompassTime(e)}}resampling(){if(1/this.particleWeight[0].reduce((e,i)=>e+i*i,0)<this.reSampNumParticle){let e=this.particleWeight[0].reduce((r,h,c)=>r.concat(r[c]+h),[0]),s=this.particleWeight[0].map(()=>1/this.NumParticle).map((r,h)=>r+Math.random()/this.NumParticle),o=[],n=0;for(let r=0;r<this.NumParticle;r++){for(;s[r]>e[n];)n++;o.push(n)}this.particleX=this.particleX.map((r,h)=>o.map(c=>r[c])),this.particleWeight[0]=Array(this.NumParticle).fill(1/this.NumParticle)}}update(t,e){for(let s=0;s<this.NumParticle;s++){let o=Re(this.particleX[0][s],this.particleX[1][s],t.x,t.y);this.particleWeight[0][s]=Math.max(1e-7,this.particleWeight[0][s]*ws(o,e))}let i=this.particleWeight[0].reduce((s,o)=>s+o,0);this.particleWeight[0]=this.particleWeight[0].map(s=>s/i)}updateCar(t,e){let i=t.x-this.xEst[0][0],s=t.y-this.xEst[1][0];for(let n=0;n<this.NumParticle;n++){let r=Re(this.particleX[0][n],this.particleX[1][n],t.x,t.y);this.particleWeight[0][n]=Math.max(1e-7,this.particleWeight[0][n]*ws(r,e)),this.particleX[0][n]+=i,this.particleX[1][n]+=s}let o=this.particleWeight[0].reduce((n,r)=>n+r,0);this.particleWeight[0]=this.particleWeight[0].map(n=>n/o)}getPosInitFlag(){return this.particle_PosInitFlag}getYawInitFlag(){return this.particle_yawInitFlag}setPosInitFlag(t){this.particle_PosInitFlag=t}setYawInitFlag(t){this.particle_yawInitFlag=t}getResultX(){let t=[0,0,0];for(let e=0;e<3;e++)for(let i=0;i<this.NumParticle;i++)t[e]+=this.particleX[e][i]*this.particleWeight[0][i];return this.xEst=t.map(e=>[e]),this.xEst[0][0]}getResultY(){return this.xEst[1][0]}getResultYaw(){let t=this.particleWeight[0].indexOf(Math.max(...this.particleWeight[0]));return this.particleX[2][t]}getEstConfidence(){let t=this.particleWeight[0].indexOf(Math.max(...this.particleWeight[0])),e=this.particleWeight[0].indexOf(Math.min(...this.particleWeight[0])),i=[this.particleX[0][t],this.particleX[1][t]],s=[this.particleX[0][e],this.particleX[1][e]],o=Re(i[0],i[1],s[0],s[1]),n=o*.67;return console.log(o,n),n}getParticleNum(){return this.NumParticle}getParticleX(){return this.particleX}setLastCompassTime(t){this.last_compass_time=t}getLastCompassTime(){return this.last_compass_time}initParticlesByPos(t,e,i){if(!this.particle_PosInitFlag){this.particleWeight[0]=Array(this.NumParticle).fill(1/this.NumParticle);let s=0;for(;s<this.NumParticle;){let n=(2*Math.random()-1)*this.initial_xy_uncertainty,r=(2*Math.random()-1)*this.initial_xy_uncertainty;i(t+n,e+r)||(this.particleWeight[0][s]*=this.unaccess_weight),this.particleX[0][s]=t+n,this.particleX[1][s]=e+r,s++}let o=this.particleWeight[0].reduce((n,r)=>n+r,0);this.particleWeight[0]=this.particleWeight[0].map(n=>n/o),this.particle_PosInitFlag=!0,this.xEst[0][0]=t,this.xEst[1][0]=e,this.xEst[2][0]=0}}initParticlesByCompass(t){console.log("Init compass: "+t);let e=360-t;e+=this.delta_yaw,e=ii(e),console.log("Init Yaw: "+e);for(let i=0;i<this.NumParticle;i++){let s=(2*Math.random()-1)*this.initial_yaw_uncertainty;this.particleX[2][i]=e+s}this.particle_yawInitFlag=!0,this.xEst[2][0]=e,this.last_yaw_compass=e,this.compass_consecutive_offset_count=0}constructor(t){this.last_yaw_compass=0,this.compass_consecutive_offset_count=0,this.NumParticle=t.NumParticle,this.reSampNumParticle=t.reSampNumParticle,this.initial_xy_uncertainty=t.initial_xy_uncertainty,this.initial_yaw_uncertainty=t.initial_yaw_uncertainty,this.step_noise_sigma=t.step_noise_sigma,this.yaw_noise_sigma=t.yaw_noise_sigma,this.compass_update_interval=t.compass_update_interval,this.sigmaCompass=t.sigmaCompass,this.delta_yaw=t.delta_yaw,this.sigmaBeacon=t.sigmaBeacon,this.unaccess_weight=t.unaccess_weight,this.particle_PosInitFlag=!1,this.particle_yawInitFlag=!1,this.xEst=[[0],[0],[0]],this.particleX=Array.from({length:3},()=>Array(this.NumParticle).fill(0)),this.particleWeight=Array.from({length:1},()=>Array(this.NumParticle).fill(1/this.NumParticle)),this.last_compass_time=0}};import"core-js/modules/es.array.push.js";import"core-js/modules/web.dom-collections.iterator.js";var _s=class{init(){this.fre=100,this.accH_fifo=[],this.accH_time_fifo=[],this.accH_fifo_len=Math.floor(1*this.fre)+1,this.step_count=0,this.state_count=0,this.last_valley_time=0,this.last_peak_time=0,this.last_step_time=0,this.min_step_time=.3,this.max_step_time=1,this.min_peak=10+.5,this.max_valley=10-.5,this.peak_num=0,this.valley_num=0,this.fft_min_amp=.3,this.fft_min_fre=0,this.fft_max_fre=4,this.last_fft_amp=0,this.abnor_start_time=0,this.abnor_fft_detected=!1,this.abnor_peak_time=0,this.abnor_peak_accH=0,this.const_step_length=.65,this.last_rot=[0,0,0],this.delta_rot=[0,0,0],this.last_yaw=0,this.delta_yaw=null,this.delta_rot_sum_fifo=[],this.delta_rot_sum_time_fifo=[],this.delta_yaw_accum=0,this.delta_yaw_accum_timestamp=0,this.delta_yaw_time_threshold=.5,this.last_px=0,this.last_py=0,this.delta_px=0,this.delta_py=0,this.is_moving=!1,this.currentMotionState="UNKNOWN",this.previousMotionState="UNKNOWN",this.acc_variance_buffer=[],this.rot_variance_buffer=[],this.acc_buffer=[],this.walkingCount=0,this.stationaryCount=0,this.phoneUseCount=0,this.stateCounter=0}reset(){this.init()}setInitPose(t){t===void 0&&(t=[0,0]),this.last_px=t[0],this.last_py=t[1],console.info("pdr init pos: "+this.last_px+", "+this.last_py)}setInitYaw(t){t===void 0&&(t=0),this.last_yaw=t}getPos(t,e,i){let s=0;return i.length===3&&(this.delta_yaw=this.getDeltaYawFromRot(t,i)),e.length===3&&(s=this.getStepLength(t,e)),s!==0&&(this.last_px+=this.delta_px,this.last_py+=this.delta_py),[this.last_px,this.last_py]}getDeltaPose(){return[this.delta_px,this.delta_py]}getMotionState(){return this.currentMotionState}getStepLength(t,e){if(e.length<3)return console.warn("acc data less than 3"),0;let i=!1,s=Math.sqrt(Math.pow(e[0],2)+Math.pow(e[1],2)+Math.pow(e[2],2));if(this.accH_fifo.push(s),this.accH_time_fifo.push(t),this.imuFreUpdate(),!this.isMoving(e,this.last_rot))return 0;if(this.accH_fifo.length<this.accH_fifo_len+1)i=!1;else{for(;this.accH_fifo.length>=this.accH_fifo_len+1;)this.accH_fifo.shift(),this.accH_time_fifo.shift();let n=this.PVStepDetec(),r=this.FFTStepDetec(),h=this.recheckState(),c=this.accH_time_fifo[Math.floor(this.accH_time_fifo.length*3/4)];Math.abs(this.abnor_start_time)<.001&&this.abnor_fft_detected?this.abnor_start_time=c:this.abnor_fft_detected||(this.abnor_start_time=0),n&&r&&h?(this.step_count+=1,this.last_step_time=c,i=!0):Math.abs(this.abnor_start_time)>.001&&this.abnor_peak_time-this.abnor_start_time>this.abnor_time_threshold&&this.step_count>1&&this.abnor_peak_time-this.last_step_time>1?(this.step_count+=1,this.last_step_time=c,i=!0):(c-this.last_step_time>2&&(this.state_count=0),i=!1)}if(i){let n=this.last_yaw/180*Math.PI;return this.delta_px=this.const_step_length*Math.cos(n),this.delta_py=this.const_step_length*Math.sin(n),this.const_step_length}else return 0}imuFreUpdate(){if(this.accH_time_fifo.length>2&&(this.accH_time_fifo[this.accH_time_fifo.length-1]-this.accH_time_fifo[this.accH_time_fifo.length-2]<0||this.accH_time_fifo[this.accH_time_fifo.length-1]-this.accH_time_fifo[this.accH_time_fifo.length-2]>10||this.accH_time_fifo[this.accH_time_fifo.length-1]===this.accH_time_fifo[0])&&(console.warn("pdr reset last one time "+this.accH_time_fifo[this.accH_time_fifo.length-1]+" last two time "+this.accH_time_fifo[this.accH_time_fifo.length-2]),this.reset()),this.accH_fifo.length>9||this.fre<15){let t=(this.accH_fifo.length-1)/(this.accH_time_fifo[this.accH_time_fifo.length-1]-this.accH_time_fifo[0]);Math.abs(this.fre-t)>8&&(this.fre=Math.round((t-3)/10)*10,(this.fre<=10||this.fre>=100)&&(console.warn("Frequency Error "+this.fre),this.fre=100),console.debug("Frequency change to "+this.fre),this.accH_fifo_len=Math.floor(1*this.fre)+1)}}recheckState(){return!0}PVStepDetec(){let t=!1,e=this.accH_fifo.slice(Math.floor(this.accH_fifo_len/2)),i=this.accH_time_fifo.slice(Math.floor(this.accH_fifo_len/2)),s=e[Math.floor(e.length/2)],o=i[Math.floor(i.length/2)],n=Math.max(...e),r=Math.min(...e),h=!1,c=!1;return Math.abs(s-r)<.01&&s<this.max_valley&&this.valley_num<=this.peak_num&&(this.last_valley_time===0?c=!0:c=o-this.last_valley_time>this.min_step_time,c&&(this.last_valley_time=o,this.valley_num+=1)),Math.abs(s-n)<.01&&s>this.min_peak&&this.peak_num<=this.valley_num&&(this.last_peak_time===0?h=!0:h=o-this.last_peak_time>this.min_step_time,h&&(this.last_peak_time=o,this.peak_num+=1)),s===n&&s>this.min_peak&&(this.abnor_peak_time=o,this.abnor_peak_accH=s),this.peak_num===this.valley_num&&(h||c)&&(t=!0),t}FFTStepDetec(){return!0}isMoving(t,e){if(t.length<3||e.length<3)return!1;this.acc_buffer.push([...t]),this.acc_buffer.length>this.static_window_size&&this.acc_buffer.shift();let i=Math.sqrt(Math.pow(t[0],2)+Math.pow(t[1],2)+Math.pow(t[2],2));this.acc_variance_buffer.push(i),this.acc_variance_buffer.length>this.static_window_size&&this.acc_variance_buffer.shift();let s=Math.abs(e[0])+Math.abs(e[1])+Math.abs(e[2]);if(this.rot_variance_buffer.push(s),this.rot_variance_buffer.length>this.static_window_size&&this.rot_variance_buffer.shift(),this.acc_variance_buffer.length<10)return this.is_moving;let o=this.acc_variance_buffer.slice(-10),n=this.rot_variance_buffer.slice(-10),r=this.calculateMean(o),h=this.calculateStdDeviation(o),c=this.calculateMean(n),l=this.calculateStdDeviation(n),p;return r>this.walkingThreshold&&h>.5?(this.walkingCount++,this.stationaryCount=0,this.phoneUseCount=0,p="WALKING"):r<this.phoneUseThreshold&&c>this.rotationThreshold?(this.phoneUseCount++,this.walkingCount=0,this.stationaryCount=0,p="USING_PHONE"):c<.5?(this.stationaryCount++,this.walkingCount=0,this.phoneUseCount=0,p="STATIONARY"):p="UNKNOWN",p!==this.currentMotionState?(this.stateCounter++,this.stateCounter>=this.stateChangeThreshold&&(this.previousMotionState=this.currentMotionState,this.currentMotionState=p,this.stateCounter=0,console.debug("Motion state changed: "+this.previousMotionState+" -> "+this.currentMotionState),console.debug("Stats: avgAcc="+r.toFixed(2)+", accStdDev="+h.toFixed(2)+", avgRot="+c.toFixed(2)+", rotStdDev="+l.toFixed(2)))):this.stateCounter=0,this.is_moving=this.currentMotionState==="WALKING",this.is_moving}calculateMean(t){return t.length===0?0:t.reduce((e,i)=>e+i,0)/t.length}calculateStdDeviation(t){if(t.length<2)return 0;let e=this.calculateMean(t),s=t.map(o=>{let n=o-e;return n*n}).reduce((o,n)=>o+n,0)/t.length;return Math.sqrt(s)}getMotionStatistics(){let t=this.acc_variance_buffer.slice(-10),e=this.rot_variance_buffer.slice(-10),i=this.calculateMean(t),s=this.calculateMean(e),o=this.calculateStdDeviation(t),n=this.calculateStdDeviation(e);return console.debug("\u8FD0\u52A8\u68C0\u6D4B: avgAcc="+i.toFixed(2)+", accStdDev="+o.toFixed(2)+", avgRot="+s.toFixed(2)+", rotStdDev="+n.toFixed(2)),console.debug("\u72B6\u6001\u5224\u65AD\u6761\u4EF6: \u884C\u8D70(avgAcc>"+this.walkingThreshold+", accStdDev>0.5), \u9759\u6B62(avgRot<0.5), \u624B\u673A(avgAcc<"+this.phoneUseThreshold+", avgRot>"+this.rotationThreshold+")"),console.debug("\u5F53\u524D\u72B6\u6001: "+this.currentMotionState+", \u8BA1\u6570: \u884C\u8D70="+this.walkingCount+", \u9759\u6B62="+this.stationaryCount+", \u624B\u673A="+this.phoneUseCount),{currentState:this.currentMotionState,avgAcceleration:i,avgRotation:s,accStdDeviation:o,rotStdDeviation:n,walkingCount:this.walkingCount,stationaryCount:this.stationaryCount,phoneUseCount:this.phoneUseCount,dataPoints:this.acc_variance_buffer.length,isMoving:this.is_moving}}getDeltaYawFromRot(t,e){if(e.length<3)return console.warn("rot data less than 3"),0;let i=[0,0,0];this.last_rot.length===3&&(i=e.map((r,h)=>r-this.last_rot[h]));for(let r=0;r<e.length;r++)i[r]<-180?i[r]+=360:i[r]>180&&(i[r]-=360);let s=.2;this.delta_rot.length===3?this.delta_rot=this.delta_rot.map((r,h)=>s*r+(1-s)*i[h]):this.delta_rot=i,this.last_rot=e,this.delta_yaw=this.delta_rot[0],this.last_yaw+=this.delta_yaw,this.last_yaw=this.limitYaw(this.last_yaw);let o=this.delta_rot.reduce((r,h)=>r+Math.abs(h),0);this.delta_rot_sum_fifo.push(o),this.delta_rot_sum_time_fifo.push(t),Math.abs(this.delta_rot_sum_time_fifo[this.delta_rot_sum_time_fifo.length-1]-this.delta_rot_sum_time_fifo[0])>1&&(this.delta_rot_sum_fifo.shift(),this.delta_rot_sum_time_fifo.shift()),this.delta_yaw_accum+=this.delta_yaw;let n=0;return Math.abs(this.delta_yaw_accum_timestamp-t)>this.delta_yaw_time_threshold?(n=this.delta_yaw_accum,this.delta_yaw_accum=0,this.delta_yaw_accum_timestamp=t,n):null}limitYaw(t){for(;t<-180;)t+=360;for(;t>180;)t-=360;return t}constructor(){this.fre=100,this.accH_fifo=[],this.accH_time_fifo=[],this.accH_fifo_len=Math.floor(1*this.fre)+1,this.step_count=0,this.state_count=0,this.last_valley_time=0,this.last_peak_time=0,this.last_step_time=0,this.min_step_time=.3,this.max_step_time=1,this.min_peak=10.5,this.max_valley=9.5,this.peak_num=0,this.valley_num=0,this.fft_min_amp=.3,this.fft_min_fre=0,this.fft_max_fre=4,this.last_fft_amp=0,this.abnor_start_time=0,this.abnor_fft_detected=!1,this.abnor_time_threshold=4,this.abnor_peak_time=0,this.abnor_peak_accH=0,this.const_step_length=.85,this.last_rot=[],this.delta_rot=[],this.last_yaw=0,this.delta_yaw=null,this.delta_rot_sum_fifo=[],this.delta_rot_sum_time_fifo=[],this.delta_yaw_accum=0,this.delta_yaw_accum_timestamp=0,this.delta_yaw_time_threshold=.5,this.last_px=0,this.last_py=0,this.delta_px=0,this.delta_py=0,this.is_moving=!1,this.currentMotionState="UNKNOWN",this.previousMotionState="UNKNOWN",this.walkingThreshold=1,this.stationaryThreshold=.6,this.phoneUseThreshold=.7,this.rotationThreshold=.8,this.walkingCount=0,this.stationaryCount=0,this.phoneUseCount=0,this.stateCounter=0,this.stateChangeThreshold=3,this.static_window_size=20,this.acc_variance_buffer=[],this.rot_variance_buffer=[],this.acc_buffer=[]}};var _d={using_gps:!0,gps_max_horizontalAccuracy:20,initial_gps_delay_time:3e3},Ps=class{pfFusionPDRiBeacon(t){let{type:e,timestamp:i,res:s}=t,o=!1;if(this.cacheSensorData.push(t),this.particleFilter.getPosInitFlag()&&this.particleFilter.getYawInitFlag()){if(e===O.ACCELERATION){let n=s,r=this.pdr.getStepLength(i/1e3,n);r!==0&&(this.particleFilter.motionModelStepLength(r,()=>!0),this.particleFilter.resampling(),this.position_count+=1,o=!0)}if(this.using_gps&&e===O.GPS)if(this.last_beacon_time===null||i-this.last_beacon_time>5e3){let n=this.getGpsPosition(s);o=n!==null,n&&(this.particleFilter.update(n,this.gps_horizontalAccuracy),this.resetParticleFilterDist(n,"gps",s[2]),this.particleFilter.resampling(),this.position_count+=1,this.cacheSensorData.length=0)}else return[!1,0,0];if(e===O.DEVICE_MOTION){let n=this.pdr.getDeltaYawFromRot(i/1e3,s);n!==null&&this.particleFilter.motionModelRotYaw(n)}e===O.COMPASS&&this.particleFilter.motionModelCompassYaw(s,i),this.last_pos_time&&i-this.last_pos_time>500&&(this.position_count+=1,o=!0)}else if(!this.particleFilter.getPosInitFlag()&&this.using_gps&&e===O.GPS)if(this.startTime&&Date.now()-this.startTime>this.options.initial_gps_delay_time){let n=this.getGpsPosition(s);o=n!==null,console.log("gps_pos",n,s),n?(this.particleFilter.initParticlesByPos(n.x,n.y,()=>!0),this.last_pos_time=i,console.log("init Pos by gps success time "+i),this.cacheSensorData.length=0):console.log("init Pos by gps fail time "+i)}else this.startTime||(this.startTime=i);else if(!this.particleFilter.getYawInitFlag()&&e===O.COMPASS){let n=s;this.particleFilter.initParticlesByCompass(n),this.particleFilter.setLastCompassTime(i),console.log("init yaw by compass success time "+i)}return o&&(this.last_pos_time=i),[o,this.particleFilter.getResultX(),this.particleFilter.getResultY()]}setBeaconPosition(t,e){if(this.last_beacon_time=e,this.particleFilter.getPosInitFlag())this.particleFilter.update(t,this.sigmaBeacon);else{this.particleFilter.initParticlesByPos(t.x,t.y,()=>!0);let i=this.cacheSensorData.filter(s=>s.timestamp>e);console.log("\u521D\u59CBsensorData",i),i.map(s=>this.pfFusionPDRiBeacon(s))}return this.resetParticleFilterDist(t),this.particleFilter.resampling(),this.position_count+=1,this.cacheSensorData.length=0,[this.particleFilter.getResultX(),this.particleFilter.getResultY()]}getGpsPosition(t){return t[2]>this.gps_max_horizontalAccuracy?null:Or(t[0],t[1])}resetParticleFilterDist(t,e,i){let s=this.particleFilter.getResultX(),o=this.particleFilter.getResultY(),n=Re(s,o,t.x,t.y);(e==="gps"?i&&n>i||n>this.GpsMaxEstimateErr:n>this.MaxEstimateErr)?(this.outTrustRegionNum+=1,this.outTrustRegionNum>=this.TrustNum&&(console.info("\u8D85\u51FA\u53EF\u4FE1\u533A\u57DF\uFF0C\u91CD\u7F6E\u7C92\u5B50\u8FC7\u6EE4\u5668\u5230: "+t.x+", "+t.y),this.particleFilter.setPosInitFlag(!1),this.particleFilter.setYawInitFlag(!1),this.outTrustRegionNum=0,this.startTime=Date.now())):this.outTrustRegionNum=0}constructor(t){this.sigmaBeacon=5,this.gps_horizontalAccuracy=10,this.using_gps=!0,this.last_beacon_time=Date.now(),this.position_count=0,this.gps_max_horizontalAccuracy=20,this.MaxEstimateErr=5,this.GpsMaxEstimateErr=30,this.outTrustRegionNum=0,this.TrustNum=1,this.cacheSensorData=[],this.startTime=null;let e=w({},_d,t);this.options=e,this.using_gps=e.using_gps,this.gps_max_horizontalAccuracy=e.gps_max_horizontalAccuracy,this.particleFilter=new Ms({NumParticle:200,reSampNumParticle:.65,initial_xy_uncertainty:12,initial_yaw_uncertainty:100,step_noise_sigma:.5,yaw_noise_sigma:2,compass_update_interval:3e3,sigmaCompass:80,delta_yaw:2,sigmaBeacon:5,unaccess_weight:.7}),this.pdr=new _s}};import{booleanPointInPolygon as Pd,point as bd}from"@turf/turf";var bs=class extends X{checkSensor(){return this.sensor.checkSensor()}setSensor(t){this.sensor=t}start(){this.sensor.start(),this.pdr.startTime=Date.now(),this.sensor.addEventListener("add-data-item",t=>{let{item:e}=t;this.getPositionBySensorItem(e,!this._pause)})}pause(){this._pause=!0}continue(){this._pause=!1}getPositionBySensorItem(t,e){e===void 0&&(e=!0);let[i,s,o]=this.pdr.pfFusionPDRiBeacon(t);return i&&e&&Pd(bd([s,o]),this.bmap.context.range)&&this.dispatchEvent({type:"position",x:s,y:o,_type:t.type===O.GPS?"gps":"pdr"}),[i,s,o]}setBeaconPosition(t,e){let[i,s]=this.pdr.setBeaconPosition(t,e);this.dispatchEvent({type:"position",x:i,y:s,_type:"beacon"})}dispose(){this.sensor.stop()}constructor(t,e={}){super(),this.bmap=t,this._pause=!1,this.sensor=new xs(e.sensor),this.pdr=new Ps(e.pdr||{})}};import"core-js/modules/web.dom-collections.iterator.js";import"core-js/modules/es.array.push.js";import"core-js/modules/web.dom-collections.iterator.js";import"core-js/modules/es.array.push.js";import"core-js/modules/es.array.flat.js";import"core-js/modules/es.array.unscopables.flat.js";import{Object3D as Ed,TextureLoader as Ld,Color as Cd,Vector2 as bo,Vector3 as Td,NormalBlending as kd,RepeatWrapping as Dd,Box3 as Ad}from"three";import{ShaderLib as Ss,ShaderMaterial as Sd,UniformsLib as Es,UniformsUtils as Rr,Vector2 as Ir}from"three";Es["custom-line"]={linewidth:{value:1},resolution:{value:new Ir(1,1)},dashScale:{value:1},dashSize:{value:1},gapSize:{value:1},repeat:{value:new Ir(1,1)},allDistance:{value:1}};Ss["custom-line"]={uniforms:Rr.merge([Es.common,Es.fog,Es["custom-line"]]),vertexShader:`
509
509
  #include <common>
510
510
  #include <color_pars_vertex>
511
511
  #include <fog_pars_vertex>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aibee/crc-bmap",
3
- "version": "0.14.6",
3
+ "version": "0.14.7",
4
4
  "description": "",
5
5
  "main": "lib/index.cjs",
6
6
  "module": "lib/index.esm.min.js",