示例#1
0
        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);
        }
示例#2
0
        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;
        }
示例#3
0
        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);
        }