Esempio n. 1
0
        protected override void ThreadFunction()
        {
            if (goTile.useElevation)
            {
                goTile.elevatedTerrainMesh();
            }
            tT = DateTime.Now;

            var        decompressed = Mapbox.Utils.Compression.Decompress(goTile.getVectorData());
            VectorTile vt           = new VectorTile(decompressed, false);

            ////DEBUG TO GEOJSON
            //string debug = vt.ToGeoJson((ulong)goTile.zoomLevel, (ulong)goTile.tileCoordinates.x, (ulong)goTile.tileCoordinates.y, 0);
            //FileHandler.SaveText("DEBUG_TILE", debug);

            //DEBUG LAYERS
            //foreach (string lyr in vt.LayerNames())
            //{
            //    Debug.Log(lyr);
            //}


            list = new List <GOParsedLayer> ();

            //Sort layers so that the order is right for dropping environment
            Array.Sort(layers, (GOLayer a, GOLayer b) => GOLayer.LayerTypeToIndex(a.layerType).CompareTo(GOLayer.LayerTypeToIndex(b.layerType)));

            foreach (GOLayer layer in layers)
            {
                if (layer.disabled)
                {
                    continue;
                }
                ParseGOLayerToList(list, vt, layer);
            }


            tF = DateTime.Now;

            if (tile.map.pois != null && (tile.map.pois.renderingOptions.Length > 0 && !tile.map.pois.disabled))
            {
                ParsePOILayerToList(list, vt, tile.map.pois);
            }
            tP = DateTime.Now;

            if (tile.map.labels != null && !tile.map.labels.disabled)
            {
                ParseLabelLayerToList(list, vt, tile.map.labels);
            }
            tL = DateTime.Now;

            if (tile.map.customMapboxTilesets != null && tile.map.customMapboxTilesets.Length > 0)
            {
                ParseTilesetsToList(list, vt, tile.map.customMapboxTilesets);
            }
            tTS = DateTime.Now;
        }
Esempio n. 2
0
        public GameObject BuildLine(GOLayer layer, GORenderingOptions renderingOptions, GOMap map, GameObject parent)
        {
            if (feature.convertedGeometry.Count == 2 && feature.convertedGeometry[0].Equals(feature.convertedGeometry[1]))
            {
                return(null);
            }

            GameObject line = GameObject.Instantiate(feature.goTile.featurePrototype, parent.transform);

            if (renderingOptions.tag.Length > 0)
            {
                line.tag = renderingOptions.tag;
            }

            if (renderingOptions.material)
            {
                renderingOptions.material.renderQueue = -(int)feature.sort;
            }
            if (renderingOptions.outlineMaterial)
            {
                renderingOptions.outlineMaterial.renderQueue = -(int)feature.sort;
            }

            GOLineMesh lineMesh = new GOLineMesh(feature.convertedGeometry);

            lineMesh.width = renderingOptions.lineWidth;
            lineMesh.load(line);
            mesh = lineMesh.mesh;
            line.GetComponent <Renderer>().material = renderingOptions.material;

            Vector3 position = line.transform.position;

            position.y = feature.y;

            line.transform.position = position;

            if (renderingOptions.outlineMaterial != null)
            {
                GameObject outline = CreateRoadOutline(line, renderingOptions.outlineMaterial, renderingOptions.lineWidth + layer.defaultRendering.outlineWidth);
                if (layer.useColliders)
                {
                    MeshCollider mc = outline.GetComponent <MeshCollider> ();
                    mc.enabled    = true;
                    mc.sharedMesh = outline.GetComponent <MeshFilter> ().sharedMesh;
                }

                outline.layer = line.layer;
                outline.tag   = line.tag;
            }
            else if (layer.useColliders)
            {
                line.GetComponent <MeshCollider> ().enabled = true;
            }

            return(line);
        }
 public void GrowTrees(Mesh mesh, GOLayer layer, GOFeatureKind kind, Vector3 center)
 {
     if (kind == GOFeatureKind.park || kind == GOFeatureKind.garden)
     {
         var randomRotation = Quaternion.Euler(0, Random.Range(0, 360), 0);
         int n = Random.Range(0, treePrefab.Length);
         center.y = treePrefab [n].transform.position.y;
         GameObject obj = (GameObject)Instantiate(treePrefab[n], center, randomRotation);
         obj.transform.parent = transform;
     }
 }
        public void AddBoats(Mesh mesh, GOLayer layer, GOFeatureKind kind, Vector3 center)
        {
            bool spawn = Random.value > 0.5f;

            if (kind != GOFeatureKind.riverbank && kind != GOFeatureKind.water && spawn)
            {
                var randomRotation = Quaternion.Euler(0, Random.Range(0, 360), 0);
                center.y = 2;
                GameObject obj = (GameObject)Instantiate(boatPrefab, center, randomRotation);
                obj.transform.parent = transform;
            }
        }
Esempio n. 5
0
        public void AddObjectToLayerMask(GOLayer layer, GameObject obj)
        {
            LayerMask mask = LayerMask.NameToLayer(layer.name);

            if (mask.value > 0 && mask.value < 31)
            {
                obj.layer = LayerMask.NameToLayer(layer.name);
            }
            else
            {
                Debug.LogWarning("[GOMap] Please create layer masks before running GoMap. A layer mask must have the same name declared in GoMap inspector, for example \"" + layer.name + "\".");
            }
        }
Esempio n. 6
0
        public static void AddMap()
        {
            GameObject locationManager = CreateGameObjectInScene("Location Manager");

            CenterOnScreen(locationManager, 0);
            GameObject newMap = CreateGameObjectInScene("Map");

            CenterOnScreen(newMap, 0);
            GOMap map = newMap.AddComponent <GOMap> ();

            map.locationManager = locationManager.AddComponent <LocationManager>();

            GOLayer buildings = new GOLayer();

            buildings.layerType        = GOLayer.GOLayerType.Buildings;
            buildings.isPolygon        = true;
            buildings.defaultRendering = new GORenderingOptions();
            buildings.defaultRendering.polygonHeight = 2;
            buildings.defaultRendering.material      = CreateMaterialWithColor(Color.white);

            GOLayer water = new GOLayer();

            buildings.layerType    = GOLayer.GOLayerType.Water;
            water.isPolygon        = true;
            water.defaultRendering = new GORenderingOptions();
            water.defaultRendering.polygonHeight = 0;
            water.defaultRendering.material      = CreateMaterialWithColor(Color.blue);

            GOLayer landuse = new GOLayer();

            buildings.layerType      = GOLayer.GOLayerType.Landuse;
            landuse.isPolygon        = true;
            landuse.defaultRendering = new GORenderingOptions();
            landuse.defaultRendering.polygonHeight = 0;
            landuse.defaultRendering.material      = CreateMaterialWithColor(Color.green);

            GOLayer roads = new GOLayer();

            buildings.layerType              = GOLayer.GOLayerType.Landuse;
            roads.isPolygon                  = false;
            roads.defaultRendering           = new GORenderingOptions();
            roads.defaultRendering.lineWidth = 2;
            roads.defaultRendering.material  = CreateMaterialWithColor(Color.gray);


            map.layers = new GOLayer[] { buildings, water, landuse, roads };

            Camera.main.transform.position    = new Vector3(0, 600, 100);
            Camera.main.transform.eulerAngles = new Vector3(70, 180, 0);
        }
Esempio n. 7
0
 public bool idCheck(object id, GOLayer layer)
 {
     if (map.buildingsIds.Contains(id))
     {
         //				Debug.Log ("id already created");
         return(false);
     }
     else
     {
         //					Debug.Log ("id added");
         buildingsIds.Add(id);
         map.buildingsIds.Add(id);
         return(true);
     }
 }
        public GOFeature(GOFeature f)
        {
            name          = f.name;
            index         = f.index;
            goFeatureType = f.goFeatureType;
            properties    = f.properties;
            attributes    = f.attributes;
            layer         = f.layer;


            //After editing the feature in tile subclasses.

            //		public string kind;
            kind             = f.kind;
            renderingOptions = f.renderingOptions;
            detail           = f.detail;
            sort             = f.sort;
            y      = f.y;
            height = f.height;
            index  = f.index;
        }
 public override string GetLayersStrings(GOLayer layer)
 {
     return(layer.json());
 }
Esempio n. 10
0
        private void ParseGOLayerToList(List <GOParsedLayer> list, VectorTile vt, GOLayer layer)
        {
            string[] lyrs = tile.GetLayersStrings(layer).Split(',');

            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.goLayer    = layer;
                    pl.goFeatures = new List <GOFeature> ();

                    int indexOfLayer = vt.LayerNames().IndexOf(lyr.Name);

                    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;
                        if (layer.layerType == GOLayer.GOLayerType.Roads)
                        {
                            gf = new GORoadFeature();
                        }
                        else
                        {
                            gf = new GOFeature();
                        }

                        gf.properties    = vtf.GetProperties();
                        gf.attributes    = GOFeature.PropertiesToAttributes(gf.properties);
                        gf.goFeatureType = vtf.GOFeatureType(geomWgs);
                        gf.layer         = layer;
                        gf.featureIndex  = (Int64)i;
                        gf.layerIndex    = indexOfLayer;
                        gf.featureCount  = featureCount;
                        gf        = tile.EditFeatureData(gf);
                        gf.goTile = goTile;
//							gf.setRenderingOptions ();
                        gf.ConvertAttributes();

                        if (geomWgs.Count > 0)
                        {
                            switch (gf.goFeatureType)
                            {
                            case GOFeatureType.Line:
                                gf.geometry = geomWgs [0];
                                gf.ConvertGeometries();
                                AddFatureToList(gf, pl.goFeatures);
                                break;

                            case GOFeatureType.Polygon:
                                gf.geometry = geomWgs[0];
                                gf.ConvertGeometries();
                                AddFatureToList(gf, pl.goFeatures);
                                break;

                            case GOFeatureType.MultiLine:
                                foreach (IList geometry in geomWgs)
                                {
                                    float     indexMulti = (((float)geomWgs.IndexOf((List <LatLng>)geometry) + 1) * (i + 1) / geomWgs.Count);
                                    GOFeature gfm;
                                    if (layer.layerType == GOLayer.GOLayerType.Roads)
                                    {
                                        gfm = new GORoadFeature((GORoadFeature)gf);
                                    }
                                    else
                                    {
                                        gfm = new GOFeature(gf);
                                    }

//									gfm.index = indexMulti;
                                    gfm.geometry = geometry;
                                    gfm.ConvertGeometries();
                                    AddFatureToList(gfm, pl.goFeatures);
                                }
                                break;

                            case GOFeatureType.MultiPolygon:
                                foreach (IList geometry in geomWgs)
                                {
                                    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, layer.layerType == GOLayer.GOLayerType.Buildings);
                                        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;
                                            AddFatureToList(gfm, pl.goFeatures);

                                            convertedSubject = null;
                                            convertedClips   = new List <List <Vector3> >();
                                        }
                                    }
                                }
                                break;
                            }
                        }
                    }

                    if (goTile.combineFeatures)
                    {
                        pl = GOCombineFeatures.Combine(pl);
                    }

                    list.Add(pl);
                }
            }
        }
Esempio n. 11
0
 public abstract IEnumerator BuildTile(IDictionary mapData, GOLayer layer, bool delayedLoad);
Esempio n. 12
0
 //THis method is called on a background thread
 public abstract string GetLayersStrings(GOLayer layer);
Esempio n. 13
0
 public override string GetLayersStrings(GOLayer layer)
 {
     return(layer.lyr_esri());
 }
Esempio n. 14
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);
        }
Esempio n. 15
0
        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);
        }
Esempio n. 16
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);
        }
Esempio n. 17
0
 public abstract GOFeature ParseFeatureData(VectorTileFeature feature, IDictionary properties, GOLayer layer, float featureIndex, Int64 layerIndex);
Esempio n. 18
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;
        }
Esempio n. 19
0
        public GameObject BuildPolygon(GOLayer layer, float height)
        {
            if (feature.convertedGeometry.Count == 2 && feature.convertedGeometry[0].Equals(feature.convertedGeometry[1]))
            {
                return(null);
            }
            List <Vector3> clean = feature.convertedGeometry.Distinct().ToList();

            if (clean == null || clean.Count <= 2)
            {
                return(null);
            }

            GameObject polygon = new GameObject();

            Profiler.BeginSample("[GoMap] Start poly2mesh");
            Poly2Mesh.Polygon poly = new Poly2Mesh.Polygon();
            poly.outside = feature.convertedGeometry;
            if (feature.clips != null)
            {
                foreach (IList clipVerts in feature.clips)
                {
                    poly.holes.Add(GOFeature.CoordsToVerts(clipVerts, true));
                }
            }
            Profiler.EndSample();

            MeshFilter filter = polygon.AddComponent <MeshFilter>();

            meshRenderer = polygon.AddComponent <MeshRenderer>();

            Profiler.BeginSample("[GoMap] Create polygon mesh");
            try {
                mesh = Poly2Mesh.CreateMesh(poly);
            } catch {
            }
            Profiler.EndSample();


            if (mesh)
            {
                Profiler.BeginSample("[GoMap] Set polygon UV");
                Vector2[] uvs      = new Vector2[mesh.vertices.Length];
                Vector3[] vertices = mesh.vertices;
                for (int i = 0; i < uvs.Length; i++)
                {
                    uvs[i] = new Vector2(vertices[i].x, vertices[i].z);
                }
                mesh.uv = uvs;
                Profiler.EndSample();

                Profiler.BeginSample("[GoMap] instantiate mesh 2D");
                mesh2D = Mesh.Instantiate(mesh);
                Profiler.EndSample();

                Profiler.BeginSample("[GoMap] polygon extrusion");
                if (height > 0)
                {
                    mesh = SimpleExtruder.SliceExtrude(mesh, polygon, height, 4f, 4f, 10f);
//					mesh = SimpleExtruder.Extrude (mesh, polygon, height);
                }
                Profiler.EndSample();
            }


            filter.sharedMesh = mesh;

            if (layer.useColliders && mesh != null && feature.convertedGeometry.Count() > 2)
            {
                polygon.AddComponent <MeshCollider>().sharedMesh = mesh;
            }


            return(polygon);
        }
Esempio n. 20
0
 public override IEnumerator BuildTile(IDictionary mapData, GOLayer layer, bool delayedLoad)
 {
     yield return(null);
 }
        public void BuildLine(GameObject line, GOLayer layer, GORenderingOptions renderingOptions, GOMap map)
        {
            if (feature.convertedGeometry.Count == 2 && feature.convertedGeometry[0].Equals(feature.convertedGeometry[1]))
            {
                return;
            }

                        #if GOLINK
            feature.convertedGeometry = GOFeatureMeshBuilder.BreakLine(feature.convertedGeometry, map.goTerrain);
                        #endif

            if (renderingOptions.tag.Length > 0)
            {
                line.tag = renderingOptions.tag;
            }

            if (renderingOptions.material)
            {
                renderingOptions.material.renderQueue = -(int)feature.sort;
            }
            if (renderingOptions.outlineMaterial)
            {
                renderingOptions.outlineMaterial.renderQueue = -(int)feature.sort;
            }

            GOLineMesh lineMesh = new GOLineMesh(feature.convertedGeometry);
            lineMesh.width = renderingOptions.lineWidth;
            lineMesh.load(line);
            mesh = lineMesh.mesh;
            line.GetComponent <Renderer>().material = renderingOptions.material;

            Vector3 position = line.transform.position;
            position.y = feature.y;

                        #if GOLINK
            if (renderingOptions.polygonHeight > 0)
            {
                int offset = GOFeature.BuildingElevationOffset;
                line.GetComponent <MeshFilter> ().sharedMesh = SimpleExtruder.Extrude(line.GetComponent <MeshFilter> ().sharedMesh, line, renderingOptions.polygonHeight + offset);
                position.y -= offset;
            }
                        #else
                        #endif

            line.transform.position = position;

            if (renderingOptions.outlineMaterial != null)
            {
                GameObject outline = CreateRoadOutline(line, renderingOptions.outlineMaterial, renderingOptions.lineWidth + layer.defaultRendering.outlineWidth);
                if (layer.useColliders)
                {
                    outline.AddComponent <MeshCollider> ().sharedMesh = outline.GetComponent <MeshFilter> ().sharedMesh;
                }

                outline.layer = line.layer;
                outline.tag   = line.tag;
            }
            else if (layer.useColliders)
            {
//				Mesh m = gameObject.GetComponent<MeshFilter> ().sharedMesh;
                line.AddComponent <MeshCollider> ();
            }
        }