The Map View component
Map View is the component that draws the map in your UI. Add Map to Scene, Add Minimap and Add World Map all create one on a UI object (it needs a Raw Image, which Unity adds for you). You set it up in the inspector, and you drive it from a script.
The map is drawn in the Game view outside Play too, so you see it while you set it up. The game controls (drag, zoom, follow, fog of war) work in Play.
The inspector
- Theme
The look of the map. The menu lists the themes baked beside the map, plus your own (see Themes and Your own style).
- Frame the Terrain
Centres the map on your baked terrain and zooms so that it fills the rectangle. Use it after you resize the map or pick another theme.
- Zoom
How close the map is. Each step doubles the size of the map. A small number shows a wide area, a large number a small one. On a baked map, Frame the Terrain finds a good value for you.
- Rotation
Turns the map, in degrees, clockwise. 0 puts north up, 90 puts east up.
The Player section holds what the map does with the player and what the player can do with the map:
- Follow
An object to keep at the centre of the map, usually the player. Empty: the map stays where it is. It needs a map baked from your scene.
- Rotate With Target
Turns the map with the followed object, so that the way it faces points up.
- Can Pan, Can Rotate, Can Zoom
Let the player drag the map, turn it (right-drag, or Ctrl + drag) and zoom it with the mouse wheel. Untick them for a fixed minimap.
- Min Zoom, Max Zoom
How far out and how close in the map can go.
- Keep Inside Map
Keeps the view over the baked terrain: the player cannot drag past its edges.
While Follow is set, the player cannot drag the map (the followed object decides the centre). Rotate With Target also overrides turning the map by hand.
The Look section makes the map Round (a round minimap) and gives it a Border Width and Border Color. Add Fog of War is described in Fog of war.
Under Advanced are the Style File (the file the theme menu writes), and the Centre Longitude and Centre Latitude of the view, in degrees. You rarely need them on a baked map.
On a Map View with no map yet, an Online Tiles menu fills in a real-world map in one click. See Real-world maps.
Use the map from a script
using RustyAstroboy.Worldprint;
MapView map = GetComponent<MapView>(); // or a field you assign in the inspector
map.Follow = player;
map.Zoom = 17;
Every setting of the inspector is also a property with the same name: Zoom, Bearing (the rotation),
Follow, RotateWithTarget, CanPan, CanRotate, CanZoom, MinZoom, MaxZoom,
KeepInsideMap, Round, BorderWidth and BorderColor. Setting Zoom, Bearing or Center
moves the view at once. To animate it, see Move the view.
Before the map is loaded
The map loads a moment after the scene starts. You do not have to wait: calls to EaseTo, FitBounds and
the marker methods (Put a marker on the map) made before it is ready are kept and run, in order, as soon as it is.
To know when the map is ready, for example to hide a loading screen:
if (map.IsLoaded) loadingScreen.SetActive(false);
else map.Loaded += () => loadingScreen.SetActive(false);
Loaded is raised once for each style, when the first complete view is drawn.
Next
Move and zoom the view: Move the view
Describe a place: Coordinates
Put markers and shapes on the map: Put a marker on the map
React to clicks and the mouse: Clicks and the pointer