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);
        }
Ejemplo n.º 2
0
        public override GOFeature EditFeatureData(GOFeature feature)
        {
            feature.name = (string)feature.properties ["name"];
            if (feature.goFeatureType == GOFeatureType.Point)
            {
                return(feature);
            }

            if (feature.GetType() == typeof(GORoadFeature))
            {
                GORoadFeature grf = (GORoadFeature)feature;

                grf.kind = GOEnumUtils.MapzenToKind((string)grf.properties ["kind"]);
                if (grf.properties.Contains("kind_detail"))                   //Mapzen
                {
                    grf.detail = (string)grf.properties ["kind_detail"];
                }

                grf.isBridge = grf.properties.Contains("is_bridge") && Convert.ToBoolean(grf.properties ["is_bridge"]);
                grf.isTunnel = grf.properties.Contains("is_tunnel") && Convert.ToBoolean(grf.properties ["is_tunnel"]);
                grf.isLink   = grf.properties.Contains("is_link") && Convert.ToBoolean(grf.properties ["is_link"]);
            }
            else
            {
                feature.kind = GOEnumUtils.MapzenToKind((string)feature.properties ["kind"]);
                if (feature.properties.Contains("kind_detail"))                   //Mapzen
                {
                    feature.kind = GOEnumUtils.MapzenToKind((string)feature.properties ["kind_detail"]);
                }
            }

            //			goFeature.name = Convert.ToString( properties ["id"]);

            feature.setRenderingOptions();

            Int64 sort = 0;

            if (feature.properties.Contains("sort_rank"))
            {
                sort = Convert.ToInt64(feature.properties ["sort_rank"]);
            }
            else if (feature.properties.Contains("sort_key"))
            {
                sort = Convert.ToInt64(feature.properties ["sort_key"]);
            }
            feature.y    = sort / 1000.0f;
            feature.sort = sort;

            feature.height = feature.renderingOptions.polygonHeight;

            if (feature.layer.useRealHeight && feature.properties.Contains("height"))
            {
                double h = Convert.ToDouble(feature.properties["height"]);
                feature.height = (float)h;
            }

            if (feature.layer.useRealHeight && feature.properties.Contains("min_height"))
            {
                double hm = Convert.ToDouble(feature.properties["min_height"]);
                feature.y = (float)hm;
                if (feature.height >= hm)
                {
                    feature.y      = (float)hm;
                    feature.height = (float)feature.height - (float)hm;
                }
            }

            if (feature.layer.forceMinHeight && feature.height < feature.renderingOptions.polygonHeight && feature.y < 0.5f)
            {
                feature.height = feature.renderingOptions.polygonHeight;
            }

            return(feature);
        }
        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!");
                FileHandler.Remove(gameObject.name);
                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.featureIndex  = (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.featureIndex  = (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.featureIndex  = (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.featureIndex  = (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);
        }
Ejemplo n.º 4
0
        public override GOFeature EditFeatureData(GOFeature goFeature)
        {
            if (goFeature.goFeatureType == GOFeatureType.Point)
            {
                goFeature.name = (string)goFeature.properties["name"];
                return(goFeature);
            }

            IDictionary properties = goFeature.properties;

            goFeature.kind = GOEnumUtils.MapboxToKind((string)properties["class"]);
            goFeature.name = (string)properties["class"];

            if (!properties.Contains("class") && properties.Contains("type"))
            {
                goFeature.kind = GOEnumUtils.MapboxToKind((string)properties["type"]);
                goFeature.name = (string)properties["type"];
            }

            if (goFeature.layer != null && goFeature.layer.layerType == GOLayer.GOLayerType.Roads)
            {
                ((GORoadFeature)goFeature).isBridge = properties.Contains("structure") && (string)properties["structure"] == "bridge";
                if (((GORoadFeature)goFeature).isBridge)
                {
                    goFeature.kind = GOFeatureKind.bridge;
                }
                ((GORoadFeature)goFeature).isTunnel = properties.Contains("structure") && (string)properties ["structure"] == "tunnel";
                if (((GORoadFeature)goFeature).isTunnel)
                {
                    goFeature.kind = GOFeatureKind.tunnel;
                }
                ((GORoadFeature)goFeature).isLink = properties.Contains("structure") && (string)properties ["structure"] == "link";


                //Fix for v8 streetnames
                if (goFeature.properties.Contains("name") && !string.IsNullOrEmpty((string)goFeature.properties["name"]))
                {
                    goFeature.name = (string)goFeature.properties["name"];
                }
                else
                {
                    goFeature.name = null;
                }
            }

//			goFeature.y = (goFeature.index / 50.0f) + goFeature.getLayerDefaultY() /150.0f;
//			float fraction = goFeature.layer.layerType == GOLayer.GOLayerType.Buildings? 100f:10f;
            float fraction = 20f;

            goFeature.y = (1 + goFeature.layerIndex + goFeature.featureIndex / goFeature.featureCount) / fraction;

            goFeature.setRenderingOptions();
            goFeature.height = goFeature.renderingOptions.polygonHeight;

            bool extrude = properties.Contains("extrude") && (string)properties["extrude"] == "true";

            if (goFeature.layer.useRealHeight && properties.Contains("height") && extrude)
            {
                double h = Convert.ToDouble(properties["height"]);
                goFeature.height = (float)h;
            }

            if (goFeature.layer.useRealHeight && properties.Contains("min_height") && extrude)
            {
                double minHeight = Convert.ToDouble(properties["min_height"]);
                goFeature.y      = (float)minHeight;
                goFeature.height = (float)goFeature.height - (float)minHeight;
            }

            if (goFeature.layer.forceMinHeight && goFeature.height < goFeature.renderingOptions.polygonHeight && goFeature.y < 0.5f)
            {
                goFeature.height = goFeature.renderingOptions.polygonHeight;
            }

            return(goFeature);
        }