Using the Built-in Camera Controls

Using the Built-in Camera Controls

A set of optional, built-in camera controls is provided for mouse and keyboard or touch devices. These help users explore the maps by panning, rotating, tilting and zooming to change their view. Alternatively, see Using your own Camera & Controls for an example of custom camera control.


  Mouse & Keyboard (PC) Touch Controls (iOS/Android)
Pan Drag with left mouse button held Single finger drag
Rotate Drag with right mouse button held Rotate two fingers on screen
Zoom In/Out Mouse Wheel Pinch gesture
Tilt Drag up/down with middle mouse button held Place two fingers on screen and move up/down in unison

Enabling the Built-in Controls

Selecting the built-in camera controls for the WrldMap behaviour

If you’re using the WrldMap behaviour, the built-in camera controls are enabled from a checkbox (pictured right) when the behaviour is selected in the Inspector. The camera to which the controls will be applied must also be selected. If you’re writing your own behaviour, you’ll need to tell the API which camera to control using SetControlledCamera as follows:


Similarly, you can stop the camera being controlled by the built-in camera controls with ClearControlledCamera like this:


Coordinate System

Choosing the coordinate space in the inspector, at edit time

The Wrld Camera API can be used to control the camera in either the UnityWorld or ECEF coordinate systems. In this example we’re using the ECEF system as it allows for travel to any point on the globe. If you’re writing your own behaviour, you can choose to run in the ECEF space at API creation time, as shown below:

	Api.Create(m_apiKey, CoordinateSystem.ECEF, rootTransform, defaultConfig);

Starting Location

Choosing the starting location

You can select the starting latitude and longitude of the point the camera focuses on by specifying the Start Latitude and Start Longitude fields on the WrldMap behaviour. The latitude and longitude are expressed in decimal degrees, using the WGS84 standard (this is the same as the standard used by Google, Bing and many other mapping providers). The initial altitude of the camera, expressed in metres above sea level can also be specified, along with a heading in decimal degrees (where 0 degrees faces north, 90 east, and so forth). If you’re writing a custom behaviour, you can instead set these fields in the Wrld.ConfigParams object that gets passed into Api.Create:

	var config = ConfigParams.MakeDefaultConfig();
	config.Altitude = m_altitude;
	config.LatitudeDegrees = m_latitudeDegrees;
	config.LongitudeDegrees = m_longitudeDegrees;
	config.HeadingDegrees = m_headingDegees;

Streaming the map resources

If you’re using the WrldMap behaviour, streaming will be looked after automatically (the set of resources to be streamed is updated when the camera location changes). If you’re writing a custom behaviour, however, you will need to tell the API when the camera changes position. The relevant call is Api.StreamResourcesForCamera: