public override GOFeature ParseFeatureData(VectorTileFeature feature, GOLayer layer) { IDictionary properties = feature.GetProperties(); GOFeature goFeature; if (layer.layerType == GOLayer.GOLayerType.Roads) { goFeature = new GORoadFeature(); } else { goFeature = new GOFeature(); } goFeature.kind = GOEnumUtils.MapboxToKind(layer.name); goFeature.y = layer.defaultLayerY(); if (properties.Contains("_symbol")) { goFeature.y = Convert.ToInt64(properties ["_symbol"]) / 10.0f * Global.tilesizeRank; } goFeature.height = layer.defaultRendering.polygonHeight; return(goFeature); }
public void BuildLine(GameObject line, GOLayer layer, GORenderingOptions renderingOptions, GOMap map) { if (feature.convertedGeometry.Count == 2 && feature.convertedGeometry[0].Equals(feature.convertedGeometry[1])) { return; } if (renderingOptions.tag.Length > 0) { line.tag = renderingOptions.tag; } if (renderingOptions.material) { renderingOptions.material.renderQueue = -(int)feature.sort; } if (renderingOptions.outlineMaterial) { renderingOptions.outlineMaterial.renderQueue = -(int)feature.sort; } GOLineMesh lineMesh = new GOLineMesh(feature.convertedGeometry); lineMesh.width = renderingOptions.lineWidth * Global.tilesizeRank; lineMesh.load(line); mesh = lineMesh.mesh; mesh = SimpleExtruder.Extrude(mesh, line, 0.05f); line.GetComponent <MeshFilter>().sharedMesh = mesh; line.GetComponent <Renderer>().material = renderingOptions.material; Vector3 position = line.transform.position; position.y = feature.y * Global.tilesizeRank; line.transform.position = position; if (renderingOptions.outlineMaterial != null) { GameObject outline = CreateRoadOutline(line, renderingOptions.outlineMaterial, Global.tilesizeRank * (renderingOptions.lineWidth + layer.defaultRendering.outlineWidth)); if (layer.useColliders) { outline.AddComponent <MeshCollider>().sharedMesh = outline.GetComponent <MeshFilter>().sharedMesh; } outline.layer = line.layer; outline.tag = line.tag; } else if (layer.useColliders) { // Mesh m = gameObject.GetComponent<MeshFilter> ().sharedMesh; line.AddComponent <MeshCollider>(); } }
public void AddBoats(Mesh mesh, GOLayer layer, GOFeatureKind kind, Vector3 center) { bool spawn = Random.value > 0.5f; if (kind != GOFeatureKind.riverbank && kind != GOFeatureKind.water && spawn) { var randomRotation = Quaternion.Euler(0, Random.Range(0, 360), 0); center.y = 2; GameObject obj = (GameObject)Instantiate(boatPrefab, center, randomRotation); obj.transform.parent = transform; } }
public bool idCheck(object id, GOLayer layer) { if (map.buildingsIds.Contains(id)) { return(false); } else { buildingsIds.Add(id); map.buildingsIds.Add(id); return(true); } }
public void AddObjectToLayerMask(GOLayer layer, GameObject obj) { LayerMask mask = LayerMask.NameToLayer(layer.name); if (mask.value > 0 && mask.value < 31) { obj.layer = LayerMask.NameToLayer(layer.name); } else { Debug.LogWarning("[GOMap] Please create layer masks before running GoMap. A layer mask must have the same name declared in GoMap inspector, for example \"" + layer.name + "\"."); } }
public static void AddMap() { GameObject locationManager = CreateGameObjectInScene("Location Manager"); CenterOnScreen(locationManager, 0); GameObject newMap = CreateGameObjectInScene("Map"); CenterOnScreen(newMap, 0); GOMap map = newMap.AddComponent <GOMap> (); map.locationManager = locationManager.AddComponent <LocationManager>(); GOLayer buildings = new GOLayer(); buildings.layerType = GOLayer.GOLayerType.Buildings; buildings.isPolygon = true; buildings.defaultRendering = new GORenderingOptions(); buildings.defaultRendering.polygonHeight = 2; buildings.defaultRendering.material = CreateMaterialWithColor(Color.white); GOLayer water = new GOLayer(); buildings.layerType = GOLayer.GOLayerType.Water; water.isPolygon = true; water.defaultRendering = new GORenderingOptions(); water.defaultRendering.polygonHeight = 0; water.defaultRendering.material = CreateMaterialWithColor(Color.blue); GOLayer landuse = new GOLayer(); buildings.layerType = GOLayer.GOLayerType.Landuse; landuse.isPolygon = true; landuse.defaultRendering = new GORenderingOptions(); landuse.defaultRendering.polygonHeight = 0; landuse.defaultRendering.material = CreateMaterialWithColor(Color.green); GOLayer roads = new GOLayer(); buildings.layerType = GOLayer.GOLayerType.Landuse; roads.isPolygon = false; roads.defaultRendering = new GORenderingOptions(); roads.defaultRendering.lineWidth = 2; roads.defaultRendering.material = CreateMaterialWithColor(Color.gray); map.layers = new GOLayer[] { buildings, water, landuse, roads }; Camera.main.transform.position = new Vector3(0, 600, 100); Camera.main.transform.eulerAngles = new Vector3(70, 180, 0); }
public override GOFeature ParseFeatureData(VectorTileFeature feature, GOLayer layer) { IDictionary properties = feature.GetProperties(); GOFeature goFeature; if (layer.layerType == GOLayer.GOLayerType.Roads) { goFeature = new GORoadFeature(); ((GORoadFeature)goFeature).isBridge = properties.Contains("brunnel") && (string)properties ["brunnel"] == "bridge"; ((GORoadFeature)goFeature).isTunnel = properties.Contains("brunnel") && (string)properties ["brunnel"] == "tunnel"; ((GORoadFeature)goFeature).isLink = properties.Contains("brunnel") && (string)properties ["brunnel"] == "link"; } else { goFeature = new GOFeature(); } goFeature.kind = GOEnumUtils.MapboxToKind((string)properties["class"]); goFeature.y = goFeature.index / 1000 + layer.defaultLayerY(); if (goFeature.kind == GOFeatureKind.lake) //terrible fix for vector maps without a sort value. { goFeature.y = layer.defaultLayerY(GOLayer.GOLayerType.Landuse); } goFeature.height = layer.defaultRendering.polygonHeight; if (layer.useRealHeight && properties.Contains("render_height")) { double h = Convert.ToDouble(properties["render_height"]); goFeature.height = (float)h; } if (layer.useRealHeight && properties.Contains("render_min_height")) { double hm = Convert.ToDouble(properties["render_min_height"]); goFeature.y = (float)hm; if (goFeature.height >= hm) { goFeature.y = (float)hm; goFeature.height = (float)goFeature.height - (float)hm; } } return(goFeature); }
public void GrowTrees(Mesh mesh, GOLayer layer, GOFeatureKind kind, Vector3 center) { //return ; // || kind == GOFeatureKind.recreation_ground | kind == GOFeatureKind.attraction || kind == GOFeatureKind.grass if (kind == GOFeatureKind.parking || kind == GOFeatureKind.park || kind == GOFeatureKind.garden || kind == GOFeatureKind.recreation_ground | kind == GOFeatureKind.attraction) { List <Vector3> treePoslist = new List <Vector3>(); Vector3[] mv = mesh.vertices; if (mv.Length > 0) { for (int i = 0; i < mv.Length - 1; i++) { float d = Vector3.Distance(mv[i], mv[i + 1]); if (d > treeDistance) { for (int j = 0; j < (int)(d / treeDistance); j++) { //Debug.Log(j/(d / treeDistance)); treePoslist.Add(Vector3.Lerp(mv[i], mv[i + 1], j / (d / treeDistance))); } } } for (int i = 0; i < treePoslist.Count; i++) { var item = treePoslist[i]; var randomRotation = Quaternion.Euler(0, Random.Range(0, 360), 0); int n = Random.Range(0, treePrefab.Length); var p = new Vector3(item.x, treePrefab[n].transform.position.y * Global.tilesizeRank, item.z); center.y = treePrefab[n].transform.position.y * Global.tilesizeRank; p = Vector3.Lerp(p, center, Random.Range(0.2f, 0.8f)); GameObject obj = (GameObject)Instantiate(treePrefab[n], p, randomRotation); obj.transform.localScale = new Vector3(Global.tilesizeRank, Global.tilesizeRank, Global.tilesizeRank); obj.transform.parent = transform; obj.name = "tree" + i; } } } }
public override string GetLayersStrings(GOLayer layer) { return(layer.lyr_osm()); }
public abstract string GetLayersStrings(GOLayer layer);
public GameObject BuildPolygon(string name, GOLayer layer, float height) { //GameObject polygon = GameObject.Instantiate((GameObject)Resources.Load("Prefabs/CityBuildings/" + "Building_CornerHouse_A")); GameObject polygon = new GameObject(); Poly2Mesh.Polygon poly = new Poly2Mesh.Polygon(); poly.outside = feature.convertedGeometry; if (feature.clips != null) { foreach (IList clipVerts in feature.clips) { poly.holes.Add(GOFeature.CoordsToVerts(clipVerts)); } } MeshFilter filter = polygon.AddComponent <MeshFilter>(); polygon.AddComponent(typeof(MeshRenderer)); try { mesh = Poly2Mesh.CreateMesh(poly); } catch { } if (height > 1) { if (mesh) { Vector2[] uv2d = new Vector2[mesh.vertices.Length]; for (int i = 0; i < uv2d.Length; i++) { uv2d[i] = new Vector2(mesh.vertices[i].x, mesh.vertices[i].z); } var meshlemp = Mesh.Instantiate(mesh); meshlemp.uv = uv2d; mesh2D = Mesh.Instantiate(meshlemp); mesh.uv = uv2d; if (height > 0) { mesh = SimpleExtruder.Extrude(mesh, polygon, height); Vector2[] uvs3D = new Vector2[mesh.vertices.Length]; for (int i = 0; i < uvs3D.Length - 1; i++) { uvs3D[i] = new Vector2(Vector2.Distance(new Vector2(mesh.vertices[i + 1].x, mesh.vertices[i + 1].z), new Vector2(mesh.vertices[i].x, mesh.vertices[i].z)), mesh.vertices[i].y); } // uvs2[uvs2.Length - 1] = new Vector2(Mathf.Sqrt((float)(Math.Pow(mesh.vertices[0].x - mesh.vertices[uvs2.Length - 1].x, 2) + Math.Pow(mesh.vertices[0].z - mesh.vertices[uvs2.Length - 1].z, 2))), mesh.vertices[uvs2.Length - 1].y); uvs3D[uvs3D.Length - 1] = new Vector2(10, mesh.vertices[uvs3D.Length - 1].y); mesh.uv = uvs3D; } } } else { if (mesh) { Vector2[] uvs = new Vector2[mesh.vertices.Length]; for (int i = 0; i < uvs.Length; i++) { uvs[i] = new Vector2(mesh.vertices[i].x, mesh.vertices[i].z); } mesh.uv = uvs; if (height > 0) { mesh = SimpleExtruder.Extrude(mesh, polygon, height); } } } filter.sharedMesh = mesh; if (layer.useColliders) { polygon.AddComponent <MeshCollider>().sharedMesh = mesh; } return(polygon); }
public override string GetLayersStrings(GOLayer layer) { return(layer.json()); }
public IEnumerator BuildLayer(VectorTileLayer layerData, GOLayer layer, bool delayedLoad) { GameObject parent = null; if (transform.FindChild(layer.name) == null) { parent = new GameObject(); parent.name = layer.name; parent.transform.parent = this.transform; parent.SetActive(!layer.startInactive); } else { parent = transform.FindChild(layer.name).gameObject; } if (layerData.FeatureCount() == 0) { yield break; } List <GOFeature> stack = new List <GOFeature> (); for (int i = 0; i < layerData.FeatureCount(); i++) { //get the feature VectorTileFeature feature = layerData.GetFeature(i); GOFeature goFeature = ParseFeatureData(feature, layer); 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; } } //multipart List <List <LatLng> > geomWgs84 = feature.GeometryAsWgs84((ulong)map.zoomLevel, (ulong)tileCoordinates.x, (ulong)tileCoordinates.y, 0); string type = feature.GetFeatureType(geomWgs84); if (type == null || feature.GeometryType == GeomType.POINT) { continue; } if (feature.GeometryType == GeomType.POLYGON && layer.layerType == GOLayer.GOLayerType.Roads) { continue; } if (type == "MultiLineString" || (type == "Polygon" && !layer.isPolygon)) { foreach (IList geometry in geomWgs84) { GOFeature gf = ParseFeatureData(feature, layer); gf.geometry = geometry; gf.type = type; gf.layer = layer; gf.parent = parent; gf.properties = feature.GetProperties(); gf.ConvertGeometries(); gf.ConvertAttributes(); gf.index = (Int64)i; gf.goFeatureType = GOFeature.GOFeatureType.MultiLine; stack.Add(gf); } } else if (type == "LineString") { GOFeature gf = ParseFeatureData(feature, layer); gf.geometry = geomWgs84 [0]; gf.type = type; gf.layer = layer; gf.parent = parent; gf.properties = feature.GetProperties(); gf.ConvertGeometries(); gf.ConvertAttributes(); gf.index = (Int64)i; gf.goFeatureType = GOFeature.GOFeatureType.Line; if (geomWgs84.Count == 0) { continue; } stack.Add(gf); } else if (type == "Polygon") { GOFeature gf = ParseFeatureData(feature, layer); gf.geometry = geomWgs84 [0]; gf.type = type; gf.layer = layer; gf.parent = parent; gf.properties = feature.GetProperties(); gf.ConvertGeometries(); gf.ConvertAttributes(); gf.index = (Int64)i; gf.goFeatureType = GOFeature.GOFeatureType.Polygon; stack.Add(gf); } else if (type == "MultiPolygon") { 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)) { GOFeature gf = ParseFeatureData(feature, layer); gf.geometry = subject; gf.clips = clips; gf.type = type; gf.layer = layer; gf.parent = parent; gf.properties = feature.GetProperties(); gf.ConvertGeometries(); gf.ConvertAttributes(); gf.index = (Int64)i; gf.goFeatureType = GOFeature.GOFeatureType.MultiPolygon; stack.Add(gf); subject = null; clips = new List <List <LatLng> >(); } } } } IList iStack = (IList)stack; if (layer.layerType == GOLayer.GOLayerType.Roads) { iStack = GORoadFeature.MergeRoads(iStack); } 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(new WaitForSeconds(0.5f)); } Resources.UnloadUnusedAssets(); yield return(null); }
public override IEnumerator BuildTile(IDictionary mapData, GOLayer layer, bool delayedLoad) { yield return(null); }
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 = GOFeature.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 = GOFeature.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 = GOFeature.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 = GOFeature.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]; 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 abstract IEnumerator BuildTile(IDictionary mapData, GOLayer layer, bool delayedLoad);
public GOFeature ParseFeatureData(IDictionary properties, GOLayer layer) { GOFeature goFeature; if (layer.layerType == GOLayer.GOLayerType.Roads) { goFeature = new GORoadFeature(); goFeature.kind = GOEnumUtils.MapzenToKind((string)properties ["kind"]); if (properties.Contains("kind_detail")) //Mapzen { goFeature.detail = (string)properties ["kind_detail"]; } ((GORoadFeature)goFeature).isBridge = properties.Contains("is_bridge") && properties ["is_bridge"].ToString() == "True"; ((GORoadFeature)goFeature).isTunnel = properties.Contains("is_tunnel") && properties ["is_tunnel"].ToString() == "True"; ((GORoadFeature)goFeature).isLink = properties.Contains("is_link") && properties ["is_link"].ToString() == "True"; } else { goFeature = new GOFeature(); goFeature.kind = GOEnumUtils.MapzenToKind((string)properties ["kind"]); if (properties.Contains("kind_detail")) //Mapzen { goFeature.kind = GOEnumUtils.MapzenToKind((string)properties ["kind_detail"]); } } goFeature.name = (string)properties ["name"]; Int64 sort = 0; if (properties.Contains("sort_rank")) { sort = (Int64)properties ["sort_rank"]; } else if (properties.Contains("sort_key")) { sort = (Int64)properties ["sort_key"]; } goFeature.y = sort / 1000.0f; goFeature.sort = sort; goFeature.height = layer.defaultRendering.polygonHeight; if (layer.useRealHeight && properties.Contains("height")) { double h = Convert.ToDouble(properties["height"]); goFeature.height = (float)h; } if (layer.useRealHeight && properties.Contains("min_height")) { double hm = Convert.ToDouble(properties["min_height"]); goFeature.y = (float)hm; if (goFeature.height >= hm) { goFeature.y = (float)hm; goFeature.height = (float)goFeature.height - (float)hm; } } return(goFeature); }
public abstract GOFeature ParseFeatureData(VectorTileFeature feature, GOLayer layer);