UNPKG

urbi-exhibitions

Version:
2 lines (1 loc) 7.52 kB
"use strict";var O=Object.defineProperty;var p=(o,t,i)=>t in o?O(o,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):o[t]=i;var l=(o,t,i)=>p(o,typeof t!="symbol"?t+"":t,i);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const h=require("../index-Dido_DCu.cjs"),f=require("../routeCaching-3pTPTO24.cjs");function z(o){const t=o.models[0];return{modelId:t.name,isDark:!!o.isDark,coordinates:o.coords,linkedIds:o.buildingIds,scale:o.scale,rotateX:o.rotateX*180,rotateY:o.rotateY*180,rotateZ:o.rotateZ*180,offsetX:o.moveX/100,offsetY:o.moveY/100,offsetZ:o.moveZ/100,modelUrl:t.path}}function R(o){return{rotateX:o.rotateX*180,rotateY:o.rotateY*180,rotateZ:o.rotateZ*180,offsetX:o.moveX/100,offsetY:o.moveY/100,offsetZ:o.moveZ/100}}function m(o){if(!o)throw new Error("coord is required");if(!Array.isArray(o)){if(o.type==="Feature"&&o.geometry!==null&&o.geometry.type==="Point")return[...o.geometry.coordinates];if(o.type==="Point")return[...o.coordinates]}if(Array.isArray(o)&&o.length>=2&&!Array.isArray(o[0])&&!Array.isArray(o[1]))return[...o];throw new Error("coord must be GeoJSON Point or an Array of numbers")}function M(o,t,i={}){if(i.final===!0)return T(o,t);const e=m(o),n=m(t),s=h.degreesToRadians(e[0]),a=h.degreesToRadians(n[0]),u=h.degreesToRadians(e[1]),r=h.degreesToRadians(n[1]),g=Math.sin(a-s)*Math.cos(r),c=Math.cos(u)*Math.sin(r)-Math.sin(u)*Math.cos(r)*Math.cos(a-s);return h.radiansToDegrees(Math.atan2(g,c))}function T(o,t){let i=M(t,o);return i=(i+180)%360,i}var b=M;function I(o,t,i={}){var e=m(o),n=m(t),s=h.degreesToRadians(n[1]-e[1]),a=h.degreesToRadians(n[0]-e[0]),u=h.degreesToRadians(e[1]),r=h.degreesToRadians(n[1]),g=Math.pow(Math.sin(s/2),2)+Math.pow(Math.sin(a/2),2)*Math.cos(u)*Math.cos(r);return h.radiansToLength(2*Math.atan2(Math.sqrt(g),Math.sqrt(1-g)),i.units)}var y=I;function E(o,t,i,e={}){const n=m(o),s=h.degreesToRadians(n[0]),a=h.degreesToRadians(n[1]),u=h.degreesToRadians(i),r=h.lengthToRadians(t,e.units),g=Math.asin(Math.sin(a)*Math.cos(r)+Math.cos(a)*Math.sin(r)*Math.cos(u)),c=s+Math.atan2(Math.sin(u)*Math.sin(r)*Math.cos(a),Math.cos(r)-Math.sin(a)*Math.sin(g)),d=h.radiansToDegrees(c),Z=h.radiansToDegrees(g);return h.point([d,Z],e.properties)}function D(o,t){const i=I(o,t),e=M(o,t);return E(o,i/2,e)}var P=D;const A={zoomInOutTime:1e3,defaultRotationDuration:4e3,defaultZoom:18.5,defaultPitch:55,step:150},F=600,w=5e3,C=120,S=60*60*1e3;class _{constructor({zoom:t,maxZoom:i,minZoom:e,center:n,pitch:s,rotation:a,baseDuration:u,maxZoomDuration:r,buildingFlightOption:g}){l(this,"zoom");l(this,"maxZoom");l(this,"minZoom");l(this,"center");l(this,"pitch");l(this,"rotation");l(this,"baseDuration");l(this,"maxZoomDuration");l(this,"zoomAmplitude");l(this,"buildingFlightOption");l(this,"flightId");l(this,"activeFlightMap");this.zoom=t,this.maxZoom=i,this.minZoom=e,this.center=n,this.pitch=s,this.rotation=a,this.baseDuration=u||F,this.maxZoomDuration=r||w,this.zoomAmplitude=i-e,this.buildingFlightOption={...A,...g||{}},this.flightId=0,this.activeFlightMap={}}getInitialMapOptions(){return{zoom:this.zoom,maxZoom:this.maxZoom,minZoom:this.minZoom,center:this.center,pitch:this.pitch,rotation:this.rotation}}getFlightId(){return++this.flightId}waitIdle(t){return new Promise(i=>{t&&t.once("idle",i)})}sleep(t){return new Promise(i=>{setTimeout(i,t)})}abortFlights(){for(const t in this.activeFlightMap)this.activeFlightMap[t]=!1}async runFlight(t,i,e=!1){this.abortFlights();const n=this.getFlightId();this.activeFlightMap[n]=!0;for(let s=0;s<i.length;s++){if(!this.activeFlightMap[n])return;const a=i[s];e&&console.log(a,s);const u=a.duration||0;if(a.center){const r={duration:u};a.centerEasing&&(r.easing=a.centerEasing),t.setCenter(a.center,r)}if(a.styleZoom!==void 0){const r={duration:u,useHeightForAnimation:!0};a.styleZoomEasing&&(r.easing=a.styleZoomEasing),t.setStyleZoom(a.styleZoom,r)}else if(a.zoom!==void 0){const r={duration:u,useHeightForAnimation:!0};a.zoomEasing&&(r.easing=a.zoomEasing),t.setZoom(a.zoom,r)}if(a.pitch!==void 0){const r={duration:u};a.pitchEasing&&(r.easing=a.pitchEasing),t.setPitch((a.incremental?t.getPitch():0)+a.pitch,r)}if(a.rotation!==void 0){const r={duration:a.rotationDuration??u};a.rotationEasing&&(r.easing=a.rotationEasing),t.setRotation((a.incremental?t.getRotation():0)+a.rotation,{...r,normalize:a.rotationNormalize??!0})}typeof a.f=="function"&&a.f(),a.waitIdle?await this.waitIdle(t):await this.sleep(u)}}async fitBounds(t,i,e){var n,s;this.abortFlights(),t.fitBounds(i,e),typeof(e==null?void 0:e.f)=="function"&&e.f(),e!=null&&e.waitIdle?await this.waitIdle(t):(n=e==null?void 0:e.animation)!=null&&n.duration&&await this.sleep((s=e==null?void 0:e.animation)==null?void 0:s.duration)}getBuildingBaseFlight({center:t,styleZoom:i,pitch:e,...n}){const s=n.rotationDuration??this.buildingFlightOption.defaultRotationDuration;return[{duration:this.buildingFlightOption.zoomInOutTime,center:t,styleZoom:i??this.buildingFlightOption.defaultZoom,pitch:e??this.buildingFlightOption.defaultPitch},{duration:s/2,rotationEasing:"easeInSine",rotation:-this.buildingFlightOption.step,incremental:!0},{duration:s/2,rotationEasing:"easeOutSine",rotation:-this.buildingFlightOption.step,incremental:!0}]}runBuildingFlight(t,i,e){const n=[...this.getBuildingBaseFlight(i),{duration:this.buildingFlightOption.zoomInOutTime,styleZoom:t.getStyleZoom(),pitch:t.getPitch(),rotation:t.getRotation()},{f:e}];return this.runFlight(t,n)}flyToOpts(t,i={},e){const n=[{duration:2e3,centerEasing:i.easing??"easeInOutQuad",zoomEasing:i.easing??"easeInOutQuad",styleZoomEasing:i.easing??"easeInOutQuad",rotationNormalize:!0,...i}];return e&&n.push({f:e}),this.runFlight(t,n)}getZoomParams({from:t=this.zoom,to:i=this.zoom}){const e=t-i;return{duration:this.maxZoomDuration*Math.abs(e)/this.zoomAmplitude,dir:e>0?"out":"in",easing:e>0?"easeInQuart":"easeOutQuart"}}getZoomPart({from:t=this.zoom,to:i=this.zoom}){const{duration:e,easing:n}=this.getZoomParams({from:t,to:i});return{duration:e,zoom:i,zoomEasing:n}}getMoveCenterOnMaxZoomPart(t){return t?{duration:2*F,center:t,centerEasing:"easeInOutQuad"}:{}}getMoveCenter(t,{to:i,...e}){if(!i)return{};const n=e.from??t.getCenter();return{duration:y(t.project(n),t.project(i))/5,center:i,centerEasing:"easeInOutQuad"}}getZoomToOpts({from:t=this.zoom,opts:i}){if(!i||!i.zoom)return{};const{duration:e,easing:n}=this.getZoomParams({from:t,to:i.zoom});return{duration:e<this.baseDuration?this.baseDuration:e,zoom:i.zoom,pitch:i.pitch,center:i.center,rotation:i.rotation,centerEasing:n}}resetMapRestrictions(t){t.setMaxZoom(this.maxZoom),t.setMinZoom(this.minZoom)}getLineFlight(t,{speed:i=C,distanceLimit:e=1/0,restrictRotationDuration:n=!1,logResult:s=!1,cb:a}){const u=[];let r=0,g=0;for(let c=0;c<t.length-1;c++){const d=y(t[c],t[c+1]);if(d===0)continue;g+=d,r=b(h.point(t[c]),h.point(t[c+1]));const v=d/i*S;if(u.push({rotation:-r,rotationDuration:n&&v>500?500:void 0,rotationNormalize:!0,traveledDistance:g,duration:v,center:t[c+1],centerEasing:"linear",waitIdle:c===0}),a&&u.push({traveledDistance:g,f:function(){a(this.traveledDistance)}}),g>e)break}return s&&console.log(u),{flight:u,speed:i,distance:g}}getMidpoint(t,i){const e=h.point(t),n=h.point(i);return P(e,n).geometry.coordinates}}exports.clearRoutesCache=f.clearRoutesCache;exports.getRouteCache=f.getRouteCache;exports.getRouteStringKey=f.getRouteStringKey;exports.prefetchRoutes=f.prefetchRoutes;exports.routesCache=f.routesCache;exports.MapFlight=_;exports.convertModelParams=R;exports.convertModelToCS=z;