Map interactions and viewport
The Felt SDK provides methods to control the map's viewport (the visible area of the map) and handle user interactions like clicking and hovering on the viewport.
Working with the viewport
Getting viewport state
You can get the current viewport state using getViewport()
:
Setting the viewport
There are two main ways to set the viewport: moving to a specific point, or fitting to bounds.
Moving to a point
Use setViewport()
to move the map to a specific location:
Fitting to bounds
Use fitViewportToBounds()
to adjust the viewport to show a specific rectangular area:
Responding to viewport changes
To stay in sync with viewport changes, use the onViewportMove
method:
Map interactions
Click events
Listen for click events on the map using onPointerClick
:
Hover events
Track mouse movement over the map using onPointerMove
:
Best practices
Cleanup: Always store and call unsubscribe functions when you're done listening for events:
Throttling: For pointer move events, consider throttling your handler if you're doing expensive operations:
By using these viewport controls and interaction handlers, you can create rich, interactive experiences with your Felt map.
Last updated