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