Пример #1
0
        public IEnumerator GetElv(Latlong latlong, int zoom)
        {
            size = 32;
            size = zoom >= 18 ? 32 : (int)(Math.Pow(2.0, (18 - zoom)) * 32.0);
            int     tileX = size / 32;
            int     tileY = size / 32;
            Latlong RBLl  = HarvenSin.pixelToLatlong(new Vector2(512 * 16, 512 * 16), latlongLT, zoom);

            if (zoom >= 18)
            {
                string ElvURL = "http://dev.virtualearth.net/REST/v1/Elevation/Bounds?bounds=" + RBLl.lati + "," + latlongLT.longti + "," + latlongLT.lati + "," + RBLl.longti + "&rows=32&cols=32&heights=ellipsoid&key=" + bingKey;
                WWW    www    = new WWW(ElvURL);
                yield return(www);

                JsonData EData = JsonMapper.ToObject(www.text);
                zoomLevel = int.Parse(EData["resourceSets"][0]["resources"][0]["zoomLevel"].ToString());
                Debug.Log(EData["resourceSets"][0]["resources"][0]["zoomLevel"]);
                ElevaList.Clear();
                //Update ElevaList to WWW
                foreach (JsonData e in EData["resourceSets"][0]["resources"][0]["elevations"])
                {
                    float eF = float.Parse(e.ToString());
                    ElevaList.Add(eF);
                }
                www.Dispose();
            }
            else
            {
                Latlong LB       = new Latlong(RBLl.lati, latlongLT.longti);
                int     pixelDis = 8192 / tileX;
                WWW[]   www      = new WWW[tileX * tileY];
                ElevaList.Clear();
                for (int i = 0; i < tileX; ++i)
                {
                    for (int j = 0; j < tileY; ++j)
                    {
                        Latlong tileLB = HarvenSin.pixelToLatlong(new Vector2(pixelDis * j, pixelDis * -i), LB, zoom);
                        Latlong tileRT = HarvenSin.pixelToLatlong(new Vector2(pixelDis, -pixelDis), tileLB, zoom);
                        string  ElvURL = "http://dev.virtualearth.net/REST/v1/Elevation/Bounds?bounds=" + tileLB.lati + "," + tileLB.longti + "," + tileRT.lati + "," + tileRT.longti + "&rows=32&cols=32&heights=ellipsoid&key=" + bingKey;
                        //Debug.Log(ElvURL);
                        www[i * tileX + j] = new WWW(ElvURL);
                    }
                    for (int j = 0; j < tileY; ++j)
                    {
                        yield return(www[i * tileX + j]);

                        JsonData EData = JsonMapper.ToObject(www[i * tileX + j].text);
                        zoomLevel = int.Parse(EData["resourceSets"][0]["resources"][0]["zoomLevel"].ToString());
                        Debug.Log("elv" + i + " " + j);
                        //Update ElevaList to WWW
                        foreach (JsonData e in EData["resourceSets"][0]["resources"][0]["elevations"])
                        {
                            float eF = float.Parse(e.ToString());
                            ElevaList.Add(eF);
                        }
                        www[i * tileX + j].Dispose();
                    }
                }
            }
        }
Пример #2
0
        public IEnumerator GetDataFormUrl(string url)
        {
            //get ElevationData From WWW
            downloaded = false;
            WWW www = new WWW(url);

            yield return(www);

            ElevaList.Clear();
            JsonData EData = JsonMapper.ToObject(www.text);

            zoomLevel = int.Parse(EData["resourceSets"][0]["resources"][0]["zoomLevel"].ToString());
            Debug.Log(EData["resourceSets"][0]["resources"][0]["zoomLevel"]);
            //Update ElevaList to WWW
            foreach (JsonData e in EData["resourceSets"][0]["resources"][0]["elevations"])
            {
                float eF = float.Parse(e.ToString());
                ElevaList.Add(eF);
            }
            downloaded = true;
            www.Dispose();
        }