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