* Released under the Apache License, Version 2.0
* see: https://github.com/dcodeIO/long.js for details
*/
-!function(t,i){e&&e.exports?e.exports=i():(t.dcodeIO=t.dcodeIO||{}).Long=i()}(hd,(function(){function e(e,t,i){this.low=0|e,this.high=0|t,this.unsigned=!!i}function t(e){return!0===(e&&e.__isLong__)}e.prototype.__isLong__,Object.defineProperty(e.prototype,"__isLong__",{value:!0,enumerable:!1,configurable:!1}),e.isLong=t;var i={},n={};function r(e,t){var r,s,o;return t?(o=0<=(e>>>=0)&&e<256)&&(s=n[e])?s:(r=a(e,(0|e)<0?-1:0,!0),o&&(n[e]=r),r):(o=-128<=(e|=0)&&e<128)&&(s=i[e])?s:(r=a(e,e<0?-1:0,!1),o&&(i[e]=r),r)}function s(e,t){if(isNaN(e)||!isFinite(e))return t?f:m;if(t){if(e<0)return f;if(e>=u)return b}else{if(e<=-d)return x;if(e+1>=d)return y}return e<0?s(-e,t).neg():a(e%l|0,e/l|0,t)}function a(t,i,n){return new e(t,i,n)}e.fromInt=r,e.fromNumber=s,e.fromBits=a;var o=Math.pow;function h(e,t,i){if(0===e.length)throw Error("empty string");if("NaN"===e||"Infinity"===e||"+Infinity"===e||"-Infinity"===e)return m;if("number"==typeof t?(i=t,t=!1):t=!!t,(i=i||10)<2||36<i)throw RangeError("radix");var n;if((n=e.indexOf("-"))>0)throw Error("interior hyphen");if(0===n)return h(e.substring(1),t,i).neg();for(var r=s(o(i,8)),a=m,c=0;c<e.length;c+=8){var l=Math.min(8,e.length-c),u=parseInt(e.substring(c,c+l),i);if(l<8){var d=s(o(i,l));a=a.mul(d).add(s(u))}else a=(a=a.mul(r)).add(s(u))}return a.unsigned=t,a}function c(t){return t instanceof e?t:"number"==typeof t?s(t):"string"==typeof t?h(t):a(t.low,t.high,t.unsigned)}e.fromString=h,e.fromValue=c;var l=4294967296,u=l*l,d=u/2,p=r(1<<24),m=r(0);e.ZERO=m;var f=r(0,!0);e.UZERO=f;var g=r(1);e.ONE=g;var _=r(1,!0);e.UONE=_;var v=r(-1);e.NEG_ONE=v;var y=a(-1,2147483647,!1);e.MAX_VALUE=y;var b=a(-1,-1,!0);e.MAX_UNSIGNED_VALUE=b;var x=a(0,-2147483648,!1);e.MIN_VALUE=x;var w=e.prototype;return w.toInt=function(){return this.unsigned?this.low>>>0:this.low},w.toNumber=function(){return this.unsigned?(this.high>>>0)*l+(this.low>>>0):this.high*l+(this.low>>>0)},w.toString=function(e){if((e=e||10)<2||36<e)throw RangeError("radix");if(this.isZero())return"0";if(this.isNegative()){if(this.eq(x)){var t=s(e),i=this.div(t),n=i.mul(t).sub(this);return i.toString(e)+n.toInt().toString(e)}return"-"+this.neg().toString(e)}for(var r=s(o(e,6),this.unsigned),a=this,h="";;){var c=a.div(r),l=(a.sub(c.mul(r)).toInt()>>>0).toString(e);if((a=c).isZero())return l+h;for(;l.length<6;)l="0"+l;h=""+l+h}},w.getHighBits=function(){return this.high},w.getHighBitsUnsigned=function(){return this.high>>>0},w.getLowBits=function(){return this.low},w.getLowBitsUnsigned=function(){return this.low>>>0},w.getNumBitsAbs=function(){if(this.isNegative())return this.eq(x)?64:this.neg().getNumBitsAbs();for(var e=0!=this.high?this.high:this.low,t=31;t>0&&0==(e&1<<t);t--);return 0!=this.high?t+33:t+1},w.isZero=function(){return 0===this.high&&0===this.low},w.isNegative=function(){return!this.unsigned&&this.high<0},w.isPositive=function(){return this.unsigned||this.high>=0},w.isOdd=function(){return 1==(1&this.low)},w.isEven=function(){return 0==(1&this.low)},w.equals=function(e){return t(e)||(e=c(e)),(this.unsigned===e.unsigned||this.high>>>31!=1||e.high>>>31!=1)&&(this.high===e.high&&this.low===e.low)},w.eq=w.equals,w.notEquals=function(e){return!this.eq(e)},w.neq=w.notEquals,w.lessThan=function(e){return this.comp(e)<0},w.lt=w.lessThan,w.lessThanOrEqual=function(e){return this.comp(e)<=0},w.lte=w.lessThanOrEqual,w.greaterThan=function(e){return this.comp(e)>0},w.gt=w.greaterThan,w.greaterThanOrEqual=function(e){return this.comp(e)>=0},w.gte=w.greaterThanOrEqual,w.compare=function(e){if(t(e)||(e=c(e)),this.eq(e))return 0;var i=this.isNegative(),n=e.isNegative();return i&&!n?-1:!i&&n?1:this.unsigned?e.high>>>0>this.high>>>0||e.high===this.high&&e.low>>>0>this.low>>>0?-1:1:this.sub(e).isNegative()?-1:1},w.comp=w.compare,w.negate=function(){return!this.unsigned&&this.eq(x)?x:this.not().add(g)},w.neg=w.negate,w.add=function(e){t(e)||(e=c(e));var i=this.high>>>16,n=65535&this.high,r=this.low>>>16,s=65535&this.low,o=e.high>>>16,h=65535&e.high,l=e.low>>>16,u=0,d=0,p=0,m=0;return p+=(m+=s+(65535&e.low))>>>16,d+=(p+=r+l)>>>16,u+=(d+=n+h)>>>16,u+=i+o,a((p&=65535)<<16|(m&=65535),(u&=65535)<<16|(d&=65535),this.unsigned)},w.subtract=function(e){return t(e)||(e=c(e)),this.add(e.neg())},w.sub=w.subtract,w.multiply=function(e){if(this.isZero())return m;if(t(e)||(e=c(e)),e.isZero())return m;if(this.eq(x))return e.isOdd()?x:m;if(e.eq(x))return this.isOdd()?x:m;if(this.isNegative())return e.isNegative()?this.neg().mul(e.neg()):this.neg().mul(e).neg();if(e.isNegative())return this.mul(e.neg()).neg();if(this.lt(p)&&e.lt(p))return s(this.toNumber()*e.toNumber(),this.unsigned);var i=this.high>>>16,n=65535&this.high,r=this.low>>>16,o=65535&this.low,h=e.high>>>16,l=65535&e.high,u=e.low>>>16,d=65535&e.low,f=0,g=0,_=0,v=0;return _+=(v+=o*d)>>>16,g+=(_+=r*d)>>>16,_&=65535,g+=(_+=o*u)>>>16,f+=(g+=n*d)>>>16,g&=65535,f+=(g+=r*u)>>>16,g&=65535,f+=(g+=o*l)>>>16,f+=i*d+n*u+r*l+o*h,a((_&=65535)<<16|(v&=65535),(f&=65535)<<16|(g&=65535),this.unsigned)},w.mul=w.multiply,w.divide=function(e){if(t(e)||(e=c(e)),e.isZero())throw Error("division by zero");if(this.isZero())return this.unsigned?f:m;var i,n,r;if(this.unsigned){if(e.unsigned||(e=e.toUnsigned()),e.gt(this))return f;if(e.gt(this.shru(1)))return _;r=f}else{if(this.eq(x))return e.eq(g)||e.eq(v)?x:e.eq(x)?g:(i=this.shr(1).div(e).shl(1)).eq(m)?e.isNegative()?g:v:(n=this.sub(e.mul(i)),r=i.add(n.div(e)));if(e.eq(x))return this.unsigned?f:m;if(this.isNegative())return e.isNegative()?this.neg().div(e.neg()):this.neg().div(e).neg();if(e.isNegative())return this.div(e.neg()).neg();r=m}for(n=this;n.gte(e);){i=Math.max(1,Math.floor(n.toNumber()/e.toNumber()));for(var a=Math.ceil(Math.log(i)/Math.LN2),h=a<=48?1:o(2,a-48),l=s(i),u=l.mul(e);u.isNegative()||u.gt(n);)u=(l=s(i-=h,this.unsigned)).mul(e);l.isZero()&&(l=g),r=r.add(l),n=n.sub(u)}return r},w.div=w.divide,w.modulo=function(e){return t(e)||(e=c(e)),this.sub(this.div(e).mul(e))},w.mod=w.modulo,w.not=function(){return a(~this.low,~this.high,this.unsigned)},w.and=function(e){return t(e)||(e=c(e)),a(this.low&e.low,this.high&e.high,this.unsigned)},w.or=function(e){return t(e)||(e=c(e)),a(this.low|e.low,this.high|e.high,this.unsigned)},w.xor=function(e){return t(e)||(e=c(e)),a(this.low^e.low,this.high^e.high,this.unsigned)},w.shiftLeft=function(e){return t(e)&&(e=e.toInt()),0==(e&=63)?this:e<32?a(this.low<<e,this.high<<e|this.low>>>32-e,this.unsigned):a(0,this.low<<e-32,this.unsigned)},w.shl=w.shiftLeft,w.shiftRight=function(e){return t(e)&&(e=e.toInt()),0==(e&=63)?this:e<32?a(this.low>>>e|this.high<<32-e,this.high>>e,this.unsigned):a(this.high>>e-32,this.high>=0?0:-1,this.unsigned)},w.shr=w.shiftRight,w.shiftRightUnsigned=function(e){if(t(e)&&(e=e.toInt()),0===(e&=63))return this;var i=this.high;return e<32?a(this.low>>>e|i<<32-e,i>>>e,this.unsigned):a(32===e?i:i>>>e-32,0,this.unsigned)},w.shru=w.shiftRightUnsigned,w.toSigned=function(){return this.unsigned?a(this.low,this.high,!1):this},w.toUnsigned=function(){return this.unsigned?this:a(this.low,this.high,!0)},w.toBytes=function(e){return e?this.toBytesLE():this.toBytesBE()},w.toBytesLE=function(){var e=this.high,t=this.low;return[255&t,t>>>8&255,t>>>16&255,t>>>24&255,255&e,e>>>8&255,e>>>16&255,e>>>24&255]},w.toBytesBE=function(){var e=this.high,t=this.low;return[e>>>24&255,e>>>16&255,e>>>8&255,255&e,t>>>24&255,t>>>16&255,t>>>8&255,255&t]},e}))}(yw),function(e){!function(e){var t=e.S2={L:{}};t.L.LatLng=function(e,t,i){var n=parseFloat(e,10),r=parseFloat(t,10);if(isNaN(n)||isNaN(r))throw new Error("Invalid LatLng object: ("+e+", "+t+")");return!0!==i&&(n=Math.max(Math.min(n,90),-90),r=(r+180)%360+(r<-180||180===r?180:-180)),{lat:n,lng:r}},t.L.LatLng.DEG_TO_RAD=Math.PI/180,t.L.LatLng.RAD_TO_DEG=180/Math.PI,t.LatLngToXYZ=function(e){var i=t.L.LatLng.DEG_TO_RAD,n=e.lat*i,r=e.lng*i,s=Math.cos(n);return[Math.cos(r)*s,Math.sin(r)*s,Math.sin(n)]},t.XYZToLatLng=function(e){var i=t.L.LatLng.RAD_TO_DEG,n=Math.atan2(e[2],Math.sqrt(e[0]*e[0]+e[1]*e[1])),r=Math.atan2(e[1],e[0]);return t.L.LatLng(n*i,r*i)};t.XYZToFaceUV=function(e){var t=function(e){var t=[Math.abs(e[0]),Math.abs(e[1]),Math.abs(e[2])];return t[0]>t[1]?t[0]>t[2]?0:2:t[1]>t[2]?1:2}(e);return e[t]<0&&(t+=3),[t,function(e,t){var i,n;switch(e){case 0:i=t[1]/t[0],n=t[2]/t[0];break;case 1:i=-t[0]/t[1],n=t[2]/t[1];break;case 2:i=-t[0]/t[2],n=-t[1]/t[2];break;case 3:i=t[2]/t[0],n=t[1]/t[0];break;case 4:i=t[2]/t[1],n=-t[0]/t[1];break;case 5:i=-t[1]/t[2],n=-t[0]/t[2];break;default:throw{error:"Invalid face"}}return[i,n]}(t,e)]},t.FaceUVToXYZ=function(e,t){var i=t[0],n=t[1];switch(e){case 0:return[1,i,n];case 1:return[-i,1,n];case 2:return[-i,-n,1];case 3:return[-1,-n,-i];case 4:return[n,-1,-i];case 5:return[n,i,-1];default:throw{error:"Invalid face"}}};var i=function(e){return e>=.5?1/3*(4*e*e-1):1/3*(1-4*(1-e)*(1-e))};t.STToUV=function(e){return[i(e[0]),i(e[1])]};var n=function(e){return e>=0?.5*Math.sqrt(1+3*e):1-.5*Math.sqrt(1-3*e)};t.UVToST=function(e){return[n(e[0]),n(e[1])]},t.STToIJ=function(e,t){var i=1<<t,n=function(e){var t=Math.floor(e*i);return Math.max(0,Math.min(i-1,t))};return[n(e[0]),n(e[1])]},t.IJToST=function(e,t,i){var n=1<<t;return[(e[0]+i[0])/n,(e[1]+i[1])/n]};var r=function(e,t,i,n){if(0==n){1==i&&(t.x=e-1-t.x,t.y=e-1-t.y);var r=t.x;t.x=t.y,t.y=r}},s=function(e,t,i,n){var r={a:[[0,"d"],[1,"a"],[3,"b"],[2,"a"]],b:[[2,"b"],[1,"b"],[3,"a"],[0,"c"]],c:[[2,"c"],[3,"d"],[1,"c"],[0,"b"]],d:[[0,"a"],[3,"c"],[1,"d"],[2,"d"]]};"number"!=typeof n&&console.warn(new Error("called pointToHilbertQuadList without face value, defaulting to '0'").stack);for(var s=n%2?"d":"a",a=[],o=i-1;o>=0;o--){var h=1<<o,c=r[s][2*(e&h?1:0)+(t&h?1:0)];a.push(c[0]),s=c[1]}return a};t.S2Cell=function(){},t.S2Cell.FromHilbertQuadKey=function(e){var i,n,s,a,o,h,c=e.split("/"),l=parseInt(c[0]),u=c[1],d=u.length,p={x:0,y:0};for(i=d-1;i>=0;i--)n=d-i,a=0,o=0,"1"===(s=u[i])?o=1:"2"===s?(a=1,o=1):"3"===s&&(a=1),h=Math.pow(2,n-1),r(h,p,a,o),p.x+=h*a,p.y+=h*o;if(l%2==1){var m=p.x;p.x=p.y,p.y=m}return t.S2Cell.FromFaceIJ(parseInt(l),[p.x,p.y],n)},t.S2Cell.FromLatLng=function(e,i){if(!e.lat&&0!==e.lat||!e.lng&&0!==e.lng)throw new Error("Pass { lat: lat, lng: lng } to S2.S2Cell.FromLatLng");var n=t.LatLngToXYZ(e),r=t.XYZToFaceUV(n),s=t.UVToST(r[1]),a=t.STToIJ(s,i);return t.S2Cell.FromFaceIJ(r[0],a,i)},t.S2Cell.FromFaceIJ=function(e,i,n){var r=new t.S2Cell;return r.face=e,r.ij=i,r.level=n,r},t.S2Cell.prototype.toString=function(){return"F"+this.face+"ij["+this.ij[0]+","+this.ij[1]+"]@"+this.level},t.S2Cell.prototype.getLatLng=function(){var e=t.IJToST(this.ij,this.level,[.5,.5]),i=t.STToUV(e),n=t.FaceUVToXYZ(this.face,i);return t.XYZToLatLng(n)},t.S2Cell.prototype.getCornerLatLngs=function(){for(var e=[],i=[[0,0],[0,1],[1,1],[1,0]],n=0;n<4;n++){var r=t.IJToST(this.ij,this.level,i[n]),s=t.STToUV(r),a=t.FaceUVToXYZ(this.face,s);e.push(t.XYZToLatLng(a))}return e},t.S2Cell.prototype.getFaceAndQuads=function(){var e=s(this.ij[0],this.ij[1],this.level,this.face);return[this.face,e]},t.S2Cell.prototype.toHilbertQuadkey=function(){var e=s(this.ij[0],this.ij[1],this.level,this.face);return this.face.toString(10)+"/"+e.join("")},t.latLngToNeighborKeys=t.S2Cell.latLngToNeighborKeys=function(e,i,n){return t.S2Cell.FromLatLng({lat:e,lng:i},n).getNeighbors().map((function(e){return e.toHilbertQuadkey()}))},t.S2Cell.prototype.getNeighbors=function(){var e=function(e,i,n){var r=1<<n;if(i[0]>=0&&i[1]>=0&&i[0]<r&&i[1]<r)return t.S2Cell.FromFaceIJ(e,i,n);var s=t.IJToST(i,n,[.5,.5]),a=t.STToUV(s),o=t.FaceUVToXYZ(e,a),h=t.XYZToFaceUV(o);return e=h[0],a=h[1],s=t.UVToST(a),i=t.STToIJ(s,n),t.S2Cell.FromFaceIJ(e,i,n)},i=this.face,n=this.ij[0],r=this.ij[1],s=this.level;return[e(i,[n-1,r],s),e(i,[n,r-1],s),e(i,[n+1,r],s),e(i,[n,r+1],s)]},t.FACE_BITS=3,t.MAX_LEVEL=30,t.POS_BITS=2*t.MAX_LEVEL+1,t.facePosLevelToId=t.S2Cell.facePosLevelToId=t.fromFacePosLevel=function(i,n,r){var s,a,o,h=e.dcodeIO&&e.dcodeIO.Long||yw.exports;for(r||(r=n.length),n.length>r&&(n=n.substr(0,r)),s=h.fromString(i.toString(10),!0,10).toString(2);s.length<t.FACE_BITS;)s="0"+s;for(a=h.fromString(n,!0,4).toString(2);a.length<2*r;)a="0"+a;for(o=s+a,o+="1";o.length<t.FACE_BITS+t.POS_BITS;)o+="0";return h.fromString(o,!0,2).toString(10)},t.keyToId=t.S2Cell.keyToId=t.toId=t.toCellId=t.fromKey=function(e){var i=e.split("/");return t.fromFacePosLevel(i[0],i[1],i[1].length)},t.idToKey=t.S2Cell.idToKey=t.S2Cell.toKey=t.toKey=t.fromId=t.fromCellId=t.S2Cell.toHilbertQuadkey=t.toHilbertQuadkey=function(i){for(var n=e.dcodeIO&&e.dcodeIO.Long||yw.exports,r=n.fromString(i,!0,10).toString(2);r.length<t.FACE_BITS+t.POS_BITS;)r="0"+r;for(var s=r.lastIndexOf("1"),a=r.substring(0,3),o=r.substring(3,s),h=o.length/2,c=n.fromString(a,!0,2).toString(10),l=n.fromString(o,!0,2).toString(4);l.length<h;)l="0"+l;return c+"/"+l},t.keyToLatLng=t.S2Cell.keyToLatLng=function(e){return t.S2Cell.FromHilbertQuadKey(e).getLatLng()},t.idToLatLng=t.S2Cell.idToLatLng=function(e){var i=t.idToKey(e);return t.keyToLatLng(i)},t.S2Cell.latLngToKey=t.latLngToKey=t.latLngToQuadkey=function(e,i,n){if(isNaN(n)||n<1||n>30)throw new Error("'level' is not a number between 1 and 30 (but it should be)");return t.S2Cell.FromLatLng({lat:e,lng:i},n).toHilbertQuadkey()},t.stepKey=function(t,i){var n,r=e.dcodeIO&&e.dcodeIO.Long||yw.exports,s=t.split("/"),a=s[0],o=s[1],h=s[1].length,c=r.fromString(o,!0,4);i>0?n=c.add(Math.abs(i)):i<0&&(n=c.subtract(Math.abs(i)));var l=n.toString(4);for("0"===l&&console.warning(new Error("face/position wrapping is not yet supported"));l.length<h;)l="0"+l;return a+"/"+l},t.S2Cell.prevKey=t.prevKey=function(e){return t.stepKey(e,-1)},t.S2Cell.nextKey=t.nextKey=function(e){return t.stepKey(e,1)}}(e.exports)}(vw);class bw extends _w{constructor(e=17){super(),this._level=e}bboxToCellIds(e,t){return this._approxBboxToCellIds(e,t)}getAdjacent(e){const t=vw.exports.S2.idToKey(e),i=t.split("/")[1].length,[n,r,s,a]=this._getNeighbors(t,i),o=[t,n,r,s,a],h=Array.from(new Set([...this._getNeighbors(n,i),...this._getNeighbors(r,i),...this._getNeighbors(s,i),...this._getNeighbors(a,i)].filter((e=>!o.includes(e))))),c=[n,r,s,a];for(const e of h){let t=0;for(const n of this._getNeighbors(e,i))o.includes(n)&&t++;2===t&&c.push(e)}return c.map((e=>vw.exports.S2.keyToId(e)))}getVertices(e){const t=vw.exports.S2.idToKey(e);return vw.exports.S2.S2Cell.FromHilbertQuadKey(t).getCornerLatLngs().map((e=>({lat:e.lat,lng:e.lng})))}lngLatToCellId(e){return this._lngLatToId(e,this._level)}_getNeighbors(e,t){const i=vw.exports.S2.keyToLatLng(e);return vw.exports.S2.latLngToNeighborKeys(i.lat,i.lng,t)}_lngLatToId(e,t){const i=vw.exports.S2.latLngToKey(e.lat,e.lng,t);return vw.exports.S2.keyToId(i)}}class xw{clusterReconstruction(e){const t=e.points,i=1/255;for(const e in t){if(!t.hasOwnProperty(e))continue;const n=t[e].color;n[0]*=i,n[1]*=i,n[2]*=i}const n=e.reference_lla;return{id:null,points:t,reference:{alt:n.altitude,lat:n.latitude,lng:n.longitude}}}coreImage(e){const t=this._geometry(e.geometry),i=this._geometry(e.computed_geometry),n={id:e.sequence};return{computed_geometry:i,geometry:t,id:e.id,sequence:n}}spatialImage(e){var t,i,n,r;e.camera_type=function(e){switch(e){case"equirectangular":case"spherical":return"spherical";case"fisheye":return"fisheye";default:return"perspective"}}(e.camera_type),e.merge_id=e.merge_cc?e.merge_cc.toString():null,e.private=null;const s="spherical"===e.camera_type?e.thumb_2048_url:e.thumb_1024_url;return e.thumb=null!==(t=e.thumb)&&void 0!==t?t:{id:null,url:s},e.cluster=null!==(i=e.sfm_cluster)&&void 0!==i?i:{id:null,url:null},e.creator={id:null,username:null},e.owner=null!==(n=e.owner)&&void 0!==n?n:{id:null},e.mesh=null!==(r=e.mesh)&&void 0!==r?r:{id:null,url:null},e}_geometry(e){const t=null==e?void 0:e.coordinates;return t?{lat:t[1],lng:t[0]}:null}}class ww{constructor(){this.imagesPath="images",this.sequencePath="image_ids",this._imageTilesPath="tiles",this.coreFields=["computed_geometry","geometry","sequence"],this.idFields=["id"],this.spatialFields=["altitude","atomic_scale","camera_parameters","camera_type","captured_at","compass_angle","computed_altitude","computed_compass_angle","computed_rotation","exif_orientation","height","merge_cc","mesh","quality_score","sfm_cluster","thumb_1024_url","thumb_2048_url","width"],this.imageTileFields=["url","z","x","y"]}images(e,t){return`image_ids=${e.join(",")}&fields=${t.join(",")}`}imagesS2(e,t){return`s2=${e}&fields=${t.join(",")}`}imageTiles(e,t){return`z=${e}&fields=${t.join(",")}`}imageTilesPath(e){return`${e}/${this._imageTilesPath}`}sequence(e){return`sequence_id=${e}`}}class Mw extends gw{constructor(e,t,i,n){var r;super(null!=t?t:new bw),this._convert=null!=i?i:new xw,this._query=null!=n?n:new ww,this._method="GET";const s=null!=e?e:{};this._endpoint=null!==(r=s.endpoint)&&void 0!==r?r:"https://graph.mapillary.com",this._accessToken=s.accessToken}getCluster(e,t){return dw(e,t).then((e=>{const t=uw(e);if(t.length<1)throw new Error("Cluster reconstruction empty");return this._convert.clusterReconstruction(t[0])}))}getCoreImages(e){const t=[...this._query.idFields,...this._query.coreFields],i=this._query.imagesS2(e,t),n=new URL(this._query.imagesPath,this._endpoint).href;return this._fetchGraphContract(i,n).then((t=>{const i={cell_id:e,images:[]},n=t.data;for(const e of n){const t=this._convert.coreImage(e);i.images.push(t)}return i}))}getImageBuffer(e,t){return dw(e,t)}getImages(e){const t=[...this._query.idFields,...this._query.coreFields,...this._query.spatialFields],i=this._query.images(e,t),n=new URL(this._query.imagesPath,this._endpoint).href;return this._fetchGraphContract(i,n).then((e=>{const t=[],i=e.data;for(const e of i){const i=this._convert.coreImage(e),n=this._convert.spatialImage(e),r={node:Object.assign({},n,i),node_id:e.id};t.push(r)}return t}))}getImageTiles(e){const t=[...this._query.imageTileFields],i=this._query.imageTiles(e.z,t),n=new URL(this._query.imageTilesPath(e.imageId),this._endpoint).href;return this._fetchGraphContract(i,n).then((t=>({node:t.data,node_id:e.imageId})))}getMesh(e,t){return dw(e,t).then((e=>mw(e)))}getSequence(e){const t=this._query.sequence(e),i=new URL(this._query.sequencePath,this._endpoint).href;return this._fetchGraphContract(t,i).then((t=>({id:e,image_ids:t.data.map((e=>e.id))})))}getSpatialImages(e){const t=[...this._query.idFields,...this._query.coreFields,...this._query.spatialFields],i=this._query.images(e,t),n=new URL(this._query.imagesPath,this._endpoint).href;return this._fetchGraphContract(i,n).then((e=>{const t=[],i=e.data;for(const e of i){const i={node:this._convert.spatialImage(e),node_id:e.id};t.push(i)}return t}))}setAccessToken(e){this._accessToken=e}_createHeaders(){const e=[{name:"Accept",value:"application/json"},{name:"Content-Type",value:"application/x-www-form-urlencoded"}];return this._accessToken&&e.push({name:"Authorization",value:`OAuth ${this._accessToken}`}),e}_fetchGraphContract(e,t){return pw(`${t}?${e}`,this._method,"json",this._createHeaders(),null,null).catch((e=>{const t=this._makeErrorMessage(e);throw new Pu(t)}))}_makeErrorMessage(e){const t=e.error;return t?`${t.code} (${t.type}, ${t.fbtrace_id}): ${t.message}`:"Failed to fetch data"}}class Sw{constructor(e,t){this._id=e,this._lngLat=t}get id(){return this._id}get geometry(){return this._geometry}get lngLat(){return this._lngLat}createGeometry(e){this._geometry||(this._createGeometry(e),this._geometry.updateMatrixWorld(!0))}disposeGeometry(){this._geometry&&(this._disposeGeometry(),this._geometry=void 0)}getInteractiveObjects(){return this._geometry?this._getInteractiveObjects():[]}lerpAltitude(e,t){this._geometry&&(this._geometry.position.z=(1-t)*this._geometry.position.z+t*e)}updatePosition(e,t){t&&(this._lngLat.lat=t.lat,this._lngLat.lng=t.lng),this._geometry&&(this._geometry.position.fromArray(e),this._geometry.updateMatrixWorld(!0))}}let Tw;function Cw(){return void 0===Tw&&(Tw=function(){const e={alpha:!1,antialias:!1,depth:!0,failIfMajorPerformanceCaveat:!1,premultipliedAlpha:!0,preserveDrawingBuffer:!1,stencil:!0},t=document.createElement("canvas");if(t.getContext("webgl2",e))return!0;const i=t.getContext("webgl",e)||t.getContext("experimental-webgl",e);if(!i)return!1;const n=["OES_standard_derivatives"],r=i.getSupportedExtensions();for(const e of n)if(-1===r.indexOf(e))return!1;return!0}()),Tw}function Ew(){return"undefined"!=typeof window&&"undefined"!=typeof document&&!!(Array.prototype&&Array.prototype.concat&&Array.prototype.filter&&Array.prototype.includes&&Array.prototype.indexOf&&Array.prototype.join&&Array.prototype.map&&Array.prototype.push&&Array.prototype.pop&&Array.prototype.reverse&&Array.prototype.shift&&Array.prototype.slice&&Array.prototype.splice&&Array.prototype.sort&&Array.prototype.unshift)&&"Blob"in window&&"URL"in window&&!!(Function.prototype&&Function.prototype.apply&&Function.prototype.bind)&&"JSON"in window&&"parse"in JSON&&"stringify"in JSON&&"Map"in window&&!!(Object.assign&&Object.keys&&Object.values)&&!!("Promise"in window&&Promise.resolve&&Promise.reject&&Promise.prototype&&Promise.prototype.catch&&Promise.prototype.then)&&"Set"in window}var Aw,Iw,Rw;e.CameraControls=void 0,(Aw=e.CameraControls||(e.CameraControls={}))[Aw.Custom=0]="Custom",Aw[Aw.Earth=1]="Earth",Aw[Aw.Street=2]="Street",e.RenderMode=void 0,(Iw=e.RenderMode||(e.RenderMode={}))[Iw.Letterbox=0]="Letterbox",Iw[Iw.Fill=1]="Fill",e.RenderPass=void 0,function(e){e[e.Opaque=0]="Opaque"}(e.RenderPass||(e.RenderPass={})),e.TransitionMode=void 0,(Rw=e.TransitionMode||(e.TransitionMode={}))[Rw.Default=0]="Default",Rw[Rw.Instantaneous=1]="Instantaneous";class Pw{constructor(e,t,i,n,r,s){this._container=e,this._observer=i,this._navigator=t,this._options=null!=r?r:{},this._key=n,this._navigable=null==n,this._componentService=s||new od(this._container,this._navigator),this._coverComponent=this._componentService.getCover(),this._initializeComponents(),n?(this._initilizeCoverComponent(),this._subscribeCoverComponent()):this._navigator.movedToId$.pipe(St((e=>null!=e))).subscribe((e=>{this._key=e,this._componentService.deactivateCover(),this._coverComponent.configure({id:this._key,state:Qm.Hidden}),this._subscribeCoverComponent(),this._navigator.stateService.start(),this._navigator.cacheService.start(),this._navigator.panService.start(),this._observer.startEmit()}))}get navigable(){return this._navigable}get(e){return this._componentService.get(e)}activate(e){this._componentService.activate(e)}activateCover(){this._coverComponent.configure({state:Qm.Visible})}deactivate(e){this._componentService.deactivate(e)}deactivateCover(){this._coverComponent.configure({state:Qm.Loading})}remove(){this._componentService.remove(),null!=this._configurationSubscription&&this._configurationSubscription.unsubscribe()}_initializeComponents(){var e,t;const i=this._options;this._uFalse(null===(e=i.fallback)||void 0===e?void 0:e.image,"imagefallback"),this._uFalse(null===(t=i.fallback)||void 0===t?void 0:t.navigation,"navigationfallback"),this._uFalse(i.marker,"marker"),this._uFalse(i.popup,"popup"),this._uFalse(i.slider,"slider"),this._uFalse(i.spatial,"spatial"),this._uFalse(i.tag,"tag"),this._uTrue(i.attribution,"attribution"),this._uTrue(i.bearing,"bearing"),this._uTrue(i.cache,"cache"),this._uTrue(i.direction,"direction"),this._uTrue(i.image,"image"),this._uTrue(i.keyboard,"keyboard"),this._uTrue(i.pointer,"pointer"),this._uTrue(i.sequence,"sequence"),this._uTrue(i.zoom,"zoom")}_initilizeCoverComponent(){let e=this._options;this._coverComponent.configure({id:this._key}),void 0===e.cover||e.cover?this.activateCover():this.deactivateCover()}_setNavigable(e){this._navigable!==e&&(this._navigable=e,this._observer.navigable$.next(e))}_subscribeCoverComponent(){this._configurationSubscription=this._coverComponent.configuration$.pipe(vt(void 0,(e=>e.state))).subscribe((e=>{e.state===Qm.Loading?this._navigator.stateService.currentId$.pipe(St(),zt((t=>{const i=null==t||t!==e.id;return i&&this._setNavigable(!1),i?this._navigator.moveTo$(e.id):this._navigator.stateService.currentImage$.pipe(St())}))).subscribe((()=>{this._navigator.stateService.start(),this._navigator.cacheService.start(),this._navigator.panService.start(),this._observer.startEmit(),this._coverComponent.configure({state:Qm.Hidden}),this._componentService.deactivateCover(),this._setNavigable(!0)}),(e=>{console.error("Failed to deactivate cover.",e),this._coverComponent.configure({state:Qm.Visible})})):e.state===Qm.Visible&&(this._observer.stopEmit(),this._navigator.stateService.stop(),this._navigator.cacheService.stop(),this._navigator.playService.stop(),this._navigator.panService.stop(),this._componentService.activateCover(),this._setNavigable(null==e.id))}))}_uFalse(e,t){void 0!==e?"boolean"!=typeof e?(this._componentService.configure(t,e),this._componentService.activate(t)):e?this._componentService.activate(t):this._componentService.deactivate(t):this._componentService.deactivate(t)}_uTrue(e,t){void 0!==e?"boolean"!=typeof e?(this._componentService.configure(t,e),this._componentService.activate(t)):e?this._componentService.activate(t):this._componentService.deactivate(t):this._componentService.activate(t)}}class Lw{constructor(t,i,n){this._adaptiveOperation$=new j,this._render$=new j,this._renderAdaptive$=new j,this._subscriptions=new rf,this._renderService=i,this._currentFrame$=n;const r=this._subscriptions,s=tf.create(tf.h("div.mapillary-dom-renderer",[]));t.appendChild(s),this._offset$=this._adaptiveOperation$.pipe(Lt(((e,t)=>t(e)),{elementHeight:t.offsetHeight,elementWidth:t.offsetWidth,imageAspect:0,renderMode:e.RenderMode.Fill}),st((e=>e.imageAspect>0&&e.elementWidth>0&&e.elementHeight>0)),De((t=>{const i=t.elementWidth/t.elementHeight,n=t.imageAspect/i;let r=0,s=0;return t.renderMode===e.RenderMode.Letterbox?t.imageAspect>i?r=t.elementHeight*(1-1/n)/2:s=t.elementWidth*(1-n)/2:t.imageAspect>i?s=-t.elementWidth*(n-1)/2:r=-t.elementHeight*(1/n-1)/2,{bottom:r,left:s,right:s,top:r}})));const a=this._currentFrame$.pipe(st((e=>null!=e.state.currentImage)),vt(((e,t)=>e===t),(e=>e.state.currentImage.id)),De((e=>e.state.currentTransform.basicAspect)),De((e=>t=>(t.imageAspect=e,t)))).subscribe(this._adaptiveOperation$),o=Ve(this._renderAdaptive$.pipe(Lt(((e,t)=>(null==t.vNode?delete e[t.name]:e[t.name]=t.vNode,e)),{})),this._offset$).pipe(De((e=>{const t=[],i=e[0];for(const e in i)i.hasOwnProperty(e)&&t.push(i[e]);const n=e[1],r={style:{bottom:n.bottom+"px",left:n.left+"px","pointer-events":"none",position:"absolute",right:n.right+"px",top:n.top+"px"}};return{name:"mapillary-dom-adaptive-renderer",vNode:tf.h("div.mapillary-dom-adaptive-renderer",r,t)}}))).subscribe(this._render$);this._vNode$=this._render$.pipe(Lt(((e,t)=>(null==t.vNode?delete e[t.name]:e[t.name]=t.vNode,e)),{}),De((e=>{const t=[];for(const i in e)e.hasOwnProperty(i)&&t.push(e[i]);return tf.h("div.mapillary-dom-renderer",t)}))),this._vPatch$=this._vNode$.pipe(Lt(((e,t)=>(e.vpatch=tf.diff(e.vNode,t),e.vNode=t,e)),{vNode:tf.h("div.mapillary-dom-renderer",[]),vpatch:null}),function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var i=e.length;if(0===i)throw new Error("list of properties cannot be empty.");return De((function(t){for(var n=t,r=0;r<i;r++){var s=null==n?void 0:n[e[r]];if(void 0===s)return;n=s}return n}))}("vpatch")),this._element$=this._vPatch$.pipe(Lt(((e,t)=>tf.patch(e,t)),s),Rt(1),U()),r.push(a),r.push(o),r.push(this._element$.subscribe((()=>{}))),r.push(this._renderService.size$.pipe(De((e=>t=>(t.elementWidth=e.width,t.elementHeight=e.height,t)))).subscribe(this._adaptiveOperation$)),r.push(this._renderService.renderMode$.pipe(De((e=>t=>(t.renderMode=e,t)))).subscribe(this._adaptiveOperation$))}get element$(){return this._element$}get render$(){return this._render$}get renderAdaptive$(){return this._renderAdaptive$}clear(e){this._renderAdaptive$.next({name:e,vNode:null}),this._render$.next({name:e,vNode:null})}remove(){this._subscriptions.unsubscribe()}}class Dw{constructor(e,t,i){this._renderFrame$=new j,this._renderCameraOperation$=new j,this._render$=new j,this._clear$=new j,this._renderOperation$=new j,this._rendererOperation$=new j,this._eraserOperation$=new j,this._triggerOperation$=new j,this._subscriptions=new rf,this._opaqueRender$=new j,this._renderService=i;const n=this._subscriptions;this._renderer$=this._rendererOperation$.pipe(Lt(((e,t)=>t(e)),{needsRender:!1,renderer:null}),st((e=>!!e.renderer))),this._renderCollection$=this._renderOperation$.pipe(Lt(((e,t)=>t(e)),{}),Dt()),this._renderCamera$=this._renderCameraOperation$.pipe(Lt(((e,t)=>t(e)),{frameId:-1,needsRender:!1,perspective:null})),this._eraser$=this._eraserOperation$.pipe(Ot((e=>e)),Lt(((e,t)=>t(e)),{needsRender:!1}));const r=this._triggerOperation$.pipe(Ot((e=>e)),Lt(((e,t)=>t(e)),{needsRender:!1})),s=new xr(986895),a=Ve(this._renderer$,this._renderCollection$,this._renderCamera$,this._eraser$,r).pipe(De((([e,t,i,n,r])=>({camera:i,eraser:n,trigger:r,renderer:e,renders:Object.keys(t).map((e=>t[e]))}))),st((e=>{let t=e.renderer.needsRender||e.camera.needsRender||e.eraser.needsRender||e.trigger.needsRender;const i=e.camera.frameId;for(const n of e.renders){if(n.frameId!==i)return!1;t=t||n.needsRender}return t})),vt(((e,t)=>e===t),(e=>e.eraser.needsRender||e.trigger.needsRender?-e.camera.frameId:e.camera.frameId))).subscribe((e=>{e.renderer.needsRender=!1,e.camera.needsRender=!1,e.eraser.needsRender=!1,e.trigger.needsRender=!1;const t=e.camera.perspective,i=[],n=[];for(const t of e.renders)t.pass===yf.Background?i.push(t.render):t.pass===yf.Opaque&&n.push(t.render);const r=e.renderer.renderer;r.resetState(),r.setClearColor(s,1),r.clear();for(const e of i)e(t,r);r.clearDepth();for(const e of n)e(t,r);r.resetState(),this._opaqueRender$.next()}));n.push(a),n.push(this._renderFrame$.pipe(De((e=>t=>(t.frameId=e.frameId,t.perspective=e.perspective,!0===e.changed&&(t.needsRender=!0),t)))).subscribe(this._renderCameraOperation$)),this._renderFrameSubscribe();const o=this._render$.pipe(De((e=>t=>(t[e.name]=e.renderer,t)))),h=this._clear$.pipe(De((e=>t=>(delete t[e],t))));n.push(it(o,h).subscribe(this._renderOperation$)),this._webGLRenderer$=this._render$.pipe(St(),De((()=>{t.appendChild(e);const n=i.element,r=new hh({canvas:e});return r.setPixelRatio(window.devicePixelRatio),r.setSize(n.offsetWidth,n.offsetHeight),r.autoClear=!1,r})),Rt(1),U()),n.push(this._webGLRenderer$.subscribe((()=>{})));const c=this._webGLRenderer$.pipe(St(),De((e=>t=>(t.needsRender=!0,t.renderer=e,t)))),l=this._renderService.size$.pipe(De((e=>t=>(null==t.renderer||(t.renderer.setSize(e.width,e.height),t.needsRender=!0),t)))),u=this._clear$.pipe(De((()=>e=>(null==e.renderer||(e.needsRender=!0),e))));n.push(it(c,l,u).subscribe(this._rendererOperation$));const d=this._renderCollection$.pipe(st((e=>0===Object.keys(e).length)),Dt());n.push(d.subscribe((()=>{null!=this._renderFrameSubscription&&(this._renderFrameSubscription.unsubscribe(),this._renderFrameSubscription=null,this._renderFrameSubscribe())}))),n.push(d.pipe(De((()=>e=>(e.needsRender=!0,e)))).subscribe(this._eraserOperation$))}get render$(){return this._render$}get opaqueRender$(){return this._opaqueRender$}get webGLRenderer$(){return this._webGLRenderer$}clear(e){this._clear$.next(e)}remove(){this._rendererOperation$.next((e=>{if(null!=e.renderer){const t=e.renderer.getContext().getExtension("WEBGL_lose_context");t&&t.loseContext(),e.renderer=null}return e})),null!=this._renderFrameSubscription&&this._renderFrameSubscription.unsubscribe(),this._subscriptions.unsubscribe()}triggerRerender(){this._renderService.renderCameraFrame$.pipe($t(1),St()).subscribe((()=>{this._triggerOperation$.next((e=>(e.needsRender=!0,e)))}))}_renderFrameSubscribe(){this._render$.pipe(St(),De((()=>e=>(e.needsRender=!0,e)))).subscribe((e=>{this._renderCameraOperation$.next(e)})),this._renderFrameSubscription=this._render$.pipe(St(),We((()=>this._renderService.renderCameraFrame$))).subscribe(this._renderFrame$)}}class Nw{constructor(e){null!=e?(this._position=(new Ki).fromArray(e.unprojectSfM([0,0],0)),this._lookat=(new Ki).fromArray(e.unprojectSfM([0,0],10)),this._up=e.upVector(),this._focal=this._getFocal(e)):(this._position=new Ki(0,0,0),this._lookat=new Ki(1,0,0),this._up=new Ki(0,0,1),this._focal=1)}get position(){return this._position}get lookat(){return this._lookat}get up(){return this._up}get focal(){return this._focal}set focal(e){this._focal=e}lerpCameras(e,t,i){this._position.subVectors(t.position,e.position).multiplyScalar(i).add(e.position),this._lookat.subVectors(t.lookat,e.lookat).multiplyScalar(i).add(e.lookat),this._up.subVectors(t.up,e.up).multiplyScalar(i).add(e.up),this._focal=(1-i)*e.focal+i*t.focal}copy(e){this._position.copy(e.position),this._lookat.copy(e.lookat),this._up.copy(e.up),this._focal=e.focal}clone(){let e=new Nw;return e.position.copy(this._position),e.lookat.copy(this._lookat),e.up.copy(this._up),e.focal=this._focal,e}diff(e){let t=this._position.distanceToSquared(e.position),i=this._lookat.distanceToSquared(e.lookat),n=this._up.distanceToSquared(e.up),r=100*Math.abs(this._focal-e.focal);return Math.max(t,i,n,r)}_getFocal(e){return $u(e.cameraType)?.5/Math.tan(Math.PI/2):e.focal}}class $w{constructor(e,t,i){this._spatial=new Du,this._viewportCoords=new hf,this._size={width:e,height:t},this._initialFov=60,this._alpha=-1,this._stateTransitionAlpha=-1,this._stateTransitionFov=-1,this._renderMode=i,this._zoom=0,this._frameId=-1,this._changed=!1,this._changedForFrame=-1,this._currentImageId=null,this._previousImageId=null,this._currentSpherical=!1,this._previousSpherical=!1,this._state=null,this._currentProjectedPoints=[],this._previousProjectedPoints=[],this._currentFov=this._initialFov,this._previousFov=this._initialFov,this._camera=new Nw,this._perspective=new hs(this._initialFov,this._computeAspect(e,t),.1,1e4),this._perspective.position.copy(this._camera.position),this._perspective.up.copy(this._camera.up),this._perspective.lookAt(this._camera.lookat),this._perspective.updateMatrixWorld(!0),this._perspective.matrixAutoUpdate=!1,this._rotation={phi:0,theta:0}}get alpha(){return this._alpha}get camera(){return this._camera}get changed(){return this._frameId===this._changedForFrame}get frameId(){return this._frameId}get perspective(){return this._perspective}get renderMode(){return this._renderMode}get rotation(){return this._rotation}get zoom(){return this._zoom}get size(){return this._size}getTilt(){return 90-this._spatial.radToDeg(this._rotation.theta)}fovToZoom(e){e=Math.min(90,Math.max(0,e));const t=this._computeCurrentFov(0),i=1===this._alpha?t:this._interpolateFov(t,this._computePreviousFov(0),this._alpha),n=Math.tan(i/2*Math.PI/180),r=Math.tan(e/2*Math.PI/180);return Math.log(n/r)/Math.log(2)}setFrame(e){const t=e.state;if(t.state!==this._state){if(this._state=t.state,this._state!==Df.Custom&&(this.setRenderMode(this._renderMode),this.setSize(this._size)),this._state===Df.Earth){const e=this._fovToY(this._perspective.fov,this._zoom);this._stateTransitionFov=this._yToFov(e,0)}this._changed=!0}const i=t.currentImage.id,n=t.previousImage?t.previousImage.id:null;i!==this._currentImageId&&(this._currentImageId=i,this._currentSpherical=$u(t.currentTransform.cameraType),this._currentProjectedPoints=this._computeProjectedPoints(t.currentTransform),this._changed=!0),n!==this._previousImageId&&(this._previousImageId=n,this._previousSpherical=$u(t.previousTransform.cameraType),this._previousProjectedPoints=this._computeProjectedPoints(t.previousTransform),this._changed=!0);const r=t.zoom;r!==this._zoom&&(this._changed=!0),this._changed&&(this._currentFov=this._computeCurrentFov(r),this._previousFov=this._computePreviousFov(r));const s=t.alpha,a=t.stateTransitionAlpha;if(this._changed||s!==this._alpha||a!==this._stateTransitionAlpha){switch(this._alpha=s,this._stateTransitionAlpha=a,this._state){case Df.Earth:{const e=this._stateTransitionFov,i=this._focalToFov(t.camera.focal),n=Oi.lerp(e,i,a),s=this._fovToY(n,0);this._perspective.fov=this._yToFov(s,r);break}case Df.Custom:break;default:this._perspective.fov=this._interpolateFov(this._currentFov,this._previousFov,this._alpha),this._changed=!0}this._zoom=r,this._state!==Df.Custom&&this._perspective.updateProjectionMatrix()}const o=t.camera;this._camera.diff(o)>1e-9&&(this._camera.copy(o),this._rotation=this._computeRotation(o),this._perspective.up.copy(o.up),this._perspective.position.copy(o.position),this._perspective.matrixAutoUpdate=!0,this._perspective.lookAt(o.lookat),this._perspective.matrixAutoUpdate=!1,this._perspective.updateMatrix(),this._perspective.updateMatrixWorld(!1),this._changed=!0),this._setFrameId(e.id)}setProjectionMatrix(e){this._perspective.fov=this._focalToFov(e[5]/2),this._perspective.projectionMatrix.fromArray(e),this._perspective.projectionMatrixInverse.copy(this._perspective.projectionMatrix).invert(),this._changed=!0}setRenderMode(e){this._renderMode=e,this._state!==Df.Custom&&(this._perspective.fov=this._computeFov(),this._perspective.updateProjectionMatrix(),this._changed=!0)}setSize(e){this._size=e,this._state!==Df.Custom&&(this._perspective.aspect=this._computeAspect(e.width,e.height),this._perspective.fov=this._computeFov(),this._perspective.updateProjectionMatrix(),this._changed=!0)}_computeAspect(e,t){return 0===e?0:e/t}_computeCurrentFov(e){return 0===this._perspective.aspect?0:this._currentImageId?this._currentSpherical?this._yToFov(1,e):this._computeVerticalFov(this._currentProjectedPoints,this._renderMode,e,this.perspective.aspect):this._initialFov}_computeFov(){return this._currentFov=this._computeCurrentFov(this._zoom),this._previousFov=this._computePreviousFov(this._zoom),this._interpolateFov(this._currentFov,this._previousFov,this._alpha)}_computePreviousFov(e){return 0===this._perspective.aspect?0:this._currentImageId?this._previousImageId?this._previousSpherical?this._yToFov(1,e):this._computeVerticalFov(this._previousProjectedPoints,this._renderMode,e,this.perspective.aspect):this._currentFov:this._initialFov}_computeProjectedPoints(e){return zu(e,[[.5,0],[1,0]],[[.5,0],[0,.5]],100,this._viewportCoords)}_computeRequiredVerticalFov(e,t,i){const n=Math.max(e[0]/i,e[1]);return this._yToFov(n,t)}_computeRotation(e){let t=e.lookat.clone().sub(e.position),i=e.up.clone();return{phi:this._spatial.azimuthal(t.toArray(),i.toArray()),theta:Math.PI/2-this._spatial.angleToPlane(t.toArray(),[0,0,1])}}_computeVerticalFov(t,i,n,r){const s=t.map((e=>this._computeRequiredVerticalFov(e,n,r)));return i===e.RenderMode.Fill?.995*Math.min(...s):Math.max(...s)}_yToFov(e,t){return 2*Math.atan(e/Math.pow(2,t))*180/Math.PI}_focalToFov(e){return 2*Math.atan2(1,2*e)*180/Math.PI}_fovToY(e,t){return Math.pow(2,t)*Math.tan(Math.PI*e/360)}_interpolateFov(e,t,i){return i*e+(1-i)*t}_setFrameId(e){this._frameId=e,this._changed&&(this._changed=!1,this._changedForFrame=e)}}class kw{constructor(t,i,n,r){this._subscriptions=new rf,this._element=t,this._currentFrame$=i,this._spatial=new Du,n=null!=n?n:e.RenderMode.Fill,this._resize$=new j,this._projectionMatrix$=new j,this._renderCameraOperation$=new j,this._size$=new W({height:this._element.offsetHeight,width:this._element.offsetWidth});const s=this._subscriptions;s.push(this._resize$.pipe(De((()=>({height:this._element.offsetHeight,width:this._element.offsetWidth})))).subscribe(this._size$)),this._renderMode$=new W(n),this._renderCameraHolder$=this._renderCameraOperation$.pipe(Ot((e=>e)),Lt(((e,t)=>t(e)),null!=r?r:new $w(this._element.offsetWidth,this._element.offsetHeight,n)),Rt(1),U()),this._renderCameraFrame$=this._currentFrame$.pipe(Vt(this._renderCameraHolder$),Ut((([e,t])=>{t.setFrame(e)})),De((e=>e[1])),Rt(1),U()),this._renderCamera$=this._renderCameraFrame$.pipe(st((e=>e.changed)),Rt(1),U()),this._bearing$=this._renderCamera$.pipe(De((e=>{let t=this._spatial.radToDeg(this._spatial.azimuthalToBearing(e.rotation.phi));return this._spatial.wrap(t,0,360)})),Rt(1),U()),s.push(this._size$.pipe($t(1),De((e=>t=>(t.setSize(e),t)))).subscribe(this._renderCameraOperation$)),s.push(this._renderMode$.pipe($t(1),De((e=>t=>(t.setRenderMode(e),t)))).subscribe(this._renderCameraOperation$)),s.push(this._projectionMatrix$.pipe(De((e=>t=>(t.setProjectionMatrix(e),t)))).subscribe(this._renderCameraOperation$)),s.push(this._bearing$.subscribe((()=>{}))),s.push(this._renderCameraHolder$.subscribe((()=>{}))),s.push(this._size$.subscribe((()=>{}))),s.push(this._renderMode$.subscribe((()=>{}))),s.push(this._renderCamera$.subscribe((()=>{}))),s.push(this._renderCameraFrame$.subscribe((()=>{})))}get bearing$(){return this._bearing$}get element(){return this._element}get projectionMatrix$(){return this._projectionMatrix$}get renderCamera$(){return this._renderCamera$}get renderCameraFrame$(){return this._renderCameraFrame$}get renderMode$(){return this._renderMode$}get resize$(){return this._resize$}get size$(){return this._size$}dispose(){this._subscriptions.unsubscribe()}}class Ow{constructor(e){this._keyDown$=Qe(e,"keydown"),this._keyUp$=Qe(e,"keyup")}get keyDown$(){return this._keyDown$}get keyUp$(){return this._keyUp$}}const zw={0:1,2:2};class Fw{constructor(e,t,i,n){this._subscriptions=new rf;const r=this._subscriptions;this._activeSubject$=new W(!1),this._active$=this._activeSubject$.pipe(vt(),Rt(1),U()),this._claimMouse$=new j,this._claimWheel$=new j,this._deferPixelClaims$=new j,this._deferPixels$=this._deferPixelClaims$.pipe(Lt(((e,t)=>(null==t.deferPixels?delete e[t.name]:e[t.name]=t.deferPixels,e)),{}),De((e=>{let t=-1;for(const i in e){if(!e.hasOwnProperty(i))continue;const n=e[i];n>t&&(t=n)}return t})),Ot(-1),Rt(1),U()),r.push(this._deferPixels$.subscribe((()=>{}))),this._documentMouseMove$=Qe(n,"pointermove").pipe(st(this._isMousePen)),this._documentMouseUp$=Qe(n,"pointerup").pipe(st(this._isMousePen)),this._mouseDown$=Qe(t,"pointerdown").pipe(st(this._isMousePen)),this._mouseEnter$=Qe(t,"pointerenter").pipe(st(this._isMousePen)),this._mouseLeave$=Qe(t,"pointerleave").pipe(st(this._isMousePen)),this._mouseMove$=Qe(t,"pointermove").pipe(st(this._isMousePen)),this._mouseUp$=Qe(t,"pointerup").pipe(st(this._isMousePen)),this._mouseOut$=Qe(t,"pointerout").pipe(st(this._isMousePen)),this._mouseOver$=Qe(t,"pointerover").pipe(st(this._isMousePen)),this._domMouseDown$=Qe(i,"pointerdown").pipe(st(this._isMousePen)),this._domMouseMove$=Qe(i,"pointermove").pipe(st(this._isMousePen)),this._click$=Qe(t,"click"),this._contextMenu$=Qe(t,"contextmenu"),this._windowBlur$=Qe(window,"blur"),this._dblClick$=it(Qe(e,"click"),Qe(t,"dblclick")).pipe(ht(3,1),st((e=>{const i=e[0],n=e[1],r=e[2];return"click"===i.type&&"click"===n.type&&"dblclick"===r.type&&i.target.parentNode===t&&n.target.parentNode===t})),De((e=>e[2])),Dt()),r.push(it(this._domMouseDown$,this._domMouseMove$,this._dblClick$,this._contextMenu$).subscribe((e=>{e.preventDefault()}))),this._mouseWheel$=it(Qe(t,"wheel"),Qe(i,"wheel")).pipe(Dt()),this._consistentContextMenu$=it(this._mouseDown$,this._mouseMove$,this._mouseOut$,this._mouseUp$,this._contextMenu$).pipe(ht(3,1),st((e=>"pointerdown"===e[0].type&&"contextmenu"===e[1].type&&"pointerup"===e[2].type)),De((e=>e[1])),Dt());const s=it(this._windowBlur$,this._documentMouseMove$.pipe(st((e=>this._buttonReleased(e,0)))),this._documentMouseUp$.pipe(st((e=>0===this._mouseButton(e))))).pipe(Dt()),a=this._createMouseDragInitiate$(0,this._mouseDown$,s,!0).pipe(Dt());this._mouseDragStart$=this._createMouseDragStart$(a).pipe(Dt()),this._mouseDrag$=this._createMouseDrag$(a,s).pipe(Dt()),this._mouseDragEnd$=this._createMouseDragEnd$(this._mouseDragStart$,s).pipe(Dt());const o=this._createMouseDragInitiate$(0,this._domMouseDown$,s,!1).pipe(Dt());this._domMouseDragStart$=this._createMouseDragStart$(o).pipe(Dt()),this._domMouseDrag$=this._createMouseDrag$(o,s).pipe(Dt()),this._domMouseDragEnd$=this._createMouseDragEnd$(this._domMouseDragStart$,s).pipe(Dt());const h=it(this._windowBlur$,this._documentMouseMove$.pipe(st((e=>this._buttonReleased(e,2)))),this._documentMouseUp$.pipe(st((e=>2===this._mouseButton(e))))).pipe(Dt()),c=this._createMouseDragInitiate$(2,this._mouseDown$,h,!0).pipe(Dt());this._mouseRightDragStart$=this._createMouseDragStart$(c).pipe(Dt()),this._mouseRightDrag$=this._createMouseDrag$(c,h).pipe(Dt()),this._mouseRightDragEnd$=this._createMouseDragEnd$(this._mouseRightDragStart$,h).pipe(Dt()),this._proximateClick$=this._mouseDown$.pipe(zt((e=>this._click$.pipe(Ft(this._createDeferredMouseMove$(e,this._documentMouseMove$)),_t(1)))),Dt()),this._staticClick$=this._mouseDown$.pipe(zt((()=>this._click$.pipe(Ft(this._documentMouseMove$),_t(1)))),Dt()),r.push(this._mouseDragStart$.subscribe()),r.push(this._mouseDrag$.subscribe()),r.push(this._mouseDragEnd$.subscribe()),r.push(this._domMouseDragStart$.subscribe()),r.push(this._domMouseDrag$.subscribe()),r.push(this._domMouseDragEnd$.subscribe()),r.push(this._mouseRightDragStart$.subscribe()),r.push(this._mouseRightDrag$.subscribe()),r.push(this._mouseRightDragEnd$.subscribe()),r.push(this._staticClick$.subscribe()),this._mouseOwner$=this._createOwner$(this._claimMouse$).pipe(Rt(1),U()),this._wheelOwner$=this._createOwner$(this._claimWheel$).pipe(Rt(1),U()),r.push(this._mouseOwner$.subscribe((()=>{}))),r.push(this._wheelOwner$.subscribe((()=>{})))}get active$(){return this._active$}get activate$(){return this._activeSubject$}get documentMouseMove$(){return this._documentMouseMove$}get documentMouseUp$(){return this._documentMouseUp$}get domMouseDragStart$(){return this._domMouseDragStart$}get domMouseDrag$(){return this._domMouseDrag$}get domMouseDragEnd$(){return this._domMouseDragEnd$}get domMouseDown$(){return this._domMouseDown$}get domMouseMove$(){return this._domMouseMove$}get mouseOwner$(){return this._mouseOwner$}get mouseDown$(){return this._mouseDown$}get mouseEnter$(){return this._mouseEnter$}get mouseMove$(){return this._mouseMove$}get mouseLeave$(){return this._mouseLeave$}get mouseOut$(){return this._mouseOut$}get mouseOver$(){return this._mouseOver$}get mouseUp$(){return this._mouseUp$}get click$(){return this._click$}get dblClick$(){return this._dblClick$}get contextMenu$(){return this._consistentContextMenu$}get mouseWheel$(){return this._mouseWheel$}get mouseDragStart$(){return this._mouseDragStart$}get mouseDrag$(){return this._mouseDrag$}get mouseDragEnd$(){return this._mouseDragEnd$}get mouseRightDragStart$(){return this._mouseRightDragStart$}get mouseRightDrag$(){return this._mouseRightDrag$}get mouseRightDragEnd$(){return this._mouseRightDragEnd$}get proximateClick$(){return this._proximateClick$}get staticClick$(){return this._staticClick$}get windowBlur$(){return this._windowBlur$}dispose(){this._subscriptions.unsubscribe()}claimMouse(e,t){this._claimMouse$.next({name:e,zindex:t})}unclaimMouse(e){this._claimMouse$.next({name:e,zindex:null})}deferPixels(e,t){this._deferPixelClaims$.next({name:e,deferPixels:t})}undeferPixels(e){this._deferPixelClaims$.next({name:e,deferPixels:null})}claimWheel(e,t){this._claimWheel$.next({name:e,zindex:t})}unclaimWheel(e){this._claimWheel$.next({name:e,zindex:null})}filtered$(e,t){return this._filtered(e,t,this._mouseOwner$)}filteredWheel$(e,t){return this._filtered(e,t,this._wheelOwner$)}_createDeferredMouseMove$(e,t){return t.pipe(De((t=>{const i=t.clientX-e.clientX,n=t.clientY-e.clientY;return[t,Math.sqrt(i*i+n*n)]})),Vt(this._deferPixels$),st((([[,e],t])=>e>t)),De((([[e]])=>e)))}_createMouseDrag$(e,t){return e.pipe(De((([,e])=>e)),zt((e=>Ze(Ce(e),this._documentMouseMove$).pipe(Ft(t)))))}_createMouseDragEnd$(e,t){return e.pipe(zt((()=>t.pipe(St()))))}_createMouseDragStart$(e){return e.pipe(De((([e])=>e)))}_createMouseDragInitiate$(e,t,i,n){return t.pipe(st((t=>this._mouseButton(t)===e)),zt((e=>Ve(Ce(e),n?this._createDeferredMouseMove$(e,this._documentMouseMove$):this._documentMouseMove$).pipe(Ft(i),_t(1)))))}_createOwner$(e){return e.pipe(Lt(((e,t)=>(null==t.zindex?delete e[t.name]:e[t.name]=t.zindex,e)),{}),De((e=>{let t=null,i=-1;for(const n in e)e.hasOwnProperty(n)&&e[n]>i&&(i=e[n],t=n);return t})),Ot(null))}_filtered(e,t,i){return t.pipe(Vt(i),st((([,t])=>t===e)),De((([e])=>e)))}_mouseButton(e){const t="pointerdown"===e.type||"pointerup"===e.type,i=window.InstallTrigger;return t&&void 0!==i&&2===e.button&&e.ctrlKey&&window.navigator.platform.toUpperCase().indexOf("MAC")>=0?0:e.button}_buttonReleased(e,t){const i=zw[t];return void 0===e.buttons||(e.buttons&i)!==i}_isMousePen(e){const t=e.pointerType;return"mouse"===t||"pen"===t}}class Bw{set json(e){this._json=e}set image(e){this._image=e,this._texture=new Wi(this._image),this._texture.minFilter=Jt}get loaded(){return!(!this._image||!this._json)}getGLSprite(e){if(!this.loaded)throw new Error("Sprites cannot be retrieved before the atlas is loaded.");let t=this._json[e];if(!t)return console.warn("Sprite with key"+e+"does not exist in sprite definition."),new tr;let i=this._texture.clone();i.needsUpdate=!0;let n=this._image.width,r=this._image.height;i.offset.x=t.x/n,i.offset.y=(r-t.y-t.height)/r,i.repeat.x=t.width/n,i.repeat.y=t.height/r;let s=new ph({map:i});return new Eh(s)}getDOMSprite(t,i){if(!this.loaded)throw new Error("Sprites cannot be retrieved before the atlas is loaded.");null==i&&(i=e.Alignment.Center);let n=this._json[t];if(!n)return console.warn("Sprite with key"+t+"does not exist in sprite definition."),tf.h("div",{},[]);let r=n.y,s=n.x+n.width,a=n.y+n.height,o=n.x,h=-n.x,c=-n.y,l=this._image.height,u=this._image.width;switch(i){case e.Alignment.Bottom:case e.Alignment.Center:case e.Alignment.Top:h-=n.width/2;break;case e.Alignment.BottomLeft:case e.Alignment.Left:case e.Alignment.TopLeft:h-=n.width;break;case e.Alignment.BottomRight:case e.Alignment.Right:case e.Alignment.TopRight:}switch(i){case e.Alignment.Center:case e.Alignment.Left:case e.Alignment.Right:c-=n.height/2;break;case e.Alignment.Top:case e.Alignment.TopLeft:case e.Alignment.TopRight:c-=n.height;break;case e.Alignment.Bottom:case e.Alignment.BottomLeft:case e.Alignment.BottomRight:}let d=1/n.pixelRatio;r*=d,s*=d,a*=d,o*=d,h*=d,c*=d,l*=d,u*=d;let p={src:this._image.src,style:{clip:`rect(${r}px, ${s}px, ${a}px, ${o}px)`,height:`${l}px`,left:`${h}px`,position:"absolute",top:`${c}px`,width:`${u}px`}};return tf.h("img",p,[])}}class Uw{constructor(e){if(this._retina=window.devicePixelRatio>1,this._spriteAtlasOperation$=new j,this._spriteAtlas$=this._spriteAtlasOperation$.pipe(Ot((e=>e)),Lt(((e,t)=>t(e)),new Bw),Rt(1),U()),this._atlasSubscription=this._spriteAtlas$.subscribe((()=>{})),null==e)return;let t=this._retina?"@2x":"",i=new XMLHttpRequest;i.open("GET",e+t+".png",!0),i.responseType="arraybuffer",i.onload=()=>{let e=new Image;e.onload=()=>{this._spriteAtlasOperation$.next((t=>(t.image=e,t)))};let t=new Blob([i.response]);e.src=window.URL.createObjectURL(t)},i.onerror=i=>{console.error(new Error(`Failed to fetch sprite sheet (${e}${t}.png)`))},i.send();let n=new XMLHttpRequest;n.open("GET",e+t+".json",!0),n.responseType="text",n.onload=()=>{let e=JSON.parse(n.response);this._spriteAtlasOperation$.next((t=>(t.json=e,t)))},n.onerror=i=>{console.error(new Error(`Failed to fetch sheet (${e}${t}.json)`))},n.send()}get spriteAtlas$(){return this._spriteAtlas$}dispose(){this._atlasSubscription.unsubscribe()}}class Vw{constructor(e,t){this._subscriptions=new rf;const i=this._subscriptions;this._activeSubject$=new W(!1),this._active$=this._activeSubject$.pipe(vt(),Rt(1),U()),i.push(Qe(t,"touchmove").subscribe((e=>{e.preventDefault()}))),this._touchStart$=Qe(e,"touchstart"),this._touchMove$=Qe(e,"touchmove"),this._touchEnd$=Qe(e,"touchend"),this._touchCancel$=Qe(e,"touchcancel");const n=this._touchStart$.pipe(st((e=>1===e.touches.length&&1===e.targetTouches.length)),Dt());var r;this._doubleTap$=n.pipe((r=()=>n.pipe(St(),zt((()=>it(tt(300),n).pipe(_t(1))))),F((function(e,t){var i=null,n=null,s=function(){null==n||n.unsubscribe();var e=i;i=[],e&&t.next(e),_e(r()).subscribe(n=new B(t,s,w))};s(),e.subscribe(new B(t,(function(e){return null==i?void 0:i.push(e)}),(function(){i&&t.next(i),t.complete()}),void 0,(function(){return i=n=null})))}))),st((e=>2===e.length)),De((e=>e[e.length-1])),Dt()),i.push(this._doubleTap$.subscribe((e=>{e.preventDefault()}))),this._singleTouchMove$=this._touchMove$.pipe(st((e=>1===e.touches.length&&1===e.targetTouches.length)),Dt());let s=it(this._touchStart$,this._touchEnd$,this._touchCancel$).pipe(st((e=>1===e.touches.length&&1===e.targetTouches.length))),a=it(this._touchStart$,this._touchEnd$,this._touchCancel$).pipe(st((e=>e.touches.length>=1))),o=it(this._touchEnd$,this._touchCancel$).pipe(st((e=>0===e.touches.length)));this._singleTouchDragStart$=s.pipe(We((()=>this._singleTouchMove$.pipe(Ft(it(o,a)),_t(1))))),this._singleTouchDragEnd$=s.pipe(We((()=>it(o,a).pipe(St())))),this._singleTouchDrag$=s.pipe(zt((()=>this._singleTouchMove$.pipe($t(1),Ft(it(a,o))))));let h=it(this._touchStart$,this._touchEnd$,this._touchCancel$);this._pinchStart$=h.pipe(st((e=>2===e.touches.length&&2===e.targetTouches.length))),this._pinchEnd$=h.pipe(st((e=>2!==e.touches.length||2!==e.targetTouches.length))),this._pinchOperation$=new j,this._pinch$=this._pinchOperation$.pipe(Lt(((e,t)=>t(e)),{changeX:0,changeY:0,clientX:0,clientY:0,distance:0,distanceChange:0,distanceX:0,distanceY:0,originalEvent:null,pageX:0,pageY:0,screenX:0,screenY:0,touch1:null,touch2:null}));const c=this._touchMove$.pipe(st((e=>2===e.touches.length&&2===e.targetTouches.length)),De((e=>t=>{let i=e.touches[0],n=e.touches[1],r=Math.min(i.clientX,n.clientX),s=Math.max(i.clientX,n.clientX),a=Math.min(i.clientY,n.clientY),o=r+(s-r)/2,h=a+(Math.max(i.clientY,n.clientY)-a)/2,c=o+i.pageX-i.clientX,l=h+i.pageY-i.clientY,u=o+i.screenX-i.clientX,d=h+i.screenY-i.clientY,p=Math.abs(i.clientX-n.clientX),m=Math.abs(i.clientY-n.clientY),f=Math.sqrt(p*p+m*m),g=f-t.distance;return{changeX:p-t.distanceX,changeY:m-t.distanceY,clientX:o,clientY:h,distance:f,distanceChange:g,distanceX:p,distanceY:m,originalEvent:e,pageX:c,pageY:l,screenX:u,screenY:d,touch1:i,touch2:n}}))).subscribe(this._pinchOperation$);i.push(c),this._pinchChange$=this._pinchStart$.pipe(zt((()=>this._pinch$.pipe($t(1),Ft(this._pinchEnd$)))))}get active$(){return this._active$}get activate$(){return this._activeSubject$}get doubleTap$(){return this._doubleTap$}get touchStart$(){return this._touchStart$}get touchMove$(){return this._touchMove$}get touchEnd$(){return this._touchEnd$}get touchCancel$(){return this._touchCancel$}get singleTouchDragStart$(){return this._singleTouchDragStart$}get singleTouchDrag$(){return this._singleTouchDrag$}get singleTouchDragEnd$(){return this._singleTouchDragEnd$}get pinch$(){return this._pinchChange$}get pinchStart$(){return this._pinchStart$}get pinchEnd$(){return this._pinchEnd$}dispose(){this._subscriptions.unsubscribe()}}class Hw{constructor(e){var t,i,n,r;const s=null!==(i=null===(t=null==e?void 0:e.url)||void 0===t?void 0:t.exploreHost)&&void 0!==i?i:"www.mapillary.com",a=`${null!==(r=null===(n=null==e?void 0:e.url)||void 0===n?void 0:n.scheme)&&void 0!==r?r:"https"}://${s}`;this._exploreUrl$=Ce(a);const o=!1!==(null==e?void 0:e.imageTiling);this._imageTiling$=Ce(o)}get exploreUrl$(){return this._exploreUrl$}get imageTiling$(){return this._imageTiling$}}class jw{constructor(e,t,i){var n;if(this._onWindowResize=()=>{this._trackResize&&this.renderService.resize$.next()},this._dom=null!=i?i:new og,"string"==typeof e.container){if(this._container=this._dom.document.getElementById(e.container),!this._container)throw new Error(`Container "${e.container}" not found.`)}else{if(!(e.container instanceof HTMLElement))throw new Error('Invalid type: "container" must be a String or HTMLElement.');this._container=e.container}this._trackResize=!1!==e.trackResize,this.id=null!==(n=this._container.id)&&void 0!==n?n:"mapillary-fallback-container-id",this._container.classList.add("mapillary-viewer"),this._canvasContainer=this._dom.createElement("div","mapillary-interactive",this._container),this._canvas=this._dom.createElement("canvas","mapillary-canvas"),this._canvas.style.position="absolute",this._canvas.setAttribute("tabindex","0"),this._domContainer=this._dom.createElement("div","mapillary-dom",this._container),this.configurationService=new Hw(e),this.renderService=new kw(this._container,t.currentState$,e.renderMode),this.glRenderer=new Dw(this._canvas,this._canvasContainer,this.renderService),this.domRenderer=new Lw(this._domContainer,this.renderService,t.currentState$),this.keyboardService=new Ow(this._canvasContainer),this.mouseService=new Fw(this._container,this._canvasContainer,this._domContainer,document),this.touchService=new Vw(this._canvasContainer,this._domContainer),this.spriteService=new Uw(e.sprite),window.addEventListener("resize",this._onWindowResize,!1)}get canvas(){return this._canvas.parentNode?this._canvas:null}get canvasContainer(){return this._canvasContainer}get container(){return this._container}get domContainer(){return this._domContainer}remove(){window.removeEventListener("resize",this._onWindowResize,!1),this.spriteService.dispose(),this.touchService.dispose(),this.mouseService.dispose(),this.glRenderer.remove(),this.domRenderer.remove(),this.renderService.dispose(),this._removeNode(this._canvasContainer),this._removeNode(this._domContainer),this._container.classList.remove("mapillary-viewer")}_removeNode(e){e.parentNode&&e.parentNode.removeChild(e)}}class Gw{constructor(e,t,i){this._graphService=e,this._stateService=t,this._api=i,this._subscriptions=new rf,this._started=!1,this._cellDepth=1}get started(){return this._started}configure(e){this._cellDepth=e?Math.max(1,Math.min(3,e.cellDepth)):1}start(){if(this._started)return;const e=this._subscriptions;e.push(this._stateService.currentState$.pipe(vt(void 0,(e=>e.state.currentImage.id)),De((e=>{const t=e.state,i=t.trajectory,n=i.map((e=>e.id)),r=i[i.length-1].sequenceId;return[n,t.currentImage.originalLngLat,r]})),ht(1,5),Vt(this._graphService.graphMode$),zt((([e,t])=>{const i=e[0][0],n=e[0][1],r=this._api.data.geometry,s=kg(r.lngLatToCellId(n),this._cellDepth,r),a=t===Nf.Sequence?e[0][2]:void 0;return this._graphService.uncache$(i,s,a)}))).subscribe((()=>{}))),e.push(this._graphService.graphMode$.pipe($t(1),Vt(this._stateService.currentState$),zt((([e,t])=>e===Nf.Sequence?this._keyToEdges(t.state.currentImage.id,(e=>e.sequenceEdges$)):ge(t.state.trajectory.map((e=>e.id)).slice(t.state.currentIndex)).pipe(We((e=>this._keyToEdges(e,(e=>e.spatialEdges$))),6))))).subscribe((()=>{}))),e.push(this._graphService.dataAdded$.pipe(Vt(this._stateService.currentId$),zt((([e,t])=>this._graphService.cacheImage$(t)))).subscribe((()=>{}))),this._started=!0}stop(){this._started&&(this._subscriptions.unsubscribe(),this._started=!1)}_keyToEdges(e,t){return this._graphService.cacheImage$(e).pipe(zt(t),St((e=>e.cached)),Pe(15e3),ct((t=>(console.error(`Failed to cache edges (${e}).`,t),ie()))))}}class Ww{constructor(){this._loadersSubject$=new j,this._loaders$=this._loadersSubject$.pipe(Lt(((e,t)=>(void 0!==t.task&&(e[t.task]=t.loading),e)),{}),Ot({}),Rt(1),U())}get loading$(){return this._loaders$.pipe(De((e=>{for(const t in e)if(e.hasOwnProperty(t)&&e[t])return!0;return!1})),ft(100),vt())}taskLoading$(e){return this._loaders$.pipe(De((t=>!!t[e])),ft(100),vt())}startLoading(e){this._loadersSubject$.next({loading:!0,task:e})}stopLoading(e){this._loadersSubject$.next({loading:!1,task:e})}}var qw;!function(e){e[e.Disabled=0]="Disabled",e[e.Enabled=1]="Enabled",e[e.Started=2]="Started"}(qw||(qw={}));class Xw{constructor(e,t,i,n,r,s){this._subscriptions=new rf,this._graphService=e,this._stateService=t,this._graphCalculator=null!=n?n:new Mu,this._spatial=null!=r?r:new Du,this._viewportCoords=null!=s?s:new hf,this._mode=!1!==i?qw.Enabled:qw.Disabled,this._panImagesSubject$=new j,this._panImages$=this._panImagesSubject$.pipe(Ot([]),Rt(1),U()),this._subscriptions.push(this._panImages$.subscribe())}get panImages$(){return this._panImages$}dispose(){this.stop(),null!=this._panImagesSubscription&&this._panImagesSubscription.unsubscribe(),this._subscriptions.unsubscribe()}enable(){this._mode===qw.Disabled&&(this._mode=qw.Enabled,this.start())}disable(){this._mode!==qw.Disabled&&(this.stop(),this._mode=qw.Disabled)}start(){if(this._mode!==qw.Enabled)return;const e=this._stateService.currentImage$.pipe(zt((e=>{if(!e.merged||$u(e.cameraType))return Ce([]);const t=Ce(e),i=this._graphCalculator.boundingBoxCorners(e.lngLat,20);return Ve(t,this._graphService.cacheBoundingBox$(i[0],i[1]).pipe(ct((t=>(console.error(`Failed to cache periphery bounding box (${e.id})`,t),ie()))),De((t=>{if($u(e.cameraType))return[];const i=[];for(const n of t)n.id!==e.id&&n.mergeId===e.mergeId&&($u(n.cameraType)||this._distance(n,e)>4||i.push(n));return i})))).pipe(Vt(this._stateService.reference$),De((([[e,t],i])=>{const n=this._spatial.viewingDirection(e.rotation),r=Ou({lat:e.lngLat.lat,lng:e.lngLat.lng,alt:e.computedAltitude},e.rotation,i),s=this._createTransform(e,r),a=this._spatial.wrap(this._spatial.azimuthal(n.toArray(),s.upVector().toArray()),0,2*Math.PI),o=this._computeProjectedPoints(s),h=this._computeHorizontalFov(o)/180*Math.PI,c=Math.PI/8;let l,u;for(const r of t){const t=Ou({lat:r.lngLat.lat,lng:r.lngLat.lng,alt:r.computedAltitude},r.rotation,i),s=this._createTransform(r,t),o=this._computeProjectedPoints(s),d=this._computeHorizontalFov(o)/180*Math.PI,p=this._spatial.viewingDirection(r.rotation),m=this._spatial.wrap(this._spatial.azimuthal(p.toArray(),s.upVector().toArray()),0,2*Math.PI),f=this._spatial.angleBetweenVector2(n.x,n.y,p.x,p.y);let g=Number.NEGATIVE_INFINITY;g=f>0?a>m?a-2*Math.PI+h/2-(m-d/2):a+h/2-(m-d/2):a<m?m+d/2-(a+2*Math.PI-h/2):m+d/2-(a-h/2);const _=Math.abs(d-g),v=this._distance(r,e)+Math.min(this._timeDifference(r,e),4)+20*Math.abs(g-c)+Math.min(5,1/Math.min(d/h,1))+(g>0?-2*_:0);g>0&&g<.5*h&&g<.5*d&&_>.5*h&&(f>0?l?v<l[0]&&(l=[v,r,s,d]):l=[v,r,s,d]:u?v<u[0]&&(u=[v,r,s,d]):u=[v,r,s,d])}const d=[];return l&&d.push([l[1],l[2],l[3]]),u&&d.push([u[1],u[2],u[3]]),d})),Ot([]))})));this._panImagesSubscription=this._stateService.currentState$.pipe(De((e=>e.state.imagesAhead>0)),vt(),zt((t=>t?Ce([]):e))).subscribe((e=>{this._panImagesSubject$.next(e)})),this._mode=qw.Started}stop(){this._mode===qw.Started&&(this._panImagesSubscription.unsubscribe(),this._panImagesSubject$.next([]),this._mode=qw.Enabled)}_distance(e,t){const[i,n,r]=_u(e.lngLat.lng,e.lngLat.lat,e.computedAltitude,t.lngLat.lng,t.lngLat.lat,t.computedAltitude);return Math.sqrt(i*i+n*n+r*r)}_timeDifference(e,t){return Math.abs(e.capturedAt-t.capturedAt)/2592e6}_createTransform(e,t){return new ug(e.exifOrientation,e.width,e.height,e.scale,e.rotation,t,e.assetsCached?e.image:void 0,void 0,e.cameraParameters,e.cameraType)}_computeProjectedPoints(e){return zu(e,[[1,0]],[[0,.5]],20,this._viewportCoords)}_computeHorizontalFov(e){const t=e.map((e=>this._coordToFov(e[0])));return Math.min(...t)}_coordToFov(e){return 2*Math.atan(e)*180/Math.PI}}class Zw{constructor(e){this._data=e}get data(){return this._data}getCoreImages$(e){return this._wrap$(this._data.getCoreImages(e))}getImages$(e){return this._wrap$(this._data.getImages(e))}getImageTiles$(e){return this._wrap$(this._data.getImageTiles(e))}getSequence$(e){return this._wrap$(this._data.getSequence(e))}getSpatialImages$(e){return this._wrap$(this._data.getSpatialImages(e))}setAccessToken(e){this._data.setAccessToken(e)}_wrap$(e){return k.create((t=>{e.then((e=>{t.next(e),t.complete()}),(e=>{t.error(e)}))}))}}class Yw{constructor(e){this._dataAdded$=new j,this._subscriptions=new rf,this._onDataAdded=e=>{this._graph$.pipe(St(),We((t=>t.updateCells$(e.cellIds).pipe(Ut((()=>{t.resetSpatialEdges()})))))).subscribe((e=>{this._dataAdded$.next(e)}))};const t=this._subscriptions;this._graph$=Ze(Ce(e),e.changed$).pipe(Rt(1),U()),t.push(this._graph$.subscribe((()=>{}))),this._graphMode=Nf.Spatial,this._graphModeSubject$=new j,this._graphMode$=this._graphModeSubject$.pipe(Ot(this._graphMode),Rt(1),U()),t.push(this._graphMode$.subscribe((()=>{}))),this._firstGraphSubjects$=[],this._initializeCacheSubscriptions=[],this._sequenceSubscriptions=[],this._spatialSubscriptions=[],e.api.data.on("datacreate",this._onDataAdded)}get dataAdded$(){return this._dataAdded$}get filter$(){return this._graph$.pipe(St(),We((e=>e.filter$)))}get graphMode$(){return this._graphMode$}cacheBoundingBox$(e,t){return this._graph$.pipe(St(),We((i=>i.cacheBoundingBox$(e,t))))}cacheCell$(e){return this._graph$.pipe(St(),We((t=>t.cacheCell$(e))))}cacheImage$(e){const t=new j;this._firstGraphSubjects$.push(t);const i=t.pipe(Rt(1),U()),n=i.pipe(De((t=>t.getNode(e))),We((e=>e.assetsCached?Ce(e):e.cacheAssets$())),Rt(1),U());let r;n.subscribe(void 0,(t=>{console.error(`Failed to cache image (${e}).`,t)})),r=this._graph$.pipe(St(),We((t=>t.isCachingFull(e)||!t.hasNode(e)?t.cacheFull$(e):t.isCachingFill(e)||!t.getNode(e).complete?t.cacheFill$(e):Ce(t))),Ut((t=>{if(!t.hasNode(e))throw new Bu(`Failed to cache image (${e})`);t.hasInitializedCache(e)||t.initializeCache(e)})),Mt((()=>{null!=r&&(this._removeFromArray(r,this._initializeCacheSubscriptions),this._removeFromArray(t,this._firstGraphSubjects$))}))).subscribe((e=>{t.next(e),t.complete()}),(e=>{t.error(e)})),r.closed||this._initializeCacheSubscriptions.push(r);const s=i.pipe(ct((()=>ie())),We((t=>t.isCachingNodeSequence(e)||!t.hasNodeSequence(e)?t.cacheNodeSequence$(e):Ce(t))),Rt(1),U());let a;if(a=s.pipe(Ut((t=>{t.getNode(e).sequenceEdges.cached||t.cacheSequenceEdges(e)})),Mt((()=>{null!=a&&this._removeFromArray(a,this._sequenceSubscriptions)}))).subscribe((()=>{}),(t=>{console.error(`Failed to cache sequence edges (${e}).`,t)})),a.closed||this._sequenceSubscriptions.push(a),this._graphMode===Nf.Spatial){let t;t=i.pipe(ct((()=>ie())),wt((t=>t.hasTiles(e)?ie():ge(t.cacheTiles$(e)).pipe(We((t=>t.pipe(We((t=>t.isCachingTiles(e)?ie():Ce(t))),ct((t=>(console.error(`Failed to cache tile data (${e}).`,t),ie()))))))))),Tt(1),We((t=>t.hasSpatialArea(e)?Ce(t):ge(t.cacheSpatialArea$(e)).pipe(We((t=>t.pipe(ct((t=>(console.error(`Failed to cache spatial images (${e}).`,t),ie()))))))))),Tt(1),We((t=>t.hasNodeSequence(e)?Ce(t):t.cacheNodeSequence$(e))),Ut((t=>{t.getNode(e).spatialEdges.cached||t.cacheSpatialEdges(e)})),Mt((()=>{null!=t&&this._removeFromArray(t,this._spatialSubscriptions)}))).subscribe((()=>{}),(t=>{const i=`Failed to cache spatial edges (${e}).`;console.error(i,t)})),t.closed||this._spatialSubscriptions.push(t)}return n.pipe(St((e=>e.assetsCached)))}cacheSequence$(e){return this._graph$.pipe(St(),We((t=>t.isCachingSequence(e)||!t.hasSequence(e)?t.cacheSequence$(e):Ce(t))),De((t=>t.getSequence(e))))}cacheSequenceImages$(e,t){return this._graph$.pipe(St(),We((t=>t.isCachingSequence(e)||!t.hasSequence(e)?t.cacheSequence$(e):Ce(t))),We((i=>i.isCachingSequenceNodes(e)||!i.hasSequenceNodes(e)?i.cacheSequenceNodes$(e,t):Ce(i))),De((t=>t.getSequence(e))))}dispose(){this._graph$.pipe(St()).subscribe((e=>{e.unsubscribe()})),this._subscriptions.unsubscribe()}setFilter$(e){return this._resetSubscriptions(this._spatialSubscriptions),this._graph$.pipe(St(),Ut((t=>{t.resetSpatialEdges(),t.setFilter(e)})),De((()=>{})))}setGraphMode(e){this._graphMode!==e&&(e===Nf.Sequence&&this._resetSubscriptions(this._spatialSubscriptions),this._graphMode=e,this._graphModeSubject$.next(this._graphMode))}reset$(e){return this._abortSubjects(this._firstGraphSubjects$),this._resetSubscriptions(this._initializeCacheSubscriptions),this._resetSubscriptions(this._sequenceSubscriptions),this._resetSubscriptions(this._spatialSubscriptions),this._graph$.pipe(St(),Ut((t=>{t.reset(e)})),De((()=>{})))}uncache$(e,t,i){return this._graph$.pipe(St(),Ut((n=>{n.uncache(e,t,i)})),De((()=>{})))}_abortSubjects(e){for(const t of e.slice())this._removeFromArray(t,e),t.error(new Error("Cache image request was aborted."))}_removeFromArray(e,t){const i=t.indexOf(e);-1!==i&&t.splice(i,1)}_resetSubscriptions(e){for(const t of e.slice())this._removeFromArray(t,e),t.closed||t.unsubscribe()}}class Jw{constructor(e){e.requestAnimationFrame?(this._cancelAnimationFrame=e.cancelAnimationFrame.bind(e),this._requestAnimationFrame=e.requestAnimationFrame.bind(e)):e.mozRequestAnimationFrame?(this._cancelAnimationFrame=e.mozCancelAnimationFrame.bind(e),this._requestAnimationFrame=e.mozRequestAnimationFrame.bind(e)):e.webkitRequestAnimationFrame?(this._cancelAnimationFrame=e.webkitCancelAnimationFrame.bind(e),this._requestAnimationFrame=e.webkitRequestAnimationFrame.bind(e)):e.msRequestAnimationFrame?(this._cancelAnimationFrame=e.msCancelAnimationFrame.bind(e),this._requestAnimationFrame=e.msRequestAnimationFrame.bind(e)):e.oRequestAnimationFrame?(this._cancelAnimationFrame=e.oCancelAnimationFrame.bind(e),this._requestAnimationFrame=e.oRequestAnimationFrame.bind(e)):(this._cancelAnimationFrame=e.clearTimeout.bind(e),this._requestAnimationFrame=t=>e.setTimeout(t,1e3/60))}get cancelAnimationFrame(){return this._cancelAnimationFrame}get requestAnimationFrame(){return this._requestAnimationFrame}}class Kw{constructor(e){this._spatial=new Du,this._referenceThreshold=.01,this._transitionMode=e.transitionMode,this._reference=e.reference,this._alpha=e.alpha,this._stateTransitionAlpha=0,this._camera=e.camera.clone(),this._zoom=e.zoom,this._currentIndex=e.currentIndex,this._trajectory=e.trajectory.slice(),this._trajectoryTransforms=[],this._trajectoryCameras=[];for(let e of this._trajectory){let t=this._imageToTranslation(e,this._reference),i=new ug(e.exifOrientation,e.width,e.height,e.scale,e.rotation,t,e.image,void 0,e.cameraParameters,e.cameraType);this._trajectoryTransforms.push(i),this._trajectoryCameras.push(new Nw(i))}this._currentImage=this._trajectory.length>0?this._trajectory[this._currentIndex]:null,this._previousImage=this._trajectory.length>1&&this.currentIndex>0?this._trajectory[this._currentIndex-1]:null,this._currentCamera=this._trajectoryCameras.length>0?this._trajectoryCameras[this._currentIndex].clone():new Nw,this._previousCamera=this._trajectoryCameras.length>1&&this.currentIndex>0?this._trajectoryCameras[this._currentIndex-1].clone():this._currentCamera.clone()}get reference(){return this._reference}get alpha(){return this._getAlpha()}get stateTransitionAlpha(){return this._getStateTransitionAlpha()}get camera(){return this._camera}get zoom(){return this._zoom}get trajectory(){return this._trajectory}get currentIndex(){return this._currentIndex}get currentImage(){return this._currentImage}get previousImage(){return this._previousImage}get currentCamera(){return this._currentCamera}get currentTransform(){return this._trajectoryTransforms.length>0?this._trajectoryTransforms[this.currentIndex]:null}get previousTransform(){return this._trajectoryTransforms.length>1&&this.currentIndex>0?this._trajectoryTransforms[this.currentIndex-1]:null}get motionless(){return this._motionless}get transitionMode(){return this._transitionMode}move(e){}moveTo(e){}rotate(e){}rotateUnbounded(e){}rotateWithoutInertia(e){}rotateBasic(e){}rotateBasicUnbounded(e){}rotateBasicWithoutInertia(e){}rotateToBasic(e){}setSpeed(e){}zoomIn(e,t){}update(e){}setCenter(e){}setZoom(e){}dolly(e){}orbit(e){}setViewMatrix(e){}truck(e){}append(e){if(e.length<1)throw Error("Trajectory can not be empty");this._currentIndex<0?this.set(e):(this._trajectory=this._trajectory.concat(e),this._appendToTrajectories(e))}prepend(e){if(e.length<1)throw Error("Trajectory can not be empty");this._trajectory=e.slice().concat(this._trajectory),this._currentIndex+=e.length,this._setCurrentImage(),this._setReference(this._currentImage)?this._setTrajectories():this._prependToTrajectories(e),this._setCurrentCamera()}remove(e){if(e<0)throw Error("n must be a positive integer");if(this._currentIndex-1<e)throw Error("Current and previous images can not be removed");for(let t=0;t<e;t++)this._trajectory.shift(),this._trajectoryTransforms.shift(),this._trajectoryCameras.shift(),this._currentIndex--;this._setCurrentImage()}clearPrior(){this._currentIndex>0&&this.remove(this._currentIndex-1)}clear(){this.cut(),this._currentIndex>0&&this.remove(this._currentIndex-1)}cut(){for(;this._trajectory.length-1>this._currentIndex;)this._trajectory.pop(),this._trajectoryTransforms.pop(),this._trajectoryCameras.pop()}set(e){this._setTrajectory(e),this._setCurrentImage(),this._setReference(this._currentImage),this._setTrajectories(),this._setCurrentCamera()}getCenter(){return null!=this._currentImage?this.currentTransform.projectBasic(this._camera.lookat.toArray()):[.5,.5]}setTransitionMode(e){this._transitionMode=e}_getAlpha(){return 1}_getStateTransitionAlpha(){return 1}_setCurrent(){this._setCurrentImage(),this._setReference(this._currentImage)&&this._setTrajectories(),this._setCurrentCamera()}_setCurrentCamera(){this._currentCamera=this._trajectoryCameras[this._currentIndex].clone(),this._previousCamera=this._currentIndex>0?this._trajectoryCameras[this._currentIndex-1].clone():this._currentCamera.clone()}_motionlessTransition(){return null!=this._currentImage&&null!=this._previousImage&&(this._transitionMode===e.TransitionMode.Instantaneous||!(this._currentImage.merged&&this._previousImage.merged&&this._withinOriginalDistance()&&this._sameConnectedComponent()))}_setReference(e){return!(Math.abs(e.lngLat.lat-this.reference.lat)<this._referenceThreshold&&Math.abs(e.lngLat.lng-this.reference.lng)<this._referenceThreshold)&&(!(null!=this._previousImage&&!this._motionlessTransition())&&(this._reference.lat=e.lngLat.lat,this._reference.lng=e.lngLat.lng,this._reference.alt=e.computedAltitude,!0))}_setCurrentImage(){this._currentImage=this._trajectory.length>0?this._trajectory[this._currentIndex]:null,this._previousImage=this._currentIndex>0?this._trajectory[this._currentIndex-1]:null}_setTrajectory(e){if(e.length<1)throw new Lu("Trajectory can not be empty");null!=this._currentImage?(this._trajectory=[this._currentImage].concat(e),this._currentIndex=1):(this._trajectory=e.slice(),this._currentIndex=0)}_setTrajectories(){this._trajectoryTransforms.length=0,this._trajectoryCameras.length=0,this._appendToTrajectories(this._trajectory)}_appendToTrajectories(e){for(let t of e){if(!t.assetsCached)throw new Lu("Assets must be cached when image is added to trajectory");let e=this._imageToTranslation(t,this.reference),i=new ug(t.exifOrientation,t.width,t.height,t.scale,t.rotation,e,t.image,void 0,t.cameraParameters,t.cameraType);this._trajectoryTransforms.push(i),this._trajectoryCameras.push(new Nw(i))}}_prependToTrajectories(e){for(let t of e.reverse()){if(!t.assetsCached)throw new Lu("Assets must be cached when added to trajectory");let e=this._imageToTranslation(t,this.reference),i=new ug(t.exifOrientation,t.width,t.height,t.scale,t.rotation,e,t.image,void 0,t.cameraParameters,t.cameraType);this._trajectoryTransforms.unshift(i),this._trajectoryCameras.unshift(new Nw(i))}}_imageToTranslation(e,t){return Ou({alt:e.computedAltitude,lat:e.lngLat.lat,lng:e.lngLat.lng},e.rotation,t)}_sameConnectedComponent(){let e=this._currentImage,t=this._previousImage;return!!e&&!!t&&e.mergeId===t.mergeId}_withinOriginalDistance(){let e=this._currentImage,t=this._previousImage;return!e||!t||this._spatial.distanceFromLngLat(e.originalLngLat.lng,e.originalLngLat.lat,t.originalLngLat.lng,t.originalLngLat.lat)<25}}class Qw extends Kw{constructor(e){super(e)}setViewMatrix(e){const t=(new Rn).fromArray(e).invert().elements,i=new Ki(t[12],t[13],t[14]),n=new Ki(-t[8],-t[9],-t[10]),r=new Ki(t[4],t[5],t[6]),s=this._camera;s.position.copy(i),s.lookat.copy(i.clone().add(n)),s.up.copy(r);const a=.5/Math.tan(Math.PI/3);s.focal=a}}class eM extends Kw{constructor(e){super(e),this._transition=0;const t=this._camera.position.clone(),i=this._camera.lookat.clone().sub(t).normalize(),n=Math.sqrt(i.x*i.x+i.y*i.y),r=Math.atan2(i.z,n),s=new Ki;if(r>-Math.PI/45)s.copy(t),t.add(new Ki(i.x,i.y,0).multiplyScalar(-50)),t.z=30;else{const e=t.clone(),n=new Ki(0,0,1),r=new Ki(0,0,-2),a=(new Ki).subVectors(r,e).dot(n)/i.dot(n),o=1e4,h=e.clone().add(i.clone().multiplyScalar(Math.min(o,a)));s.copy(h);const c=t.clone().sub(h).normalize();t.copy(h.add(c.multiplyScalar(Math.max(50,c.length()))))}const a=this._camera.position.clone(),o=a.clone().add(i.clone().normalize().multiplyScalar(10)),h=this._camera.up.clone(),c=o.clone(),l=c.clone().add(i.clone().normalize().multiplyScalar(10)),u=h.clone(),d=t.clone(),p=s.clone(),m=new Ki(0,0,1),f=t.clone().add(p.clone().sub(d).normalize().multiplyScalar(-10)),g=p.clone(),_=m.clone();this._curveE=new dc([c,a,d,f]),this._curveL=new dc([l,o,p,g]),this._curveU=new dc([u,h,m,_]),this._zoom0=this._zoom,this._zoom1=0,this._camera.focal=.5/Math.tan(Math.PI/4)}get _isTransitioning(){return this._transition<1}dolly(e){if(this._isTransitioning)return;const t=this._camera,i=t.position.clone().sub(t.lookat),n=i.length()*Math.pow(2,-e),r=Math.max(1,Math.min(n,4e3));i.normalize(),i.multiplyScalar(r),t.position.copy(t.lookat).add(i)}orbit(e){if(this._isTransitioning)return;const t=this._camera,i=(new Ji).setFromUnitVectors(t.up,new Ki(0,0,1)),n=i.clone().invert(),r=t.position.clone().sub(t.lookat);r.applyQuaternion(i);const s=r.length();let a=Math.atan2(r.y,r.x);a+=e.phi;let o=Math.atan2(Math.sqrt(r.x*r.x+r.y*r.y),r.z);o+=e.theta;const h=Math.PI/36;o=Math.max(h,Math.min(Math.PI/2-h,o)),r.x=Math.sin(o)*Math.cos(a),r.y=Math.sin(o)*Math.sin(a),r.z=Math.cos(o),r.applyQuaternion(n),t.position.copy(t.lookat).add(r.multiplyScalar(s))}truck(e){if(this._isTransitioning)return;const t=this._camera;t.position.add((new Ki).fromArray(e)),t.lookat.add((new Ki).fromArray(e))}update(e){if(!this._isTransitioning)return;this._transition=Math.min(this._transition+2*e/3,1);const t=Oi.smootherstep(this._transition,0,1),i=(t+1)/3,n=this._curveE.getPoint(i),r=this._curveL.getPoint(i),s=this._curveU.getPoint(i);this._camera.position.copy(n),this._camera.lookat.copy(r),this._camera.up.copy(s),this._zoom=Oi.lerp(this._zoom0,this._zoom1,t),this._stateTransitionAlpha=t}_getStateTransitionAlpha(){return this._stateTransitionAlpha}}class tM{constructor(e,t){this._phi=e,this._theta=t}get phi(){return this._phi}set phi(e){this._phi=e}get theta(){return this._theta}set theta(e){this._theta=e}get isZero(){return 0===this._phi&&0===this._theta}copy(e){this._phi=e.phi,this._theta=e.theta}lerp(e,t){this._phi=(1-t)*this._phi+t*e.phi,this._theta=(1-t)*this._theta+t*e.theta}multiply(e){this._phi*=e,this._theta*=e}threshold(e){this._phi=Math.abs(this._phi)>e?this._phi:0,this._theta=Math.abs(this._theta)>e?this._theta:0}lengthSquared(){return this._phi*this._phi+this._theta*this._theta}reset(){this._phi=0,this._theta=0}}class iM extends Kw{constructor(e){super(e),this._animationSpeed=1/40,this._rotationDelta=new tM(0,0),this._requestedRotationDelta=null,this._basicRotation=[0,0],this._requestedBasicRotation=null,this._requestedBasicRotationUnbounded=null,this._rotationAcceleration=.86,this._rotationIncreaseAlpha=.97,this._rotationDecreaseAlpha=.9,this._rotationThreshold=.001,this._unboundedRotationAlpha=.8,this._desiredZoom=e.zoom,this._minZoom=0,this._maxZoom=3,this._lookatDepth=10,this._desiredLookat=null,this._desiredCenter=null}rotate(e){null!=this._currentImage&&(0===e.phi&&0===e.theta||(this._desiredZoom=this._zoom,this._desiredLookat=null,this._requestedBasicRotation=null,null!=this._requestedRotationDelta?(this._requestedRotationDelta.phi=this._requestedRotationDelta.phi+e.phi,this._requestedRotationDelta.theta=this._requestedRotationDelta.theta+e.theta):this._requestedRotationDelta=new tM(e.phi,e.theta)))}rotateUnbounded(e){if(null==this._currentImage)return;if(this._requestedBasicRotation=null,this._requestedRotationDelta=null,this._applyRotation(e,this._currentCamera),this._applyRotation(e,this._previousCamera),!this._desiredLookat)return;const t=(new Ji).setFromUnitVectors(this._currentCamera.up,new Ki(0,0,1)),i=t.clone().invert(),n=(new Ki).copy(this._desiredLookat).sub(this._camera.position).applyQuaternion(t),r=n.length();let s=Math.atan2(n.y,n.x);s+=e.phi;let a=Math.atan2(Math.sqrt(n.x*n.x+n.y*n.y),n.z);a+=e.theta,a=Math.max(.1,Math.min(Math.PI-.1,a)),n.x=Math.sin(a)*Math.cos(s),n.y=Math.sin(a)*Math.sin(s),n.z=Math.cos(a),n.applyQuaternion(i),this._desiredLookat.copy(this._camera.position).add(n.multiplyScalar(r))}rotateWithoutInertia(e){if(null==this._currentImage)return;this._desiredZoom=this._zoom,this._desiredLookat=null,this._requestedBasicRotation=null,this._requestedRotationDelta=null;const t=Math.PI/(10*Math.pow(2,this._zoom)),i={phi:this._spatial.clamp(e.phi,-t,t),theta:this._spatial.clamp(e.theta,-t,t)};this._applyRotation(i,this._currentCamera),this._applyRotation(i,this._previousCamera)}rotateBasic(e){if(null!=this._currentImage)if(this._desiredZoom=this._zoom,this._desiredLookat=null,this._requestedRotationDelta=null,null!=this._requestedBasicRotation){this._requestedBasicRotation[0]+=e[0],this._requestedBasicRotation[1]+=e[1];let t=.05/Math.pow(2,this._zoom);this._requestedBasicRotation[0]=this._spatial.clamp(this._requestedBasicRotation[0],-t,t),this._requestedBasicRotation[1]=this._spatial.clamp(this._requestedBasicRotation[1],-t,t)}else this._requestedBasicRotation=e.slice()}rotateBasicUnbounded(e){null!=this._currentImage&&(null!=this._requestedBasicRotationUnbounded?(this._requestedBasicRotationUnbounded[0]+=e[0],this._requestedBasicRotationUnbounded[1]+=e[1]):this._requestedBasicRotationUnbounded=e.slice())}rotateBasicWithoutInertia(e){if(null==this._currentImage)return;this._desiredZoom=this._zoom,this._desiredLookat=null,this._requestedRotationDelta=null,this._requestedBasicRotation=null;const t=.05/Math.pow(2,this._zoom),i=e.slice();i[0]=this._spatial.clamp(i[0],-t,t),i[1]=this._spatial.clamp(i[1],-t,t),this._applyRotationBasic(i)}rotateToBasic(e){if(null==this._currentImage)return;this._desiredZoom=this._zoom,this._desiredLookat=null,e[0]=this._spatial.clamp(e[0],0,1),e[1]=this._spatial.clamp(e[1],0,1);let t=this.currentTransform.unprojectBasic(e,this._lookatDepth);this._currentCamera.lookat.fromArray(t)}zoomIn(e,t){if(null==this._currentImage)return;this._desiredZoom=Math.max(this._minZoom,Math.min(this._maxZoom,this._desiredZoom+e));let i=this.currentTransform.projectBasic(this._currentCamera.lookat.toArray()),n=i[0],r=i[1],s=Math.pow(2,this._zoom),a=Math.pow(2,this._desiredZoom),o=t[0],h=t[1];$u(this.currentTransform.cameraType)&&(o-n>.5?o-=1:n-o>.5&&(o=1+o));let c=o-s/a*(o-n),l=h-s/a*(h-r);$u(this._currentImage.cameraType)?(c=this._spatial.wrap(c+this._basicRotation[0],0,1),l=this._spatial.clamp(l+this._basicRotation[1],.05,.95)):(c=this._spatial.clamp(c,0,1),l=this._spatial.clamp(l,0,1)),this._desiredLookat=(new Ki).fromArray(this.currentTransform.unprojectBasic([c,l],this._lookatDepth))}setCenter(e){this._desiredLookat=null,this._requestedRotationDelta=null,this._requestedBasicRotation=null,this._desiredZoom=this._zoom;let t=[this._spatial.clamp(e[0],0,1),this._spatial.clamp(e[1],0,1)];if(null==this._currentImage)return void(this._desiredCenter=t);this._desiredCenter=null;let i=(new Ki).fromArray(this.currentTransform.unprojectBasic(t,this._lookatDepth)),n=null!=this.previousTransform?this.previousTransform:this.currentTransform,r=(new Ki).fromArray(n.unprojectBasic(t,this._lookatDepth));this._currentCamera.lookat.copy(i),this._previousCamera.lookat.copy(r)}setZoom(e){this._desiredLookat=null,this._requestedRotationDelta=null,this._requestedBasicRotation=null,this._zoom=this._spatial.clamp(e,this._minZoom,this._maxZoom),this._desiredZoom=this._zoom}_applyRotation(e,t){if(null==t)return;let i=(new Ji).setFromUnitVectors(t.up,new Ki(0,0,1)),n=i.clone().invert(),r=new Ki;r.copy(t.lookat).sub(t.position),r.applyQuaternion(i);let s=r.length(),a=Math.atan2(r.y,r.x);a+=e.phi;let o=Math.atan2(Math.sqrt(r.x*r.x+r.y*r.y),r.z);o+=e.theta,o=Math.max(.1,Math.min(Math.PI-.1,o)),r.x=Math.sin(o)*Math.cos(a),r.y=Math.sin(o)*Math.sin(a),r.z=Math.cos(o),r.applyQuaternion(n),t.lookat.copy(t.position).add(r.multiplyScalar(s))}_applyRotationBasic(e){let t=this._currentImage,i=null!=this._previousImage?this.previousImage:this.currentImage,n=this._currentCamera,r=this._previousCamera,s=this.currentTransform,a=null!=this.previousTransform?this.previousTransform:this.currentTransform,o=s.projectBasic(n.lookat.toArray()),h=a.projectBasic(r.lookat.toArray());$u(t.cameraType)?(o[0]=this._spatial.wrap(o[0]+e[0],0,1),o[1]=this._spatial.clamp(o[1]+e[1],.05,.95)):(o[0]=this._spatial.clamp(o[0]+e[0],0,1),o[1]=this._spatial.clamp(o[1]+e[1],0,1)),$u(i.cameraType)?(h[0]=this._spatial.wrap(h[0]+e[0],0,1),h[1]=this._spatial.clamp(h[1]+e[1],.05,.95)):(h[0]=this._spatial.clamp(h[0]+e[0],0,1),h[1]=this._spatial.clamp(o[1]+e[1],0,1));let c=s.unprojectBasic(o,this._lookatDepth);n.lookat.fromArray(c);let l=a.unprojectBasic(h,this._lookatDepth);r.lookat.fromArray(l)}_updateZoom(e){let t=this._desiredZoom-this._zoom,i=t>0?1:t<0?-1:0;0!==t&&(Math.abs(t)<.002?(this._zoom=this._desiredZoom,null!=this._desiredLookat&&(this._desiredLookat=null)):this._zoom+=i*Math.max(Math.abs(5*e*t),.002))}_updateLookat(e){if(null===this._desiredLookat)return;let t=this._desiredLookat.distanceToSquared(this._currentCamera.lookat);Math.abs(t)<1e-6?(this._currentCamera.lookat.copy(this._desiredLookat),this._desiredLookat=null):this._currentCamera.lookat.lerp(this._desiredLookat,5*e)}_updateRotation(){if(null!=this._requestedRotationDelta){let e=this._rotationDelta.lengthSquared();return this._requestedRotationDelta.lengthSquared()>e?this._rotationDelta.lerp(this._requestedRotationDelta,this._rotationIncreaseAlpha):this._rotationDelta.lerp(this._requestedRotationDelta,this._rotationDecreaseAlpha),void(this._requestedRotationDelta=null)}if(this._rotationDelta.isZero)return;const e=$u(this.currentImage.cameraType)?1:this._alpha;this._rotationDelta.multiply(this._rotationAcceleration*e),this._rotationDelta.threshold(this._rotationThreshold)}_updateRotationBasic(){if(null!=this._requestedBasicRotation){let e=this._basicRotation[0],t=this._basicRotation[1],i=this._requestedBasicRotation[0],n=this._requestedBasicRotation[1];return Math.abs(i)>Math.abs(e)?this._basicRotation[0]=(1-this._rotationIncreaseAlpha)*e+this._rotationIncreaseAlpha*i:this._basicRotation[0]=(1-this._rotationDecreaseAlpha)*e+this._rotationDecreaseAlpha*i,Math.abs(n)>Math.abs(t)?this._basicRotation[1]=(1-this._rotationIncreaseAlpha)*t+this._rotationIncreaseAlpha*n:this._basicRotation[1]=(1-this._rotationDecreaseAlpha)*t+this._rotationDecreaseAlpha*n,void(this._requestedBasicRotation=null)}if(null!=this._requestedBasicRotationUnbounded){let e=this._requestedBasicRotationUnbounded[0],t=this._requestedBasicRotationUnbounded[1];if(Math.abs(e)>0&&(this._basicRotation[0]=(1-this._unboundedRotationAlpha)*this._basicRotation[0]+this._unboundedRotationAlpha*e),Math.abs(t)>0&&(this._basicRotation[1]=(1-this._unboundedRotationAlpha)*this._basicRotation[1]+this._unboundedRotationAlpha*t),null!=this._desiredLookat){let i=this.currentTransform.projectBasic(this._desiredLookat.toArray());i[0]+=e,i[1]+=t,this._desiredLookat=(new Ki).fromArray(this.currentTransform.unprojectBasic(i,this._lookatDepth))}this._requestedBasicRotationUnbounded=null}0===this._basicRotation[0]&&0===this._basicRotation[1]||(this._basicRotation[0]=this._rotationAcceleration*this._basicRotation[0],this._basicRotation[1]=this._rotationAcceleration*this._basicRotation[1],Math.abs(this._basicRotation[0])<this._rotationThreshold/Math.pow(2,this._zoom)&&Math.abs(this._basicRotation[1])<this._rotationThreshold/Math.pow(2,this._zoom)&&(this._basicRotation=[0,0]))}_clearRotation(){$u(this._currentImage.cameraType)||(null!=this._requestedRotationDelta&&(this._requestedRotationDelta=null),this._rotationDelta.isZero||this._rotationDelta.reset(),null!=this._requestedBasicRotation&&(this._requestedBasicRotation=null),(this._basicRotation[0]>0||this._basicRotation[1]>0)&&(this._basicRotation=[0,0]))}_setDesiredCenter(){if(null==this._desiredCenter)return;let e=(new Ki).fromArray(this.currentTransform.unprojectBasic(this._desiredCenter,this._lookatDepth)).sub(this._currentCamera.position);this._currentCamera.lookat.copy(this._currentCamera.position.clone().add(e)),this._previousCamera.lookat.copy(this._previousCamera.position.clone().add(e)),this._desiredCenter=null}_setDesiredZoom(){this._desiredZoom=$u(this._currentImage.cameraType)||null==this._previousImage?this._zoom:0}}class nM extends iM{constructor(e){super(e),this._adjustCameras(),this._motionless=this._motionlessTransition()}prepend(e){super.prepend(e),this._motionless=this._motionlessTransition()}set(e){super.set(e),this._motionless=this._motionlessTransition()}move(e){this._alpha=Math.max(0,Math.min(1,this._alpha+e))}moveTo(e){this._alpha=Math.max(0,Math.min(1,e))}update(e){this._updateRotation(),this._rotationDelta.isZero||(this._applyRotation(this._rotationDelta,this._previousCamera),this._applyRotation(this._rotationDelta,this._currentCamera)),this._updateRotationBasic(),0===this._basicRotation[0]&&0===this._basicRotation[1]||this._applyRotationBasic(this._basicRotation);let t=this._animationSpeed*e/.1*6;this._updateZoom(t),this._updateLookat(t),this._camera.lerpCameras(this._previousCamera,this._currentCamera,this.alpha)}_getAlpha(){return this._motionless?Math.round(this._alpha):this._alpha}_setCurrentCamera(){super._setCurrentCamera(),this._adjustCameras()}_adjustCameras(){if(null!=this._previousImage){if($u(this._currentImage.cameraType)){let e=this._camera.lookat.clone().sub(this._camera.position);this._currentCamera.lookat.copy(e.clone().add(this._currentCamera.position))}if($u(this._previousImage.cameraType)){let e=this._currentCamera.lookat.clone().sub(this._currentCamera.position);this._previousCamera.lookat.copy(e.clone().add(this._previousCamera.position))}}}}class rM extends iM{constructor(e){super(e),this._adjustCameras(),this._motionless=this._motionlessTransition(),this._baseAlpha=this._alpha,this._speedCoefficient=1,this._smoothing=!1}append(e){let t=0===this._trajectory.length;t&&this._resetTransition(),super.append(e),t&&(this._setDesiredCenter(),this._setDesiredZoom())}prepend(e){let t=0===this._trajectory.length;t&&this._resetTransition(),super.prepend(e),t&&(this._setDesiredCenter(),this._setDesiredZoom())}set(e){super.set(e),this._desiredLookat=null,this._resetTransition(),this._clearRotation(),this._setDesiredCenter(),this._setDesiredZoom(),this._trajectory.length<3&&(this._smoothing=!0)}setSpeed(e){this._speedCoefficient=this._spatial.clamp(e,0,10)}update(e){1===this._alpha&&this._currentIndex+this._alpha<this._trajectory.length&&(this._currentIndex+=1,this._smoothing=this._trajectory.length<3&&this._currentIndex+1===this._trajectory.length,this._setCurrent(),this._resetTransition(),this._clearRotation(),this._desiredZoom=$u(this._currentImage.cameraType)?this._zoom:0,this._desiredLookat=null);let t=this._animationSpeed*e/.1*6;this._baseAlpha=Math.min(1,this._baseAlpha+this._speedCoefficient*t),this._smoothing?this._alpha=Oi.smootherstep(this._baseAlpha,0,1):this._alpha=this._baseAlpha,this._updateRotation(),this._rotationDelta.isZero||(this._applyRotation(this._rotationDelta,this._previousCamera),this._applyRotation(this._rotationDelta,this._currentCamera)),this._updateRotationBasic(),0===this._basicRotation[0]&&0===this._basicRotation[1]||this._applyRotationBasic(this._basicRotation),this._updateZoom(t),this._updateLookat(t),this._camera.lerpCameras(this._previousCamera,this._currentCamera,this.alpha)}_getAlpha(){return this._motionless?Math.ceil(this._alpha):this._alpha}_setCurrentCamera(){super._setCurrentCamera(),this._adjustCameras()}_adjustCameras(){if(null==this._previousImage)return;let e=this._camera.lookat.clone().sub(this._camera.position);this._previousCamera.lookat.copy(e.clone().add(this._previousCamera.position)),$u(this._currentImage.cameraType)&&this._currentCamera.lookat.copy(e.clone().add(this._currentCamera.position))}_resetTransition(){this._alpha=0,this._baseAlpha=0,this._motionless=this._motionlessTransition()}}class sM extends Kw{constructor(e){super(e),this._zoom=0,this._adjustCameras(),this._motionless=this._motionlessTransition()}prepend(e){super.prepend(e),this._motionless=this._motionlessTransition()}set(e){super.set(e),this._motionless=this._motionlessTransition()}move(e){this._alpha=Math.max(0,Math.min(1,this._alpha+e))}moveTo(e){this._alpha=Math.max(0,Math.min(1,e))}update(){this._camera.lerpCameras(this._previousCamera,this._currentCamera,this.alpha)}_getAlpha(){return this._motionless?Math.round(this._alpha):this._alpha}_setCurrentCamera(){super._setCurrentCamera(),this._adjustCameras()}_adjustCameras(){if(null!=this._previousImage){if($u(this._currentImage.cameraType)){let e=this._camera.lookat.clone().sub(this._camera.position);this._currentCamera.lookat.copy(e.clone().add(this._currentCamera.position))}if($u(this._previousImage.cameraType)){let e=this._currentCamera.lookat.clone().sub(this._currentCamera.position);this._previousCamera.lookat.copy(e.clone().add(this._previousCamera.position))}}}}class aM{constructor(){const e=Df[Df.Custom],t=Df[Df.Earth],i=Df[Df.Traversing],n=Df[Df.Waiting],r=Df[Df.WaitingInteractively];this._creators=new Map;const s=this._creators;s.set(e,Qw),s.set(t,eM),s.set(i,rM),s.set(n,sM),s.set(r,nM),this._transitions=new Map;const a=this._transitions;a.set(e,[t,i]),a.set(t,[e,i]),a.set(i,[e,t,n,r]),a.set(n,[i,r]),a.set(r,[i,n])}getState(e){if(e instanceof Qw)return Df.Custom;if(e instanceof eM)return Df.Earth;if(e instanceof rM)return Df.Traversing;if(e instanceof sM)return Df.Waiting;if(e instanceof nM)return Df.WaitingInteractively;throw new Error("Invalid state instance")}generate(e,t){return new(this._creators.get(Df[e]))(t)}transition(e,t){if(!this.validate(e,t))throw new Error("Invalid transition");return this.generate(t,e)}validate(e,t){const i=Df[this.getState(e)],n=Df[t],r=this._transitions;return r.has(i)&&r.get(i).includes(n)}}class oM{constructor(t,i){this._transitions=new aM,this._state=this._transitions.generate(t,{alpha:1,camera:new Nw,currentIndex:-1,reference:{alt:0,lat:0,lng:0},trajectory:[],transitionMode:null==i?e.TransitionMode.Default:i,zoom:0})}get state(){return this._transitions.getState(this._state)}get reference(){return this._state.reference}get alpha(){return this._state.alpha}get stateTransitionAlpha(){return this._state.stateTransitionAlpha}get camera(){return this._state.camera}get zoom(){return this._state.zoom}get currentImage(){return this._state.currentImage}get previousImage(){return this._state.previousImage}get currentCamera(){return this._state.currentCamera}get currentTransform(){return this._state.currentTransform}get previousTransform(){return this._state.previousTransform}get trajectory(){return this._state.trajectory}get currentIndex(){return this._state.currentIndex}get lastImage(){return this._state.trajectory[this._state.trajectory.length-1]}get imagesAhead(){return this._state.trajectory.length-1-this._state.currentIndex}get motionless(){return this._state.motionless}custom(){this._transition(Df.Custom)}earth(){this._transition(Df.Earth)}traverse(){this._transition(Df.Traversing)}wait(){this._transition(Df.Waiting)}waitInteractively(){this._transition(Df.WaitingInteractively)}getCenter(){return this._state.getCenter()}setCenter(e){this._state.setCenter(e)}setZoom(e){this._state.setZoom(e)}update(e){this._state.update(e)}append(e){this._state.append(e)}prepend(e){this._state.prepend(e)}remove(e){this._state.remove(e)}clear(){this._state.clear()}clearPrior(){this._state.clearPrior()}cut(){this._state.cut()}set(e){this._state.set(e)}setViewMatrix(e){this._state.setViewMatrix(e)}rotate(e){this._state.rotate(e)}rotateUnbounded(e){this._state.rotateUnbounded(e)}rotateWithoutInertia(e){this._state.rotateWithoutInertia(e)}rotateBasic(e){this._state.rotateBasic(e)}rotateBasicUnbounded(e){this._state.rotateBasicUnbounded(e)}rotateBasicWithoutInertia(e){this._state.rotateBasicWithoutInertia(e)}rotateToBasic(e){this._state.rotateToBasic(e)}move(e){this._state.move(e)}moveTo(e){this._state.moveTo(e)}zoomIn(e,t){this._state.zoomIn(e,t)}setSpeed(e){this._state.setSpeed(e)}setTransitionMode(e){this._state.setTransitionMode(e)}dolly(e){this._state.dolly(e)}orbit(e){this._state.orbit(e)}truck(e){this._state.truck(e)}_transition(e){if(!this._transitions.validate(this._state,e)){const t=this._transitions.getState(this._state);return void console.warn(`Transition not valid (${Df[t]} - ${Df[e]})`)}const t=this._transitions.transition(this._state,e);this._state=t}}class hM{constructor(e,t){this._appendImage$=new j,this._clock=new jl,this._subscriptions=new rf;const i=this._subscriptions;this._start$=new j,this._frame$=new j,this._contextOperation$=new W((e=>e)),this._context$=this._contextOperation$.pipe(Lt(((e,t)=>t(e)),new oM(e,t)),Rt(1),U()),this._state$=this._context$.pipe(De((e=>e.state)),vt(),Rt(1),U()),this._currentState$=this._frame$.pipe(Vt(this._context$,((e,t)=>[e,t])),st((e=>null!=e[1].currentImage)),Ut((e=>{e[1].update(this._clock.getDelta())})),De((e=>({fps:60,id:e[0],state:e[1]}))),Dt()),this._lastState$=this._currentState$.pipe(Rt(1),U());let n=this._currentState$.pipe(vt(void 0,(e=>e.state.currentImage.id)),Rt(1),U()),r=new j;i.push(n.subscribe(r)),this._currentId$=new W(null),i.push(r.pipe(De((e=>e.state.currentImage.id))).subscribe(this._currentId$)),this._currentImage$=r.pipe(De((e=>e.state.currentImage)),Rt(1),U()),this._currentCamera$=r.pipe(De((e=>e.state.currentCamera)),Rt(1),U()),this._currentTransform$=r.pipe(De((e=>e.state.currentTransform)),Rt(1),U()),this._reference$=r.pipe(De((e=>e.state.reference)),vt(((e,t)=>e.lat===t.lat&&e.lng===t.lng),(e=>({lat:e.lat,lng:e.lng}))),Rt(1),U()),this._currentImageExternal$=n.pipe(De((e=>e.state.currentImage)),Rt(1),U()),i.push(this._appendImage$.pipe(De((e=>t=>(t.append([e]),t)))).subscribe(this._contextOperation$)),this._inMotionOperation$=new j,i.push(n.pipe(De((()=>!0))).subscribe(this._inMotionOperation$)),i.push(this._inMotionOperation$.pipe(vt(),st((e=>e)),zt((()=>this._currentState$.pipe(st((e=>0===e.state.imagesAhead)),De((e=>[e.state.camera.clone(),e.state.zoom])),At(),De((e=>{let t=e[0][0],i=e[1][0],n=e[0][1],r=e[1][1];return t.diff(i)>1e-5||Math.abs(n-r)>1e-5})),St((e=>!e)))))).subscribe(this._inMotionOperation$)),this._inMotion$=this._inMotionOperation$.pipe(vt(),Rt(1),U()),this._inTranslationOperation$=new j,i.push(n.pipe(De((()=>!0))).subscribe(this._inTranslationOperation$)),i.push(this._inTranslationOperation$.pipe(vt(),st((e=>e)),zt((()=>this._currentState$.pipe(st((e=>0===e.state.imagesAhead)),De((e=>e.state.camera.position.clone())),At(),De((e=>0!==e[0].distanceToSquared(e[1]))),St((e=>!e)))))).subscribe(this._inTranslationOperation$)),this._inTranslation$=this._inTranslationOperation$.pipe(vt(),Rt(1),U()),i.push(this._state$.subscribe((()=>{}))),i.push(this._currentImage$.subscribe((()=>{}))),i.push(this._currentCamera$.subscribe((()=>{}))),i.push(this._currentTransform$.subscribe((()=>{}))),i.push(this._reference$.subscribe((()=>{}))),i.push(this._currentImageExternal$.subscribe((()=>{}))),i.push(this._lastState$.subscribe((()=>{}))),i.push(this._inMotion$.subscribe((()=>{}))),i.push(this._inTranslation$.subscribe((()=>{}))),this._frameId=null,this._frameGenerator=new Jw(window)}get currentState$(){return this._currentState$}get currentImage$(){return this._currentImage$}get currentId$(){return this._currentId$}get currentImageExternal$(){return this._currentImageExternal$}get currentCamera$(){return this._currentCamera$}get currentTransform$(){return this._currentTransform$}get state$(){return this._state$}get reference$(){return this._reference$}get inMotion$(){return this._inMotion$}get inTranslation$(){return this._inTranslation$}get appendImage$(){return this._appendImage$}dispose(){this.stop(),this._subscriptions.unsubscribe()}custom(){this._inMotionOperation$.next(!0),this._invokeContextOperation((e=>{e.custom()}))}earth(){this._inMotionOperation$.next(!0),this._invokeContextOperation((e=>{e.earth()}))}traverse(){this._inMotionOperation$.next(!0),this._invokeContextOperation((e=>{e.traverse()}))}wait(){this._invokeContextOperation((e=>{e.wait()}))}waitInteractively(){this._invokeContextOperation((e=>{e.waitInteractively()}))}appendImagess(e){this._invokeContextOperation((t=>{t.append(e)}))}prependImages(e){this._invokeContextOperation((t=>{t.prepend(e)}))}removeImages(e){this._invokeContextOperation((t=>{t.remove(e)}))}clearImages(){this._invokeContextOperation((e=>{e.clear()}))}clearPriorImages(){this._invokeContextOperation((e=>{e.clearPrior()}))}cutImages(){this._invokeContextOperation((e=>{e.cut()}))}setImages(e){this._invokeContextOperation((t=>{t.set(e)}))}setViewMatrix(e){this._inMotionOperation$.next(!0),this._invokeContextOperation((t=>{t.setViewMatrix(e)}))}rotate(e){this._inMotionOperation$.next(!0),this._invokeContextOperation((t=>{t.rotate(e)}))}rotateUnbounded(e){this._inMotionOperation$.next(!0),this._invokeContextOperation((t=>{t.rotateUnbounded(e)}))}rotateWithoutInertia(e){this._inMotionOperation$.next(!0),this._invokeContextOperation((t=>{t.rotateWithoutInertia(e)}))}rotateBasic(e){this._inMotionOperation$.next(!0),this._invokeContextOperation((t=>{t.rotateBasic(e)}))}rotateBasicUnbounded(e){this._inMotionOperation$.next(!0),this._invokeContextOperation((t=>{t.rotateBasicUnbounded(e)}))}rotateBasicWithoutInertia(e){this._inMotionOperation$.next(!0),this._invokeContextOperation((t=>{t.rotateBasicWithoutInertia(e)}))}rotateToBasic(e){this._inMotionOperation$.next(!0),this._invokeContextOperation((t=>{t.rotateToBasic(e)}))}move(e){this._inMotionOperation$.next(!0),this._invokeContextOperation((t=>{t.move(e)}))}moveTo(e){this._inMotionOperation$.next(!0),this._invokeContextOperation((t=>{t.moveTo(e)}))}dolly(e){this._inMotionOperation$.next(!0),this._invokeContextOperation((t=>{t.dolly(e)}))}orbit(e){this._inMotionOperation$.next(!0),this._invokeContextOperation((t=>{t.orbit(e)}))}truck(e){this._inMotionOperation$.next(!0),this._invokeContextOperation((t=>{t.truck(e)}))}zoomIn(e,t){this._inMotionOperation$.next(!0),this._invokeContextOperation((i=>{i.zoomIn(e,t)}))}getCenter(){return this._lastState$.pipe(St(),De((e=>e.state.getCenter())))}getZoom(){return this._lastState$.pipe(St(),De((e=>e.state.zoom)))}setCenter(e){this._inMotionOperation$.next(!0),this._invokeContextOperation((t=>{t.setCenter(e)}))}setSpeed(e){this._invokeContextOperation((t=>{t.setSpeed(e)}))}setTransitionMode(e){this._invokeContextOperation((t=>{t.setTransitionMode(e)}))}setZoom(e){this._inMotionOperation$.next(!0),this._invokeContextOperation((t=>{t.setZoom(e)}))}start(){this._clock.start(),null==this._frameId&&(this._start$.next(null),this._frameId=this._frameGenerator.requestAnimationFrame(this._frame.bind(this)),this._frame$.next(this._frameId))}stop(){this._clock.stop(),null!=this._frameId&&(this._frameGenerator.cancelAnimationFrame(this._frameId),this._frameId=null)}_invokeContextOperation(e){this._contextOperation$.next((t=>(e(t),t)))}_frame(){this._frameId=this._frameGenerator.requestAnimationFrame(this._frame.bind(this)),this._frame$.next(this._frameId)}}function cM(t){switch(t){case e.CameraControls.Custom:return Df.Custom;case e.CameraControls.Earth:return Df.Earth;case e.CameraControls.Street:return Df.Traversing;default:return null}}class lM{constructor(t,i,n,r,s,a,o,h){var c;i?this._api=i:t.dataProvider?this._api=new Zw(t.dataProvider):this._api=new Zw(new Mw({accessToken:t.accessToken})),this._graphService=null!=n?n:new Yw(new Uu(this.api)),this._loadingName="navigator",this._loadingService=null!=r?r:new Ww;const l=null!==(c=t.cameraControls)&&void 0!==c?c:e.CameraControls.Street;this._stateService=null!=s?s:new hM(cM(l),t.transitionMode),this._cacheService=null!=a?a:new Gw(this._graphService,this._stateService,this._api),this._playService=null!=o?o:new fg(this._graphService,this._stateService),this._panService=null!=h?h:new Xw(this._graphService,this._stateService,t.combinedPanning),this._idRequested$=new W(null),this._movedToId$=new W(null),this._request$=null,this._requestSubscription=null,this._imageRequestSubscription=null}get api(){return this._api}get cacheService(){return this._cacheService}get graphService(){return this._graphService}get loadingService(){return this._loadingService}get movedToId$(){return this._movedToId$}get panService(){return this._panService}get playService(){return this._playService}get stateService(){return this._stateService}dispose(){this._abortRequest("viewer removed"),this._cacheService.stop(),this._graphService.dispose(),this._panService.dispose(),this._playService.dispose(),this._stateService.dispose()}moveTo$(e){this._abortRequest(`to id ${e}`),this._loadingService.startLoading(this._loadingName);const t=this._moveTo$(e);return this._makeRequest$(t)}moveDir$(t){this._abortRequest(`in dir ${e.NavigationDirection[t]}`),this._loadingService.startLoading(this._loadingName);const i=this.stateService.currentImage$.pipe(St(),We((i=>([e.NavigationDirection.Next,e.NavigationDirection.Prev].indexOf(t)>-1?i.sequenceEdges$:i.spatialEdges$).pipe(St(),De((e=>{for(let i of e.edges)if(i.data.direction===t)return i.target;return null}))))),We((e=>null==e?(this._loadingService.stopLoading(this._loadingName),Ee(new Error(`Direction (${t}) does not exist for current image.`))):this._moveTo$(e))));return this._makeRequest$(i)}setFilter$(e){return this._stateService.clearImages(),this._movedToId$.pipe(St(),We((t=>null!=t?this._trajectoryIds$().pipe(We((t=>this._graphService.setFilter$(e).pipe(We((()=>this._cacheIds$(t)))))),Ct()):this._idRequested$.pipe(St(),We((t=>null!=t?this._graphService.setFilter$(e).pipe(We((()=>this._graphService.cacheImage$(t)))):this._graphService.setFilter$(e).pipe(De((()=>{})))))))),De((()=>{})))}setAccessToken$(e){return this._abortRequest("to set user token"),this._stateService.clearImages(),this._movedToId$.pipe(St(),Ut((()=>{this._api.setAccessToken(e)})),We((e=>null==e?this._graphService.reset$([]):this._trajectoryIds$().pipe(We((e=>this._graphService.reset$(e).pipe(We((()=>this._cacheIds$(e)))))),Ct(),De((()=>{}))))))}_cacheIds$(e){return ge(e.map((e=>this._graphService.cacheImage$(e)))).pipe(qe())}_abortRequest(e){null!=this._requestSubscription&&(this._requestSubscription.unsubscribe(),this._requestSubscription=null),null!=this._imageRequestSubscription&&(this._imageRequestSubscription.unsubscribe(),this._imageRequestSubscription=null),null!=this._request$&&(this._request$.isStopped||this._request$.hasError||this._request$.error(new uf(`Request aborted by a subsequent request ${e}.`)),this._request$=null)}_makeRequest$(e){const t=new X(1);return this._requestSubscription=t.subscribe(void 0,(()=>{})),this._request$=t,this._imageRequestSubscription=e.subscribe((e=>{this._request$=null,t.next(e),t.complete()}),(e=>{this._request$=null,t.error(e)})),t}_moveTo$(e){return this._idRequested$.next(e),this._graphService.cacheImage$(e).pipe(Ut((e=>{this._stateService.setImages([e]),this._movedToId$.next(e.id)})),Mt((()=>{this._loadingService.stopLoading(this._loadingName)})))}_trajectoryIds$(){return this._stateService.currentState$.pipe(St(),De((e=>e.state.trajectory.map((e=>e.id)))))}}class uM{constructor(e,t){this._spatial=null!=t?t:new Du,this._viewportCoords=null!=e?e:new hf}basicToCanvas(e,t,i,n){return this._viewportCoords.basicToCanvasSafe(e[0],e[1],t,n,i.perspective)}canvasToBasic(e,t,i,n){let r=this._viewportCoords.canvasToBasic(e[0],e[1],t,n,i.perspective);return(r[0]<0||r[0]>1||r[1]<0||r[1]>1)&&(r=null),r}eventToUnprojection(e,t,i,n,r){const s=this._viewportCoords.canvasPosition(e,t);return this.canvasToUnprojection(s,t,i,n,r)}canvasToUnprojection(e,t,i,n,r){const s=e[0],a=e[1],[o,h]=this._viewportCoords.canvasToViewport(s,a,t),c=new Ki(o,h,1).unproject(i.perspective);let l=r.projectBasic(c.toArray());(l[0]<0||l[0]>1||l[1]<0||l[1]>1)&&(l=null);const u=c.clone().sub(i.camera.position).normalize(),d=-2/u.z;let p=null;if(d>0&&d<100&&l){const e=u.clone().multiplyScalar(d).add(i.camera.position),[t,r]=vu(e.x,e.y,e.z,n.lng,n.lat,n.alt);p={lat:r,lng:t}}return{basicPoint:l,lngLat:p,pixelPoint:[s,a]}}cameraToLngLat(e,t){const i=e.camera.position,[n,r]=vu(i.x,i.y,i.z,t.lng,t.lat,t.alt);return{lat:r,lng:n}}lngLatToCanvas(e,t,i,n){const r=_u(e.lng,e.lat,0,n.lng,n.lat,n.alt);return this._viewportCoords.projectToCanvasSafe(r,t,i.perspective)}distanceBetweenLngLats(e,t){return this._spatial.distanceFromLngLat(e.lng,e.lat,t.lng,t.lat)}}class dM{constructor(e,t,i){this._subscriptions=new rf,this._emitSubscriptions=new rf,this._container=i,this._viewer=e,this._navigator=t,this._projection=new uM,this._started=!1,this._navigable$=new j;const n=this._subscriptions;n.push(this._navigable$.subscribe((e=>{const t="navigable",i={navigable:e,target:this._viewer,type:t};this._viewer.fire(t,i)}))),n.push(this._navigator.loadingService.loading$.subscribe((e=>{const t="dataloading",i={loading:e,target:this._viewer,type:t};this._viewer.fire(t,i)}))),n.push(this._container.glRenderer.opaqueRender$.pipe(St()).subscribe((()=>{const e="load",t={target:this._viewer,type:e};this._viewer.fire(e,t)})))}get started(){return this._started}get navigable$(){return this._navigable$}get projection(){return this._projection}dispose(){this.stopEmit(),this._subscriptions.unsubscribe()}project$(e){return Ve(this._container.renderService.renderCamera$,this._navigator.stateService.currentImage$,this._navigator.stateService.reference$).pipe(St(),De((([t,i,n])=>{if(this._projection.distanceBetweenLngLats(e,i.lngLat)>1e3)return null;const r=this._projection.lngLatToCanvas(e,this._container.container,t,n);return r?[Math.round(r[0]),Math.round(r[1])]:null})))}projectBasic$(e){return Ve(this._container.renderService.renderCamera$,this._navigator.stateService.currentTransform$).pipe(St(),De((([t,i])=>{const n=this._projection.basicToCanvas(e,this._container.container,t,i);return n?[Math.round(n[0]),Math.round(n[1])]:null})))}startEmit(){if(this._started)return;this._started=!0;const e=this._emitSubscriptions;e.push(this._navigator.stateService.currentImageExternal$.subscribe((e=>{const t="image",i={image:e,target:this._viewer,type:t};this._viewer.fire(t,i)}))),e.push(this._navigator.stateService.currentImageExternal$.pipe(zt((e=>e.sequenceEdges$))).subscribe((e=>{const t="sequenceedges",i={status:e,target:this._viewer,type:t};this._viewer.fire(t,i)}))),e.push(this._navigator.stateService.currentImageExternal$.pipe(zt((e=>e.spatialEdges$))).subscribe((e=>{const t="spatialedges",i={status:e,target:this._viewer,type:t};this._viewer.fire(t,i)}))),e.push(this._navigator.stateService.reference$.subscribe((e=>{const t="reference",i={reference:e,target:this._viewer,type:t};this._viewer.fire(t,i)}))),e.push(Ve(this._navigator.stateService.inMotion$,this._container.mouseService.active$,this._container.touchService.active$).pipe(De((e=>e[0]||e[1]||e[2])),vt()).subscribe((e=>{const t=e?"movestart":"moveend",i={target:this._viewer,type:t};this._viewer.fire(t,i)}))),e.push(this._container.renderService.bearing$.pipe(ot(100),vt(((e,t)=>Math.abs(t-e)<1))).subscribe((e=>{const t="bearing",i={bearing:e,target:this._viewer,type:t};this._viewer.fire(t,i)})));const t=this._container.mouseService.active$.pipe(zt((e=>e?ie():this._container.mouseService.mouseMove$)));e.push(it(this._mapMouseEvent$("click",this._container.mouseService.staticClick$),this._mapMouseEvent$("contextmenu",this._container.mouseService.contextMenu$),this._mapMouseEvent$("dblclick",this._container.mouseService.dblClick$),this._mapMouseEvent$("mousedown",this._container.mouseService.mouseDown$),this._mapMouseEvent$("mousemove",t),this._mapMouseEvent$("mouseout",this._container.mouseService.mouseOut$),this._mapMouseEvent$("mouseover",this._container.mouseService.mouseOver$),this._mapMouseEvent$("mouseup",this._container.mouseService.mouseUp$)).pipe(Vt(this._container.renderService.renderCamera$,this._navigator.stateService.reference$,this._navigator.stateService.currentTransform$,this._navigator.stateService.state$),De((([[e,t],i,n,r,s])=>{const a=this._projection.eventToUnprojection(t,this._container.container,i,n,r);return{basicPoint:s===Df.Traversing?a.basicPoint:null,lngLat:a.lngLat,originalEvent:t,pixelPoint:a.pixelPoint,target:this._viewer,type:e}}))).subscribe((e=>{this._viewer.fire(e.type,e)}))),e.push(this._container.renderService.renderCamera$.pipe(vt((([e,t],[i,n])=>this._closeTo(e,i,.01)&&this._closeTo(t,n,.01)),(e=>e.camera.position.toArray()))).subscribe((()=>{const e="position",t={target:this._viewer,type:e};this._viewer.fire(e,t)}))),e.push(this._container.renderService.renderCamera$.pipe(vt((([e,t],[i,n])=>this._closeTo(e,i,.001)&&this._closeTo(t,n,.001)),(e=>[e.rotation.phi,e.rotation.theta]))).subscribe((()=>{const e={target:this._viewer,type:"pov"};this._viewer.fire("pov",e)}))),e.push(this._container.renderService.renderCamera$.pipe(vt(((e,t)=>this._closeTo(e,t,.01)),(e=>e.perspective.fov))).subscribe((()=>{const e={target:this._viewer,type:"fov"};this._viewer.fire("fov",e)})))}stopEmit(){this.started&&(this._emitSubscriptions.unsubscribe(),this._started=!1)}unproject$(e){return Ve(this._container.renderService.renderCamera$,this._navigator.stateService.reference$,this._navigator.stateService.currentTransform$).pipe(St(),De((([t,i,n])=>this._projection.canvasToUnprojection(e,this._container.container,t,i,n).lngLat)))}unprojectBasic$(e){return Ve(this._container.renderService.renderCamera$,this._navigator.stateService.currentTransform$).pipe(St(),De((([t,i])=>this._projection.canvasToBasic(e,this._container.container,t,i))))}_closeTo(e,t,i){return Math.abs(e-t)<=i}_mapMouseEvent$(e,t){return t.pipe(De((t=>[e,t])))}}class pM{constructor(e,t){this._container=e,this._navigator=t,this._renderers={}}add(e,t){const i=new rf;this._renderers[e.id]={subs:i,renderer:e},i.push(Ve([this._container.glRenderer.webGLRenderer$,this._navigator.stateService.reference$]).pipe(_t(1)).subscribe((([i,n])=>{e.onAdd(t,n,i.getContext())}))),i.push(this._container.glRenderer.opaqueRender$.pipe(Vt(this._container.renderService.renderCamera$,this._container.glRenderer.webGLRenderer$)).subscribe((([,t,i])=>{const n=i.getContext(),r=t.perspective.matrixWorldInverse,s=t.perspective.projectionMatrix;e.render(n,r.toArray(),s.toArray())}))),i.push(this._navigator.stateService.reference$.pipe($t(1)).subscribe((i=>{e.onReference(t,i)})))}dispose(e){for(const t of Object.keys(this._renderers))this.remove(t,e)}has(e){return e in this._renderers}remove(e,t){this._renderers[e].subs.unsubscribe();const i=this._renderers[e].renderer;delete this._renderers[e],this._container.glRenderer.webGLRenderer$.subscribe((e=>{i.onRemove(t,e.getContext())}))}}class mM{constructor(e,t){this._container=e,this._navigator=t,this._controls=null,this._subscriptions=new rf}attach(e,t){if(this._controls)throw new Pu("Custom camera controls already attached");this._controls=e;const i=new j,n=i.pipe(zt((()=>this._navigator.stateService.state$)),De((e=>e===Df.Custom)),vt()),r=this._subscriptions;r.push(n.pipe(Ot(!1),At(),Vt(this._navigator.stateService.reference$,this._container.renderService.renderCamera$)).subscribe((([[i,n],r,s])=>{n?e.onActivate(t,s.perspective.matrixWorldInverse.toArray(),s.perspective.projectionMatrix.toArray(),r):i&&e.onDeactivate(t)}))),r.push(n.pipe(zt((e=>e?this._navigator.stateService.currentState$.pipe($t(1)):ie()))).subscribe((i=>{e.onAnimationFrame(t,i.id)}))),r.push(n.pipe(zt((e=>e?this._navigator.stateService.reference$.pipe($t(1)):ie()))).subscribe((i=>e.onReference(t,i)))),r.push(n.pipe(zt((e=>e?this._container.renderService.size$.pipe($t(1)):ie()))).subscribe((()=>e.onResize(t)))),r.push(Ve([this._container.glRenderer.webGLRenderer$,this._container.renderService.renderCamera$,this._navigator.stateService.reference$,this._navigator.stateService.state$]).pipe(St()).subscribe((()=>{e.onAttach(t,(t=>{this._controls&&e===this._controls&&this._updateViewMatrix(t)}),(t=>{this._controls&&e===this._controls&&this._updateProjectionMatrix(t)})),i.next(),i.complete()})))}detach(e){const t=this._controls;return this._controls=null,this._subscriptions.unsubscribe(),new Promise((i=>{this._navigator.stateService.state$.pipe(_t(1)).subscribe((n=>{t?(n===Df.Custom&&t.onDeactivate(e),t.onDetach(e),i(t)):i(null)}))}))}dispose(e){this.detach(e)}has(e){return!!this._controls&&e===this._controls}_updateProjectionMatrix(e){this._navigator.stateService.state$.pipe(St()).subscribe((t=>{if(t===Df.Custom)this._container.renderService.projectionMatrix$.next(e);else{const e="Incorrect camera control mode for projection matrix update";console.warn(e)}}))}_updateViewMatrix(e){this._navigator.stateService.state$.pipe(St()).subscribe((t=>{if(t===Df.Custom)this._navigator.stateService.setViewMatrix(e);else{const e="Incorrect camera control mode for view matrix update";console.warn(e)}}))}}Uu.register(ad),Vu.register(ad),od.registerCover(af),od.register(of),od.register(cf),od.register(lf),od.register(mf),od.register(Of),od.register(Hf),od.register(Gf),od.register(ag),od.register(hg),od.register(lg),od.register(mg),od.register(zg),od.register(Uv),od.register(Vv),od.register(Hv),od.register(jv),e.ArgumentMapillaryError=Lu,e.BearingComponent=cf,e.CacheComponent=lf,e.CancelMapillaryError=uf,e.CircleMarker=class extends Sw{constructor(e,t,i){super(e,t),i=i||{},this._color=null!=i.color?i.color:16777215,this._opacity=null!=i.opacity?i.opacity:.4,this._radius=null!=i.radius?i.radius:1}_createGeometry(e){const t=new es(new nc(this._radius,16),new wr({color:this._color,opacity:this._opacity,transparent:!0}));t.up.fromArray([0,0,1]),t.renderOrder=-1;const i=new tr;i.add(t),i.position.fromArray(e),this._geometry=i}_disposeGeometry(){for(let e of this._geometry.children)e.geometry.dispose(),e.material.dispose()}_getInteractiveObjects(){return[]}},e.Component=sf,e.DataProviderBase=gw,e.DirectionComponent=mf,e.DragPanHandler=ig,e.EventEmitter=nf,e.ExtremePointTag=Tv,e.Geometry=Fg,e.GeometryProviderBase=_w,e.GeometryTagError=Bg,e.GraphDataProvider=Mw,e.GraphMapillaryError=Bu,e.Image=Su,e.KeyPlayHandler=Vf,e.KeySequenceNavigationHandler=Ff,e.KeySpatialNavigationHandler=Bf,e.KeyZoomHandler=Uf,e.KeyboardComponent=Hf,e.MapillaryError=Pu,e.Marker=Sw,e.MarkerComponent=Gf,e.OutlineTag=Ev,e.PointGeometry=Pv,e.PointerComponent=ag,e.PointsGeometry=Ug,e.PolygonGeometry=dv,e.Popup=class{constructor(e,t,i){this._options={},e=e||{},this._options.capturePointer=!1!==e.capturePointer||e.capturePointer,this._options.clean=e.clean,this._options.float=e.float,this._options.offset=e.offset,this._options.opacity=e.opacity,this._options.position=e.position,this._dom=i||new og,this._viewportCoords=t||new hf,this._notifyChanged$=new j}get changed$(){return this._notifyChanged$}remove(){this._content&&this._content.parentNode&&this._content.parentNode.removeChild(this._content),this._container&&(this._container.parentNode.removeChild(this._container),delete this._container),this._parentContainer&&delete this._parentContainer}setBasicPoint(e){this._point=e.slice(),this._rect=null,this._notifyChanged$.next(this)}setBasicRect(e){this._rect=e.slice(),this._point=null,this._notifyChanged$.next(this)}setDOMContent(e){this._content&&this._content.parentNode&&this._content.parentNode.removeChild(this._content);const t="mapillary-popup-content"+(!0===this._options.clean?"-clean":"")+(!0===this._options.capturePointer?" mapillary-popup-capture-pointer":"");this._content=this._dom.createElement("div",t,this._container),this._content.appendChild(e),this._notifyChanged$.next(this)}setHTML(e){const t=this._dom.document.createDocumentFragment(),i=this._dom.createElement("body");let n;for(i.innerHTML=e;n=i.firstChild,n;)t.appendChild(n);this.setDOMContent(t)}setText(e){this.setDOMContent(this._dom.document.createTextNode(e))}setParentContainer(e){this._parentContainer=e}update(t,i,n){if(!this._parentContainer||!this._content)return;if(!this._point&&!this._rect)return;if(!this._container){this._container=this._dom.createElement("div","mapillary-popup",this._parentContainer);if(!0!==this._options.clean&&this._options.float!==e.Alignment.Center){const e="mapillary-popup-tip"+(!0===this._options.capturePointer?" mapillary-popup-capture-pointer":"");this._tip=this._dom.createElement("div",e,this._container),this._dom.createElement("div","mapillary-popup-tip-inner",this._tip)}this._container.appendChild(this._content),this._parentContainer.appendChild(this._container),null!=this._options.opacity&&(this._container.style.opacity=this._options.opacity.toString())}let r=null,s=this._alignmentToPopupAligment(this._options.position),a=this._alignmentToPopupAligment(this._options.float);const o=this._container.classList;if(null!=this._point)r=this._viewportCoords.basicToCanvasSafe(this._point[0],this._point[1],{offsetHeight:i.height,offsetWidth:i.width},n,t.perspective);else{const e=["center","top","bottom","left","right","top-left","top-right","bottom-left","bottom-right"];let h=null;for(const t of e)if(o.contains(`mapillary-popup-float-${t}`)){h=t;break}[r,s]=this._rectToPixel(this._rect,s,h,t,i,n),a||(a=s)}if(null==r)return void(this._container.style.display="none");if(this._container.style.display="",!a){const e=this._container.offsetWidth,t=this._container.offsetHeight,n=this._pixelToFloats(r,i,e,t);a=0===n.length?"top":n.join("-")}const h=this._normalizeOffset(this._options.offset);r=[r[0]+h[a][0],r[1]+h[a][1]],r=[Math.round(r[0]),Math.round(r[1])];const c={bottom:"translate(-50%,0)","bottom-left":"translate(-100%,0)","bottom-right":"translate(0,0)",center:"translate(-50%,-50%)",left:"translate(-100%,-50%)",right:"translate(0,-50%)",top:"translate(-50%,-100%)","top-left":"translate(-100%,-100%)","top-right":"translate(0,-100%)"};for(const e in c)c.hasOwnProperty(e)&&o.remove(`mapillary-popup-float-${e}`);o.add(`mapillary-popup-float-${a}`),this._container.style.transform=`${c[a]} translate(${r[0]}px,${r[1]}px)`}_rectToPixel(e,t,i,n,r,s){if(!t){const t=this._container.offsetWidth,a=this._container.offsetHeight,o={bottom:[0,a/2],"bottom-left":[-t/2,a/2],"bottom-right":[t/2,a/2],left:[-t/2,0],right:[t/2,0],top:[0,-a/2],"top-left":[-t/2,-a/2],"top-right":[t/2,-a/2]},h=["top","bottom","left","right"];let c=[0,null,null];for(const l of h){const h=this._pointFromRectPosition(e,l),u=this._viewportCoords.basicToCanvasSafe(h[0],h[1],{offsetHeight:r.height,offsetWidth:r.width},s,n.perspective);if(null==u)continue;const d=o[l],p=[u[0]+d[0],u[1]+d[1]],m=null!=i&&i===l?1:.7;if(0===this._pixelToFloats(p,r,t/m,a/(2*m)).length&&u[0]>0&&u[0]<r.width&&u[1]>0&&u[1]<r.height)return[u,l];const f=Math.max(p[0]-t/2,0),g=Math.min(p[0]+t/2,r.width),_=Math.max(p[1]-a/2,0),v=Math.min(p[1]+a/2,r.height),y=m*Math.max(0,g-f)*Math.max(0,v-_);y>c[0]&&(c[0]=y,c[1]=u,c[2]=l)}if(c[0]>0)return[c[1],c[2]]}const a=this._pointFromRectPosition(e,t);return[this._viewportCoords.basicToCanvasSafe(a[0],a[1],{offsetHeight:r.height,offsetWidth:r.width},s,n.perspective),null!=t?t:"top"]}_alignmentToPopupAligment(t){switch(t){case e.Alignment.Bottom:return"bottom";case e.Alignment.BottomLeft:return"bottom-left";case e.Alignment.BottomRight:return"bottom-right";case e.Alignment.Center:return"center";case e.Alignment.Left:return"left";case e.Alignment.Right:return"right";case e.Alignment.Top:return"top";case e.Alignment.TopLeft:return"top-left";case e.Alignment.TopRight:return"top-right";default:return null}}_normalizeOffset(e){if(null==e)return this._normalizeOffset(0);if("number"==typeof e){const t=e,i=(t>=0?1:-1)*Math.round(Math.sqrt(.5*Math.pow(t,2)));return{bottom:[0,t],"bottom-left":[-i,i],"bottom-right":[i,i],center:[0,0],left:[-t,0],right:[t,0],top:[0,-t],"top-left":[-i,-i],"top-right":[i,-i]}}return{bottom:e.bottom||[0,0],"bottom-left":e.bottomLeft||[0,0],"bottom-right":e.bottomRight||[0,0],center:e.center||[0,0],left:e.left||[0,0],right:e.right||[0,0],top:e.top||[0,0],"top-left":e.topLeft||[0,0],"top-right":e.topRight||[0,0]}}_pixelToFloats(e,t,i,n){const r=[];return e[1]<n?r.push("bottom"):e[1]>t.height-n&&r.push("top"),e[0]<i/2?r.push("right"):e[0]>t.width-i/2&&r.push("left"),r}_pointFromRectPosition(e,t){const i=e[0],n=e[0]<e[2]?e[2]:e[2]+1,r=e[1],s=e[3];switch(t){case"bottom":return[(i+n)/2,s];case"bottom-left":return[i,s];case"bottom-right":return[n,s];case"center":return[(i+n)/2,(r+s)/2];case"left":return[i,(r+s)/2];case"right":return[n,(r+s)/2];case"top":return[(i+n)/2,r];case"top-left":return[i,r];case"top-right":return[n,r];default:return[(i+n)/2,s]}}},e.PopupComponent=hg,e.RectGeometry=lv,e.S2GeometryProvider=bw,e.ScrollZoomHandler=rg,e.SequenceComponent=lg,e.SimpleMarker=class extends Sw{constructor(e,t,i){super(e,t),i=i||{},this._ballColor=null!=i.ballColor?i.ballColor:16711680,this._ballOpacity=null!=i.ballOpacity?i.ballOpacity:.8,this._circleToRayAngle=2,this._color=null!=i.color?i.color:16711680,this._interactive=!!i.interactive,this._opacity=null!=i.opacity?i.opacity:.4,this._radius=null!=i.radius?i.radius:1}_createGeometry(e){const t=this._radius,i=this._markerHeight(t),n=new wr({color:this._color,opacity:this._opacity,transparent:!0,depthWrite:!1}),r=new es(this._createMarkerGeometry(t,8,8),n),s=new es(new nl(t/2,8,8),new wr({color:this._ballColor,opacity:this._ballOpacity,transparent:!0}));s.position.z=i,s.renderOrder=1;const a=new tr;a.add(s),a.add(r),a.position.fromArray(e),this._geometry=a}_disposeGeometry(){for(const e of this._geometry.children)e.geometry.dispose(),e.material.dispose()}_getInteractiveObjects(){return this._interactive?[this._geometry.children[0]]:[]}_markerHeight(e){const t=Math.tan(Math.PI-this._circleToRayAngle);return e*Math.sqrt(1+t*t)}_createMarkerGeometry(e,t,i){const n=this._markerHeight(e),r=this._circleToRayAngle,s=[],a=new Float32Array(3*(t+1)*(i+1));let o=0;for(let h=0;h<=i;++h){const c=[];for(let s=0;s<=t;++s){const l=s/t*Math.PI*2,u=h/i*Math.PI;let d=e;if(u>r){const t=Math.tan(u-r);d=e*Math.sqrt(1+t*t)}const p=3*o,m=Math.sin(u);a[p+0]=d*Math.cos(l)*m,a[p+1]=d*Math.sin(l)*m,a[p+2]=d*Math.cos(u)+n,c.push(o++)}s.push(c)}const h=new Uint16Array(6*t*i);let c=0;for(let e=0;e<i;++e)for(let i=0;i<t;++i){const t=s[e][i+1],n=s[e][i],r=s[e+1][i],a=s[e+1][i+1];h[c++]=t,h[c++]=n,h[c++]=a,h[c++]=n,h[c++]=r,h[c++]=a}const l=new kr,u=new Tr(a,3);return l.setAttribute("position",u),l.setIndex(new Tr(h,1)),l}},e.SliderComponent=mg,e.SpatialComponent=zg,e.SpotTag=Iv,e.Tag=Sv,e.TagComponent=Uv,e.TouchZoomHandler=sg,e.VertexGeometry=cv,e.Viewer=class extends nf{constructor(e){super(),this._navigator=new lM(e),this._container=new jw(e,this._navigator.stateService),this._observer=new dM(this,this._navigator,this._container),this._componentController=new Pw(this._container,this._navigator,this._observer,e.imageId,e.component),this._customRenderer=new pM(this._container,this._navigator),this._customCameraControls=new mM(this._container,this._navigator)}get dataProvider(){return this._navigator.api.data}get isNavigable(){return this._componentController.navigable}activateCombinedPanning(){this._navigator.panService.enable()}activateComponent(e){this._componentController.activate(e)}activateCover(){this._componentController.activateCover()}addCustomRenderer(e){this._customRenderer.add(e,this)}attachCustomCameraControls(e){this._customCameraControls.attach(e,this)}deactivateCombinedPanning(){this._navigator.panService.disable()}deactivateComponent(e){this._componentController.deactivate(e)}deactivateCover(){this._componentController.deactivateCover()}detachCustomCameraControls(){return this._customCameraControls.detach(this)}fire(e,t){super.fire(e,t)}getBearing(){return new Promise(((e,t)=>{this._container.renderService.bearing$.pipe(St()).subscribe((t=>{e(t)}),(e=>{t(e)}))}))}getCameraControls(){return new Promise(((t,i)=>{this._navigator.stateService.state$.pipe(St()).subscribe((i=>{switch(i){case Df.Custom:t(e.CameraControls.Custom);break;case Df.Earth:t(e.CameraControls.Earth);break;default:t(e.CameraControls.Street)}}),(e=>{i(e)}))}))}getCanvas(){return this._container.canvas}getCanvasContainer(){return this._container.canvasContainer}getCenter(){return new Promise(((e,t)=>{this._navigator.stateService.getCenter().subscribe((t=>{e(t)}),(e=>{t(e)}))}))}getComponent(e){return this._componentController.get(e)}getContainer(){return this._container.container}getFieldOfView(){return new Promise(((e,t)=>{this._container.renderService.renderCamera$.pipe(St()).subscribe((t=>{e(t.perspective.fov)}),(e=>{t(e)}))}))}getImage(){return new Promise(((e,t)=>{this._navigator.stateService.currentImage$.pipe(St()).subscribe((t=>{e(t)}),(e=>{t(e)}))}))}getPointOfView(){return new Promise(((e,t)=>{Ve(this._container.renderService.renderCamera$,this._container.renderService.bearing$).pipe(St()).subscribe((([t,i])=>{e({bearing:i,tilt:t.getTilt()})}),(e=>{t(e)}))}))}getPosition(){return new Promise(((e,t)=>{Ve(this._container.renderService.renderCamera$,this._navigator.stateService.reference$).pipe(St()).subscribe((([t,i])=>{e(this._observer.projection.cameraToLngLat(t,i))}),(e=>{t(e)}))}))}getReference(){return new Promise(((e,t)=>{this._navigator.stateService.reference$.pipe(St()).subscribe((t=>{e(t)}),(e=>{t(e)}))}))}getZoom(){return new Promise(((e,t)=>{this._navigator.stateService.getZoom().subscribe((t=>{e(t)}),(e=>{t(e)}))}))}hasCustomCameraControls(e){return this._customCameraControls.has(e)}hasCustomRenderer(e){return this._customRenderer.has(e)}moveDir(e){const t=this.isNavigable?this._navigator.moveDir$(e):Ee(new Error("Calling moveDir is not supported when viewer is not navigable."));return new Promise(((e,i)=>{t.subscribe((t=>{e(t)}),(e=>{i(e)}))}))}moveTo(e){const t=this.isNavigable?this._navigator.moveTo$(e):Ee(new Error("Calling moveTo is not supported when viewer is not navigable."));return new Promise(((e,i)=>{t.subscribe((t=>{e(t)}),(e=>{i(e)}))}))}off(e,t){super.off(e,t)}on(e,t){super.on(e,t)}project(e){return new Promise(((t,i)=>{this._observer.project$(e).subscribe((e=>{t(e)}),(e=>{i(e)}))}))}projectFromBasic(e){return new Promise(((t,i)=>{this._observer.projectBasic$(e).subscribe((e=>{t(e)}),(e=>{i(e)}))}))}remove(){this._customRenderer.dispose(this),this._customCameraControls.dispose(this),this._observer.dispose(),this._componentController.remove(),this._navigator.dispose(),this._container.remove();const e="remove",t={target:this,type:e};this.fire(e,t)}removeCustomRenderer(e){this._customRenderer.remove(e,this)}resize(){this._container.renderService.resize$.next()}setCameraControls(e){const t=cM(e);t===Df.Traversing?this._navigator.stateService.traverse():t===Df.Earth?this._navigator.stateService.earth():t===Df.Custom?this._navigator.stateService.custom():console.warn(`Unsupported camera control transition (${e})`)}setCenter(e){this._navigator.stateService.setCenter(e)}setFieldOfView(e){this._container.renderService.renderCamera$.pipe(St()).subscribe((t=>{const i=t.fovToZoom(e);this._navigator.stateService.setZoom(i)}))}setFilter(e){return new Promise(((t,i)=>{this._navigator.setFilter$(e).subscribe((()=>{t(void 0)}),(e=>{i(e)}))}))}setRenderMode(e){this._container.renderService.renderMode$.next(e)}setTransitionMode(e){this._navigator.stateService.setTransitionMode(e)}setAccessToken(e){const t=this.isNavigable?this._navigator.setAccessToken$(e):Ee(new Error("Calling setAccessToken is not supported when viewer is not navigable."));return new Promise(((e,i)=>{t.subscribe((()=>{e(void 0)}),(e=>{i(e)}))}))}setZoom(e){this._navigator.stateService.setZoom(e)}triggerRerender(){this._container.glRenderer.triggerRerender()}unproject(e){return new Promise(((t,i)=>{this._observer.unproject$(e).subscribe((e=>{t(e)}),(e=>{i(e)}))}))}unprojectToBasic(e){return new Promise(((t,i)=>{this._observer.unprojectBasic$(e).subscribe((e=>{t(e)}),(e=>{i(e)}))}))}},e.ZoomComponent=Vv,e.decompress=uw,e.ecefToEnu=yu,e.ecefToGeodetic=wu,e.enuToEcef=bu,e.enuToGeodetic=vu,e.fetchArrayBuffer=dw,e.geodeticToEcef=xu,e.geodeticToEnu=_u,e.isFallbackSupported=Ew,e.isSupported=function(){return Ew()&&Cw()},e.readMeshPbf=mw,Object.defineProperty(e,"__esModule",{value:!0})}));
+!function(t,i){e&&e.exports?e.exports=i():(t.dcodeIO=t.dcodeIO||{}).Long=i()}(hd,(function(){function e(e,t,i){this.low=0|e,this.high=0|t,this.unsigned=!!i}function t(e){return!0===(e&&e.__isLong__)}e.prototype.__isLong__,Object.defineProperty(e.prototype,"__isLong__",{value:!0,enumerable:!1,configurable:!1}),e.isLong=t;var i={},n={};function r(e,t){var r,s,o;return t?(o=0<=(e>>>=0)&&e<256)&&(s=n[e])?s:(r=a(e,(0|e)<0?-1:0,!0),o&&(n[e]=r),r):(o=-128<=(e|=0)&&e<128)&&(s=i[e])?s:(r=a(e,e<0?-1:0,!1),o&&(i[e]=r),r)}function s(e,t){if(isNaN(e)||!isFinite(e))return t?f:m;if(t){if(e<0)return f;if(e>=u)return b}else{if(e<=-d)return x;if(e+1>=d)return y}return e<0?s(-e,t).neg():a(e%l|0,e/l|0,t)}function a(t,i,n){return new e(t,i,n)}e.fromInt=r,e.fromNumber=s,e.fromBits=a;var o=Math.pow;function h(e,t,i){if(0===e.length)throw Error("empty string");if("NaN"===e||"Infinity"===e||"+Infinity"===e||"-Infinity"===e)return m;if("number"==typeof t?(i=t,t=!1):t=!!t,(i=i||10)<2||36<i)throw RangeError("radix");var n;if((n=e.indexOf("-"))>0)throw Error("interior hyphen");if(0===n)return h(e.substring(1),t,i).neg();for(var r=s(o(i,8)),a=m,c=0;c<e.length;c+=8){var l=Math.min(8,e.length-c),u=parseInt(e.substring(c,c+l),i);if(l<8){var d=s(o(i,l));a=a.mul(d).add(s(u))}else a=(a=a.mul(r)).add(s(u))}return a.unsigned=t,a}function c(t){return t instanceof e?t:"number"==typeof t?s(t):"string"==typeof t?h(t):a(t.low,t.high,t.unsigned)}e.fromString=h,e.fromValue=c;var l=4294967296,u=l*l,d=u/2,p=r(1<<24),m=r(0);e.ZERO=m;var f=r(0,!0);e.UZERO=f;var g=r(1);e.ONE=g;var _=r(1,!0);e.UONE=_;var v=r(-1);e.NEG_ONE=v;var y=a(-1,2147483647,!1);e.MAX_VALUE=y;var b=a(-1,-1,!0);e.MAX_UNSIGNED_VALUE=b;var x=a(0,-2147483648,!1);e.MIN_VALUE=x;var w=e.prototype;return w.toInt=function(){return this.unsigned?this.low>>>0:this.low},w.toNumber=function(){return this.unsigned?(this.high>>>0)*l+(this.low>>>0):this.high*l+(this.low>>>0)},w.toString=function(e){if((e=e||10)<2||36<e)throw RangeError("radix");if(this.isZero())return"0";if(this.isNegative()){if(this.eq(x)){var t=s(e),i=this.div(t),n=i.mul(t).sub(this);return i.toString(e)+n.toInt().toString(e)}return"-"+this.neg().toString(e)}for(var r=s(o(e,6),this.unsigned),a=this,h="";;){var c=a.div(r),l=(a.sub(c.mul(r)).toInt()>>>0).toString(e);if((a=c).isZero())return l+h;for(;l.length<6;)l="0"+l;h=""+l+h}},w.getHighBits=function(){return this.high},w.getHighBitsUnsigned=function(){return this.high>>>0},w.getLowBits=function(){return this.low},w.getLowBitsUnsigned=function(){return this.low>>>0},w.getNumBitsAbs=function(){if(this.isNegative())return this.eq(x)?64:this.neg().getNumBitsAbs();for(var e=0!=this.high?this.high:this.low,t=31;t>0&&0==(e&1<<t);t--);return 0!=this.high?t+33:t+1},w.isZero=function(){return 0===this.high&&0===this.low},w.isNegative=function(){return!this.unsigned&&this.high<0},w.isPositive=function(){return this.unsigned||this.high>=0},w.isOdd=function(){return 1==(1&this.low)},w.isEven=function(){return 0==(1&this.low)},w.equals=function(e){return t(e)||(e=c(e)),(this.unsigned===e.unsigned||this.high>>>31!=1||e.high>>>31!=1)&&(this.high===e.high&&this.low===e.low)},w.eq=w.equals,w.notEquals=function(e){return!this.eq(e)},w.neq=w.notEquals,w.lessThan=function(e){return this.comp(e)<0},w.lt=w.lessThan,w.lessThanOrEqual=function(e){return this.comp(e)<=0},w.lte=w.lessThanOrEqual,w.greaterThan=function(e){return this.comp(e)>0},w.gt=w.greaterThan,w.greaterThanOrEqual=function(e){return this.comp(e)>=0},w.gte=w.greaterThanOrEqual,w.compare=function(e){if(t(e)||(e=c(e)),this.eq(e))return 0;var i=this.isNegative(),n=e.isNegative();return i&&!n?-1:!i&&n?1:this.unsigned?e.high>>>0>this.high>>>0||e.high===this.high&&e.low>>>0>this.low>>>0?-1:1:this.sub(e).isNegative()?-1:1},w.comp=w.compare,w.negate=function(){return!this.unsigned&&this.eq(x)?x:this.not().add(g)},w.neg=w.negate,w.add=function(e){t(e)||(e=c(e));var i=this.high>>>16,n=65535&this.high,r=this.low>>>16,s=65535&this.low,o=e.high>>>16,h=65535&e.high,l=e.low>>>16,u=0,d=0,p=0,m=0;return p+=(m+=s+(65535&e.low))>>>16,d+=(p+=r+l)>>>16,u+=(d+=n+h)>>>16,u+=i+o,a((p&=65535)<<16|(m&=65535),(u&=65535)<<16|(d&=65535),this.unsigned)},w.subtract=function(e){return t(e)||(e=c(e)),this.add(e.neg())},w.sub=w.subtract,w.multiply=function(e){if(this.isZero())return m;if(t(e)||(e=c(e)),e.isZero())return m;if(this.eq(x))return e.isOdd()?x:m;if(e.eq(x))return this.isOdd()?x:m;if(this.isNegative())return e.isNegative()?this.neg().mul(e.neg()):this.neg().mul(e).neg();if(e.isNegative())return this.mul(e.neg()).neg();if(this.lt(p)&&e.lt(p))return s(this.toNumber()*e.toNumber(),this.unsigned);var i=this.high>>>16,n=65535&this.high,r=this.low>>>16,o=65535&this.low,h=e.high>>>16,l=65535&e.high,u=e.low>>>16,d=65535&e.low,f=0,g=0,_=0,v=0;return _+=(v+=o*d)>>>16,g+=(_+=r*d)>>>16,_&=65535,g+=(_+=o*u)>>>16,f+=(g+=n*d)>>>16,g&=65535,f+=(g+=r*u)>>>16,g&=65535,f+=(g+=o*l)>>>16,f+=i*d+n*u+r*l+o*h,a((_&=65535)<<16|(v&=65535),(f&=65535)<<16|(g&=65535),this.unsigned)},w.mul=w.multiply,w.divide=function(e){if(t(e)||(e=c(e)),e.isZero())throw Error("division by zero");if(this.isZero())return this.unsigned?f:m;var i,n,r;if(this.unsigned){if(e.unsigned||(e=e.toUnsigned()),e.gt(this))return f;if(e.gt(this.shru(1)))return _;r=f}else{if(this.eq(x))return e.eq(g)||e.eq(v)?x:e.eq(x)?g:(i=this.shr(1).div(e).shl(1)).eq(m)?e.isNegative()?g:v:(n=this.sub(e.mul(i)),r=i.add(n.div(e)));if(e.eq(x))return this.unsigned?f:m;if(this.isNegative())return e.isNegative()?this.neg().div(e.neg()):this.neg().div(e).neg();if(e.isNegative())return this.div(e.neg()).neg();r=m}for(n=this;n.gte(e);){i=Math.max(1,Math.floor(n.toNumber()/e.toNumber()));for(var a=Math.ceil(Math.log(i)/Math.LN2),h=a<=48?1:o(2,a-48),l=s(i),u=l.mul(e);u.isNegative()||u.gt(n);)u=(l=s(i-=h,this.unsigned)).mul(e);l.isZero()&&(l=g),r=r.add(l),n=n.sub(u)}return r},w.div=w.divide,w.modulo=function(e){return t(e)||(e=c(e)),this.sub(this.div(e).mul(e))},w.mod=w.modulo,w.not=function(){return a(~this.low,~this.high,this.unsigned)},w.and=function(e){return t(e)||(e=c(e)),a(this.low&e.low,this.high&e.high,this.unsigned)},w.or=function(e){return t(e)||(e=c(e)),a(this.low|e.low,this.high|e.high,this.unsigned)},w.xor=function(e){return t(e)||(e=c(e)),a(this.low^e.low,this.high^e.high,this.unsigned)},w.shiftLeft=function(e){return t(e)&&(e=e.toInt()),0==(e&=63)?this:e<32?a(this.low<<e,this.high<<e|this.low>>>32-e,this.unsigned):a(0,this.low<<e-32,this.unsigned)},w.shl=w.shiftLeft,w.shiftRight=function(e){return t(e)&&(e=e.toInt()),0==(e&=63)?this:e<32?a(this.low>>>e|this.high<<32-e,this.high>>e,this.unsigned):a(this.high>>e-32,this.high>=0?0:-1,this.unsigned)},w.shr=w.shiftRight,w.shiftRightUnsigned=function(e){if(t(e)&&(e=e.toInt()),0===(e&=63))return this;var i=this.high;return e<32?a(this.low>>>e|i<<32-e,i>>>e,this.unsigned):a(32===e?i:i>>>e-32,0,this.unsigned)},w.shru=w.shiftRightUnsigned,w.toSigned=function(){return this.unsigned?a(this.low,this.high,!1):this},w.toUnsigned=function(){return this.unsigned?this:a(this.low,this.high,!0)},w.toBytes=function(e){return e?this.toBytesLE():this.toBytesBE()},w.toBytesLE=function(){var e=this.high,t=this.low;return[255&t,t>>>8&255,t>>>16&255,t>>>24&255,255&e,e>>>8&255,e>>>16&255,e>>>24&255]},w.toBytesBE=function(){var e=this.high,t=this.low;return[e>>>24&255,e>>>16&255,e>>>8&255,255&e,t>>>24&255,t>>>16&255,t>>>8&255,255&t]},e}))}(yw),function(e){!function(e){var t=e.S2={L:{}};t.L.LatLng=function(e,t,i){var n=parseFloat(e,10),r=parseFloat(t,10);if(isNaN(n)||isNaN(r))throw new Error("Invalid LatLng object: ("+e+", "+t+")");return!0!==i&&(n=Math.max(Math.min(n,90),-90),r=(r+180)%360+(r<-180||180===r?180:-180)),{lat:n,lng:r}},t.L.LatLng.DEG_TO_RAD=Math.PI/180,t.L.LatLng.RAD_TO_DEG=180/Math.PI,t.LatLngToXYZ=function(e){var i=t.L.LatLng.DEG_TO_RAD,n=e.lat*i,r=e.lng*i,s=Math.cos(n);return[Math.cos(r)*s,Math.sin(r)*s,Math.sin(n)]},t.XYZToLatLng=function(e){var i=t.L.LatLng.RAD_TO_DEG,n=Math.atan2(e[2],Math.sqrt(e[0]*e[0]+e[1]*e[1])),r=Math.atan2(e[1],e[0]);return t.L.LatLng(n*i,r*i)};t.XYZToFaceUV=function(e){var t=function(e){var t=[Math.abs(e[0]),Math.abs(e[1]),Math.abs(e[2])];return t[0]>t[1]?t[0]>t[2]?0:2:t[1]>t[2]?1:2}(e);return e[t]<0&&(t+=3),[t,function(e,t){var i,n;switch(e){case 0:i=t[1]/t[0],n=t[2]/t[0];break;case 1:i=-t[0]/t[1],n=t[2]/t[1];break;case 2:i=-t[0]/t[2],n=-t[1]/t[2];break;case 3:i=t[2]/t[0],n=t[1]/t[0];break;case 4:i=t[2]/t[1],n=-t[0]/t[1];break;case 5:i=-t[1]/t[2],n=-t[0]/t[2];break;default:throw{error:"Invalid face"}}return[i,n]}(t,e)]},t.FaceUVToXYZ=function(e,t){var i=t[0],n=t[1];switch(e){case 0:return[1,i,n];case 1:return[-i,1,n];case 2:return[-i,-n,1];case 3:return[-1,-n,-i];case 4:return[n,-1,-i];case 5:return[n,i,-1];default:throw{error:"Invalid face"}}};var i=function(e){return e>=.5?1/3*(4*e*e-1):1/3*(1-4*(1-e)*(1-e))};t.STToUV=function(e){return[i(e[0]),i(e[1])]};var n=function(e){return e>=0?.5*Math.sqrt(1+3*e):1-.5*Math.sqrt(1-3*e)};t.UVToST=function(e){return[n(e[0]),n(e[1])]},t.STToIJ=function(e,t){var i=1<<t,n=function(e){var t=Math.floor(e*i);return Math.max(0,Math.min(i-1,t))};return[n(e[0]),n(e[1])]},t.IJToST=function(e,t,i){var n=1<<t;return[(e[0]+i[0])/n,(e[1]+i[1])/n]};var r=function(e,t,i,n){if(0==n){1==i&&(t.x=e-1-t.x,t.y=e-1-t.y);var r=t.x;t.x=t.y,t.y=r}},s=function(e,t,i,n){var r={a:[[0,"d"],[1,"a"],[3,"b"],[2,"a"]],b:[[2,"b"],[1,"b"],[3,"a"],[0,"c"]],c:[[2,"c"],[3,"d"],[1,"c"],[0,"b"]],d:[[0,"a"],[3,"c"],[1,"d"],[2,"d"]]};"number"!=typeof n&&console.warn(new Error("called pointToHilbertQuadList without face value, defaulting to '0'").stack);for(var s=n%2?"d":"a",a=[],o=i-1;o>=0;o--){var h=1<<o,c=r[s][2*(e&h?1:0)+(t&h?1:0)];a.push(c[0]),s=c[1]}return a};t.S2Cell=function(){},t.S2Cell.FromHilbertQuadKey=function(e){var i,n,s,a,o,h,c=e.split("/"),l=parseInt(c[0]),u=c[1],d=u.length,p={x:0,y:0};for(i=d-1;i>=0;i--)n=d-i,a=0,o=0,"1"===(s=u[i])?o=1:"2"===s?(a=1,o=1):"3"===s&&(a=1),h=Math.pow(2,n-1),r(h,p,a,o),p.x+=h*a,p.y+=h*o;if(l%2==1){var m=p.x;p.x=p.y,p.y=m}return t.S2Cell.FromFaceIJ(parseInt(l),[p.x,p.y],n)},t.S2Cell.FromLatLng=function(e,i){if(!e.lat&&0!==e.lat||!e.lng&&0!==e.lng)throw new Error("Pass { lat: lat, lng: lng } to S2.S2Cell.FromLatLng");var n=t.LatLngToXYZ(e),r=t.XYZToFaceUV(n),s=t.UVToST(r[1]),a=t.STToIJ(s,i);return t.S2Cell.FromFaceIJ(r[0],a,i)},t.S2Cell.FromFaceIJ=function(e,i,n){var r=new t.S2Cell;return r.face=e,r.ij=i,r.level=n,r},t.S2Cell.prototype.toString=function(){return"F"+this.face+"ij["+this.ij[0]+","+this.ij[1]+"]@"+this.level},t.S2Cell.prototype.getLatLng=function(){var e=t.IJToST(this.ij,this.level,[.5,.5]),i=t.STToUV(e),n=t.FaceUVToXYZ(this.face,i);return t.XYZToLatLng(n)},t.S2Cell.prototype.getCornerLatLngs=function(){for(var e=[],i=[[0,0],[0,1],[1,1],[1,0]],n=0;n<4;n++){var r=t.IJToST(this.ij,this.level,i[n]),s=t.STToUV(r),a=t.FaceUVToXYZ(this.face,s);e.push(t.XYZToLatLng(a))}return e},t.S2Cell.prototype.getFaceAndQuads=function(){var e=s(this.ij[0],this.ij[1],this.level,this.face);return[this.face,e]},t.S2Cell.prototype.toHilbertQuadkey=function(){var e=s(this.ij[0],this.ij[1],this.level,this.face);return this.face.toString(10)+"/"+e.join("")},t.latLngToNeighborKeys=t.S2Cell.latLngToNeighborKeys=function(e,i,n){return t.S2Cell.FromLatLng({lat:e,lng:i},n).getNeighbors().map((function(e){return e.toHilbertQuadkey()}))},t.S2Cell.prototype.getNeighbors=function(){var e=function(e,i,n){var r=1<<n;if(i[0]>=0&&i[1]>=0&&i[0]<r&&i[1]<r)return t.S2Cell.FromFaceIJ(e,i,n);var s=t.IJToST(i,n,[.5,.5]),a=t.STToUV(s),o=t.FaceUVToXYZ(e,a),h=t.XYZToFaceUV(o);return e=h[0],a=h[1],s=t.UVToST(a),i=t.STToIJ(s,n),t.S2Cell.FromFaceIJ(e,i,n)},i=this.face,n=this.ij[0],r=this.ij[1],s=this.level;return[e(i,[n-1,r],s),e(i,[n,r-1],s),e(i,[n+1,r],s),e(i,[n,r+1],s)]},t.FACE_BITS=3,t.MAX_LEVEL=30,t.POS_BITS=2*t.MAX_LEVEL+1,t.facePosLevelToId=t.S2Cell.facePosLevelToId=t.fromFacePosLevel=function(i,n,r){var s,a,o,h=e.dcodeIO&&e.dcodeIO.Long||yw.exports;for(r||(r=n.length),n.length>r&&(n=n.substr(0,r)),s=h.fromString(i.toString(10),!0,10).toString(2);s.length<t.FACE_BITS;)s="0"+s;for(a=h.fromString(n,!0,4).toString(2);a.length<2*r;)a="0"+a;for(o=s+a,o+="1";o.length<t.FACE_BITS+t.POS_BITS;)o+="0";return h.fromString(o,!0,2).toString(10)},t.keyToId=t.S2Cell.keyToId=t.toId=t.toCellId=t.fromKey=function(e){var i=e.split("/");return t.fromFacePosLevel(i[0],i[1],i[1].length)},t.idToKey=t.S2Cell.idToKey=t.S2Cell.toKey=t.toKey=t.fromId=t.fromCellId=t.S2Cell.toHilbertQuadkey=t.toHilbertQuadkey=function(i){for(var n=e.dcodeIO&&e.dcodeIO.Long||yw.exports,r=n.fromString(i,!0,10).toString(2);r.length<t.FACE_BITS+t.POS_BITS;)r="0"+r;for(var s=r.lastIndexOf("1"),a=r.substring(0,3),o=r.substring(3,s),h=o.length/2,c=n.fromString(a,!0,2).toString(10),l=n.fromString(o,!0,2).toString(4);l.length<h;)l="0"+l;return c+"/"+l},t.keyToLatLng=t.S2Cell.keyToLatLng=function(e){return t.S2Cell.FromHilbertQuadKey(e).getLatLng()},t.idToLatLng=t.S2Cell.idToLatLng=function(e){var i=t.idToKey(e);return t.keyToLatLng(i)},t.S2Cell.latLngToKey=t.latLngToKey=t.latLngToQuadkey=function(e,i,n){if(isNaN(n)||n<1||n>30)throw new Error("'level' is not a number between 1 and 30 (but it should be)");return t.S2Cell.FromLatLng({lat:e,lng:i},n).toHilbertQuadkey()},t.stepKey=function(t,i){var n,r=e.dcodeIO&&e.dcodeIO.Long||yw.exports,s=t.split("/"),a=s[0],o=s[1],h=s[1].length,c=r.fromString(o,!0,4);i>0?n=c.add(Math.abs(i)):i<0&&(n=c.subtract(Math.abs(i)));var l=n.toString(4);for("0"===l&&console.warning(new Error("face/position wrapping is not yet supported"));l.length<h;)l="0"+l;return a+"/"+l},t.S2Cell.prevKey=t.prevKey=function(e){return t.stepKey(e,-1)},t.S2Cell.nextKey=t.nextKey=function(e){return t.stepKey(e,1)}}(e.exports)}(vw);class bw extends _w{constructor(e=17){super(),this._level=e}bboxToCellIds(e,t){return this._approxBboxToCellIds(e,t)}getAdjacent(e){const t=vw.exports.S2.idToKey(e),i=t.split("/")[1].length,[n,r,s,a]=this._getNeighbors(t,i),o=[t,n,r,s,a],h=Array.from(new Set([...this._getNeighbors(n,i),...this._getNeighbors(r,i),...this._getNeighbors(s,i),...this._getNeighbors(a,i)].filter((e=>!o.includes(e))))),c=[n,r,s,a];for(const e of h){let t=0;for(const n of this._getNeighbors(e,i))o.includes(n)&&t++;2===t&&c.push(e)}return c.map((e=>vw.exports.S2.keyToId(e)))}getVertices(e){const t=vw.exports.S2.idToKey(e);return vw.exports.S2.S2Cell.FromHilbertQuadKey(t).getCornerLatLngs().map((e=>({lat:e.lat,lng:e.lng})))}lngLatToCellId(e){return this._lngLatToId(e,this._level)}_getNeighbors(e,t){const i=vw.exports.S2.keyToLatLng(e);return vw.exports.S2.latLngToNeighborKeys(i.lat,i.lng,t)}_lngLatToId(e,t){const i=vw.exports.S2.latLngToKey(e.lat,e.lng,t);return vw.exports.S2.keyToId(i)}}class xw{clusterReconstruction(e){const t=e.points,i=1/255;for(const e in t){if(!t.hasOwnProperty(e))continue;const n=t[e].color;n[0]*=i,n[1]*=i,n[2]*=i}const n=e.reference_lla;return{id:null,points:t,reference:{alt:n.altitude,lat:n.latitude,lng:n.longitude}}}coreImage(e){const t=this._geometry(e.geometry),i=this._geometry(e.computed_geometry),n={id:e.sequence};return{computed_geometry:i,geometry:t,id:e.id,sequence:n}}spatialImage(e){var t,i,n,r;e.camera_type=function(e){switch(e){case"equirectangular":case"spherical":return"spherical";case"fisheye":return"fisheye";default:return"perspective"}}(e.camera_type),e.merge_id=e.merge_cc?e.merge_cc.toString():null,e.private=null;const s="spherical"===e.camera_type?e.thumb_2048_url:e.thumb_1024_url;return e.thumb=null!==(t=e.thumb)&&void 0!==t?t:{id:null,url:s},e.cluster=null!==(i=e.sfm_cluster)&&void 0!==i?i:{id:null,url:null},e.creator={id:null,username:null},e.owner=null!==(n=e.organization)&&void 0!==n?n:{id:null},e.mesh=null!==(r=e.mesh)&&void 0!==r?r:{id:null,url:null},e}_geometry(e){const t=null==e?void 0:e.coordinates;return t?{lat:t[1],lng:t[0]}:null}}class ww{constructor(){this.imagesPath="images",this.sequencePath="image_ids",this._imageTilesPath="tiles",this.coreFields=["computed_geometry","geometry","sequence"],this.idFields=["id"],this.spatialFields=["altitude","atomic_scale","camera_parameters","camera_type","captured_at","compass_angle","computed_altitude","computed_compass_angle","computed_rotation","exif_orientation","height","merge_cc","mesh","organization","quality_score","sfm_cluster","thumb_1024_url","thumb_2048_url","width"],this.imageTileFields=["url","z","x","y"]}images(e,t){return`image_ids=${e.join(",")}&fields=${t.join(",")}`}imagesS2(e,t){return`s2=${e}&fields=${t.join(",")}`}imageTiles(e,t){return`z=${e}&fields=${t.join(",")}`}imageTilesPath(e){return`${e}/${this._imageTilesPath}`}sequence(e){return`sequence_id=${e}`}}class Mw extends gw{constructor(e,t,i,n){var r;super(null!=t?t:new bw),this._convert=null!=i?i:new xw,this._query=null!=n?n:new ww,this._method="GET";const s=null!=e?e:{};this._endpoint=null!==(r=s.endpoint)&&void 0!==r?r:"https://graph.mapillary.com",this._accessToken=s.accessToken}getCluster(e,t){return dw(e,t).then((e=>{const t=uw(e);if(t.length<1)throw new Error("Cluster reconstruction empty");return this._convert.clusterReconstruction(t[0])}))}getCoreImages(e){const t=[...this._query.idFields,...this._query.coreFields],i=this._query.imagesS2(e,t),n=new URL(this._query.imagesPath,this._endpoint).href;return this._fetchGraphContract(i,n).then((t=>{const i={cell_id:e,images:[]},n=t.data;for(const e of n){const t=this._convert.coreImage(e);i.images.push(t)}return i}))}getImageBuffer(e,t){return dw(e,t)}getImages(e){const t=[...this._query.idFields,...this._query.coreFields,...this._query.spatialFields],i=this._query.images(e,t),n=new URL(this._query.imagesPath,this._endpoint).href;return this._fetchGraphContract(i,n).then((e=>{const t=[],i=e.data;for(const e of i){const i=this._convert.coreImage(e),n=this._convert.spatialImage(e),r={node:Object.assign({},n,i),node_id:e.id};t.push(r)}return t}))}getImageTiles(e){const t=[...this._query.imageTileFields],i=this._query.imageTiles(e.z,t),n=new URL(this._query.imageTilesPath(e.imageId),this._endpoint).href;return this._fetchGraphContract(i,n).then((t=>({node:t.data,node_id:e.imageId})))}getMesh(e,t){return dw(e,t).then((e=>mw(e)))}getSequence(e){const t=this._query.sequence(e),i=new URL(this._query.sequencePath,this._endpoint).href;return this._fetchGraphContract(t,i).then((t=>({id:e,image_ids:t.data.map((e=>e.id))})))}getSpatialImages(e){const t=[...this._query.idFields,...this._query.coreFields,...this._query.spatialFields],i=this._query.images(e,t),n=new URL(this._query.imagesPath,this._endpoint).href;return this._fetchGraphContract(i,n).then((e=>{const t=[],i=e.data;for(const e of i){const i={node:this._convert.spatialImage(e),node_id:e.id};t.push(i)}return t}))}setAccessToken(e){this._accessToken=e}_createHeaders(){const e=[{name:"Accept",value:"application/json"},{name:"Content-Type",value:"application/x-www-form-urlencoded"}];return this._accessToken&&e.push({name:"Authorization",value:`OAuth ${this._accessToken}`}),e}_fetchGraphContract(e,t){return pw(`${t}?${e}`,this._method,"json",this._createHeaders(),null,null).catch((e=>{const t=this._makeErrorMessage(e);throw new Pu(t)}))}_makeErrorMessage(e){const t=e.error;return t?`${t.code} (${t.type}, ${t.fbtrace_id}): ${t.message}`:"Failed to fetch data"}}class Sw{constructor(e,t){this._id=e,this._lngLat=t}get id(){return this._id}get geometry(){return this._geometry}get lngLat(){return this._lngLat}createGeometry(e){this._geometry||(this._createGeometry(e),this._geometry.updateMatrixWorld(!0))}disposeGeometry(){this._geometry&&(this._disposeGeometry(),this._geometry=void 0)}getInteractiveObjects(){return this._geometry?this._getInteractiveObjects():[]}lerpAltitude(e,t){this._geometry&&(this._geometry.position.z=(1-t)*this._geometry.position.z+t*e)}updatePosition(e,t){t&&(this._lngLat.lat=t.lat,this._lngLat.lng=t.lng),this._geometry&&(this._geometry.position.fromArray(e),this._geometry.updateMatrixWorld(!0))}}let Tw;function Cw(){return void 0===Tw&&(Tw=function(){const e={alpha:!1,antialias:!1,depth:!0,failIfMajorPerformanceCaveat:!1,premultipliedAlpha:!0,preserveDrawingBuffer:!1,stencil:!0},t=document.createElement("canvas");if(t.getContext("webgl2",e))return!0;const i=t.getContext("webgl",e)||t.getContext("experimental-webgl",e);if(!i)return!1;const n=["OES_standard_derivatives"],r=i.getSupportedExtensions();for(const e of n)if(-1===r.indexOf(e))return!1;return!0}()),Tw}function Ew(){return"undefined"!=typeof window&&"undefined"!=typeof document&&!!(Array.prototype&&Array.prototype.concat&&Array.prototype.filter&&Array.prototype.includes&&Array.prototype.indexOf&&Array.prototype.join&&Array.prototype.map&&Array.prototype.push&&Array.prototype.pop&&Array.prototype.reverse&&Array.prototype.shift&&Array.prototype.slice&&Array.prototype.splice&&Array.prototype.sort&&Array.prototype.unshift)&&"Blob"in window&&"URL"in window&&!!(Function.prototype&&Function.prototype.apply&&Function.prototype.bind)&&"JSON"in window&&"parse"in JSON&&"stringify"in JSON&&"Map"in window&&!!(Object.assign&&Object.keys&&Object.values)&&!!("Promise"in window&&Promise.resolve&&Promise.reject&&Promise.prototype&&Promise.prototype.catch&&Promise.prototype.then)&&"Set"in window}var Aw,Iw,Rw;e.CameraControls=void 0,(Aw=e.CameraControls||(e.CameraControls={}))[Aw.Custom=0]="Custom",Aw[Aw.Earth=1]="Earth",Aw[Aw.Street=2]="Street",e.RenderMode=void 0,(Iw=e.RenderMode||(e.RenderMode={}))[Iw.Letterbox=0]="Letterbox",Iw[Iw.Fill=1]="Fill",e.RenderPass=void 0,function(e){e[e.Opaque=0]="Opaque"}(e.RenderPass||(e.RenderPass={})),e.TransitionMode=void 0,(Rw=e.TransitionMode||(e.TransitionMode={}))[Rw.Default=0]="Default",Rw[Rw.Instantaneous=1]="Instantaneous";class Pw{constructor(e,t,i,n,r,s){this._container=e,this._observer=i,this._navigator=t,this._options=null!=r?r:{},this._key=n,this._navigable=null==n,this._componentService=s||new od(this._container,this._navigator),this._coverComponent=this._componentService.getCover(),this._initializeComponents(),n?(this._initilizeCoverComponent(),this._subscribeCoverComponent()):this._navigator.movedToId$.pipe(St((e=>null!=e))).subscribe((e=>{this._key=e,this._componentService.deactivateCover(),this._coverComponent.configure({id:this._key,state:Qm.Hidden}),this._subscribeCoverComponent(),this._navigator.stateService.start(),this._navigator.cacheService.start(),this._navigator.panService.start(),this._observer.startEmit()}))}get navigable(){return this._navigable}get(e){return this._componentService.get(e)}activate(e){this._componentService.activate(e)}activateCover(){this._coverComponent.configure({state:Qm.Visible})}deactivate(e){this._componentService.deactivate(e)}deactivateCover(){this._coverComponent.configure({state:Qm.Loading})}remove(){this._componentService.remove(),null!=this._configurationSubscription&&this._configurationSubscription.unsubscribe()}_initializeComponents(){var e,t;const i=this._options;this._uFalse(null===(e=i.fallback)||void 0===e?void 0:e.image,"imagefallback"),this._uFalse(null===(t=i.fallback)||void 0===t?void 0:t.navigation,"navigationfallback"),this._uFalse(i.marker,"marker"),this._uFalse(i.popup,"popup"),this._uFalse(i.slider,"slider"),this._uFalse(i.spatial,"spatial"),this._uFalse(i.tag,"tag"),this._uTrue(i.attribution,"attribution"),this._uTrue(i.bearing,"bearing"),this._uTrue(i.cache,"cache"),this._uTrue(i.direction,"direction"),this._uTrue(i.image,"image"),this._uTrue(i.keyboard,"keyboard"),this._uTrue(i.pointer,"pointer"),this._uTrue(i.sequence,"sequence"),this._uTrue(i.zoom,"zoom")}_initilizeCoverComponent(){let e=this._options;this._coverComponent.configure({id:this._key}),void 0===e.cover||e.cover?this.activateCover():this.deactivateCover()}_setNavigable(e){this._navigable!==e&&(this._navigable=e,this._observer.navigable$.next(e))}_subscribeCoverComponent(){this._configurationSubscription=this._coverComponent.configuration$.pipe(vt(void 0,(e=>e.state))).subscribe((e=>{e.state===Qm.Loading?this._navigator.stateService.currentId$.pipe(St(),zt((t=>{const i=null==t||t!==e.id;return i&&this._setNavigable(!1),i?this._navigator.moveTo$(e.id):this._navigator.stateService.currentImage$.pipe(St())}))).subscribe((()=>{this._navigator.stateService.start(),this._navigator.cacheService.start(),this._navigator.panService.start(),this._observer.startEmit(),this._coverComponent.configure({state:Qm.Hidden}),this._componentService.deactivateCover(),this._setNavigable(!0)}),(e=>{console.error("Failed to deactivate cover.",e),this._coverComponent.configure({state:Qm.Visible})})):e.state===Qm.Visible&&(this._observer.stopEmit(),this._navigator.stateService.stop(),this._navigator.cacheService.stop(),this._navigator.playService.stop(),this._navigator.panService.stop(),this._componentService.activateCover(),this._setNavigable(null==e.id))}))}_uFalse(e,t){void 0!==e?"boolean"!=typeof e?(this._componentService.configure(t,e),this._componentService.activate(t)):e?this._componentService.activate(t):this._componentService.deactivate(t):this._componentService.deactivate(t)}_uTrue(e,t){void 0!==e?"boolean"!=typeof e?(this._componentService.configure(t,e),this._componentService.activate(t)):e?this._componentService.activate(t):this._componentService.deactivate(t):this._componentService.activate(t)}}class Lw{constructor(t,i,n){this._adaptiveOperation$=new j,this._render$=new j,this._renderAdaptive$=new j,this._subscriptions=new rf,this._renderService=i,this._currentFrame$=n;const r=this._subscriptions,s=tf.create(tf.h("div.mapillary-dom-renderer",[]));t.appendChild(s),this._offset$=this._adaptiveOperation$.pipe(Lt(((e,t)=>t(e)),{elementHeight:t.offsetHeight,elementWidth:t.offsetWidth,imageAspect:0,renderMode:e.RenderMode.Fill}),st((e=>e.imageAspect>0&&e.elementWidth>0&&e.elementHeight>0)),De((t=>{const i=t.elementWidth/t.elementHeight,n=t.imageAspect/i;let r=0,s=0;return t.renderMode===e.RenderMode.Letterbox?t.imageAspect>i?r=t.elementHeight*(1-1/n)/2:s=t.elementWidth*(1-n)/2:t.imageAspect>i?s=-t.elementWidth*(n-1)/2:r=-t.elementHeight*(1/n-1)/2,{bottom:r,left:s,right:s,top:r}})));const a=this._currentFrame$.pipe(st((e=>null!=e.state.currentImage)),vt(((e,t)=>e===t),(e=>e.state.currentImage.id)),De((e=>e.state.currentTransform.basicAspect)),De((e=>t=>(t.imageAspect=e,t)))).subscribe(this._adaptiveOperation$),o=Ve(this._renderAdaptive$.pipe(Lt(((e,t)=>(null==t.vNode?delete e[t.name]:e[t.name]=t.vNode,e)),{})),this._offset$).pipe(De((e=>{const t=[],i=e[0];for(const e in i)i.hasOwnProperty(e)&&t.push(i[e]);const n=e[1],r={style:{bottom:n.bottom+"px",left:n.left+"px","pointer-events":"none",position:"absolute",right:n.right+"px",top:n.top+"px"}};return{name:"mapillary-dom-adaptive-renderer",vNode:tf.h("div.mapillary-dom-adaptive-renderer",r,t)}}))).subscribe(this._render$);this._vNode$=this._render$.pipe(Lt(((e,t)=>(null==t.vNode?delete e[t.name]:e[t.name]=t.vNode,e)),{}),De((e=>{const t=[];for(const i in e)e.hasOwnProperty(i)&&t.push(e[i]);return tf.h("div.mapillary-dom-renderer",t)}))),this._vPatch$=this._vNode$.pipe(Lt(((e,t)=>(e.vpatch=tf.diff(e.vNode,t),e.vNode=t,e)),{vNode:tf.h("div.mapillary-dom-renderer",[]),vpatch:null}),function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var i=e.length;if(0===i)throw new Error("list of properties cannot be empty.");return De((function(t){for(var n=t,r=0;r<i;r++){var s=null==n?void 0:n[e[r]];if(void 0===s)return;n=s}return n}))}("vpatch")),this._element$=this._vPatch$.pipe(Lt(((e,t)=>tf.patch(e,t)),s),Rt(1),U()),r.push(a),r.push(o),r.push(this._element$.subscribe((()=>{}))),r.push(this._renderService.size$.pipe(De((e=>t=>(t.elementWidth=e.width,t.elementHeight=e.height,t)))).subscribe(this._adaptiveOperation$)),r.push(this._renderService.renderMode$.pipe(De((e=>t=>(t.renderMode=e,t)))).subscribe(this._adaptiveOperation$))}get element$(){return this._element$}get render$(){return this._render$}get renderAdaptive$(){return this._renderAdaptive$}clear(e){this._renderAdaptive$.next({name:e,vNode:null}),this._render$.next({name:e,vNode:null})}remove(){this._subscriptions.unsubscribe()}}class Dw{constructor(e,t,i){this._renderFrame$=new j,this._renderCameraOperation$=new j,this._render$=new j,this._clear$=new j,this._renderOperation$=new j,this._rendererOperation$=new j,this._eraserOperation$=new j,this._triggerOperation$=new j,this._subscriptions=new rf,this._opaqueRender$=new j,this._renderService=i;const n=this._subscriptions;this._renderer$=this._rendererOperation$.pipe(Lt(((e,t)=>t(e)),{needsRender:!1,renderer:null}),st((e=>!!e.renderer))),this._renderCollection$=this._renderOperation$.pipe(Lt(((e,t)=>t(e)),{}),Dt()),this._renderCamera$=this._renderCameraOperation$.pipe(Lt(((e,t)=>t(e)),{frameId:-1,needsRender:!1,perspective:null})),this._eraser$=this._eraserOperation$.pipe(Ot((e=>e)),Lt(((e,t)=>t(e)),{needsRender:!1}));const r=this._triggerOperation$.pipe(Ot((e=>e)),Lt(((e,t)=>t(e)),{needsRender:!1})),s=new xr(986895),a=Ve(this._renderer$,this._renderCollection$,this._renderCamera$,this._eraser$,r).pipe(De((([e,t,i,n,r])=>({camera:i,eraser:n,trigger:r,renderer:e,renders:Object.keys(t).map((e=>t[e]))}))),st((e=>{let t=e.renderer.needsRender||e.camera.needsRender||e.eraser.needsRender||e.trigger.needsRender;const i=e.camera.frameId;for(const n of e.renders){if(n.frameId!==i)return!1;t=t||n.needsRender}return t})),vt(((e,t)=>e===t),(e=>e.eraser.needsRender||e.trigger.needsRender?-e.camera.frameId:e.camera.frameId))).subscribe((e=>{e.renderer.needsRender=!1,e.camera.needsRender=!1,e.eraser.needsRender=!1,e.trigger.needsRender=!1;const t=e.camera.perspective,i=[],n=[];for(const t of e.renders)t.pass===yf.Background?i.push(t.render):t.pass===yf.Opaque&&n.push(t.render);const r=e.renderer.renderer;r.resetState(),r.setClearColor(s,1),r.clear();for(const e of i)e(t,r);r.clearDepth();for(const e of n)e(t,r);r.resetState(),this._opaqueRender$.next()}));n.push(a),n.push(this._renderFrame$.pipe(De((e=>t=>(t.frameId=e.frameId,t.perspective=e.perspective,!0===e.changed&&(t.needsRender=!0),t)))).subscribe(this._renderCameraOperation$)),this._renderFrameSubscribe();const o=this._render$.pipe(De((e=>t=>(t[e.name]=e.renderer,t)))),h=this._clear$.pipe(De((e=>t=>(delete t[e],t))));n.push(it(o,h).subscribe(this._renderOperation$)),this._webGLRenderer$=this._render$.pipe(St(),De((()=>{t.appendChild(e);const n=i.element,r=new hh({canvas:e});return r.setPixelRatio(window.devicePixelRatio),r.setSize(n.offsetWidth,n.offsetHeight),r.autoClear=!1,r})),Rt(1),U()),n.push(this._webGLRenderer$.subscribe((()=>{})));const c=this._webGLRenderer$.pipe(St(),De((e=>t=>(t.needsRender=!0,t.renderer=e,t)))),l=this._renderService.size$.pipe(De((e=>t=>(null==t.renderer||(t.renderer.setSize(e.width,e.height),t.needsRender=!0),t)))),u=this._clear$.pipe(De((()=>e=>(null==e.renderer||(e.needsRender=!0),e))));n.push(it(c,l,u).subscribe(this._rendererOperation$));const d=this._renderCollection$.pipe(st((e=>0===Object.keys(e).length)),Dt());n.push(d.subscribe((()=>{null!=this._renderFrameSubscription&&(this._renderFrameSubscription.unsubscribe(),this._renderFrameSubscription=null,this._renderFrameSubscribe())}))),n.push(d.pipe(De((()=>e=>(e.needsRender=!0,e)))).subscribe(this._eraserOperation$))}get render$(){return this._render$}get opaqueRender$(){return this._opaqueRender$}get webGLRenderer$(){return this._webGLRenderer$}clear(e){this._clear$.next(e)}remove(){this._rendererOperation$.next((e=>{if(null!=e.renderer){const t=e.renderer.getContext().getExtension("WEBGL_lose_context");t&&t.loseContext(),e.renderer=null}return e})),null!=this._renderFrameSubscription&&this._renderFrameSubscription.unsubscribe(),this._subscriptions.unsubscribe()}triggerRerender(){this._renderService.renderCameraFrame$.pipe($t(1),St()).subscribe((()=>{this._triggerOperation$.next((e=>(e.needsRender=!0,e)))}))}_renderFrameSubscribe(){this._render$.pipe(St(),De((()=>e=>(e.needsRender=!0,e)))).subscribe((e=>{this._renderCameraOperation$.next(e)})),this._renderFrameSubscription=this._render$.pipe(St(),We((()=>this._renderService.renderCameraFrame$))).subscribe(this._renderFrame$)}}class Nw{constructor(e){null!=e?(this._position=(new Ki).fromArray(e.unprojectSfM([0,0],0)),this._lookat=(new Ki).fromArray(e.unprojectSfM([0,0],10)),this._up=e.upVector(),this._focal=this._getFocal(e)):(this._position=new Ki(0,0,0),this._lookat=new Ki(1,0,0),this._up=new Ki(0,0,1),this._focal=1)}get position(){return this._position}get lookat(){return this._lookat}get up(){return this._up}get focal(){return this._focal}set focal(e){this._focal=e}lerpCameras(e,t,i){this._position.subVectors(t.position,e.position).multiplyScalar(i).add(e.position),this._lookat.subVectors(t.lookat,e.lookat).multiplyScalar(i).add(e.lookat),this._up.subVectors(t.up,e.up).multiplyScalar(i).add(e.up),this._focal=(1-i)*e.focal+i*t.focal}copy(e){this._position.copy(e.position),this._lookat.copy(e.lookat),this._up.copy(e.up),this._focal=e.focal}clone(){let e=new Nw;return e.position.copy(this._position),e.lookat.copy(this._lookat),e.up.copy(this._up),e.focal=this._focal,e}diff(e){let t=this._position.distanceToSquared(e.position),i=this._lookat.distanceToSquared(e.lookat),n=this._up.distanceToSquared(e.up),r=100*Math.abs(this._focal-e.focal);return Math.max(t,i,n,r)}_getFocal(e){return $u(e.cameraType)?.5/Math.tan(Math.PI/2):e.focal}}class $w{constructor(e,t,i){this._spatial=new Du,this._viewportCoords=new hf,this._size={width:e,height:t},this._initialFov=60,this._alpha=-1,this._stateTransitionAlpha=-1,this._stateTransitionFov=-1,this._renderMode=i,this._zoom=0,this._frameId=-1,this._changed=!1,this._changedForFrame=-1,this._currentImageId=null,this._previousImageId=null,this._currentSpherical=!1,this._previousSpherical=!1,this._state=null,this._currentProjectedPoints=[],this._previousProjectedPoints=[],this._currentFov=this._initialFov,this._previousFov=this._initialFov,this._camera=new Nw,this._perspective=new hs(this._initialFov,this._computeAspect(e,t),.1,1e4),this._perspective.position.copy(this._camera.position),this._perspective.up.copy(this._camera.up),this._perspective.lookAt(this._camera.lookat),this._perspective.updateMatrixWorld(!0),this._perspective.matrixAutoUpdate=!1,this._rotation={phi:0,theta:0}}get alpha(){return this._alpha}get camera(){return this._camera}get changed(){return this._frameId===this._changedForFrame}get frameId(){return this._frameId}get perspective(){return this._perspective}get renderMode(){return this._renderMode}get rotation(){return this._rotation}get zoom(){return this._zoom}get size(){return this._size}getTilt(){return 90-this._spatial.radToDeg(this._rotation.theta)}fovToZoom(e){e=Math.min(90,Math.max(0,e));const t=this._computeCurrentFov(0),i=1===this._alpha?t:this._interpolateFov(t,this._computePreviousFov(0),this._alpha),n=Math.tan(i/2*Math.PI/180),r=Math.tan(e/2*Math.PI/180);return Math.log(n/r)/Math.log(2)}setFrame(e){const t=e.state;if(t.state!==this._state){if(this._state=t.state,this._state!==Df.Custom&&(this.setRenderMode(this._renderMode),this.setSize(this._size)),this._state===Df.Earth){const e=this._fovToY(this._perspective.fov,this._zoom);this._stateTransitionFov=this._yToFov(e,0)}this._changed=!0}const i=t.currentImage.id,n=t.previousImage?t.previousImage.id:null;i!==this._currentImageId&&(this._currentImageId=i,this._currentSpherical=$u(t.currentTransform.cameraType),this._currentProjectedPoints=this._computeProjectedPoints(t.currentTransform),this._changed=!0),n!==this._previousImageId&&(this._previousImageId=n,this._previousSpherical=$u(t.previousTransform.cameraType),this._previousProjectedPoints=this._computeProjectedPoints(t.previousTransform),this._changed=!0);const r=t.zoom;r!==this._zoom&&(this._changed=!0),this._changed&&(this._currentFov=this._computeCurrentFov(r),this._previousFov=this._computePreviousFov(r));const s=t.alpha,a=t.stateTransitionAlpha;if(this._changed||s!==this._alpha||a!==this._stateTransitionAlpha){switch(this._alpha=s,this._stateTransitionAlpha=a,this._state){case Df.Earth:{const e=this._stateTransitionFov,i=this._focalToFov(t.camera.focal),n=Oi.lerp(e,i,a),s=this._fovToY(n,0);this._perspective.fov=this._yToFov(s,r);break}case Df.Custom:break;default:this._perspective.fov=this._interpolateFov(this._currentFov,this._previousFov,this._alpha),this._changed=!0}this._zoom=r,this._state!==Df.Custom&&this._perspective.updateProjectionMatrix()}const o=t.camera;this._camera.diff(o)>1e-9&&(this._camera.copy(o),this._rotation=this._computeRotation(o),this._perspective.up.copy(o.up),this._perspective.position.copy(o.position),this._perspective.matrixAutoUpdate=!0,this._perspective.lookAt(o.lookat),this._perspective.matrixAutoUpdate=!1,this._perspective.updateMatrix(),this._perspective.updateMatrixWorld(!1),this._changed=!0),this._setFrameId(e.id)}setProjectionMatrix(e){this._perspective.fov=this._focalToFov(e[5]/2),this._perspective.projectionMatrix.fromArray(e),this._perspective.projectionMatrixInverse.copy(this._perspective.projectionMatrix).invert(),this._changed=!0}setRenderMode(e){this._renderMode=e,this._state!==Df.Custom&&(this._perspective.fov=this._computeFov(),this._perspective.updateProjectionMatrix(),this._changed=!0)}setSize(e){this._size=e,this._state!==Df.Custom&&(this._perspective.aspect=this._computeAspect(e.width,e.height),this._perspective.fov=this._computeFov(),this._perspective.updateProjectionMatrix(),this._changed=!0)}_computeAspect(e,t){return 0===e?0:e/t}_computeCurrentFov(e){return 0===this._perspective.aspect?0:this._currentImageId?this._currentSpherical?this._yToFov(1,e):this._computeVerticalFov(this._currentProjectedPoints,this._renderMode,e,this.perspective.aspect):this._initialFov}_computeFov(){return this._currentFov=this._computeCurrentFov(this._zoom),this._previousFov=this._computePreviousFov(this._zoom),this._interpolateFov(this._currentFov,this._previousFov,this._alpha)}_computePreviousFov(e){return 0===this._perspective.aspect?0:this._currentImageId?this._previousImageId?this._previousSpherical?this._yToFov(1,e):this._computeVerticalFov(this._previousProjectedPoints,this._renderMode,e,this.perspective.aspect):this._currentFov:this._initialFov}_computeProjectedPoints(e){return zu(e,[[.5,0],[1,0]],[[.5,0],[0,.5]],100,this._viewportCoords)}_computeRequiredVerticalFov(e,t,i){const n=Math.max(e[0]/i,e[1]);return this._yToFov(n,t)}_computeRotation(e){let t=e.lookat.clone().sub(e.position),i=e.up.clone();return{phi:this._spatial.azimuthal(t.toArray(),i.toArray()),theta:Math.PI/2-this._spatial.angleToPlane(t.toArray(),[0,0,1])}}_computeVerticalFov(t,i,n,r){const s=t.map((e=>this._computeRequiredVerticalFov(e,n,r)));return i===e.RenderMode.Fill?.995*Math.min(...s):Math.max(...s)}_yToFov(e,t){return 2*Math.atan(e/Math.pow(2,t))*180/Math.PI}_focalToFov(e){return 2*Math.atan2(1,2*e)*180/Math.PI}_fovToY(e,t){return Math.pow(2,t)*Math.tan(Math.PI*e/360)}_interpolateFov(e,t,i){return i*e+(1-i)*t}_setFrameId(e){this._frameId=e,this._changed&&(this._changed=!1,this._changedForFrame=e)}}class kw{constructor(t,i,n,r){this._subscriptions=new rf,this._element=t,this._currentFrame$=i,this._spatial=new Du,n=null!=n?n:e.RenderMode.Fill,this._resize$=new j,this._projectionMatrix$=new j,this._renderCameraOperation$=new j,this._size$=new W({height:this._element.offsetHeight,width:this._element.offsetWidth});const s=this._subscriptions;s.push(this._resize$.pipe(De((()=>({height:this._element.offsetHeight,width:this._element.offsetWidth})))).subscribe(this._size$)),this._renderMode$=new W(n),this._renderCameraHolder$=this._renderCameraOperation$.pipe(Ot((e=>e)),Lt(((e,t)=>t(e)),null!=r?r:new $w(this._element.offsetWidth,this._element.offsetHeight,n)),Rt(1),U()),this._renderCameraFrame$=this._currentFrame$.pipe(Vt(this._renderCameraHolder$),Ut((([e,t])=>{t.setFrame(e)})),De((e=>e[1])),Rt(1),U()),this._renderCamera$=this._renderCameraFrame$.pipe(st((e=>e.changed)),Rt(1),U()),this._bearing$=this._renderCamera$.pipe(De((e=>{let t=this._spatial.radToDeg(this._spatial.azimuthalToBearing(e.rotation.phi));return this._spatial.wrap(t,0,360)})),Rt(1),U()),s.push(this._size$.pipe($t(1),De((e=>t=>(t.setSize(e),t)))).subscribe(this._renderCameraOperation$)),s.push(this._renderMode$.pipe($t(1),De((e=>t=>(t.setRenderMode(e),t)))).subscribe(this._renderCameraOperation$)),s.push(this._projectionMatrix$.pipe(De((e=>t=>(t.setProjectionMatrix(e),t)))).subscribe(this._renderCameraOperation$)),s.push(this._bearing$.subscribe((()=>{}))),s.push(this._renderCameraHolder$.subscribe((()=>{}))),s.push(this._size$.subscribe((()=>{}))),s.push(this._renderMode$.subscribe((()=>{}))),s.push(this._renderCamera$.subscribe((()=>{}))),s.push(this._renderCameraFrame$.subscribe((()=>{})))}get bearing$(){return this._bearing$}get element(){return this._element}get projectionMatrix$(){return this._projectionMatrix$}get renderCamera$(){return this._renderCamera$}get renderCameraFrame$(){return this._renderCameraFrame$}get renderMode$(){return this._renderMode$}get resize$(){return this._resize$}get size$(){return this._size$}dispose(){this._subscriptions.unsubscribe()}}class Ow{constructor(e){this._keyDown$=Qe(e,"keydown"),this._keyUp$=Qe(e,"keyup")}get keyDown$(){return this._keyDown$}get keyUp$(){return this._keyUp$}}const zw={0:1,2:2};class Fw{constructor(e,t,i,n){this._subscriptions=new rf;const r=this._subscriptions;this._activeSubject$=new W(!1),this._active$=this._activeSubject$.pipe(vt(),Rt(1),U()),this._claimMouse$=new j,this._claimWheel$=new j,this._deferPixelClaims$=new j,this._deferPixels$=this._deferPixelClaims$.pipe(Lt(((e,t)=>(null==t.deferPixels?delete e[t.name]:e[t.name]=t.deferPixels,e)),{}),De((e=>{let t=-1;for(const i in e){if(!e.hasOwnProperty(i))continue;const n=e[i];n>t&&(t=n)}return t})),Ot(-1),Rt(1),U()),r.push(this._deferPixels$.subscribe((()=>{}))),this._documentMouseMove$=Qe(n,"pointermove").pipe(st(this._isMousePen)),this._documentMouseUp$=Qe(n,"pointerup").pipe(st(this._isMousePen)),this._mouseDown$=Qe(t,"pointerdown").pipe(st(this._isMousePen)),this._mouseEnter$=Qe(t,"pointerenter").pipe(st(this._isMousePen)),this._mouseLeave$=Qe(t,"pointerleave").pipe(st(this._isMousePen)),this._mouseMove$=Qe(t,"pointermove").pipe(st(this._isMousePen)),this._mouseUp$=Qe(t,"pointerup").pipe(st(this._isMousePen)),this._mouseOut$=Qe(t,"pointerout").pipe(st(this._isMousePen)),this._mouseOver$=Qe(t,"pointerover").pipe(st(this._isMousePen)),this._domMouseDown$=Qe(i,"pointerdown").pipe(st(this._isMousePen)),this._domMouseMove$=Qe(i,"pointermove").pipe(st(this._isMousePen)),this._click$=Qe(t,"click"),this._contextMenu$=Qe(t,"contextmenu"),this._windowBlur$=Qe(window,"blur"),this._dblClick$=it(Qe(e,"click"),Qe(t,"dblclick")).pipe(ht(3,1),st((e=>{const i=e[0],n=e[1],r=e[2];return"click"===i.type&&"click"===n.type&&"dblclick"===r.type&&i.target.parentNode===t&&n.target.parentNode===t})),De((e=>e[2])),Dt()),r.push(it(this._domMouseDown$,this._domMouseMove$,this._dblClick$,this._contextMenu$).subscribe((e=>{e.preventDefault()}))),this._mouseWheel$=it(Qe(t,"wheel"),Qe(i,"wheel")).pipe(Dt()),this._consistentContextMenu$=it(this._mouseDown$,this._mouseMove$,this._mouseOut$,this._mouseUp$,this._contextMenu$).pipe(ht(3,1),st((e=>"pointerdown"===e[0].type&&"contextmenu"===e[1].type&&"pointerup"===e[2].type)),De((e=>e[1])),Dt());const s=it(this._windowBlur$,this._documentMouseMove$.pipe(st((e=>this._buttonReleased(e,0)))),this._documentMouseUp$.pipe(st((e=>0===this._mouseButton(e))))).pipe(Dt()),a=this._createMouseDragInitiate$(0,this._mouseDown$,s,!0).pipe(Dt());this._mouseDragStart$=this._createMouseDragStart$(a).pipe(Dt()),this._mouseDrag$=this._createMouseDrag$(a,s).pipe(Dt()),this._mouseDragEnd$=this._createMouseDragEnd$(this._mouseDragStart$,s).pipe(Dt());const o=this._createMouseDragInitiate$(0,this._domMouseDown$,s,!1).pipe(Dt());this._domMouseDragStart$=this._createMouseDragStart$(o).pipe(Dt()),this._domMouseDrag$=this._createMouseDrag$(o,s).pipe(Dt()),this._domMouseDragEnd$=this._createMouseDragEnd$(this._domMouseDragStart$,s).pipe(Dt());const h=it(this._windowBlur$,this._documentMouseMove$.pipe(st((e=>this._buttonReleased(e,2)))),this._documentMouseUp$.pipe(st((e=>2===this._mouseButton(e))))).pipe(Dt()),c=this._createMouseDragInitiate$(2,this._mouseDown$,h,!0).pipe(Dt());this._mouseRightDragStart$=this._createMouseDragStart$(c).pipe(Dt()),this._mouseRightDrag$=this._createMouseDrag$(c,h).pipe(Dt()),this._mouseRightDragEnd$=this._createMouseDragEnd$(this._mouseRightDragStart$,h).pipe(Dt()),this._proximateClick$=this._mouseDown$.pipe(zt((e=>this._click$.pipe(Ft(this._createDeferredMouseMove$(e,this._documentMouseMove$)),_t(1)))),Dt()),this._staticClick$=this._mouseDown$.pipe(zt((()=>this._click$.pipe(Ft(this._documentMouseMove$),_t(1)))),Dt()),r.push(this._mouseDragStart$.subscribe()),r.push(this._mouseDrag$.subscribe()),r.push(this._mouseDragEnd$.subscribe()),r.push(this._domMouseDragStart$.subscribe()),r.push(this._domMouseDrag$.subscribe()),r.push(this._domMouseDragEnd$.subscribe()),r.push(this._mouseRightDragStart$.subscribe()),r.push(this._mouseRightDrag$.subscribe()),r.push(this._mouseRightDragEnd$.subscribe()),r.push(this._staticClick$.subscribe()),this._mouseOwner$=this._createOwner$(this._claimMouse$).pipe(Rt(1),U()),this._wheelOwner$=this._createOwner$(this._claimWheel$).pipe(Rt(1),U()),r.push(this._mouseOwner$.subscribe((()=>{}))),r.push(this._wheelOwner$.subscribe((()=>{})))}get active$(){return this._active$}get activate$(){return this._activeSubject$}get documentMouseMove$(){return this._documentMouseMove$}get documentMouseUp$(){return this._documentMouseUp$}get domMouseDragStart$(){return this._domMouseDragStart$}get domMouseDrag$(){return this._domMouseDrag$}get domMouseDragEnd$(){return this._domMouseDragEnd$}get domMouseDown$(){return this._domMouseDown$}get domMouseMove$(){return this._domMouseMove$}get mouseOwner$(){return this._mouseOwner$}get mouseDown$(){return this._mouseDown$}get mouseEnter$(){return this._mouseEnter$}get mouseMove$(){return this._mouseMove$}get mouseLeave$(){return this._mouseLeave$}get mouseOut$(){return this._mouseOut$}get mouseOver$(){return this._mouseOver$}get mouseUp$(){return this._mouseUp$}get click$(){return this._click$}get dblClick$(){return this._dblClick$}get contextMenu$(){return this._consistentContextMenu$}get mouseWheel$(){return this._mouseWheel$}get mouseDragStart$(){return this._mouseDragStart$}get mouseDrag$(){return this._mouseDrag$}get mouseDragEnd$(){return this._mouseDragEnd$}get mouseRightDragStart$(){return this._mouseRightDragStart$}get mouseRightDrag$(){return this._mouseRightDrag$}get mouseRightDragEnd$(){return this._mouseRightDragEnd$}get proximateClick$(){return this._proximateClick$}get staticClick$(){return this._staticClick$}get windowBlur$(){return this._windowBlur$}dispose(){this._subscriptions.unsubscribe()}claimMouse(e,t){this._claimMouse$.next({name:e,zindex:t})}unclaimMouse(e){this._claimMouse$.next({name:e,zindex:null})}deferPixels(e,t){this._deferPixelClaims$.next({name:e,deferPixels:t})}undeferPixels(e){this._deferPixelClaims$.next({name:e,deferPixels:null})}claimWheel(e,t){this._claimWheel$.next({name:e,zindex:t})}unclaimWheel(e){this._claimWheel$.next({name:e,zindex:null})}filtered$(e,t){return this._filtered(e,t,this._mouseOwner$)}filteredWheel$(e,t){return this._filtered(e,t,this._wheelOwner$)}_createDeferredMouseMove$(e,t){return t.pipe(De((t=>{const i=t.clientX-e.clientX,n=t.clientY-e.clientY;return[t,Math.sqrt(i*i+n*n)]})),Vt(this._deferPixels$),st((([[,e],t])=>e>t)),De((([[e]])=>e)))}_createMouseDrag$(e,t){return e.pipe(De((([,e])=>e)),zt((e=>Ze(Ce(e),this._documentMouseMove$).pipe(Ft(t)))))}_createMouseDragEnd$(e,t){return e.pipe(zt((()=>t.pipe(St()))))}_createMouseDragStart$(e){return e.pipe(De((([e])=>e)))}_createMouseDragInitiate$(e,t,i,n){return t.pipe(st((t=>this._mouseButton(t)===e)),zt((e=>Ve(Ce(e),n?this._createDeferredMouseMove$(e,this._documentMouseMove$):this._documentMouseMove$).pipe(Ft(i),_t(1)))))}_createOwner$(e){return e.pipe(Lt(((e,t)=>(null==t.zindex?delete e[t.name]:e[t.name]=t.zindex,e)),{}),De((e=>{let t=null,i=-1;for(const n in e)e.hasOwnProperty(n)&&e[n]>i&&(i=e[n],t=n);return t})),Ot(null))}_filtered(e,t,i){return t.pipe(Vt(i),st((([,t])=>t===e)),De((([e])=>e)))}_mouseButton(e){const t="pointerdown"===e.type||"pointerup"===e.type,i=window.InstallTrigger;return t&&void 0!==i&&2===e.button&&e.ctrlKey&&window.navigator.platform.toUpperCase().indexOf("MAC")>=0?0:e.button}_buttonReleased(e,t){const i=zw[t];return void 0===e.buttons||(e.buttons&i)!==i}_isMousePen(e){const t=e.pointerType;return"mouse"===t||"pen"===t}}class Bw{set json(e){this._json=e}set image(e){this._image=e,this._texture=new Wi(this._image),this._texture.minFilter=Jt}get loaded(){return!(!this._image||!this._json)}getGLSprite(e){if(!this.loaded)throw new Error("Sprites cannot be retrieved before the atlas is loaded.");let t=this._json[e];if(!t)return console.warn("Sprite with key"+e+"does not exist in sprite definition."),new tr;let i=this._texture.clone();i.needsUpdate=!0;let n=this._image.width,r=this._image.height;i.offset.x=t.x/n,i.offset.y=(r-t.y-t.height)/r,i.repeat.x=t.width/n,i.repeat.y=t.height/r;let s=new ph({map:i});return new Eh(s)}getDOMSprite(t,i){if(!this.loaded)throw new Error("Sprites cannot be retrieved before the atlas is loaded.");null==i&&(i=e.Alignment.Center);let n=this._json[t];if(!n)return console.warn("Sprite with key"+t+"does not exist in sprite definition."),tf.h("div",{},[]);let r=n.y,s=n.x+n.width,a=n.y+n.height,o=n.x,h=-n.x,c=-n.y,l=this._image.height,u=this._image.width;switch(i){case e.Alignment.Bottom:case e.Alignment.Center:case e.Alignment.Top:h-=n.width/2;break;case e.Alignment.BottomLeft:case e.Alignment.Left:case e.Alignment.TopLeft:h-=n.width;break;case e.Alignment.BottomRight:case e.Alignment.Right:case e.Alignment.TopRight:}switch(i){case e.Alignment.Center:case e.Alignment.Left:case e.Alignment.Right:c-=n.height/2;break;case e.Alignment.Top:case e.Alignment.TopLeft:case e.Alignment.TopRight:c-=n.height;break;case e.Alignment.Bottom:case e.Alignment.BottomLeft:case e.Alignment.BottomRight:}let d=1/n.pixelRatio;r*=d,s*=d,a*=d,o*=d,h*=d,c*=d,l*=d,u*=d;let p={src:this._image.src,style:{clip:`rect(${r}px, ${s}px, ${a}px, ${o}px)`,height:`${l}px`,left:`${h}px`,position:"absolute",top:`${c}px`,width:`${u}px`}};return tf.h("img",p,[])}}class Uw{constructor(e){if(this._retina=window.devicePixelRatio>1,this._spriteAtlasOperation$=new j,this._spriteAtlas$=this._spriteAtlasOperation$.pipe(Ot((e=>e)),Lt(((e,t)=>t(e)),new Bw),Rt(1),U()),this._atlasSubscription=this._spriteAtlas$.subscribe((()=>{})),null==e)return;let t=this._retina?"@2x":"",i=new XMLHttpRequest;i.open("GET",e+t+".png",!0),i.responseType="arraybuffer",i.onload=()=>{let e=new Image;e.onload=()=>{this._spriteAtlasOperation$.next((t=>(t.image=e,t)))};let t=new Blob([i.response]);e.src=window.URL.createObjectURL(t)},i.onerror=i=>{console.error(new Error(`Failed to fetch sprite sheet (${e}${t}.png)`))},i.send();let n=new XMLHttpRequest;n.open("GET",e+t+".json",!0),n.responseType="text",n.onload=()=>{let e=JSON.parse(n.response);this._spriteAtlasOperation$.next((t=>(t.json=e,t)))},n.onerror=i=>{console.error(new Error(`Failed to fetch sheet (${e}${t}.json)`))},n.send()}get spriteAtlas$(){return this._spriteAtlas$}dispose(){this._atlasSubscription.unsubscribe()}}class Vw{constructor(e,t){this._subscriptions=new rf;const i=this._subscriptions;this._activeSubject$=new W(!1),this._active$=this._activeSubject$.pipe(vt(),Rt(1),U()),i.push(Qe(t,"touchmove").subscribe((e=>{e.preventDefault()}))),this._touchStart$=Qe(e,"touchstart"),this._touchMove$=Qe(e,"touchmove"),this._touchEnd$=Qe(e,"touchend"),this._touchCancel$=Qe(e,"touchcancel");const n=this._touchStart$.pipe(st((e=>1===e.touches.length&&1===e.targetTouches.length)),Dt());var r;this._doubleTap$=n.pipe((r=()=>n.pipe(St(),zt((()=>it(tt(300),n).pipe(_t(1))))),F((function(e,t){var i=null,n=null,s=function(){null==n||n.unsubscribe();var e=i;i=[],e&&t.next(e),_e(r()).subscribe(n=new B(t,s,w))};s(),e.subscribe(new B(t,(function(e){return null==i?void 0:i.push(e)}),(function(){i&&t.next(i),t.complete()}),void 0,(function(){return i=n=null})))}))),st((e=>2===e.length)),De((e=>e[e.length-1])),Dt()),i.push(this._doubleTap$.subscribe((e=>{e.preventDefault()}))),this._singleTouchMove$=this._touchMove$.pipe(st((e=>1===e.touches.length&&1===e.targetTouches.length)),Dt());let s=it(this._touchStart$,this._touchEnd$,this._touchCancel$).pipe(st((e=>1===e.touches.length&&1===e.targetTouches.length))),a=it(this._touchStart$,this._touchEnd$,this._touchCancel$).pipe(st((e=>e.touches.length>=1))),o=it(this._touchEnd$,this._touchCancel$).pipe(st((e=>0===e.touches.length)));this._singleTouchDragStart$=s.pipe(We((()=>this._singleTouchMove$.pipe(Ft(it(o,a)),_t(1))))),this._singleTouchDragEnd$=s.pipe(We((()=>it(o,a).pipe(St())))),this._singleTouchDrag$=s.pipe(zt((()=>this._singleTouchMove$.pipe($t(1),Ft(it(a,o))))));let h=it(this._touchStart$,this._touchEnd$,this._touchCancel$);this._pinchStart$=h.pipe(st((e=>2===e.touches.length&&2===e.targetTouches.length))),this._pinchEnd$=h.pipe(st((e=>2!==e.touches.length||2!==e.targetTouches.length))),this._pinchOperation$=new j,this._pinch$=this._pinchOperation$.pipe(Lt(((e,t)=>t(e)),{changeX:0,changeY:0,clientX:0,clientY:0,distance:0,distanceChange:0,distanceX:0,distanceY:0,originalEvent:null,pageX:0,pageY:0,screenX:0,screenY:0,touch1:null,touch2:null}));const c=this._touchMove$.pipe(st((e=>2===e.touches.length&&2===e.targetTouches.length)),De((e=>t=>{let i=e.touches[0],n=e.touches[1],r=Math.min(i.clientX,n.clientX),s=Math.max(i.clientX,n.clientX),a=Math.min(i.clientY,n.clientY),o=r+(s-r)/2,h=a+(Math.max(i.clientY,n.clientY)-a)/2,c=o+i.pageX-i.clientX,l=h+i.pageY-i.clientY,u=o+i.screenX-i.clientX,d=h+i.screenY-i.clientY,p=Math.abs(i.clientX-n.clientX),m=Math.abs(i.clientY-n.clientY),f=Math.sqrt(p*p+m*m),g=f-t.distance;return{changeX:p-t.distanceX,changeY:m-t.distanceY,clientX:o,clientY:h,distance:f,distanceChange:g,distanceX:p,distanceY:m,originalEvent:e,pageX:c,pageY:l,screenX:u,screenY:d,touch1:i,touch2:n}}))).subscribe(this._pinchOperation$);i.push(c),this._pinchChange$=this._pinchStart$.pipe(zt((()=>this._pinch$.pipe($t(1),Ft(this._pinchEnd$)))))}get active$(){return this._active$}get activate$(){return this._activeSubject$}get doubleTap$(){return this._doubleTap$}get touchStart$(){return this._touchStart$}get touchMove$(){return this._touchMove$}get touchEnd$(){return this._touchEnd$}get touchCancel$(){return this._touchCancel$}get singleTouchDragStart$(){return this._singleTouchDragStart$}get singleTouchDrag$(){return this._singleTouchDrag$}get singleTouchDragEnd$(){return this._singleTouchDragEnd$}get pinch$(){return this._pinchChange$}get pinchStart$(){return this._pinchStart$}get pinchEnd$(){return this._pinchEnd$}dispose(){this._subscriptions.unsubscribe()}}class Hw{constructor(e){var t,i,n,r;const s=null!==(i=null===(t=null==e?void 0:e.url)||void 0===t?void 0:t.exploreHost)&&void 0!==i?i:"www.mapillary.com",a=`${null!==(r=null===(n=null==e?void 0:e.url)||void 0===n?void 0:n.scheme)&&void 0!==r?r:"https"}://${s}`;this._exploreUrl$=Ce(a);const o=!1!==(null==e?void 0:e.imageTiling);this._imageTiling$=Ce(o)}get exploreUrl$(){return this._exploreUrl$}get imageTiling$(){return this._imageTiling$}}class jw{constructor(e,t,i){var n;if(this._onWindowResize=()=>{this._trackResize&&this.renderService.resize$.next()},this._dom=null!=i?i:new og,"string"==typeof e.container){if(this._container=this._dom.document.getElementById(e.container),!this._container)throw new Error(`Container "${e.container}" not found.`)}else{if(!(e.container instanceof HTMLElement))throw new Error('Invalid type: "container" must be a String or HTMLElement.');this._container=e.container}this._trackResize=!1!==e.trackResize,this.id=null!==(n=this._container.id)&&void 0!==n?n:"mapillary-fallback-container-id",this._container.classList.add("mapillary-viewer"),this._canvasContainer=this._dom.createElement("div","mapillary-interactive",this._container),this._canvas=this._dom.createElement("canvas","mapillary-canvas"),this._canvas.style.position="absolute",this._canvas.setAttribute("tabindex","0"),this._domContainer=this._dom.createElement("div","mapillary-dom",this._container),this.configurationService=new Hw(e),this.renderService=new kw(this._container,t.currentState$,e.renderMode),this.glRenderer=new Dw(this._canvas,this._canvasContainer,this.renderService),this.domRenderer=new Lw(this._domContainer,this.renderService,t.currentState$),this.keyboardService=new Ow(this._canvasContainer),this.mouseService=new Fw(this._container,this._canvasContainer,this._domContainer,document),this.touchService=new Vw(this._canvasContainer,this._domContainer),this.spriteService=new Uw(e.sprite),window.addEventListener("resize",this._onWindowResize,!1)}get canvas(){return this._canvas.parentNode?this._canvas:null}get canvasContainer(){return this._canvasContainer}get container(){return this._container}get domContainer(){return this._domContainer}remove(){window.removeEventListener("resize",this._onWindowResize,!1),this.spriteService.dispose(),this.touchService.dispose(),this.mouseService.dispose(),this.glRenderer.remove(),this.domRenderer.remove(),this.renderService.dispose(),this._removeNode(this._canvasContainer),this._removeNode(this._domContainer),this._container.classList.remove("mapillary-viewer")}_removeNode(e){e.parentNode&&e.parentNode.removeChild(e)}}class Gw{constructor(e,t,i){this._graphService=e,this._stateService=t,this._api=i,this._subscriptions=new rf,this._started=!1,this._cellDepth=1}get started(){return this._started}configure(e){this._cellDepth=e?Math.max(1,Math.min(3,e.cellDepth)):1}start(){if(this._started)return;const e=this._subscriptions;e.push(this._stateService.currentState$.pipe(vt(void 0,(e=>e.state.currentImage.id)),De((e=>{const t=e.state,i=t.trajectory,n=i.map((e=>e.id)),r=i[i.length-1].sequenceId;return[n,t.currentImage.originalLngLat,r]})),ht(1,5),Vt(this._graphService.graphMode$),zt((([e,t])=>{const i=e[0][0],n=e[0][1],r=this._api.data.geometry,s=kg(r.lngLatToCellId(n),this._cellDepth,r),a=t===Nf.Sequence?e[0][2]:void 0;return this._graphService.uncache$(i,s,a)}))).subscribe((()=>{}))),e.push(this._graphService.graphMode$.pipe($t(1),Vt(this._stateService.currentState$),zt((([e,t])=>e===Nf.Sequence?this._keyToEdges(t.state.currentImage.id,(e=>e.sequenceEdges$)):ge(t.state.trajectory.map((e=>e.id)).slice(t.state.currentIndex)).pipe(We((e=>this._keyToEdges(e,(e=>e.spatialEdges$))),6))))).subscribe((()=>{}))),e.push(this._graphService.dataAdded$.pipe(Vt(this._stateService.currentId$),zt((([e,t])=>this._graphService.cacheImage$(t)))).subscribe((()=>{}))),this._started=!0}stop(){this._started&&(this._subscriptions.unsubscribe(),this._started=!1)}_keyToEdges(e,t){return this._graphService.cacheImage$(e).pipe(zt(t),St((e=>e.cached)),Pe(15e3),ct((t=>(console.error(`Failed to cache edges (${e}).`,t),ie()))))}}class Ww{constructor(){this._loadersSubject$=new j,this._loaders$=this._loadersSubject$.pipe(Lt(((e,t)=>(void 0!==t.task&&(e[t.task]=t.loading),e)),{}),Ot({}),Rt(1),U())}get loading$(){return this._loaders$.pipe(De((e=>{for(const t in e)if(e.hasOwnProperty(t)&&e[t])return!0;return!1})),ft(100),vt())}taskLoading$(e){return this._loaders$.pipe(De((t=>!!t[e])),ft(100),vt())}startLoading(e){this._loadersSubject$.next({loading:!0,task:e})}stopLoading(e){this._loadersSubject$.next({loading:!1,task:e})}}var qw;!function(e){e[e.Disabled=0]="Disabled",e[e.Enabled=1]="Enabled",e[e.Started=2]="Started"}(qw||(qw={}));class Xw{constructor(e,t,i,n,r,s){this._subscriptions=new rf,this._graphService=e,this._stateService=t,this._graphCalculator=null!=n?n:new Mu,this._spatial=null!=r?r:new Du,this._viewportCoords=null!=s?s:new hf,this._mode=!1!==i?qw.Enabled:qw.Disabled,this._panImagesSubject$=new j,this._panImages$=this._panImagesSubject$.pipe(Ot([]),Rt(1),U()),this._subscriptions.push(this._panImages$.subscribe())}get panImages$(){return this._panImages$}dispose(){this.stop(),null!=this._panImagesSubscription&&this._panImagesSubscription.unsubscribe(),this._subscriptions.unsubscribe()}enable(){this._mode===qw.Disabled&&(this._mode=qw.Enabled,this.start())}disable(){this._mode!==qw.Disabled&&(this.stop(),this._mode=qw.Disabled)}start(){if(this._mode!==qw.Enabled)return;const e=this._stateService.currentImage$.pipe(zt((e=>{if(!e.merged||$u(e.cameraType))return Ce([]);const t=Ce(e),i=this._graphCalculator.boundingBoxCorners(e.lngLat,20);return Ve(t,this._graphService.cacheBoundingBox$(i[0],i[1]).pipe(ct((t=>(console.error(`Failed to cache periphery bounding box (${e.id})`,t),ie()))),De((t=>{if($u(e.cameraType))return[];const i=[];for(const n of t)n.id!==e.id&&n.mergeId===e.mergeId&&($u(n.cameraType)||this._distance(n,e)>4||i.push(n));return i})))).pipe(Vt(this._stateService.reference$),De((([[e,t],i])=>{const n=this._spatial.viewingDirection(e.rotation),r=Ou({lat:e.lngLat.lat,lng:e.lngLat.lng,alt:e.computedAltitude},e.rotation,i),s=this._createTransform(e,r),a=this._spatial.wrap(this._spatial.azimuthal(n.toArray(),s.upVector().toArray()),0,2*Math.PI),o=this._computeProjectedPoints(s),h=this._computeHorizontalFov(o)/180*Math.PI,c=Math.PI/8;let l,u;for(const r of t){const t=Ou({lat:r.lngLat.lat,lng:r.lngLat.lng,alt:r.computedAltitude},r.rotation,i),s=this._createTransform(r,t),o=this._computeProjectedPoints(s),d=this._computeHorizontalFov(o)/180*Math.PI,p=this._spatial.viewingDirection(r.rotation),m=this._spatial.wrap(this._spatial.azimuthal(p.toArray(),s.upVector().toArray()),0,2*Math.PI),f=this._spatial.angleBetweenVector2(n.x,n.y,p.x,p.y);let g=Number.NEGATIVE_INFINITY;g=f>0?a>m?a-2*Math.PI+h/2-(m-d/2):a+h/2-(m-d/2):a<m?m+d/2-(a+2*Math.PI-h/2):m+d/2-(a-h/2);const _=Math.abs(d-g),v=this._distance(r,e)+Math.min(this._timeDifference(r,e),4)+20*Math.abs(g-c)+Math.min(5,1/Math.min(d/h,1))+(g>0?-2*_:0);g>0&&g<.5*h&&g<.5*d&&_>.5*h&&(f>0?l?v<l[0]&&(l=[v,r,s,d]):l=[v,r,s,d]:u?v<u[0]&&(u=[v,r,s,d]):u=[v,r,s,d])}const d=[];return l&&d.push([l[1],l[2],l[3]]),u&&d.push([u[1],u[2],u[3]]),d})),Ot([]))})));this._panImagesSubscription=this._stateService.currentState$.pipe(De((e=>e.state.imagesAhead>0)),vt(),zt((t=>t?Ce([]):e))).subscribe((e=>{this._panImagesSubject$.next(e)})),this._mode=qw.Started}stop(){this._mode===qw.Started&&(this._panImagesSubscription.unsubscribe(),this._panImagesSubject$.next([]),this._mode=qw.Enabled)}_distance(e,t){const[i,n,r]=_u(e.lngLat.lng,e.lngLat.lat,e.computedAltitude,t.lngLat.lng,t.lngLat.lat,t.computedAltitude);return Math.sqrt(i*i+n*n+r*r)}_timeDifference(e,t){return Math.abs(e.capturedAt-t.capturedAt)/2592e6}_createTransform(e,t){return new ug(e.exifOrientation,e.width,e.height,e.scale,e.rotation,t,e.assetsCached?e.image:void 0,void 0,e.cameraParameters,e.cameraType)}_computeProjectedPoints(e){return zu(e,[[1,0]],[[0,.5]],20,this._viewportCoords)}_computeHorizontalFov(e){const t=e.map((e=>this._coordToFov(e[0])));return Math.min(...t)}_coordToFov(e){return 2*Math.atan(e)*180/Math.PI}}class Zw{constructor(e){this._data=e}get data(){return this._data}getCoreImages$(e){return this._wrap$(this._data.getCoreImages(e))}getImages$(e){return this._wrap$(this._data.getImages(e))}getImageTiles$(e){return this._wrap$(this._data.getImageTiles(e))}getSequence$(e){return this._wrap$(this._data.getSequence(e))}getSpatialImages$(e){return this._wrap$(this._data.getSpatialImages(e))}setAccessToken(e){this._data.setAccessToken(e)}_wrap$(e){return k.create((t=>{e.then((e=>{t.next(e),t.complete()}),(e=>{t.error(e)}))}))}}class Yw{constructor(e){this._dataAdded$=new j,this._subscriptions=new rf,this._onDataAdded=e=>{this._graph$.pipe(St(),We((t=>t.updateCells$(e.cellIds).pipe(Ut((()=>{t.resetSpatialEdges()})))))).subscribe((e=>{this._dataAdded$.next(e)}))};const t=this._subscriptions;this._graph$=Ze(Ce(e),e.changed$).pipe(Rt(1),U()),t.push(this._graph$.subscribe((()=>{}))),this._graphMode=Nf.Spatial,this._graphModeSubject$=new j,this._graphMode$=this._graphModeSubject$.pipe(Ot(this._graphMode),Rt(1),U()),t.push(this._graphMode$.subscribe((()=>{}))),this._firstGraphSubjects$=[],this._initializeCacheSubscriptions=[],this._sequenceSubscriptions=[],this._spatialSubscriptions=[],e.api.data.on("datacreate",this._onDataAdded)}get dataAdded$(){return this._dataAdded$}get filter$(){return this._graph$.pipe(St(),We((e=>e.filter$)))}get graphMode$(){return this._graphMode$}cacheBoundingBox$(e,t){return this._graph$.pipe(St(),We((i=>i.cacheBoundingBox$(e,t))))}cacheCell$(e){return this._graph$.pipe(St(),We((t=>t.cacheCell$(e))))}cacheImage$(e){const t=new j;this._firstGraphSubjects$.push(t);const i=t.pipe(Rt(1),U()),n=i.pipe(De((t=>t.getNode(e))),We((e=>e.assetsCached?Ce(e):e.cacheAssets$())),Rt(1),U());let r;n.subscribe(void 0,(t=>{console.error(`Failed to cache image (${e}).`,t)})),r=this._graph$.pipe(St(),We((t=>t.isCachingFull(e)||!t.hasNode(e)?t.cacheFull$(e):t.isCachingFill(e)||!t.getNode(e).complete?t.cacheFill$(e):Ce(t))),Ut((t=>{if(!t.hasNode(e))throw new Bu(`Failed to cache image (${e})`);t.hasInitializedCache(e)||t.initializeCache(e)})),Mt((()=>{null!=r&&(this._removeFromArray(r,this._initializeCacheSubscriptions),this._removeFromArray(t,this._firstGraphSubjects$))}))).subscribe((e=>{t.next(e),t.complete()}),(e=>{t.error(e)})),r.closed||this._initializeCacheSubscriptions.push(r);const s=i.pipe(ct((()=>ie())),We((t=>t.isCachingNodeSequence(e)||!t.hasNodeSequence(e)?t.cacheNodeSequence$(e):Ce(t))),Rt(1),U());let a;if(a=s.pipe(Ut((t=>{t.getNode(e).sequenceEdges.cached||t.cacheSequenceEdges(e)})),Mt((()=>{null!=a&&this._removeFromArray(a,this._sequenceSubscriptions)}))).subscribe((()=>{}),(t=>{console.error(`Failed to cache sequence edges (${e}).`,t)})),a.closed||this._sequenceSubscriptions.push(a),this._graphMode===Nf.Spatial){let t;t=i.pipe(ct((()=>ie())),wt((t=>t.hasTiles(e)?ie():ge(t.cacheTiles$(e)).pipe(We((t=>t.pipe(We((t=>t.isCachingTiles(e)?ie():Ce(t))),ct((t=>(console.error(`Failed to cache tile data (${e}).`,t),ie()))))))))),Tt(1),We((t=>t.hasSpatialArea(e)?Ce(t):ge(t.cacheSpatialArea$(e)).pipe(We((t=>t.pipe(ct((t=>(console.error(`Failed to cache spatial images (${e}).`,t),ie()))))))))),Tt(1),We((t=>t.hasNodeSequence(e)?Ce(t):t.cacheNodeSequence$(e))),Ut((t=>{t.getNode(e).spatialEdges.cached||t.cacheSpatialEdges(e)})),Mt((()=>{null!=t&&this._removeFromArray(t,this._spatialSubscriptions)}))).subscribe((()=>{}),(t=>{const i=`Failed to cache spatial edges (${e}).`;console.error(i,t)})),t.closed||this._spatialSubscriptions.push(t)}return n.pipe(St((e=>e.assetsCached)))}cacheSequence$(e){return this._graph$.pipe(St(),We((t=>t.isCachingSequence(e)||!t.hasSequence(e)?t.cacheSequence$(e):Ce(t))),De((t=>t.getSequence(e))))}cacheSequenceImages$(e,t){return this._graph$.pipe(St(),We((t=>t.isCachingSequence(e)||!t.hasSequence(e)?t.cacheSequence$(e):Ce(t))),We((i=>i.isCachingSequenceNodes(e)||!i.hasSequenceNodes(e)?i.cacheSequenceNodes$(e,t):Ce(i))),De((t=>t.getSequence(e))))}dispose(){this._graph$.pipe(St()).subscribe((e=>{e.unsubscribe()})),this._subscriptions.unsubscribe()}setFilter$(e){return this._resetSubscriptions(this._spatialSubscriptions),this._graph$.pipe(St(),Ut((t=>{t.resetSpatialEdges(),t.setFilter(e)})),De((()=>{})))}setGraphMode(e){this._graphMode!==e&&(e===Nf.Sequence&&this._resetSubscriptions(this._spatialSubscriptions),this._graphMode=e,this._graphModeSubject$.next(this._graphMode))}reset$(e){return this._abortSubjects(this._firstGraphSubjects$),this._resetSubscriptions(this._initializeCacheSubscriptions),this._resetSubscriptions(this._sequenceSubscriptions),this._resetSubscriptions(this._spatialSubscriptions),this._graph$.pipe(St(),Ut((t=>{t.reset(e)})),De((()=>{})))}uncache$(e,t,i){return this._graph$.pipe(St(),Ut((n=>{n.uncache(e,t,i)})),De((()=>{})))}_abortSubjects(e){for(const t of e.slice())this._removeFromArray(t,e),t.error(new Error("Cache image request was aborted."))}_removeFromArray(e,t){const i=t.indexOf(e);-1!==i&&t.splice(i,1)}_resetSubscriptions(e){for(const t of e.slice())this._removeFromArray(t,e),t.closed||t.unsubscribe()}}class Jw{constructor(e){e.requestAnimationFrame?(this._cancelAnimationFrame=e.cancelAnimationFrame.bind(e),this._requestAnimationFrame=e.requestAnimationFrame.bind(e)):e.mozRequestAnimationFrame?(this._cancelAnimationFrame=e.mozCancelAnimationFrame.bind(e),this._requestAnimationFrame=e.mozRequestAnimationFrame.bind(e)):e.webkitRequestAnimationFrame?(this._cancelAnimationFrame=e.webkitCancelAnimationFrame.bind(e),this._requestAnimationFrame=e.webkitRequestAnimationFrame.bind(e)):e.msRequestAnimationFrame?(this._cancelAnimationFrame=e.msCancelAnimationFrame.bind(e),this._requestAnimationFrame=e.msRequestAnimationFrame.bind(e)):e.oRequestAnimationFrame?(this._cancelAnimationFrame=e.oCancelAnimationFrame.bind(e),this._requestAnimationFrame=e.oRequestAnimationFrame.bind(e)):(this._cancelAnimationFrame=e.clearTimeout.bind(e),this._requestAnimationFrame=t=>e.setTimeout(t,1e3/60))}get cancelAnimationFrame(){return this._cancelAnimationFrame}get requestAnimationFrame(){return this._requestAnimationFrame}}class Kw{constructor(e){this._spatial=new Du,this._referenceThreshold=.01,this._transitionMode=e.transitionMode,this._reference=e.reference,this._alpha=e.alpha,this._stateTransitionAlpha=0,this._camera=e.camera.clone(),this._zoom=e.zoom,this._currentIndex=e.currentIndex,this._trajectory=e.trajectory.slice(),this._trajectoryTransforms=[],this._trajectoryCameras=[];for(let e of this._trajectory){let t=this._imageToTranslation(e,this._reference),i=new ug(e.exifOrientation,e.width,e.height,e.scale,e.rotation,t,e.image,void 0,e.cameraParameters,e.cameraType);this._trajectoryTransforms.push(i),this._trajectoryCameras.push(new Nw(i))}this._currentImage=this._trajectory.length>0?this._trajectory[this._currentIndex]:null,this._previousImage=this._trajectory.length>1&&this.currentIndex>0?this._trajectory[this._currentIndex-1]:null,this._currentCamera=this._trajectoryCameras.length>0?this._trajectoryCameras[this._currentIndex].clone():new Nw,this._previousCamera=this._trajectoryCameras.length>1&&this.currentIndex>0?this._trajectoryCameras[this._currentIndex-1].clone():this._currentCamera.clone()}get reference(){return this._reference}get alpha(){return this._getAlpha()}get stateTransitionAlpha(){return this._getStateTransitionAlpha()}get camera(){return this._camera}get zoom(){return this._zoom}get trajectory(){return this._trajectory}get currentIndex(){return this._currentIndex}get currentImage(){return this._currentImage}get previousImage(){return this._previousImage}get currentCamera(){return this._currentCamera}get currentTransform(){return this._trajectoryTransforms.length>0?this._trajectoryTransforms[this.currentIndex]:null}get previousTransform(){return this._trajectoryTransforms.length>1&&this.currentIndex>0?this._trajectoryTransforms[this.currentIndex-1]:null}get motionless(){return this._motionless}get transitionMode(){return this._transitionMode}move(e){}moveTo(e){}rotate(e){}rotateUnbounded(e){}rotateWithoutInertia(e){}rotateBasic(e){}rotateBasicUnbounded(e){}rotateBasicWithoutInertia(e){}rotateToBasic(e){}setSpeed(e){}zoomIn(e,t){}update(e){}setCenter(e){}setZoom(e){}dolly(e){}orbit(e){}setViewMatrix(e){}truck(e){}append(e){if(e.length<1)throw Error("Trajectory can not be empty");this._currentIndex<0?this.set(e):(this._trajectory=this._trajectory.concat(e),this._appendToTrajectories(e))}prepend(e){if(e.length<1)throw Error("Trajectory can not be empty");this._trajectory=e.slice().concat(this._trajectory),this._currentIndex+=e.length,this._setCurrentImage(),this._setReference(this._currentImage)?this._setTrajectories():this._prependToTrajectories(e),this._setCurrentCamera()}remove(e){if(e<0)throw Error("n must be a positive integer");if(this._currentIndex-1<e)throw Error("Current and previous images can not be removed");for(let t=0;t<e;t++)this._trajectory.shift(),this._trajectoryTransforms.shift(),this._trajectoryCameras.shift(),this._currentIndex--;this._setCurrentImage()}clearPrior(){this._currentIndex>0&&this.remove(this._currentIndex-1)}clear(){this.cut(),this._currentIndex>0&&this.remove(this._currentIndex-1)}cut(){for(;this._trajectory.length-1>this._currentIndex;)this._trajectory.pop(),this._trajectoryTransforms.pop(),this._trajectoryCameras.pop()}set(e){this._setTrajectory(e),this._setCurrentImage(),this._setReference(this._currentImage),this._setTrajectories(),this._setCurrentCamera()}getCenter(){return null!=this._currentImage?this.currentTransform.projectBasic(this._camera.lookat.toArray()):[.5,.5]}setTransitionMode(e){this._transitionMode=e}_getAlpha(){return 1}_getStateTransitionAlpha(){return 1}_setCurrent(){this._setCurrentImage(),this._setReference(this._currentImage)&&this._setTrajectories(),this._setCurrentCamera()}_setCurrentCamera(){this._currentCamera=this._trajectoryCameras[this._currentIndex].clone(),this._previousCamera=this._currentIndex>0?this._trajectoryCameras[this._currentIndex-1].clone():this._currentCamera.clone()}_motionlessTransition(){return null!=this._currentImage&&null!=this._previousImage&&(this._transitionMode===e.TransitionMode.Instantaneous||!(this._currentImage.merged&&this._previousImage.merged&&this._withinOriginalDistance()&&this._sameConnectedComponent()))}_setReference(e){return!(Math.abs(e.lngLat.lat-this.reference.lat)<this._referenceThreshold&&Math.abs(e.lngLat.lng-this.reference.lng)<this._referenceThreshold)&&(!(null!=this._previousImage&&!this._motionlessTransition())&&(this._reference.lat=e.lngLat.lat,this._reference.lng=e.lngLat.lng,this._reference.alt=e.computedAltitude,!0))}_setCurrentImage(){this._currentImage=this._trajectory.length>0?this._trajectory[this._currentIndex]:null,this._previousImage=this._currentIndex>0?this._trajectory[this._currentIndex-1]:null}_setTrajectory(e){if(e.length<1)throw new Lu("Trajectory can not be empty");null!=this._currentImage?(this._trajectory=[this._currentImage].concat(e),this._currentIndex=1):(this._trajectory=e.slice(),this._currentIndex=0)}_setTrajectories(){this._trajectoryTransforms.length=0,this._trajectoryCameras.length=0,this._appendToTrajectories(this._trajectory)}_appendToTrajectories(e){for(let t of e){if(!t.assetsCached)throw new Lu("Assets must be cached when image is added to trajectory");let e=this._imageToTranslation(t,this.reference),i=new ug(t.exifOrientation,t.width,t.height,t.scale,t.rotation,e,t.image,void 0,t.cameraParameters,t.cameraType);this._trajectoryTransforms.push(i),this._trajectoryCameras.push(new Nw(i))}}_prependToTrajectories(e){for(let t of e.reverse()){if(!t.assetsCached)throw new Lu("Assets must be cached when added to trajectory");let e=this._imageToTranslation(t,this.reference),i=new ug(t.exifOrientation,t.width,t.height,t.scale,t.rotation,e,t.image,void 0,t.cameraParameters,t.cameraType);this._trajectoryTransforms.unshift(i),this._trajectoryCameras.unshift(new Nw(i))}}_imageToTranslation(e,t){return Ou({alt:e.computedAltitude,lat:e.lngLat.lat,lng:e.lngLat.lng},e.rotation,t)}_sameConnectedComponent(){let e=this._currentImage,t=this._previousImage;return!!e&&!!t&&e.mergeId===t.mergeId}_withinOriginalDistance(){let e=this._currentImage,t=this._previousImage;return!e||!t||this._spatial.distanceFromLngLat(e.originalLngLat.lng,e.originalLngLat.lat,t.originalLngLat.lng,t.originalLngLat.lat)<25}}class Qw extends Kw{constructor(e){super(e)}setViewMatrix(e){const t=(new Rn).fromArray(e).invert().elements,i=new Ki(t[12],t[13],t[14]),n=new Ki(-t[8],-t[9],-t[10]),r=new Ki(t[4],t[5],t[6]),s=this._camera;s.position.copy(i),s.lookat.copy(i.clone().add(n)),s.up.copy(r);const a=.5/Math.tan(Math.PI/3);s.focal=a}}class eM extends Kw{constructor(e){super(e),this._transition=0;const t=this._camera.position.clone(),i=this._camera.lookat.clone().sub(t).normalize(),n=Math.sqrt(i.x*i.x+i.y*i.y),r=Math.atan2(i.z,n),s=new Ki;if(r>-Math.PI/45)s.copy(t),t.add(new Ki(i.x,i.y,0).multiplyScalar(-50)),t.z=30;else{const e=t.clone(),n=new Ki(0,0,1),r=new Ki(0,0,-2),a=(new Ki).subVectors(r,e).dot(n)/i.dot(n),o=1e4,h=e.clone().add(i.clone().multiplyScalar(Math.min(o,a)));s.copy(h);const c=t.clone().sub(h).normalize();t.copy(h.add(c.multiplyScalar(Math.max(50,c.length()))))}const a=this._camera.position.clone(),o=a.clone().add(i.clone().normalize().multiplyScalar(10)),h=this._camera.up.clone(),c=o.clone(),l=c.clone().add(i.clone().normalize().multiplyScalar(10)),u=h.clone(),d=t.clone(),p=s.clone(),m=new Ki(0,0,1),f=t.clone().add(p.clone().sub(d).normalize().multiplyScalar(-10)),g=p.clone(),_=m.clone();this._curveE=new dc([c,a,d,f]),this._curveL=new dc([l,o,p,g]),this._curveU=new dc([u,h,m,_]),this._zoom0=this._zoom,this._zoom1=0,this._camera.focal=.5/Math.tan(Math.PI/4)}get _isTransitioning(){return this._transition<1}dolly(e){if(this._isTransitioning)return;const t=this._camera,i=t.position.clone().sub(t.lookat),n=i.length()*Math.pow(2,-e),r=Math.max(1,Math.min(n,4e3));i.normalize(),i.multiplyScalar(r),t.position.copy(t.lookat).add(i)}orbit(e){if(this._isTransitioning)return;const t=this._camera,i=(new Ji).setFromUnitVectors(t.up,new Ki(0,0,1)),n=i.clone().invert(),r=t.position.clone().sub(t.lookat);r.applyQuaternion(i);const s=r.length();let a=Math.atan2(r.y,r.x);a+=e.phi;let o=Math.atan2(Math.sqrt(r.x*r.x+r.y*r.y),r.z);o+=e.theta;const h=Math.PI/36;o=Math.max(h,Math.min(Math.PI/2-h,o)),r.x=Math.sin(o)*Math.cos(a),r.y=Math.sin(o)*Math.sin(a),r.z=Math.cos(o),r.applyQuaternion(n),t.position.copy(t.lookat).add(r.multiplyScalar(s))}truck(e){if(this._isTransitioning)return;const t=this._camera;t.position.add((new Ki).fromArray(e)),t.lookat.add((new Ki).fromArray(e))}update(e){if(!this._isTransitioning)return;this._transition=Math.min(this._transition+2*e/3,1);const t=Oi.smootherstep(this._transition,0,1),i=(t+1)/3,n=this._curveE.getPoint(i),r=this._curveL.getPoint(i),s=this._curveU.getPoint(i);this._camera.position.copy(n),this._camera.lookat.copy(r),this._camera.up.copy(s),this._zoom=Oi.lerp(this._zoom0,this._zoom1,t),this._stateTransitionAlpha=t}_getStateTransitionAlpha(){return this._stateTransitionAlpha}}class tM{constructor(e,t){this._phi=e,this._theta=t}get phi(){return this._phi}set phi(e){this._phi=e}get theta(){return this._theta}set theta(e){this._theta=e}get isZero(){return 0===this._phi&&0===this._theta}copy(e){this._phi=e.phi,this._theta=e.theta}lerp(e,t){this._phi=(1-t)*this._phi+t*e.phi,this._theta=(1-t)*this._theta+t*e.theta}multiply(e){this._phi*=e,this._theta*=e}threshold(e){this._phi=Math.abs(this._phi)>e?this._phi:0,this._theta=Math.abs(this._theta)>e?this._theta:0}lengthSquared(){return this._phi*this._phi+this._theta*this._theta}reset(){this._phi=0,this._theta=0}}class iM extends Kw{constructor(e){super(e),this._animationSpeed=1/40,this._rotationDelta=new tM(0,0),this._requestedRotationDelta=null,this._basicRotation=[0,0],this._requestedBasicRotation=null,this._requestedBasicRotationUnbounded=null,this._rotationAcceleration=.86,this._rotationIncreaseAlpha=.97,this._rotationDecreaseAlpha=.9,this._rotationThreshold=.001,this._unboundedRotationAlpha=.8,this._desiredZoom=e.zoom,this._minZoom=0,this._maxZoom=3,this._lookatDepth=10,this._desiredLookat=null,this._desiredCenter=null}rotate(e){null!=this._currentImage&&(0===e.phi&&0===e.theta||(this._desiredZoom=this._zoom,this._desiredLookat=null,this._requestedBasicRotation=null,null!=this._requestedRotationDelta?(this._requestedRotationDelta.phi=this._requestedRotationDelta.phi+e.phi,this._requestedRotationDelta.theta=this._requestedRotationDelta.theta+e.theta):this._requestedRotationDelta=new tM(e.phi,e.theta)))}rotateUnbounded(e){if(null==this._currentImage)return;if(this._requestedBasicRotation=null,this._requestedRotationDelta=null,this._applyRotation(e,this._currentCamera),this._applyRotation(e,this._previousCamera),!this._desiredLookat)return;const t=(new Ji).setFromUnitVectors(this._currentCamera.up,new Ki(0,0,1)),i=t.clone().invert(),n=(new Ki).copy(this._desiredLookat).sub(this._camera.position).applyQuaternion(t),r=n.length();let s=Math.atan2(n.y,n.x);s+=e.phi;let a=Math.atan2(Math.sqrt(n.x*n.x+n.y*n.y),n.z);a+=e.theta,a=Math.max(.1,Math.min(Math.PI-.1,a)),n.x=Math.sin(a)*Math.cos(s),n.y=Math.sin(a)*Math.sin(s),n.z=Math.cos(a),n.applyQuaternion(i),this._desiredLookat.copy(this._camera.position).add(n.multiplyScalar(r))}rotateWithoutInertia(e){if(null==this._currentImage)return;this._desiredZoom=this._zoom,this._desiredLookat=null,this._requestedBasicRotation=null,this._requestedRotationDelta=null;const t=Math.PI/(10*Math.pow(2,this._zoom)),i={phi:this._spatial.clamp(e.phi,-t,t),theta:this._spatial.clamp(e.theta,-t,t)};this._applyRotation(i,this._currentCamera),this._applyRotation(i,this._previousCamera)}rotateBasic(e){if(null!=this._currentImage)if(this._desiredZoom=this._zoom,this._desiredLookat=null,this._requestedRotationDelta=null,null!=this._requestedBasicRotation){this._requestedBasicRotation[0]+=e[0],this._requestedBasicRotation[1]+=e[1];let t=.05/Math.pow(2,this._zoom);this._requestedBasicRotation[0]=this._spatial.clamp(this._requestedBasicRotation[0],-t,t),this._requestedBasicRotation[1]=this._spatial.clamp(this._requestedBasicRotation[1],-t,t)}else this._requestedBasicRotation=e.slice()}rotateBasicUnbounded(e){null!=this._currentImage&&(null!=this._requestedBasicRotationUnbounded?(this._requestedBasicRotationUnbounded[0]+=e[0],this._requestedBasicRotationUnbounded[1]+=e[1]):this._requestedBasicRotationUnbounded=e.slice())}rotateBasicWithoutInertia(e){if(null==this._currentImage)return;this._desiredZoom=this._zoom,this._desiredLookat=null,this._requestedRotationDelta=null,this._requestedBasicRotation=null;const t=.05/Math.pow(2,this._zoom),i=e.slice();i[0]=this._spatial.clamp(i[0],-t,t),i[1]=this._spatial.clamp(i[1],-t,t),this._applyRotationBasic(i)}rotateToBasic(e){if(null==this._currentImage)return;this._desiredZoom=this._zoom,this._desiredLookat=null,e[0]=this._spatial.clamp(e[0],0,1),e[1]=this._spatial.clamp(e[1],0,1);let t=this.currentTransform.unprojectBasic(e,this._lookatDepth);this._currentCamera.lookat.fromArray(t)}zoomIn(e,t){if(null==this._currentImage)return;this._desiredZoom=Math.max(this._minZoom,Math.min(this._maxZoom,this._desiredZoom+e));let i=this.currentTransform.projectBasic(this._currentCamera.lookat.toArray()),n=i[0],r=i[1],s=Math.pow(2,this._zoom),a=Math.pow(2,this._desiredZoom),o=t[0],h=t[1];$u(this.currentTransform.cameraType)&&(o-n>.5?o-=1:n-o>.5&&(o=1+o));let c=o-s/a*(o-n),l=h-s/a*(h-r);$u(this._currentImage.cameraType)?(c=this._spatial.wrap(c+this._basicRotation[0],0,1),l=this._spatial.clamp(l+this._basicRotation[1],.05,.95)):(c=this._spatial.clamp(c,0,1),l=this._spatial.clamp(l,0,1)),this._desiredLookat=(new Ki).fromArray(this.currentTransform.unprojectBasic([c,l],this._lookatDepth))}setCenter(e){this._desiredLookat=null,this._requestedRotationDelta=null,this._requestedBasicRotation=null,this._desiredZoom=this._zoom;let t=[this._spatial.clamp(e[0],0,1),this._spatial.clamp(e[1],0,1)];if(null==this._currentImage)return void(this._desiredCenter=t);this._desiredCenter=null;let i=(new Ki).fromArray(this.currentTransform.unprojectBasic(t,this._lookatDepth)),n=null!=this.previousTransform?this.previousTransform:this.currentTransform,r=(new Ki).fromArray(n.unprojectBasic(t,this._lookatDepth));this._currentCamera.lookat.copy(i),this._previousCamera.lookat.copy(r)}setZoom(e){this._desiredLookat=null,this._requestedRotationDelta=null,this._requestedBasicRotation=null,this._zoom=this._spatial.clamp(e,this._minZoom,this._maxZoom),this._desiredZoom=this._zoom}_applyRotation(e,t){if(null==t)return;let i=(new Ji).setFromUnitVectors(t.up,new Ki(0,0,1)),n=i.clone().invert(),r=new Ki;r.copy(t.lookat).sub(t.position),r.applyQuaternion(i);let s=r.length(),a=Math.atan2(r.y,r.x);a+=e.phi;let o=Math.atan2(Math.sqrt(r.x*r.x+r.y*r.y),r.z);o+=e.theta,o=Math.max(.1,Math.min(Math.PI-.1,o)),r.x=Math.sin(o)*Math.cos(a),r.y=Math.sin(o)*Math.sin(a),r.z=Math.cos(o),r.applyQuaternion(n),t.lookat.copy(t.position).add(r.multiplyScalar(s))}_applyRotationBasic(e){let t=this._currentImage,i=null!=this._previousImage?this.previousImage:this.currentImage,n=this._currentCamera,r=this._previousCamera,s=this.currentTransform,a=null!=this.previousTransform?this.previousTransform:this.currentTransform,o=s.projectBasic(n.lookat.toArray()),h=a.projectBasic(r.lookat.toArray());$u(t.cameraType)?(o[0]=this._spatial.wrap(o[0]+e[0],0,1),o[1]=this._spatial.clamp(o[1]+e[1],.05,.95)):(o[0]=this._spatial.clamp(o[0]+e[0],0,1),o[1]=this._spatial.clamp(o[1]+e[1],0,1)),$u(i.cameraType)?(h[0]=this._spatial.wrap(h[0]+e[0],0,1),h[1]=this._spatial.clamp(h[1]+e[1],.05,.95)):(h[0]=this._spatial.clamp(h[0]+e[0],0,1),h[1]=this._spatial.clamp(o[1]+e[1],0,1));let c=s.unprojectBasic(o,this._lookatDepth);n.lookat.fromArray(c);let l=a.unprojectBasic(h,this._lookatDepth);r.lookat.fromArray(l)}_updateZoom(e){let t=this._desiredZoom-this._zoom,i=t>0?1:t<0?-1:0;0!==t&&(Math.abs(t)<.002?(this._zoom=this._desiredZoom,null!=this._desiredLookat&&(this._desiredLookat=null)):this._zoom+=i*Math.max(Math.abs(5*e*t),.002))}_updateLookat(e){if(null===this._desiredLookat)return;let t=this._desiredLookat.distanceToSquared(this._currentCamera.lookat);Math.abs(t)<1e-6?(this._currentCamera.lookat.copy(this._desiredLookat),this._desiredLookat=null):this._currentCamera.lookat.lerp(this._desiredLookat,5*e)}_updateRotation(){if(null!=this._requestedRotationDelta){let e=this._rotationDelta.lengthSquared();return this._requestedRotationDelta.lengthSquared()>e?this._rotationDelta.lerp(this._requestedRotationDelta,this._rotationIncreaseAlpha):this._rotationDelta.lerp(this._requestedRotationDelta,this._rotationDecreaseAlpha),void(this._requestedRotationDelta=null)}if(this._rotationDelta.isZero)return;const e=$u(this.currentImage.cameraType)?1:this._alpha;this._rotationDelta.multiply(this._rotationAcceleration*e),this._rotationDelta.threshold(this._rotationThreshold)}_updateRotationBasic(){if(null!=this._requestedBasicRotation){let e=this._basicRotation[0],t=this._basicRotation[1],i=this._requestedBasicRotation[0],n=this._requestedBasicRotation[1];return Math.abs(i)>Math.abs(e)?this._basicRotation[0]=(1-this._rotationIncreaseAlpha)*e+this._rotationIncreaseAlpha*i:this._basicRotation[0]=(1-this._rotationDecreaseAlpha)*e+this._rotationDecreaseAlpha*i,Math.abs(n)>Math.abs(t)?this._basicRotation[1]=(1-this._rotationIncreaseAlpha)*t+this._rotationIncreaseAlpha*n:this._basicRotation[1]=(1-this._rotationDecreaseAlpha)*t+this._rotationDecreaseAlpha*n,void(this._requestedBasicRotation=null)}if(null!=this._requestedBasicRotationUnbounded){let e=this._requestedBasicRotationUnbounded[0],t=this._requestedBasicRotationUnbounded[1];if(Math.abs(e)>0&&(this._basicRotation[0]=(1-this._unboundedRotationAlpha)*this._basicRotation[0]+this._unboundedRotationAlpha*e),Math.abs(t)>0&&(this._basicRotation[1]=(1-this._unboundedRotationAlpha)*this._basicRotation[1]+this._unboundedRotationAlpha*t),null!=this._desiredLookat){let i=this.currentTransform.projectBasic(this._desiredLookat.toArray());i[0]+=e,i[1]+=t,this._desiredLookat=(new Ki).fromArray(this.currentTransform.unprojectBasic(i,this._lookatDepth))}this._requestedBasicRotationUnbounded=null}0===this._basicRotation[0]&&0===this._basicRotation[1]||(this._basicRotation[0]=this._rotationAcceleration*this._basicRotation[0],this._basicRotation[1]=this._rotationAcceleration*this._basicRotation[1],Math.abs(this._basicRotation[0])<this._rotationThreshold/Math.pow(2,this._zoom)&&Math.abs(this._basicRotation[1])<this._rotationThreshold/Math.pow(2,this._zoom)&&(this._basicRotation=[0,0]))}_clearRotation(){$u(this._currentImage.cameraType)||(null!=this._requestedRotationDelta&&(this._requestedRotationDelta=null),this._rotationDelta.isZero||this._rotationDelta.reset(),null!=this._requestedBasicRotation&&(this._requestedBasicRotation=null),(this._basicRotation[0]>0||this._basicRotation[1]>0)&&(this._basicRotation=[0,0]))}_setDesiredCenter(){if(null==this._desiredCenter)return;let e=(new Ki).fromArray(this.currentTransform.unprojectBasic(this._desiredCenter,this._lookatDepth)).sub(this._currentCamera.position);this._currentCamera.lookat.copy(this._currentCamera.position.clone().add(e)),this._previousCamera.lookat.copy(this._previousCamera.position.clone().add(e)),this._desiredCenter=null}_setDesiredZoom(){this._desiredZoom=$u(this._currentImage.cameraType)||null==this._previousImage?this._zoom:0}}class nM extends iM{constructor(e){super(e),this._adjustCameras(),this._motionless=this._motionlessTransition()}prepend(e){super.prepend(e),this._motionless=this._motionlessTransition()}set(e){super.set(e),this._motionless=this._motionlessTransition()}move(e){this._alpha=Math.max(0,Math.min(1,this._alpha+e))}moveTo(e){this._alpha=Math.max(0,Math.min(1,e))}update(e){this._updateRotation(),this._rotationDelta.isZero||(this._applyRotation(this._rotationDelta,this._previousCamera),this._applyRotation(this._rotationDelta,this._currentCamera)),this._updateRotationBasic(),0===this._basicRotation[0]&&0===this._basicRotation[1]||this._applyRotationBasic(this._basicRotation);let t=this._animationSpeed*e/.1*6;this._updateZoom(t),this._updateLookat(t),this._camera.lerpCameras(this._previousCamera,this._currentCamera,this.alpha)}_getAlpha(){return this._motionless?Math.round(this._alpha):this._alpha}_setCurrentCamera(){super._setCurrentCamera(),this._adjustCameras()}_adjustCameras(){if(null!=this._previousImage){if($u(this._currentImage.cameraType)){let e=this._camera.lookat.clone().sub(this._camera.position);this._currentCamera.lookat.copy(e.clone().add(this._currentCamera.position))}if($u(this._previousImage.cameraType)){let e=this._currentCamera.lookat.clone().sub(this._currentCamera.position);this._previousCamera.lookat.copy(e.clone().add(this._previousCamera.position))}}}}class rM extends iM{constructor(e){super(e),this._adjustCameras(),this._motionless=this._motionlessTransition(),this._baseAlpha=this._alpha,this._speedCoefficient=1,this._smoothing=!1}append(e){let t=0===this._trajectory.length;t&&this._resetTransition(),super.append(e),t&&(this._setDesiredCenter(),this._setDesiredZoom())}prepend(e){let t=0===this._trajectory.length;t&&this._resetTransition(),super.prepend(e),t&&(this._setDesiredCenter(),this._setDesiredZoom())}set(e){super.set(e),this._desiredLookat=null,this._resetTransition(),this._clearRotation(),this._setDesiredCenter(),this._setDesiredZoom(),this._trajectory.length<3&&(this._smoothing=!0)}setSpeed(e){this._speedCoefficient=this._spatial.clamp(e,0,10)}update(e){1===this._alpha&&this._currentIndex+this._alpha<this._trajectory.length&&(this._currentIndex+=1,this._smoothing=this._trajectory.length<3&&this._currentIndex+1===this._trajectory.length,this._setCurrent(),this._resetTransition(),this._clearRotation(),this._desiredZoom=$u(this._currentImage.cameraType)?this._zoom:0,this._desiredLookat=null);let t=this._animationSpeed*e/.1*6;this._baseAlpha=Math.min(1,this._baseAlpha+this._speedCoefficient*t),this._smoothing?this._alpha=Oi.smootherstep(this._baseAlpha,0,1):this._alpha=this._baseAlpha,this._updateRotation(),this._rotationDelta.isZero||(this._applyRotation(this._rotationDelta,this._previousCamera),this._applyRotation(this._rotationDelta,this._currentCamera)),this._updateRotationBasic(),0===this._basicRotation[0]&&0===this._basicRotation[1]||this._applyRotationBasic(this._basicRotation),this._updateZoom(t),this._updateLookat(t),this._camera.lerpCameras(this._previousCamera,this._currentCamera,this.alpha)}_getAlpha(){return this._motionless?Math.ceil(this._alpha):this._alpha}_setCurrentCamera(){super._setCurrentCamera(),this._adjustCameras()}_adjustCameras(){if(null==this._previousImage)return;let e=this._camera.lookat.clone().sub(this._camera.position);this._previousCamera.lookat.copy(e.clone().add(this._previousCamera.position)),$u(this._currentImage.cameraType)&&this._currentCamera.lookat.copy(e.clone().add(this._currentCamera.position))}_resetTransition(){this._alpha=0,this._baseAlpha=0,this._motionless=this._motionlessTransition()}}class sM extends Kw{constructor(e){super(e),this._zoom=0,this._adjustCameras(),this._motionless=this._motionlessTransition()}prepend(e){super.prepend(e),this._motionless=this._motionlessTransition()}set(e){super.set(e),this._motionless=this._motionlessTransition()}move(e){this._alpha=Math.max(0,Math.min(1,this._alpha+e))}moveTo(e){this._alpha=Math.max(0,Math.min(1,e))}update(){this._camera.lerpCameras(this._previousCamera,this._currentCamera,this.alpha)}_getAlpha(){return this._motionless?Math.round(this._alpha):this._alpha}_setCurrentCamera(){super._setCurrentCamera(),this._adjustCameras()}_adjustCameras(){if(null!=this._previousImage){if($u(this._currentImage.cameraType)){let e=this._camera.lookat.clone().sub(this._camera.position);this._currentCamera.lookat.copy(e.clone().add(this._currentCamera.position))}if($u(this._previousImage.cameraType)){let e=this._currentCamera.lookat.clone().sub(this._currentCamera.position);this._previousCamera.lookat.copy(e.clone().add(this._previousCamera.position))}}}}class aM{constructor(){const e=Df[Df.Custom],t=Df[Df.Earth],i=Df[Df.Traversing],n=Df[Df.Waiting],r=Df[Df.WaitingInteractively];this._creators=new Map;const s=this._creators;s.set(e,Qw),s.set(t,eM),s.set(i,rM),s.set(n,sM),s.set(r,nM),this._transitions=new Map;const a=this._transitions;a.set(e,[t,i]),a.set(t,[e,i]),a.set(i,[e,t,n,r]),a.set(n,[i,r]),a.set(r,[i,n])}getState(e){if(e instanceof Qw)return Df.Custom;if(e instanceof eM)return Df.Earth;if(e instanceof rM)return Df.Traversing;if(e instanceof sM)return Df.Waiting;if(e instanceof nM)return Df.WaitingInteractively;throw new Error("Invalid state instance")}generate(e,t){return new(this._creators.get(Df[e]))(t)}transition(e,t){if(!this.validate(e,t))throw new Error("Invalid transition");return this.generate(t,e)}validate(e,t){const i=Df[this.getState(e)],n=Df[t],r=this._transitions;return r.has(i)&&r.get(i).includes(n)}}class oM{constructor(t,i){this._transitions=new aM,this._state=this._transitions.generate(t,{alpha:1,camera:new Nw,currentIndex:-1,reference:{alt:0,lat:0,lng:0},trajectory:[],transitionMode:null==i?e.TransitionMode.Default:i,zoom:0})}get state(){return this._transitions.getState(this._state)}get reference(){return this._state.reference}get alpha(){return this._state.alpha}get stateTransitionAlpha(){return this._state.stateTransitionAlpha}get camera(){return this._state.camera}get zoom(){return this._state.zoom}get currentImage(){return this._state.currentImage}get previousImage(){return this._state.previousImage}get currentCamera(){return this._state.currentCamera}get currentTransform(){return this._state.currentTransform}get previousTransform(){return this._state.previousTransform}get trajectory(){return this._state.trajectory}get currentIndex(){return this._state.currentIndex}get lastImage(){return this._state.trajectory[this._state.trajectory.length-1]}get imagesAhead(){return this._state.trajectory.length-1-this._state.currentIndex}get motionless(){return this._state.motionless}custom(){this._transition(Df.Custom)}earth(){this._transition(Df.Earth)}traverse(){this._transition(Df.Traversing)}wait(){this._transition(Df.Waiting)}waitInteractively(){this._transition(Df.WaitingInteractively)}getCenter(){return this._state.getCenter()}setCenter(e){this._state.setCenter(e)}setZoom(e){this._state.setZoom(e)}update(e){this._state.update(e)}append(e){this._state.append(e)}prepend(e){this._state.prepend(e)}remove(e){this._state.remove(e)}clear(){this._state.clear()}clearPrior(){this._state.clearPrior()}cut(){this._state.cut()}set(e){this._state.set(e)}setViewMatrix(e){this._state.setViewMatrix(e)}rotate(e){this._state.rotate(e)}rotateUnbounded(e){this._state.rotateUnbounded(e)}rotateWithoutInertia(e){this._state.rotateWithoutInertia(e)}rotateBasic(e){this._state.rotateBasic(e)}rotateBasicUnbounded(e){this._state.rotateBasicUnbounded(e)}rotateBasicWithoutInertia(e){this._state.rotateBasicWithoutInertia(e)}rotateToBasic(e){this._state.rotateToBasic(e)}move(e){this._state.move(e)}moveTo(e){this._state.moveTo(e)}zoomIn(e,t){this._state.zoomIn(e,t)}setSpeed(e){this._state.setSpeed(e)}setTransitionMode(e){this._state.setTransitionMode(e)}dolly(e){this._state.dolly(e)}orbit(e){this._state.orbit(e)}truck(e){this._state.truck(e)}_transition(e){if(!this._transitions.validate(this._state,e)){const t=this._transitions.getState(this._state);return void console.warn(`Transition not valid (${Df[t]} - ${Df[e]})`)}const t=this._transitions.transition(this._state,e);this._state=t}}class hM{constructor(e,t){this._appendImage$=new j,this._clock=new jl,this._subscriptions=new rf;const i=this._subscriptions;this._start$=new j,this._frame$=new j,this._contextOperation$=new W((e=>e)),this._context$=this._contextOperation$.pipe(Lt(((e,t)=>t(e)),new oM(e,t)),Rt(1),U()),this._state$=this._context$.pipe(De((e=>e.state)),vt(),Rt(1),U()),this._currentState$=this._frame$.pipe(Vt(this._context$,((e,t)=>[e,t])),st((e=>null!=e[1].currentImage)),Ut((e=>{e[1].update(this._clock.getDelta())})),De((e=>({fps:60,id:e[0],state:e[1]}))),Dt()),this._lastState$=this._currentState$.pipe(Rt(1),U());let n=this._currentState$.pipe(vt(void 0,(e=>e.state.currentImage.id)),Rt(1),U()),r=new j;i.push(n.subscribe(r)),this._currentId$=new W(null),i.push(r.pipe(De((e=>e.state.currentImage.id))).subscribe(this._currentId$)),this._currentImage$=r.pipe(De((e=>e.state.currentImage)),Rt(1),U()),this._currentCamera$=r.pipe(De((e=>e.state.currentCamera)),Rt(1),U()),this._currentTransform$=r.pipe(De((e=>e.state.currentTransform)),Rt(1),U()),this._reference$=r.pipe(De((e=>e.state.reference)),vt(((e,t)=>e.lat===t.lat&&e.lng===t.lng),(e=>({lat:e.lat,lng:e.lng}))),Rt(1),U()),this._currentImageExternal$=n.pipe(De((e=>e.state.currentImage)),Rt(1),U()),i.push(this._appendImage$.pipe(De((e=>t=>(t.append([e]),t)))).subscribe(this._contextOperation$)),this._inMotionOperation$=new j,i.push(n.pipe(De((()=>!0))).subscribe(this._inMotionOperation$)),i.push(this._inMotionOperation$.pipe(vt(),st((e=>e)),zt((()=>this._currentState$.pipe(st((e=>0===e.state.imagesAhead)),De((e=>[e.state.camera.clone(),e.state.zoom])),At(),De((e=>{let t=e[0][0],i=e[1][0],n=e[0][1],r=e[1][1];return t.diff(i)>1e-5||Math.abs(n-r)>1e-5})),St((e=>!e)))))).subscribe(this._inMotionOperation$)),this._inMotion$=this._inMotionOperation$.pipe(vt(),Rt(1),U()),this._inTranslationOperation$=new j,i.push(n.pipe(De((()=>!0))).subscribe(this._inTranslationOperation$)),i.push(this._inTranslationOperation$.pipe(vt(),st((e=>e)),zt((()=>this._currentState$.pipe(st((e=>0===e.state.imagesAhead)),De((e=>e.state.camera.position.clone())),At(),De((e=>0!==e[0].distanceToSquared(e[1]))),St((e=>!e)))))).subscribe(this._inTranslationOperation$)),this._inTranslation$=this._inTranslationOperation$.pipe(vt(),Rt(1),U()),i.push(this._state$.subscribe((()=>{}))),i.push(this._currentImage$.subscribe((()=>{}))),i.push(this._currentCamera$.subscribe((()=>{}))),i.push(this._currentTransform$.subscribe((()=>{}))),i.push(this._reference$.subscribe((()=>{}))),i.push(this._currentImageExternal$.subscribe((()=>{}))),i.push(this._lastState$.subscribe((()=>{}))),i.push(this._inMotion$.subscribe((()=>{}))),i.push(this._inTranslation$.subscribe((()=>{}))),this._frameId=null,this._frameGenerator=new Jw(window)}get currentState$(){return this._currentState$}get currentImage$(){return this._currentImage$}get currentId$(){return this._currentId$}get currentImageExternal$(){return this._currentImageExternal$}get currentCamera$(){return this._currentCamera$}get currentTransform$(){return this._currentTransform$}get state$(){return this._state$}get reference$(){return this._reference$}get inMotion$(){return this._inMotion$}get inTranslation$(){return this._inTranslation$}get appendImage$(){return this._appendImage$}dispose(){this.stop(),this._subscriptions.unsubscribe()}custom(){this._inMotionOperation$.next(!0),this._invokeContextOperation((e=>{e.custom()}))}earth(){this._inMotionOperation$.next(!0),this._invokeContextOperation((e=>{e.earth()}))}traverse(){this._inMotionOperation$.next(!0),this._invokeContextOperation((e=>{e.traverse()}))}wait(){this._invokeContextOperation((e=>{e.wait()}))}waitInteractively(){this._invokeContextOperation((e=>{e.waitInteractively()}))}appendImagess(e){this._invokeContextOperation((t=>{t.append(e)}))}prependImages(e){this._invokeContextOperation((t=>{t.prepend(e)}))}removeImages(e){this._invokeContextOperation((t=>{t.remove(e)}))}clearImages(){this._invokeContextOperation((e=>{e.clear()}))}clearPriorImages(){this._invokeContextOperation((e=>{e.clearPrior()}))}cutImages(){this._invokeContextOperation((e=>{e.cut()}))}setImages(e){this._invokeContextOperation((t=>{t.set(e)}))}setViewMatrix(e){this._inMotionOperation$.next(!0),this._invokeContextOperation((t=>{t.setViewMatrix(e)}))}rotate(e){this._inMotionOperation$.next(!0),this._invokeContextOperation((t=>{t.rotate(e)}))}rotateUnbounded(e){this._inMotionOperation$.next(!0),this._invokeContextOperation((t=>{t.rotateUnbounded(e)}))}rotateWithoutInertia(e){this._inMotionOperation$.next(!0),this._invokeContextOperation((t=>{t.rotateWithoutInertia(e)}))}rotateBasic(e){this._inMotionOperation$.next(!0),this._invokeContextOperation((t=>{t.rotateBasic(e)}))}rotateBasicUnbounded(e){this._inMotionOperation$.next(!0),this._invokeContextOperation((t=>{t.rotateBasicUnbounded(e)}))}rotateBasicWithoutInertia(e){this._inMotionOperation$.next(!0),this._invokeContextOperation((t=>{t.rotateBasicWithoutInertia(e)}))}rotateToBasic(e){this._inMotionOperation$.next(!0),this._invokeContextOperation((t=>{t.rotateToBasic(e)}))}move(e){this._inMotionOperation$.next(!0),this._invokeContextOperation((t=>{t.move(e)}))}moveTo(e){this._inMotionOperation$.next(!0),this._invokeContextOperation((t=>{t.moveTo(e)}))}dolly(e){this._inMotionOperation$.next(!0),this._invokeContextOperation((t=>{t.dolly(e)}))}orbit(e){this._inMotionOperation$.next(!0),this._invokeContextOperation((t=>{t.orbit(e)}))}truck(e){this._inMotionOperation$.next(!0),this._invokeContextOperation((t=>{t.truck(e)}))}zoomIn(e,t){this._inMotionOperation$.next(!0),this._invokeContextOperation((i=>{i.zoomIn(e,t)}))}getCenter(){return this._lastState$.pipe(St(),De((e=>e.state.getCenter())))}getZoom(){return this._lastState$.pipe(St(),De((e=>e.state.zoom)))}setCenter(e){this._inMotionOperation$.next(!0),this._invokeContextOperation((t=>{t.setCenter(e)}))}setSpeed(e){this._invokeContextOperation((t=>{t.setSpeed(e)}))}setTransitionMode(e){this._invokeContextOperation((t=>{t.setTransitionMode(e)}))}setZoom(e){this._inMotionOperation$.next(!0),this._invokeContextOperation((t=>{t.setZoom(e)}))}start(){this._clock.start(),null==this._frameId&&(this._start$.next(null),this._frameId=this._frameGenerator.requestAnimationFrame(this._frame.bind(this)),this._frame$.next(this._frameId))}stop(){this._clock.stop(),null!=this._frameId&&(this._frameGenerator.cancelAnimationFrame(this._frameId),this._frameId=null)}_invokeContextOperation(e){this._contextOperation$.next((t=>(e(t),t)))}_frame(){this._frameId=this._frameGenerator.requestAnimationFrame(this._frame.bind(this)),this._frame$.next(this._frameId)}}function cM(t){switch(t){case e.CameraControls.Custom:return Df.Custom;case e.CameraControls.Earth:return Df.Earth;case e.CameraControls.Street:return Df.Traversing;default:return null}}class lM{constructor(t,i,n,r,s,a,o,h){var c;i?this._api=i:t.dataProvider?this._api=new Zw(t.dataProvider):this._api=new Zw(new Mw({accessToken:t.accessToken})),this._graphService=null!=n?n:new Yw(new Uu(this.api)),this._loadingName="navigator",this._loadingService=null!=r?r:new Ww;const l=null!==(c=t.cameraControls)&&void 0!==c?c:e.CameraControls.Street;this._stateService=null!=s?s:new hM(cM(l),t.transitionMode),this._cacheService=null!=a?a:new Gw(this._graphService,this._stateService,this._api),this._playService=null!=o?o:new fg(this._graphService,this._stateService),this._panService=null!=h?h:new Xw(this._graphService,this._stateService,t.combinedPanning),this._idRequested$=new W(null),this._movedToId$=new W(null),this._request$=null,this._requestSubscription=null,this._imageRequestSubscription=null}get api(){return this._api}get cacheService(){return this._cacheService}get graphService(){return this._graphService}get loadingService(){return this._loadingService}get movedToId$(){return this._movedToId$}get panService(){return this._panService}get playService(){return this._playService}get stateService(){return this._stateService}dispose(){this._abortRequest("viewer removed"),this._cacheService.stop(),this._graphService.dispose(),this._panService.dispose(),this._playService.dispose(),this._stateService.dispose()}moveTo$(e){this._abortRequest(`to id ${e}`),this._loadingService.startLoading(this._loadingName);const t=this._moveTo$(e);return this._makeRequest$(t)}moveDir$(t){this._abortRequest(`in dir ${e.NavigationDirection[t]}`),this._loadingService.startLoading(this._loadingName);const i=this.stateService.currentImage$.pipe(St(),We((i=>([e.NavigationDirection.Next,e.NavigationDirection.Prev].indexOf(t)>-1?i.sequenceEdges$:i.spatialEdges$).pipe(St(),De((e=>{for(let i of e.edges)if(i.data.direction===t)return i.target;return null}))))),We((e=>null==e?(this._loadingService.stopLoading(this._loadingName),Ee(new Error(`Direction (${t}) does not exist for current image.`))):this._moveTo$(e))));return this._makeRequest$(i)}setFilter$(e){return this._stateService.clearImages(),this._movedToId$.pipe(St(),We((t=>null!=t?this._trajectoryIds$().pipe(We((t=>this._graphService.setFilter$(e).pipe(We((()=>this._cacheIds$(t)))))),Ct()):this._idRequested$.pipe(St(),We((t=>null!=t?this._graphService.setFilter$(e).pipe(We((()=>this._graphService.cacheImage$(t)))):this._graphService.setFilter$(e).pipe(De((()=>{})))))))),De((()=>{})))}setAccessToken$(e){return this._abortRequest("to set user token"),this._stateService.clearImages(),this._movedToId$.pipe(St(),Ut((()=>{this._api.setAccessToken(e)})),We((e=>null==e?this._graphService.reset$([]):this._trajectoryIds$().pipe(We((e=>this._graphService.reset$(e).pipe(We((()=>this._cacheIds$(e)))))),Ct(),De((()=>{}))))))}_cacheIds$(e){return ge(e.map((e=>this._graphService.cacheImage$(e)))).pipe(qe())}_abortRequest(e){null!=this._requestSubscription&&(this._requestSubscription.unsubscribe(),this._requestSubscription=null),null!=this._imageRequestSubscription&&(this._imageRequestSubscription.unsubscribe(),this._imageRequestSubscription=null),null!=this._request$&&(this._request$.isStopped||this._request$.hasError||this._request$.error(new uf(`Request aborted by a subsequent request ${e}.`)),this._request$=null)}_makeRequest$(e){const t=new X(1);return this._requestSubscription=t.subscribe(void 0,(()=>{})),this._request$=t,this._imageRequestSubscription=e.subscribe((e=>{this._request$=null,t.next(e),t.complete()}),(e=>{this._request$=null,t.error(e)})),t}_moveTo$(e){return this._idRequested$.next(e),this._graphService.cacheImage$(e).pipe(Ut((e=>{this._stateService.setImages([e]),this._movedToId$.next(e.id)})),Mt((()=>{this._loadingService.stopLoading(this._loadingName)})))}_trajectoryIds$(){return this._stateService.currentState$.pipe(St(),De((e=>e.state.trajectory.map((e=>e.id)))))}}class uM{constructor(e,t){this._spatial=null!=t?t:new Du,this._viewportCoords=null!=e?e:new hf}basicToCanvas(e,t,i,n){return this._viewportCoords.basicToCanvasSafe(e[0],e[1],t,n,i.perspective)}canvasToBasic(e,t,i,n){let r=this._viewportCoords.canvasToBasic(e[0],e[1],t,n,i.perspective);return(r[0]<0||r[0]>1||r[1]<0||r[1]>1)&&(r=null),r}eventToUnprojection(e,t,i,n,r){const s=this._viewportCoords.canvasPosition(e,t);return this.canvasToUnprojection(s,t,i,n,r)}canvasToUnprojection(e,t,i,n,r){const s=e[0],a=e[1],[o,h]=this._viewportCoords.canvasToViewport(s,a,t),c=new Ki(o,h,1).unproject(i.perspective);let l=r.projectBasic(c.toArray());(l[0]<0||l[0]>1||l[1]<0||l[1]>1)&&(l=null);const u=c.clone().sub(i.camera.position).normalize(),d=-2/u.z;let p=null;if(d>0&&d<100&&l){const e=u.clone().multiplyScalar(d).add(i.camera.position),[t,r]=vu(e.x,e.y,e.z,n.lng,n.lat,n.alt);p={lat:r,lng:t}}return{basicPoint:l,lngLat:p,pixelPoint:[s,a]}}cameraToLngLat(e,t){const i=e.camera.position,[n,r]=vu(i.x,i.y,i.z,t.lng,t.lat,t.alt);return{lat:r,lng:n}}lngLatToCanvas(e,t,i,n){const r=_u(e.lng,e.lat,0,n.lng,n.lat,n.alt);return this._viewportCoords.projectToCanvasSafe(r,t,i.perspective)}distanceBetweenLngLats(e,t){return this._spatial.distanceFromLngLat(e.lng,e.lat,t.lng,t.lat)}}class dM{constructor(e,t,i){this._subscriptions=new rf,this._emitSubscriptions=new rf,this._container=i,this._viewer=e,this._navigator=t,this._projection=new uM,this._started=!1,this._navigable$=new j;const n=this._subscriptions;n.push(this._navigable$.subscribe((e=>{const t="navigable",i={navigable:e,target:this._viewer,type:t};this._viewer.fire(t,i)}))),n.push(this._navigator.loadingService.loading$.subscribe((e=>{const t="dataloading",i={loading:e,target:this._viewer,type:t};this._viewer.fire(t,i)}))),n.push(this._container.glRenderer.opaqueRender$.pipe(St()).subscribe((()=>{const e="load",t={target:this._viewer,type:e};this._viewer.fire(e,t)})))}get started(){return this._started}get navigable$(){return this._navigable$}get projection(){return this._projection}dispose(){this.stopEmit(),this._subscriptions.unsubscribe()}project$(e){return Ve(this._container.renderService.renderCamera$,this._navigator.stateService.currentImage$,this._navigator.stateService.reference$).pipe(St(),De((([t,i,n])=>{if(this._projection.distanceBetweenLngLats(e,i.lngLat)>1e3)return null;const r=this._projection.lngLatToCanvas(e,this._container.container,t,n);return r?[Math.round(r[0]),Math.round(r[1])]:null})))}projectBasic$(e){return Ve(this._container.renderService.renderCamera$,this._navigator.stateService.currentTransform$).pipe(St(),De((([t,i])=>{const n=this._projection.basicToCanvas(e,this._container.container,t,i);return n?[Math.round(n[0]),Math.round(n[1])]:null})))}startEmit(){if(this._started)return;this._started=!0;const e=this._emitSubscriptions;e.push(this._navigator.stateService.currentImageExternal$.subscribe((e=>{const t="image",i={image:e,target:this._viewer,type:t};this._viewer.fire(t,i)}))),e.push(this._navigator.stateService.currentImageExternal$.pipe(zt((e=>e.sequenceEdges$))).subscribe((e=>{const t="sequenceedges",i={status:e,target:this._viewer,type:t};this._viewer.fire(t,i)}))),e.push(this._navigator.stateService.currentImageExternal$.pipe(zt((e=>e.spatialEdges$))).subscribe((e=>{const t="spatialedges",i={status:e,target:this._viewer,type:t};this._viewer.fire(t,i)}))),e.push(this._navigator.stateService.reference$.subscribe((e=>{const t="reference",i={reference:e,target:this._viewer,type:t};this._viewer.fire(t,i)}))),e.push(Ve(this._navigator.stateService.inMotion$,this._container.mouseService.active$,this._container.touchService.active$).pipe(De((e=>e[0]||e[1]||e[2])),vt()).subscribe((e=>{const t=e?"movestart":"moveend",i={target:this._viewer,type:t};this._viewer.fire(t,i)}))),e.push(this._container.renderService.bearing$.pipe(ot(100),vt(((e,t)=>Math.abs(t-e)<1))).subscribe((e=>{const t="bearing",i={bearing:e,target:this._viewer,type:t};this._viewer.fire(t,i)})));const t=this._container.mouseService.active$.pipe(zt((e=>e?ie():this._container.mouseService.mouseMove$)));e.push(it(this._mapMouseEvent$("click",this._container.mouseService.staticClick$),this._mapMouseEvent$("contextmenu",this._container.mouseService.contextMenu$),this._mapMouseEvent$("dblclick",this._container.mouseService.dblClick$),this._mapMouseEvent$("mousedown",this._container.mouseService.mouseDown$),this._mapMouseEvent$("mousemove",t),this._mapMouseEvent$("mouseout",this._container.mouseService.mouseOut$),this._mapMouseEvent$("mouseover",this._container.mouseService.mouseOver$),this._mapMouseEvent$("mouseup",this._container.mouseService.mouseUp$)).pipe(Vt(this._container.renderService.renderCamera$,this._navigator.stateService.reference$,this._navigator.stateService.currentTransform$,this._navigator.stateService.state$),De((([[e,t],i,n,r,s])=>{const a=this._projection.eventToUnprojection(t,this._container.container,i,n,r);return{basicPoint:s===Df.Traversing?a.basicPoint:null,lngLat:a.lngLat,originalEvent:t,pixelPoint:a.pixelPoint,target:this._viewer,type:e}}))).subscribe((e=>{this._viewer.fire(e.type,e)}))),e.push(this._container.renderService.renderCamera$.pipe(vt((([e,t],[i,n])=>this._closeTo(e,i,.01)&&this._closeTo(t,n,.01)),(e=>e.camera.position.toArray()))).subscribe((()=>{const e="position",t={target:this._viewer,type:e};this._viewer.fire(e,t)}))),e.push(this._container.renderService.renderCamera$.pipe(vt((([e,t],[i,n])=>this._closeTo(e,i,.001)&&this._closeTo(t,n,.001)),(e=>[e.rotation.phi,e.rotation.theta]))).subscribe((()=>{const e={target:this._viewer,type:"pov"};this._viewer.fire("pov",e)}))),e.push(this._container.renderService.renderCamera$.pipe(vt(((e,t)=>this._closeTo(e,t,.01)),(e=>e.perspective.fov))).subscribe((()=>{const e={target:this._viewer,type:"fov"};this._viewer.fire("fov",e)})))}stopEmit(){this.started&&(this._emitSubscriptions.unsubscribe(),this._started=!1)}unproject$(e){return Ve(this._container.renderService.renderCamera$,this._navigator.stateService.reference$,this._navigator.stateService.currentTransform$).pipe(St(),De((([t,i,n])=>this._projection.canvasToUnprojection(e,this._container.container,t,i,n).lngLat)))}unprojectBasic$(e){return Ve(this._container.renderService.renderCamera$,this._navigator.stateService.currentTransform$).pipe(St(),De((([t,i])=>this._projection.canvasToBasic(e,this._container.container,t,i))))}_closeTo(e,t,i){return Math.abs(e-t)<=i}_mapMouseEvent$(e,t){return t.pipe(De((t=>[e,t])))}}class pM{constructor(e,t){this._container=e,this._navigator=t,this._renderers={}}add(e,t){const i=new rf;this._renderers[e.id]={subs:i,renderer:e},i.push(Ve([this._container.glRenderer.webGLRenderer$,this._navigator.stateService.reference$]).pipe(_t(1)).subscribe((([i,n])=>{e.onAdd(t,n,i.getContext())}))),i.push(this._container.glRenderer.opaqueRender$.pipe(Vt(this._container.renderService.renderCamera$,this._container.glRenderer.webGLRenderer$)).subscribe((([,t,i])=>{const n=i.getContext(),r=t.perspective.matrixWorldInverse,s=t.perspective.projectionMatrix;e.render(n,r.toArray(),s.toArray())}))),i.push(this._navigator.stateService.reference$.pipe($t(1)).subscribe((i=>{e.onReference(t,i)})))}dispose(e){for(const t of Object.keys(this._renderers))this.remove(t,e)}has(e){return e in this._renderers}remove(e,t){this._renderers[e].subs.unsubscribe();const i=this._renderers[e].renderer;delete this._renderers[e],this._container.glRenderer.webGLRenderer$.subscribe((e=>{i.onRemove(t,e.getContext())}))}}class mM{constructor(e,t){this._container=e,this._navigator=t,this._controls=null,this._subscriptions=new rf}attach(e,t){if(this._controls)throw new Pu("Custom camera controls already attached");this._controls=e;const i=new j,n=i.pipe(zt((()=>this._navigator.stateService.state$)),De((e=>e===Df.Custom)),vt()),r=this._subscriptions;r.push(n.pipe(Ot(!1),At(),Vt(this._navigator.stateService.reference$,this._container.renderService.renderCamera$)).subscribe((([[i,n],r,s])=>{n?e.onActivate(t,s.perspective.matrixWorldInverse.toArray(),s.perspective.projectionMatrix.toArray(),r):i&&e.onDeactivate(t)}))),r.push(n.pipe(zt((e=>e?this._navigator.stateService.currentState$.pipe($t(1)):ie()))).subscribe((i=>{e.onAnimationFrame(t,i.id)}))),r.push(n.pipe(zt((e=>e?this._navigator.stateService.reference$.pipe($t(1)):ie()))).subscribe((i=>e.onReference(t,i)))),r.push(n.pipe(zt((e=>e?this._container.renderService.size$.pipe($t(1)):ie()))).subscribe((()=>e.onResize(t)))),r.push(Ve([this._container.glRenderer.webGLRenderer$,this._container.renderService.renderCamera$,this._navigator.stateService.reference$,this._navigator.stateService.state$]).pipe(St()).subscribe((()=>{e.onAttach(t,(t=>{this._controls&&e===this._controls&&this._updateViewMatrix(t)}),(t=>{this._controls&&e===this._controls&&this._updateProjectionMatrix(t)})),i.next(),i.complete()})))}detach(e){const t=this._controls;return this._controls=null,this._subscriptions.unsubscribe(),new Promise((i=>{this._navigator.stateService.state$.pipe(_t(1)).subscribe((n=>{t?(n===Df.Custom&&t.onDeactivate(e),t.onDetach(e),i(t)):i(null)}))}))}dispose(e){this.detach(e)}has(e){return!!this._controls&&e===this._controls}_updateProjectionMatrix(e){this._navigator.stateService.state$.pipe(St()).subscribe((t=>{if(t===Df.Custom)this._container.renderService.projectionMatrix$.next(e);else{const e="Incorrect camera control mode for projection matrix update";console.warn(e)}}))}_updateViewMatrix(e){this._navigator.stateService.state$.pipe(St()).subscribe((t=>{if(t===Df.Custom)this._navigator.stateService.setViewMatrix(e);else{const e="Incorrect camera control mode for view matrix update";console.warn(e)}}))}}Uu.register(ad),Vu.register(ad),od.registerCover(af),od.register(of),od.register(cf),od.register(lf),od.register(mf),od.register(Of),od.register(Hf),od.register(Gf),od.register(ag),od.register(hg),od.register(lg),od.register(mg),od.register(zg),od.register(Uv),od.register(Vv),od.register(Hv),od.register(jv),e.ArgumentMapillaryError=Lu,e.BearingComponent=cf,e.CacheComponent=lf,e.CancelMapillaryError=uf,e.CircleMarker=class extends Sw{constructor(e,t,i){super(e,t),i=i||{},this._color=null!=i.color?i.color:16777215,this._opacity=null!=i.opacity?i.opacity:.4,this._radius=null!=i.radius?i.radius:1}_createGeometry(e){const t=new es(new nc(this._radius,16),new wr({color:this._color,opacity:this._opacity,transparent:!0}));t.up.fromArray([0,0,1]),t.renderOrder=-1;const i=new tr;i.add(t),i.position.fromArray(e),this._geometry=i}_disposeGeometry(){for(let e of this._geometry.children)e.geometry.dispose(),e.material.dispose()}_getInteractiveObjects(){return[]}},e.Component=sf,e.DataProviderBase=gw,e.DirectionComponent=mf,e.DragPanHandler=ig,e.EventEmitter=nf,e.ExtremePointTag=Tv,e.Geometry=Fg,e.GeometryProviderBase=_w,e.GeometryTagError=Bg,e.GraphDataProvider=Mw,e.GraphMapillaryError=Bu,e.Image=Su,e.KeyPlayHandler=Vf,e.KeySequenceNavigationHandler=Ff,e.KeySpatialNavigationHandler=Bf,e.KeyZoomHandler=Uf,e.KeyboardComponent=Hf,e.MapillaryError=Pu,e.Marker=Sw,e.MarkerComponent=Gf,e.OutlineTag=Ev,e.PointGeometry=Pv,e.PointerComponent=ag,e.PointsGeometry=Ug,e.PolygonGeometry=dv,e.Popup=class{constructor(e,t,i){this._options={},e=e||{},this._options.capturePointer=!1!==e.capturePointer||e.capturePointer,this._options.clean=e.clean,this._options.float=e.float,this._options.offset=e.offset,this._options.opacity=e.opacity,this._options.position=e.position,this._dom=i||new og,this._viewportCoords=t||new hf,this._notifyChanged$=new j}get changed$(){return this._notifyChanged$}remove(){this._content&&this._content.parentNode&&this._content.parentNode.removeChild(this._content),this._container&&(this._container.parentNode.removeChild(this._container),delete this._container),this._parentContainer&&delete this._parentContainer}setBasicPoint(e){this._point=e.slice(),this._rect=null,this._notifyChanged$.next(this)}setBasicRect(e){this._rect=e.slice(),this._point=null,this._notifyChanged$.next(this)}setDOMContent(e){this._content&&this._content.parentNode&&this._content.parentNode.removeChild(this._content);const t="mapillary-popup-content"+(!0===this._options.clean?"-clean":"")+(!0===this._options.capturePointer?" mapillary-popup-capture-pointer":"");this._content=this._dom.createElement("div",t,this._container),this._content.appendChild(e),this._notifyChanged$.next(this)}setHTML(e){const t=this._dom.document.createDocumentFragment(),i=this._dom.createElement("body");let n;for(i.innerHTML=e;n=i.firstChild,n;)t.appendChild(n);this.setDOMContent(t)}setText(e){this.setDOMContent(this._dom.document.createTextNode(e))}setParentContainer(e){this._parentContainer=e}update(t,i,n){if(!this._parentContainer||!this._content)return;if(!this._point&&!this._rect)return;if(!this._container){this._container=this._dom.createElement("div","mapillary-popup",this._parentContainer);if(!0!==this._options.clean&&this._options.float!==e.Alignment.Center){const e="mapillary-popup-tip"+(!0===this._options.capturePointer?" mapillary-popup-capture-pointer":"");this._tip=this._dom.createElement("div",e,this._container),this._dom.createElement("div","mapillary-popup-tip-inner",this._tip)}this._container.appendChild(this._content),this._parentContainer.appendChild(this._container),null!=this._options.opacity&&(this._container.style.opacity=this._options.opacity.toString())}let r=null,s=this._alignmentToPopupAligment(this._options.position),a=this._alignmentToPopupAligment(this._options.float);const o=this._container.classList;if(null!=this._point)r=this._viewportCoords.basicToCanvasSafe(this._point[0],this._point[1],{offsetHeight:i.height,offsetWidth:i.width},n,t.perspective);else{const e=["center","top","bottom","left","right","top-left","top-right","bottom-left","bottom-right"];let h=null;for(const t of e)if(o.contains(`mapillary-popup-float-${t}`)){h=t;break}[r,s]=this._rectToPixel(this._rect,s,h,t,i,n),a||(a=s)}if(null==r)return void(this._container.style.display="none");if(this._container.style.display="",!a){const e=this._container.offsetWidth,t=this._container.offsetHeight,n=this._pixelToFloats(r,i,e,t);a=0===n.length?"top":n.join("-")}const h=this._normalizeOffset(this._options.offset);r=[r[0]+h[a][0],r[1]+h[a][1]],r=[Math.round(r[0]),Math.round(r[1])];const c={bottom:"translate(-50%,0)","bottom-left":"translate(-100%,0)","bottom-right":"translate(0,0)",center:"translate(-50%,-50%)",left:"translate(-100%,-50%)",right:"translate(0,-50%)",top:"translate(-50%,-100%)","top-left":"translate(-100%,-100%)","top-right":"translate(0,-100%)"};for(const e in c)c.hasOwnProperty(e)&&o.remove(`mapillary-popup-float-${e}`);o.add(`mapillary-popup-float-${a}`),this._container.style.transform=`${c[a]} translate(${r[0]}px,${r[1]}px)`}_rectToPixel(e,t,i,n,r,s){if(!t){const t=this._container.offsetWidth,a=this._container.offsetHeight,o={bottom:[0,a/2],"bottom-left":[-t/2,a/2],"bottom-right":[t/2,a/2],left:[-t/2,0],right:[t/2,0],top:[0,-a/2],"top-left":[-t/2,-a/2],"top-right":[t/2,-a/2]},h=["top","bottom","left","right"];let c=[0,null,null];for(const l of h){const h=this._pointFromRectPosition(e,l),u=this._viewportCoords.basicToCanvasSafe(h[0],h[1],{offsetHeight:r.height,offsetWidth:r.width},s,n.perspective);if(null==u)continue;const d=o[l],p=[u[0]+d[0],u[1]+d[1]],m=null!=i&&i===l?1:.7;if(0===this._pixelToFloats(p,r,t/m,a/(2*m)).length&&u[0]>0&&u[0]<r.width&&u[1]>0&&u[1]<r.height)return[u,l];const f=Math.max(p[0]-t/2,0),g=Math.min(p[0]+t/2,r.width),_=Math.max(p[1]-a/2,0),v=Math.min(p[1]+a/2,r.height),y=m*Math.max(0,g-f)*Math.max(0,v-_);y>c[0]&&(c[0]=y,c[1]=u,c[2]=l)}if(c[0]>0)return[c[1],c[2]]}const a=this._pointFromRectPosition(e,t);return[this._viewportCoords.basicToCanvasSafe(a[0],a[1],{offsetHeight:r.height,offsetWidth:r.width},s,n.perspective),null!=t?t:"top"]}_alignmentToPopupAligment(t){switch(t){case e.Alignment.Bottom:return"bottom";case e.Alignment.BottomLeft:return"bottom-left";case e.Alignment.BottomRight:return"bottom-right";case e.Alignment.Center:return"center";case e.Alignment.Left:return"left";case e.Alignment.Right:return"right";case e.Alignment.Top:return"top";case e.Alignment.TopLeft:return"top-left";case e.Alignment.TopRight:return"top-right";default:return null}}_normalizeOffset(e){if(null==e)return this._normalizeOffset(0);if("number"==typeof e){const t=e,i=(t>=0?1:-1)*Math.round(Math.sqrt(.5*Math.pow(t,2)));return{bottom:[0,t],"bottom-left":[-i,i],"bottom-right":[i,i],center:[0,0],left:[-t,0],right:[t,0],top:[0,-t],"top-left":[-i,-i],"top-right":[i,-i]}}return{bottom:e.bottom||[0,0],"bottom-left":e.bottomLeft||[0,0],"bottom-right":e.bottomRight||[0,0],center:e.center||[0,0],left:e.left||[0,0],right:e.right||[0,0],top:e.top||[0,0],"top-left":e.topLeft||[0,0],"top-right":e.topRight||[0,0]}}_pixelToFloats(e,t,i,n){const r=[];return e[1]<n?r.push("bottom"):e[1]>t.height-n&&r.push("top"),e[0]<i/2?r.push("right"):e[0]>t.width-i/2&&r.push("left"),r}_pointFromRectPosition(e,t){const i=e[0],n=e[0]<e[2]?e[2]:e[2]+1,r=e[1],s=e[3];switch(t){case"bottom":return[(i+n)/2,s];case"bottom-left":return[i,s];case"bottom-right":return[n,s];case"center":return[(i+n)/2,(r+s)/2];case"left":return[i,(r+s)/2];case"right":return[n,(r+s)/2];case"top":return[(i+n)/2,r];case"top-left":return[i,r];case"top-right":return[n,r];default:return[(i+n)/2,s]}}},e.PopupComponent=hg,e.RectGeometry=lv,e.S2GeometryProvider=bw,e.ScrollZoomHandler=rg,e.SequenceComponent=lg,e.SimpleMarker=class extends Sw{constructor(e,t,i){super(e,t),i=i||{},this._ballColor=null!=i.ballColor?i.ballColor:16711680,this._ballOpacity=null!=i.ballOpacity?i.ballOpacity:.8,this._circleToRayAngle=2,this._color=null!=i.color?i.color:16711680,this._interactive=!!i.interactive,this._opacity=null!=i.opacity?i.opacity:.4,this._radius=null!=i.radius?i.radius:1}_createGeometry(e){const t=this._radius,i=this._markerHeight(t),n=new wr({color:this._color,opacity:this._opacity,transparent:!0,depthWrite:!1}),r=new es(this._createMarkerGeometry(t,8,8),n),s=new es(new nl(t/2,8,8),new wr({color:this._ballColor,opacity:this._ballOpacity,transparent:!0}));s.position.z=i,s.renderOrder=1;const a=new tr;a.add(s),a.add(r),a.position.fromArray(e),this._geometry=a}_disposeGeometry(){for(const e of this._geometry.children)e.geometry.dispose(),e.material.dispose()}_getInteractiveObjects(){return this._interactive?[this._geometry.children[0]]:[]}_markerHeight(e){const t=Math.tan(Math.PI-this._circleToRayAngle);return e*Math.sqrt(1+t*t)}_createMarkerGeometry(e,t,i){const n=this._markerHeight(e),r=this._circleToRayAngle,s=[],a=new Float32Array(3*(t+1)*(i+1));let o=0;for(let h=0;h<=i;++h){const c=[];for(let s=0;s<=t;++s){const l=s/t*Math.PI*2,u=h/i*Math.PI;let d=e;if(u>r){const t=Math.tan(u-r);d=e*Math.sqrt(1+t*t)}const p=3*o,m=Math.sin(u);a[p+0]=d*Math.cos(l)*m,a[p+1]=d*Math.sin(l)*m,a[p+2]=d*Math.cos(u)+n,c.push(o++)}s.push(c)}const h=new Uint16Array(6*t*i);let c=0;for(let e=0;e<i;++e)for(let i=0;i<t;++i){const t=s[e][i+1],n=s[e][i],r=s[e+1][i],a=s[e+1][i+1];h[c++]=t,h[c++]=n,h[c++]=a,h[c++]=n,h[c++]=r,h[c++]=a}const l=new kr,u=new Tr(a,3);return l.setAttribute("position",u),l.setIndex(new Tr(h,1)),l}},e.SliderComponent=mg,e.SpatialComponent=zg,e.SpotTag=Iv,e.Tag=Sv,e.TagComponent=Uv,e.TouchZoomHandler=sg,e.VertexGeometry=cv,e.Viewer=class extends nf{constructor(e){super(),this._navigator=new lM(e),this._container=new jw(e,this._navigator.stateService),this._observer=new dM(this,this._navigator,this._container),this._componentController=new Pw(this._container,this._navigator,this._observer,e.imageId,e.component),this._customRenderer=new pM(this._container,this._navigator),this._customCameraControls=new mM(this._container,this._navigator)}get dataProvider(){return this._navigator.api.data}get isNavigable(){return this._componentController.navigable}activateCombinedPanning(){this._navigator.panService.enable()}activateComponent(e){this._componentController.activate(e)}activateCover(){this._componentController.activateCover()}addCustomRenderer(e){this._customRenderer.add(e,this)}attachCustomCameraControls(e){this._customCameraControls.attach(e,this)}deactivateCombinedPanning(){this._navigator.panService.disable()}deactivateComponent(e){this._componentController.deactivate(e)}deactivateCover(){this._componentController.deactivateCover()}detachCustomCameraControls(){return this._customCameraControls.detach(this)}fire(e,t){super.fire(e,t)}getBearing(){return new Promise(((e,t)=>{this._container.renderService.bearing$.pipe(St()).subscribe((t=>{e(t)}),(e=>{t(e)}))}))}getCameraControls(){return new Promise(((t,i)=>{this._navigator.stateService.state$.pipe(St()).subscribe((i=>{switch(i){case Df.Custom:t(e.CameraControls.Custom);break;case Df.Earth:t(e.CameraControls.Earth);break;default:t(e.CameraControls.Street)}}),(e=>{i(e)}))}))}getCanvas(){return this._container.canvas}getCanvasContainer(){return this._container.canvasContainer}getCenter(){return new Promise(((e,t)=>{this._navigator.stateService.getCenter().subscribe((t=>{e(t)}),(e=>{t(e)}))}))}getComponent(e){return this._componentController.get(e)}getContainer(){return this._container.container}getFieldOfView(){return new Promise(((e,t)=>{this._container.renderService.renderCamera$.pipe(St()).subscribe((t=>{e(t.perspective.fov)}),(e=>{t(e)}))}))}getImage(){return new Promise(((e,t)=>{this._navigator.stateService.currentImage$.pipe(St()).subscribe((t=>{e(t)}),(e=>{t(e)}))}))}getPointOfView(){return new Promise(((e,t)=>{Ve(this._container.renderService.renderCamera$,this._container.renderService.bearing$).pipe(St()).subscribe((([t,i])=>{e({bearing:i,tilt:t.getTilt()})}),(e=>{t(e)}))}))}getPosition(){return new Promise(((e,t)=>{Ve(this._container.renderService.renderCamera$,this._navigator.stateService.reference$).pipe(St()).subscribe((([t,i])=>{e(this._observer.projection.cameraToLngLat(t,i))}),(e=>{t(e)}))}))}getReference(){return new Promise(((e,t)=>{this._navigator.stateService.reference$.pipe(St()).subscribe((t=>{e(t)}),(e=>{t(e)}))}))}getZoom(){return new Promise(((e,t)=>{this._navigator.stateService.getZoom().subscribe((t=>{e(t)}),(e=>{t(e)}))}))}hasCustomCameraControls(e){return this._customCameraControls.has(e)}hasCustomRenderer(e){return this._customRenderer.has(e)}moveDir(e){const t=this.isNavigable?this._navigator.moveDir$(e):Ee(new Error("Calling moveDir is not supported when viewer is not navigable."));return new Promise(((e,i)=>{t.subscribe((t=>{e(t)}),(e=>{i(e)}))}))}moveTo(e){const t=this.isNavigable?this._navigator.moveTo$(e):Ee(new Error("Calling moveTo is not supported when viewer is not navigable."));return new Promise(((e,i)=>{t.subscribe((t=>{e(t)}),(e=>{i(e)}))}))}off(e,t){super.off(e,t)}on(e,t){super.on(e,t)}project(e){return new Promise(((t,i)=>{this._observer.project$(e).subscribe((e=>{t(e)}),(e=>{i(e)}))}))}projectFromBasic(e){return new Promise(((t,i)=>{this._observer.projectBasic$(e).subscribe((e=>{t(e)}),(e=>{i(e)}))}))}remove(){this._customRenderer.dispose(this),this._customCameraControls.dispose(this),this._observer.dispose(),this._componentController.remove(),this._navigator.dispose(),this._container.remove();const e="remove",t={target:this,type:e};this.fire(e,t)}removeCustomRenderer(e){this._customRenderer.remove(e,this)}resize(){this._container.renderService.resize$.next()}setCameraControls(e){const t=cM(e);t===Df.Traversing?this._navigator.stateService.traverse():t===Df.Earth?this._navigator.stateService.earth():t===Df.Custom?this._navigator.stateService.custom():console.warn(`Unsupported camera control transition (${e})`)}setCenter(e){this._navigator.stateService.setCenter(e)}setFieldOfView(e){this._container.renderService.renderCamera$.pipe(St()).subscribe((t=>{const i=t.fovToZoom(e);this._navigator.stateService.setZoom(i)}))}setFilter(e){return new Promise(((t,i)=>{this._navigator.setFilter$(e).subscribe((()=>{t(void 0)}),(e=>{i(e)}))}))}setRenderMode(e){this._container.renderService.renderMode$.next(e)}setTransitionMode(e){this._navigator.stateService.setTransitionMode(e)}setAccessToken(e){const t=this.isNavigable?this._navigator.setAccessToken$(e):Ee(new Error("Calling setAccessToken is not supported when viewer is not navigable."));return new Promise(((e,i)=>{t.subscribe((()=>{e(void 0)}),(e=>{i(e)}))}))}setZoom(e){this._navigator.stateService.setZoom(e)}triggerRerender(){this._container.glRenderer.triggerRerender()}unproject(e){return new Promise(((t,i)=>{this._observer.unproject$(e).subscribe((e=>{t(e)}),(e=>{i(e)}))}))}unprojectToBasic(e){return new Promise(((t,i)=>{this._observer.unprojectBasic$(e).subscribe((e=>{t(e)}),(e=>{i(e)}))}))}},e.ZoomComponent=Vv,e.decompress=uw,e.ecefToEnu=yu,e.ecefToGeodetic=wu,e.enuToEcef=bu,e.enuToGeodetic=vu,e.fetchArrayBuffer=dw,e.geodeticToEcef=xu,e.geodeticToEnu=_u,e.isFallbackSupported=Ew,e.isSupported=function(){return Ew()&&Cw()},e.readMeshPbf=mw,Object.defineProperty(e,"__esModule",{value:!0})}));
//# sourceMappingURL=mapillary.js.map