# raruto/leaflet-city-mapper architecture

> Architecture diagram of the GitHub repository raruto/leaflet-city-mapper, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-17). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/raruto/leaflet-city-mapper
- Repository: https://github.com/raruto/leaflet-city-mapper

## Overview

Leaflet City Mapper is a WebGPU 3D rendering plugin exposed as Leaflet layers. The main user flow is to add a layer with a source, load and prepare geospatial or model data, and display it in a pitched or rotated map; users can also interact with features and control camera, walking, and simulated sunlight. The README documents the supported source types and controls, while sampled code shows the Leaflet integration, camera extensions, worker execution, and rendering-pipeline setup. Internal links for unsampled source and scene orchestration are left unverified.

Main entry points: [`src/scene/layerInitialize.js`](https://github.com/raruto/leaflet-city-mapper/blob/master/src/scene/layerInitialize.js) (Source initialization), [`src/index.js`](https://github.com/raruto/leaflet-city-mapper/blob/master/src/index.js) (Leaflet layer API), [`src/rendering/render.js`](https://github.com/raruto/leaflet-city-mapper/blob/master/src/rendering/render.js) (WebGPU rendering), [`src/camera/mapCamera.js`](https://github.com/raruto/leaflet-city-mapper/blob/master/src/camera/mapCamera.js) (Map camera)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_leaflet["Leaflet integration"]
  node_leaflet_layer["Leaflet layer API<br/>[index.js]"]
  node_source_router["Source initialization<br/>[layerInitialize.js]"]
  node_native_layers["Native Leaflet layers<br/>[nativeLayer.js]"]
end

subgraph group_sources["Data sources"]
  node_vector["Vector features<br/>[evaluateStyle.js]"]
  node_vector_tiles["MVT decoding"]
  node_archives["PMTiles archives<br/>[loadSource.js]"]
  node_cog["COG imagery<br/>[openCog.js]"]
  node_raster["Raster tiles<br/>[loadRasterTile.js]"]
  node_models["glTF models<br/>[loadModel.js]"]
  node_terrain["Terrain layers<br/>[loadGridTerrain.js]"]
end

subgraph group_scene["3D scene"]
  node_geometry["Geometry building<br/>[roofFootprint.js]"]
  node_workers["Source workers<br/>[runSourceWorker.js]"]
  node_renderer["WebGPU rendering<br/>[render.js]"]
  node_pipeline["Mesh pipelines<br/>[drawPipeline.js]"]
end

subgraph group_interaction["Map interaction"]
  node_camera["Map camera<br/>[mapCamera.js]"]
  node_camera_controls["Camera controls<br/>[dragCamera.js]"]
  node_picking["Feature picking<br/>[raycast.js]"]
end

subgraph group_controls["Time and controls"]
  node_walk["Walk control<br/>[createWalk.js]"]
  node_sunlight["Sunlight and time<br/>[updateSun.js]"]
end

node_user(("Map developer"))

node_user -->|"creates layer"| node_leaflet_layer
node_leaflet_layer -->|"initializes source"| node_source_router
node_leaflet_layer -->|"extends map"| node_camera
node_source_router -.->|"selects source"| node_vector
node_source_router -.->|"selects source"| node_archives
node_source_router -.->|"selects source"| node_cog
node_source_router -.->|"selects source"| node_raster
node_source_router -.->|"selects source"| node_models
node_source_router -.->|"selects source"| node_terrain
node_source_router -.->|"initializes layers"| node_native_layers
node_vector -.->|"may decode tiles"| node_vector_tiles
node_archives -.->|"may read imagery"| node_cog
node_workers -.->|"runs source jobs"| node_geometry
node_geometry -.->|"supplies geometry"| node_renderer
node_renderer -.->|"creates pipelines"| node_pipeline
node_camera_controls -.->|"changes view"| node_camera
node_picking -.->|"reports features"| node_leaflet_layer
node_walk -.->|"controls movement"| node_camera
node_sunlight -.->|"requests render"| node_renderer

click node_leaflet_layer "https://github.com/raruto/leaflet-city-mapper/blob/master/src/index.js"
click node_source_router "https://github.com/raruto/leaflet-city-mapper/blob/master/src/scene/layerInitialize.js"
click node_vector "https://github.com/raruto/leaflet-city-mapper/blob/master/src/vector-style/evaluateStyle.js"
click node_vector_tiles "https://github.com/raruto/leaflet-city-mapper/blob/master/src/mvt/decodeVectorTile.js"
click node_archives "https://github.com/raruto/leaflet-city-mapper/blob/master/src/archives/loadSource.js"
click node_cog "https://github.com/raruto/leaflet-city-mapper/blob/master/src/cog/openCog.js"
click node_raster "https://github.com/raruto/leaflet-city-mapper/blob/master/src/raster/loadRasterTile.js"
click node_models "https://github.com/raruto/leaflet-city-mapper/blob/master/src/models/loadModel.js"
click node_terrain "https://github.com/raruto/leaflet-city-mapper/blob/master/src/native/loadGridTerrain.js"
click node_native_layers "https://github.com/raruto/leaflet-city-mapper/blob/master/src/native/nativeLayer.js"
click node_geometry "https://github.com/raruto/leaflet-city-mapper/blob/master/src/geometry/roofFootprint.js"
click node_workers "https://github.com/raruto/leaflet-city-mapper/blob/master/src/workers/runSourceWorker.js"
click node_renderer "https://github.com/raruto/leaflet-city-mapper/blob/master/src/rendering/render.js"
click node_pipeline "https://github.com/raruto/leaflet-city-mapper/blob/master/src/rendering/drawPipeline.js"
click node_camera "https://github.com/raruto/leaflet-city-mapper/blob/master/src/camera/mapCamera.js"
click node_camera_controls "https://github.com/raruto/leaflet-city-mapper/blob/master/src/controls/dragCamera.js"
click node_picking "https://github.com/raruto/leaflet-city-mapper/blob/master/src/picking/raycast.js"
click node_walk "https://github.com/raruto/leaflet-city-mapper/blob/master/src/walk/createWalk.js"
click node_sunlight "https://github.com/raruto/leaflet-city-mapper/blob/master/src/sunlight/updateSun.js"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_leaflet_layer,node_source_router,node_native_layers toneBlue
class node_vector,node_vector_tiles,node_archives,node_cog,node_raster,node_models,node_terrain toneAmber
class node_geometry,node_workers,node_renderer,node_pipeline toneMint
class node_camera,node_camera_controls,node_picking toneRose
class node_walk,node_sunlight,node_user toneIndigo
```

## Components

### Leaflet integration

- [Leaflet layer API](https://github.com/raruto/leaflet-city-mapper/blob/master/src/index.js): `src/index.js`
- [Source initialization](https://github.com/raruto/leaflet-city-mapper/blob/master/src/scene/layerInitialize.js): `src/scene/layerInitialize.js`
- [Native Leaflet layers](https://github.com/raruto/leaflet-city-mapper/blob/master/src/native/nativeLayer.js): `src/native/nativeLayer.js`

### Data sources

- [Vector features](https://github.com/raruto/leaflet-city-mapper/blob/master/src/vector-style/evaluateStyle.js): `src/vector-style/evaluateStyle.js`
- [MVT decoding](https://github.com/raruto/leaflet-city-mapper/blob/master/src/mvt/decodeVectorTile.js): `src/mvt/decodeVectorTile.js`
- [PMTiles archives](https://github.com/raruto/leaflet-city-mapper/blob/master/src/archives/loadSource.js): `src/archives/loadSource.js`
- [COG imagery](https://github.com/raruto/leaflet-city-mapper/blob/master/src/cog/openCog.js): `src/cog/openCog.js`
- [Raster tiles](https://github.com/raruto/leaflet-city-mapper/blob/master/src/raster/loadRasterTile.js): `src/raster/loadRasterTile.js`
- [glTF models](https://github.com/raruto/leaflet-city-mapper/blob/master/src/models/loadModel.js): `src/models/loadModel.js`
- [Terrain layers](https://github.com/raruto/leaflet-city-mapper/blob/master/src/native/loadGridTerrain.js): `src/native/loadGridTerrain.js`

### 3D scene

- [Geometry building](https://github.com/raruto/leaflet-city-mapper/blob/master/src/geometry/roofFootprint.js): `src/geometry/roofFootprint.js`
- [Source workers](https://github.com/raruto/leaflet-city-mapper/blob/master/src/workers/runSourceWorker.js): `src/workers/runSourceWorker.js`
- [WebGPU rendering](https://github.com/raruto/leaflet-city-mapper/blob/master/src/rendering/render.js): `src/rendering/render.js`
- [Mesh pipelines](https://github.com/raruto/leaflet-city-mapper/blob/master/src/rendering/drawPipeline.js): `src/rendering/drawPipeline.js`

### Map interaction

- [Map camera](https://github.com/raruto/leaflet-city-mapper/blob/master/src/camera/mapCamera.js): `src/camera/mapCamera.js`
- [Camera controls](https://github.com/raruto/leaflet-city-mapper/blob/master/src/controls/dragCamera.js): `src/controls/dragCamera.js`
- [Feature picking](https://github.com/raruto/leaflet-city-mapper/blob/master/src/picking/raycast.js): `src/picking/raycast.js`

### Time and controls

- [Walk control](https://github.com/raruto/leaflet-city-mapper/blob/master/src/walk/createWalk.js): `src/walk/createWalk.js`
- [Sunlight and time](https://github.com/raruto/leaflet-city-mapper/blob/master/src/sunlight/updateSun.js): `src/sunlight/updateSun.js`

### Other components

- **Map developer**

## Connections

- Map developer → Leaflet layer API: creates layer (evidence: `README.md`)
- Leaflet layer API → Source initialization: initializes source (evidence: `src/index.js`)
- Leaflet layer API → Map camera: extends map (evidence: `src/index.js`)
- Source initialization → Vector features: selects source
- Source initialization → PMTiles archives: selects source
- Source initialization → COG imagery: selects source
- Source initialization → Raster tiles: selects source
- Source initialization → glTF models: selects source
- Source initialization → Terrain layers: selects source
- Source initialization → Native Leaflet layers: initializes layers
- Vector features → MVT decoding: may decode tiles
- PMTiles archives → COG imagery: may read imagery
- Source workers → Geometry building: runs source jobs
- Geometry building → WebGPU rendering: supplies geometry
- WebGPU rendering → Mesh pipelines: creates pipelines
- Camera controls → Map camera: changes view
- Feature picking → Leaflet layer API: reports features
- Walk control → Map camera: controls movement
- Sunlight and time → WebGPU rendering: requests render
