using UnityEngine; public class TestESRIElevations : MonoBehaviour { private OnlineMapsWWW www; private void Start () { OnlineMapsTileSetControl.instance.OnGetElevation += OnGetElevation; } private void OnGetElevation(Vector2 topLeft, Vector2 bottomRight) { www = OnlineMapsUtils.GetWWW("http://sampleserver4.arcgisonline.com/ArcGIS/rest/services/Elevation/ESRI_Elevation_World/MapServer/exts/ElevationsSOE/ElevationLayers/1/GetElevationData?f=json&Extent={%22spatialReference%22:{%22wkid%22:4326},%22ymin%22:" + bottomRight.y + ",%22ymax%22:" + topLeft.y + ",%22xmin%22:" + topLeft.x + ",%22xmax%22:" + bottomRight.x + "}&Rows=32&Columns=32"); } private void Update() { if (www != null && www.isDone) { if (!string.IsNullOrEmpty(www.error)) { Debug.Log(www.error); www = null; return; } string r = www.text; www = null; int dataIndex = r.IndexOf("\"data\":["); if (dataIndex == -1) { Debug.Log("Something wrong"); Debug.Log(r); return; } dataIndex += 8; short[,] elevationData = new short[32, 32]; int index = 0; int v = 0; bool isNegative = false; for (int i = dataIndex; i < r.Length; i++) { char c = r[i]; if (c == ',') { int x = index % 32; int y = 31 - index / 32; if (isNegative) v = -v; elevationData[x, y] = (short) v; v = 0; isNegative = false; index++; } else if (c == '-') isNegative = true; else if (c > 47 && c < 58) v = v * 10 + (c - 48); else break; } OnlineMapsTileSetControl.instance.SetElevationData(elevationData); } } }