/* INFINITY CODE 2013-2016 */
/* http://www.infinity-code.com */
using UnityEngine;
namespace InfinityCode.OnlineMapsExamples
{
///
/// Example how to change the position of the map using the joystick.
///
[AddComponentMenu("Infinity Code/Online Maps/Examples (API Usage)/ChangePositionUsingJoystick")]
public class ChangePositionUsingJoystick : MonoBehaviour
{
///
/// Speed of moving the map.
///
public float speed = 1;
private OnlineMaps map;
private void Start()
{
map = OnlineMaps.instance;
}
private void Update()
{
// Gets axis
float latitudeSpeed = Input.GetAxis("Vertical") * Time.deltaTime;
float longitudeSpeed = Input.GetAxis("Horizontal") * Time.deltaTime;
if (latitudeSpeed == 0 && longitudeSpeed == 0) return;
// Gets map position
double lng, lat;
map.GetPosition(out lng, out lat);
// Converts the geographic coordinates to the tile coordinates.
double tx, ty;
map.projection.CoordinatesToTile(lng, lat, map.zoom, out tx, out ty);
// Move tile coordinates
tx += longitudeSpeed * speed;
ty -= latitudeSpeed * speed;
double nLng, nLat;
// Converts the tile coordinates to the geographic coordinates.
map.projection.TileToCoordinates(tx, ty, map.zoom, out nLng, out nLat);
if (longitudeSpeed != 0) lng = nLng;
if (latitudeSpeed != 0) lat = nLat;
// Set map position
map.SetPosition(lng, lat);
}
}
}