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():
constviewport=awaitfelt.getViewport();console.log(viewport.center);// { latitude: number, longitude: number }console.log(viewport.zoom);// number
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:
const unsubscribe = felt.onPointerClick({
handler: (event) => {
// Location of the click
console.log("Click location:", event.center);
// Features under the click
console.log("Clicked features:", event.features);
// The pixel coordinates of the cursor, measured from the top left corner of the map DOM element.
console.log("Screen coordinates:", event.point);
// Raster values, if applicable
const {value, categoryName, color} = event.rasterValues;
}
});
const unsubscribe = felt.onPointerMove({
handler: (event) => {
// Current mouse location
console.log("Mouse location:", event.center);
// Features under the cursor
console.log("Hovered features:", event.features);
// The pixel coordinates of the cursor, measured from the top left corner of the map DOM element.
console.log("Screen coordinates:", event.point);
// Raster values, if applicable
const {value, categoryName, color} = event.rasterValues;
}
});