Is Indoor: {dynamicFocus.isIndoor ? 'Yes' : 'No'}
Is Outdoor: {dynamicFocus.isOutdoor ? 'Yes' : 'No'}
);
}
```
Dynamic Focus has a number of options that can be enabled either at instantiation or at any time via `updateState()`.
```ts
dynamicFocus.updateState({
autoFocus: true, // whether to automatically focus on camera move
indoorZoomThreshold: 18, // the zoom level at which the indoors is revealed
outdoorZoomThreshold: 17, // the zoom level at which the indoors are hidden
setFloorOnFocus: true, // whether to automatically call setFloor during focus
indoorAnimationOptions: {
// options for the animation to fade out the facades
duration: 150,
},
outdoorAnimationOptions: {
// options for the animation to fade in the facades
duration: 150,
},
});
```
### Auto Focus
Dynamic Focus' auto focus provides default behavior to transition the currently visible map from one building to the next as the camera pans over it. The default behavior can be overridden by setting the `autoFocus` option to `false`, allowing the developer to control the focus manually.
```ts
/**
* Create a new Dynamic Focus controller that automatically updates the MapView.
*/
const dynamicFocus = useDynamicFocus();
/**
* Enable Dynamic Focus.
*/
dynamicFocus.enable({
autoFocus: true,
setFloorOnFocus: true,
});
/**
* Disable automatic updates - now the app needs to manually call `focus()` to update the view.
*/
dynamicFocus.updateState({ autoFocus: false });
/**
* Manually trigger a focus update to show/hide facades and update floor visibility.
* This shows the default Floor in the FloorStack that is currently centered on the map.
*/
dynamicFocus.focus();
/**
* Clean up the controller and restore default floor visibility behavior
*/
dynamicFocus.destroy();
```
### Setting FloorStack Default Floor
The default floor is the Floor that is visible when focus is transitioned to a new FloorStack (building). The default Floor for a FloorStack can be set by calling `setDefaultFloorForStack()` with the floor stack and floor ID. The default floor can be reset by calling `resetDefaultFloorForStack()` with the floor stack.
```ts
const dynamicFocus = useDynamicFocus();
dynamicFocus.setDefaultFloorForStack(floorStack, floor);
dynamicFocus.resetDefaultFloorForStack(floorStack);
```
## Implementing Dynamic Focus using MapView
Dynamic Focus can be implemented using the MapViewControl.updateState method. This approach is more flexible and allows for full customization of Dynamic Focus behavior, but it requires more code to implement. For a simple implementation of Dynamic Focus, refer to the Mappedin Dynamic Focus Package section.
Implementing Dynamic Focus using MapViewControl.updateState requires the app to switch the visibility of a building Facade and Floor when the camera pans over a building. The Facade represents the look of the building from the outside, with its roof on. The Floor represents the look of the building from the inside, showing the indoor map.
### Listen for Changes to Facades In view
The `facades-in-view-change` event is emitted when the facades in view change. This event is emitted when the camera pans over a building. The event provides the list of facades in view. The app can use this event to update the visibility of the facades and floors. The first Facade in the array contains the one that is most centered in view.
```tsx
// Act on the facades-in-view-change event to update floor visibility.
const [facadesInView, setFacadesInView] = useState