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(); } } } }
public IEnumerator CreateTerrainZoom(int zoom) { Terrain t1 = GetComponent <Terrain>(); t1.basemapDistance = 10000; Latlong RBLl = HarvenSin.pixelToLatlong(new Vector2(512 * 16, 512 * 16), latlongLT, zoom); ElevationData evData = new ElevationData(); //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; //yield return StartCoroutine(evData.GetDataFormUrl(ElvURL)); yield return(StartCoroutine(evData.GetElv(latlongLT, zoom))); float[,] heightmap = evData.GetHeightMap(); //float[,] heightmap = evData.GetHeightMap(32, 32); t1.terrainData.heightmapResolution = evData.size; t1.terrainData.SetHeights(0, 0, heightmap); //yield return StartCoroutine(GetImageFormTile(latlongLT,16,16,19)); yield return(StartCoroutine(ImageDataP.GetImageFormUrl(latlongLT, 16, 16, zoom))); SplatPrototype[] sp = new SplatPrototype[1]; t1.terrainData.size = new Vector3((float)HarvenSin.Distance(latlongLT.lati, latlongLT.longti, latlongLT.lati, RBLl.longti) * 1000, 10000f, (float)HarvenSin.Distance(RBLl.lati, latlongLT.longti, latlongLT.lati, latlongLT.longti) * 1000f); sp[0] = CreateSplatPrototype(imageCombined, new Vector2(t1.terrainData.size.x, t1.terrainData.size.z), new Vector2(0f, 0f)); File.WriteAllBytes("Assets/TerrainTexture/test.jpg", imageCombined.EncodeToJPG());//output Texture t1.terrainData.splatPrototypes = sp; }
public static IEnumerator GetImageFormUrl(Latlong latlong, int tilex, int tiley, double zoom) { Mappixel startMapP = HarvenSin.latlongToPixel(latlong, zoom); startMapP.x += 256; startMapP.y += 256; Texture2D Img = new Texture2D(tilex * 512, tiley * 512); WWW[] www = new WWW[16 * 16]; for (int i = 0; i < tilex; ++i) { for (int j = 0; j < tiley; ++j) { Mappixel mpTmp = new Mappixel(startMapP.x + 512 * i, startMapP.y + 512 * j); Latlong ll = HarvenSin.pixelToLatlong(mpTmp, zoom); string url = "http://dev.virtualearth.net/REST/v1/Imagery/Map/Aerial/" + ll.lati + "," + ll.longti + "/" + zoom + "?&mapSize=512,544&key=" + bingKey; //string url = "http://dev.virtualearth.net/REST/v1/Imagery/Map/Road/47.619048,-122.35384/15?mapSize=500,500&pp=47.620495,-122.34931;21;AA&pp=47.619385,-122.351485;;AB&pp=47.616295,-122.3556;22&key=BingMapsKey"+bingKey; //Debug.Log(url); www[i * 16 + j] = new WWW(url); } for (int j = 0; j < 16; j++) { yield return(www[i * 16 + j]); Color[] color = www[i * 16 + j].texture.GetPixels(0, 16, 512, 512); Img.SetPixels(i * 512, 512 * (tiley - 1 - j), 512, 512, color); www[i * 16 + j].Dispose(); Debug.Log(i + " " + j); } } Img.Apply(); imageCombined = Img; }