IEnumerator DownloadOSMCo()
        {
            CreateFolders();

            string url = Paths.GetPath(ePATHSPEC.OSMURL);
            //DRect r = MapTools.TileLatLonBounds(new DVector3(TileX, 0, TileZ), ZoomLevel);
            DRect r = MapTools.TileIdToBounds(TileX, TileZ, ZoomLevel);

            url = url.Replace("{x2}", r.Min.z.ToString());
            url = url.Replace("{y2}", r.Min.x.ToString());
            url = url.Replace("{x1}", r.Max.z.ToString());
            url = url.Replace("{y1}", r.Max.x.ToString());

            WWW www = new WWW(url);

            progress = 0;
            Debug.Log(url);
            while (!www.isDone)
            {
                //progress = www.progress;
                progress++;
                this.Repaint();
                yield return(new WaitForSeconds(0.01f));
            }
            progress = 0;
            File.WriteAllText(Paths.GetPath(ePATHSPEC.OSMPath), www.text);
            AssetDatabase.Refresh();
            Done--;
        }
Example #2
0
        //x,y,z tile index for the zoom level, same as mapzen or bing maps id
        public void SetTileIndex(Vector3 pos, int Zoom)
        {
            ZoomLevel = Zoom;
            TileIndex = DVector3.FromVector3(pos);
            //DRect r = MapFuncs.TileBoundsInMeters(new DVector3(pos.x, 0, pos.z), Zoom);
            //DVector3 c = MapFuncs.TileIdToCenterLatitudeLongitude((int)pos.x, (int)pos.z, Zoom);
            DRect    latlonbounds = MapTools.TileIdToBounds((int)pos.x, (int)pos.z, Zoom);
            DVector3 c            = latlonbounds.Max;

            PositionMeters = MapTools.LatLonToMeters(c.x, c.z);

            TileBoundsMeters = new DRect(MapTools.LatLonToMeters(latlonbounds.Min.x, latlonbounds.Min.z),
                                         MapTools.LatLonToMeters(latlonbounds.Max.x, latlonbounds.Max.z));
            Info = TileBoundsMeters.ToString();
        }
        IEnumerator GetGeoInfoCo()
        {
            CreateFolders();
            string FullURL  = Paths.GetPath(ePATHSPEC.GEOINFOURL);
            DRect  worldpos = MapTools.TileIdToBounds(TileX, TileZ, ZoomLevel);

            FullURL = FullURL.Replace("{e}", worldpos.Min.z.ToString());
            FullURL = FullURL.Replace("{n}", worldpos.Min.x.ToString());

            FullURL = FullURL.Replace("{w}", worldpos.Max.z.ToString());
            FullURL = FullURL.Replace("{s}", worldpos.Max.x.ToString());
            string outpath = Paths.GetPath(ePATHSPEC.GEOINFOPATH);

            string data = "";

            if (File.Exists(outpath))
            {
                Debug.Log("Cache Hit: " + outpath);
                data = File.ReadAllText(outpath);
            }
            else
            {
                Debug.Log(FullURL);
                WWW www = new WWW(FullURL);

                while (!www.isDone)
                {
                    progress = www.progress;
                    this.Repaint();
                    yield return(new WaitForSeconds(0.01f));
                }
                progress = 1;
                this.Repaint();

                if (string.IsNullOrEmpty(www.error))
                {
                    data = www.text;
                    File.WriteAllText(outpath, data);
                    AssetDatabase.Refresh();
                }
                else
                {
                    Debug.LogError(www.error);
                }
            }
            Done--;
        }