Skip to content
Snippets Groups Projects
Commit 47918f95 authored by Rico Possienka's avatar Rico Possienka
Browse files

support picking

parent fdd77df2
No related branches found
No related tags found
No related merge requests found
......@@ -560,7 +560,8 @@ MonoBehaviour:
m_EditorClassIdentifier:
map: {fileID: 1531869475}
mainCamera: {fileID: 1351042193}
pointProvider: {fileID: 1589241769}
dataPointVisualize: {fileID: 1020559675}
selectedLineRendererThickness: 3
--- !u!4 &512039574
Transform:
m_ObjectHideFlags: 0
......@@ -964,7 +965,7 @@ MonoBehaviour:
map: {fileID: 1531869475}
dataPathPrefab: {fileID: 30970607541745683, guid: b4fe9b9891b8d4243be82fd4ef1a8ecb,
type: 3}
dataLimit: 3
dataLimit: 99
dataPointProvider: {fileID: 1589241769}
--- !u!1 &1215081329
GameObject:
......
......@@ -33,6 +33,14 @@ public class DataPointVisualize : MonoBehaviour
Vector3 _targetPosition;
public List<DataPath> Paths
{
get
{
return paths;
}
}
List<DataPath> paths = new List<DataPath>();
public void SetTime(float t)
......@@ -144,7 +152,6 @@ public class DataPointVisualize : MonoBehaviour
lastID = point.id_hash;
//GameObject go = new GameObject(point.id);
GameObject go = Instantiate(this.dataPathPrefab, this.transform);
go.name = point.id_hash.ToString();
path = go.GetComponent<DataPath>();
......
......@@ -4,12 +4,17 @@ using System.Collections.Generic;
using UnityEngine;
using Mapbox.Unity.Utilities;
using Mapbox.Utils;
using System;
public class PathPicker : MonoBehaviour
{
public AbstractMap map;
public Camera mainCamera;
public DataPointProvider pointProvider;
public DataPointVisualize dataPointVisualize;
public float selectedLineRendererThickness = 3;
private LineRenderer lastLineRender = null;
private float lastLineRenderWidth;
public void Update()
{
......@@ -17,6 +22,45 @@ public class PathPicker : MonoBehaviour
ProcessClick();
}
}
private void pickPath(Vector2d geo)
{
double distances = Double.MaxValue;
DataPath closestPath = null;
Debug.Log(dataPointVisualize.Paths);
foreach (var path in dataPointVisualize.Paths)
{
foreach (var point in path.points)
{
Vector2d p = new Vector2d(point.lat, point.lon);
var div = geo - p;
var mag = div.sqrMagnitude;
if (mag < distances) {
distances = mag;
closestPath = path;
}
}
}
if (closestPath != null)
{
Debug.Log(closestPath.id_hash);
var lr = closestPath.GetComponent<LineRenderer>();
if (lastLineRender) {
lastLineRender.startWidth = lastLineRenderWidth;
lastLineRender.endWidth = lastLineRenderWidth;
}
lastLineRender = lr;
lastLineRenderWidth = lr.startWidth;
lr.startWidth = selectedLineRendererThickness;
lr.endWidth = selectedLineRendererThickness;
}
}
public void ProcessClick()
{
......@@ -33,6 +77,7 @@ public class PathPicker : MonoBehaviour
var geo = p.GetGeoPosition(map.CenterMercator, map.WorldRelativeScale);
Debug.Log(geo.ToString());
pickPath(geo);
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment