You can listen for user events such as clicks, mouse movement, and touch gestures.
Copy
// Listen for a click event on the mapmap.on('click', (event) => { console.log('Map clicked at:', event.lngLat);});// Listen for mouse move eventsmap.on('mousemove', (event) => { // Show coordinates or highlight features});
Interact with specific features on the map, such as highlighting or displaying popups.
Copy
// Show a popup when a feature is clickedmap.on('click', 'layer-id', (event) => { const coordinates = event.features[0].geometry.coordinates; new map.Popup() .setLngLat(coordinates) .setHTML('<strong>Feature Info</strong>') .addTo(map);});