private void ParseLabelLayerToList(List <GOParsedLayer> list, VectorTile vt, GOLabelsLayer layer) { string[] lyrs = tile.GetLabelsStrings().Split(','); // string kindKey = tile.GetPoisKindKey(); foreach (string l in lyrs) { VectorTileLayer lyr = vt.GetLayer(l); if (lyr != null) { int featureCount = lyr.FeatureCount(); if (featureCount == 0) { continue; } GOParsedLayer pl = new GOParsedLayer(); pl.name = lyr.Name; pl.labelsLayer = layer; pl.goFeatures = new List <GOFeature> (); for (int i = 0; i < featureCount; i++) { VectorTileFeature vtf = lyr.GetFeature(i); IDictionary properties = vtf.GetProperties(); List <List <LatLng> > geomWgs = vtf.GeometryAsWgs84((ulong)goTile.zoomLevel, (ulong)goTile.tileCoordinates.x, (ulong)goTile.tileCoordinates.y, 0); if (geomWgs.Count == 0 || geomWgs[0].Count <= 1) { continue; } GOFeature gf = new GOFeature(); gf.properties = properties; gf.goFeatureType = vtf.GOFeatureType(geomWgs); gf.labelsLayer = layer; gf.featureIndex = (Int64)i + vt.LayerNames().IndexOf(lyr.Name); gf.goTile = goTile; gf = tile.EditLabelData(gf); gf.goFeatureType = GOFeatureType.Label; gf.ConvertAttributes(); if (geomWgs.Count > 0) { gf.geometry = geomWgs[0]; gf.ConvertGeometries(); gf.preloadedLabelData = GOSegment.FindTheLongestStreightSegment(gf.convertedGeometry, 0); AddFatureToList(gf, pl.goFeatures); } } list.Add(pl); } } }
private void ParseTilesetsToList(List <GOParsedLayer> list, VectorTile vt, GOTilesetLayer[] tilesets) { foreach (GOTilesetLayer tileSet in tilesets) { string kind = string.IsNullOrEmpty(tileSet.TilesetKindProperty)? tileSet.TilesetKindProperty : "kind"; VectorTileLayer lyr = vt.GetLayer(tileSet.TilesetName); if (lyr != null) { int featureCount = lyr.FeatureCount(); if (featureCount == 0) { continue; } GOParsedLayer pl = new GOParsedLayer(); pl.name = lyr.Name; pl.tilesetLayer = tileSet; pl.goFeatures = new List <GOFeature>(); for (int i = 0; i < featureCount; i++) { VectorTileFeature vtf = lyr.GetFeature(i); List <List <LatLng> > geomWgs = vtf.GeometryAsWgs84((ulong)goTile.zoomLevel, (ulong)goTile.tileCoordinates.x, (ulong)goTile.tileCoordinates.y, 0); GOFeature gf = new GOFeature(); gf.properties = vtf.GetProperties(); gf.attributes = GOFeature.PropertiesToAttributes(gf.properties); gf.goFeatureType = vtf.GOFeatureType(geomWgs); gf.tileSetKind = kind; gf.tilesetLayer = tileSet; gf.goTile = goTile; gf.featureIndex = (Int64)i; //gf.layerIndex = indexOfLayer; gf.featureCount = featureCount; //gf = tile.EditFeatureData(gf); gf.goTile = goTile; gf.ConvertAttributes(); if (gf.goFeatureType == GOFeatureType.Undefined) { continue; } string name = "Dataset " + gf.goFeatureType.ToString(); //Debug.Log(name); if (geomWgs.Count > 0 && (gf.goFeatureType == GOFeatureType.Point || gf.goFeatureType == GOFeatureType.MultiPoint)) //Probably needs a fix for multi points { //GOPOIKind kind = GOEnumUtils.PoiKindToEnum((string)properties[kindKey]); GOTilesetPOIRendering rendering = tileSet.TilesetPOIRenderingForKind(kind); if (rendering == null) { continue; } gf.geometry = geomWgs[0]; gf.tileSetPoiRendering = rendering; gf.name = name; gf.ConvertPOIGeometries(); AddFatureToList(gf, pl.goFeatures); } else if (geomWgs.Count > 0) { switch (gf.goFeatureType) { case GOFeatureType.Line: GOTilesetLINERendering lineRendering = tileSet.TilesetLINERenderingForKind(kind); if (lineRendering == null) { continue; } gf.geometry = geomWgs[0]; gf.ConvertGeometries(); gf.tileSetLineRendering = lineRendering; gf.name = name; gf.height = lineRendering.height; AddFatureToList(gf, pl.goFeatures); break; case GOFeatureType.Polygon: GOTilesetPOLYGONRendering polygonRendering = tileSet.TilesetPOLYGONRenderingForKind(kind); if (polygonRendering == null) { continue; } gf.geometry = geomWgs[0]; gf.ConvertGeometries(); gf.name = name; gf.tileSetPolygonRendering = polygonRendering; gf.height = polygonRendering.height; AddFatureToList(gf, pl.goFeatures); break; case GOFeatureType.MultiLine: lineRendering = tileSet.TilesetLINERenderingForKind(kind); if (lineRendering == null) { continue; } foreach (IList geometry in geomWgs) { float indexMulti = (((float)geomWgs.IndexOf((List <LatLng>)geometry) + 1) * (i + 1) / geomWgs.Count); GOFeature gfm = new GOFeature(gf); gf.name = name; gfm.geometry = geometry; gfm.ConvertGeometries(); gf.tileSetLineRendering = lineRendering; gf.height = lineRendering.height; AddFatureToList(gfm, pl.goFeatures); } break; case GOFeatureType.MultiPolygon: foreach (IList geometry in geomWgs) { polygonRendering = tileSet.TilesetPOLYGONRenderingForKind(kind); if (polygonRendering == null) { continue; } List <Vector3> convertedSubject = null; List <List <Vector3> > convertedClips = new List <List <Vector3> >(); for (int j = 0; j < geomWgs.Count; j++) { //Clip ascending IList p = geomWgs[j]; List <Vector3> convertedP = GOFeature.CoordsToVerts(p, false); if (GOFeature.IsClockwise(convertedP)) { convertedSubject = convertedP; } else { //Add clip convertedClips.Add(convertedP); } //Last one if (j == geomWgs.Count - 1 || (j < geomWgs.Count - 1 && GOFeature.IsGeoPolygonClockwise(geomWgs[j + 1]) && convertedSubject != null)) { GOFeature gfm = new GOFeature(gf); // gfm.index = (i +1)*j; gfm.convertedGeometry = convertedSubject; gfm.clips = convertedClips; gf.tileSetPolygonRendering = polygonRendering; gf.name = name; AddFatureToList(gfm, pl.goFeatures); convertedSubject = null; convertedClips = new List <List <Vector3> >(); } } } break; } } } list.Add(pl); } } }
private void ParsePOILayerToList(List <GOParsedLayer> list, VectorTile vt, GOPOILayer layer) { string[] lyrs = tile.GetPoisStrings().Split(','); string kindKey = tile.GetPoisKindKey(); foreach (string l in lyrs) { VectorTileLayer lyr = vt.GetLayer(l); if (lyr != null) { int featureCount = lyr.FeatureCount(); if (featureCount == 0) { continue; } GOParsedLayer pl = new GOParsedLayer(); pl.name = lyr.Name; pl.poiLayer = layer; pl.goFeatures = new List <GOFeature> (); for (int i = 0; i < featureCount; i++) { VectorTileFeature vtf = lyr.GetFeature(i); IDictionary properties = vtf.GetProperties(); GOPOIKind kind = GOEnumUtils.PoiKindToEnum((string)properties[kindKey]); GOPOIRendering rendering = layer.GetRenderingForPoiKind(kind); if (kind == GOPOIKind.UNDEFINED || rendering == null) { continue; } List <List <LatLng> > geomWgs = vtf.GeometryAsWgs84((ulong)goTile.zoomLevel, (ulong)goTile.tileCoordinates.x, (ulong)goTile.tileCoordinates.y, 0); GOFeature gf = new GOFeature(); gf.poiKind = kind; gf.goTile = goTile; gf.properties = properties; gf.attributes = GOFeature.PropertiesToAttributes(gf.properties); gf.goFeatureType = vtf.GOFeatureType(geomWgs); if (gf.goFeatureType == GOFeatureType.Undefined) { continue; } gf.poiLayer = layer; gf.poiRendering = rendering; gf.featureIndex = (Int64)i + vt.LayerNames().IndexOf(lyr.Name); gf = tile.EditFeatureData(gf); gf.ConvertAttributes(); if (geomWgs.Count > 0 && gf.goFeatureType == GOFeatureType.Point) { gf.geometry = geomWgs [0]; gf.ConvertPOIGeometries(); AddFatureToList(gf, pl.goFeatures); } } list.Add(pl); } } }
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); }