Essentials · Angular, React and OpenLayers

A full-screen map for phones

Fill mobile browser screens cleanly using a 100dvh OpenLayers viewport that centres on the first GPS fix at street level while allowing pans.

A street-level map of Kraków's Main Square at zoom 16, centred on the reported position.
A screenshot of the example. Map data © OpenStreetMap contributors.

What this example shows

Designed for standalone mobile web apps, the map expands edge-to-edge across the full dynamic height of the device viewport (height="100dvh"), starts geolocation immediately over Kraków’s Main Square at zoom 12, and centres on your live position at street-level zoom 16 once the first fix arrives.

Once that initial lock frames your surroundings, automatic re-centring yields control so you can pan and explore nearby streets freely without GPS updates snapping the camera back.

When you need it

Dedicated mobile web utilities—such as city bike finders, parking meters, festival maps and field check-in screens—consist almost entirely of a full-bleed map starting at the user’s current street corner.

Mobile browsers dynamically retract and expand address and tab bars during touch interaction, causing classic 100vh layouts to overflow beneath browser chrome and clip bottom attribution or scale controls.

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.

mobile-full-screen.ts
import { ChangeDetectionStrategy, Component, viewChild } from '@angular/core';
import {
  CoordinateComponent,
  DefaultControlComponent,
  DefaultInteractionComponent,
  GeolocationComponent,
  LayerTileComponent,
  MapComponent,
  SourceOsmComponent,
  ViewComponent,
} from 'cc-openlayers';

/**
 * A map as tall as the screen that follows the device: it tracks the position from the start and centres the first
 * one at about 2.4 m per pixel (zoom 16). Meant for a phone, where the map fills the screen.
 */
@Component({
  selector: 'app-mobile-full-screen',
  imports: [
    CoordinateComponent,
    DefaultControlComponent,
    DefaultInteractionComponent,
    GeolocationComponent,
    LayerTileComponent,
    MapComponent,
    SourceOsmComponent,
    ViewComponent,
  ],
  changeDetection: ChangeDetectionStrategy.OnPush,
  template: `
    <aol-map height="100dvh">
      <aol-interaction-default />
      <aol-control-defaults />
      <aol-view [zoom]="12">
        <aol-coordinate [x]="19.9368" [y]="50.0614" srid="EPSG:4326" />
      </aol-view>
      <aol-layer-tile><aol-source-osm /></aol-layer-tile>
      <aol-geolocation [tracking]="true" (changePosition)="locate()" />
    </aol-map>
  `,
})
export class MobileFullScreen {
  private readonly map = viewChild.required(MapComponent);
  private readonly geolocation = viewChild.required(GeolocationComponent);
  private located = false;

  /** Centres the first position the device reports. */
  protected locate(): void {
    if (this.located) return;
    this.located = true;
    const view = this.map().instance.getView();
    view.setCenter(this.geolocation().instance.getPosition());
    view.setResolution(2.388657133911758);
  }
}

Architecture and OpenLayers mechanics

Sizing the map host with CSS dynamic viewport units (height="100dvh") tracks the browser’s real visible height as mobile toolbars collapse and reappear, triggering OpenLayers’ internal resize observer automatically.

Enabling [tracking]="true" starts geolocation on load; the first (changePosition) event centres the view and calls setResolution(2.388657133911758) (Web Mercator zoom 16, ~1.5 m/px in Kraków), while a one-shot boolean guard prevents subsequent sensor ticks from hijacking manual user pans.

How it works

  • height="100dvh" matches the mobile browser’s dynamic viewport height so retracting address bars never clip bottom map controls.
  • [tracking]="true" activates geolocation immediately and centres the camera on the first (changePosition) fix.
  • setResolution(2.388657133911758) sets zoom level 16 (~2.4 m/px at the equator and ~1.5 m/px at Kraków’s latitude).
  • A one-time initialisation flag makes later fixes return early, so the camera stays exactly where the user panned it.

Pitfalls

  • Using 100vh instead of 100dvh on iOS Safari and mobile Chrome sizes the container taller than the visible window while toolbars are open, hiding bottom-corner attributions.
  • Starting [tracking]="true" immediately triggers the browser’s location permission prompt on initial page load; in multi-purpose apps, prefer a user-initiated “Locate me” button instead.

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.