Hello.
For RWT, you can get the coordinate under the cursor with RealWorldTerrainMonoBase.GetCoordinatesUnderCursor.
http://infinity-code.com/doxygen/real-w … c9b337f452
For Online Maps, you can get the coordinate under the cursor using OnlineMapsControlBase.GetCoords.
https://infinity-code.com/doxygen/onlin … ab8b006546
Unfortunately you don't have a way to automatically make map and terrain match.
You can implement some kind of algorithm (something like below), but it's still not ideal and will have a calculation error.
using System;
using System.Collections;
using InfinityCode.RealWorldTerrain;
using UnityEngine;
public class MatchTerrainSize : MonoBehaviour
{
public RealWorldTerrainContainer container;
[Range(0, 1)]
public float mapAlpha = 1;
private float _mapAlpha = 1;
public static void GetCenterPointAndZoom(OnlineMaps map, IEnumerable positions, out OnlineMapsVector2d center, out float zoom, Vector2 inset = default(Vector2))
{
center = new OnlineMapsVector2d();
zoom = OnlineMaps.MINZOOM;
if (positions == null || map == null) return;
double minX = double.MaxValue;
double minY = double.MaxValue;
double maxX = double.MinValue;
double maxY = double.MinValue;
int type = -1; // 0 - Vector2, 1 - OnlineMapsVector2d, 2 - marker2D, 3 - marker3d, 4 - float, 5 - double
object prev = null;
int pindex = -1;
int vindex = 0;
bool useTwoValues = false;
foreach (object v in positions)
{
pindex++;
if (type == -1)
{
if (v is Vector2) type = 0;
else if (v is OnlineMapsVector2d) type = 1;
else if (v is OnlineMapsMarker) type = 2;
else if (v is OnlineMapsMarker3D) type = 3;
else if (v is float) type = 4;
else if (v is double) type = 5;
else return;
if (type >= 4) useTwoValues = true;
}
if (useTwoValues && pindex % 2 != 1)
{
prev = v;
continue;
}
double lng = 0, lat = 0;
if (type == 0)
{
Vector2 p = (Vector2)v;
lng = p.x;
lat = p.y;
}
else if (type == 1)
{
OnlineMapsVector2d p = (OnlineMapsVector2d)v;
lng = p.x;
lat = p.y;
}
else if (type == 2 || type == 3)
{
OnlineMapsMarkerBase p = v as OnlineMapsMarkerBase;
p.GetPosition(out lng, out lat);
}
else if (type == 4)
{
lng = (float)prev;
lat = (float)v;
}
else if (type == 5)
{
lng = (double)prev;
lat = (double)v;
}
if (vindex > 0)
{
double rx = lng - minX;
if (rx > 180) lng -= 360;
else if (rx < -180) lng += 360;
}
if (lng < minX) minX = lng;
if (lng > maxX) maxX = lng;
if (lat < minY) minY = lat;
if (lat > maxY) maxY = lat;
vindex++;
}
double sx = maxX - minX;
double sy = maxY - minY;
center = new OnlineMapsVector2d(sx / 2 + minX, sy / 2 + minY);
if (center.x < -180) center.x += 360;
else if (center.x > 180) center.x -= 360;
if (vindex == 1)
{
zoom = OnlineMaps.MAXZOOM;
return;
}
OnlineMapsProjection projection = map.projection;
double alx, aty, arx, aby;
projection.CoordinatesToTile(minX, maxY, OnlineMaps.MAXZOOM, out alx, out aty);
projection.CoordinatesToTile(maxX, minY, OnlineMaps.MAXZOOM, out arx, out aby);
double mapRangeX = (map.width - inset.x * 2) / OnlineMapsUtils.tileSize;
double mapRangeY = (map.height - inset.y * 2) / OnlineMapsUtils.tileSize;
double areaRangeX = arx - alx;
double areaRangeY = aby - aty;
double rangeX = areaRangeX / mapRangeX;
double rangeY = areaRangeY / mapRangeY;
double zoomOffsetX = Math.Log(rangeX, 2);
double zoomOffsetY = Math.Log(rangeY, 2);
zoom = OnlineMaps.MAXZOOM - (float)Math.Max(zoomOffsetX, zoomOffsetY) - 0.5f;
}
private void Start()
{
if (container == null) return;
OnlineMaps map = OnlineMaps.instance;
OnlineMapsVector2d center;
float zoom;
GetCenterPointAndZoom(map, new double[]
{
container.leftLongitude,
container.topLatitude,
container.rightLongitude,
container.bottomLatitude
}, out center, out zoom);
map.SetPositionAndZoom(center.x, center.y, zoom);
OnlineMapsTileSetControl control = map.control as OnlineMapsTileSetControl;
float size = Mathf.Max(container.size.x, container.size.z);
control.sizeInScene = new Vector2(size, size);
map.transform.rotation = Quaternion.Euler(0, 180, 0);
map.transform.position = container.transform.position + new Vector3((container.size.x - size) / 2, 0, size + (container.size.z - size) / 2);
control.OnDrawTile += OnDrawTile;
}
private void OnDrawTile(OnlineMapsTile tile, Material material)
{
Color color = material.color;
color.a = mapAlpha;
material.color = color;
}
private void Update()
{
if (_mapAlpha != mapAlpha)
{
OnlineMaps.instance.Redraw();
_mapAlpha = mapAlpha;
}
}
}
Kind Regards,
Infinity Code Team.
Boost your productivity a lot and immediately using
Ultimate Editor Enhancer.
Trial and non-commerce versions available.