The parameters for the `setViewport` method.
optionalcenter: {latitude:number;longitude:number; }
latitude
number
Latitude
longitude
number
Longitude
optionalzoom:number
The Viewport module allows you to control the viewport of the map, such as setting the current viewport, getting the current viewport, and being notified when the viewport changes.
The input type for setting the viewport to a particular center and zoom.
center:
LatLng
The center of the viewport in latitude and longitude.
zoom:
number
The zoom level of the viewport.
The constraints for the viewport. Used to ensure that the viewport stays within certain bounds and zoom levels.
minZoom:
null|number
The minimum zoom level for the viewport.
maxZoom:
null|number
The maximum zoom level for the viewport.
bounds:
null| [number,number,number,number]
The bounds for the viewport.
The parameters for the `fitViewportToBounds` method.
bounds: [
number,number,number,number]
The bounds to fit the viewport to.
The viewport controller allows you to control the viewport of the map.
You can get the current viewport, move the viewport, and be notified when the viewport changes.
getViewport():
Promise<ViewportState>
Gets the current state of the viewport.
Use this method to retrieve the current center coordinates and zoom level of the map viewport.
Promise<ViewportState>
A promise that resolves to the current viewport state.
// Get current viewport state
const viewport = await felt.getViewport();
console.log({
center: viewport.center,
zoom: viewport.zoom,
});setViewport(
viewport:SetViewportCenterZoomParams):void
Moves the map to the specified location.
Use this method to programmatically change the map's viewport to a specific location and zoom level. The map will animate to the new position.
viewport
void
felt.setViewport({
center: { latitude: 0, longitude: 0 },
zoom: 10,
});getViewportConstraints():
Promise<null|ViewportConstraints>
Gets the current state of the viewport constraints.
Use this method to retrieve the current viewport constraints, which limit where users can pan and zoom on the map.
Promise<null | ViewportConstraints>
A promise that resolves to the current viewport constraints, or null if no constraints are set.
// Get current viewport constraints
const constraints = await felt.getViewportConstraints();
if (constraints) {
console.log({
bounds: constraints.bounds,
minZoom: constraints.minZoom,
maxZoom: constraints.maxZoom
});
} else {
console.log("No viewport constraints set");
}setViewportConstraints(
constraints:null|Partial<ViewportConstraints>):void
Constrains the map viewport so it stays inside certain bounds and/or certain zoom levels.
Use this method to limit where users can navigate on the map. This is useful for keeping users focused on a specific area or preventing them from zooming too far in or out.
constraints
null | Partial<>
void
felt.setViewportConstraints({
bounds: [-122.5372532, 37.6652478, -122.1927016, 37.881707],
minZoom: 1,
maxZoom: 23,
});every constraint is optional
felt.setViewportConstraints({
bounds: [-122.5372532, 37.6652478, -122.1927016, 37.881707],
});if a constraint is null, it will be removed but keeping the others
felt.setViewportConstraints({ bounds: null });if method receives null, it will remove the constraints
felt.setViewportConstraints(null);fitViewportToBounds(
bounds:ViewportFitBoundsParams):void
Fits the map to the specified bounds.
Use this method to automatically adjust the viewport to show a specific geographic area. The map will calculate the appropriate center and zoom level to fit the bounds within the current map size.
bounds
void
const west = -122.4194;
const south = 37.7749;
const east = -122.4194;
const north = 37.7749;
felt.fitViewportToBounds({ bounds: [west, south, east, north] });onViewportMove(
args: {handler: (viewport:ViewportState) =>void; }):VoidFunction
Adds a listener for when the viewport changes.
Use this to react to viewport changes, such as updating your UI or triggering other actions when users navigate the map.
args
{ handler: (viewport: ) => void; }
-
args.handler
(viewport: ) => void
This callback is called with the current viewport state whenever the viewport changes.
VoidFunction
A function to unsubscribe from the listener.
const unsubscribe = felt.onViewportMove({
handler: viewport => console.log(viewport.center.latitude),
});
// later on...
unsubscribe();onViewportMoveEnd(
args: {handler: (viewport:ViewportState) =>void; }):VoidFunction
Adds a listener for when the viewport move ends, which is when the user stops dragging or zooming the map, animations have finished, or inertial dragging ends.
Use this to react to the end of viewport changes, such as triggering data loading or analysis when users finish navigating.
args
{ handler: (viewport: ) => void; }
args.handler
(viewport: ) => void
VoidFunction
A function to unsubscribe from the listener.
const unsubscribe = felt.onViewportMoveEnd({
handler: viewport => console.log(viewport.center.latitude),
});
// later on...
unsubscribe();onMapIdle(
args: {handler: () =>void; }):VoidFunction
Adds a listener for when the map is idle, which is defined as:
No transitions are in progress
The user is not interacting with the map, e.g. by panning or zooming
All tiles for the current viewport have been loaded
Any fade transitions (e.g. for labels) have completed
Use this to perform actions when the map is completely stable and ready for user interaction, such as enabling certain features or triggering data analysis.
args
{ handler: () => void; }
args.handler
() => void
VoidFunction
A function to unsubscribe from the listener.
const unsubscribe = felt.onMapIdle({ handler: () => console.log("map is idle") });
// later on...
unsubscribe();The current state of the viewport, including the derived bounds.
center:
LatLng
The center of the viewport in latitude and longitude.
zoom:
number
The zoom level of the viewport.
bounds: [
number,number,number,number]
The bounding box of the viewport in [west, south, east, north] order.
This is derived, and depends on the center and zoom of the viewport, as well as its size.