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.

The orthophotomap of Kraków's Old Town, Wawel and the Vistula at zoom 14, with the full screen button in the top right corner and the hint below the map.
A screenshot of the example. Orthophotomap © GUGiK.

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.ts
import { 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}`);
}

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-fullscreen adds 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 ORTOFOTOMAPA WMTS layer in EPSG:3857 using a 20-level aol-tilegrid-wmts pyramid.
  • 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.

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.