UNPKG

@expofp/floorplan

Version:

Interactive floor plan library for expos and events

2 lines (1 loc) • 2.3 kB
import{Box as b}from"@expofp/geometry";import{getSvgArea as d,isSvgAreaExplicit as g}from"../../data/svg.js";import u,{uiState as s}from"../../store";import{convertLocalToGps as P}from"../../utils/gps";import{useReaction as m}from"../../utils/mobx";import{expandRectByPercent as y,getVenueFitMarginPercent as T,resolveVenueFitRect as S}from"../../utils/scene-bounds";import{withKiosk as x}from"../Map/with-kiosk.js";import{fitMapToLocalRect as h,getVisibleRectFitPadding as O,isLngLatInVisibleViewport as v}from"./utils/geo-config";const a=s,M=15,L=24,B=20;function I(r){return y(r,T(r,d())).expand(B)}function R(r,o){return Math.min(Math.max(o,r.getMinZoom()),r.getMaxZoom())}function _(r,o,f){if(f.length!==1)return!1;const e=f[0]?.id,t=u.poiMarkerStore.markers.find(c=>c.boothId===e);if(!t)return!1;const n=P(t.center.x,t.center.y,o.gpsConfig),i=O(L);return v(r,n,i)||r.easeTo({center:n,zoom:R(r,M),bearing:o.bearing,duration:500,essential:!0}),!0}export function useCameraReactions(r,o,f){m(()=>a.moveToBooths,e=>{const t=r.current;if(!e||!t||!o)return;const n=e.filter(c=>c.rect);if(n.length===0)return;if(_(t,o,n)){a.moveToBooths=null;return}const i=b.fromUnion(...n.map(c=>c.rect));h(t,I(i),o),a.moveToBooths=null}),m(()=>a.moveToRect,e=>{const t=r.current;if(!e||!t||!o)return;const{width:n,height:i}=e.size,c=n>0&&i>0?x(e):e,p=a.moveToRectPaddingPercent??T(e,d()),l=y(c,p/(1-2*p));h(t,l,o,{padding:0}),a.moveToRect=null,a.moveToRectPaddingPercent=null}),m(()=>a.zoomBy,e=>{const t=r.current;!e||!t||(t.flyTo({zoom:t.getZoom()+(e>1?.5:-.5),animate:!0,duration:500}),a.zoomBy=null)}),m(()=>[s.moveToLocation,u.maplibreStore.cameraPort,u.routeStore.currentPosition],([e])=>{if(!e)return;const t=r.current,n=u.routeStore.currentPosition;if(!n){s.moveToLocation=!1;return}if(!t)return;const{lng:i,lat:c}=n,p=typeof i=="number"&&Number.isFinite(i)&&typeof c=="number"&&Number.isFinite(c);s.moveToLocation=!1;let l;if(p)l=[i,c];else{if(!o)return;l=P(n.x,n.y,o.gpsConfig)}t.flyTo({center:l,animate:!0,duration:1e3})}),m(()=>s.centerMap,e=>{const t=r.current;if(!e||!t||!o)return;if(!(s.list.type==="search"&&!s.list.text)){const{rect:i}=S({layerViewbox:u.layerStore.viewboxRectangle,explicitArea:g()?d():null,layerRectangle:u.layerStore.rectangle,sceneDef:f,svgArea:d()});h(t,i,o)}s.centerMap=!1})}