Overview

Mapper is a desktop map of any city, written in C++ in one semester. Beside the 2D map, search, and directions is a 3D viewer that rebuilds the city from open data, lit by the real sun at any hour.

The Brief

Mapper began as the ECE297 (Software Design & Communication) project at the University of Toronto, where every team builds the same map application on OpenStreetMap in four milestones: fast spatial queries, a searchable 2D map, pathfinding, and a travelling salesman problem.

The milestones are graded against the same tests, so the algorithms had to be fast. But a map that only answers “how do I get there” can’t tell you what a place looks like, what you’ll see from it, or whether the terrace faces the sunset. So on top of the required work, the team built a 3D viewer that rebuilds the city under the real sun, and tied it to the map.

The 3D Viewer

The viewer works in three stages: acquisition gathers the city from open data, processing turns it into meshes and textures, and rendering draws it under a sun placed for the chosen hour.

  1. Acquisition

    Buildings, roads, areas, and trees from OpenStreetMap, elevation from ArcGIS, and the sun’s position from NREL SPA.

  2. Processing

    GLM turns that data into building meshes, complex roofs, landmarks, billboarded trees, and texture assignments.

  3. Rendering

    OpenGL and GLSL shaders draw the sky, sun, and buildings, lit for the time of day, in perspective or top down.

Figure 1. The rendering pipeline: acquisition, processing, and rendering.

Buildings, Roads, and Areas

Every OpenStreetMap building is extruded from its footprint to its tagged height, roads are laid down as geometry, and parks, water, and plazas become coloured surfaces. That alone shows what a 2D map can’t: which towers are tall, and where the city is dense.

Lower Manhattan rendered in the 3D viewer from the harbour, with the skyline at its real heights.
Figure 2. Lower Manhattan, extruded from OpenStreetMap footprints.

Terrain

Hills decide sightlines. On a flat city, a spot that overlooks the water in real life looks into the side of a building, so the ground is a terrain mesh sampled from ArcGIS elevation data. That created the first real problem: OpenStreetMap areas arrive as flat polygons, and draping them over the terrain puts two surfaces in nearly the same place. The GPU can’t tell which is in front, so they flicker through each other as the camera moves. That is z-fighting, and at city scale it covers everything.

Two renders: on the left, parks and terrain flicker through each other in a speckled pattern; on the right, the same city with clean green areas over the terrain.
Laid over
Cut in
Figure 3. Areas laid over the terrain z-fight. Cut into it, they don't.

The fix was to cut instead of layer. Each area’s outline is cut into the elevation mesh, and the area’s own mesh is set into the hole, following the ground. With one surface at every point, there is nothing left to fight.

1Elevation meshArcGIS
2Area outlineOpenStreetMap
3Cut into the mesh
4Area set in
Figure 4. Area edges cut the elevation mesh, and the area is set into the hole.

Cutting exposed the next problem: some water polygons overlap the shore, and cutting them in faithfully flooded parts of the city. Rules for which area wins left a mesh that holds up at street level, where pedestrian mode walks on it.

Two renders of cities on hilly terrain with water, parks, and buildings sitting cleanly on the ground.
Figure 5. Terrain, water, and areas resolved into one walkable surface.

Landmarks and Complex Roofs

People navigate by landmarks, and landmarks are rarely boxes. OpenStreetMap describes them as parts, pieces with their own building:levels, min_level, height, and min_height, stacked into the real shape. A tower on a podium, a bridge between blocks, and a spire are all parts.

7 floors
24 m
5 floors
16 m
121
1Towers
  • building:levels=7
  • height=24
2Bridge
  • building:levels=7
  • building:min_level=5
  • height=24
  • min_height=16
Figure 6. A building from parts: each piece carries its own levels and heights.

Each part’s roof:shape is built too, from flat and gabled to dome and onion. Level of detail follows the camera: a distant part is a plain block, and gains its real roof as you approach.

Roof shape, from roof:shape

flat
skillion
gabled
half-hipped
hipped
pyramidal
gambrel
mansard
dome
onion
round
saltbox

Level of detail, from the camera’s distance

LOD 0
LOD 1
LOD 2
LOD 3
Figure 7. Roof shapes and level of detail, chosen from the camera's position.

Parts and roofs are what turn a field of extrusions into places people recognise.

Four renders: the Forbidden City in Beijing, Seoul Tower and Namsan Park, the Art Gallery of Ontario in Toronto, and Chaotianmen Square in Chongqing.
Forbidden City
Seoul Tower
Art Gallery of Ontario
Chaotianmen
Figure 8. The Forbidden City, Seoul Tower, the Art Gallery of Ontario, and Chaotianmen.

Time of Day

Light is most of what makes a render feel like a place. On startup, the viewer gives NREL’s Solar Position Algorithm the city’s latitude and longitude and the chosen date and time, and gets back where the sun really is and how strong it is. That drives a Hosek-Wilkie sky model, evaluated from precomputed coefficients, which colours the whole sky.

lat43.65° N
long79.38° W
date28 Apr
time19:24

On startup

Place and timeToronto, any date and hour
alt 8° · az 282°

NREL SPA

Sun positionElevation and azimuth

Hosek-Wilkie

Sky colourFrom precomputed coefficients

GLSL

Sky drawn, city litBy the sky’s average colour
19:24
Figure 9. Sun position from NREL SPA drives the sky model, and the sky lights the city.

The sky does double duty. Its average colour lights the buildings, so the city is warm at sunset, white at noon, and blue after dusk, without anyone picking a colour.

The same view across the water toward a city skyline, at midday on the left and at dusk on the right.
Midday
Dusk
Figure 10. The same viewpoint at midday and at dusk.

Trees

A city needs thousands of trees, and a real tree mesh has thousands of triangles. Instead, each tree is a billboard: three textured quads crossed through each other, which read as a full tree from any angle at a fraction of the cost. Trees go wherever OpenStreetMap marks one and are scattered across woods and natural areas, each with a random size, rotation, and tilt so a forest doesn’t look stamped.

1Tree textures
2Three crossed quads
3Size*, turn, and lean
4Placed from the map
natural=treelanduse=wood

* Size is only randomised when OpenStreetMap has no age for the tree.

Figure 11. Crossed-quad billboards, randomised and placed from OpenStreetMap.
Two renders: a road through dense trees at ground level, and an aerial view of a shoreline with parks full of trees.
Street level
From the air
Figure 12. Billboarded trees at street level and from the air.

Ground and Building Textures

Solid colours tell buildings apart but don’t make them believable. Walls take a facade texture from the building’s material tag, glass, brick, or concrete, and the areas cut into the terrain take ground textures of their own.

Mesh

Buildings, with roof parts

building:material

Facade texture

glass
concrete
brick

To the screen

GLSL
A textured concrete facade in the viewer, close up

Mesh

Terrain, with areas set in

area tags

Ground texture

Each area cut into the terrain takes a texture of its own

Figure 13. Wall textures by material tag, and ground textures for areas.
The same street-level view of a skyline in flat colours on the left and with brick, glass, and concrete facades on the right.
Flat colour
Textured
Figure 14. The same view in flat colour and textured.

Shading

Two shader choices do most of the work. The first is smooth shading. With one normal per face, a curve shows every triangle, and the only fix is more triangles. Interpolating normals across vertices shades a coarse mesh as if it were smooth, moving the cost from geometry, where it is expensive, to the fragment shader, where it is nearly free.

A domed building rendered twice: faceted on the left with flat shading, smooth on the right with interpolated normals.
Face normals
Vertex normals
Figure 15. One dome, shaded with face normals and with interpolated vertex normals.
A mountain range rendered faceted on the left and smooth on the right.
Faceted
Smooth
Figure 16. Terrain gains the most: the same mountains, faceted and smooth.

The second is Blinn-Phong lighting, built in layers. Sunlight alone turns every shaded side black, where the real atmosphere bounces light back in, so an ambient term fakes the bounce. That still looks matte, so a specular highlight fakes reflection. Three cheap terms read as a lit city.

The Rogers Centre dome lit three ways: harsh sunlight only, with ambient light added, and with a specular highlight added.
Sun only
+ Ambient
+ Specular
Figure 17. Sunlight alone, with ambient fill, and with a specular highlight.

Performance

Every choice above was made against one number. Nielsen puts the limit for feeling responsive at a tenth of a second; past it, you are waiting on the program instead of using it. Three principles kept the renderer inside it:

  • Balance detail

    Spend detail where the eye is: real roofs up close, plain blocks far away, and billboards instead of tree meshes.

  • Cheat

    Approximate and precompute: the sky comes from stored coefficients, bounced light is one ambient term, and smoothness is interpolated normals.

  • Cull

    Don’t draw what the camera can’t see.

At 1920×1080, scenes up to about two million triangles hold 60 frames a second, and 5.3 million triangles of Toronto hold 27. The worst case, 12.3 million triangles of Tokyo, still averages 12, with its slowest frames inside the tenth-of-a-second line.

Scenes by triangle count

Average1% low
Toronto Small0.24M triangles

60 / 56

Tokyo Medium1.5M triangles

60 / 54

Toronto Medium2.0M triangles

60 / 54

Tokyo Small3.6M triangles

38 / 34

Toronto Large5.3M triangles

27 / 24

Tokyo Large7.6M triangles

19 / 18

Tokyo Very large12.3M triangles

12 / 11

Figure 18. Average and 1% low frame rates at 1920×1080, by scene size.

The 2D Map

The 2D map is where most people start, so it had to feel like a modern map app, not a course assignment. Three tabs, Navigate, Explore, and Directions, sit beside the map, and one button opens the 3D viewer at the same spot.

Custom Styling

The interface is styled with CSS instead of the toolkit’s defaults: rounded inputs, one blue for primary actions, and quiet secondary buttons across the whole panel. The panel’s logic is kept apart from its presentation, MVVM style, so the look can change without touching behaviour.

University AveCollege St
Toronto, Canada ▾
+−3D
Figure 19. The styled 2D map, with a route through downtown Toronto.

Places Nearby

The Explore tab lists places near where you’re looking and narrows them to a type, such as restaurants, with one dropdown. The list sits beside the map on purpose: Fitts’s law says the time to reach a target grows with its distance. Clicking a result pans the map to it and labels it, so you never hunt for something on the map that you already found in the list.

The Black BriikType: restaurant
Toronto, Canada ▾
+−3D
Figure 20. Nearby places, filtered to restaurants, with one selected on the map.

Map Algorithms

Under the interface are the algorithm milestones, graded on speed as much as correctness.

Spatial Quadtree

The first milestone is a question the map asks constantly: which intersection is closest to this point? Checking every one works for a town and falls over for a city, so intersections are indexed in a quadtree. The map is split into quadrants, and any quadrant with too many points is split again until each holds only a few. A query checks the region its point falls in first, opens a neighbouring region only if it could hold something closer, and skips the rest unopened.

Home region

Where the query point falls. Its few intersections are checked first.

Neighbours

Opened only where the search circle reaches into them.

Closest

Found without opening the rest of the map.

Figure 21. Building the quadtree, and answering a closest-intersection query.

Against a brute-force scan, the quadtree’s query time stays nearly flat as the city grows, while the scan’s grows linearly. At 65,500 intersections it is 146 to 294 times faster, fastest on a clustered downtown.

Median query latency

QuadtreeBrute-force scan
1µs10µs100µs
257µs1.11µs
5122k8.2k32.8k65.5k

intersections indexed

Speedup over brute force at 65.5k intersections

294×Clustered downtown
210×Regular grid
146×Street corridors
247×Uniform city
Figure 22. Query latency as the city grows, and the speedup over a brute-force scan.

The fairer comparison is a regular grid. There the quadtree is 1.2 times faster on a clustered downtown and along street corridors, even on a uniform city, and 0.7 times as fast on a perfect grid, where the grid’s cells already match the data. Real cities are clustered, so the quadtree earns its complexity where it counts.

← grid fasterquadtree faster →
Clustered downtown
1.2×
Regular grid
0.7×
Street corridors
1.2×
Uniform city
1.0×
Figure 23. The quadtree against a regular grid: better on clustered cities, worse on a perfect grid.

Pathfinding

The third milestone, routing, runs on A* search. Roads are explored in order of travel time so far plus an estimate of the time left, obeying one-way rules and charging for every turn, until the destination is reached. The route is then rebuilt from the saved steps.

Explored

Opened in order of time so far plus an estimate of the time left, so the search leans toward the goal.

Route

Rebuilt from the saved steps once the goal is reached.

One-way streets

Followed only in the direction they run. The thick road is faster, so it costs less.

Figure 24. The A* implementation, from road network to route.

The estimate is straight-line distance over the map’s fastest speed limit, which never overestimates, so the route found is always the fastest. Most of the speed came from caching each segment’s travel time and each intersection’s neighbours instead of recomputing them on every search.

Impossible routes, across water or into a closed-off area, get a clear message instead of a hang or a nonsense path.

University AveCollege St

Error

No route found between selected intersections.

Close
Figure 25. An impossible route, caught and explained.

Intelligent Directions

Real trips are rarely one mode. Mapper can plan a walk plus drive: you walk to a pickup point, within a speed and time limit you set, and are driven from there. It finds every intersection you can reach on foot in that time, then runs one A* search from all of them at once instead of one per candidate, which keeps it fast.

University AveCollege St
Walk + driveWalking speed 1.4 m/sTime limit 8 min
Figure 26. Everywhere reachable on foot in the time limit, then one search from all of it: the green leg is walked and the red leg is driven.

The Directions tab turns either route into turn-by-turn steps, with the total distance and time at the top. The same two endpoints give different instructions depending on whether you walk part of the way.

Walk + drive1.57 km · 8 min 56 s

Step 1 of 5

Start on Queen’s Park and go straight for 109 m.

PreviousNext
Drive only1.64 km · 2 min 37 s

Step 1 of 4

Start on College Street and go straight for 376 m.

PreviousNext
Figure 27. Turn-by-turn directions for the walk plus drive route and for driving only.

Courier Optimisation

The fourth milestone is the travelling courier problem: the travelling salesman problem with pickups and drop-offs. The courier must find the cheapest route that collects every package before delivering it, within a fixed time budget. Trying every order is hopeless; the count explodes long before the list gets long.

The approach follows Johnson and McGeoch’s work on the problem. Build a valid route greedily, always going to the nearest legal stop, then improve it until the time runs out, trying small changes and keeping the best route seen. Simulated annealing decides which changes to accept, taking some worse routes early to escape local minima and growing strict as time runs down.

01

Start with a greedy route

02

Precompute travel times between every pair of stops

loopuntil time runs out
  1. 3

    Try a small change to the route

  2. 4

    Decide whether it helps

05

Return the best route seen

Figure 28. Greedy start, then local improvement until the budget runs out.

Three things raise the quality. A good greedy start leaves less ground to cover. Precomputed travel times between every pair of stops make each candidate a lookup instead of a pathfinding run. And several threads explore more changes in the same time. Annealing cut the greedy route’s cost by 25.2% within a 47.5-second budget.

Route cost improvement over the greedy start

0%10%20%30%
25.2%
0s10s20s30s40s
Figure 29. Improvement over the greedy route as simulated annealing runs.

A Walk in Toronto

The pieces matter most together. Take a real errand: finding a rooftop restaurant in Toronto with a view of the sunset.

On the 2D map, Explore filters nearby places to restaurants, and picking one opens the 3D viewer over its building.

The Explore tab filtered to restaurants near downtown Toronto, and the 3D viewer opened over the chosen restaurant's building.
Figure 30. Finding a restaurant on the 2D map, then seeing its building in 3D.

The walking route crosses the rail corridor, and a flat map doesn’t show where. The viewer’s overview mode shows the textured city from directly above, beside the route, and the crossing is obvious.

The 3D viewer's overview mode looking straight down on downtown Toronto, with the rail corridor crossing the textured blocks.
Overview mode
Figure 31. The rail corridor from directly above, in the viewer's overview mode.

Pedestrian mode then walks the route at street height. Towers close in, and the CN Tower appears as the route crosses the tracks, something you would otherwise only learn by going.

Four pedestrian-mode views along the walk: between towers and trees, past a brick building, crossing toward the CN Tower, and looking up at it through the trees.
Figure 32. The walk at street level, with the CN Tower appearing over the tracks.

The trip is for the view. From the rooftop, the tower next door blocks the southeast and the south, and only the southwest is open.

Three views from the rooftop: blocked by a dark tower to the southeast, blocked to the south, and open to the southwest over the stadium and the lake.
Southeast
South
Southwest
Figure 33. From the rooftop: blocked to the southeast and south, open to the southwest.

Moving the clock to evening settles it: the sun sets behind the neighbouring building. The terrace would sit in shadow with its view blocked, and no flat map could have warned you.

Two sunset views from the rooftop: the sun low beside the CN Tower, and the same sun hidden behind the adjacent building.
Figure 34. At sunset, the adjacent building blocks the sun.

Back to search. KOST, another rooftop downtown, gets the same check at the same hour.

The 3D viewer opened over a second rooftop restaurant's building in a dense part of downtown Toronto.
Figure 35. A second option, checked the same way.
Two sunset views from the second rooftop, with the sun low and unobstructed over the city and the lake.
Figure 36. At KOST, the sun sets in the open.

Search, the handoff to 3D, routing, pedestrian mode, and the sun each carried part of that errand, and together they answered a question ordinary maps can’t.

Pitch and Vision

The project’s goal was to make urban environments easier to understand and explore, through realistic renders of any city at any time. The test is whether a render matches the real place, so the team checked it against their own photos from earlier trips.

The 3D viewer's render of Chaotianmen in Chongqing from the river, beside a photograph of the same view.
Render
Photo
Figure 37. Chongqing, rendered and photographed from the same spot.
The 3D viewer's render of the Toronto skyline at sunset from the Toronto Island pier, beside a photograph taken there at sunset.
Render
Photo
Figure 38. The Toronto skyline from the Island pier at sunset, rendered and real.

Apple Maps is the obvious comparison. Its 3D mode shows nothing in Chongqing, and Look Around has real photos only where a camera car has driven, frozen at the moment they were taken. Neither can show you a view at sunset in December. Mapper can, anywhere OpenStreetMap has buildings.

Apple Maps over Chongqing with an empty 3D mode, and Apple Maps Look Around at the Toronto waterfront, showing a single fixed photograph.
Figure 39. Apple Maps: an empty 3D mode in Chongqing, and Look Around fixed at one moment.

Nothing is tied to Toronto. The same pipeline renders any city in the data, with its own terrain, landmarks, and sky.

Six renders of different cities: a mountain-backed city, a city of domed mosques, a valley at sunset, a skyline with a supertall tower, a riverside city, and Toronto with the CN Tower.
Figure 40. Any city, from the same pipeline.

Improvements

The next steps deepen the same product in three directions: better data, higher fidelity, and more interactivity.

Data Sources

OpenStreetMap is excellent at buildings and poor at everything else. Some of the world’s most recognisable landmarks aren’t buildings: in Rio de Janeiro, Christ the Redeemer is missing from its mountain. Hand-made meshes for landmarks like it would fill the gaps.

Rio de Janeiro rendered with an empty peak where Christ the Redeemer should be, beside a 3D model of the statue.
Rio de Janeiro
Model mesh
Figure 41. Rio de Janeiro without Christ the Redeemer, and a model mesh that would fill the gap.

Transit is the other gap. Streetcar rails and schedules and the VIA and GO lines are missing from both the render and routing. Adding them would put transit in directions, and the rail corridor from the walk would finally show its tracks.

The overview mode of downtown Toronto from above, with the missing rail corridor and a streetcar line drawn over it.
VIA and GO rail Streetcar
Missing from the data
Figure 42. Downtown Toronto from above, with the missing rail and streetcar lines drawn in.

Visual Fidelity

The renders are realistic; the next step is photorealistic. Physically based rendering would make the Art Gallery of Ontario’s glass reflect the street as it does in person, instead of reading as a flat blue wall.

The glass facade of the Art Gallery of Ontario in the renderer, flat and blue, beside a photo where it reflects the sky and street.
Render
Photo
Figure 43. The Art Gallery of Ontario's facade, rendered and photographed.

Shadow maps are the other half. For a question like “will this terrace be in the sun”, shadows are the answer, and beside ShadowMap at noon, the render lights streets that are really in shade.

Downtown Toronto at about noon in the renderer without shadows, beside ShadowMap showing the same blocks with building shadows.
Mapper
ShadowMap
Figure 44. Noon in Mapper, without shadows, and in ShadowMap.

Interactivity

A sunset spot is only a sunset spot if it isn’t raining. Weather would answer the question after “where is the view”: is it worth going tonight?

The Toronto skyline at sunset in the renderer, mocked up with a storm front, rain, and a flash of lightning.
Mockup
Figure 45. A mockup of a sunset in the rain.

Moving vehicles would add what a rendered city most obviously lacks: life. In some cities transit is part of the identity, like Toronto’s red streetcars and San Francisco’s cable cars.

A mockup of a Toronto streetcar in the renderer beneath overhead wires, beside a photo of a San Francisco cable car.
Mockup
San Francisco
Figure 46. A streetcar mocked up in the renderer, and San Francisco's cable cars.

Opportunities

The renderer is useful well beyond maps. The first opening is a digital twin for planners and architects: a live model of a city where you can add or change a building and see its effect at once, on sightlines, shadows, and the skyline. Digital twins are among the fastest-growing markets in software, estimated at around 41% a year, and cities already use them to plan for climate and change.

A mockup of the renderer with a new white tower inserted into Toronto's skyline, beside a Google Earth view of the same area.
Proposed tower
Google Earth
Figure 47. A proposed tower placed into the city, and Google Earth over Toronto.

The second is simulation: flight, driving, and disaster planning. Photorealistic renders plus flight controls and physics make a flight simulator, and even Microsoft Flight Simulator players have found Toronto’s CN Tower missing. The same engine fits urban air mobility research, where drone and air-taxi projects already build simulations on game engines, and a growing market of flight simulation enthusiasts and pilots.

A fly-over view of Toronto's waterfront in the renderer, beside Microsoft Flight Simulator flying past the CN Tower.
Mapper
Flight Simulator
Figure 48. A fly-over in Mapper, and in Microsoft Flight Simulator.

The Real Goal

The project began with a goal about maps: make urban environments easier to understand and explore. Seen through a planner placing a tower, or a pilot learning an approach over a city they have never flown, it is a narrower version of a larger one.

Make spatial intelligence more accessible. Knowing what a place is like, what you’ll see from it, when the sun reaches it, and what changes if something is built beside it has always meant being there or paying for expensive tools. Mapper is a first step toward that for any city, at any hour, on an ordinary laptop.