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 float AngleWithRoad(GORoadFeature r) { Vector3 dir1 = Vector3.zero; //this Vector3 dir2 = Vector3.zero; //other if (r.startingPoint.Equals(endingPoint)) { dir1 = convertedGeometry [convertedGeometry.Count - 2] - endingPoint; dir2 = r.convertedGeometry[1] - r.startingPoint; } else if (r.endingPoint.Equals(startingPoint)) { dir2 = r.convertedGeometry [r.convertedGeometry.Count - 2] - r.endingPoint; dir1 = convertedGeometry[1] - startingPoint; } else if (r.startingPoint.Equals(startingPoint)) { dir1 = convertedGeometry[1] - startingPoint; dir2 = r.convertedGeometry[1] - r.startingPoint; } else if (r.endingPoint.Equals(endingPoint)) { dir1 = convertedGeometry [convertedGeometry.Count - 2] - endingPoint; dir2 = r.convertedGeometry [r.convertedGeometry.Count - 2] - r.endingPoint; } float angle = Vector3.Angle(dir1, dir2); return(angle); }
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 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 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 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); }