public IEnumerator ReloadMap(Coordinates location, bool delayed) { if (!dynamicLoad) { yield break; } //Get SmartTiles List <Vector2> tileList = location.adiacentNTiles(zoomLevel, tileBuffer); List <GOTile> newTiles = new List <GOTile> (); // Create new tiles foreach (Vector2 tileCoords in tileList) { if (!isSmartTileAlreadyCreated(tileCoords, zoomLevel)) { GOTile adiacentSmartTile = createSmartTileObject(tileCoords, zoomLevel); adiacentSmartTile.tileCenter = new Coordinates(tileCoords, zoomLevel); adiacentSmartTile.diagonalLenght = adiacentSmartTile.tileCenter.diagonalLenght(zoomLevel); adiacentSmartTile.gameObject.transform.position = adiacentSmartTile.tileCenter.convertCoordinateToVector(); newTiles.Add(adiacentSmartTile); if (tileBackground != null) { CreateTileBackground(adiacentSmartTile); } } } foreach (GOTile tile in newTiles) { if (OnTileLoad != null) { OnTileLoad.Invoke(tile); } #if !UNITY_WEBPLAYER // if (tile != null && FileHandler.Exist (tile.gameObject.name) && useCache) { if (Application.isPlaying) { yield return(tile.StartCoroutine(tile.LoadTileData(this, tile.tileCenter, zoomLevel, layers, delayed))); } else { GORoutine.start(tile.LoadTileData(this, tile.tileCenter, zoomLevel, layers, delayed), tile); } // } else { // tile.StartCoroutine(tile.LoadTileData(this, tile.tileCenter, zoomLevel,layers,delayed)); // } #endif } //Destroy far tiles List <Vector2> tileListForDestroy = location.adiacentNTiles(zoomLevel, tileBuffer + 1); yield return(StartCoroutine(DestroyTiles(tileListForDestroy))); }
public IEnumerator ReloadMap(Coordinates location, bool delayed) { if (!dynamicLoad) { yield break; } GOFeature.BuildingElevationOffset *= locationManager.worldScale; GOFeature.RoadsHeightForElevation *= locationManager.worldScale; //Get SmartTiles List <Vector2> tileList = location.adiacentNTiles(zoomLevel, tileBuffer); List <GOTile> newTiles = new List <GOTile> (); // Create new tiles foreach (Vector2 tileCoords in tileList) { if (!isSmartTileAlreadyCreated(tileCoords, zoomLevel)) { GOTile adiacentSmartTile = createSmartTileObject(tileCoords, zoomLevel); adiacentSmartTile.gameObject.transform.position = adiacentSmartTile.goTile.tileCenter.convertCoordinateToVector(); adiacentSmartTile.map = this; newTiles.Add(adiacentSmartTile); if (tileBackground != null) { adiacentSmartTile.createTileBackground(); } } } foreach (GOTile tile in newTiles) { if (Application.isPlaying) { yield return(tile.StartCoroutine(tile.LoadTileData(layers, delayed))); } else { GORoutine routine = GORoutine.start(tile.LoadTileData(layers, delayed), tile); while (!routine.finished) { yield return(null); } } } //Destroy far tiles List <Vector2> tileListForDestroy = location.adiacentNTiles(zoomLevel, tileBuffer + 1); if (destroyTilesRoutine != null) { yield return(destroyTilesRoutine); } destroyTilesRoutine = DestroyTiles(tileListForDestroy); yield return(StartCoroutine(destroyTilesRoutine)); }
public void OnFeatureLoad(GOFeature feature, GameObject featureObject) { if (feature.layer.layerType == GOLayer.GOLayerType.Buildings) { foreach (GOEnvironmentKind kind in buildings) { bool kindCondition = kind.kind == feature.kind; // if (kindCondition) { // if (Application.isPlaying) // StartCoroutine (SpawnBuildings (feature, featureObject, kind)); // else // GORoutine.start (SpawnBuildings (feature, featureObject, kind), this); // } } } else if (goMap.useElevation == true) { foreach (GOEnvironmentKind kind in featureEnvironment) { bool kindCondition = kind.kind == feature.kind; bool layerCondition = kind.layer == feature.layer.layerType && kind.kind == GOFeatureKind.baseKind; if (kindCondition || layerCondition) { if (Application.isPlaying) { StartCoroutine(SpawnPrefabsIn3DMesh(feature, featureObject, kind)); } else { GORoutine.start(SpawnPrefabsIn3DMesh(feature, featureObject, kind), this); } } } } else { foreach (GOEnvironmentKind kind in featureEnvironment) { bool kindCondition = kind.kind == feature.kind; bool layerCondition = kind.layer == feature.layer.layerType && kind.kind == GOFeatureKind.baseKind; if (kindCondition || layerCondition) { if (Application.isPlaying) { StartCoroutine(SpawnPrefabsInMesh(feature, featureObject, kind)); } else { GORoutine.start(SpawnPrefabsInMesh(feature, featureObject, kind), this); } } } } }
//This is called only in the editor mode. public void OnProcedureComplete(GOPbfProcedure procedure) { if (!Application.isPlaying) { foreach (GOParsedLayer p in procedure.list) { GORoutine.start(BuildLayer(p, false), this); } } }
public void Download(MonoBehaviour host, Action <byte[], string, string> action) { if (Application.isPlaying) { host.StartCoroutine(GOUrlRequest.getRequest(host, url, useCache, filename, action)); } else { GORoutine.start(GOUrlRequest.getRequest(host, url, useCache, filename, action), host); } }
public void Update() { if (Application.isPlaying || TileLoaded || !map) { return; } if (mapData != null) { TileLoaded = true; GORoutine.start(ParseTileData(map, tileCenter, map.locationManager.zoomLevel, map.layers, false, map.layerNames()), this); } }
public void BuildInsideEditor() { dynamicLoad = true; //This fixes the map origin locationManager.LoadDemoLocation(); //Wipe buildings id list buildingsIds = new List <object>(); //Start load routine (This might take some time...) IEnumerator routine = ReloadMap(locationManager.demo_CenterWorldCoordinates.tileCenter(locationManager.zoomLevel), false); GORoutine.start(routine, this); }
public static GORoutine start(IEnumerator _routine, MonoBehaviour owner) { if (Application.isEditor) { GORoutine coroutine = new GORoutine(_routine); coroutine.start(); return(coroutine); } else { owner.StartCoroutine(_routine); return(null); } }
public void OnTileLoad(GOTile tile) { foreach (GOEnvironmentKind kind in floatingEnvironment) { if (Application.isPlaying) { StartCoroutine(SpawnPrefabsInTile(tile, tile.gameObject, kind)); } else { GORoutine.start(SpawnPrefabsInTile(tile, tile.gameObject, kind), this); } } }
//This is called only in the editor mode. public void OnProcedureComplete(GOPbfProcedure procedure) { if (!Application.isPlaying) { if (goTile.useElevation) { MeshFilter filter = GetComponent <MeshFilter> (); filter.mesh = procedure.goTile.goMesh.ToMesh(); } foreach (GOParsedLayer p in procedure.list) { GORoutine.start(BuildLayer(p, false), this); } } }
public void OnFeatureLoad(GOFeature feature, GameObject featureObject) { if (goMap.useElevation == true) { foreach (GOEnvironmentKind kind in featureEnvironment) { bool kindCondition = kind.kind == feature.kind; bool layerCondition = kind.layer == feature.layer.layerType && kind.kind == GOFeatureKind.baseKind; if (kindCondition || layerCondition) { if (Application.isPlaying) { StartCoroutine(SpawnPrefabsIn3DMesh(feature, featureObject, kind)); } else { GORoutine.start(SpawnPrefabsIn3DMesh(feature, featureObject, kind), this); } } } } else { foreach (GOEnvironmentKind kind in featureEnvironment) { bool kindCondition = kind.kind == feature.kind || kind.kind == GOFeatureKind.baseKind; bool layerCondition = kind.layer == feature.layer.layerType; if (kindCondition && layerCondition) { //Debug.Log(kind.layer + " " + feature.layer.layerType); if (Application.isPlaying) { StartCoroutine(SpawnPrefabsInMesh(feature, featureObject, kind)); } else { GORoutine.start(SpawnPrefabsInMesh(feature, featureObject, kind), this); } } } } }
public IEnumerator LoadTileData(GOMap m, Coordinates tilecenter, int zoom, GOLayer[] layers, bool delayedLoad) { map = m; tileCoordinates = tileCenter.tileCoordinates(map.zoomLevel); if (Application.isPlaying) { yield return(StartCoroutine(DownloadData(m, tileCenter, zoom, layers, delayedLoad))); List <string> layerNames = map.layerNames(); yield return(StartCoroutine(ParseTileData(map, tileCenter, zoom, layers, delayedLoad, layerNames))); } else { GORoutine.start(DownloadData(m, tileCenter, zoom, layers, delayedLoad), this); } }
public void OnFeatureLoad(GOFeature feature, GameObject featureObject) { foreach (GOEnvironmentKind kind in featureEnvironment) { int spawn = 0; if (spawn == 0 && kind.kind == feature.kind) { if (Application.isPlaying) { StartCoroutine(SpawnPrefabsInMesh(feature, featureObject, kind)); } else { GORoutine.start(SpawnPrefabsInMesh(feature, featureObject, kind), this); } } } }
public void BuildInsideEditor() { dynamicLoad = true; //This fixes the map origin locationManager.LoadDemoLocation(); //Wipe buildings id list buildingsIds = new List <object> (); //Start load routine (This might take some time...) if (locationManager.demo_CenterWorldCoordinates == null) { Debug.LogWarning("[GOMap Editor] Warning, check if you have \"No GPS Test\" set on the Location Manager."); return; } IEnumerator routine = ReloadMap(locationManager.demo_CenterWorldCoordinates.tileCenter(locationManager.zoomLevel), false); GORoutine.start(routine, this); }
public IEnumerator LoadTileData(GOLayer[] layers, bool delayedLoad) { goTile.SetupAdiacentTiles(map.tiles); PrepareGoTile(); BuildFeaturePrototype(); if (map.useElevation) { AddTerrainToLayerMask("GOTerrain", gameObject); } // goTile.ShowDebugMarkers (); if (Application.isPlaying) { yield return(StartCoroutine(goTile.downloadData(this))); if (map.useSatelliteBackground) { MeshRenderer renderer = GetComponent <MeshRenderer> (); Material material = renderer.material; renderer.sharedMaterial = material; renderer.sharedMaterial.mainTexture = goTile.getSatelliteTexture(); } yield return(StartCoroutine(ParseTileData(layers, delayedLoad, map.layerNames()))); } else { goTile.downloadData(this, () => { if (map.useSatelliteBackground) { MeshRenderer renderer = GetComponent <MeshRenderer> (); Material material = Material.Instantiate(renderer.sharedMaterial); material.mainTexture = goTile.getSatelliteTexture(); renderer.sharedMaterial = material; } GORoutine.start(ParseTileData(layers, delayedLoad, map.layerNames()), this); }); } }
public void BuildMapPortionInsideEditor(Coordinates location, Coordinates origin) { dynamicLoad = true; //This fixes the map origin ((LocationManager)locationManager).SetOriginAndLocation(origin, location); //Wipe buildings id list buildingsIds = new List <object>(); tiles = new List <GOTile>(); containers = new List <GOCenterContainer>(); //Start load routine (This might take some time...) if (locationManager.worldOrigin == null) { Debug.LogWarning("[GOMap Editor] Warning, check if you have \"No GPS Test\" set on the Location Manager."); return; } IEnumerator routine = ReloadMap(location, true); GORoutine.start(routine, this); }
public override IEnumerator BuildTile(IDictionary mapData, GOLayer layer, bool delayedLoad) { GameObject parent = new GameObject(); parent.name = layer.name; parent.transform.parent = this.transform; parent.SetActive(!layer.startInactive); if (mapData == null) { Debug.LogWarning("Map Data is null!"); #if !UNITY_WEBPLAYER FileHandler.Remove(gameObject.name); #endif yield break; } IList features = (IList)mapData ["features"]; if (features == null) { yield break; } IList stack = new List <GOFeature> (); foreach (IDictionary geo in features) { IDictionary geometry = (IDictionary)geo ["geometry"]; IDictionary properties = (IDictionary)geo ["properties"]; string type = (string)geometry ["type"]; string kind = (string)properties ["kind"]; if (properties.Contains("kind_detail")) { kind = (string)properties ["kind_detail"]; } var id = properties ["id"]; if (idCheck(id, layer) == false && layer.layerType == GOLayer.GOLayerType.Buildings) { continue; } if (layer.useOnly.Length > 0 && !layer.useOnly.Contains(GOEnumUtils.MapzenToKind(kind))) { continue; } if (layer.avoid.Length > 0 && layer.avoid.Contains(GOEnumUtils.MapzenToKind(kind))) { continue; } if (type == "MultiLineString" || (type == "Polygon" && !layer.isPolygon)) { IList lines = new List <object>(); lines = (IList)geometry ["coordinates"]; foreach (IList coordinates in lines) { GOFeature gf = ParseFeatureData(properties, layer); gf.geometry = coordinates; // gf.type = type; gf.layer = layer; gf.parent = parent; gf.properties = properties; gf.ConvertGeometries(); gf.ConvertAttributes(); gf.index = (Int64)features.IndexOf(geo); gf.goFeatureType = GOFeatureType.MultiLine; stack.Add(gf); } } else if (type == "LineString") { IList coordinates = (IList)geometry ["coordinates"]; GOFeature gf = ParseFeatureData(properties, layer); gf.geometry = coordinates; // gf.type = type; gf.layer = layer; gf.parent = parent; gf.properties = properties; gf.ConvertGeometries(); gf.ConvertAttributes(); gf.index = (Int64)features.IndexOf(geo); gf.goFeatureType = GOFeatureType.Line; stack.Add(gf); } else if (type == "Polygon") { List <object> shapes = new List <object>(); shapes = (List <object>)geometry["coordinates"]; IList subject = null; List <object> clips = null; if (shapes.Count == 1) { subject = (List <object>)shapes[0]; } else if (shapes.Count > 1) { subject = (List <object>)shapes[0]; clips = shapes.GetRange(1, shapes.Count - 1); } else { continue; } GOFeature gf = ParseFeatureData(properties, layer); gf.geometry = subject; gf.clips = clips; // gf.type = type; gf.layer = layer; gf.parent = parent; gf.properties = properties; gf.ConvertGeometries(); gf.ConvertAttributes(); gf.index = (Int64)features.IndexOf(geo); gf.goFeatureType = GOFeatureType.Polygon; stack.Add(gf); } if (type == "MultiPolygon") { GameObject multi = new GameObject("MultiPolygon"); multi.transform.parent = parent.transform; IList shapes = new List <object>(); shapes = (IList)geometry["coordinates"]; foreach (List <object> polygon in shapes) { IList subject = null; List <object> clips = null; if (polygon.Count > 0) { subject = (List <object>)polygon[0]; } else if (polygon.Count > 1) { clips = polygon.GetRange(1, polygon.Count - 1); } else { continue; } GOFeature gf = ParseFeatureData(properties, layer); gf.geometry = subject; gf.clips = clips; // gf.type = type; gf.layer = layer; gf.parent = parent; gf.properties = properties; gf.ConvertGeometries(); gf.ConvertAttributes(); gf.index = (Int64)features.IndexOf(geo); gf.goFeatureType = GOFeatureType.MultiPolygon; stack.Add(gf); } } } // if (layer.layerType == GOLayer.GOLayerType.Roads) { // stack = GORoadFeature.MergeRoads (stack); // } // int n = 25; for (int i = 0; i < stack.Count; i += n) { for (int k = 0; k < n; k++) { if (i + k >= stack.Count) { yield return(null); break; } GOFeature r = (GOFeature)stack [i + k]; r.setRenderingOptions(); IEnumerator routine = r.BuildFeature(this, delayedLoad); if (routine != null) { if (Application.isPlaying) { StartCoroutine(routine); } else { GORoutine.start(routine, this); } } } yield return(null); } yield return(null); }
public IEnumerator BuildLayer(GOParsedLayer parsedLayer, bool delayedLoad) { GOLayer goLayer = parsedLayer.goLayer; Profiler.BeginSample("[GoMap] [BuildLayer] game object"); GameObject parent = null; parent = new GameObject(); parent.name = parsedLayer.name; parent.transform.parent = this.transform; if (parsedLayer.goLayer != null) { parent.SetActive(!goLayer.startInactive); } else { parent.SetActive(!map.pois.startInactive); } Profiler.EndSample(); int featureCount = parsedLayer.goFeatures.Count; if (featureCount == 0) { yield break; } IList iList = new List <GOFeature> (); for (int i = 0; i < featureCount; i++) { GOFeature goFeature = (GOFeature)parsedLayer.goFeatures [i]; if (goFeature.goFeatureType == GOFeatureType.Undefined || goFeature.goFeatureType == GOFeatureType.MultiPoint) { continue; } if (goFeature.goFeatureType == GOFeatureType.Point || goFeature.goFeatureType == GOFeatureType.Label) //POIS { goFeature.parent = parent; iList.Add(goFeature); continue; } if (goLayer.useOnly.Length > 0 && !goLayer.useOnly.Contains(goFeature.kind)) { continue; } if (goLayer.avoid.Length > 0 && goLayer.avoid.Contains(goFeature.kind)) { continue; } if (goLayer.layerType == GOLayer.GOLayerType.Roads) { if (goFeature.goFeatureType != GOFeatureType.Line && goFeature.goFeatureType != GOFeatureType.MultiLine) { continue; } GORoadFeature grf = (GORoadFeature)goFeature; if ((grf.isBridge && !goLayer.useBridges) || (grf.isTunnel && !goLayer.useTunnels) || (grf.isLink && !goLayer.useBridges)) { continue; } } goFeature.parent = parent; iList.Add(goFeature); } // Profiler.BeginSample("[GoMap] [BuildLayer] merge roads"); // if (goLayer.layerType == GOLayer.GOLayerType.Roads) { // iList = GORoadFeature.MergeRoads (iList); // } // Profiler.EndSample (); int n = 100; for (int i = 0; i < iList.Count; i += n) { for (int k = 0; k < n; k++) { if (i + k >= iList.Count) { // yield return null; break; } GOFeature r = (GOFeature)iList [i + k]; IEnumerator routine = r.BuildFeature(this, delayedLoad); if (routine != null) { if (Application.isPlaying) { StartCoroutine(routine); } else { GORoutine.start(routine, this); } } } // yield return null; } // // yield return null; }
public IEnumerator BuildLayer(VectorTileLayer layerData, GOLayer layer, bool delayedLoad) { Profiler.BeginSample("[GoMap] [BuildLayer] game object"); GameObject parent = null; if (transform.Find(layer.name) == null) { parent = new GameObject(); parent.name = layer.name; parent.transform.parent = this.transform; parent.SetActive(!layer.startInactive); } else { parent = transform.Find(layer.name).gameObject; } Profiler.EndSample(); int featureCount = layerData.FeatureCount(); if (featureCount == 0) { yield break; } List <GOFeature> stack = new List <GOFeature> (); //Caching variables.. VectorTileFeature feature; List <List <LatLng> > geomWgs84; //= new List<List<LatLng>>(); GOFeature goFeature; Dictionary <string, object> properties = null; List <KeyValue> attributes = null; List <Vector3> convertedGeometry = null; for (int i = 0; i < featureCount; i++) { feature = layerData.GetFeature(i); properties = feature.GetProperties(); geomWgs84 = feature.GeometryAsWgs84((ulong)map.zoomLevel, (ulong)tileCoordinates.x, (ulong)tileCoordinates.y, 0); attributes = GOFeature.PropertiesToAttributes(properties); if (geomWgs84.Count > 0) { convertedGeometry = GOFeature.CoordsToVerts(geomWgs84[0], false); } //get the feature (here is the actual protobuf conversion) goFeature = ParseFeatureData(feature, properties, layer, -1, -1); //8-11mb if (layer.useOnly.Length > 0 && !layer.useOnly.Contains(goFeature.kind)) { continue; } if (layer.avoid.Length > 0 && layer.avoid.Contains(goFeature.kind)) { continue; } if (layer.layerType == GOLayer.GOLayerType.Roads) { GORoadFeature grf = (GORoadFeature)goFeature; if ((grf.isBridge && !layer.useBridges) || (grf.isTunnel && !layer.useTunnels) || (grf.isLink && !layer.useBridges)) { continue; } } GOFeatureType gotype = feature.GOFeatureType(geomWgs84); if (gotype == GOFeatureType.Undefined || feature.GeometryType == GeomType.POINT) { continue; } if (feature.GeometryType == GeomType.POLYGON && layer.layerType == GOLayer.GOLayerType.Roads) { continue; } Int64 index = vt.LayerNames().IndexOf(layerData.Name) + 1; GOFeature gf; Profiler.BeginSample("[GoMap] [BuildLayer] IF"); if (gotype == GOFeatureType.MultiLine || (gotype == GOFeatureType.Polygon && !layer.isPolygon)) { Profiler.BeginSample("[GoMap] [BuildLayer] multi line"); foreach (IList geometry in geomWgs84) { float indexMulti = ((float)geomWgs84.IndexOf((List <LatLng>)geometry) / geomWgs84.Count); gf = ParseFeatureData(feature, properties, layer, Convert.ToInt64(i) + indexMulti, index); gf.geometry = geometry; gf.layer = layer; gf.parent = parent; gf.properties = properties; gf.ConvertGeometries(); gf.attributes = attributes; gf.goFeatureType = GOFeatureType.MultiLine; stack.Add(gf); } Profiler.EndSample(); } else if (gotype == GOFeatureType.Line) { Profiler.BeginSample("[GoMap] [BuildLayer] line"); gf = ParseFeatureData(feature, properties, layer, Convert.ToInt64(i), index); gf.geometry = geomWgs84 [0]; gf.layer = layer; gf.parent = parent; gf.properties = properties; gf.convertedGeometry = convertedGeometry; gf.attributes = attributes; gf.index = (Int64)i + vt.LayerNames().IndexOf(layerData.Name); gf.goFeatureType = GOFeatureType.Line; if (geomWgs84.Count == 0) { continue; } stack.Add(gf); Profiler.EndSample(); } else if (gotype == GOFeatureType.Polygon) { Profiler.BeginSample("[GoMap] [BuildLayer] polygon"); gf = ParseFeatureData(feature, properties, layer, Convert.ToInt64(i), index); gf.geometry = geomWgs84 [0]; gf.layer = layer; gf.parent = parent; gf.properties = properties; gf.convertedGeometry = convertedGeometry; gf.attributes = attributes; gf.index = (Int64)i + vt.LayerNames().IndexOf(layerData.Name); gf.goFeatureType = GOFeatureType.Polygon; stack.Add(gf); Profiler.EndSample(); } else if (gotype == GOFeatureType.MultiPolygon) { Profiler.BeginSample("[GoMap] [BuildLayer] multi polygon"); // GameObject multi = new GameObject ("MultiPolygon"); // multi.transform.parent = parent.transform; IList subject = null; IList clips = new List <List <LatLng> >(); for (int j = 0; j < geomWgs84.Count; j++) //Clip ascending { IList p = geomWgs84 [j]; if (GOFeature.IsGeoPolygonClockwise(p)) { subject = p; } else { //Add clip clips.Add(p); } //Last one if (j == geomWgs84.Count - 1 || (j < geomWgs84.Count - 1 && GOFeature.IsGeoPolygonClockwise(geomWgs84 [j + 1]) && subject != null)) { gf = ParseFeatureData(feature, properties, layer, Convert.ToInt64(i), index); gf.geometry = subject; gf.clips = clips; gf.layer = layer; gf.parent = parent; gf.properties = properties; gf.ConvertGeometries(); gf.attributes = attributes; gf.index = (Int64)i + vt.LayerNames().IndexOf(layerData.Name); gf.goFeatureType = GOFeatureType.MultiPolygon; stack.Add(gf); subject = null; clips = new List <List <LatLng> >(); } } Profiler.EndSample(); } Profiler.EndSample(); } Profiler.BeginSample("[GoMap] [BuildLayer] merge roads"); IList iStack = (IList)stack; if (layer.layerType == GOLayer.GOLayerType.Roads) { iStack = GORoadFeature.MergeRoads(iStack); // Debug.Log ("Roads: "+stack.Count+" Merged: "+iStack.Count); } Profiler.EndSample(); int n = 25; for (int i = 0; i < iStack.Count; i += n) { for (int k = 0; k < n; k++) { if (i + k >= iStack.Count) { yield return(null); break; } GOFeature r = (GOFeature)iStack [i + k]; IEnumerator routine = r.BuildFeature(this, delayedLoad); if (routine != null) { if (Application.isPlaying) { StartCoroutine(routine); } else { GORoutine.start(routine, this); } } } yield return(null); } Resources.UnloadUnusedAssets(); yield return(null); }
public IEnumerator LoadTileData(object m, Coordinates tilecenter, int zoom, Layer[] layers, bool delayedLoad) { #if !UNITY_WEBPLAYER map = (GOMap)m; Vector2 realPos = tileCenter.tileCoordinates(zoom); var tileurl = realPos.x + "/" + realPos.y; var baseUrl = "https://tile.mapzen.com/mapzen/vector/v1/"; // var baseUrl = "https://vector.mapzen.com/osm/"; oldapi List <string> layerNames = new List <string>(); for (int i = 0; i < layers.ToList().Count; i++) { if (layers[i].disabled == false) { layerNames.Add(layers[i].json); } } layerNames.RemoveAll(str => String.IsNullOrEmpty(str)); // var url = baseUrl + string.Join(",",layerNames.ToArray())+"/"+zoom+"/"; var url = baseUrl + "all/" + zoom + "/"; var completeurl = url + tileurl + ".json"; if (map.mapzen_api_key != null && map.mapzen_api_key != "") { completeurl = completeurl + "?api_key=" + map.mapzen_api_key; } if (Application.isPlaying) //Runtime build { if (map.useCache && FileHandler.Exist(gameObject.name)) { yield return(StartCoroutine(ParseJson(FileHandler.LoadText(gameObject.name)))); } else { Debug.Log(completeurl); var www = new WWW(completeurl); yield return(www); if (www.error == null && www.text.Length > 0) { FileHandler.SaveText(gameObject.name, www.text); } else if (www.error != null && (www.error.Contains("429") || www.error.Contains("timed out"))) { Debug.LogWarning("Tile data reload " + www.error); yield return(new WaitForSeconds(1)); yield return(StartCoroutine(LoadTileData(map, tilecenter, zoom, layers, delayedLoad))); yield break; } else { Debug.LogWarning("Tile data missing " + www.error); ((GOMap)m).tiles.Remove(this); GameObject.Destroy(this.gameObject); yield break; } yield return(StartCoroutine(ParseJson(www.text))); } mapData = job.OutData; yield return(StartCoroutine(ParseTileData(map, tileCenter, zoom, layers, delayedLoad, layerNames))); } else //Editor build { if (map.useCache && FileHandler.Exist(gameObject.name)) { mapData = Json.Deserialize(FileHandler.LoadText(gameObject.name)); GORoutine.start(ParseTileData(map, tileCenter, zoom, layers, delayedLoad, layerNames), this); } else { #if UNITY_EDITOR WWW www = new WWW(completeurl); ContinuationManager.Add(() => www.isDone, () => { if (!string.IsNullOrEmpty(www.error)) { Debug.LogWarning("Tile data missing " + www.error); System.Threading.Thread.Sleep(1000); GORoutine.start(LoadTileData(map, tilecenter, zoom, layers, delayedLoad), this); } else if (this != null) { FileHandler.SaveText(gameObject.name, www.text); mapData = Json.Deserialize(FileHandler.LoadText(gameObject.name)); GORoutine.start(ParseTileData(map, tileCenter, zoom, layers, delayedLoad, layerNames), this); } }); #endif yield break; } } #else yield return(null); #endif }