Example #1
0
    /// <summary>
    ///
    /// </summary>
    public void StartParsingNoChunks(bool reloadContent)
    {
        isRunning = true;
        finished  = false;
        Stopwatch timer = new Stopwatch();

        timer.Start();

#if UNITY_EDITOR
        string tmpFolder = EditorApplication.applicationContentsPath + @"/OSM_TMP/";
#else
        string tmpFolder = Application.dataPath + @"/OSM_TMP/";
#endif
        string tmpFile = tmpFolder + MapBounds.MaxBounds(this.boundsList).GetHashCode();


        //=======
        //        timer.Start();


        //        string tmpFolder = string.Empty;
        //        string tmpFile = string.Empty;
        //#if UNITY_EDITOR
        //        tmpFolder = EditorApplication.applicationContentsPath + @"/OSM_TMP/";
        //        tmpFile = tmpFolder + MapBounds.MaxBounds(this.boundsList).GetHashCode();
        //#elif STANDALONE
        //        tmpFolder = UnityEngine.Application.dataPath + @"/OSM_TMP/";
        //        tmpFile = tmpFolder + MapBounds.MaxBounds(this.boundsList).GetHashCode();
        //#endif
        //>>>>>>> scenemanager
        if (!File.Exists(tmpFile) || reloadContent)
        {
            if (!Directory.Exists(tmpFolder))
            {
                Debug.Log("!Directory.Exists(tmpFolder): " + !Directory.Exists(tmpFolder));
#if UNITY_EDITOR
                string newPath = Path.Combine(EditorApplication.applicationContentsPath, "OSM_TMP");
#else
                string newPath = Path.Combine(Application.dataPath, "OSM_TMP");
#endif

                Directory.CreateDirectory(newPath);
            }

            this.Map.Box = MapBounds.MaxBounds(boundsList);
            Debug.Log("\n* this.Map.Box " + this.Map.Box);

            Debug.Log("\n* Calculating Chunksize... ");
            double north = boundsList[0].North;
            double south = boundsList[0].South;
            double west  = boundsList[0].West;
            double east  = boundsList[0].East;


            // statistics and estimation


            int counter = 0;

            this.sourceType = OSMSourceType.Server;
            this.FilePath   = this.serverURL +
                              west.ToString().Replace(",", ".") + "," +
                              south.ToString().Replace(",", ".") + "," +
                              east.ToString().Replace(",", ".") + "," +
                              north.ToString().Replace(",", ".");


            this.ParseOSM();


            Debug.Log("\r* Parsing completed...\n");
#if UNITY_EDITOR
            EditorUtility.DisplayProgressBar("OSM-Data", "Writing to XML-File... ", this.progressBar);
#endif

            //this.WriteXMLFile(@"e:\dennis\XML-Chunks\Unity-Test.osm");
            this.WriteXMLFile(tmpFile);
            Debug.Log("done " + tmpFile + ".\n\n");

            Debug.Log("\n* ");
        }
        else
        {
            Debug.Log("Datei bereits vorhanden: " + tmpFile);
            this.FilePath = tmpFile;
            this.ParseOSM();
        }

        timer.Stop();
        isRunning = false;
        finished  = true;
    }
Example #2
0
    /// <summary>
    ///
    /// </summary>
    public void StartParsing(bool reloadContent)
    {
        isRunning = true;
        finished  = false;
        Stopwatch timer = new Stopwatch();

        timer.Start();


        string tmpFolder = string.Empty;
        string tmpFile   = string.Empty;

#if UNITY_EDITOR
        tmpFolder = EditorApplication.applicationContentsPath + @"/OSM_TMP/";
        tmpFile   = tmpFolder + MapBounds.MaxBounds(this.boundsList).GetHashCode();
#elif STANDALONE
        tmpFolder = UnityEngine.Application.dataPath + @"/OSM_TMP/";
        tmpFile   = tmpFolder + MapBounds.MaxBounds(this.boundsList).GetHashCode();
#endif

        if (!File.Exists(tmpFile) || reloadContent)
        {
            if (!Directory.Exists(tmpFolder))
            {
                Debug.Log("!Directory.Exists(tmpFolder): " + !Directory.Exists(tmpFolder));
                string newPath = Path.Combine(tmpFolder, "OSM_TMP");
                Directory.CreateDirectory(newPath);
            }

            this.Map.Box = MapBounds.MaxBounds(boundsList);
            Debug.Log("\n* this.Map.Box " + this.Map.Box);

            Debug.Log("\n* Calculating Chunksize... ");
            double north = boundsList[0].North;
            double south = boundsList[0].South;
            double west  = boundsList[0].West;
            double east  = boundsList[0].East;

            int    xSteps      = 0;
            int    ySteps      = 0;
            double chunkWidth  = 0.0f;
            double chunkHeight = 0.0f;
            MapBounds.calculateChunksize(
                ref north, ref south,
                ref west, ref east,
                ref xSteps, ref ySteps,
                ref chunkWidth, ref chunkHeight);
            Debug.Log("done.");

            // statistics and estimation
            int   gesamt  = ySteps * xSteps;
            float prozent = 1f / gesamt;

            this.progressBar = 0.0f;

            Debug.Log("\n* Retrieving and Parsing Chunks...\n");
            int counter = 0;

            double yPointer = north;
            for (int y = 0; y < ySteps; y++)
            {
                double xPointer = west;
                for (int x = 0; x < xSteps; x++)
                {
                    this.sourceType = OSMSourceType.Server;
                    this.FilePath   = this.serverURL +
                                      xPointer.ToString().Replace(",", ".") + "," +
                                      (yPointer - chunkHeight).ToString().Replace(",", ".") + "," +
                                      (xPointer + chunkWidth).ToString().Replace(",", ".") + "," +
                                      yPointer.ToString().Replace(",", ".");

                    Debug.Log("Chunk Bounds kontrolle: " + this.FilePath);
                    counter++;
                    //timer.NextLap();
                    //string estimatedTime = timer.formatTimeSpan(timer.estimateCompleteTime(counter, gesamt));

                    //progressBar = prozent * counter;
                    //lastMessage = "\t* Chunk " + counter + "/" + gesamt + " | " + (prozent * counter) + "% | estimated time left: " + estimatedTime.ToString();
                    //Debug.Log("\t* Chunk " + counter + "/" + gesamt + " | " + (prozent * counter) + "% | estimated time left: " + estimatedTime.ToString());
                    //Debug.Log("\t* map statistics: nodes=" + map.Nodes.Count + " ways=" + map.Ways.Count + " relations=" + map.Relations.Count);
                    //EditorUtility.DisplayProgressBar("OSM-Data", lastMessage, this.progressBar);

                    this.ParseOSM();
                    xPointer += chunkWidth;
                }
                yPointer -= chunkHeight;
            }

            Debug.Log("\r* Parsing completed...\n");
#if UNITY_EDITOR
            EditorUtility.DisplayProgressBar("OSM-Data", "Writing to XML-File... ", this.progressBar);
#endif
            //this.WriteXMLFile(@"e:\dennis\XML-Chunks\Unity-Test.osm");

            this.WriteXMLFile(tmpFile);
            Debug.Log("done " + tmpFile + ".\n\n");

            Debug.Log("\n* ");
        }
        else
        {
            Debug.Log("Datei bereits vorhanden: " + tmpFile);
            this.FilePath = tmpFile;
            this.ParseOSM();
        }

        timer.Stop();
        isRunning = false;
        finished  = true;
    }