Controls · Angular, React and OpenLayers
A full screen button
Add an OpenLayers FullScreen button over GUGiK WMTS orthophoto tiles of Kraków so the map expands to fill the screen and resizes cleanly.

What this example shows
High-resolution aerial orthophotography of Kraków’s Old Town, Wawel Castle and the Vistula river bend opens at zoom 14 from Poland’s national GUGiK WMTS service, equipped with a FullScreen toggle button in the top-right corner.
Clicking the button expands the map canvas across your entire monitor via the browser Fullscreen API, automatically recalculates viewport dimensions to fill the larger area with tiles, and restores the embedded page layout on a second click or Escape.
When you need it
Inspecting dense aerial orthophotography, utility networks or cadastral boundaries inside a narrow article column or dashboard card often feels cramped, yet navigating away to a separate page loses work context.
A native FullScreen control lets analysts temporarily dedicate every pixel of their monitor to the map and return seamlessly with Escape.
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.
full-screen.tsimport { ChangeDetectionStrategy, Component } from '@angular/core';
import { getTopLeft, getWidth } from 'ol/extent';
import { EXTENT } from 'ol/proj/epsg3857';
import {
ControlFullScreenComponent,
CoordinateComponent,
DefaultControlComponent,
DefaultInteractionComponent,
LayerTileComponent,
MapComponent,
SourceTileWMTSComponent,
TileGridWMTSComponent,
ViewComponent,
} from 'cc-openlayers';
const size = getWidth(EXTENT) / 256;
/** The orthophoto with a full screen control in the corner of the map. */
@Component({
selector: 'app-full-screen',
imports: [
ControlFullScreenComponent,
CoordinateComponent,
DefaultControlComponent,
DefaultInteractionComponent,
LayerTileComponent,
MapComponent,
SourceTileWMTSComponent,
TileGridWMTSComponent,
ViewComponent,
],
changeDetection: ChangeDetectionStrategy.OnPush,
template: `
<aol-map height="480px">
<aol-interaction-default />
<aol-control-defaults />
<aol-control-fullscreen />
<aol-view [zoom]="14">
<aol-coordinate [x]="19.9368" [y]="50.0614" srid="EPSG:4326" />
</aol-view>
<aol-layer-tile>
<aol-source-tilewmts
attributions='Tiles © <a href="https://www.geoportal.gov.pl/" target="_blank">GUGiK</a>'
url="https://mapy.geoportal.gov.pl/wss/service/PZGIK/ORTO/WMTS/StandardResolution"
layer="ORTOFOTOMAPA"
matrixSet="EPSG:3857"
format="image/jpeg"
projection="EPSG:3857"
[style]="'default'"
>
<aol-tilegrid-wmts [origin]="origin" [resolutions]="resolutions" [matrixIds]="matrixIds" />
</aol-source-tilewmts>
</aol-layer-tile>
</aol-map>
<div class="example-controls">
<p class="example-hint">
Click the control in the top right corner of the map to go full screen, and again to leave it.
</p>
</div>
`,
})
export class FullScreen {
protected readonly origin = getTopLeft(EXTENT);
protected readonly resolutions = Array.from({ length: 20 }, (_, z) => size / 2 ** z);
protected readonly matrixIds = Array.from({ length: 20 }, (_, z) => `EPSG:3857:${z}`);
} 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.
full-screen.react.tsximport { getTopLeft, getWidth } from 'ol/extent.js';
import { EXTENT } from 'ol/proj/epsg3857.js';
import {
Coordinate,
DefaultControls,
DefaultInteractions,
FullScreenControl,
Map,
TileLayer,
View,
WMTSSource,
useWMTSTileGrid,
} from 'cc-openlayers/react';
const size = getWidth(EXTENT) / 256;
const gridOptions = {
origin: getTopLeft(EXTENT),
resolutions: Array.from({ length: 20 }, (_, z) => size / 2 ** z),
matrixIds: Array.from({ length: 20 }, (_, z) => `EPSG:3857:${z}`),
};
/** The orthophoto with a full screen control in the corner of the map. */
export function FullScreen() {
const tileGrid = useWMTSTileGrid(gridOptions);
return (
<>
<Map height="480px">
<DefaultInteractions />
<DefaultControls />
<FullScreenControl />
<View zoom={14}>
<Coordinate x={19.9368} y={50.0614} srid="EPSG:4326" />
</View>
<TileLayer>
<WMTSSource
attributions='Tiles © <a href="https://www.geoportal.gov.pl/" target="_blank">GUGiK</a>'
url="https://mapy.geoportal.gov.pl/wss/service/PZGIK/ORTO/WMTS/StandardResolution"
layer="ORTOFOTOMAPA"
matrixSet="EPSG:3857"
format="image/jpeg"
projection="EPSG:3857"
style="default"
tileGrid={tileGrid}
/>
</TileLayer>
</Map>
<div className="example-controls">
<p className="example-hint">
Click the control in the top right corner of the map to go full screen, and again to leave it.
</p>
</div>
</>
);
}How the React version works
A full-screen control beside the defaults, over Kraków's orthophoto at zoom 14.
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. Both versions compute the WMTS tile grid of GUGiK's orthophoto (origin, 20 resolutions, ids EPSG:3857:z) in the same way; in React the useWMTSTileGrid hook creates it once from module constants.
From Angular to React
| Angular | React |
|---|---|
<aol-control-fullscreen /> | <FullScreenControl /> |
<aol-source-tilewmts> with <aol-tilegrid-wmts> inside | <WMTSSource tileGrid={tileGrid}> with useWMTSTileGrid(...) |
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. The control is a child of Map, as in the Angular template; the adapter adds it to the map and removes it on unmount.
Architecture and OpenLayers mechanics
Mounting aol-control-fullscreen places OpenLayers’ FullScreen widget in the top-right control slot (above the auto-hiding rotate button). Without a custom source target, it requests fullscreen directly on OpenLayers’ own viewport element and triggers an automatic map size update both on enter and on exit.
The aerial backdrop connects to GUGiK’s public WMTS (ORTOFOTOMAPA in the EPSG:3857 matrix set), with aol-tilegrid-wmts defining the top-left Web Mercator origin and 20 resolution steps.
How it works
aol-control-fullscreenadds the top-right full-screen toggle targeting the map’s own viewport element by default.- Entering and exiting full screen automatically re-measures the map container so tiles fill the monitor and then return cleanly to page dimensions.
- Aerial imagery streams from GUGiK’s
ORTOFOTOMAPAWMTS layer inEPSG:3857using a 20-levelaol-tilegrid-wmtspyramid. - When the view is rotated, the compass reset button positions itself cleanly beneath the full-screen button in the same corner.
Pitfalls
- In environments where the Fullscreen API is unavailable or blocked by iframe permissions (such as certain embedded webviews or older iOS browsers), OpenLayers hides the button automatically—do not rely on it as the sole layout path.
- Default full-screen mode promotes only the OpenLayers map element: external HTML legends, sidebars or Angular/React dialogs rendered outside the map container stay hidden behind the fullscreen surface unless wrapped together via
source, as shown in the full-screen-source example.
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.