using UnityEngine; using System.Collections; using System.Threading; using System.IO; using System.Runtime.Serialization.Formatters.Binary; using System.Xml; using System.Globalization; public class OnlineMapManager : MonoBehaviour { private OnlineMapsTileSetControl control; private OnlineMapsWWW elevationRequest = null; private OnlineMaps map; IEnumerator Start () { // Get Tileset control. control = OnlineMapsControlBase.instance as OnlineMapsTileSetControl; map = OnlineMaps.instance; if (control == null) { Debug.LogError("You must use the Tileset control."); yield return null; } // Intercept elevation request control.OnGetElevation += OnGetElevation; } private void OnGetElevation(Vector2 topLeftCoords, Vector2 bottomRightCoords) { //Debug.Log ("topLeftCoords.x = " + topLeftCoords.x + "\ttopLeftCoords.y = " + topLeftCoords.y); //Debug.Log ("bottomRightCoords.x = " + bottomRightCoords.x + "\tbottomRightCoords.y = " + bottomRightCoords.y + "\n"); double north = 0; double south = 0; double west = 0; double east = 0; north = topLeftCoords.y; south = bottomRightCoords.y; west = topLeftCoords.x; east = bottomRightCoords.x; // Elevation map must be 32x32 short[,] elevation = new short[32, 32]; string url = string.Format(CultureInfo.InvariantCulture, "http://gis.eltel.co.il:8080/geoserver/WorldDEM/wms?service=WMS&version=1.1.0&request=GetMap&layers=WorldDEM:Wold_DEM&styles=&bbox={0},{1},{2},{3}&width=768&height=384&srs=EPSG:4326&format=application/openlayers", west, south, east, north ); //Debug.Log ("west = " + west + "\tsouth = " + south + "\teast = " + east + "\tnorth = " + north); elevationRequest = OnlineMapsUtils.GetWWW(url); lab1:; if(elevationRequest.isDone==false) { goto lab1; } if (elevationRequest.isDone == true) { byte[] bytes = elevationRequest.bytes; int n = 0; using (MemoryStream ms = new MemoryStream(bytes)) { BinaryReader reader = new BinaryReader(ms); for (int y = 0; y < 32; y++) { for (int x = 0; x < 32; x++) { elevation[x, y] =(short)(reader.ReadInt32()); //Debug.Log ("y = " + y + "\tx = " + x + "\t elevation[x, y] = " + elevation[x, y]); n++; } } } } // Set elevation map control.SetElevationData(elevation); } }