@expofp/floorplan
Version:
Interactive floor plan library for expos and events
2 lines (1 loc) • 2.15 kB
JavaScript
import{Box as h}from"@expofp/geometry";import{svgArea as f,svgAreaExplicit as y}from"../../data/svg";import u,{uiState as s}from"../../store";import{convertLocalToGps as T}from"../../utils/gps";import{useReaction as l}from"../../utils/mobx";import{expandRectByPercent as b,getVenueFitMarginPercent as v,resolveVenueFitRect as x}from"../../utils/scene-bounds";import{fitMapToLocalRect as d,getVisibleRectFitPadding as O,isLngLatInVisibleViewport as M}from"./utils/geo-config";const a=s,S=15,g=24,L=20;function R(e){return b(e,v(e,f)).expand(L)}function B(e,r){return Math.min(Math.max(r,e.getMinZoom()),e.getMaxZoom())}function I(e,r,m){if(m.length!==1)return!1;const o=m[0]?.id,t=u.poiMarkerStore.markers.find(c=>c.boothId===o);if(!t)return!1;const n=T(t.center.x,t.center.y,r.gpsConfig),i=O(g);return M(e,n,i)||e.easeTo({center:n,zoom:B(e,S),bearing:r.bearing,duration:500,essential:!0}),!0}export function useCameraReactions(e,r,m){l(()=>a.moveToBooths,o=>{const t=e.current;if(!o||!t||!r)return;const n=o.filter(c=>c.rect);if(n.length===0)return;if(I(t,r,n)){a.moveToBooths=null;return}const i=h.fromUnion(...n.map(c=>c.rect));d(t,R(i),r),a.moveToBooths=null}),l(()=>a.moveToRect,o=>{const t=e.current;!o||!t||!r||(d(t,o,r,{paddingPercent:a.moveToRectPaddingPercent}),a.moveToRect=null,a.moveToRectPaddingPercent=null)}),l(()=>a.zoomBy,o=>{const t=e.current;!o||!t||(t.flyTo({zoom:t.getZoom()+(o>1?.5:-.5),animate:!0,duration:500}),a.zoomBy=null)}),l(()=>[s.moveToLocation,u.maplibreStore.cameraPort,u.routeStore.currentPosition],([o])=>{if(!o)return;const t=e.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 p;if(P)p=[i,c];else{if(!r)return;p=T(n.x,n.y,r.gpsConfig)}t.flyTo({center:p,animate:!0,duration:1e3})}),l(()=>s.centerMap,o=>{const t=e.current;if(!o||!t||!r)return;if(!(s.list.type==="search"&&!s.list.text)){const{rect:i}=x({layerViewbox:u.layerStore.viewboxRectangle,explicitArea:y?f:null,layerRectangle:u.layerStore.rectangle,sceneDef:m,svgArea:f});d(t,i,r)}s.centerMap=!1})}