View on GitHub

leaflet-city-mapper

A small 3D rendering engine for leaflet

Camera

Source guide Project README

Extends map behavior for pitch and bearing and updates the scene camera to match the Leaflet view. Camera-aware bounds and pan operations live here as well.

Map state versus scene camera

flowchart LR
  Input["Controls / map API"] --> Set["Validate angles"]
  Set --> State["Per-map pitch + bearing"]
  State --> Events["pitch / rotate events"]
  State --> Camera["updateMapCamera"]
  View["Viewport + zoom + origin"] --> Camera
  Height["Terrain + walker height"] --> Camera
  Camera --> Render["Scene perspective"]

Pitch is clamped and bearing normalized. The rendering camera is derived from map state, including intermediate zoom views; elevated geometry uses the GPU camera, not a CSS transform. Ground conversion lives in projections.

The perspective maps the near plane to depth 1 and the far plane to depth 0. The scene uses depth32float, clears to 0 and compares greater-equal so metre-offset overlays keep their depth separation even at overview zoom. The near plane follows one percent of the focus distance, with a 10 cm minimum for close-up and walking views. Frustum distances are unchanged; shadow maps keep their independent orthographic projection and forward depth convention.

Related: controls, projections, animations.