public void CalculateLatLon(MapBoundaries mb)
    {
        var latlon = new Vector3[4];

        for (int i = 0; i < vertices.Length; i++)
        {
            var res = CoordinateConvertor.Vector3ToLatLon(vertices[i], mb);
            latlon[i] = new Vector3(res[0], 0, res[1]);
        }
        var bounds = GetBounds(latlon);

        minLat = bounds[0];
        maxLat = bounds[1];
        minLon = bounds[2];
        maxLon = bounds[3];

        if (verbose)
        {
            for (int i = 0; i < vertices.Length; i++)
            {
                var convVert = CoordinateConvertor.LatLonToVector3(latlon[i].x, latlon[i].z, latlon[i].y, mb);
                Debug.Log("vertice: " + vertices[i] + " converted back: " + convVert);
            }
        }
    }
Beispiel #2
0
    /// <summary>
    /// Log the position of the dropped object in Lat-Lon coordinates.
    /// </summary>
    public void LogPositionInLatLon()
    {
        if (!deleting)
        {
            float[] latLon = CoordinateConvertor.Vector3ToLatLon(this.transform.position);

            Debug.Log(this.name + " placed at " + latLon[0] + ", " + latLon[1]);

            if (loggerAssembly != null && loggerAssembly.logDragAndDrop)
            {
                log.Info(string.Format("{0} placed at {1}, {2}", this.name, latLon[0].ToString(), latLon[1].ToString()));
            }
        }
    }
Beispiel #3
0
    void OnGUI()
    {
        GUILayout.Label("Coordinate Convertor Tool", EditorStyles.boldLabel);

        vector3 = EditorGUILayout.Vector3Field("3D point to convert", vector3);

        if (GUILayout.Button("Convert point to lat-lon"))
        {
            float[] conversion = CoordinateConvertor.Vector3ToLatLon(vector3, FindObjectOfType <MapBoundaries>());
            latitude  = conversion[0];
            longitude = conversion[1];
        }

        latitude  = EditorGUILayout.FloatField("latitude", latitude);
        longitude = EditorGUILayout.FloatField("longitude", longitude);
    }
    static void SaveStationsAndLines()
    {
        var sgos = GameObject.FindGameObjectsWithTag("TransStation");

        if (sgos.Length < 1)
        {
            Debug.Log("no stations to save.");
            return;
        }
        var lgos = GameObject.FindGameObjectsWithTag("TransLine");

        if (lgos.Length < 1)
        {
            Debug.Log("no lines to save.");
            return;
        }

        var path = EditorUtility.SaveFilePanel("Save XML Data", "Assets/Transportations", "", "xml");

        if (path.Length == 0)
        {
            EditorUtility.DisplayDialog("Saving Cancelled", "No file was provided", "OK");
            return;
        }

        List <BaseStation> stations = new List <BaseStation>();

        foreach (var go in sgos)
        {
            CoordinateConvertor.Initialize();
            float[] latLon = CoordinateConvertor.Vector3ToLatLon(go.transform.position);

            var sc = go.GetComponent <StationController>();
            var bs = new BaseStation
            {
                id   = int.Parse(sc.name),
                lat  = latLon[0],
                lon  = latLon[1],
                x    = go.transform.position.x,
                y    = go.transform.position.y,
                z    = go.transform.position.z,
                name = sc.stationName,
            };
            stations.Add(bs);
        }

        List <BaseLine> lines = new List <BaseLine>();

        foreach (var go in lgos)
        {
            var lc = go.GetComponent <LineController>();
            var bl = LineController.CreateBaseLine(lc);
            lines.Add(bl);
        }

        var container = new TrafficContainer();

        container.stations = stations;
        container.lines    = lines;
        container.Save(path);
        string stationStats = string.Format("{0} stations saved.", container.stations.Count);
        string lineStats    = string.Format("{0} lines saved.", container.lines.Count);

        EditorUtility.DisplayDialog("Saving Finished", stationStats + "\n" + lineStats + "\n to: " + path, "OK");
    }