@mcolabs/threebox-plugin 4.0.0 → 4.0.1

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/dist/threebox.cjs CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("three"),t=require("three/addons/loaders/OBJLoader.js"),i=require("three/addons/loaders/MTLLoader.js"),r=require("three/addons/loaders/FBXLoader.js"),a=require("three/addons/loaders/GLTFLoader.js"),n=require("three/addons/loaders/ColladaLoader.js"),s=require("three/addons/lines/Line2.js"),l=require("three/addons/lines/LineMaterial.js"),h=require("three/addons/lines/LineGeometry.js");function c(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e)for(const i in e)if("default"!==i){const r=Object.getOwnPropertyDescriptor(e,i);Object.defineProperty(t,i,r.get?r:{enumerable:!0,get:()=>e[i]})}return t.default=e,Object.freeze(t)}const u=c(e),d=1024e3,p=.1/180*Math.PI,m=Math.atan(3/4),f=6371008.8,g={WORLD_SIZE:d,PROJECTION_WORLD_SIZE:d/(f*Math.PI*2),MERCATOR_A:f,DEG2RAD:Math.PI/180,RAD2DEG:180/Math.PI,EARTH_RADIUS:f,EARTH_CIRCUMFERENCE:2*Math.PI*f,EARTH_CIRCUMFERENCE_EQUATOR:40075017,FOV_ORTHO:p,FOV:m,FOV_DEGREES:180*m/Math.PI,TILE_SIZE:512};function b(){}b.prototype={Coords:function(e){if(e.constructor===Array)if(e.length<2)console.error("Coords length must be at least 2");else{for(const t of e)if(t.constructor!==Number)return void console.error("Coords values must be numbers");if(!(Math.abs(e[1])>90))return e;console.error("Latitude must be between -90 and 90")}else console.error("Coords must be an array")},Line:function(e){if(e.constructor===Array){for(const t of e)if(!this.Coords(t))return void console.error("Each coordinate in a line must be a valid Coords type");return e}console.error("Line must be an array")},Rotation:function(e){if(e.constructor===Number)e={z:e};else{if(e.constructor!==Object)return void console.error("Rotation must be an object or a number");for(const t of Object.keys(e)){if(!["x","y","z"].includes(t))return void console.error("Rotation parameters must be x, y, or z");if(e[t].constructor!==Number)return void console.error("Individual rotation values must be numbers")}}return e},Scale:function(e){if(e.constructor===Number)e={x:e,y:e,z:e};else{if(e.constructor!==Object)return void console.error("Scale must be an object or a number");for(const t of Object.keys(e)){if(!["x","y","z"].includes(t))return void console.error("Scale parameters must be x, y, or z");if(e[t].constructor!==Number)return void console.error("Individual scale values must be numbers")}}return e}};var y={prettyPrintMatrix:function(e){for(var t=0;t<4;t++){var i=[e[t],e[t+4],e[t+8],e[t+12]];console.log(i.map(function(e){return e.toFixed(4)}))}},makePerspectiveMatrix:function(e,t,i,r){var o=new u.Matrix4,a=1/Math.tan(e/2),n=1/(i-r),s=[a/t,0,0,0,0,a,0,0,0,0,(r+i)*n,-1,0,0,2*r*i*n,0];return o.elements=s,o},makeOrthographicMatrix:function(e,t,i,r,o,a){var n=new u.Matrix4;const s=1/(t-e),l=1/(i-r),h=1/(a-o);var c=[2*s,0,0,0,0,2*l,0,0,0,0,-1*h,0,-((t+e)*s),-((i+r)*l),-(o*h),1];return n.elements=c,n},radify:function(e){function t(e){return e=e||0,2*Math.PI*e/360}return"object"==typeof e?e.length>0?e.map(function(e){return t(e)}):[t(e.x),t(e.y),t(e.z)]:t(e)},degreeify:function(e){function t(e){return 360*(e=e||0)/(2*Math.PI)}return"object"==typeof e?[t(e.x),t(e.y),t(e.z)]:t(e)},projectToWorld:function(e){var t=[-g.MERCATOR_A*g.DEG2RAD*e[0]*g.PROJECTION_WORLD_SIZE,-g.MERCATOR_A*Math.log(Math.tan(.25*Math.PI+.5*g.DEG2RAD*e[1]))*g.PROJECTION_WORLD_SIZE];if(e[2]){var i=this.projectedUnitsPerMeter(e[1]);t.push(e[2]*i)}else t.push(0);return new u.Vector3(t[0],t[1],t[2])},projectedUnitsPerMeter:function(e){return Math.abs(g.WORLD_SIZE/Math.cos(g.DEG2RAD*e)/g.EARTH_CIRCUMFERENCE)},_circumferenceAtLatitude:function(e){return g.EARTH_CIRCUMFERENCE*Math.cos(e*Math.PI/180)},mercatorZfromAltitude:function(e,t){return e/this._circumferenceAtLatitude(t)},_scaleVerticesToMeters:function(e,t){var i=this.projectedUnitsPerMeter(e[1]);this.projectToWorld(e);for(var r=0;r<t.length;r++)t[r].multiplyScalar(i);return t},projectToScreen:function(e){console.log("WARNING: Projecting to screen coordinates is not yet implemented")},unprojectFromScreen:function(e){console.log("WARNING: unproject is not yet implemented")},unprojectFromWorld:function(e){var t=[-e.x/(g.MERCATOR_A*g.DEG2RAD*g.PROJECTION_WORLD_SIZE),2*(Math.atan(Math.exp(e.y/(g.PROJECTION_WORLD_SIZE*-g.MERCATOR_A)))-Math.PI/4)/g.DEG2RAD],i=this.projectedUnitsPerMeter(t[1]),r=e.z||0;return t.push(r/i),t},toScreenPosition:function(e,t){var i=new u.Vector3,r=.5*renderer.context.canvas.width,o=.5*renderer.context.canvas.height;return e.updateMatrixWorld(),i.setFromMatrixPosition(e.matrixWorld),i.project(t),i.x=i.x*r+r,i.y=-i.y*o+o,{x:i.x,y:i.y}},getFeatureCenter:function(e,t,i){let r=[],o=0,a=0,n=0,s=[...e.geometry.coordinates[0]];return"Point"===e.geometry.type?r=[...s[0]]:("MultiPolygon"===e.geometry.type&&(s=s[0]),s.splice(-1,1),s.forEach(function(e){o+=e[0],a+=e[1]}),r=[o/s.length,a/s.length]),n=this.getObjectHeightOnFloor(e,t,i),r.length<3?r.push(n):r[2]=n,r},getObjectHeightOnFloor:function(e,t,i=e.properties.level||0){let r=i*(e.properties.levelHeight||0),o=e.properties.base_height||e.properties.min_height||0;return r+((t&&t.model?0:e.properties.height-o)+o)},_flipMaterialSides:function(e){},normalizeVertices(e){let t=new u.BufferGeometry,i=[];for(var r=0;r<e.length;r++){let t=e[r];i.push(t.x,t.y,t.z),i.push(t.x,t.y,t.z)}t.setAttribute("position",new u.BufferAttribute(new Float32Array(i),3)),t.computeBoundingSphere();var o=t.boundingSphere.center;return{vertices:e.map(function(e){return e.sub(o)}),position:o}},flattenVectors(e){var t=[];for(let i of e)t.push(i.x,i.y,i.z);return t},lnglatsToWorld:function(e){return e.map(function(e){var t=y.projectToWorld(e);return new u.Vector3(t.x,t.y,t.z)})},extend:function(e,t){for(let i in t)e[i]=t[i]},clone:function(e){var t={};for(let i in e)t[i]=e[i];return t},clamp:function(e,t,i){return Math.min(i,Math.max(t,e))},types:{rotation:function(e,t){e||(e=0),"number"==typeof e&&(e={z:e});var i=this.applyDefault([e.x,e.y,e.z],t);return y.radify(i)},scale:function(e,t){return e||(e=1),"number"==typeof e?[e,e,e]:this.applyDefault([e.x,e.y,e.z],t)},applyDefault:function(e,t){return e.map(function(e,i){return e=e||t[i]})}},toDecimal:function(e,t){return Number(e.toFixed(t))},equal:function(e,t){const i=Object.keys(e),r=Object.keys(t);if(i.length!==r.length)return!1;if(0==i.length&&0==r.length&&i!==r)return!1;for(const o of i){const i=e[o],r=t[o],a=this.isObject(i)&&this.isObject(r);if(a&&!equal(i,r)||!a&&i!==r)return!1}return!0},isObject:function(e){return null!=e&&"object"==typeof e},curveToLine:(e,t)=>{let{width:i,color:r}=t,o=(new u.BufferGeometry).setFromPoints(e.getPoints(100)),a=new u.LineBasicMaterial({color:r,linewidth:i});return new u.Line(o,a)},curvesToLines:e=>{var t=[16711680,2031360,2490623];return e.map((e,i)=>curveToLine(e,{width:3,color:t[i]||"purple"}))},_validate:function(e,t){e=e||{};var i={};y.extend(i,e);for(let r of Object.keys(t))if(void 0===e[r]){if(null===t[r])return void console.error(r+" is required");i[r]=t[r]}else i[r]=e[r];return i},Validator:new b,exposedMethods:["projectToWorld","projectedUnitsPerMeter","extend","unprojectFromWorld"]};function v(e,t,i){this.map=e,this.camera=t,this.active=!0,this.camera.matrixAutoUpdate=!1,this.world=i||new u.Group,this.world.position.x=this.world.position.y=g.WORLD_SIZE/2,this.world.matrixAutoUpdate=!1,this.state={translateCenter:(new u.Matrix4).makeTranslation(g.WORLD_SIZE/2,-g.WORLD_SIZE/2,0),worldSizeRatio:g.TILE_SIZE/g.WORLD_SIZE,worldSize:g.TILE_SIZE*this.map.transform.scale};let r=this;this.map.on("move",function(){r.updateCamera()}).on("resize",function(){r.setupCamera()}),this.setupCamera()}v.prototype={setupCamera:function(){const e=this.map.transform;this.camera.aspect=e.width/e.height,this.halfFov=e._fov/2,this.cameraToCenterDistance=.5/Math.tan(this.halfFov)*e.height;const t=e._maxPitch*Math.PI/180;this.acuteAngle=Math.PI/2-t,this.updateCamera()},updateCamera:function(e){if(!this.camera)return void console.log("nocamera");const t=this.map.transform;this.camera.aspect=t.width/t.height;const i=t.centerOffset||new u.Vector3;let r=0,o=0;this.halfFov=t._fov/2;const a=Math.PI/2+t._pitch,n=Math.cos(Math.PI/2-t._pitch);this.cameraToCenterDistance=.5/Math.tan(this.halfFov)*t.height;let s=1;const l=this.worldSize();if(this.map.tb.mapboxVersion>=2){s=this.mercatorZfromAltitude(1,t.center.lat)*l;const e=t._fov*(.5+t.centerOffset.y/t.height),i=t.elevation?t.elevation.getMinElevationBelowMSL()*s:0,h=(t._camera.position[2]*l-i)/Math.cos(t._pitch);o=n*(Math.sin(e)*h/Math.sin(y.clamp(Math.PI-a-e,.01,Math.PI-.01)))+h;const c=h*(1/t._horizonShift);r=Math.min(1.01*o,c)}else{o=n*(Math.sin(this.halfFov)*this.cameraToCenterDistance/Math.sin(Math.PI-a-this.halfFov))+this.cameraToCenterDistance,r=1.01*o}this.cameraTranslateZ=(new u.Matrix4).makeTranslation(0,0,this.cameraToCenterDistance);const h=t.height/50,c=Math.max(h*n,h),d=t.height,p=t.width;this.camera instanceof u.OrthographicCamera?this.camera.projectionMatrix=y.makeOrthographicMatrix(p/-2,p/2,d/2,d/-2,c,r):this.camera.projectionMatrix=y.makePerspectiveMatrix(t._fov,p/d,c,r),this.camera.projectionMatrix.elements[8]=2*-i.x/t.width,this.camera.projectionMatrix.elements[9]=2*i.y/t.height;let m=this.calcCameraMatrix(t._pitch,t.angle);t.elevation&&(m.elements[14]=t._camera.position[2]*l),this.camera.matrixWorld.copy(m);let f=t.scale*this.state.worldSizeRatio,g=new u.Matrix4,b=new u.Matrix4,x=new u.Matrix4;g.makeScale(f,f,f);let w=t.x||t.point.x,M=t.y||t.point.y;b.makeTranslation(-w,M,0),x.makeRotationZ(Math.PI),this.world.matrix=(new u.Matrix4).premultiply(x).premultiply(this.state.translateCenter).premultiply(g).premultiply(b),this.map.fire("CameraSynced",{detail:{nearZ:c,farZ:r,pitch:t._pitch,angle:t.angle,furthestDistance:o,cameraToCenterDistance:this.cameraToCenterDistance,t:this.map.transform,tbProjMatrix:this.camera.projectionMatrix.elements,tbWorldMatrix:this.world.matrix.elements,cameraSyn:v}})},worldSize(){let e=this.map.transform;return e.tileSize*e.scale},worldSizeFromZoom(){let e=this.map.transform;return Math.pow(2,e.zoom)*e.tileSize},mercatorZfromAltitude(e,t){return e/this.circumferenceAtLatitude(t)},mercatorZfromZoom(){return this.cameraToCenterDistance/this.worldSizeFromZoom()},circumferenceAtLatitude:e=>g.EARTH_CIRCUMFERENCE*Math.cos(e*Math.PI/180),calcCameraMatrix(e,t,i){const r=this.map.transform,o=void 0===e?r._pitch:e,a=void 0===t?r.angle:t,n=void 0===i?this.cameraTranslateZ:i;return(new u.Matrix4).premultiply(n).premultiply((new u.Matrix4).makeRotationX(o)).premultiply((new u.Matrix4).makeRotationZ(a))},updateCameraState(){let e=this.map.transform;if(!e.height)return;const t=e._camera.forward(),i=e.cameraToCenterDistance,r=e.point;e._cameraZoom?e._cameraZoom:e._zoom;const o=this.mercatorZfromZoom(e)-this.mercatorZfromAltitude(e._centerAltitude,e.center.lat),a=e.cameraToCenterDistance/o;return[r.x/this.worldSize()-t[0]*i/a,r.y/this.worldSize()-t[1]*i/a,this.mercatorZfromAltitude(e._centerAltitude,e._center.lat)+-t[2]*i/a]},getWorldToCamera(e,t){let i=this.map.transform;const r=new u.Matrix4,o=new u.Matrix4,a=i._camera._orientation,n=i._camera.position,s=new u.Vector3(n[0],n[1],n[2]),l=new u.Quaternion;l.set(a[0],a[1],a[2],a[3]);const h=l.conjugate();return s.multiplyScalar(-e),o.makeTranslation(s.x,s.y,s.z),r.makeRotationFromQuaternion(h).premultiply(o),r.elements[1]*=-1,r.elements[5]*=-1,r.elements[9]*=-1,r.elements[13]*=-1,r.elements[8]*=t,r.elements[9]*=t,r.elements[10]*=t,r.elements[11]*=t,r},translate(e,t,i){let r,o,a,n,s,l,h,c,u,d,p,m,f=i[0]||i.x,g=i[1]||i.y,b=i[2]||i.z;return t===e?(e[12]=t[0]*f+t[4]*g+t[8]*b+t[12],e[13]=t[1]*f+t[5]*g+t[9]*b+t[13],e[14]=t[2]*f+t[6]*g+t[10]*b+t[14],e[15]=t[3]*f+t[7]*g+t[11]*b+t[15]):(r=t[0],o=t[1],a=t[2],n=t[3],s=t[4],l=t[5],h=t[6],c=t[7],u=t[8],d=t[9],p=t[10],m=t[11],e[0]=r,e[1]=o,e[2]=a,e[3]=n,e[4]=s,e[5]=l,e[6]=h,e[7]=c,e[8]=u,e[9]=d,e[10]=p,e[11]=m,e[12]=r*f+s*g+u*b+t[12],e[13]=o*f+l*g+d*b+t[13],e[14]=a*f+h*g+p*b+t[14],e[15]=n*f+c*g+m*b+t[15]),e}};var x=Math.PI,w=Math.sin,M=Math.cos,j=Math.tan,S=Math.asin,O=Math.atan2,L=Math.acos,C=x/180,_=864e5,P=2440588,D=2451545;function z(e){return e.valueOf()/_-.5+P}function T(e){return new Date((e+.5-P)*_)}function F(e){return z(e)-D}var E=23.4397*C;function A(e,t){return O(w(e)*M(E)-j(t)*w(E),M(e))}function R(e,t){return S(w(t)*M(E)+M(t)*w(E)*w(e))}function k(e,t,i){return O(w(e),M(e)*w(t)-j(i)*M(t))}function H(e,t,i){return S(w(t)*w(i)+M(t)*M(i)*M(e))}function B(e,t){return C*(280.16+360.9856235*e)-t}function I(e){return C*(357.5291+.98560028*e)}function N(e){return e+C*(1.9148*w(e)+.02*w(2*e)+3e-4*w(3*e))+102.9372*C+x}function V(e){var t=N(I(e));return{dec:R(t,0),ra:A(t,0)}}var W={getPosition:function(e,t,i){var r=C*-i,o=C*t,a=F(e),n=V(a),s=B(a,r)-n.ra;return{azimuth:k(s,o,n.dec),altitude:H(s,o,n.dec)}},toJulian:function(e){return z(e)}},G=W.times=[[-.833,"sunrise","sunset"],[-.3,"sunriseEnd","sunsetStart"],[-6,"dawn","dusk"],[-12,"nauticalDawn","nauticalDusk"],[-18,"nightEnd","night"],[6,"goldenHourEnd","goldenHour"]];W.addTime=function(e,t,i){G.push([e,t,i])};var Z=9e-4;function q(e,t,i){return Z+(e+t)/(2*x)+i}function U(e,t,i){return D+e+.0053*w(t)-.0069*w(2*i)}function Q(e,t,i,r,o,a,n){var s=function(e,t,i){return L((w(e)-w(t)*w(i))/(M(t)*M(i)))}(e,i,r);return U(q(s,t,o),a,n)}function J(e){var t=C*(134.963+13.064993*e),i=C*(93.272+13.22935*e),r=C*(218.316+13.176396*e)+6.289*C*w(t),o=5.128*C*w(i),a=385001-20905*M(t);return{ra:A(r,o),dec:R(r,o),dist:a}}function X(e,t){return new Date(e.valueOf()+t*_/24)}W.getTimes=function(e,t,i,r){var o,a,n,s,l,h=C*-i,c=C*t,u=function(e){return-2.076*Math.sqrt(e)/60}(r=r||0),d=function(e,t){return Math.round(e-Z-t/(2*x))}(F(e),h),p=q(0,h,d),m=I(p),f=N(m),g=R(f,0),b=U(p,m,f),y={solarNoon:T(b),nadir:T(b-.5)};for(o=0,a=G.length;o<a;o+=1)l=b-((s=Q(((n=G[o])[0]+u)*C,h,c,g,d,m,f))-b),y[n[1]]=T(l),y[n[2]]=T(s);return y},W.getMoonPosition=function(e,t,i){var r=C*-i,o=C*t,a=F(e),n=J(a),s=B(a,r)-n.ra,l=H(s,o,n.dec),h=O(w(s),j(o)*M(n.dec)-w(n.dec)*M(s));return l+=function(e){return e<0&&(e=0),2967e-7/Math.tan(e+.00312536/(e+.08901179))}(l),{azimuth:k(s,o,n.dec),altitude:l,distance:n.dist,parallacticAngle:h}},W.getMoonIllumination=function(e){var t=F(e||new Date),i=V(t),r=J(t),o=149598e3,a=L(w(i.dec)*w(r.dec)+M(i.dec)*M(r.dec)*M(i.ra-r.ra)),n=O(o*w(a),r.dist-o*M(a)),s=O(M(i.dec)*w(i.ra-r.ra),w(i.dec)*M(r.dec)-M(i.dec)*w(r.dec)*M(i.ra-r.ra));return{fraction:(1+M(n))/2,phase:.5+.5*n*(s<0?-1:1)/Math.PI,angle:s}},W.getMoonTimes=function(e,t,i,r){var o=new Date(e);r?o.setUTCHours(0,0,0,0):o.setHours(0,0,0,0);for(var a,n,s,l,h,c,u,d,p,m,f,g,b,y=.133*C,v=W.getMoonPosition(o,t,i).altitude-y,x=1;x<=24&&(a=W.getMoonPosition(X(o,x),t,i).altitude-y,d=((h=(v+(n=W.getMoonPosition(X(o,x+1),t,i).altitude-y))/2-a)*(u=-(c=(n-v)/2)/(2*h))+c)*u+a,m=0,(p=c*c-4*h*a)>=0&&(f=u-(b=Math.sqrt(p)/(2*Math.abs(h))),g=u+b,Math.abs(f)<=1&&m++,Math.abs(g)<=1&&m++,f<-1&&(f=g)),1===m?v<0?s=x+f:l=x+f:2===m&&(s=x+(d<0?g:f),l=x+(d<0?f:g)),!s||!l);x+=2)v=n;var w={};return s&&(w.rise=X(o,s)),l&&(w.set=X(o,l)),s||l||(w[d>0?"alwaysUp":"alwaysDown"]=!0),w};var K={material:"MeshBasicMaterial",color:"black",opacity:1};function Y(e){var t;function i(){return new u[K.material]({color:K.color})}return e?((t=(e=y._validate(e,K)).material&&e.material.isMaterial?e.material:e.material||e.color||e.opacity?new u[e.material]({color:e.color,transparent:e.opacity<1}):i()).opacity=e.opacity,e.side&&(t.side=e.side)):t=i(),t}function $(e){this.map=e,this.enrolledObjects=[],this.previousFrameTime}$.prototype={unenroll:function(e){this.enrolledObjects.splice(this.enrolledObjects.indexOf(e),1)},enroll:function(e){if(e.clock=new u.Clock,e.hasDefaultAnimation=!1,e.defaultAction,e.actions=[],e.mixer,e.animations&&e.animations.length>0){e.hasDefaultAnimation=!0;let i=e.userData.defaultAnimation?e.userData.defaultAnimation:0;e.mixer=new u.AnimationMixer(e),t(i)}function t(t){for(let i=0;i<e.animations.length;i++){t>e.animations.length&&console.log("The animation index "+t+" doesn't exist for this object");let r=e.animations[i],o=e.mixer.clipAction(r);e.actions.push(o),t===i?(e.defaultAction=o,o.setEffectiveWeight(1)):o.setEffectiveWeight(0),o.play()}}let i=!1;Object.defineProperty(e,"isPlaying",{get:()=>i,set(t){i!=t&&(i=t,e.dispatchEvent({type:"IsPlayingChanged",detail:e}))}}),this.enrolledObjects.push(e),e.animationQueue=[],e.set=function(t){if(t.duration>0){let i={start:Date.now(),expiration:Date.now()+t.duration,endState:{}};y.extend(t,i);let r=t.coords,o=t.rotation,a=t.scale||t.scaleX||t.scaleY||t.scaleZ;if(o){let i=e.rotation;t.startRotation=[i.x,i.y,i.z],t.endState.rotation=y.types.rotation(t.rotation,t.startRotation),t.rotationPerMs=t.endState.rotation.map(function(e,i){return(e-t.startRotation[i])/t.duration})}if(a){let i=e.scale;t.startScale=[i.x,i.y,i.z],t.endState.scale=y.types.scale(t.scale,t.startScale),t.scalePerMs=t.endState.scale.map(function(e,i){return(e-t.startScale[i])/t.duration})}r&&(t.pathCurve=new u.CatmullRomCurve3(y.lnglatsToWorld([e.coordinates,t.coords])));let n={type:"set",parameters:t};this.animationQueue.push(n),tb.map.repaint=!0}else this.stop(),t.rotation=y.radify(t.rotation),this._setObject(t);return this},e.animationMethod=null,e.stop=function(t){return e.mixer&&(e.isPlaying=!1,cancelAnimationFrame(e.animationMethod)),this.animationQueue=[],this},e.followPath=function(e,t){let i={type:"followPath",parameters:y._validate(e,ee.followPath)};return y.extend(i.parameters,{pathCurve:new u.CatmullRomCurve3(y.lnglatsToWorld(e.path)),start:Date.now(),expiration:Date.now()+i.parameters.duration,cb:t}),this.animationQueue.push(i),tb.map.repaint=!0,this},e._setObject=function(t){e.setScale();let i=t.position,r=t.rotation,o=t.scale,a=t.worldCoordinates,n=t.quaternion,s=t.translate,l=t.worldTranslate;if(i){this.coordinates=i;let e=y.projectToWorld(i);this.position.copy(e)}if(s){this.coordinates=[this.coordinates[0]+s[0],this.coordinates[1]+s[1],this.coordinates[2]+s[2]];let e=y.projectToWorld(s);this.position.copy(e),t.position=this.coordinates}if(l){this.translateX(l.x),this.translateY(l.y),this.translateZ(l.z);let e=y.unprojectFromWorld(this.position);this.coordinates=t.position=e}if(r&&(this.rotation.set(r[0],r[1],r[2]),t.rotation=new u.Vector3(r[0],r[1],r[2])),o&&(this.scale.set(o[0],o[1],o[2]),t.scale=this.scale),n&&(this.quaternion.setFromAxisAngle(n[0],n[1]),t.rotation=n[0].multiplyScalar(n[1])),a){this.position.copy(a);let e=y.unprojectFromWorld(a);this.coordinates=t.position=e}this.setBoundingBoxShadowFloor(),this.setReceiveShadowFloor(),this.updateMatrixWorld(),tb.map.repaint=!0;let h={type:"ObjectChanged",detail:{object:this,action:{position:t.position,rotation:t.rotation,scale:t.scale}}};this.dispatchEvent(h)},e.playDefault=function(t){if(e.mixer&&e.hasDefaultAnimation){let i={start:Date.now(),expiration:Date.now()+t.duration,endState:{}};y.extend(t,i),e.mixer.timeScale=t.speed||1;let r={type:"playDefault",parameters:t};return this.animationQueue.push(r),tb.map.repaint=!0,this}},e.playAnimation=function(i){e.mixer&&(i.animation&&t(i.animation),e.playDefault(i))},e.pauseAllActions=function(){e.mixer&&e.actions.forEach(function(e){e.paused=!0})},e.unPauseAllActions=function(){e.mixer&&e.actions.forEach(function(e){e.paused=!1})},e.deactivateAllActions=function(){e.mixer&&e.actions.forEach(function(e){e.stop()})},e.activateAllActions=function(){e.mixer&&e.actions.forEach(function(e){e.play()})},e.idle=function(){return e.mixer&&e.mixer.update(.01),tb.map.repaint=!0,this}},update:function(e){if(void 0===this.previousFrameTime&&(this.previousFrameTime=e),!this.enrolledObjects)return!1;for(let t=this.enrolledObjects.length-1;t>=0;t--){let i=this.enrolledObjects[t];if(i.animationQueue&&0!==i.animationQueue.length)for(let t=i.animationQueue.length-1;t>=0;t--){let r=i.animationQueue[t];if(!r)continue;let o=r.parameters;if(!o.expiration)return i.animationQueue.splice(t,1),void(i.animationQueue[t]&&(i.animationQueue[t].parameters.start=e));if(e>=o.expiration)o.expiration=!1,"playDefault"===r.type?i.stop():(o.endState&&i._setObject(o.endState),void 0!==o.cb&&o.cb());else{let t=(e-o.start)/o.duration;if("set"===r.type){let e={};o.pathCurve&&(e.worldCoordinates=o.pathCurve.getPoint(t)),o.rotationPerMs&&(e.rotation=o.startRotation.map(function(e,i){return e+o.rotationPerMs[i]*t*o.duration})),o.scalePerMs&&(e.scale=o.startScale.map(function(e,i){return e+o.scalePerMs[i]*t*o.duration})),i._setObject(e)}if("followPath"===r.type){let e={worldCoordinates:o.pathCurve.getPointAt(t)};if(o.trackHeading){let i=o.pathCurve.getTangentAt(t).normalize(),r=new u.Vector3(0,0,0),a=new u.Vector3(0,1,0);r.crossVectors(a,i).normalize();let n=Math.acos(a.dot(i));e.quaternion=[r,n]}i._setObject(e)}"playDefault"===r.type&&(i.activateAllActions(),i.isPlaying=!0,i.animationMethod=requestAnimationFrame(this.update),i.mixer.update(i.clock.getDelta()),tb.map.repaint=!0)}}}this.previousFrameTime=e}};const ee={followPath:{path:null,duration:1e3,trackHeading:!0}};class te extends u.Object3D{constructor(e){super(),this.element=e||document.createElement("div"),this.element.style.position="absolute",this.element.style.userSelect="none",this.element.setAttribute("draggable",!1),this.alwaysVisible=!1,Object.defineProperty(this,"layer",{get(){return this.parent&&this.parent.parent?this.parent.parent.layer:null}}),this.dispose=function(){this.remove(),this.element=null},this.remove=function(){this.element instanceof Element&&null!==this.element.parentNode&&this.element.parentNode.removeChild(this.element)},this.addEventListener("removed",function(){this.remove()})}copy(e,t){return super.copy(e,t),this.element=e.element.cloneNode(!0),this}}te.prototype.isCSS2DObject=!0;const ie=new u.Vector3,re=new u.Matrix4,oe=new u.Matrix4,ae=new u.Vector3,ne=new u.Vector3;class se{constructor(){const e=this;let t,i,r,o;const a={objects:new WeakMap,list:new Map};this.cacheList=a.list;const n=document.createElement("div");function s(t,i,h){if(t.isCSS2DObject)if(t.visible){t.onBeforeRender(e,i,h),ie.setFromMatrixPosition(t.matrixWorld),ie.applyMatrix4(oe);const s=t.element;var c;c=/apple/i.test(navigator.vendor)?"translate(-50%,-50%) translate("+Math.round(ie.x*r+r)+"px,"+Math.round(-ie.y*o+o)+"px)":"translate(-50%,-50%) translate("+(ie.x*r+r)+"px,"+(-ie.y*o+o)+"px)",s.style.WebkitTransform=c,s.style.MozTransform=c,s.style.oTransform=c,s.style.transform=c,s.style.display=t.visible&&ie.z>=-1&&ie.z<=1?"":"none";const u={distanceToCameraSquared:l(h,t)};a.objects.set({key:t.uuid},u),a.list.set(t.uuid,t),s.parentNode!==n&&n.appendChild(s),t.onAfterRender(e,i,h)}else a.objects.delete({key:t.uuid}),a.list.delete(t.uuid),t.remove();for(let e=0,r=t.children.length;e<r;e++)s(t.children[e],i,h)}function l(e,t){return ae.setFromMatrixPosition(e.matrixWorld),ne.setFromMatrixPosition(t.matrixWorld),ae.distanceToSquared(ne)}n.style.overflow="hidden",this.domElement=n,this.getSize=function(){return{width:t,height:i}},this.render=function(e,t){!0===e.autoUpdate&&e.updateMatrixWorld(),null===t.parent&&t.updateMatrixWorld(),re.copy(t.matrixWorldInverse),oe.multiplyMatrices(t.projectionMatrix,re),s(e,e,t),function(e){const t=function(e){const t=[];return e.traverse(function(e){e.isCSS2DObject&&t.push(e)}),t}(e).sort(function(e,t){let i=a.objects.get({key:e.uuid}),r=a.objects.get({key:t.uuid});if(i&&r){return i.distanceToCameraSquared-r.distanceToCameraSquared}}),i=t.length;for(let r=0,o=t.length;r<o;r++)t[r].element.style.zIndex=i-r}(e)},this.setSize=function(e,a){t=e,i=a,r=t/2,o=i/2,n.style.width=e+"px",n.style.height=a+"px"}}}function le(){}function he(e){let t=(e=y._validate(e,le.prototype._defaults.Object3D)).obj;const i=y.types.rotation(e.rotation,[0,0,0]),r=y.types.scale(e.scale,[1,1,1]);t.rotation.set(i[0],i[1],i[2]),t.scale.set(r[0],r[1],r[2]),t.name="model";let o=le.prototype._makeGroup(t,e);return e.obj.name="model",le.prototype._addMethods(o),o.setAnchor(e.anchor),o.setCenter(e.adjustment),o.raycasted=e.raycasted,o.visibility=!0,o}function ce(e){e=y._validate(e,le.prototype._defaults.extrusion);let t=ce.prototype.buildShape(e.coordinates),i=ce.prototype.buildGeometry(t,e.geometryOptions),r=new u.Mesh(i,e.materials);return e.obj=r,new he(e)}le.prototype={line:function(e){e=y._validate(e,this._defaults.line);var t=y.lnglatsToWorld(e.geometry),i=y.normalizeVertices(t),r=y.flattenVectors(i.vertices),o=new Float32Array(r),a=new u.BufferGeometry;a.setAttribute("position",new u.BufferAttribute(o,3));var n=new u.LineBasicMaterial({color:16711680,linewidth:21}),s=new u.Line(a,n);return s.options=options||{},s.position.copy(i.position),s},extrusion:function(e){},unenroll:function(e,t){t||this.animationManager.unenroll(e)},_addMethods:function(e,t){var i=this;const r="label",o="tooltip",a="help",n="shadowPlane";if(t);else{let t=function(e,t,i,r){let o=y.radify(r);e.position.sub(t),e.position.applyAxisAngle(i,o),e.position.add(t),e.rotateOnAxis(i,o),tb.map.repaint=!0},s=function(e){return Math.pow(2,e)};e.coordinates||(e.coordinates=[0,0,0]),Object.defineProperty(e,"model",{get:()=>e.getObjectByName("model")}),Object.defineProperty(e,"animations",{get(){const t=e.model;return t?t.animations:null}}),i.animationManager.enroll(e),e.setCoords=function(t){return e.userData.topMargin&&e.userData.feature&&(t[2]+=((e.userData.feature.properties.height||0)-(e.userData.feature.properties.base_height||e.userData.feature.properties.min_height||0))*(e.userData.topMargin||0)),e.coordinates=t,e.set({position:t}),e},e.setTranslate=function(t){return e.set({translate:t}),e},e.setRotation=function(t){"number"==typeof t&&(t={z:t});var i={x:y.radify(t.x)||e.rotation.x,y:y.radify(t.y)||e.rotation.y,z:y.radify(t.z)||e.rotation.z};e._setObject({rotation:[i.x,i.y,i.z]})},e.calculateAdjustedPosition=function(t,i,r){let o=t.slice(),a=y.unprojectFromWorld(e.modelSize);return r?(o[0]-=0!=i.x?a[0]/i.x:0,o[1]-=0!=i.y?a[1]/i.y:0,o[2]-=0!=i.z?a[2]/i.z:0):(o[0]+=0!=i.x?a[0]/i.x:0,o[1]+=0!=i.y?a[1]/i.y:0,o[2]+=0!=i.z?a[2]/i.z:0),o},e.setRotationAxis=function(i){"number"==typeof i&&(i={z:i});let r=e.modelBox(),o=new u.Vector3(r.max.x,r.max.y,r.min.z);0!=i.x&&t(e,o,new u.Vector3(0,0,1),i.x),0!=i.y&&t(e,o,new u.Vector3(0,0,1),i.y),0!=i.z&&t(e,o,new u.Vector3(0,0,1),i.z)},Object.defineProperty(e,"scaleGroup",{get:()=>e.getObjectByName("scaleGroup")}),Object.defineProperty(e,"boxGroup",{get:()=>e.getObjectByName("boxGroup")}),Object.defineProperty(e,"boundingBox",{get:()=>e.getObjectByName("boxModel")}),Object.defineProperty(e,"boundingBoxShadow",{get:()=>e.getObjectByName("boxShadow")}),e.drawBoundingBox=function(){let t=e.box3(),i=new u.Group;i.name="boxGroup",i.updateMatrixWorld(!0);let r=new u.Box3Helper(t,le.prototype._defaults.colors.yellow);r.name="boxModel",i.add(r),r.layers.disable(0);let o=t.clone();o.max.z=o.min.z;let a=new u.Box3Helper(o,le.prototype._defaults.colors.black);a.name="boxShadow",i.add(a),a.layers.disable(0),i.visible=!1,e.scaleGroup.add(i),e.setBoundingBoxShadowFloor()},e.setBoundingBoxShadowFloor=function(){if(e.boundingBoxShadow){let t=-e.modelHeight,i=e.rotation,r=e.boundingBoxShadow;r.box.max.z=r.box.min.z=t,r.rotation.y=i.y,r.rotation.x=-i.x}},e.setAnchor=function(t){const i=e.box3(),r=i.getCenter(new u.Vector3);switch(e.none={x:0,y:0,z:0},e.center={x:r.x,y:r.y,z:i.min.z},e.bottom={x:r.x,y:i.max.y,z:i.min.z},e.bottomLeft={x:i.max.x,y:i.max.y,z:i.min.z},e.bottomRight={x:i.min.x,y:i.max.y,z:i.min.z},e.top={x:r.x,y:i.min.y,z:i.min.z},e.topLeft={x:i.max.x,y:i.min.y,z:i.min.z},e.topRight={x:i.min.x,y:i.min.y,z:i.min.z},e.left={x:i.max.x,y:r.y,z:i.min.z},e.right={x:i.min.x,y:r.y,z:i.min.z},t){case"center":e.anchor=e.center;break;case"top":e.anchor=e.top;break;case"top-left":e.anchor=e.topLeft;break;case"top-right":e.anchor=e.topRight;break;case"left":e.anchor=e.left;break;case"right":e.anchor=e.right;break;case"bottom":e.anchor=e.bottom;break;case"bottom-left":default:e.anchor=e.bottomLeft;break;case"bottom-right":e.anchor=e.bottomRight;break;case"auto":case"none":e.anchor=e.none}e.model.position.set(-e.anchor.x,-e.anchor.y,-e.anchor.z)},e.setCenter=function(t){if(t&&(0!=t.x||0!=t.y||0!=t.z)){let i=e.getSize();e.anchor={x:e.anchor.x-i.x*t.x,y:e.anchor.y-i.y*t.y,z:e.anchor.z-i.z*t.z},e.model.position.set(-e.anchor.x,-e.anchor.y,-e.anchor.z)}},Object.defineProperty(e,"label",{get:()=>e.getObjectByName(r)}),Object.defineProperty(e,"tooltip",{get:()=>e.getObjectByName(o)}),Object.defineProperty(e,"help",{get:()=>e.getObjectByName(a)});let l=!1;Object.defineProperty(e,"hidden",{get:()=>l,set(t){l!=t&&(l=t,e.visibility=!l)}}),Object.defineProperty(e,"visibility",{get:()=>e.visible,set(t){let i=t;if("visible"==t||1==t)i=!0,e.label&&(e.label.visible=i);else{if("none"!=t&&0!=t)return;i=!1,e.label&&e.label.alwaysVisible&&(e.label.visible=i),e.tooltip&&(e.tooltip.visible=i)}if(e.visible!=i){if(e.hidden&&i)return;e.visible=i,e.model&&e.model.traverse(function(t){"Mesh"!=t.type&&"SkinnedMesh"!=t.type||(i&&e.raycasted?t.layers.enable(0):t.layers.disable(0)),"LineSegments"==t.type&&t.layers.disableAll()})}}}),e.addLabel=function(t,i,r,o){t&&e.drawLabelHTML(t,i,r,o)},e.removeLabel=function(){e.removeCSS2D(r)},e.drawLabelHTML=function(t,o=!1,a=e.anchor,n=.5){let s=i.drawLabelHTML(t,le.prototype._defaults.label.cssClass),l=e.addCSS2D(s,r,a,n);return l.alwaysVisible=o,l.visible=o,l},e.addTooltip=function(t,i,r,a=!0,n=1){let s=e.addHelp(t,o,i,r,n);s.visible=!1,s.custom=a},e.removeTooltip=function(){e.removeCSS2D(o)},e.addHelp=function(t,r=a,o=!1,n=e.anchor,s=0){let l=i.drawTooltip(t,o),h=e.addCSS2D(l,r,n,s);return h.visible=!0,h},e.removeHelp=function(){e.removeCSS2D(a)},e.addCSS2D=function(t,i,r=e.anchor,o=1){if(t){const a=e.box3(),n=a.getSize(new u.Vector3);let s={x:a.max.x,y:a.max.y,z:a.min.z};e.removeCSS2D(i);let l=new te(t);return l.name=i,l.position.set(.5*-n.x-e.model.position.x-r.x+s.x,.5*-n.y-e.model.position.y-r.y+s.y,n.z*o),l.visible=!1,e.scaleGroup.add(l),l}},e.removeCSS2D=function(t){let i=e.getObjectByName(t);if(i){i.dispose();let t=e.scaleGroup.children;t.splice(t.indexOf(i),1)}},Object.defineProperty(e,"shadowPlane",{get:()=>e.getObjectByName(n)});let h=!1;Object.defineProperty(e,"castShadow",{get:()=>h,set(t){if(e.model&&h!==t){if(e.model.traverse(function(e){e.isMesh&&(e.castShadow=!0)}),t){const i=e.modelSize,r=[i.x,i.y,i.z,e.modelHeight],o=10*Math.max(...r),a=new u.PlaneGeometry(o,o),s=new u.ShadowMaterial;s.opacity=.5;let l=new u.Mesh(a,s);l.name=n,l.layers.enable(1),l.layers.disable(0),l.receiveShadow=t,e.add(l)}else e.traverse(function(t){t.isMesh&&t.material instanceof u.ShadowMaterial&&e.remove(t)});h=t}}}),e.setReceiveShadowFloor=function(){if(e.castShadow){let t=e.shadowPlane,i=t.position,r=t.rotation;if(i.z=-e.modelHeight,r.y=e.rotation.y,r.x=-e.rotation.x,"meters"===e.userData.units){const r=e.modelSize,o=[r.x,r.y,r.z,-i.z],a=10*Math.max(...o)/t.geometry.parameters.width;t.scale.set(a,a,a)}}};let c=!1;Object.defineProperty(e,"receiveShadow",{get:()=>c,set(t){e.model&&c!==t&&(e.model.traverse(function(e){e.isMesh&&(e.receiveShadow=!0)}),c=t)}});let d=!1;Object.defineProperty(e,"wireframe",{get:()=>d,set(t){e.model&&d!==t&&(e.model.traverse(function(e){if("Mesh"==e.type||"SkinnedMesh"==e.type){let i=[];Array.isArray(e.material)?i=e.material:i.push(e.material);let r=i[0];t?(e.userData.materials=r,e.material=r.clone(),e.material.wireframe=e.material.transparent=t,e.material.opacity=.3):(e.material.dispose(),e.material=e.userData.materials,e.userData.materials.dispose(),e.userData.materials=null),t?(e.layers.disable(0),e.layers.enable(1)):(e.layers.disable(1),e.layers.enable(0))}"LineSegments"==e.type&&e.layers.disableAll()}),d=t,e.dispatchEvent({type:"Wireframed",detail:e}))}});let p=null;Object.defineProperty(e,"color",{get:()=>p,set(t){e.model&&p!==t&&(e.model.traverse(function(e){if("Mesh"==e.type||"SkinnedMesh"==e.type){let i=[];Array.isArray(e.material)?i=e.material:i.push(e.material);let r=i[0];t?(e.userData.materials=r,e.material=new u.MeshStandardMaterial,e.material.color.setHex(t)):(e.material.dispose(),e.material=e.userData.materials,e.userData.materials.dispose(),e.userData.materials=null)}}),p=t)}});let m=!1;Object.defineProperty(e,"selected",{get:()=>m,set(t){t?(e.userData.bbox&&!e.boundingBox&&e.drawBoundingBox(),e.boxGroup&&(e.boundingBox.material=le.prototype._defaults.materials.boxSelectedMaterial,e.boundingBox.parent.visible=!0,e.boundingBox.layers.enable(1),e.boundingBoxShadow.layers.enable(1)),e.label&&!e.label.alwaysVisible&&(e.label.visible=!0)):(e.boxGroup&&e.remove(e.boxGroup),e.label&&!e.label.alwaysVisible&&(e.label.visible=!1),e.removeHelp()),e.tooltip&&(e.tooltip.visible=t),m!=t&&(m=t,e.dispatchEvent({type:"SelectedChange",detail:e}))}});let f=!0;Object.defineProperty(e,"raycasted",{get:()=>f,set(t){e.model&&f!==t&&(e.model.traverse(function(e){"Mesh"!=e.type&&"SkinnedMesh"!=e.type||(t?(e.layers.disable(1),e.layers.enable(0)):(e.layers.disable(0),e.layers.enable(1)))}),f=t)}});let g=!1;Object.defineProperty(e,"over",{get:()=>g,set(t){t?(e.selected||(e.userData.bbox&&!e.boundingBox&&e.drawBoundingBox(),e.userData.tooltip&&!e.tooltip&&e.addTooltip(e.uuid,!0,e.anchor,!1),e.boxGroup&&(e.boundingBox.material=le.prototype._defaults.materials.boxOverMaterial,e.boundingBox.parent.visible=!0,e.boundingBox.layers.enable(1),e.boundingBoxShadow.layers.enable(1))),e.label&&!e.label.alwaysVisible&&(e.label.visible=!0),e.dispatchEvent({type:"ObjectMouseOver",detail:e})):(e.selected||(e.boxGroup&&(e.remove(e.boxGroup),e.tooltip&&!e.tooltip.custom&&e.removeTooltip()),e.label&&!e.label.alwaysVisible&&(e.label.visible=!1)),e.dispatchEvent({type:"ObjectMouseOut",detail:e})),e.tooltip&&(e.tooltip.visible=t||e.selected),g=t}}),e.box3=function(){let t;if(e.updateMatrix(),e.updateMatrixWorld(!0,!0),e.model){let i=e.clone(!0),r=e.model.clone();if(t=(new u.Box3).setFromObject(r),e.parent){let o=new u.Matrix4,a=new u.Matrix4;e.matrix.extractRotation(o),a.copy(o).invert(),i.setRotationFromMatrix(a),t=(new u.Box3).setFromObject(r)}}return t},e.modelBox=function(){return e.box3()},e.getSize=function(){return e.box3().getSize(new u.Vector3(0,0,0))};let b=!1;Object.defineProperty(e,"modelSize",{get:()=>(b=e.getSize(),b),set(e){b!=e&&(b=e)}}),Object.defineProperty(e,"modelHeight",{get(){let t=e.coordinates[2]||0;return"scene"===e.userData.units&&(t*=e.unitsPerMeter/e.scale.x),t}}),Object.defineProperty(e,"unitsPerMeter",{get:()=>Number(y.projectedUnitsPerMeter(e.coordinates[1]).toFixed(7))}),Object.defineProperty(e,"fixedZoom",{get:()=>e.userData.fixedZoom,set(t){e.userData.fixedZoom!==t&&(e.userData.fixedZoom=t,e.userData.units=t?"scene":"meters")}}),e.setFixedZoom=function(t){if(null!=e.fixedZoom&&0!=e.fixedZoom){t||(t=e.userData.mapScale);let i=s(e.fixedZoom);if(i>t){let r=i/t;e.scale.set(r,r,r)}else e.scale.set(1,1,1)}},e.setScale=function(t){if("scene"!=e.userData.units){let t=e.unitsPerMeter;e.scale.set(t,t,t)}else e.fixedZoom?(t&&(e.userData.mapScale=t),e.setFixedZoom(e.userData.mapScale)):e.scale.set(1,1,1)},e.setObjectScale=function(t){e.setScale(t),e.setBoundingBoxShadowFloor(),e.setReceiveShadowFloor()}}e.add=function(t){return e.scaleGroup.add(t),t.position.z=e.coordinates[2]?-e.coordinates[2]:0,t},e.remove=function(t){t&&(t.traverse(e=>{if(e.geometry&&e.geometry.dispose(),e.material)if(e.material.isMaterial)s(e.material);else for(const t of e.material)s(t);e.dispose&&e.dispose()}),e.scaleGroup.remove(t),tb.map.repaint=!0)},e.duplicate=function(t){let r=e.clone(!0);if(r.getObjectByName("model").animations=e.animations,r.userData.feature&&(t&&t.feature&&(r.userData.feature=t.feature),r.userData.feature.properties.uuid=r.uuid),i._addMethods(r),!t||y.equal(t.scale,e.userData.scale))return r.copyAnchor(e),r;{r.userData=t,r.userData.isGeoGroup=!0,r.remove(r.boxGroup);const e=y.types.rotation(t.rotation,[0,0,0]),i=y.types.scale(t.scale,[1,1,1]);return r.model.position.set(0,0,0),r.model.rotation.set(e[0],e[1],e[2]),r.model.scale.set(i[0],i[1],i[2]),r.setAnchor(t.anchor),r.setCenter(t.adjustment),r}},e.copyAnchor=function(t){e.anchor=t.anchor,e.none={x:0,y:0,z:0},e.center=t.center,e.bottom=t.bottom,e.bottomLeft=t.bottomLeft,e.bottomRight=t.bottomRight,e.top=t.top,e.topLeft=t.topLeft,e.topRight=t.topRight,e.left=t.left,e.right=t.right},e.dispose=function(){le.prototype.unenroll(e),e.traverse(e=>{if((!e.parent||"world"!=e.parent.name)&&"threeboxObject"!==e.name){if(e.geometry&&e.geometry.dispose(),e.material)if(e.material.isMaterial)s(e.material);else for(const t of e.material)s(t);e.dispose&&e.dispose()}}),e.children=[]};const s=e=>{e.dispose();for(const i of Object.keys(e)){const t=e[i];t&&"object"==typeof t&&"minFilter"in t&&t.dispose()}let t=e;(t.map||t.alphaMap||t.aoMap||t.bumpMap||t.displacementMap||t.emissiveMap||t.envMap||t.lightMap||t.metalnessMap||t.normalMap||t.roughnessMap)&&(t.map&&t.map.dispose(),t.alphaMap&&t.alphaMap.dispose(),t.aoMap&&t.aoMap.dispose(),t.bumpMap&&t.bumpMap.dispose(),t.displacementMap&&t.displacementMap.dispose(),t.emissiveMap&&t.emissiveMap.dispose(),t.envMap&&t.envMap.dispose(),t.lightMap&&t.lightMap.dispose(),t.metalnessMap&&t.metalnessMap.dispose(),t.normalMap&&t.normalMap.dispose(),t.roughnessMap&&t.roughnessMap.dispose())};return e},_makeGroup:function(e,t){let i=new u.Group;i.name="scaleGroup",i.add(e);var r=new u.Group;if(r.userData=t||{},r.userData.isGeoGroup=!0,r.userData.feature&&(r.userData.feature.properties.uuid=r.uuid),i.length)for(o of i)r.add(o);else r.add(i);return r.name="threeboxObject",r},animationManager:new $,drawTooltip:function(e,t=!1){if(e){let i;if(t){let t=document.createElement("div");t.className="mapboxgl-popup-content";let r=document.createElement("strong");r.innerHTML=e,t.appendChild(r);let o=document.createElement("div");o.className="mapboxgl-popup-tip";let a=document.createElement("div");a.className="marker mapboxgl-popup-anchor-bottom",a.appendChild(o),a.appendChild(t),i=document.createElement("div"),i.className+="label3D",i.appendChild(a)}else i=document.createElement("span"),i.className=this._defaults.tooltip.cssClass,i.innerHTML=e;return i}},drawLabelHTML:function(e,t){let i=document.createElement("div");return i.className+=t,i.innerHTML="string"==typeof e?e:e.outerHTML,i},_defaults:{colors:{red:new u.Color(16711680),yellow:new u.Color(16776960),green:new u.Color(65280),black:new u.Color(0)},materials:{boxNormalMaterial:new u.LineBasicMaterial({color:new u.Color(16711680)}),boxOverMaterial:new u.LineBasicMaterial({color:new u.Color(16776960)}),boxSelectedMaterial:new u.LineBasicMaterial({color:new u.Color(65280)})},line:{geometry:null,color:"black",width:1,opacity:1},label:{htmlElement:null,cssClass:" label3D",alwaysVisible:!1,topMargin:-.5},tooltip:{text:"",cssClass:"toolTip text-xs",mapboxStyle:!1,topMargin:0},sphere:{position:[0,0,0],radius:1,sides:20,units:"scene",material:"MeshBasicMaterial",anchor:"bottom-left",bbox:!0,tooltip:!0,raycasted:!0},tube:{geometry:null,radius:1,sides:6,units:"scene",material:"MeshBasicMaterial",anchor:"center",bbox:!0,tooltip:!0,raycasted:!0},loadObj:{type:null,obj:null,units:"scene",scale:1,rotation:0,defaultAnimation:0,anchor:"bottom-left",bbox:!0,tooltip:!0,raycasted:!0,clone:!0,withCredentials:!1},Object3D:{obj:null,units:"scene",anchor:"bottom-left",bbox:!0,tooltip:!0,raycasted:!0},extrusion:{coordinates:[[[]]],geometryOptions:{},height:100,materials:new u.MeshPhongMaterial({color:6684672,side:u.DoubleSide}),scale:1,rotation:0,units:"scene",anchor:"center",bbox:!0,tooltip:!0,raycasted:!0}},geometries:{line:["LineString"],tube:["LineString"],sphere:["Point"]}},ce.prototype={buildShape:function(e){if(e[0]instanceof(u.Vector2||u.Vector3))return new u.Shape(e);let t=new u.Shape;for(let i=0;i<e.length;i++)0===i?t=new u.Shape(this.buildPoints(e[0],e[0])):t.holes.push(new u.Path(this.buildPoints(e[i],e[0])));return t},buildPoints:function(e,t){const i=[];let r=y.projectToWorld([t[0][0],t[0][1],0]);for(let o=0;o<e.length;o++){let t=y.projectToWorld([e[o][0],e[o][1],0]);i.push(new u.Vector2(y.toDecimal(t.x-r.x,9),y.toDecimal(t.y-r.y,9)))}return i},buildGeometry:function(e,t){let i=new u.ExtrudeGeometry(e,t);return i.computeBoundingBox(),i}};const ue=new t.OBJLoader,de=new i.MTLLoader,pe=new a.GLTFLoader,me=new r.FBXLoader,fe=new n.ColladaLoader;function ge(e,t,i){if(void 0===e)return console.error("Invalid options provided to loadObj()");let r;switch((e=y._validate(e,le.prototype._defaults.loadObj)).type||(e.type="mtl"),e.type){case"mtl":r=ue;break;case"gltf":case"glb":r=pe;break;case"fbx":r=me;break;case"dae":r=fe}de.withCredentials=e.withCredentials,de.load(e.mtl,function(o){o&&"mtl"==e.type&&(o.preload(),r.setMaterials(o));r.withCredentials=e.withCredentials,r.load(e.obj,r=>{let o=[];switch(e.type){case"mtl":r=r.children[0];break;case"gltf":case"glb":case"dae":o=r.animations,r=r.scene;break;case"fbx":o=r.animations}r.animations=o;const a=y.types.rotation(e.rotation,[0,0,0]),n=y.types.scale(e.scale,[1,1,1]);r.rotation.set(a[0],a[1],a[2]),r.scale.set(n[0],n[1],n[2]),e.normalize&&r.traverse(function(e){if(e.isMesh){let t;"MeshStandardMaterial"==e.material.type?(e.material.metalness&&(e.material.metalness*=.1),e.material.glossiness&&(e.material.glossiness*=.25),t=new u.Color(12,12,12)):"MeshPhongMaterial"==e.material.type&&(e.material.shininess=.1,t=new u.Color(20,20,20)),e.material.specular&&e.material.specular.isColor&&(e.material.specular=t)}}),r.name="model";let s=le.prototype._makeGroup(r,e);le.prototype._addMethods(s),s.setAnchor(e.anchor),s.setCenter(e.adjustment),s.raycasted=e.raycasted,i(s),t(s),s.setFixedZoom(e.mapScale),s.idle()},()=>null,t=>{console.error("Could not load model file: "+e.obj+" \n "+t.stack),i("Error loading the model")})},()=>null,e=>{console.warn("No material file found "+e.stack)})}function be(e){this.map=e,this.renderer=new se,this.renderer.setSize(this.map.getCanvas().clientWidth,this.map.getCanvas().clientHeight),this.renderer.domElement.style.position="absolute",this.renderer.domElement.id="labelCanvas",this.renderer.domElement.style.top=0,this.renderer.domElement.style.zIndex="0",this.map.getCanvasContainer().appendChild(this.renderer.domElement),this.scene,this.camera,this.dispose=function(){this.map.getCanvasContainer().removeChild(this.renderer.domElement),this.renderer.domElement.remove(),this.renderer={}},this.setSize=function(e,t){this.renderer.setSize(e,t)},this.map.on("resize",function(){this.renderer.setSize(this.map.getCanvas().clientWidth,this.map.getCanvas().clientHeight)}.bind(this)),this.state={reset:function(){}},this.render=async function(e,t){return this.scene=e,this.camera=t,new Promise(i=>{i(this.renderer.render(e,t))})},this.toggleLabels=async function(e,t){return new Promise(i=>{i(this.setVisibility(e,t,this.scene,this.camera,this.renderer))})},this.setVisibility=function(e,t,i,r,o){this.renderer.cacheList.forEach(function(a){a.visible!=t&&a.layer===e&&(t&&a.alwaysVisible||!t)&&(a.visible=t,o.renderObject(a,i,r))})}}class ye{constructor(e,t){this.id=e.layerId,this.type="custom",this.renderingMode="3d",this.opacity=.5,this.buildingsLayerId=e.buildingsLayerId,this.minAltitude=e.minAltitude||.1,this.tb=t}onAdd(e,t){this.map=e;const i=this.map.getLayer(this.buildingsLayerId).source;this.source=(this.map.style.sourceCaches||this.map.style._otherSourceCaches)[i],this.source||console.warn(`Can't find layer ${this.buildingsLayerId}'s source.`);const r=this._getVertexSource(),o=t.createShader(t.VERTEX_SHADER);t.shaderSource(o,r),t.compileShader(o);const a=t.createShader(t.FRAGMENT_SHADER);t.shaderSource(a,"\n\t\t\tvoid main() {\n\t\t\t\tgl_FragColor = vec4(0.0, 0.0, 0.0, 0.7);\n\t\t\t}\n\t\t\t"),t.compileShader(a),this.program=t.createProgram(),t.attachShader(this.program,o),t.attachShader(this.program,a),t.linkProgram(this.program),t.validateProgram(this.program),this.uMatrix=t.getUniformLocation(this.program,"u_matrix"),this.uHeightFactor=t.getUniformLocation(this.program,"u_height_factor"),this.uAltitude=t.getUniformLocation(this.program,"u_altitude"),this.uAzimuth=t.getUniformLocation(this.program,"u_azimuth"),this.tb.mapboxVersion>=2?this.aPosNormal=t.getAttribLocation(this.program,"a_pos_normal_ed"):(this.aPos=t.getAttribLocation(this.program,"a_pos"),this.aNormal=t.getAttribLocation(this.program,"a_normal_ed")),this.aBase=t.getAttribLocation(this.program,"a_base"),this.aHeight=t.getAttribLocation(this.program,"a_height")}render(e,t){if(!this.source)return;e.useProgram(this.program);const i=this.source.getVisibleCoordinates().reverse(),r=this.map.getLayer(this.buildingsLayerId),o=this.map.painter.context,{lng:a,lat:n}=this.map.getCenter(),s=this.tb.getSunPosition(this.tb.lightDateTime,[a,n]);e.uniform1f(this.uAltitude,s.altitude>this.minAltitude?s.altitude:0),e.uniform1f(this.uAzimuth,s.azimuth+3*Math.PI/2),e.enable(e.BLEND),e.blendFunc(e.SRC_ALPHA,e.ONE_MINUS_SRC_ALPHA),e.getExtension("EXT_blend_minmax"),e.disable(e.DEPTH_TEST);for(const l of i){const t=this.source.getTile(l),i=t.getBucket(r);if(!i)continue;const[a,n]=i.programConfigurations.programConfigurations[this.buildingsLayerId]._buffers;e.uniformMatrix4fv(this.uMatrix,!1,l.posMatrix||l.projMatrix),e.uniform1f(this.uHeightFactor,Math.pow(2,l.overscaledZ)/t.tileSize/8);for(const r of i.segments.get()){const t=o.currentNumAttributes||0,s=2;for(let i=s;i<t;i++)e.disableVertexAttribArray(i);const l=r.vertexOffset||0;e.enableVertexAttribArray(this.aNormal),e.enableVertexAttribArray(this.aHeight),e.enableVertexAttribArray(this.aBase),i.layoutVertexBuffer.bind(),this.tb.mapboxVersion>=2?(e.enableVertexAttribArray(this.aPosNormal),e.vertexAttribPointer(this.aPosNormal,4,e.SHORT,!1,8,8*l)):(e.enableVertexAttribArray(this.aPos),e.vertexAttribPointer(this.aPos,2,e.SHORT,!1,12,12*l),e.vertexAttribPointer(this.aNormal,4,e.SHORT,!1,12,4+12*l)),a.bind(),e.vertexAttribPointer(this.aHeight,1,e.FLOAT,!1,4,4*l),n.bind(),e.vertexAttribPointer(this.aBase,1,e.FLOAT,!1,4,4*l),i.indexBuffer.bind(),o.currentNumAttributes=s,e.drawElements(e.TRIANGLES,3*r.primitiveLength,e.UNSIGNED_SHORT,3*r.primitiveOffset*2)}}}_getVertexSource(){return this.tb.mapboxVersion>=2?"\n\t\t\t\tuniform mat4 u_matrix;\n\t\t\t\tuniform float u_height_factor;\n\t\t\t\tuniform float u_altitude;\n\t\t\t\tuniform float u_azimuth;\n\t\t\t\tattribute vec4 a_pos_normal_ed;\n\t\t\t\tattribute lowp vec2 a_base;\n\t\t\t\tattribute lowp vec2 a_height;\n\t\t\t\tvoid main() {\n\t\t\t\t\tfloat base = max(0.0, a_base.x);\n\t\t\t\t\tfloat height = max(0.0, a_height.x);\n\n\t\t\t\t\tvec3 pos_nx = floor(a_pos_normal_ed.xyz * 0.5);\n\t\t\t\t\tmediump vec3 top_up_ny = a_pos_normal_ed.xyz - 2.0 * pos_nx;\n\t\t\t\t\tfloat t = top_up_ny.x;\n\t\t\t\t\tvec4 pos = vec4(pos_nx.xy, t > 0.0 ? height : base, 1);\n\n\t\t\t\t\tfloat len = pos.z * u_height_factor / tan(u_altitude);\n\t\t\t\t\tpos.x += cos(u_azimuth) * len;\n\t\t\t\t\tpos.y += sin(u_azimuth) * len;\n\t\t\t\t\tpos.z = 0.0;\n\t\t\t\t\tgl_Position = u_matrix * pos;\n\t\t\t\t}\n\t\t\t":"\n\t\t\t\tuniform mat4 u_matrix;\n\t\t\t\tuniform float u_height_factor;\n\t\t\t\tuniform float u_altitude;\n\t\t\t\tuniform float u_azimuth;\n\t\t\t\tattribute vec2 a_pos;\n\t\t\t\tattribute vec4 a_normal_ed;\n\t\t\t\tattribute lowp vec2 a_base;\n\t\t\t\tattribute lowp vec2 a_height;\n\t\t\t\tvoid main() {\n\t\t\t\t\tfloat base = max(0.0, a_base.x);\n\t\t\t\t\tfloat height = max(0.0, a_height.x);\n\t\t\t\t\tfloat t = mod(a_normal_ed.x, 2.0);\n\t\t\t\t\tvec4 pos = vec4(a_pos, t > 0.0 ? height : base, 1);\n\t\t\t\t\tfloat len = pos.z * u_height_factor / tan(u_altitude);\n\t\t\t\t\tpos.x += cos(u_azimuth) * len;\n\t\t\t\t\tpos.y += sin(u_azimuth) * len;\n\t\t\t\t\tpos.z = 0.0;\n\t\t\t\t\tgl_Position = u_matrix * pos;\n\t\t\t\t}\n\t\t\t"}}function ve(e,t,i){this.init(e,t,i)}ve.prototype={repaint:function(){this.map.repaint=!0},init:function(e,t,i){this.options=y._validate(i||{},xe),this.map=e,this.map.tb=this,this.objects=new le,this.mapboxVersion=parseFloat(this.map.version),this.renderer=new u.WebGLRenderer({alpha:!0,antialias:!0,preserveDrawingBuffer:i.preserveDrawingBuffer,canvas:e.getCanvas(),context:t}),this.renderer.setPixelRatio(window.devicePixelRatio),this.renderer.setSize(this.map.getCanvas().clientWidth,this.map.getCanvas().clientHeight),this.renderer.outputColorSpace=u.SRGBColorSpace,this.renderer.autoClear=!1,this.labelRenderer=new be(this.map),this.scene=new u.Scene,this.world=new u.Group,this.world.name="world",this.scene.add(this.world),this.objectsCache=new Map,this.zoomLayers=[],this.fov=this.options.fov,this.orthographic=this.options.orthographic||!1,this.raycaster=new u.Raycaster,this.raycaster.layers.set(0),this.mapCenter=this.map.getCenter(),this.mapCenterUnits=y.projectToWorld([this.mapCenter.lng,this.mapCenter.lat]),this.lightDateTime=new Date,this.lightLng=this.mapCenter.lng,this.lightLat=this.mapCenter.lat,this.sunPosition,this.rotationStep=5,this.gridStep=6,this.altitudeStep=.1,this.defaultCursor="default",this.lights=this.initLights,this.options.defaultLights&&this.defaultLights(),this.options.realSunlight&&this.realSunlight(this.options.realSunlightHelper),this.skyLayerName="sky-layer",this.terrainSourceName="mapbox-dem",this.terrainExaggeration=1,this.terrainLayerName="",this.enableSelectingFeatures=this.options.enableSelectingFeatures||!1,this.enableSelectingObjects=this.options.enableSelectingObjects||!1,this.enableDraggingObjects=this.options.enableDraggingObjects||!1,this.enableRotatingObjects=this.options.enableRotatingObjects||!1,this.enableTooltips=this.options.enableTooltips||!1,this.multiLayer=this.options.multiLayer||!1,this.enableHelpTooltips=this.options.enableHelpTooltips||!1,this.map.on("style.load",function(){this.tb.zoomLayers=[],this.tb.options.multiLayer&&this.addLayer({id:"threebox_layer",type:"custom",renderingMode:"3d",map:this,onAdd:function(e,t){},render:function(e,t){this.map.tb.update()}}),this.once("idle",()=>{this.tb.setObjectsScale()}),this.tb.options.sky&&(this.tb.sky=!0),this.tb.options.terrain&&(this.tb.terrain=!0);["satellite","mapbox-mapbox-satellite","satelliteLayer"].forEach(e=>{this.getLayer(e)&&(this.tb.terrainLayerName=e)})}),this.map.on("load",function(){let t;this.selectedObject,this.selectedFeature,this.draggedObject,this.overedObject,this.overedFeature;let i,r=this.getCanvasContainer();this.getCanvasContainer().style.cursor=this.tb.defaultCursor;let o,a,n,s,l=[];function h(e){var t=r.getBoundingClientRect();return{x:e.originalEvent.clientX-t.left-r.clientLeft,y:e.originalEvent.clientY-t.top-r.clientTop}}this.unselectObject=function(){this.selectedObject.selected=!1,this.selectedObject=null},this.outObject=function(){this.overedObject.over=!1,this.overedObject=null},this.unselectFeature=function(e){void 0!==e.id&&(this.setFeatureState({source:e.source,sourceLayer:e.sourceLayer,id:e.id},{select:!1}),this.removeTooltip(e),(e=this.queryRenderedFeatures({layers:[e.layer.id],filter:["==",["id"],e.id]})[0])&&this.fire("SelectedFeatureChange",{detail:e}),this.selectedFeature=null)},this.selectFeature=function(e){this.selectedFeature=e,this.setFeatureState({source:this.selectedFeature.source,sourceLayer:this.selectedFeature.sourceLayer,id:this.selectedFeature.id},{select:!0}),this.selectedFeature=this.queryRenderedFeatures({layers:[this.selectedFeature.layer.id],filter:["==",["id"],this.selectedFeature.id]})[0],this.addTooltip(this.selectedFeature),this.fire("SelectedFeatureChange",{detail:this.selectedFeature})},this.outFeature=function(t){this.overedFeature&&void 0!==this.overedFeature&&this.overedFeature.id!=t&&(e.setFeatureState({source:this.overedFeature.source,sourceLayer:this.overedFeature.sourceLayer,id:this.overedFeature.id},{hover:!1}),this.removeTooltip(this.overedFeature),this.overedFeature=null)},this.addTooltip=function(e){if(!this.tb.enableTooltips)return;let t=this.tb.getFeatureCenter(e),i=this.tb.tooltip({text:e.properties.name||e.id||e.type,mapboxStyle:!0,feature:e});i.setCoords(t),this.tb.add(i,e.layer.id),e.tooltip=i,e.tooltip.tooltip.visible=!0},this.removeTooltip=function(e){e.tooltip&&(e.tooltip.visibility=!1,this.tb.remove(e.tooltip),e.tooltip=null)},e.onContextMenu=function(e){alert("contextMenu")},this.onClick=function(t){let i,r=[];if(e.tb.enableSelectingObjects&&(r=this.tb.queryRenderedFeatures(t.point)),i="object"==typeof r[0],i){let e=ve.prototype.findParent3DObject(r[0]);if(e){if(this.selectedFeature&&this.unselectFeature(this.selectedFeature),this.selectedObject){if(this.selectedObject.uuid!=e.uuid)this.selectedObject.selected=!1,e.selected=!0,this.selectedObject=e;else if(this.selectedObject.uuid==e.uuid)return void this.unselectObject()}else this.selectedObject=e,this.selectedObject.selected=!0;this.selectedObject.dispatchEvent({type:"Wireframed",detail:this.selectedObject}),this.selectedObject.dispatchEvent({type:"IsPlayingChanged",detail:this.selectedObject}),this.repaint=!0,t.preventDefault()}}else{let i=[];if(e.tb.enableSelectingFeatures&&(i=this.queryRenderedFeatures(t.point)),i.length>0&&"fill-extrusion"==i[0].layer.type&&void 0!==i[0].id)if(this.selectedObject&&this.unselectObject(),this.selectedFeature){if(this.selectedFeature.id!=i[0].id)this.unselectFeature(this.selectedFeature),this.selectFeature(i[0]);else if(this.selectedFeature.id==i[0].id)return void this.unselectFeature(this.selectedFeature)}else this.selectFeature(i[0])}},this.onMouseMove=function(r){let l,c=h(r);if(this.getCanvasContainer().style.cursor=this.tb.defaultCursor,r.originalEvent.altKey&&this.draggedObject){if(!e.tb.enableRotatingObjects)return;t="rotate",this.getCanvasContainer().style.cursor="move",Math.min(i.x,c.x),Math.max(i.x,c.x),Math.min(i.y,c.y),Math.max(i.y,c.y);let r={x:0,y:0,z:Math.round(s[2]+~~((c.x-i.x)/this.tb.rotationStep)%360*this.tb.rotationStep%360)};return this.draggedObject.setRotation(r),void(e.tb.enableHelpTooltips&&this.draggedObject.addHelp("rot: "+r.z+"&#176;"))}if(r.originalEvent.shiftKey&&this.draggedObject){if(!e.tb.enableDraggingObjects)return;t="translate",this.getCanvasContainer().style.cursor="move";let i=r.lngLat,n=[Number((i.lng+o).toFixed(this.tb.gridStep)),Number((i.lat+a).toFixed(this.tb.gridStep)),this.draggedObject.modelHeight];return this.draggedObject.setCoords(n),void(e.tb.enableHelpTooltips&&this.draggedObject.addHelp("lng: "+n[0]+"&#176;, lat: "+n[1]+"&#176;"))}if(r.originalEvent.ctrlKey&&this.draggedObject){if(!e.tb.enableDraggingObjects)return;t="altitude",this.getCanvasContainer().style.cursor="move";let i=r.point.y*this.tb.altitudeStep,o=[this.draggedObject.coordinates[0],this.draggedObject.coordinates[1],Number((-i-n).toFixed(this.tb.gridStep))];return this.draggedObject.setCoords(o),void(e.tb.enableHelpTooltips&&this.draggedObject.addHelp("alt: "+o[2]+"m"))}let u=[];if(e.tb.enableSelectingObjects&&(u=this.tb.queryRenderedFeatures(r.point)),l="object"==typeof u[0],l){let e=ve.prototype.findParent3DObject(u[0]);e&&(this.outFeature(this.overedFeature),this.getCanvasContainer().style.cursor="pointer",this.selectedObject&&e.uuid==this.selectedObject.uuid?this.selectedObject&&e.uuid==this.selectedObject.uuid&&(e.over=!0,this.overedObject=e):(this.overedObject&&this.overedObject.uuid!=e.uuid&&this.outObject(),e.over=!0,this.overedObject=e),this.repaint=!0,r.preventDefault())}else{this.overedObject&&this.outObject();let t=[];e.tb.enableSelectingFeatures&&(t=this.queryRenderedFeatures(r.point)),t.length>0&&(this.outFeature(t[0]),"fill-extrusion"==t[0].layer.type&&void 0!==t[0].id&&(this.selectedFeature&&this.selectedFeature.id==t[0].id||(this.getCanvasContainer().style.cursor="pointer",this.overedFeature=t[0],this.setFeatureState({source:this.overedFeature.source,sourceLayer:this.overedFeature.sourceLayer,id:this.overedFeature.id},{hover:!0}),this.overedFeature=e.queryRenderedFeatures({layers:[this.overedFeature.layer.id],filter:["==",["id"],this.overedFeature.id]})[0],this.addTooltip(this.overedFeature))))}},this.onMouseDown=function(t){(t.originalEvent.shiftKey||t.originalEvent.altKey||t.originalEvent.ctrlKey)&&0===t.originalEvent.button&&this.selectedObject&&(e.tb.enableDraggingObjects||e.tb.enableRotatingObjects)&&(t.preventDefault(),e.getCanvasContainer().style.cursor="move",e.once("mouseup",this.onMouseUp),this.draggedObject=this.selectedObject,i=h(t),l=this.draggedObject.coordinates,s=y.degreeify(this.draggedObject.rotation),o=l[0]-t.lngLat.lng,a=l[1]-t.lngLat.lat,n=-this.draggedObject.modelHeight-t.point.y*this.tb.altitudeStep)},this.onMouseUp=function(e){this.getCanvasContainer().style.cursor=this.tb.defaultCursor,this.off("mouseup",this.onMouseUp),this.off("mouseout",this.onMouseUp),this.dragPan.enable(),this.draggedObject&&(this.draggedObject.dispatchEvent({type:"ObjectDragged",detail:{draggedObject:this.draggedObject,draggedAction:t}}),this.draggedObject.removeHelp(),this.draggedObject=null,t=null)},this.onMouseOut=function(e){if(this.overedFeature){let t=this.queryRenderedFeatures(e.point);t.length>0&&this.overedFeature.id!=t[0].id&&(this.getCanvasContainer().style.cursor=this.tb.defaultCursor,this.outFeature(t[0]))}},this.onZoom=function(e){this.tb.zoomLayers.forEach(e=>{this.tb.toggleLayer(e)}),this.tb.setObjectsScale()};let c=!1;this.on("click",this.onClick),this.on("mousemove",this.onMouseMove),this.on("mouseout",this.onMouseOut),this.on("mousedown",this.onMouseDown),this.on("zoom",this.onZoom),this.on("zoomend",this.onZoom),document.addEventListener("keydown",function(t){17===t.which||t.which,16===t.which&&(c=!0);let i=this.selectedObject;if(c&&83===t.which&&i){let t=y.toDecimal;if(i.help)i.removeHelp();else{let r=i.modelSize,o=1;"meters"!==i.userData.units&&(o=y.projectedUnitsPerMeter(i.coordinates[1]),o||(o=1),o=t(o,7)),e.tb.enableHelpTooltips&&i.addHelp("size(m): "+t(r.x/o,3)+" W, "+t(r.y/o,3)+" L, "+t(r.z/o,3)+" H"),this.repaint=!0}return!1}}.bind(this),!0),document.addEventListener("keyup",function(e){17==e.which||e.which,16===e.which&&(c=!1)}.bind(this))})},get sky(){return this.options.sky},set sky(e){e?this.createSkyLayer():this.removeLayer(this.skyLayerName),this.options.sky=e},get terrain(){return this.options.terrain},set terrain(e){if(this.terrainLayerName="",e)this.createTerrainLayer();else{if(this.mapboxVersion<2)return void console.warn("Terrain layer are only supported by Mapbox-gl-js > v2.0");this.map.getTerrain()&&(this.map.setTerrain(null),this.map.removeSource(this.terrainSourceName))}this.options.terrain=e},get fov(){return this.options.fov},set fov(e){this.camera instanceof u.PerspectiveCamera&&this.options.fov!==e&&(this.map.transform.fov=e,this.camera.fov=this.map.transform.fov,this.cameraSync.setupCamera(),this.map.repaint=!0,this.options.fov=e)},get orthographic(){return this.options.orthographic},set orthographic(e){const t=this.map.getCanvas().clientHeight,i=this.map.getCanvas().clientWidth;e?(this.map.transform.fov=0,this.camera=new u.OrthographicCamera(i/-2,i/2,t/2,t/-2,.1,1e21)):(this.map.transform.fov=this.fov,this.camera=new u.PerspectiveCamera(this.map.transform.fov,i/t,.1,1e21)),this.camera.layers.enable(0),this.camera.layers.enable(1),this.cameraSync=new v(this.map,this.camera,this.world),this.map.repaint=!0,this.options.orthographic=e},createSkyLayer:function(){if(this.mapboxVersion<2)return console.warn("Sky layer are only supported by Mapbox-gl-js > v2.0"),void(this.options.sky=!1);this.map.getLayer(this.skyLayerName)||(this.map.addLayer({id:this.skyLayerName,type:"sky",paint:{"sky-opacity":["interpolate",["linear"],["zoom"],0,0,5,.3,8,1],"sky-type":"atmosphere","sky-atmosphere-sun":this.getSunSky(this.lightDateTime),"sky-atmosphere-sun-intensity":10}}),this.map.once("idle",()=>{this.setSunlight(),this.repaint()}))},createTerrainLayer:function(){if(this.mapboxVersion<2)return console.warn("Terrain layer are only supported by Mapbox-gl-js > v2.0"),void(this.options.terrain=!1);this.map.getTerrain()||(this.map.addSource(this.terrainSourceName,{type:"raster-dem",url:"mapbox://mapbox.mapbox-terrain-dem-v1",tileSize:512,maxzoom:14}),this.map.setTerrain({source:this.terrainSourceName,exaggeration:this.terrainExaggeration}),this.map.once("idle",()=>{this.cameraSync.updateCamera(),this.repaint()}))},sphere:function(e){return this.setDefaultView(e,this.options),function(e){e=y._validate(e,le.prototype._defaults.sphere);let t=new u.SphereGeometry(e.radius,e.sides,e.sides),i=Y(e);return new he({obj:new u.Mesh(t,i),units:e.units,anchor:e.anchor,adjustment:e.adjustment,bbox:e.bbox,tooltip:e.tooltip,raycasted:e.raycasted})}(e,this.world)},line:function(e){e=y._validate(e,le.prototype._defaults.line);var t=y.lnglatsToWorld(e.geometry),i=y.normalizeVertices(t),r=y.flattenVectors(i.vertices),o=new h.LineGeometry;o.setPositions(r);let a=new l.LineMaterial({color:e.color,linewidth:e.width,dashed:!1,opacity:e.opacity});a.resolution.set(window.innerWidth,window.innerHeight),a.isMaterial=!0,a.transparent=!0,a.depthWrite=!1;let n=new s.Line2(o,a);return n.position.copy(i.position),n.computeLineDistances(),n},label:function(e){e=y._validate(e,le.prototype._defaults.label);let t=le.prototype.drawLabelHTML(e.htmlElement,e.cssClass),i=new te(t);i.name="label",i.visible=e.alwaysVisible,i.alwaysVisible=e.alwaysVisible;var r=le.prototype._makeGroup(i,e);return le.prototype._addMethods(r),r.visibility=e.alwaysVisible,r},tooltip:function(e){if((e=y._validate(e,le.prototype._defaults.tooltip)).text){let i=le.prototype.drawTooltip(e.text,e.mapboxStyle),r=new te(i);r.visible=!1,r.name="tooltip";var t=le.prototype._makeGroup(r,e);return le.prototype._addMethods(t),t}},tube:function(e){return this.setDefaultView(e,this.options),function(e){e=y._validate(e,le.prototype._defaults.tube);let t=[];e.geometry.forEach(e=>{t.push(new u.Vector3(e[0],e[1],e[2]))});const i=new u.CatmullRomCurve3(t);let r=new u.TubeGeometry(i,t.length,e.radius,e.sides,!1),o=Y(e);return new he({obj:new u.Mesh(r,o),units:e.units,anchor:e.anchor,adjustment:e.adjustment,bbox:e.bbox,tooltip:e.tooltip,raycasted:e.raycasted})}(e,this.world)},extrusion:function(e){return this.setDefaultView(e,this.options),ce(e)},Object3D:function(e){return this.setDefaultView(e,this.options),he(e)},loadObj:async function(e,t){if(this.setDefaultView(e,this.options),!1===e.clone)return new Promise(async i=>{ge(e,t,async e=>{i(e)})});{let i=this.objectsCache.get(e.obj);i?i.promise.then(i=>{t(i.duplicate(e))}).catch(t=>{this.objectsCache.delete(e.obj),console.error("Could not load model file: "+e.obj)}):this.objectsCache.set(e.obj,{promise:new Promise(async(i,r)=>{ge(e,t,async e=>{e.duplicate?i(e.duplicate()):r(e)})})})}},material:function(e){return Y(e)},initLights:{ambientLight:null,dirLight:null,dirLightBack:null,dirLightHelper:null,hemiLight:null,pointLight:null},utils:y,SunCalc:W,Constants:g,projectToWorld:function(e){return this.utils.projectToWorld(e)},unprojectFromWorld:function(e){return this.utils.unprojectFromWorld(e)},projectedUnitsPerMeter:function(e){return this.utils.projectedUnitsPerMeter(e)},getFeatureCenter:function(e,t,i){return y.getFeatureCenter(e,t,i)},getObjectHeightOnFloor:function(e,t,i){return y.getObjectHeightOnFloor(e,t,i)},queryRenderedFeatures:function(e){let t=new u.Vector2;return t.x=e.x/this.map.transform.width*2-1,t.y=1-e.y/this.map.transform.height*2,this.raycaster.setFromCamera(t,this.camera),this.raycaster.intersectObjects(this.world.children,!0)},findParent3DObject:function(e){var t;return e.object.traverseAncestors(function(e){e.parent&&"Group"==e.parent.type&&e.userData.obj&&(t=e)}),t},setLayoutProperty:function(e,t,i){this.map.setLayoutProperty(e,t,i),null!=i&&"visibility"===t&&this.world.children.filter(t=>t.layer===e).forEach(e=>{e.visibility=i})},setLayerZoomRange:function(e,t,i){this.map.getLayer(e)&&(this.map.setLayerZoomRange(e,t,i),this.zoomLayers.includes(e)||this.zoomLayers.push(e),this.toggleLayer(e))},setLayerHeigthProperty:function(e,t){let i=this.map.getLayer(e);if(i)if("fill-extrusion"==i.type){let e=this.map.getStyle().sources[i.source].data;e.features.forEach(function(e){e.properties.level=t}),this.map.getSource(i.source).setData(e)}else"custom"==i.type&&this.world.children.forEach(function(i){let r=i.userData.feature;if(r&&r.layer===e){let e=this.tb.getFeatureCenter(r,i,t);i.setCoords(e)}})},setObjectsScale:function(){this.world.children.filter(e=>null!=e.fixedZoom).forEach(e=>{e.setObjectScale(this.map.transform.scale)})},setStyle:function(e,t){this.clear().then(()=>{this.map.setStyle(e,t)})},toggleLayer:function(e,t=!0){let i=this.map.getLayer(e);if(i){if(!t)return void this.toggle(i.id,!1);let e=this.map.getZoom();if(i.minzoom&&e<i.minzoom)return void this.toggle(i.id,!1);if(i.maxzoom&&e>=i.maxzoom)return void this.toggle(i.id,!1);this.toggle(i.id,!0)}},toggle:function(e,t){this.setLayoutProperty(e,"visibility",t?"visible":"none"),this.labelRenderer.toggleLabels(e,t)},update:function(){this.map.repaint&&(this.map.repaint=!1);var e=Date.now();this.objects.animationManager.update(e),this.updateLightHelper(),this.renderer.resetState(),this.renderer.render(this.scene,this.camera),this.labelRenderer.render(this.scene,this.camera),!1===this.options.passiveRendering&&this.map.triggerRepaint()},add:function(e,t,i){if(!this.enableTooltips&&e.tooltip&&(e.tooltip.visibility=!1),this.world.add(e),t){e.layer=t,e.source=i;let r=this.map.getLayer(t);if(r){let t=r.visibility,i=void 0===t;e.visibility=!(!i&&"visible"!==t)}}},removeByName:function(e){let t=this.world.getObjectByName(e);t&&this.remove(t)},remove:function(e){this.map.selectedObject&&e.uuid==this.map.selectedObject.uuid&&this.map.unselectObject(),this.map.draggedObject&&e.uuid==this.map.draggedObject.uuid&&(this.map.draggedObject=null),e.dispose&&e.dispose(),this.world.remove(e),e=null},clear:async function(e=null,t=!1){return new Promise((i,r)=>{let o=[];this.world.children.forEach(function(e){o.push(e)});for(let t=0;t<o.length;t++){let i=o[t];i.layer!==e&&e||this.remove(i)}t&&this.objectsCache.forEach(e=>{e.promise.then(e=>{e.dispose(),e=null})}),i("clear")})},removeLayer:function(e){this.clear(e,!0).then(()=>{this.map.removeLayer(e)})},getSunPosition:function(e,t){return W.getPosition(e||Date.now(),t[1],t[0])},getSunTimes:function(e,t){return W.getTimes(e,t[1],t[0],t[2]?t[2]:0)},setBuildingShadows:function(e){if(this.map.getLayer(e.buildingsLayerId)){let t=new ye(e,this);this.map.addLayer(t,e.buildingsLayerId)}else console.warn("The layer '"+e.buildingsLayerId+"' does not exist in the map.")},setSunlight:function(e=new Date,t){if(!this.lights.dirLight||!this.options.realSunlight)return void console.warn("To use setSunlight it's required to set realSunlight : true in Threebox initial options.");var i=new Date(e.getTime());if(t?t.lng&&t.lat?this.mapCenter=t:this.mapCenter={lng:t[0],lat:t[1]}:this.mapCenter=this.map.getCenter(),this.lightDateTime&&this.lightDateTime.getTime()===i.getTime()&&this.lightLng===this.mapCenter.lng&&this.lightLat===this.mapCenter.lat)return;this.lightDateTime=i,this.lightLng=this.mapCenter.lng,this.lightLat=this.mapCenter.lat,this.sunPosition=this.getSunPosition(i,[this.mapCenter.lng,this.mapCenter.lat]);let r=this.sunPosition.altitude,o=Math.PI+this.sunPosition.azimuth,a=g.WORLD_SIZE/2,n=Math.sin(r),s=Math.cos(r),l=Math.cos(o)*s,h=Math.sin(o)*s;this.lights.dirLight.position.set(h,l,n),this.lights.dirLight.position.multiplyScalar(a),this.lights.dirLight.intensity=Math.max(n,0),this.lights.hemiLight.intensity=Math.max(1*n,.1),this.lights.dirLight.updateMatrixWorld(),this.updateLightHelper(),this.map.loaded()&&(this.updateSunGround(this.sunPosition),this.map.setLight({anchor:"map",position:[3,180+180*this.sunPosition.azimuth/Math.PI,90-180*this.sunPosition.altitude/Math.PI],intensity:Math.cos(this.sunPosition.altitude),color:`hsl(40, ${50*Math.cos(this.sunPosition.altitude)}%, ${Math.max(20,20+96*Math.sin(this.sunPosition.altitude))}%)`},{duration:0}),this.sky&&this.updateSunSky(this.getSunSky(i,this.sunPosition)))},getSunSky:function(e,t){if(!t){var i=this.map.getCenter();t=this.getSunPosition(e||Date.now(),[i.lng,i.lat])}return[180+180*t.azimuth/Math.PI,90-180*t.altitude/Math.PI]},updateSunSky:function(e){this.sky&&this.map.setPaintProperty(this.skyLayerName,"sky-atmosphere-sun",e)},updateSunGround:function(e){""!=this.terrainLayerName&&this.map.setPaintProperty(this.terrainLayerName,"raster-opacity",Math.max(Math.min(1,4*e.altitude),.25))},updateLightHelper:function(){this.lights.dirLightHelper&&(this.lights.dirLightHelper.position.setFromMatrixPosition(this.lights.dirLight.matrixWorld),this.lights.dirLightHelper.updateMatrix(),this.lights.dirLightHelper.update())},dispose:async function(){return console.log(this.memory()),new Promise(e=>{e(this.clear(null,!0).then(e=>(this.map.remove(),this.map={},this.scene.remove(this.world),this.world.children=[],this.world=null,this.objectsCache.clear(),this.labelRenderer.dispose(),console.log(this.memory()),this.renderer.dispose(),e)))})},defaultLights:function(){this.lights.ambientLight=new u.AmbientLight(new u.Color("hsl(0, 0%, 100%)"),.75),this.scene.add(this.lights.ambientLight),this.lights.dirLightBack=new u.DirectionalLight(new u.Color("hsl(0, 0%, 100%)"),.25),this.lights.dirLightBack.position.set(30,100,100),this.scene.add(this.lights.dirLightBack),this.lights.dirLight=new u.DirectionalLight(new u.Color("hsl(0, 0%, 100%)"),.25),this.lights.dirLight.position.set(-30,100,-100),this.scene.add(this.lights.dirLight)},realSunlight:function(e=!1){this.renderer.shadowMap.enabled=!0,this.lights.dirLight=new u.DirectionalLight(16777215,1),this.scene.add(this.lights.dirLight),e&&(this.lights.dirLightHelper=new u.DirectionalLightHelper(this.lights.dirLight,5),this.scene.add(this.lights.dirLightHelper));this.lights.dirLight.castShadow=!0,this.lights.dirLight.shadow.radius=2,this.lights.dirLight.shadow.mapSize.width=8192,this.lights.dirLight.shadow.mapSize.height=8192,this.lights.dirLight.shadow.camera.top=this.lights.dirLight.shadow.camera.right=1e3,this.lights.dirLight.shadow.camera.bottom=this.lights.dirLight.shadow.camera.left=-1e3,this.lights.dirLight.shadow.camera.near=1,this.lights.dirLight.shadow.camera.visible=!0,this.lights.dirLight.shadow.camera.far=4e8,this.lights.hemiLight=new u.HemisphereLight(new u.Color(16777215),new u.Color(16777215),.6),this.lights.hemiLight.color.setHSL(.661,.96,.12),this.lights.hemiLight.groundColor.setHSL(.11,.96,.14),this.lights.hemiLight.position.set(0,0,50),this.scene.add(this.lights.hemiLight),this.setSunlight(),this.map.once("idle",()=>{this.setSunlight(),this.repaint()})},setDefaultView:function(e,t){e.bbox=(e.bbox||null==e.bbox)&&t.enableSelectingObjects,e.tooltip=(e.tooltip||null==e.tooltip)&&t.enableTooltips,e.mapScale=this.map.transform.scale},memory:function(){return this.renderer.info.memory},programs:function(){return this.renderer.info.programs.length},version:"2.2.7"};var xe={defaultLights:!1,realSunlight:!1,realSunlightHelper:!1,passiveRendering:!0,preserveDrawingBuffer:!1,enableSelectingFeatures:!1,enableSelectingObjects:!1,enableDraggingObjects:!1,enableRotatingObjects:!1,enableTooltips:!1,enableHelpTooltips:!1,multiLayer:!1,orthographic:!1,fov:g.FOV_DEGREES,sky:!1,terrain:!1};exports.Threebox=ve;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("three"),t=require("three/addons/loaders/OBJLoader.js"),i=require("three/addons/loaders/MTLLoader.js"),r=require("three/addons/loaders/FBXLoader.js"),a=require("three/addons/loaders/GLTFLoader.js"),n=require("three/addons/loaders/ColladaLoader.js"),s=require("three/addons/lines/Line2.js"),l=require("three/addons/lines/LineMaterial.js"),h=require("three/addons/lines/LineGeometry.js");function c(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e)for(const i in e)if("default"!==i){const r=Object.getOwnPropertyDescriptor(e,i);Object.defineProperty(t,i,r.get?r:{enumerable:!0,get:()=>e[i]})}return t.default=e,Object.freeze(t)}const u=c(e),d=1024e3,p=.1/180*Math.PI,m=Math.atan(3/4),f=6371008.8,g={WORLD_SIZE:d,PROJECTION_WORLD_SIZE:d/(f*Math.PI*2),MERCATOR_A:f,DEG2RAD:Math.PI/180,RAD2DEG:180/Math.PI,EARTH_RADIUS:f,EARTH_CIRCUMFERENCE:2*Math.PI*f,EARTH_CIRCUMFERENCE_EQUATOR:40075017,FOV_ORTHO:p,FOV:m,FOV_DEGREES:180*m/Math.PI,TILE_SIZE:512};function b(){}b.prototype={Coords:function(e){if(e.constructor===Array)if(e.length<2)console.error("Coords length must be at least 2");else{for(const t of e)if(t.constructor!==Number)return void console.error("Coords values must be numbers");if(!(Math.abs(e[1])>90))return e;console.error("Latitude must be between -90 and 90")}else console.error("Coords must be an array")},Line:function(e){if(e.constructor===Array){for(const t of e)if(!this.Coords(t))return void console.error("Each coordinate in a line must be a valid Coords type");return e}console.error("Line must be an array")},Rotation:function(e){if(e.constructor===Number)e={z:e};else{if(e.constructor!==Object)return void console.error("Rotation must be an object or a number");for(const t of Object.keys(e)){if(!["x","y","z"].includes(t))return void console.error("Rotation parameters must be x, y, or z");if(e[t].constructor!==Number)return void console.error("Individual rotation values must be numbers")}}return e},Scale:function(e){if(e.constructor===Number)e={x:e,y:e,z:e};else{if(e.constructor!==Object)return void console.error("Scale must be an object or a number");for(const t of Object.keys(e)){if(!["x","y","z"].includes(t))return void console.error("Scale parameters must be x, y, or z");if(e[t].constructor!==Number)return void console.error("Individual scale values must be numbers")}}return e}};var y={prettyPrintMatrix:function(e){for(var t=0;t<4;t++){var i=[e[t],e[t+4],e[t+8],e[t+12]];console.log(i.map(function(e){return e.toFixed(4)}))}},makePerspectiveMatrix:function(e,t,i,r){var o=new u.Matrix4,a=1/Math.tan(e/2),n=1/(i-r),s=[a/t,0,0,0,0,a,0,0,0,0,(r+i)*n,-1,0,0,2*r*i*n,0];return o.elements=s,o},makeOrthographicMatrix:function(e,t,i,r,o,a){var n=new u.Matrix4;const s=1/(t-e),l=1/(i-r),h=1/(a-o);var c=[2*s,0,0,0,0,2*l,0,0,0,0,-1*h,0,-((t+e)*s),-((i+r)*l),-(o*h),1];return n.elements=c,n},radify:function(e){function t(e){return e=e||0,2*Math.PI*e/360}return"object"==typeof e?e.length>0?e.map(function(e){return t(e)}):[t(e.x),t(e.y),t(e.z)]:t(e)},degreeify:function(e){function t(e){return 360*(e=e||0)/(2*Math.PI)}return"object"==typeof e?[t(e.x),t(e.y),t(e.z)]:t(e)},projectToWorld:function(e){var t=[-g.MERCATOR_A*g.DEG2RAD*e[0]*g.PROJECTION_WORLD_SIZE,-g.MERCATOR_A*Math.log(Math.tan(.25*Math.PI+.5*g.DEG2RAD*e[1]))*g.PROJECTION_WORLD_SIZE];if(e[2]){var i=this.projectedUnitsPerMeter(e[1]);t.push(e[2]*i)}else t.push(0);return new u.Vector3(t[0],t[1],t[2])},projectedUnitsPerMeter:function(e){return Math.abs(g.WORLD_SIZE/Math.cos(g.DEG2RAD*e)/g.EARTH_CIRCUMFERENCE)},_circumferenceAtLatitude:function(e){return g.EARTH_CIRCUMFERENCE*Math.cos(e*Math.PI/180)},mercatorZfromAltitude:function(e,t){return e/this._circumferenceAtLatitude(t)},_scaleVerticesToMeters:function(e,t){var i=this.projectedUnitsPerMeter(e[1]);this.projectToWorld(e);for(var r=0;r<t.length;r++)t[r].multiplyScalar(i);return t},projectToScreen:function(e){console.log("WARNING: Projecting to screen coordinates is not yet implemented")},unprojectFromScreen:function(e){console.log("WARNING: unproject is not yet implemented")},unprojectFromWorld:function(e){var t=[-e.x/(g.MERCATOR_A*g.DEG2RAD*g.PROJECTION_WORLD_SIZE),2*(Math.atan(Math.exp(e.y/(g.PROJECTION_WORLD_SIZE*-g.MERCATOR_A)))-Math.PI/4)/g.DEG2RAD],i=this.projectedUnitsPerMeter(t[1]),r=e.z||0;return t.push(r/i),t},toScreenPosition:function(e,t){var i=new u.Vector3,r=.5*renderer.context.canvas.width,o=.5*renderer.context.canvas.height;return e.updateMatrixWorld(),i.setFromMatrixPosition(e.matrixWorld),i.project(t),i.x=i.x*r+r,i.y=-i.y*o+o,{x:i.x,y:i.y}},getFeatureCenter:function(e,t,i){let r=[],o=0,a=0,n=0,s=[...e.geometry.coordinates[0]];return"Point"===e.geometry.type?r=[...s[0]]:("MultiPolygon"===e.geometry.type&&(s=s[0]),s.splice(-1,1),s.forEach(function(e){o+=e[0],a+=e[1]}),r=[o/s.length,a/s.length]),n=this.getObjectHeightOnFloor(e,t,i),r.length<3?r.push(n):r[2]=n,r},getObjectHeightOnFloor:function(e,t,i=e.properties.level||0){let r=i*(e.properties.levelHeight||0),o=e.properties.base_height||e.properties.min_height||0;return r+((t&&t.model?0:e.properties.height-o)+o)},_flipMaterialSides:function(e){},normalizeVertices(e){let t=new u.BufferGeometry,i=[];for(var r=0;r<e.length;r++){let t=e[r];i.push(t.x,t.y,t.z),i.push(t.x,t.y,t.z)}t.setAttribute("position",new u.BufferAttribute(new Float32Array(i),3)),t.computeBoundingSphere();var o=t.boundingSphere.center;return{vertices:e.map(function(e){return e.sub(o)}),position:o}},flattenVectors(e){var t=[];for(let i of e)t.push(i.x,i.y,i.z);return t},lnglatsToWorld:function(e){return e.map(function(e){var t=y.projectToWorld(e);return new u.Vector3(t.x,t.y,t.z)})},extend:function(e,t){for(let i in t)e[i]=t[i]},clone:function(e){var t={};for(let i in e)t[i]=e[i];return t},clamp:function(e,t,i){return Math.min(i,Math.max(t,e))},types:{rotation:function(e,t){e||(e=0),"number"==typeof e&&(e={z:e});var i=this.applyDefault([e.x,e.y,e.z],t);return y.radify(i)},scale:function(e,t){return e||(e=1),"number"==typeof e?[e,e,e]:this.applyDefault([e.x,e.y,e.z],t)},applyDefault:function(e,t){return e.map(function(e,i){return e=e||t[i]})}},toDecimal:function(e,t){return Number(e.toFixed(t))},equal:function(e,t){const i=Object.keys(e),r=Object.keys(t);if(i.length!==r.length)return!1;if(0==i.length&&0==r.length&&i!==r)return!1;for(const o of i){const i=e[o],r=t[o],a=this.isObject(i)&&this.isObject(r);if(a&&!equal(i,r)||!a&&i!==r)return!1}return!0},isObject:function(e){return null!=e&&"object"==typeof e},curveToLine:(e,t)=>{let{width:i,color:r}=t,o=(new u.BufferGeometry).setFromPoints(e.getPoints(100)),a=new u.LineBasicMaterial({color:r,linewidth:i});return new u.Line(o,a)},curvesToLines:e=>{var t=[16711680,2031360,2490623];return e.map((e,i)=>curveToLine(e,{width:3,color:t[i]||"purple"}))},_validate:function(e,t){e=e||{};var i={};y.extend(i,e);for(let r of Object.keys(t))if(void 0===e[r]){if(null===t[r])return void console.error(r+" is required");i[r]=t[r]}else i[r]=e[r];return i},Validator:new b,exposedMethods:["projectToWorld","projectedUnitsPerMeter","extend","unprojectFromWorld"]};function v(e,t,i){this.map=e,this.camera=t,this.active=!0,this.camera.matrixAutoUpdate=!1,this.world=i||new u.Group,this.world.position.x=this.world.position.y=g.WORLD_SIZE/2,this.world.matrixAutoUpdate=!1,this.state={translateCenter:(new u.Matrix4).makeTranslation(g.WORLD_SIZE/2,-g.WORLD_SIZE/2,0),worldSizeRatio:g.TILE_SIZE/g.WORLD_SIZE,worldSize:g.TILE_SIZE*this.map.transform.scale};let r=this;this.map.on("move",function(){r.updateCamera()}).on("resize",function(){r.setupCamera()}),this.setupCamera()}v.prototype={setupCamera:function(){const e=this.map.transform;this.camera.aspect=e.width/e.height,this.halfFov=e._fov/2,this.cameraToCenterDistance=.5/Math.tan(this.halfFov)*e.height;const t=e._maxPitch*Math.PI/180;this.acuteAngle=Math.PI/2-t,this.updateCamera()},updateCamera:function(e){if(!this.camera)return void console.log("nocamera");const t=this.map.transform;this.camera.aspect=t.width/t.height;const i=t.centerOffset||new u.Vector3;let r=0,o=0;this.halfFov=t._fov/2;const a=Math.PI/2+t._pitch,n=Math.cos(Math.PI/2-t._pitch);this.cameraToCenterDistance=.5/Math.tan(this.halfFov)*t.height;let s=1;const l=this.worldSize();if(this.map.tb.mapboxVersion>=2){s=this.mercatorZfromAltitude(1,t.center.lat)*l;const e=t._fov*(.5+t.centerOffset.y/t.height),i=t.elevation?t.elevation.getMinElevationBelowMSL()*s:0,h=(t._camera.position[2]*l-i)/Math.cos(t._pitch);o=n*(Math.sin(e)*h/Math.sin(y.clamp(Math.PI-a-e,.01,Math.PI-.01)))+h;const c=h*(1/t._horizonShift);r=Math.min(1.01*o,c)}else{o=n*(Math.sin(this.halfFov)*this.cameraToCenterDistance/Math.sin(Math.PI-a-this.halfFov))+this.cameraToCenterDistance,r=1.01*o}this.cameraTranslateZ=(new u.Matrix4).makeTranslation(0,0,this.cameraToCenterDistance);const h=t.height/50,c=Math.max(h*n,h),d=t.height,p=t.width;this.camera instanceof u.OrthographicCamera?this.camera.projectionMatrix=y.makeOrthographicMatrix(p/-2,p/2,d/2,d/-2,c,r):this.camera.projectionMatrix=y.makePerspectiveMatrix(t._fov,p/d,c,r),this.camera.projectionMatrix.elements[8]=2*-i.x/t.width,this.camera.projectionMatrix.elements[9]=2*i.y/t.height;let m=this.calcCameraMatrix(t._pitch,t.angle);t.elevation&&(m.elements[14]=t._camera.position[2]*l),this.camera.matrixWorld.copy(m);let f=t.scale*this.state.worldSizeRatio,g=new u.Matrix4,b=new u.Matrix4,x=new u.Matrix4;g.makeScale(f,f,f);let w=t.x||t.point.x,M=t.y||t.point.y;b.makeTranslation(-w,M,0),x.makeRotationZ(Math.PI),this.world.matrix=(new u.Matrix4).premultiply(x).premultiply(this.state.translateCenter).premultiply(g).premultiply(b),this.map.fire("CameraSynced",{detail:{nearZ:c,farZ:r,pitch:t._pitch,angle:t.angle,furthestDistance:o,cameraToCenterDistance:this.cameraToCenterDistance,t:this.map.transform,tbProjMatrix:this.camera.projectionMatrix.elements,tbWorldMatrix:this.world.matrix.elements,cameraSyn:v}})},worldSize(){let e=this.map.transform;return e.tileSize*e.scale},worldSizeFromZoom(){let e=this.map.transform;return Math.pow(2,e.zoom)*e.tileSize},mercatorZfromAltitude(e,t){return e/this.circumferenceAtLatitude(t)},mercatorZfromZoom(){return this.cameraToCenterDistance/this.worldSizeFromZoom()},circumferenceAtLatitude:e=>g.EARTH_CIRCUMFERENCE*Math.cos(e*Math.PI/180),calcCameraMatrix(e,t,i){const r=this.map.transform,o=void 0===e?r._pitch:e,a=void 0===t?r.angle:t,n=void 0===i?this.cameraTranslateZ:i;return(new u.Matrix4).premultiply(n).premultiply((new u.Matrix4).makeRotationX(o)).premultiply((new u.Matrix4).makeRotationZ(a))},updateCameraState(){let e=this.map.transform;if(!e.height)return;const t=e._camera.forward(),i=e.cameraToCenterDistance,r=e.point;e._cameraZoom?e._cameraZoom:e._zoom;const o=this.mercatorZfromZoom(e)-this.mercatorZfromAltitude(e._centerAltitude,e.center.lat),a=e.cameraToCenterDistance/o;return[r.x/this.worldSize()-t[0]*i/a,r.y/this.worldSize()-t[1]*i/a,this.mercatorZfromAltitude(e._centerAltitude,e._center.lat)+-t[2]*i/a]},getWorldToCamera(e,t){let i=this.map.transform;const r=new u.Matrix4,o=new u.Matrix4,a=i._camera._orientation,n=i._camera.position,s=new u.Vector3(n[0],n[1],n[2]),l=new u.Quaternion;l.set(a[0],a[1],a[2],a[3]);const h=l.conjugate();return s.multiplyScalar(-e),o.makeTranslation(s.x,s.y,s.z),r.makeRotationFromQuaternion(h).premultiply(o),r.elements[1]*=-1,r.elements[5]*=-1,r.elements[9]*=-1,r.elements[13]*=-1,r.elements[8]*=t,r.elements[9]*=t,r.elements[10]*=t,r.elements[11]*=t,r},translate(e,t,i){let r,o,a,n,s,l,h,c,u,d,p,m,f=i[0]||i.x,g=i[1]||i.y,b=i[2]||i.z;return t===e?(e[12]=t[0]*f+t[4]*g+t[8]*b+t[12],e[13]=t[1]*f+t[5]*g+t[9]*b+t[13],e[14]=t[2]*f+t[6]*g+t[10]*b+t[14],e[15]=t[3]*f+t[7]*g+t[11]*b+t[15]):(r=t[0],o=t[1],a=t[2],n=t[3],s=t[4],l=t[5],h=t[6],c=t[7],u=t[8],d=t[9],p=t[10],m=t[11],e[0]=r,e[1]=o,e[2]=a,e[3]=n,e[4]=s,e[5]=l,e[6]=h,e[7]=c,e[8]=u,e[9]=d,e[10]=p,e[11]=m,e[12]=r*f+s*g+u*b+t[12],e[13]=o*f+l*g+d*b+t[13],e[14]=a*f+h*g+p*b+t[14],e[15]=n*f+c*g+m*b+t[15]),e}};var x=Math.PI,w=Math.sin,M=Math.cos,j=Math.tan,S=Math.asin,O=Math.atan2,L=Math.acos,C=x/180,_=864e5,P=2440588,D=2451545;function z(e){return e.valueOf()/_-.5+P}function T(e){return new Date((e+.5-P)*_)}function F(e){return z(e)-D}var E=23.4397*C;function A(e,t){return O(w(e)*M(E)-j(t)*w(E),M(e))}function R(e,t){return S(w(t)*M(E)+M(t)*w(E)*w(e))}function k(e,t,i){return O(w(e),M(e)*w(t)-j(i)*M(t))}function H(e,t,i){return S(w(t)*w(i)+M(t)*M(i)*M(e))}function B(e,t){return C*(280.16+360.9856235*e)-t}function I(e){return C*(357.5291+.98560028*e)}function N(e){return e+C*(1.9148*w(e)+.02*w(2*e)+3e-4*w(3*e))+102.9372*C+x}function V(e){var t=N(I(e));return{dec:R(t,0),ra:A(t,0)}}var W={getPosition:function(e,t,i){var r=C*-i,o=C*t,a=F(e),n=V(a),s=B(a,r)-n.ra;return{azimuth:k(s,o,n.dec),altitude:H(s,o,n.dec)}},toJulian:function(e){return z(e)}},G=W.times=[[-.833,"sunrise","sunset"],[-.3,"sunriseEnd","sunsetStart"],[-6,"dawn","dusk"],[-12,"nauticalDawn","nauticalDusk"],[-18,"nightEnd","night"],[6,"goldenHourEnd","goldenHour"]];W.addTime=function(e,t,i){G.push([e,t,i])};var Z=9e-4;function q(e,t,i){return Z+(e+t)/(2*x)+i}function U(e,t,i){return D+e+.0053*w(t)-.0069*w(2*i)}function Q(e,t,i,r,o,a,n){var s=function(e,t,i){return L((w(e)-w(t)*w(i))/(M(t)*M(i)))}(e,i,r);return U(q(s,t,o),a,n)}function J(e){var t=C*(134.963+13.064993*e),i=C*(93.272+13.22935*e),r=C*(218.316+13.176396*e)+6.289*C*w(t),o=5.128*C*w(i),a=385001-20905*M(t);return{ra:A(r,o),dec:R(r,o),dist:a}}function X(e,t){return new Date(e.valueOf()+t*_/24)}W.getTimes=function(e,t,i,r){var o,a,n,s,l,h=C*-i,c=C*t,u=function(e){return-2.076*Math.sqrt(e)/60}(r=r||0),d=function(e,t){return Math.round(e-Z-t/(2*x))}(F(e),h),p=q(0,h,d),m=I(p),f=N(m),g=R(f,0),b=U(p,m,f),y={solarNoon:T(b),nadir:T(b-.5)};for(o=0,a=G.length;o<a;o+=1)l=b-((s=Q(((n=G[o])[0]+u)*C,h,c,g,d,m,f))-b),y[n[1]]=T(l),y[n[2]]=T(s);return y},W.getMoonPosition=function(e,t,i){var r=C*-i,o=C*t,a=F(e),n=J(a),s=B(a,r)-n.ra,l=H(s,o,n.dec),h=O(w(s),j(o)*M(n.dec)-w(n.dec)*M(s));return l+=function(e){return e<0&&(e=0),2967e-7/Math.tan(e+.00312536/(e+.08901179))}(l),{azimuth:k(s,o,n.dec),altitude:l,distance:n.dist,parallacticAngle:h}},W.getMoonIllumination=function(e){var t=F(e||new Date),i=V(t),r=J(t),o=149598e3,a=L(w(i.dec)*w(r.dec)+M(i.dec)*M(r.dec)*M(i.ra-r.ra)),n=O(o*w(a),r.dist-o*M(a)),s=O(M(i.dec)*w(i.ra-r.ra),w(i.dec)*M(r.dec)-M(i.dec)*w(r.dec)*M(i.ra-r.ra));return{fraction:(1+M(n))/2,phase:.5+.5*n*(s<0?-1:1)/Math.PI,angle:s}},W.getMoonTimes=function(e,t,i,r){var o=new Date(e);r?o.setUTCHours(0,0,0,0):o.setHours(0,0,0,0);for(var a,n,s,l,h,c,u,d,p,m,f,g,b,y=.133*C,v=W.getMoonPosition(o,t,i).altitude-y,x=1;x<=24&&(a=W.getMoonPosition(X(o,x),t,i).altitude-y,d=((h=(v+(n=W.getMoonPosition(X(o,x+1),t,i).altitude-y))/2-a)*(u=-(c=(n-v)/2)/(2*h))+c)*u+a,m=0,(p=c*c-4*h*a)>=0&&(f=u-(b=Math.sqrt(p)/(2*Math.abs(h))),g=u+b,Math.abs(f)<=1&&m++,Math.abs(g)<=1&&m++,f<-1&&(f=g)),1===m?v<0?s=x+f:l=x+f:2===m&&(s=x+(d<0?g:f),l=x+(d<0?f:g)),!s||!l);x+=2)v=n;var w={};return s&&(w.rise=X(o,s)),l&&(w.set=X(o,l)),s||l||(w[d>0?"alwaysUp":"alwaysDown"]=!0),w};var K={material:"MeshBasicMaterial",color:"black",opacity:1};function Y(e){var t;function i(){return new u[K.material]({color:K.color})}return e?((t=(e=y._validate(e,K)).material&&e.material.isMaterial?e.material:e.material||e.color||e.opacity?new u[e.material]({color:e.color,transparent:e.opacity<1}):i()).opacity=e.opacity,e.side&&(t.side=e.side)):t=i(),t}function $(e){this.map=e,this.enrolledObjects=[],this.previousFrameTime}$.prototype={unenroll:function(e){this.enrolledObjects.splice(this.enrolledObjects.indexOf(e),1)},enroll:function(e){if(e.clock=new u.Clock,e.hasDefaultAnimation=!1,e.defaultAction,e.actions=[],e.mixer,e.animations&&e.animations.length>0){e.hasDefaultAnimation=!0;let i=e.userData.defaultAnimation?e.userData.defaultAnimation:0;e.mixer=new u.AnimationMixer(e),t(i)}function t(t){for(let i=0;i<e.animations.length;i++){t>e.animations.length&&console.log("The animation index "+t+" doesn't exist for this object");let r=e.animations[i],o=e.mixer.clipAction(r);e.actions.push(o),t===i?(e.defaultAction=o,o.setEffectiveWeight(1)):o.setEffectiveWeight(0),o.play()}}let i=!1;Object.defineProperty(e,"isPlaying",{get:()=>i,set(t){i!=t&&(i=t,e.dispatchEvent({type:"IsPlayingChanged",detail:e}))}}),this.enrolledObjects.push(e),e.animationQueue=[],e.set=function(t){if(t.duration>0){let i={start:Date.now(),expiration:Date.now()+t.duration,endState:{}};y.extend(t,i);let r=t.coords,o=t.rotation,a=t.scale||t.scaleX||t.scaleY||t.scaleZ;if(o){let i=e.rotation;t.startRotation=[i.x,i.y,i.z],t.endState.rotation=y.types.rotation(t.rotation,t.startRotation),t.rotationPerMs=t.endState.rotation.map(function(e,i){return(e-t.startRotation[i])/t.duration})}if(a){let i=e.scale;t.startScale=[i.x,i.y,i.z],t.endState.scale=y.types.scale(t.scale,t.startScale),t.scalePerMs=t.endState.scale.map(function(e,i){return(e-t.startScale[i])/t.duration})}r&&(t.pathCurve=new u.CatmullRomCurve3(y.lnglatsToWorld([e.coordinates,t.coords])));let n={type:"set",parameters:t};this.animationQueue.push(n),tb.map.repaint=!0}else this.stop(),t.rotation=y.radify(t.rotation),this._setObject(t);return this},e.animationMethod=null,e.stop=function(t){return e.mixer&&(e.isPlaying=!1,cancelAnimationFrame(e.animationMethod)),this.animationQueue=[],this},e.followPath=function(e,t){let i={type:"followPath",parameters:y._validate(e,ee.followPath)};return y.extend(i.parameters,{pathCurve:new u.CatmullRomCurve3(y.lnglatsToWorld(e.path)),start:Date.now(),expiration:Date.now()+i.parameters.duration,cb:t}),this.animationQueue.push(i),tb.map.repaint=!0,this},e._setObject=function(t){e.setScale();let i=t.position,r=t.rotation,o=t.scale,a=t.worldCoordinates,n=t.quaternion,s=t.translate,l=t.worldTranslate;if(i){this.coordinates=i;let e=y.projectToWorld(i);this.position.copy(e)}if(s){this.coordinates=[this.coordinates[0]+s[0],this.coordinates[1]+s[1],this.coordinates[2]+s[2]];let e=y.projectToWorld(s);this.position.copy(e),t.position=this.coordinates}if(l){this.translateX(l.x),this.translateY(l.y),this.translateZ(l.z);let e=y.unprojectFromWorld(this.position);this.coordinates=t.position=e}if(r&&(this.rotation.set(r[0],r[1],r[2]),t.rotation=new u.Vector3(r[0],r[1],r[2])),o&&(this.scale.set(o[0],o[1],o[2]),t.scale=this.scale),n&&(this.quaternion.setFromAxisAngle(n[0],n[1]),t.rotation=n[0].multiplyScalar(n[1])),a){this.position.copy(a);let e=y.unprojectFromWorld(a);this.coordinates=t.position=e}this.setBoundingBoxShadowFloor(),this.setReceiveShadowFloor(),this.updateMatrixWorld(),tb.map.repaint=!0;let h={type:"ObjectChanged",detail:{object:this,action:{position:t.position,rotation:t.rotation,scale:t.scale}}};this.dispatchEvent(h)},e.playDefault=function(t){if(e.mixer&&e.hasDefaultAnimation){let i={start:Date.now(),expiration:Date.now()+t.duration,endState:{}};y.extend(t,i),e.mixer.timeScale=t.speed||1;let r={type:"playDefault",parameters:t};return this.animationQueue.push(r),tb.map.repaint=!0,this}},e.playAnimation=function(i){e.mixer&&(i.animation&&t(i.animation),e.playDefault(i))},e.pauseAllActions=function(){e.mixer&&e.actions.forEach(function(e){e.paused=!0})},e.unPauseAllActions=function(){e.mixer&&e.actions.forEach(function(e){e.paused=!1})},e.deactivateAllActions=function(){e.mixer&&e.actions.forEach(function(e){e.stop()})},e.activateAllActions=function(){e.mixer&&e.actions.forEach(function(e){e.play()})},e.idle=function(){return e.mixer&&e.mixer.update(.01),tb.map.repaint=!0,this}},update:function(e){if(void 0===this.previousFrameTime&&(this.previousFrameTime=e),!this.enrolledObjects)return!1;for(let t=this.enrolledObjects.length-1;t>=0;t--){let i=this.enrolledObjects[t];if(i.animationQueue&&0!==i.animationQueue.length)for(let t=i.animationQueue.length-1;t>=0;t--){let r=i.animationQueue[t];if(!r)continue;let o=r.parameters;if(!o.expiration)return i.animationQueue.splice(t,1),void(i.animationQueue[t]&&(i.animationQueue[t].parameters.start=e));if(e>=o.expiration)o.expiration=!1,"playDefault"===r.type?i.stop():(o.endState&&i._setObject(o.endState),void 0!==o.cb&&o.cb());else{let t=(e-o.start)/o.duration;if("set"===r.type){let e={};o.pathCurve&&(e.worldCoordinates=o.pathCurve.getPoint(t)),o.rotationPerMs&&(e.rotation=o.startRotation.map(function(e,i){return e+o.rotationPerMs[i]*t*o.duration})),o.scalePerMs&&(e.scale=o.startScale.map(function(e,i){return e+o.scalePerMs[i]*t*o.duration})),i._setObject(e)}if("followPath"===r.type){let e={worldCoordinates:o.pathCurve.getPointAt(t)};if(o.trackHeading){let i=o.pathCurve.getTangentAt(t).normalize(),r=new u.Vector3(0,0,0),a=new u.Vector3(0,1,0);r.crossVectors(a,i).normalize();let n=Math.acos(a.dot(i));e.quaternion=[r,n]}i._setObject(e)}"playDefault"===r.type&&(i.activateAllActions(),i.isPlaying=!0,i.animationMethod=requestAnimationFrame(this.update),i.mixer.update(i.clock.getDelta()),tb.map.repaint=!0)}}}this.previousFrameTime=e}};const ee={followPath:{path:null,duration:1e3,trackHeading:!0}};class te extends u.Object3D{constructor(e){super(),this.element=e||document.createElement("div"),this.element.style.position="absolute",this.element.style.userSelect="none",this.element.setAttribute("draggable",!1),this.alwaysVisible=!1,Object.defineProperty(this,"layer",{get(){return this.parent&&this.parent.parent?this.parent.parent.layer:null}}),this.dispose=function(){this.remove(),this.element=null},this.remove=function(){this.element instanceof Element&&null!==this.element.parentNode&&this.element.parentNode.removeChild(this.element)},this.addEventListener("removed",function(){this.remove()})}copy(e,t){return super.copy(e,t),this.element=e.element.cloneNode(!0),this}}te.prototype.isCSS2DObject=!0;const ie=new u.Vector3,re=new u.Matrix4,oe=new u.Matrix4,ae=new u.Vector3,ne=new u.Vector3;class se{constructor(){const e=this;let t,i,r,o;const a={objects:new WeakMap,list:new Map};this.cacheList=a.list;const n=document.createElement("div");function s(t,i,h){if(t.isCSS2DObject)if(t.visible){t.onBeforeRender(e,i,h),ie.setFromMatrixPosition(t.matrixWorld),ie.applyMatrix4(oe);const s=t.element;var c;c=/apple/i.test(navigator.vendor)?"translate(-50%,-50%) translate("+Math.round(ie.x*r+r)+"px,"+Math.round(-ie.y*o+o)+"px)":"translate(-50%,-50%) translate("+(ie.x*r+r)+"px,"+(-ie.y*o+o)+"px)",s.style.WebkitTransform=c,s.style.MozTransform=c,s.style.oTransform=c,s.style.transform=c,s.style.display=t.visible&&ie.z>=-1&&ie.z<=1?"":"none";const u={distanceToCameraSquared:l(h,t)};a.objects.set({key:t.uuid},u),a.list.set(t.uuid,t),s.parentNode!==n&&n.appendChild(s),t.onAfterRender(e,i,h)}else a.objects.delete({key:t.uuid}),a.list.delete(t.uuid),t.remove();for(let e=0,r=t.children.length;e<r;e++)s(t.children[e],i,h)}function l(e,t){return ae.setFromMatrixPosition(e.matrixWorld),ne.setFromMatrixPosition(t.matrixWorld),ae.distanceToSquared(ne)}n.style.overflow="hidden",this.domElement=n,this.getSize=function(){return{width:t,height:i}},this.render=function(e,t){!0===e.autoUpdate&&e.updateMatrixWorld(),null===t.parent&&t.updateMatrixWorld(),re.copy(t.matrixWorldInverse),oe.multiplyMatrices(t.projectionMatrix,re),s(e,e,t),function(e){const t=function(e){const t=[];return e.traverse(function(e){e.isCSS2DObject&&t.push(e)}),t}(e).sort(function(e,t){let i=a.objects.get({key:e.uuid}),r=a.objects.get({key:t.uuid});if(i&&r){return i.distanceToCameraSquared-r.distanceToCameraSquared}}),i=t.length;for(let r=0,o=t.length;r<o;r++)t[r].element.style.zIndex=i-r}(e)},this.setSize=function(e,a){t=e,i=a,r=t/2,o=i/2,n.style.width=e+"px",n.style.height=a+"px"}}}function le(){}function he(e){let t=(e=y._validate(e,le.prototype._defaults.Object3D)).obj;const i=y.types.rotation(e.rotation,[0,0,0]),r=y.types.scale(e.scale,[1,1,1]);t.rotation.set(i[0],i[1],i[2]),t.scale.set(r[0],r[1],r[2]),t.name="model";let o=le.prototype._makeGroup(t,e);return e.obj.name="model",le.prototype._addMethods(o),o.setAnchor(e.anchor),o.setCenter(e.adjustment),o.raycasted=e.raycasted,o.visibility=!0,o}function ce(e){e=y._validate(e,le.prototype._defaults.extrusion);let t=ce.prototype.buildShape(e.coordinates),i=ce.prototype.buildGeometry(t,e.geometryOptions),r=new u.Mesh(i,e.materials);return e.obj=r,new he(e)}le.prototype={line:function(e){e=y._validate(e,this._defaults.line);var t=y.lnglatsToWorld(e.geometry),i=y.normalizeVertices(t),r=y.flattenVectors(i.vertices),o=new Float32Array(r),a=new u.BufferGeometry;a.setAttribute("position",new u.BufferAttribute(o,3));var n=new u.LineBasicMaterial({color:16711680,linewidth:21}),s=new u.Line(a,n);return s.options=options||{},s.position.copy(i.position),s},extrusion:function(e){},unenroll:function(e,t){t||this.animationManager.unenroll(e)},_addMethods:function(e,t){var i=this;const r="label",o="tooltip",a="help",n="shadowPlane";if(t);else{let t=function(e,t,i,r){let o=y.radify(r);e.position.sub(t),e.position.applyAxisAngle(i,o),e.position.add(t),e.rotateOnAxis(i,o),tb.map.repaint=!0},s=function(e){return Math.pow(2,e)};e.coordinates||(e.coordinates=[0,0,0]),Object.defineProperty(e,"model",{get:()=>e.getObjectByName("model")}),Object.defineProperty(e,"animations",{get(){const t=e.model;return t?t.animations:null}}),i.animationManager.enroll(e),e.setCoords=function(t){return e.userData.topMargin&&e.userData.feature&&(t[2]+=((e.userData.feature.properties.height||0)-(e.userData.feature.properties.base_height||e.userData.feature.properties.min_height||0))*(e.userData.topMargin||0)),e.coordinates=t,e.set({position:t}),e},e.setTranslate=function(t){return e.set({translate:t}),e},e.setRotation=function(t){"number"==typeof t&&(t={z:t});var i={x:y.radify(t.x)||e.rotation.x,y:y.radify(t.y)||e.rotation.y,z:y.radify(t.z)||e.rotation.z};e._setObject({rotation:[i.x,i.y,i.z]})},e.calculateAdjustedPosition=function(t,i,r){let o=t.slice(),a=y.unprojectFromWorld(e.modelSize);return r?(o[0]-=0!=i.x?a[0]/i.x:0,o[1]-=0!=i.y?a[1]/i.y:0,o[2]-=0!=i.z?a[2]/i.z:0):(o[0]+=0!=i.x?a[0]/i.x:0,o[1]+=0!=i.y?a[1]/i.y:0,o[2]+=0!=i.z?a[2]/i.z:0),o},e.setRotationAxis=function(i){"number"==typeof i&&(i={z:i});let r=e.modelBox(),o=new u.Vector3(r.max.x,r.max.y,r.min.z);0!=i.x&&t(e,o,new u.Vector3(0,0,1),i.x),0!=i.y&&t(e,o,new u.Vector3(0,0,1),i.y),0!=i.z&&t(e,o,new u.Vector3(0,0,1),i.z)},Object.defineProperty(e,"scaleGroup",{get:()=>e.getObjectByName("scaleGroup")}),Object.defineProperty(e,"boxGroup",{get:()=>e.getObjectByName("boxGroup")}),Object.defineProperty(e,"boundingBox",{get:()=>e.getObjectByName("boxModel")}),Object.defineProperty(e,"boundingBoxShadow",{get:()=>e.getObjectByName("boxShadow")}),e.drawBoundingBox=function(){let t=e.box3(),i=new u.Group;i.name="boxGroup",i.updateMatrixWorld(!0);let r=new u.Box3Helper(t,le.prototype._defaults.colors.yellow);r.name="boxModel",i.add(r),r.layers.disable(0);let o=t.clone();o.max.z=o.min.z;let a=new u.Box3Helper(o,le.prototype._defaults.colors.black);a.name="boxShadow",i.add(a),a.layers.disable(0),i.visible=!1,e.scaleGroup.add(i),e.setBoundingBoxShadowFloor()},e.setBoundingBoxShadowFloor=function(){if(e.boundingBoxShadow){let t=-e.modelHeight,i=e.rotation,r=e.boundingBoxShadow;r.box.max.z=r.box.min.z=t,r.rotation.y=i.y,r.rotation.x=-i.x}},e.setAnchor=function(t){const i=e.box3(),r=i.getCenter(new u.Vector3);switch(e.none={x:0,y:0,z:0},e.center={x:r.x,y:r.y,z:i.min.z},e.bottom={x:r.x,y:i.max.y,z:i.min.z},e.bottomLeft={x:i.max.x,y:i.max.y,z:i.min.z},e.bottomRight={x:i.min.x,y:i.max.y,z:i.min.z},e.top={x:r.x,y:i.min.y,z:i.min.z},e.topLeft={x:i.max.x,y:i.min.y,z:i.min.z},e.topRight={x:i.min.x,y:i.min.y,z:i.min.z},e.left={x:i.max.x,y:r.y,z:i.min.z},e.right={x:i.min.x,y:r.y,z:i.min.z},t){case"center":e.anchor=e.center;break;case"top":e.anchor=e.top;break;case"top-left":e.anchor=e.topLeft;break;case"top-right":e.anchor=e.topRight;break;case"left":e.anchor=e.left;break;case"right":e.anchor=e.right;break;case"bottom":e.anchor=e.bottom;break;case"bottom-left":default:e.anchor=e.bottomLeft;break;case"bottom-right":e.anchor=e.bottomRight;break;case"auto":case"none":e.anchor=e.none}e.model.position.set(-e.anchor.x,-e.anchor.y,-e.anchor.z)},e.setCenter=function(t){if(t&&(0!=t.x||0!=t.y||0!=t.z)){let i=e.getSize();e.anchor={x:e.anchor.x-i.x*t.x,y:e.anchor.y-i.y*t.y,z:e.anchor.z-i.z*t.z},e.model.position.set(-e.anchor.x,-e.anchor.y,-e.anchor.z)}},Object.defineProperty(e,"label",{get:()=>e.getObjectByName(r)}),Object.defineProperty(e,"tooltip",{get:()=>e.getObjectByName(o)}),Object.defineProperty(e,"help",{get:()=>e.getObjectByName(a)});let l=!1;Object.defineProperty(e,"hidden",{get:()=>l,set(t){l!=t&&(l=t,e.visibility=!l)}}),Object.defineProperty(e,"visibility",{get:()=>e.visible,set(t){let i=t;if("visible"==t||1==t)i=!0,e.label&&(e.label.visible=i);else{if("none"!=t&&0!=t)return;i=!1,e.label&&e.label.alwaysVisible&&(e.label.visible=i),e.tooltip&&(e.tooltip.visible=i)}if(e.visible!=i){if(e.hidden&&i)return;e.visible=i,e.model&&e.model.traverse(function(t){"Mesh"!=t.type&&"SkinnedMesh"!=t.type||(i&&e.raycasted?t.layers.enable(0):t.layers.disable(0)),"LineSegments"==t.type&&t.layers.disableAll()})}}}),e.addLabel=function(t,i,r,o){t&&e.drawLabelHTML(t,i,r,o)},e.removeLabel=function(){e.removeCSS2D(r)},e.drawLabelHTML=function(t,o=!1,a=e.anchor,n=.5){let s=i.drawLabelHTML(t,le.prototype._defaults.label.cssClass),l=e.addCSS2D(s,r,a,n);return l.alwaysVisible=o,l.visible=o,l},e.addTooltip=function(t,i,r,a=!0,n=1){let s=e.addHelp(t,o,i,r,n);s.visible=!1,s.custom=a},e.removeTooltip=function(){e.removeCSS2D(o)},e.addHelp=function(t,r=a,o=!1,n=e.anchor,s=0){let l=i.drawTooltip(t,o),h=e.addCSS2D(l,r,n,s);return h.visible=!0,h},e.removeHelp=function(){e.removeCSS2D(a)},e.addCSS2D=function(t,i,r=e.anchor,o=1){if(t){const a=e.box3(),n=a.getSize(new u.Vector3);let s={x:a.max.x,y:a.max.y,z:a.min.z};e.removeCSS2D(i);let l=new te(t);return l.name=i,l.position.set(.5*-n.x-e.model.position.x-r.x+s.x,.5*-n.y-e.model.position.y-r.y+s.y,n.z*o),l.visible=!1,e.scaleGroup.add(l),l}},e.removeCSS2D=function(t){let i=e.getObjectByName(t);if(i){i.dispose();let t=e.scaleGroup.children;t.splice(t.indexOf(i),1)}},Object.defineProperty(e,"shadowPlane",{get:()=>e.getObjectByName(n)});let h=!1;Object.defineProperty(e,"castShadow",{get:()=>h,set(t){if(e.model&&h!==t){if(e.model.traverse(function(e){e.isMesh&&(e.castShadow=!0)}),t){const i=e.modelSize,r=[i.x,i.y,i.z,e.modelHeight],o=10*Math.max(...r),a=new u.PlaneGeometry(o,o),s=new u.ShadowMaterial;s.opacity=.5;let l=new u.Mesh(a,s);l.name=n,l.layers.enable(1),l.layers.disable(0),l.receiveShadow=t,e.add(l)}else e.traverse(function(t){t.isMesh&&t.material instanceof u.ShadowMaterial&&e.remove(t)});h=t}}}),e.setReceiveShadowFloor=function(){if(e.castShadow){let t=e.shadowPlane,i=t.position,r=t.rotation;if(i.z=-e.modelHeight,r.y=e.rotation.y,r.x=-e.rotation.x,"meters"===e.userData.units){const r=e.modelSize,o=[r.x,r.y,r.z,-i.z],a=10*Math.max(...o)/t.geometry.parameters.width;t.scale.set(a,a,a)}}};let c=!1;Object.defineProperty(e,"receiveShadow",{get:()=>c,set(t){e.model&&c!==t&&(e.model.traverse(function(e){e.isMesh&&(e.receiveShadow=!0)}),c=t)}});let d=!1;Object.defineProperty(e,"wireframe",{get:()=>d,set(t){e.model&&d!==t&&(e.model.traverse(function(e){if("Mesh"==e.type||"SkinnedMesh"==e.type){let i=[];Array.isArray(e.material)?i=e.material:i.push(e.material);let r=i[0];t?(e.userData.materials=r,e.material=r.clone(),e.material.wireframe=e.material.transparent=t,e.material.opacity=.3):(e.material.dispose(),e.material=e.userData.materials,e.userData.materials.dispose(),e.userData.materials=null),t?(e.layers.disable(0),e.layers.enable(1)):(e.layers.disable(1),e.layers.enable(0))}"LineSegments"==e.type&&e.layers.disableAll()}),d=t,e.dispatchEvent({type:"Wireframed",detail:e}))}});let p=null;Object.defineProperty(e,"color",{get:()=>p,set(t){e.model&&p!==t&&(e.model.traverse(function(e){if("Mesh"==e.type||"SkinnedMesh"==e.type){let i=[];Array.isArray(e.material)?i=e.material:i.push(e.material);let r=i[0];t?(e.userData.materials=r,e.material=new u.MeshStandardMaterial,e.material.color.setHex(t)):(e.material.dispose(),e.material=e.userData.materials,e.userData.materials.dispose(),e.userData.materials=null)}}),p=t)}});let m=!1;Object.defineProperty(e,"selected",{get:()=>m,set(t){t?(e.userData.bbox&&!e.boundingBox&&e.drawBoundingBox(),e.boxGroup&&(e.boundingBox.material=le.prototype._defaults.materials.boxSelectedMaterial,e.boundingBox.parent.visible=!0,e.boundingBox.layers.enable(1),e.boundingBoxShadow.layers.enable(1)),e.label&&!e.label.alwaysVisible&&(e.label.visible=!0)):(e.boxGroup&&e.remove(e.boxGroup),e.label&&!e.label.alwaysVisible&&(e.label.visible=!1),e.removeHelp()),e.tooltip&&(e.tooltip.visible=t),m!=t&&(m=t,e.dispatchEvent({type:"SelectedChange",detail:e}))}});let f=!0;Object.defineProperty(e,"raycasted",{get:()=>f,set(t){e.model&&f!==t&&(e.model.traverse(function(e){"Mesh"!=e.type&&"SkinnedMesh"!=e.type||(t?(e.layers.disable(1),e.layers.enable(0)):(e.layers.disable(0),e.layers.enable(1)))}),f=t)}});let g=!1;Object.defineProperty(e,"over",{get:()=>g,set(t){t?(e.selected||(e.userData.bbox&&!e.boundingBox&&e.drawBoundingBox(),e.userData.tooltip&&!e.tooltip&&e.addTooltip(e.uuid,!0,e.anchor,!1),e.boxGroup&&(e.boundingBox.material=le.prototype._defaults.materials.boxOverMaterial,e.boundingBox.parent.visible=!0,e.boundingBox.layers.enable(1),e.boundingBoxShadow.layers.enable(1))),e.label&&!e.label.alwaysVisible&&(e.label.visible=!0),e.dispatchEvent({type:"ObjectMouseOver",detail:e})):(e.selected||(e.boxGroup&&(e.remove(e.boxGroup),e.tooltip&&!e.tooltip.custom&&e.removeTooltip()),e.label&&!e.label.alwaysVisible&&(e.label.visible=!1)),e.dispatchEvent({type:"ObjectMouseOut",detail:e})),e.tooltip&&(e.tooltip.visible=t||e.selected),g=t}}),e.box3=function(){let t;if(e.updateMatrix(),e.updateMatrixWorld(!0,!0),e.model){let i=e.clone(!0),r=e.model.clone();if(t=(new u.Box3).setFromObject(r),e.parent){let o=new u.Matrix4,a=new u.Matrix4;e.matrix.extractRotation(o),a.copy(o).invert(),i.setRotationFromMatrix(a),t=(new u.Box3).setFromObject(r)}}return t},e.modelBox=function(){return e.box3()},e.getSize=function(){return e.box3().getSize(new u.Vector3(0,0,0))};let b=!1;Object.defineProperty(e,"modelSize",{get:()=>(b=e.getSize(),b),set(e){b!=e&&(b=e)}}),Object.defineProperty(e,"modelHeight",{get(){let t=e.coordinates[2]||0;return"scene"===e.userData.units&&(t*=e.unitsPerMeter/e.scale.x),t}}),Object.defineProperty(e,"unitsPerMeter",{get:()=>Number(y.projectedUnitsPerMeter(e.coordinates[1]).toFixed(7))}),Object.defineProperty(e,"fixedZoom",{get:()=>e.userData.fixedZoom,set(t){e.userData.fixedZoom!==t&&(e.userData.fixedZoom=t,e.userData.units=t?"scene":"meters")}}),e.setFixedZoom=function(t){if(null!=e.fixedZoom&&0!=e.fixedZoom){t||(t=e.userData.mapScale);let i=s(e.fixedZoom);if(i>t){let r=i/t;e.scale.set(r,r,r)}else e.scale.set(1,1,1)}},e.setScale=function(t){if("scene"!=e.userData.units){let t=e.unitsPerMeter;e.scale.set(t,t,t)}else e.fixedZoom?(t&&(e.userData.mapScale=t),e.setFixedZoom(e.userData.mapScale)):e.scale.set(1,1,1)},e.setObjectScale=function(t){e.setScale(t),e.setBoundingBoxShadowFloor(),e.setReceiveShadowFloor()}}e.add=function(t){return e.scaleGroup.add(t),t.position.z=e.coordinates[2]?-e.coordinates[2]:0,t},e.remove=function(t){t&&(t.traverse(e=>{if(e.geometry&&e.geometry.dispose(),e.material)if(e.material.isMaterial)s(e.material);else for(const t of e.material)s(t);e.dispose&&e.dispose()}),e.scaleGroup.remove(t),tb.map.repaint=!0)},e.duplicate=function(t){let r=e.clone(!0);if(r.getObjectByName("model").animations=e.animations,r.userData.feature&&(t&&t.feature&&(r.userData.feature=t.feature),r.userData.feature.properties.uuid=r.uuid),i._addMethods(r),!t||y.equal(t.scale,e.userData.scale))return r.copyAnchor(e),r;{r.userData=t,r.userData.isGeoGroup=!0,r.remove(r.boxGroup);const e=y.types.rotation(t.rotation,[0,0,0]),i=y.types.scale(t.scale,[1,1,1]);return r.model.position.set(0,0,0),r.model.rotation.set(e[0],e[1],e[2]),r.model.scale.set(i[0],i[1],i[2]),r.setAnchor(t.anchor),r.setCenter(t.adjustment),r}},e.copyAnchor=function(t){e.anchor=t.anchor,e.none={x:0,y:0,z:0},e.center=t.center,e.bottom=t.bottom,e.bottomLeft=t.bottomLeft,e.bottomRight=t.bottomRight,e.top=t.top,e.topLeft=t.topLeft,e.topRight=t.topRight,e.left=t.left,e.right=t.right},e.dispose=function(){le.prototype.unenroll(e),e.traverse(e=>{if((!e.parent||"world"!=e.parent.name)&&"threeboxObject"!==e.name){if(e.geometry&&e.geometry.dispose(),e.material)if(e.material.isMaterial)s(e.material);else for(const t of e.material)s(t);e.dispose&&e.dispose()}}),e.children=[]};const s=e=>{e.dispose();for(const i of Object.keys(e)){const t=e[i];t&&"object"==typeof t&&"minFilter"in t&&t.dispose()}let t=e;(t.map||t.alphaMap||t.aoMap||t.bumpMap||t.displacementMap||t.emissiveMap||t.envMap||t.lightMap||t.metalnessMap||t.normalMap||t.roughnessMap)&&(t.map&&t.map.dispose(),t.alphaMap&&t.alphaMap.dispose(),t.aoMap&&t.aoMap.dispose(),t.bumpMap&&t.bumpMap.dispose(),t.displacementMap&&t.displacementMap.dispose(),t.emissiveMap&&t.emissiveMap.dispose(),t.envMap&&t.envMap.dispose(),t.lightMap&&t.lightMap.dispose(),t.metalnessMap&&t.metalnessMap.dispose(),t.normalMap&&t.normalMap.dispose(),t.roughnessMap&&t.roughnessMap.dispose())};return e},_makeGroup:function(e,t){let i=new u.Group;i.name="scaleGroup",i.add(e);var r=new u.Group;if(r.userData=t||{},r.userData.isGeoGroup=!0,r.userData.feature&&(r.userData.feature.properties.uuid=r.uuid),i.length)for(o of i)r.add(o);else r.add(i);return r.name="threeboxObject",r},animationManager:new $,drawTooltip:function(e,t=!1){if(e){let i;if(t){let t=document.createElement("div");t.className="mapboxgl-popup-content";let r=document.createElement("strong");r.innerHTML=e,t.appendChild(r);let o=document.createElement("div");o.className="mapboxgl-popup-tip";let a=document.createElement("div");a.className="marker mapboxgl-popup-anchor-bottom",a.appendChild(o),a.appendChild(t),i=document.createElement("div"),i.className+="label3D",i.appendChild(a)}else i=document.createElement("span"),i.className=this._defaults.tooltip.cssClass,i.innerHTML=e;return i}},drawLabelHTML:function(e,t){let i=document.createElement("div");return i.className+=t,i.innerHTML="string"==typeof e?e:e.outerHTML,i},_defaults:{colors:{red:new u.Color(16711680),yellow:new u.Color(16776960),green:new u.Color(65280),black:new u.Color(0)},materials:{boxNormalMaterial:new u.LineBasicMaterial({color:new u.Color(16711680)}),boxOverMaterial:new u.LineBasicMaterial({color:new u.Color(16776960)}),boxSelectedMaterial:new u.LineBasicMaterial({color:new u.Color(65280)})},line:{geometry:null,color:"black",width:1,opacity:1},label:{htmlElement:null,cssClass:" label3D",alwaysVisible:!1,topMargin:-.5},tooltip:{text:"",cssClass:"toolTip text-xs",mapboxStyle:!1,topMargin:0},sphere:{position:[0,0,0],radius:1,sides:20,units:"scene",material:"MeshBasicMaterial",anchor:"bottom-left",bbox:!0,tooltip:!0,raycasted:!0},tube:{geometry:null,radius:1,sides:6,units:"scene",material:"MeshBasicMaterial",anchor:"center",bbox:!0,tooltip:!0,raycasted:!0},loadObj:{type:null,obj:null,units:"scene",scale:1,rotation:0,defaultAnimation:0,anchor:"bottom-left",bbox:!0,tooltip:!0,raycasted:!0,clone:!0,withCredentials:!1},Object3D:{obj:null,units:"scene",anchor:"bottom-left",bbox:!0,tooltip:!0,raycasted:!0},extrusion:{coordinates:[[[]]],geometryOptions:{},height:100,materials:new u.MeshPhongMaterial({color:6684672,side:u.DoubleSide}),scale:1,rotation:0,units:"scene",anchor:"center",bbox:!0,tooltip:!0,raycasted:!0}},geometries:{line:["LineString"],tube:["LineString"],sphere:["Point"]}},ce.prototype={buildShape:function(e){if(e[0]instanceof(u.Vector2||u.Vector3))return new u.Shape(e);let t=new u.Shape;for(let i=0;i<e.length;i++)0===i?t=new u.Shape(this.buildPoints(e[0],e[0])):t.holes.push(new u.Path(this.buildPoints(e[i],e[0])));return t},buildPoints:function(e,t){const i=[];let r=y.projectToWorld([t[0][0],t[0][1],0]);for(let o=0;o<e.length;o++){let t=y.projectToWorld([e[o][0],e[o][1],0]);i.push(new u.Vector2(y.toDecimal(t.x-r.x,9),y.toDecimal(t.y-r.y,9)))}return i},buildGeometry:function(e,t){let i=new u.ExtrudeGeometry(e,t);return i.computeBoundingBox(),i}};const ue=new t.OBJLoader,de=new i.MTLLoader,pe=new a.GLTFLoader,me=new r.FBXLoader,fe=new n.ColladaLoader;function ge(e,t,i){if(void 0===e)return console.error("Invalid options provided to loadObj()");let r;switch((e=y._validate(e,le.prototype._defaults.loadObj)).type||(e.type="mtl"),e.type){case"mtl":r=ue;break;case"gltf":case"glb":r=pe;break;case"fbx":r=me;break;case"dae":r=fe}function o(o){o&&"mtl"==e.type&&(o.preload(),r.setMaterials(o)),r.withCredentials=e.withCredentials,r.load(e.obj,r=>{let o=[];switch(e.type){case"mtl":r=r.children[0];break;case"gltf":case"glb":case"dae":o=r.animations,r=r.scene;break;case"fbx":o=r.animations}r.animations=o;const a=y.types.rotation(e.rotation,[0,0,0]),n=y.types.scale(e.scale,[1,1,1]);r.rotation.set(a[0],a[1],a[2]),r.scale.set(n[0],n[1],n[2]),e.normalize&&r.traverse(function(e){if(e.isMesh){let t;"MeshStandardMaterial"==e.material.type?(e.material.metalness&&(e.material.metalness*=.1),e.material.glossiness&&(e.material.glossiness*=.25),t=new u.Color(12,12,12)):"MeshPhongMaterial"==e.material.type&&(e.material.shininess=.1,t=new u.Color(20,20,20)),e.material.specular&&e.material.specular.isColor&&(e.material.specular=t)}}),r.name="model";let s=le.prototype._makeGroup(r,e);le.prototype._addMethods(s),s.setAnchor(e.anchor),s.setCenter(e.adjustment),s.raycasted=e.raycasted,i(s),t(s),s.setFixedZoom(e.mapScale),s.idle()},()=>null,t=>{console.error("Could not load model file: "+e.obj+" \n "+t.stack),i("Error loading the model")})}e.mtl?(de.withCredentials=e.withCredentials,de.load(e.mtl,o,()=>null,e=>{console.warn("No material file found "+e.stack),o(null)})):o(null)}function be(e){this.map=e,this.renderer=new se,this.renderer.setSize(this.map.getCanvas().clientWidth,this.map.getCanvas().clientHeight),this.renderer.domElement.style.position="absolute",this.renderer.domElement.id="labelCanvas",this.renderer.domElement.style.top=0,this.renderer.domElement.style.zIndex="0",this.map.getCanvasContainer().appendChild(this.renderer.domElement),this.scene,this.camera,this.dispose=function(){this.map.getCanvasContainer().removeChild(this.renderer.domElement),this.renderer.domElement.remove(),this.renderer={}},this.setSize=function(e,t){this.renderer.setSize(e,t)},this.map.on("resize",function(){this.renderer.setSize(this.map.getCanvas().clientWidth,this.map.getCanvas().clientHeight)}.bind(this)),this.state={reset:function(){}},this.render=async function(e,t){return this.scene=e,this.camera=t,new Promise(i=>{i(this.renderer.render(e,t))})},this.toggleLabels=async function(e,t){return new Promise(i=>{i(this.setVisibility(e,t,this.scene,this.camera,this.renderer))})},this.setVisibility=function(e,t,i,r,o){this.renderer.cacheList.forEach(function(a){a.visible!=t&&a.layer===e&&(t&&a.alwaysVisible||!t)&&(a.visible=t,o.renderObject(a,i,r))})}}class ye{constructor(e,t){this.id=e.layerId,this.type="custom",this.renderingMode="3d",this.opacity=.5,this.buildingsLayerId=e.buildingsLayerId,this.minAltitude=e.minAltitude||.1,this.tb=t}onAdd(e,t){this.map=e;const i=this.map.getLayer(this.buildingsLayerId).source;this.source=(this.map.style.sourceCaches||this.map.style._otherSourceCaches)[i],this.source||console.warn(`Can't find layer ${this.buildingsLayerId}'s source.`);const r=this._getVertexSource(),o=t.createShader(t.VERTEX_SHADER);t.shaderSource(o,r),t.compileShader(o);const a=t.createShader(t.FRAGMENT_SHADER);t.shaderSource(a,"\n\t\t\tvoid main() {\n\t\t\t\tgl_FragColor = vec4(0.0, 0.0, 0.0, 0.7);\n\t\t\t}\n\t\t\t"),t.compileShader(a),this.program=t.createProgram(),t.attachShader(this.program,o),t.attachShader(this.program,a),t.linkProgram(this.program),t.validateProgram(this.program),this.uMatrix=t.getUniformLocation(this.program,"u_matrix"),this.uHeightFactor=t.getUniformLocation(this.program,"u_height_factor"),this.uAltitude=t.getUniformLocation(this.program,"u_altitude"),this.uAzimuth=t.getUniformLocation(this.program,"u_azimuth"),this.tb.mapboxVersion>=2?this.aPosNormal=t.getAttribLocation(this.program,"a_pos_normal_ed"):(this.aPos=t.getAttribLocation(this.program,"a_pos"),this.aNormal=t.getAttribLocation(this.program,"a_normal_ed")),this.aBase=t.getAttribLocation(this.program,"a_base"),this.aHeight=t.getAttribLocation(this.program,"a_height")}render(e,t){if(!this.source)return;e.useProgram(this.program);const i=this.source.getVisibleCoordinates().reverse(),r=this.map.getLayer(this.buildingsLayerId),o=this.map.painter.context,{lng:a,lat:n}=this.map.getCenter(),s=this.tb.getSunPosition(this.tb.lightDateTime,[a,n]);e.uniform1f(this.uAltitude,s.altitude>this.minAltitude?s.altitude:0),e.uniform1f(this.uAzimuth,s.azimuth+3*Math.PI/2),e.enable(e.BLEND),e.blendFunc(e.SRC_ALPHA,e.ONE_MINUS_SRC_ALPHA),e.getExtension("EXT_blend_minmax"),e.disable(e.DEPTH_TEST);for(const l of i){const t=this.source.getTile(l),i=t.getBucket(r);if(!i)continue;const[a,n]=i.programConfigurations.programConfigurations[this.buildingsLayerId]._buffers;e.uniformMatrix4fv(this.uMatrix,!1,l.posMatrix||l.projMatrix),e.uniform1f(this.uHeightFactor,Math.pow(2,l.overscaledZ)/t.tileSize/8);for(const r of i.segments.get()){const t=o.currentNumAttributes||0,s=2;for(let i=s;i<t;i++)e.disableVertexAttribArray(i);const l=r.vertexOffset||0;e.enableVertexAttribArray(this.aNormal),e.enableVertexAttribArray(this.aHeight),e.enableVertexAttribArray(this.aBase),i.layoutVertexBuffer.bind(),this.tb.mapboxVersion>=2?(e.enableVertexAttribArray(this.aPosNormal),e.vertexAttribPointer(this.aPosNormal,4,e.SHORT,!1,8,8*l)):(e.enableVertexAttribArray(this.aPos),e.vertexAttribPointer(this.aPos,2,e.SHORT,!1,12,12*l),e.vertexAttribPointer(this.aNormal,4,e.SHORT,!1,12,4+12*l)),a.bind(),e.vertexAttribPointer(this.aHeight,1,e.FLOAT,!1,4,4*l),n.bind(),e.vertexAttribPointer(this.aBase,1,e.FLOAT,!1,4,4*l),i.indexBuffer.bind(),o.currentNumAttributes=s,e.drawElements(e.TRIANGLES,3*r.primitiveLength,e.UNSIGNED_SHORT,3*r.primitiveOffset*2)}}}_getVertexSource(){return this.tb.mapboxVersion>=2?"\n\t\t\t\tuniform mat4 u_matrix;\n\t\t\t\tuniform float u_height_factor;\n\t\t\t\tuniform float u_altitude;\n\t\t\t\tuniform float u_azimuth;\n\t\t\t\tattribute vec4 a_pos_normal_ed;\n\t\t\t\tattribute lowp vec2 a_base;\n\t\t\t\tattribute lowp vec2 a_height;\n\t\t\t\tvoid main() {\n\t\t\t\t\tfloat base = max(0.0, a_base.x);\n\t\t\t\t\tfloat height = max(0.0, a_height.x);\n\n\t\t\t\t\tvec3 pos_nx = floor(a_pos_normal_ed.xyz * 0.5);\n\t\t\t\t\tmediump vec3 top_up_ny = a_pos_normal_ed.xyz - 2.0 * pos_nx;\n\t\t\t\t\tfloat t = top_up_ny.x;\n\t\t\t\t\tvec4 pos = vec4(pos_nx.xy, t > 0.0 ? height : base, 1);\n\n\t\t\t\t\tfloat len = pos.z * u_height_factor / tan(u_altitude);\n\t\t\t\t\tpos.x += cos(u_azimuth) * len;\n\t\t\t\t\tpos.y += sin(u_azimuth) * len;\n\t\t\t\t\tpos.z = 0.0;\n\t\t\t\t\tgl_Position = u_matrix * pos;\n\t\t\t\t}\n\t\t\t":"\n\t\t\t\tuniform mat4 u_matrix;\n\t\t\t\tuniform float u_height_factor;\n\t\t\t\tuniform float u_altitude;\n\t\t\t\tuniform float u_azimuth;\n\t\t\t\tattribute vec2 a_pos;\n\t\t\t\tattribute vec4 a_normal_ed;\n\t\t\t\tattribute lowp vec2 a_base;\n\t\t\t\tattribute lowp vec2 a_height;\n\t\t\t\tvoid main() {\n\t\t\t\t\tfloat base = max(0.0, a_base.x);\n\t\t\t\t\tfloat height = max(0.0, a_height.x);\n\t\t\t\t\tfloat t = mod(a_normal_ed.x, 2.0);\n\t\t\t\t\tvec4 pos = vec4(a_pos, t > 0.0 ? height : base, 1);\n\t\t\t\t\tfloat len = pos.z * u_height_factor / tan(u_altitude);\n\t\t\t\t\tpos.x += cos(u_azimuth) * len;\n\t\t\t\t\tpos.y += sin(u_azimuth) * len;\n\t\t\t\t\tpos.z = 0.0;\n\t\t\t\t\tgl_Position = u_matrix * pos;\n\t\t\t\t}\n\t\t\t"}}function ve(e,t,i){this.init(e,t,i)}ve.prototype={repaint:function(){this.map.repaint=!0},init:function(e,t,i){this.options=y._validate(i||{},xe),this.map=e,this.map.tb=this,this.objects=new le,this.mapboxVersion=parseFloat(this.map.version),this.renderer=new u.WebGLRenderer({alpha:!0,antialias:!0,preserveDrawingBuffer:i.preserveDrawingBuffer,canvas:e.getCanvas(),context:t}),this.renderer.setPixelRatio(window.devicePixelRatio),this.renderer.setSize(this.map.getCanvas().clientWidth,this.map.getCanvas().clientHeight),this.renderer.outputColorSpace=u.SRGBColorSpace,this.renderer.autoClear=!1,this.labelRenderer=new be(this.map),this.scene=new u.Scene,this.world=new u.Group,this.world.name="world",this.scene.add(this.world),this.objectsCache=new Map,this.zoomLayers=[],this.fov=this.options.fov,this.orthographic=this.options.orthographic||!1,this.raycaster=new u.Raycaster,this.raycaster.layers.set(0),this.mapCenter=this.map.getCenter(),this.mapCenterUnits=y.projectToWorld([this.mapCenter.lng,this.mapCenter.lat]),this.lightDateTime=new Date,this.lightLng=this.mapCenter.lng,this.lightLat=this.mapCenter.lat,this.sunPosition,this.rotationStep=5,this.gridStep=6,this.altitudeStep=.1,this.defaultCursor="default",this.lights=this.initLights,this.options.defaultLights&&this.defaultLights(),this.options.realSunlight&&this.realSunlight(this.options.realSunlightHelper),this.skyLayerName="sky-layer",this.terrainSourceName="mapbox-dem",this.terrainExaggeration=1,this.terrainLayerName="",this.enableSelectingFeatures=this.options.enableSelectingFeatures||!1,this.enableSelectingObjects=this.options.enableSelectingObjects||!1,this.enableDraggingObjects=this.options.enableDraggingObjects||!1,this.enableRotatingObjects=this.options.enableRotatingObjects||!1,this.enableTooltips=this.options.enableTooltips||!1,this.multiLayer=this.options.multiLayer||!1,this.enableHelpTooltips=this.options.enableHelpTooltips||!1,this.map.on("style.load",function(){this.tb.zoomLayers=[],this.tb.options.multiLayer&&this.addLayer({id:"threebox_layer",type:"custom",renderingMode:"3d",map:this,onAdd:function(e,t){},render:function(e,t){this.map.tb.update()}}),this.once("idle",()=>{this.tb.setObjectsScale()}),this.tb.options.sky&&(this.tb.sky=!0),this.tb.options.terrain&&(this.tb.terrain=!0);["satellite","mapbox-mapbox-satellite","satelliteLayer"].forEach(e=>{this.getLayer(e)&&(this.tb.terrainLayerName=e)})}),this.map.on("load",function(){let t;this.selectedObject,this.selectedFeature,this.draggedObject,this.overedObject,this.overedFeature;let i,r=this.getCanvasContainer();this.getCanvasContainer().style.cursor=this.tb.defaultCursor;let o,a,n,s,l=[];function h(e){var t=r.getBoundingClientRect();return{x:e.originalEvent.clientX-t.left-r.clientLeft,y:e.originalEvent.clientY-t.top-r.clientTop}}this.unselectObject=function(){this.selectedObject.selected=!1,this.selectedObject=null},this.outObject=function(){this.overedObject.over=!1,this.overedObject=null},this.unselectFeature=function(e){void 0!==e.id&&(this.setFeatureState({source:e.source,sourceLayer:e.sourceLayer,id:e.id},{select:!1}),this.removeTooltip(e),(e=this.queryRenderedFeatures({layers:[e.layer.id],filter:["==",["id"],e.id]})[0])&&this.fire("SelectedFeatureChange",{detail:e}),this.selectedFeature=null)},this.selectFeature=function(e){this.selectedFeature=e,this.setFeatureState({source:this.selectedFeature.source,sourceLayer:this.selectedFeature.sourceLayer,id:this.selectedFeature.id},{select:!0}),this.selectedFeature=this.queryRenderedFeatures({layers:[this.selectedFeature.layer.id],filter:["==",["id"],this.selectedFeature.id]})[0],this.addTooltip(this.selectedFeature),this.fire("SelectedFeatureChange",{detail:this.selectedFeature})},this.outFeature=function(t){this.overedFeature&&void 0!==this.overedFeature&&this.overedFeature.id!=t&&(e.setFeatureState({source:this.overedFeature.source,sourceLayer:this.overedFeature.sourceLayer,id:this.overedFeature.id},{hover:!1}),this.removeTooltip(this.overedFeature),this.overedFeature=null)},this.addTooltip=function(e){if(!this.tb.enableTooltips)return;let t=this.tb.getFeatureCenter(e),i=this.tb.tooltip({text:e.properties.name||e.id||e.type,mapboxStyle:!0,feature:e});i.setCoords(t),this.tb.add(i,e.layer.id),e.tooltip=i,e.tooltip.tooltip.visible=!0},this.removeTooltip=function(e){e.tooltip&&(e.tooltip.visibility=!1,this.tb.remove(e.tooltip),e.tooltip=null)},e.onContextMenu=function(e){alert("contextMenu")},this.onClick=function(t){let i,r=[];if(e.tb.enableSelectingObjects&&(r=this.tb.queryRenderedFeatures(t.point)),i="object"==typeof r[0],i){let e=ve.prototype.findParent3DObject(r[0]);if(e){if(this.selectedFeature&&this.unselectFeature(this.selectedFeature),this.selectedObject){if(this.selectedObject.uuid!=e.uuid)this.selectedObject.selected=!1,e.selected=!0,this.selectedObject=e;else if(this.selectedObject.uuid==e.uuid)return void this.unselectObject()}else this.selectedObject=e,this.selectedObject.selected=!0;this.selectedObject.dispatchEvent({type:"Wireframed",detail:this.selectedObject}),this.selectedObject.dispatchEvent({type:"IsPlayingChanged",detail:this.selectedObject}),this.repaint=!0,t.preventDefault()}}else{let i=[];if(e.tb.enableSelectingFeatures&&(i=this.queryRenderedFeatures(t.point)),i.length>0&&"fill-extrusion"==i[0].layer.type&&void 0!==i[0].id)if(this.selectedObject&&this.unselectObject(),this.selectedFeature){if(this.selectedFeature.id!=i[0].id)this.unselectFeature(this.selectedFeature),this.selectFeature(i[0]);else if(this.selectedFeature.id==i[0].id)return void this.unselectFeature(this.selectedFeature)}else this.selectFeature(i[0])}},this.onMouseMove=function(r){let l,c=h(r);if(this.getCanvasContainer().style.cursor=this.tb.defaultCursor,r.originalEvent.altKey&&this.draggedObject){if(!e.tb.enableRotatingObjects)return;t="rotate",this.getCanvasContainer().style.cursor="move",Math.min(i.x,c.x),Math.max(i.x,c.x),Math.min(i.y,c.y),Math.max(i.y,c.y);let r={x:0,y:0,z:Math.round(s[2]+~~((c.x-i.x)/this.tb.rotationStep)%360*this.tb.rotationStep%360)};return this.draggedObject.setRotation(r),void(e.tb.enableHelpTooltips&&this.draggedObject.addHelp("rot: "+r.z+"&#176;"))}if(r.originalEvent.shiftKey&&this.draggedObject){if(!e.tb.enableDraggingObjects)return;t="translate",this.getCanvasContainer().style.cursor="move";let i=r.lngLat,n=[Number((i.lng+o).toFixed(this.tb.gridStep)),Number((i.lat+a).toFixed(this.tb.gridStep)),this.draggedObject.modelHeight];return this.draggedObject.setCoords(n),void(e.tb.enableHelpTooltips&&this.draggedObject.addHelp("lng: "+n[0]+"&#176;, lat: "+n[1]+"&#176;"))}if(r.originalEvent.ctrlKey&&this.draggedObject){if(!e.tb.enableDraggingObjects)return;t="altitude",this.getCanvasContainer().style.cursor="move";let i=r.point.y*this.tb.altitudeStep,o=[this.draggedObject.coordinates[0],this.draggedObject.coordinates[1],Number((-i-n).toFixed(this.tb.gridStep))];return this.draggedObject.setCoords(o),void(e.tb.enableHelpTooltips&&this.draggedObject.addHelp("alt: "+o[2]+"m"))}let u=[];if(e.tb.enableSelectingObjects&&(u=this.tb.queryRenderedFeatures(r.point)),l="object"==typeof u[0],l){let e=ve.prototype.findParent3DObject(u[0]);e&&(this.outFeature(this.overedFeature),this.getCanvasContainer().style.cursor="pointer",this.selectedObject&&e.uuid==this.selectedObject.uuid?this.selectedObject&&e.uuid==this.selectedObject.uuid&&(e.over=!0,this.overedObject=e):(this.overedObject&&this.overedObject.uuid!=e.uuid&&this.outObject(),e.over=!0,this.overedObject=e),this.repaint=!0,r.preventDefault())}else{this.overedObject&&this.outObject();let t=[];e.tb.enableSelectingFeatures&&(t=this.queryRenderedFeatures(r.point)),t.length>0&&(this.outFeature(t[0]),"fill-extrusion"==t[0].layer.type&&void 0!==t[0].id&&(this.selectedFeature&&this.selectedFeature.id==t[0].id||(this.getCanvasContainer().style.cursor="pointer",this.overedFeature=t[0],this.setFeatureState({source:this.overedFeature.source,sourceLayer:this.overedFeature.sourceLayer,id:this.overedFeature.id},{hover:!0}),this.overedFeature=e.queryRenderedFeatures({layers:[this.overedFeature.layer.id],filter:["==",["id"],this.overedFeature.id]})[0],this.addTooltip(this.overedFeature))))}},this.onMouseDown=function(t){(t.originalEvent.shiftKey||t.originalEvent.altKey||t.originalEvent.ctrlKey)&&0===t.originalEvent.button&&this.selectedObject&&(e.tb.enableDraggingObjects||e.tb.enableRotatingObjects)&&(t.preventDefault(),e.getCanvasContainer().style.cursor="move",e.once("mouseup",this.onMouseUp),this.draggedObject=this.selectedObject,i=h(t),l=this.draggedObject.coordinates,s=y.degreeify(this.draggedObject.rotation),o=l[0]-t.lngLat.lng,a=l[1]-t.lngLat.lat,n=-this.draggedObject.modelHeight-t.point.y*this.tb.altitudeStep)},this.onMouseUp=function(e){this.getCanvasContainer().style.cursor=this.tb.defaultCursor,this.off("mouseup",this.onMouseUp),this.off("mouseout",this.onMouseUp),this.dragPan.enable(),this.draggedObject&&(this.draggedObject.dispatchEvent({type:"ObjectDragged",detail:{draggedObject:this.draggedObject,draggedAction:t}}),this.draggedObject.removeHelp(),this.draggedObject=null,t=null)},this.onMouseOut=function(e){if(this.overedFeature){let t=this.queryRenderedFeatures(e.point);t.length>0&&this.overedFeature.id!=t[0].id&&(this.getCanvasContainer().style.cursor=this.tb.defaultCursor,this.outFeature(t[0]))}},this.onZoom=function(e){this.tb.zoomLayers.forEach(e=>{this.tb.toggleLayer(e)}),this.tb.setObjectsScale()};let c=!1;this.on("click",this.onClick),this.on("mousemove",this.onMouseMove),this.on("mouseout",this.onMouseOut),this.on("mousedown",this.onMouseDown),this.on("zoom",this.onZoom),this.on("zoomend",this.onZoom),document.addEventListener("keydown",function(t){17===t.which||t.which,16===t.which&&(c=!0);let i=this.selectedObject;if(c&&83===t.which&&i){let t=y.toDecimal;if(i.help)i.removeHelp();else{let r=i.modelSize,o=1;"meters"!==i.userData.units&&(o=y.projectedUnitsPerMeter(i.coordinates[1]),o||(o=1),o=t(o,7)),e.tb.enableHelpTooltips&&i.addHelp("size(m): "+t(r.x/o,3)+" W, "+t(r.y/o,3)+" L, "+t(r.z/o,3)+" H"),this.repaint=!0}return!1}}.bind(this),!0),document.addEventListener("keyup",function(e){17==e.which||e.which,16===e.which&&(c=!1)}.bind(this))})},get sky(){return this.options.sky},set sky(e){e?this.createSkyLayer():this.removeLayer(this.skyLayerName),this.options.sky=e},get terrain(){return this.options.terrain},set terrain(e){if(this.terrainLayerName="",e)this.createTerrainLayer();else{if(this.mapboxVersion<2)return void console.warn("Terrain layer are only supported by Mapbox-gl-js > v2.0");this.map.getTerrain()&&(this.map.setTerrain(null),this.map.removeSource(this.terrainSourceName))}this.options.terrain=e},get fov(){return this.options.fov},set fov(e){this.camera instanceof u.PerspectiveCamera&&this.options.fov!==e&&(this.map.transform.fov=e,this.camera.fov=this.map.transform.fov,this.cameraSync.setupCamera(),this.map.repaint=!0,this.options.fov=e)},get orthographic(){return this.options.orthographic},set orthographic(e){const t=this.map.getCanvas().clientHeight,i=this.map.getCanvas().clientWidth;e?(this.map.transform.fov=0,this.camera=new u.OrthographicCamera(i/-2,i/2,t/2,t/-2,.1,1e21)):(this.map.transform.fov=this.fov,this.camera=new u.PerspectiveCamera(this.map.transform.fov,i/t,.1,1e21)),this.camera.layers.enable(0),this.camera.layers.enable(1),this.cameraSync=new v(this.map,this.camera,this.world),this.map.repaint=!0,this.options.orthographic=e},createSkyLayer:function(){if(this.mapboxVersion<2)return console.warn("Sky layer are only supported by Mapbox-gl-js > v2.0"),void(this.options.sky=!1);this.map.getLayer(this.skyLayerName)||(this.map.addLayer({id:this.skyLayerName,type:"sky",paint:{"sky-opacity":["interpolate",["linear"],["zoom"],0,0,5,.3,8,1],"sky-type":"atmosphere","sky-atmosphere-sun":this.getSunSky(this.lightDateTime),"sky-atmosphere-sun-intensity":10}}),this.map.once("idle",()=>{this.setSunlight(),this.repaint()}))},createTerrainLayer:function(){if(this.mapboxVersion<2)return console.warn("Terrain layer are only supported by Mapbox-gl-js > v2.0"),void(this.options.terrain=!1);this.map.getTerrain()||(this.map.addSource(this.terrainSourceName,{type:"raster-dem",url:"mapbox://mapbox.mapbox-terrain-dem-v1",tileSize:512,maxzoom:14}),this.map.setTerrain({source:this.terrainSourceName,exaggeration:this.terrainExaggeration}),this.map.once("idle",()=>{this.cameraSync.updateCamera(),this.repaint()}))},sphere:function(e){return this.setDefaultView(e,this.options),function(e){e=y._validate(e,le.prototype._defaults.sphere);let t=new u.SphereGeometry(e.radius,e.sides,e.sides),i=Y(e);return new he({obj:new u.Mesh(t,i),units:e.units,anchor:e.anchor,adjustment:e.adjustment,bbox:e.bbox,tooltip:e.tooltip,raycasted:e.raycasted})}(e,this.world)},line:function(e){e=y._validate(e,le.prototype._defaults.line);var t=y.lnglatsToWorld(e.geometry),i=y.normalizeVertices(t),r=y.flattenVectors(i.vertices),o=new h.LineGeometry;o.setPositions(r);let a=new l.LineMaterial({color:e.color,linewidth:e.width,dashed:!1,opacity:e.opacity});a.resolution.set(window.innerWidth,window.innerHeight),a.isMaterial=!0,a.transparent=!0,a.depthWrite=!1;let n=new s.Line2(o,a);return n.position.copy(i.position),n.computeLineDistances(),n},label:function(e){e=y._validate(e,le.prototype._defaults.label);let t=le.prototype.drawLabelHTML(e.htmlElement,e.cssClass),i=new te(t);i.name="label",i.visible=e.alwaysVisible,i.alwaysVisible=e.alwaysVisible;var r=le.prototype._makeGroup(i,e);return le.prototype._addMethods(r),r.visibility=e.alwaysVisible,r},tooltip:function(e){if((e=y._validate(e,le.prototype._defaults.tooltip)).text){let i=le.prototype.drawTooltip(e.text,e.mapboxStyle),r=new te(i);r.visible=!1,r.name="tooltip";var t=le.prototype._makeGroup(r,e);return le.prototype._addMethods(t),t}},tube:function(e){return this.setDefaultView(e,this.options),function(e){e=y._validate(e,le.prototype._defaults.tube);let t=[];e.geometry.forEach(e=>{t.push(new u.Vector3(e[0],e[1],e[2]))});const i=new u.CatmullRomCurve3(t);let r=new u.TubeGeometry(i,t.length,e.radius,e.sides,!1),o=Y(e);return new he({obj:new u.Mesh(r,o),units:e.units,anchor:e.anchor,adjustment:e.adjustment,bbox:e.bbox,tooltip:e.tooltip,raycasted:e.raycasted})}(e,this.world)},extrusion:function(e){return this.setDefaultView(e,this.options),ce(e)},Object3D:function(e){return this.setDefaultView(e,this.options),he(e)},loadObj:async function(e,t){if(this.setDefaultView(e,this.options),!1===e.clone)return new Promise(async i=>{ge(e,t,async e=>{i(e)})});{let i=this.objectsCache.get(e.obj);i?i.promise.then(i=>{t(i.duplicate(e))}).catch(t=>{this.objectsCache.delete(e.obj),console.error("Could not load model file: "+e.obj)}):this.objectsCache.set(e.obj,{promise:new Promise(async(i,r)=>{ge(e,t,async e=>{e.duplicate?i(e.duplicate()):r(e)})})})}},material:function(e){return Y(e)},initLights:{ambientLight:null,dirLight:null,dirLightBack:null,dirLightHelper:null,hemiLight:null,pointLight:null},utils:y,SunCalc:W,Constants:g,projectToWorld:function(e){return this.utils.projectToWorld(e)},unprojectFromWorld:function(e){return this.utils.unprojectFromWorld(e)},projectedUnitsPerMeter:function(e){return this.utils.projectedUnitsPerMeter(e)},getFeatureCenter:function(e,t,i){return y.getFeatureCenter(e,t,i)},getObjectHeightOnFloor:function(e,t,i){return y.getObjectHeightOnFloor(e,t,i)},queryRenderedFeatures:function(e){let t=new u.Vector2;return t.x=e.x/this.map.transform.width*2-1,t.y=1-e.y/this.map.transform.height*2,this.raycaster.setFromCamera(t,this.camera),this.raycaster.intersectObjects(this.world.children,!0)},findParent3DObject:function(e){var t;return e.object.traverseAncestors(function(e){e.parent&&"Group"==e.parent.type&&e.userData.obj&&(t=e)}),t},setLayoutProperty:function(e,t,i){this.map.setLayoutProperty(e,t,i),null!=i&&"visibility"===t&&this.world.children.filter(t=>t.layer===e).forEach(e=>{e.visibility=i})},setLayerZoomRange:function(e,t,i){this.map.getLayer(e)&&(this.map.setLayerZoomRange(e,t,i),this.zoomLayers.includes(e)||this.zoomLayers.push(e),this.toggleLayer(e))},setLayerHeigthProperty:function(e,t){let i=this.map.getLayer(e);if(i)if("fill-extrusion"==i.type){let e=this.map.getStyle().sources[i.source].data;e.features.forEach(function(e){e.properties.level=t}),this.map.getSource(i.source).setData(e)}else"custom"==i.type&&this.world.children.forEach(function(i){let r=i.userData.feature;if(r&&r.layer===e){let e=this.tb.getFeatureCenter(r,i,t);i.setCoords(e)}})},setObjectsScale:function(){this.world.children.filter(e=>null!=e.fixedZoom).forEach(e=>{e.setObjectScale(this.map.transform.scale)})},setStyle:function(e,t){this.clear().then(()=>{this.map.setStyle(e,t)})},toggleLayer:function(e,t=!0){let i=this.map.getLayer(e);if(i){if(!t)return void this.toggle(i.id,!1);let e=this.map.getZoom();if(i.minzoom&&e<i.minzoom)return void this.toggle(i.id,!1);if(i.maxzoom&&e>=i.maxzoom)return void this.toggle(i.id,!1);this.toggle(i.id,!0)}},toggle:function(e,t){this.setLayoutProperty(e,"visibility",t?"visible":"none"),this.labelRenderer.toggleLabels(e,t)},update:function(){this.map.repaint&&(this.map.repaint=!1);var e=Date.now();this.objects.animationManager.update(e),this.updateLightHelper(),this.renderer.resetState(),this.renderer.render(this.scene,this.camera),this.labelRenderer.render(this.scene,this.camera),!1===this.options.passiveRendering&&this.map.triggerRepaint()},add:function(e,t,i){if(!this.enableTooltips&&e.tooltip&&(e.tooltip.visibility=!1),this.world.add(e),t){e.layer=t,e.source=i;let r=this.map.getLayer(t);if(r){let t=r.visibility,i=void 0===t;e.visibility=!(!i&&"visible"!==t)}}},removeByName:function(e){let t=this.world.getObjectByName(e);t&&this.remove(t)},remove:function(e){this.map.selectedObject&&e.uuid==this.map.selectedObject.uuid&&this.map.unselectObject(),this.map.draggedObject&&e.uuid==this.map.draggedObject.uuid&&(this.map.draggedObject=null),e.dispose&&e.dispose(),this.world.remove(e),e=null},clear:async function(e=null,t=!1){return new Promise((i,r)=>{let o=[];this.world.children.forEach(function(e){o.push(e)});for(let t=0;t<o.length;t++){let i=o[t];i.layer!==e&&e||this.remove(i)}t&&this.objectsCache.forEach(e=>{e.promise.then(e=>{e.dispose(),e=null})}),i("clear")})},removeLayer:function(e){this.clear(e,!0).then(()=>{this.map.removeLayer(e)})},getSunPosition:function(e,t){return W.getPosition(e||Date.now(),t[1],t[0])},getSunTimes:function(e,t){return W.getTimes(e,t[1],t[0],t[2]?t[2]:0)},setBuildingShadows:function(e){if(this.map.getLayer(e.buildingsLayerId)){let t=new ye(e,this);this.map.addLayer(t,e.buildingsLayerId)}else console.warn("The layer '"+e.buildingsLayerId+"' does not exist in the map.")},setSunlight:function(e=new Date,t){if(!this.lights.dirLight||!this.options.realSunlight)return void console.warn("To use setSunlight it's required to set realSunlight : true in Threebox initial options.");var i=new Date(e.getTime());if(t?t.lng&&t.lat?this.mapCenter=t:this.mapCenter={lng:t[0],lat:t[1]}:this.mapCenter=this.map.getCenter(),this.lightDateTime&&this.lightDateTime.getTime()===i.getTime()&&this.lightLng===this.mapCenter.lng&&this.lightLat===this.mapCenter.lat)return;this.lightDateTime=i,this.lightLng=this.mapCenter.lng,this.lightLat=this.mapCenter.lat,this.sunPosition=this.getSunPosition(i,[this.mapCenter.lng,this.mapCenter.lat]);let r=this.sunPosition.altitude,o=Math.PI+this.sunPosition.azimuth,a=g.WORLD_SIZE/2,n=Math.sin(r),s=Math.cos(r),l=Math.cos(o)*s,h=Math.sin(o)*s;this.lights.dirLight.position.set(h,l,n),this.lights.dirLight.position.multiplyScalar(a),this.lights.dirLight.intensity=Math.max(n,0),this.lights.hemiLight.intensity=Math.max(1*n,.1),this.lights.dirLight.updateMatrixWorld(),this.updateLightHelper(),this.map.loaded()&&(this.updateSunGround(this.sunPosition),this.map.setLight({anchor:"map",position:[3,180+180*this.sunPosition.azimuth/Math.PI,90-180*this.sunPosition.altitude/Math.PI],intensity:Math.cos(this.sunPosition.altitude),color:`hsl(40, ${50*Math.cos(this.sunPosition.altitude)}%, ${Math.max(20,20+96*Math.sin(this.sunPosition.altitude))}%)`},{duration:0}),this.sky&&this.updateSunSky(this.getSunSky(i,this.sunPosition)))},getSunSky:function(e,t){if(!t){var i=this.map.getCenter();t=this.getSunPosition(e||Date.now(),[i.lng,i.lat])}return[180+180*t.azimuth/Math.PI,90-180*t.altitude/Math.PI]},updateSunSky:function(e){this.sky&&this.map.setPaintProperty(this.skyLayerName,"sky-atmosphere-sun",e)},updateSunGround:function(e){""!=this.terrainLayerName&&this.map.setPaintProperty(this.terrainLayerName,"raster-opacity",Math.max(Math.min(1,4*e.altitude),.25))},updateLightHelper:function(){this.lights.dirLightHelper&&(this.lights.dirLightHelper.position.setFromMatrixPosition(this.lights.dirLight.matrixWorld),this.lights.dirLightHelper.updateMatrix(),this.lights.dirLightHelper.update())},dispose:async function(){return console.log(this.memory()),new Promise(e=>{e(this.clear(null,!0).then(e=>(this.map.remove(),this.map={},this.scene.remove(this.world),this.world.children=[],this.world=null,this.objectsCache.clear(),this.labelRenderer.dispose(),console.log(this.memory()),this.renderer.dispose(),e)))})},defaultLights:function(){this.lights.ambientLight=new u.AmbientLight(new u.Color("hsl(0, 0%, 100%)"),.75),this.scene.add(this.lights.ambientLight),this.lights.dirLightBack=new u.DirectionalLight(new u.Color("hsl(0, 0%, 100%)"),.25),this.lights.dirLightBack.position.set(30,100,100),this.scene.add(this.lights.dirLightBack),this.lights.dirLight=new u.DirectionalLight(new u.Color("hsl(0, 0%, 100%)"),.25),this.lights.dirLight.position.set(-30,100,-100),this.scene.add(this.lights.dirLight)},realSunlight:function(e=!1){this.renderer.shadowMap.enabled=!0,this.lights.dirLight=new u.DirectionalLight(16777215,1),this.scene.add(this.lights.dirLight),e&&(this.lights.dirLightHelper=new u.DirectionalLightHelper(this.lights.dirLight,5),this.scene.add(this.lights.dirLightHelper));this.lights.dirLight.castShadow=!0,this.lights.dirLight.shadow.radius=2,this.lights.dirLight.shadow.mapSize.width=8192,this.lights.dirLight.shadow.mapSize.height=8192,this.lights.dirLight.shadow.camera.top=this.lights.dirLight.shadow.camera.right=1e3,this.lights.dirLight.shadow.camera.bottom=this.lights.dirLight.shadow.camera.left=-1e3,this.lights.dirLight.shadow.camera.near=1,this.lights.dirLight.shadow.camera.visible=!0,this.lights.dirLight.shadow.camera.far=4e8,this.lights.hemiLight=new u.HemisphereLight(new u.Color(16777215),new u.Color(16777215),.6),this.lights.hemiLight.color.setHSL(.661,.96,.12),this.lights.hemiLight.groundColor.setHSL(.11,.96,.14),this.lights.hemiLight.position.set(0,0,50),this.scene.add(this.lights.hemiLight),this.setSunlight(),this.map.once("idle",()=>{this.setSunlight(),this.repaint()})},setDefaultView:function(e,t){e.bbox=(e.bbox||null==e.bbox)&&t.enableSelectingObjects,e.tooltip=(e.tooltip||null==e.tooltip)&&t.enableTooltips,e.mapScale=this.map.transform.scale},memory:function(){return this.renderer.info.memory},programs:function(){return this.renderer.info.programs.length},version:"2.2.7"};var xe={defaultLights:!1,realSunlight:!1,realSunlightHelper:!1,passiveRendering:!0,preserveDrawingBuffer:!1,enableSelectingFeatures:!1,enableSelectingObjects:!1,enableDraggingObjects:!1,enableRotatingObjects:!1,enableTooltips:!1,enableHelpTooltips:!1,multiLayer:!1,orthographic:!1,fov:g.FOV_DEGREES,sky:!1,terrain:!1};exports.Threebox=ve;
2
2
  //# sourceMappingURL=threebox.cjs.map