If you open Google Maps in Chrome/Firefox on a laptop with a trackpad, if you pinch-zoom, it just zooms the map, and the floating UI elements remain static. So I know what I am trying to do is possible.
It seems the browser doesn't emit touch* events for trackpad touches on desktop browsers, but it does emit a series of wheel events (with event.ctrlKey set to true) for a trackpad pinch-zoom gesture.
The problem is, even with event.preventDefault(), the browser still always zooms the whole page. It seems that calling preventDefault() on a wheel event just prints this warning in the console (Chrome 92):
[Intervention] Unable to preventDefault inside passive event listener due to target being treated as passive. See https://www.chromestatus.com/features/6662647093133312`
(The URL in the warning doesn't seem to be any use.)
I tried using same the meta viewport tag as Google Maps (<meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no">) but it doesn't help.
So how does Google Maps do it? How do they prevent the default behaviour (zooming the whole page) when you pinch-zoom on the trackpad?