Esempio n. 1
0
        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);
            }
        }
Esempio n. 2
0
        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 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);
        }
Esempio n. 4
0
        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);
        }