Essentials · Angular, React and OpenLayers
Whole zoom levels with constrainResolution
Snap OpenLayers pinch, wheel and button zooms to crisp integer tile levels with constrainResolution on the view to eliminate raster label blur.

What this example shows
Over central Kraków at zoom 13, continuous pinch gestures on touch screens and trackpads still scale smoothly beneath your fingers during movement, but as soon as you lift your fingers—or stop rolling the mouse wheel—the camera settles onto the nearest whole zoom level.
Every settled view displays OpenStreetMap’s 256 × 256 PNG tiles at exact 1:1 native pixel resolution with crisp street labels and sharp linework.
When you need it
Maps built around pre-rendered raster basemaps—such as OpenStreetMap, topographic scans or historical cartography—suffer noticeable text halo blur whenever the camera stops on fractional zoom levels like 12.37.
Enabling resolution snapping on reading-focused street maps guarantees native raster sharpness after every gesture while preserving fluid continuous scaling while the gesture is in flight.
The code
The example uses cc-openlayers, my Angular component library for OpenLayers: each aol-… element creates the OpenLayers object it names, updates it from its inputs and disposes of it with the component.
pinch-zoom.tsimport { ChangeDetectionStrategy, Component } from '@angular/core';
import {
CoordinateComponent,
DefaultControlComponent,
DefaultInteractionComponent,
LayerTileComponent,
MapComponent,
SourceOsmComponent,
ViewComponent,
} from 'cc-openlayers';
/** Pinch zooming restricted to whole zoom levels by the view's constrainResolution. */
@Component({
selector: 'app-pinch-zoom',
imports: [
CoordinateComponent,
DefaultControlComponent,
DefaultInteractionComponent,
LayerTileComponent,
MapComponent,
SourceOsmComponent,
ViewComponent,
],
changeDetection: ChangeDetectionStrategy.OnPush,
template: `
<aol-map height="480px">
<aol-interaction-default />
<aol-control-defaults />
<aol-view [zoom]="13" [constrainResolution]="true">
<aol-coordinate [x]="19.9368" [y]="50.0614" srid="EPSG:4326" />
</aol-view>
<aol-layer-tile><aol-source-osm /></aol-layer-tile>
</aol-map>
`,
})
export class PinchZoom {} The React version uses the library's React adapter, cc-openlayers/react: each component creates the OpenLayers object it names when it mounts, updates it from its props and disposes of it when it unmounts.
pinch-zoom.react.tsximport { Coordinate, DefaultControls, DefaultInteractions, Map, OSMSource, TileLayer, View } from 'cc-openlayers/react';
/** Pinch zooming restricted to whole zoom levels by the view's constrainResolution. */
export function PinchZoom() {
return (
<Map height="480px">
<DefaultInteractions />
<DefaultControls />
<View zoom={13} constrainResolution>
<Coordinate x={19.9368} y={50.0614} srid="EPSG:4326" />
</View>
<TileLayer>
<OSMSource />
</TileLayer>
</Map>
);
}How the React version works
A pinch changes the zoom, but the view settles only on whole levels (constrainResolution).
What both versions share
OpenLayers renders the map and handles the interactions; the cc-openlayers/core layer gives both adapters the same view binding (MapViewBinding) and the same conversion of coordinates from EPSG:4326 to the map's projection.
From Angular to React
| Angular | React |
|---|---|
[constrainResolution]="true" | constrainResolution |
Who creates, updates and disposes
Map creates the ol/Map in useLayoutEffect and disposes of it on unmount; each layer, source and interaction component adds its object to the parent it gets from context and removes it in its effect's cleanup, as ngOnDestroy does in Angular.
Architecture and OpenLayers mechanics
Setting [constrainResolution]="true" on aol-view applies integer resolution rounding at the camera constraint layer rather than inside a single input handler. During an active two-finger pinch, OpenLayers lets intermediate frames track finger spread smoothly, then animates the view cleanly onto the closest integer zoom step when the gesture ends.
Because the constraint lives on the view itself, mouse-wheel ticks, zoom buttons, keyboard +/− shortcuts and programmatic extent fits all honour the exact same integer zoom grid.
How it works
[constrainResolution]="true"on the view snaps settled camera resolutions to whole zoom levels while keeping active pinch gestures fluid.- Wheel zoom, on-map +/− buttons and keyboard shortcuts all end on integer zoom levels automatically because the rule belongs to the view.
- At integer zoom levels, raster OpenStreetMap tiles map 1:1 to screen pixels without bilinear upscaling or downscaling blur.
Pitfalls
- Calling fit() on a polygon with resolution snapping active chooses the coarsest integer zoom that still contains the entire geometry, which can leave wider margins around a parcel than unconstrained fractional zoom.
- Precision CAD, surveying or vector-tile maps where users need fine intermediate scales between levels 16 and 17 should leave resolution snapping off.
Related examples
The same feature in the OpenLayers examples .
Background: state and lifecycle of maps in Angular with OpenLayers, which the components of cc-openlayers take care of.